1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002, 2003 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"
30 /* The pretty-printer code is primarily designed to closely follow
31 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
32 codes we used to have in the past. Following a structured
33 approach (preferably the official grammars) is believed to make it
34 much easier to add extensions and nifty pretty-printing effects that
35 takes expression or declaration contexts into account. */
38 #define pp_c_maybe_whitespace(PP) \
40 if (pp_base (PP)->padding == pp_before) \
41 pp_c_whitespace (PP); \
44 #define pp_c_left_brace(PP) \
47 pp_base (PP)->padding = pp_none; \
50 #define pp_c_right_brace(PP) \
52 pp_right_brace (PP); \
53 pp_base (PP)->padding = pp_none; \
56 #define pp_c_left_bracket(PP) \
58 pp_left_bracket (PP); \
59 pp_base (PP)->padding = pp_none; \
62 #define pp_c_right_bracket(PP) \
64 pp_right_bracket (PP); \
65 pp_base (PP)->padding = pp_none; \
68 #define pp_c_star(PP) \
71 pp_base (PP)->padding = pp_none; \
75 static void pp_c_char (c_pretty_printer
*, int);
77 /* postfix-expression */
78 static void pp_c_initializer_list (c_pretty_printer
*, tree
);
80 static void pp_c_multiplicative_expression (c_pretty_printer
*, tree
);
81 static void pp_c_additive_expression (c_pretty_printer
*, tree
);
82 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
83 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
84 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
85 static void pp_c_and_expression (c_pretty_printer
*, tree
);
86 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
87 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
88 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
89 static void pp_c_conditional_expression (c_pretty_printer
*, tree
);
90 static void pp_c_assignment_expression (c_pretty_printer
*, tree
);
95 /* Helper functions. */
98 pp_c_whitespace (c_pretty_printer
*pp
)
101 pp_base (pp
)->padding
= pp_none
;
105 pp_c_left_paren (c_pretty_printer
*pp
)
108 pp_base (pp
)->padding
= pp_none
;
112 pp_c_right_paren (c_pretty_printer
*pp
)
115 pp_base (pp
)->padding
= pp_none
;
119 pp_c_dot (c_pretty_printer
*pp
)
122 pp_base (pp
)->padding
= pp_none
;
126 pp_c_ampersand (c_pretty_printer
*pp
)
129 pp_base (pp
)->padding
= pp_none
;
133 pp_c_arrow (c_pretty_printer
*pp
)
136 pp_base (pp
)->padding
= pp_none
;
140 pp_c_semicolon(c_pretty_printer
*pp
)
143 pp_base (pp
)->padding
= pp_none
;
147 pp_c_cv_qualifier (c_pretty_printer
*pp
, const char *cv
)
149 const char *p
= pp_last_position_in_text (pp
);
150 if (p
!= NULL
&& *p
== '*')
151 pp_c_whitespace (pp
);
152 pp_c_identifier (pp
, cv
);
155 /* Pretty-print T using the type-cast notation '( type-name )'. */
157 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
159 pp_c_left_paren (pp
);
161 pp_c_right_paren (pp
);
165 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
167 if (POINTER_TYPE_P (t
))
169 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
170 if (TREE_CODE (pointee
) != ARRAY_TYPE
171 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
172 pp_c_whitespace (pp
);
179 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
180 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
181 of its type. Take care of possible extensions.
185 type-qualifier-list type-qualifier
190 __restrict__ -- GNU C
193 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
200 qualifiers
= TYPE_QUALS (t
);
201 if (qualifiers
& TYPE_QUAL_CONST
)
202 pp_c_cv_qualifier (pp
, "const");
203 if (qualifiers
& TYPE_QUAL_VOLATILE
)
204 pp_c_cv_qualifier (pp
, "volatile");
205 if (qualifiers
& TYPE_QUAL_RESTRICT
)
206 pp_c_cv_qualifier (pp
, flag_isoc99
? "restrict" : "__restrict__");
210 * type-qualifier-list(opt)
211 * type-qualifier-list(opt) pointer */
213 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
215 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
217 switch (TREE_CODE (t
))
220 /* It is easier to handle C++ reference types here. */
222 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
223 pp_c_pointer (pp
, TREE_TYPE (t
));
224 if (TREE_CODE (t
) == POINTER_TYPE
)
228 pp_c_type_qualifier_list (pp
, t
);
232 pp_unsupported_tree (pp
, t
);
249 struct-or-union-specifier
254 simple-type-specifier:
258 pp_c_type_specifier (c_pretty_printer
*pp
, tree t
)
260 const enum tree_code code
= TREE_CODE (t
);
264 pp_c_identifier (pp
, "<type-error>");
267 case IDENTIFIER_NODE
:
268 pp_c_tree_identifier (pp
, t
);
276 pp_c_type_specifier (pp
, TYPE_NAME (t
));
281 pp_id_expression (pp
, t
);
283 pp_c_identifier (pp
, "<typedef-error>");
289 if (code
== UNION_TYPE
)
290 pp_c_identifier (pp
, "union");
291 else if (code
== RECORD_TYPE
)
292 pp_c_identifier (pp
, "struct");
293 else if (code
== ENUMERAL_TYPE
)
294 pp_c_identifier (pp
, "enum");
296 pp_c_identifier (pp
, "<tag-error>");
299 pp_id_expression (pp
, TYPE_NAME (t
));
301 pp_c_identifier (pp
, "<anonymous>");
305 pp_unsupported_tree (pp
, t
);
310 /* specifier-qualifier-list:
311 type-specifier specifier-qualifier-list-opt
312 type-qualifier specifier-qualifier-list-opt
315 Implementation note: Because of the non-linearities in array or
316 function declarations, this routine prints not just the
317 specifier-qualifier-list of such entities or types of such entities,
318 but also the 'pointer' production part of their declarators. The
319 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
321 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
323 const enum tree_code code
= TREE_CODE (t
);
325 if (TREE_CODE (t
) != POINTER_TYPE
)
326 pp_c_type_qualifier_list (pp
, t
);
332 /* Get the types-specifier of this type. */
333 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
334 pp_c_specifier_qualifier_list (pp
, pointee
);
335 if (TREE_CODE (pointee
) == ARRAY_TYPE
336 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
338 pp_c_whitespace (pp
);
339 pp_c_left_paren (pp
);
341 pp_ptr_operator (pp
, t
);
347 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
352 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
353 if (code
== COMPLEX_TYPE
)
354 pp_c_identifier (pp
, flag_isoc99
? "_Complex" : "__complex__");
355 else if (code
== VECTOR_TYPE
)
356 pp_c_identifier (pp
, "__vector__");
360 pp_simple_type_specifier (pp
, t
);
365 /* parameter-type-list:
370 parameter-declaration
371 parameter-list , parameter-declaration
373 parameter-declaration:
374 declaration-specifiers declarator
375 declaration-specifiers abstract-declarator(opt) */
377 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
379 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
380 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
381 pp_c_left_paren (pp
);
382 if (parms
== void_list_node
)
383 pp_c_identifier (pp
, "void");
387 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
390 pp_separate_with (pp
, ',');
392 pp_declaration_specifiers
393 (pp
, want_parm_decl
? parms
: TREE_VALUE (parms
));
395 pp_declarator (pp
, parms
);
397 pp_abstract_declarator (pp
, TREE_VALUE (parms
));
400 pp_c_right_paren (pp
);
403 /* abstract-declarator:
405 pointer(opt) direct-abstract-declarator */
407 pp_c_abstract_declarator (c_pretty_printer
*pp
, tree t
)
409 if (TREE_CODE (t
) == POINTER_TYPE
)
411 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
412 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
413 pp_c_right_paren (pp
);
417 pp_direct_abstract_declarator (pp
, t
);
420 /* direct-abstract-declarator:
421 ( abstract-declarator )
422 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
423 direct-abstract-declarator(opt) [ * ]
424 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
426 pp_c_direct_abstract_declarator (c_pretty_printer
*pp
, tree t
)
428 switch (TREE_CODE (t
))
431 pp_abstract_declarator (pp
, t
);
435 pp_c_parameter_type_list (pp
, t
);
436 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
440 pp_c_left_bracket (pp
);
442 pp_expression (pp
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)));
443 pp_c_right_bracket (pp
);
444 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
447 case IDENTIFIER_NODE
:
461 pp_unsupported_tree (pp
, t
);
467 specifier-qualifier-list abstract-declarator(opt) */
469 pp_c_type_id (c_pretty_printer
*pp
, tree t
)
471 pp_c_specifier_qualifier_list (pp
, t
);
472 pp_abstract_declarator (pp
, t
);
475 /* storage-class-specifier:
482 pp_c_storage_class_specifier (c_pretty_printer
*pp
, tree t
)
484 if (TREE_CODE (t
) == TYPE_DECL
)
485 pp_c_identifier (pp
, "typedef");
488 if (DECL_REGISTER (t
))
489 pp_c_identifier (pp
, "register");
490 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
491 pp_c_identifier (pp
, "static");
495 /* function-specifier:
498 pp_c_function_specifier (c_pretty_printer
*pp
, tree t
)
500 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
501 pp_c_identifier (pp
, "inline");
504 /* declaration-specifiers:
505 storage-class-specifier declaration-specifiers(opt)
506 type-specifier declaration-specifiers(opt)
507 type-qualifier declaration-specifiers(opt)
508 function-specifier declaration-specifiers(opt) */
510 pp_c_declaration_specifiers (c_pretty_printer
*pp
, tree t
)
512 pp_storage_class_specifier (pp
, t
);
513 pp_function_specifier (pp
, t
);
514 pp_c_specifier_qualifier_list (pp
, DECL_P (t
) ? TREE_TYPE (t
) : t
);
520 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
521 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
522 direct-declarator [ type-qualifier-list static assignment-exression ]
523 direct-declarator [ type-qualifier-list * ]
524 direct-declaratpr ( parameter-type-list )
525 direct-declarator ( identifier-list(opt) ) */
527 pp_c_direct_declarator (c_pretty_printer
*pp
, tree t
)
529 switch (TREE_CODE (t
))
538 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (t
));
539 pp_c_tree_identifier (pp
, DECL_NAME (t
));
543 pp_abstract_declarator (pp
, TREE_TYPE (t
));
547 pp_parameter_list (pp
, t
);
548 pp_abstract_declarator (pp
, TREE_TYPE (t
));
552 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
553 pp_c_tree_identifier (pp
, DECL_NAME (t
));
554 if (pp_c_base (pp
)->flags
& pp_c_flag_abstract
)
555 pp_abstract_declarator (pp
, TREE_TYPE (t
));
558 pp_parameter_list (pp
, t
);
559 pp_abstract_declarator (pp
, TREE_TYPE (TREE_TYPE (t
)));
571 pp_unsupported_tree (pp
, t
);
578 pointer(opt) direct-declarator */
580 pp_c_declarator (c_pretty_printer
*pp
, tree t
)
582 switch (TREE_CODE (t
))
598 pp_direct_declarator (pp
, t
);
603 pp_unsupported_tree (pp
, t
);
609 declaration-specifiers init-declarator-list(opt) ; */
611 pp_c_declaration (c_pretty_printer
*pp
, tree t
)
613 pp_declaration_specifiers (pp
, t
);
614 pp_c_init_declarator (pp
, t
);
617 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
619 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
621 if (attributes
== NULL_TREE
)
624 pp_c_identifier (pp
, "__attribute__");
625 pp_c_left_paren (pp
);
626 pp_c_left_paren (pp
);
627 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
629 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
630 if (TREE_VALUE (attributes
))
631 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
633 if (TREE_CHAIN (attributes
))
634 pp_separate_with (pp
, ',');
636 pp_c_right_paren (pp
);
637 pp_c_right_paren (pp
);
640 /* function-definition:
641 declaration-specifiers declarator compound-statement */
643 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
645 pp_declaration_specifiers (pp
, t
);
646 pp_declarator (pp
, t
);
647 pp_needs_newline (pp
) = true;
648 pp_statement (pp
, DECL_SAVED_TREE (t
));
656 /* Print out a c-char. */
658 pp_c_char (c_pretty_printer
*pp
, int c
)
663 pp_string (pp
, "\\n");
666 pp_string (pp
, "\\t");
669 pp_string (pp
, "\\v");
672 pp_string (pp
, "\\b");
675 pp_string (pp
, "\\r");
678 pp_string (pp
, "\\f");
681 pp_string (pp
, "\\a");
684 pp_string (pp
, "\\\\");
687 pp_string (pp
, "\\'");
690 pp_string (pp
, "\\\"");
694 pp_character (pp
, c
);
696 pp_scalar (pp
, "\\%03o", (unsigned) c
);
701 /* Print out a STRING literal. */
703 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
705 const char *p
= TREE_STRING_POINTER (s
);
706 int n
= TREE_STRING_LENGTH (s
) - 1;
709 for (i
= 0; i
< n
; ++i
)
710 pp_c_char (pp
, p
[i
]);
715 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
717 if (host_integerp (i
, 0))
718 pp_wide_integer (pp
, TREE_INT_CST_LOW (i
));
721 if (tree_int_cst_sgn (i
) < 0)
724 i
= build_int_2 (-TREE_INT_CST_LOW (i
),
725 ~TREE_INT_CST_HIGH (i
) + !TREE_INT_CST_LOW (i
));
727 sprintf (pp_buffer (pp
)->digit_buffer
,
728 HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
729 TREE_INT_CST_HIGH (i
), TREE_INT_CST_LOW (i
));
730 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
734 /* Print out a CHARACTER literal. */
736 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
738 tree type
= TREE_TYPE (c
);
739 if (type
== wchar_type_node
)
740 pp_character (pp
, 'L');
742 if (host_integerp (c
, TREE_UNSIGNED (type
)))
743 pp_c_char (pp
, tree_low_cst (c
, TREE_UNSIGNED (type
)));
745 pp_scalar (pp
, "\\x%x", (unsigned) TREE_INT_CST_LOW (c
));
749 /* Print out a BOOLEAN literal. */
751 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
753 if (b
== boolean_false_node
)
755 if (c_dialect_cxx ())
756 pp_c_identifier (pp
, "false");
757 else if (flag_isoc99
)
758 pp_c_identifier (pp
, "_False");
760 pp_unsupported_tree (pp
, b
);
762 else if (b
== boolean_true_node
)
764 if (c_dialect_cxx ())
765 pp_c_identifier (pp
, "true");
766 else if (flag_isoc99
)
767 pp_c_identifier (pp
, "_True");
769 pp_unsupported_tree (pp
, b
);
771 else if (TREE_CODE (b
) == INTEGER_CST
)
772 pp_c_integer_constant (pp
, b
);
774 pp_unsupported_tree (pp
, b
);
777 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
778 false; that means the value was obtained by a cast, in which case
779 print out the type-id part of the cast-expression -- the casted value
780 is then printed by pp_c_integer_literal. */
782 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
784 bool value_is_named
= true;
785 tree type
= TREE_TYPE (e
);
788 /* Find the name of this constant. */
789 for (value
= TYPE_VALUES (type
);
790 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
791 value
= TREE_CHAIN (value
))
794 if (value
!= NULL_TREE
)
795 pp_id_expression (pp
, TREE_PURPOSE (value
));
798 /* Value must have been cast. */
799 pp_c_type_cast (pp
, type
);
800 value_is_named
= false;
803 return value_is_named
;
806 /* Print out a REAL value. */
808 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
810 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
811 sizeof (pp_buffer (pp
)->digit_buffer
), 0, 1);
812 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
819 chatracter-constant */
821 pp_c_constant (c_pretty_printer
*pp
, tree e
)
823 switch (TREE_CODE (e
))
827 tree type
= TREE_TYPE (e
);
828 if (type
== boolean_type_node
)
829 pp_c_bool_constant (pp
, e
);
830 else if (type
== char_type_node
)
831 pp_c_character_constant (pp
, e
);
832 else if (TREE_CODE (type
) == ENUMERAL_TYPE
833 && pp_c_enumeration_constant (pp
, e
))
836 pp_c_integer_constant (pp
, e
);
841 pp_c_floating_constant (pp
, e
);
845 pp_c_string_literal (pp
, e
);
849 pp_unsupported_tree (pp
, e
);
855 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
857 pp_c_maybe_whitespace (pp
);
858 pp_identifier (pp
, id
);
859 pp_base (pp
)->padding
= pp_before
;
862 /* Pretty-print a C primary-expression.
869 pp_c_primary_expression (c_pretty_printer
*pp
, tree e
)
871 switch (TREE_CODE (e
))
881 case IDENTIFIER_NODE
:
882 pp_c_tree_identifier (pp
, e
);
886 pp_c_identifier (pp
, "<erroneous-expression>");
890 pp_c_identifier (pp
, "<return-value>");
896 pp_c_constant (pp
, e
);
900 pp_c_left_paren (pp
);
901 pp_statement (pp
, STMT_EXPR_STMT (e
));
902 pp_c_right_paren (pp
);
906 /* FIXME: Make sure we won't get into an infinie loop. */
907 pp_c_left_paren (pp
);
908 pp_expression (pp
, e
);
909 pp_c_right_paren (pp
);
914 /* Print out a C initializer -- also support C compound-literals.
916 assignment-expression:
918 { initializer-list , } */
921 pp_c_initializer (c_pretty_printer
*pp
, tree e
)
923 if (TREE_CODE (e
) == CONSTRUCTOR
)
925 enum tree_code code
= TREE_CODE (TREE_TYPE (e
));
926 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
|| code
== ARRAY_TYPE
)
928 pp_c_left_brace (pp
);
929 pp_c_initializer_list (pp
, e
);
930 pp_c_right_brace (pp
);
933 pp_unsupported_tree (pp
, TREE_OPERAND (e
, 1));
936 pp_expression (pp
, e
);
941 declarator = initializer */
943 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
945 pp_declarator (pp
, t
);
946 if (DECL_INITIAL (t
))
948 tree init
= DECL_INITIAL (t
);
949 /* This C++ bit is handled here because it is easier to do so.
950 In templates, the C++ parser builds a TREE_LIST for a
951 direct-initialization; the TREE_PURPOSE is the variable to
952 initialize and the TREE_VALUE is the initializer. */
953 if (TREE_CODE (init
) == TREE_LIST
)
955 pp_c_left_paren (pp
);
956 pp_expression (pp
, TREE_VALUE (init
));
964 pp_c_initializer (pp
, init
);
970 designation(opt) initializer
971 initializer-list , designation(opt) initializer
978 designator-list designator
981 [ constant-expression ]
984 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
986 tree type
= TREE_TYPE (e
);
987 const enum tree_code code
= TREE_CODE (type
);
989 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
|| code
== ARRAY_TYPE
)
991 tree init
= TREE_OPERAND (e
, 0);
992 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
994 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
997 pp_c_primary_expression (pp
, TREE_PURPOSE (init
));
1001 pp_c_left_bracket (pp
);
1002 if (TREE_PURPOSE (init
))
1003 pp_c_constant (pp
, TREE_PURPOSE (init
));
1004 pp_c_right_bracket (pp
);
1006 pp_c_whitespace (pp
);
1008 pp_c_whitespace (pp
);
1009 pp_initializer (pp
, TREE_VALUE (init
));
1010 if (TREE_CHAIN (init
))
1011 pp_separate_with (pp
, ',');
1015 pp_unsupported_tree (pp
, type
);
1018 /* This is a convenient function, used to bridge gap between C and C++
1024 pp_c_id_expression (c_pretty_printer
*pp
, tree t
)
1026 switch (TREE_CODE (t
))
1036 case IDENTIFIER_NODE
:
1037 pp_c_tree_identifier (pp
, t
);
1041 pp_unsupported_tree (pp
, t
);
1046 /* postfix-expression:
1048 postfix-expression [ expression ]
1049 postfix-expression ( argument-expression-list(opt) )
1050 postfix-expression . identifier
1051 postfix-expression -> identifier
1052 postfix-expression ++
1053 postfix-expression --
1054 ( type-name ) { initializer-list }
1055 ( type-name ) { initializer-list , } */
1057 pp_c_postfix_expression (c_pretty_printer
*pp
, tree e
)
1059 enum tree_code code
= TREE_CODE (e
);
1062 case POSTINCREMENT_EXPR
:
1063 case POSTDECREMENT_EXPR
:
1064 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1065 pp_identifier (pp
, code
== POSTINCREMENT_EXPR
? "++" : "--");
1069 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1074 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1075 pp_c_left_bracket (pp
);
1076 pp_expression (pp
, TREE_OPERAND (e
, 1));
1077 pp_c_right_bracket (pp
);
1081 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1082 pp_c_call_argument_list (pp
, TREE_OPERAND (e
, 1));
1087 pp_c_identifier (pp
,
1088 code
== ABS_EXPR
? "__builtin_abs" : "__builtin_ffs");
1089 pp_c_left_paren (pp
);
1090 pp_expression (pp
, TREE_OPERAND (e
, 0));
1091 pp_c_right_paren (pp
);
1096 tree object
= TREE_OPERAND (e
, 0);
1097 if (TREE_CODE (object
) == INDIRECT_REF
)
1099 pp_postfix_expression (pp
, TREE_OPERAND (object
, 0));
1104 pp_postfix_expression (pp
, object
);
1107 pp_expression (pp
, TREE_OPERAND (e
, 1));
1114 pp_c_type_cast (pp
, TREE_TYPE (e
));
1115 pp_c_left_brace (pp
);
1117 if (code
== COMPLEX_CST
)
1119 pp_expression (pp
, TREE_REALPART (e
));
1120 pp_separate_with (pp
, ',');
1121 pp_expression (pp
, TREE_IMAGPART (e
));
1123 else if (code
== VECTOR_CST
)
1124 pp_c_expression_list (pp
, TREE_VECTOR_CST_ELTS (e
));
1125 else if (code
== COMPLEX_EXPR
)
1127 pp_expression (pp
, TREE_OPERAND (e
, 0));
1128 pp_separate_with (pp
, ',');
1129 pp_expression (pp
, TREE_OPERAND (e
, 1));
1132 pp_c_right_brace (pp
);
1135 case COMPOUND_LITERAL_EXPR
:
1136 e
= DECL_INITIAL (e
);
1139 pp_initializer (pp
, e
);
1143 pp_c_identifier (pp
, "__builtin_va_arg");
1144 pp_c_left_paren (pp
);
1145 pp_assignment_expression (pp
, TREE_OPERAND (e
, 0));
1146 pp_separate_with (pp
, ',');
1147 pp_type_id (pp
, TREE_TYPE (e
));
1148 pp_c_right_paren (pp
);
1152 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1154 pp_c_id_expression (pp
, TREE_OPERAND (e
, 0));
1157 /* else fall through. */
1160 pp_primary_expression (pp
, e
);
1165 /* Print out an expression-list; E is expected to be a TREE_LIST */
1167 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1169 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1171 pp_expression (pp
, TREE_VALUE (e
));
1173 pp_separate_with (pp
, ',');
1177 /* Print out an expression-list in parens, as in a function call. */
1179 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1181 pp_c_left_paren (pp
);
1182 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1183 pp_c_expression_list (pp
, t
);
1184 pp_c_right_paren (pp
);
1187 /* unary-expression:
1191 unary-operator cast-expression
1192 sizeof unary-expression
1195 unary-operator: one of
1200 __alignof__ unary-expression
1201 __alignof__ ( type-id )
1202 __real__ unary-expression
1203 __imag__ unary-expression */
1205 pp_c_unary_expression (c_pretty_printer
*pp
, tree e
)
1207 enum tree_code code
= TREE_CODE (e
);
1210 case PREINCREMENT_EXPR
:
1211 case PREDECREMENT_EXPR
:
1212 pp_identifier (pp
, code
== PREINCREMENT_EXPR
? "++" : "--");
1213 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1220 case TRUTH_NOT_EXPR
:
1222 /* String literal are used by address. */
1223 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1225 else if (code
== INDIRECT_REF
)
1227 else if (code
== NEGATE_EXPR
)
1229 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1231 else if (code
== TRUTH_NOT_EXPR
)
1232 pp_exclamation (pp
);
1233 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1238 pp_c_identifier (pp
, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
1239 pp_c_whitespace (pp
);
1240 if (TYPE_P (TREE_OPERAND (e
, 0)))
1241 pp_c_type_cast (pp
, TREE_OPERAND (e
, 0));
1243 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1248 pp_c_identifier (pp
, code
== REALPART_EXPR
? "__real__" : "__imag__");
1249 pp_c_whitespace (pp
);
1250 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1254 pp_postfix_expression (pp
, e
);
1261 ( type-name ) cast-expression */
1263 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1265 switch (TREE_CODE (e
))
1268 case FIX_TRUNC_EXPR
:
1270 pp_c_type_cast (pp
, TREE_TYPE (e
));
1271 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1275 pp_unary_expression (pp
, e
);
1279 /* multiplicative-expression:
1281 multiplicative-expression * cast-expression
1282 multiplicative-expression / cast-expression
1283 multiplicative-expression % cast-expression */
1285 pp_c_multiplicative_expression (c_pretty_printer
*pp
, tree e
)
1287 enum tree_code code
= TREE_CODE (e
);
1291 case TRUNC_DIV_EXPR
:
1292 case TRUNC_MOD_EXPR
:
1293 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
1294 pp_c_whitespace (pp
);
1295 if (code
== MULT_EXPR
)
1297 else if (code
== TRUNC_DIV_EXPR
)
1301 pp_c_whitespace (pp
);
1302 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 1));
1306 pp_c_cast_expression (pp
, e
);
1311 /* additive-expression:
1312 multiplicative-expression
1313 additive-expression + multiplicative-expression
1314 additive-expression - multiplicative-expression */
1316 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1318 enum tree_code code
= TREE_CODE (e
);
1323 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1324 pp_c_whitespace (pp
);
1325 if (code
== PLUS_EXPR
)
1329 pp_c_whitespace (pp
);
1330 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 1));
1334 pp_multiplicative_expression (pp
, e
);
1339 /* additive-expression:
1341 shift-expression << additive-expression
1342 shift-expression >> additive-expression */
1344 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1346 enum tree_code code
= TREE_CODE (e
);
1351 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1352 pp_c_whitespace (pp
);
1353 pp_identifier (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1354 pp_c_whitespace (pp
);
1355 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1359 pp_c_additive_expression (pp
, e
);
1363 /* relational-expression:
1365 relational-expression < shift-expression
1366 relational-expression > shift-expression
1367 relational-expression <= shift-expression
1368 relational-expression >= shift-expression */
1370 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1372 enum tree_code code
= TREE_CODE (e
);
1379 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1380 pp_c_whitespace (pp
);
1381 if (code
== LT_EXPR
)
1383 else if (code
== GT_EXPR
)
1385 else if (code
== LE_EXPR
)
1386 pp_identifier (pp
, "<=");
1387 else if (code
== GE_EXPR
)
1388 pp_identifier (pp
, ">=");
1389 pp_c_whitespace (pp
);
1390 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1394 pp_c_shift_expression (pp
, e
);
1399 /* equality-expression:
1400 relational-expression
1401 equality-expression == relational-expression
1402 equality-equality != relational-expression */
1404 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1406 enum tree_code code
= TREE_CODE (e
);
1411 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1412 pp_c_whitespace (pp
);
1413 pp_identifier (pp
, code
== EQ_EXPR
? "==" : "!=");
1414 pp_c_whitespace (pp
);
1415 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1419 pp_c_relational_expression (pp
, e
);
1426 AND-expression & equality-equality */
1428 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1430 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1432 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1433 pp_c_whitespace (pp
);
1435 pp_c_whitespace (pp
);
1436 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1439 pp_c_equality_expression (pp
, e
);
1442 /* exclusive-OR-expression:
1444 exclusive-OR-expression ^ AND-expression */
1446 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1448 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
1450 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1451 pp_c_maybe_whitespace (pp
);
1453 pp_c_whitespace (pp
);
1454 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
1457 pp_c_and_expression (pp
, e
);
1460 /* inclusive-OR-expression:
1461 exclusive-OR-expression
1462 inclusive-OR-expression | exclusive-OR-expression */
1464 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1466 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
1468 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1469 pp_c_whitespace (pp
);
1471 pp_c_whitespace (pp
);
1472 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1475 pp_c_exclusive_or_expression (pp
, e
);
1478 /* logical-AND-expression:
1479 inclusive-OR-expression
1480 logical-AND-expression && inclusive-OR-expression */
1482 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
1484 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
)
1486 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
1487 pp_c_whitespace (pp
);
1488 pp_identifier (pp
, "&&");
1489 pp_c_whitespace (pp
);
1490 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1493 pp_c_inclusive_or_expression (pp
, e
);
1496 /* logical-OR-expression:
1497 logical-AND-expression
1498 logical-OR-expression || logical-AND-expression */
1500 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
1502 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
)
1504 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1505 pp_c_whitespace (pp
);
1506 pp_identifier (pp
, "||");
1507 pp_c_whitespace (pp
);
1508 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
1511 pp_c_logical_and_expression (pp
, e
);
1514 /* conditional-expression:
1515 logical-OR-expression
1516 logical-OR-expression ? expression : conditional-expression */
1518 pp_c_conditional_expression (c_pretty_printer
*pp
, tree e
)
1520 if (TREE_CODE (e
) == COND_EXPR
)
1522 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1523 pp_c_whitespace (pp
);
1525 pp_c_whitespace (pp
);
1526 pp_expression (pp
, TREE_OPERAND (e
, 1));
1527 pp_c_whitespace (pp
);
1529 pp_c_whitespace (pp
);
1530 pp_c_conditional_expression (pp
, TREE_OPERAND (e
, 2));
1533 pp_c_logical_or_expression (pp
, e
);
1537 /* assignment-expression:
1538 conditional-expression
1539 unary-expression assignment-operator assignment-expression
1541 assignment-expression: one of
1542 = *= /= %= += -= >>= <<= &= ^= |= */
1544 pp_c_assignment_expression (c_pretty_printer
*pp
, tree e
)
1546 if (TREE_CODE (e
) == MODIFY_EXPR
|| TREE_CODE (e
) == INIT_EXPR
)
1548 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1549 pp_c_whitespace (pp
);
1552 pp_c_expression (pp
, TREE_OPERAND (e
, 1));
1555 pp_c_conditional_expression (pp
, e
);
1559 assignment-expression
1560 expression , assignment-expression
1562 Implementation note: instead of going through the usual recursion
1563 chain, I take the liberty of dispatching nodes to the appropriate
1564 functions. This makes some redundancy, but it worths it. That also
1565 prevents a possible infinite recursion between pp_c_primary_expression ()
1566 and pp_c_expression (). */
1568 pp_c_expression (c_pretty_printer
*pp
, tree e
)
1570 switch (TREE_CODE (e
))
1573 pp_c_integer_constant (pp
, e
);
1577 pp_c_floating_constant (pp
, e
);
1581 pp_c_string_literal (pp
, e
);
1584 case IDENTIFIER_NODE
:
1594 pp_primary_expression (pp
, e
);
1597 case POSTINCREMENT_EXPR
:
1598 case POSTDECREMENT_EXPR
:
1608 case COMPOUND_LITERAL_EXPR
:
1611 pp_postfix_expression (pp
, e
);
1619 case TRUTH_NOT_EXPR
:
1620 case PREINCREMENT_EXPR
:
1621 case PREDECREMENT_EXPR
:
1626 pp_c_unary_expression (pp
, e
);
1630 case FIX_TRUNC_EXPR
:
1632 pp_c_cast_expression (pp
, e
);
1636 case TRUNC_MOD_EXPR
:
1637 case TRUNC_DIV_EXPR
:
1638 pp_multiplicative_expression (pp
, e
);
1643 pp_c_shift_expression (pp
, e
);
1650 pp_c_relational_expression (pp
, e
);
1654 pp_c_and_expression (pp
, e
);
1658 pp_c_exclusive_or_expression (pp
, e
);
1662 pp_c_inclusive_or_expression (pp
, e
);
1665 case TRUTH_ANDIF_EXPR
:
1666 pp_c_logical_and_expression (pp
, e
);
1669 case TRUTH_ORIF_EXPR
:
1670 pp_c_logical_or_expression (pp
, e
);
1675 pp_c_equality_expression (pp
, e
);
1679 pp_conditional_expression (pp
, e
);
1684 pp_c_additive_expression (pp
, e
);
1689 pp_assignment_expression (pp
, e
);
1693 pp_c_left_paren (pp
);
1694 pp_expression (pp
, TREE_OPERAND (e
, 0));
1695 pp_separate_with (pp
, ',');
1696 pp_assignment_expression (pp
, TREE_OPERAND (e
, 1));
1697 pp_c_right_paren (pp
);
1701 case NON_LVALUE_EXPR
:
1704 pp_expression (pp
, TREE_OPERAND (e
, 0));
1708 pp_postfix_expression (pp
, TREE_OPERAND (e
, 1));
1712 pp_unsupported_tree (pp
, e
);
1724 expression-statement
1729 pp_c_statement (c_pretty_printer
*pp
, tree stmt
)
1731 enum tree_code code
;
1736 code
= TREE_CODE (stmt
);
1739 /* labeled-statement:
1740 identifier : statement
1741 case constant-expression : statement
1742 default : statement */
1745 if (pp_needs_newline (pp
))
1746 pp_newline_and_indent (pp
, -3);
1748 pp_indentation (pp
) -= 3;
1749 if (code
== LABEL_STMT
)
1750 pp_tree_identifier (pp
, DECL_NAME (LABEL_STMT_LABEL (stmt
)));
1751 else if (code
== CASE_LABEL
)
1753 if (CASE_LOW (stmt
) == NULL_TREE
)
1754 pp_identifier (pp
, "default");
1757 pp_c_identifier (pp
, "case");
1758 pp_c_whitespace (pp
);
1759 pp_conditional_expression (pp
, CASE_LOW (stmt
));
1760 if (CASE_HIGH (stmt
))
1762 pp_identifier (pp
, "...");
1763 pp_conditional_expression (pp
, CASE_HIGH (stmt
));
1768 pp_indentation (pp
) += 3;
1769 pp_needs_newline (pp
) = true;
1772 /* coumpound-statement:
1773 { block-item-list(opt) }
1777 block-item-list block-item
1783 if (pp_needs_newline (pp
))
1784 pp_newline_and_indent (pp
, 0);
1785 pp_c_left_brace (pp
);
1786 pp_newline_and_indent (pp
, 3);
1787 for (stmt
= COMPOUND_BODY (stmt
); stmt
; stmt
= TREE_CHAIN (stmt
))
1788 pp_statement (pp
, stmt
);
1789 pp_newline_and_indent (pp
, -3);
1790 pp_c_right_brace (pp
);
1791 pp_needs_newline (pp
) = true;
1794 /* expression-statement:
1795 expression(opt) ; */
1798 if (pp_needs_newline (pp
))
1799 pp_newline_and_indent (pp
, 0);
1801 tree e
= code
== EXPR_STMT
1802 ? EXPR_STMT_EXPR (stmt
)
1803 : CLEANUP_EXPR (stmt
);
1805 pp_expression (pp
, e
);
1807 pp_c_semicolon (pp
);
1808 pp_needs_newline (pp
) = true;
1811 /* selection-statement:
1812 if ( expression ) statement
1813 if ( expression ) statement else statement
1814 switch ( expression ) statement */
1816 if (pp_needs_newline (pp
))
1817 pp_newline_and_indent (pp
, 0);
1818 pp_c_identifier (pp
, "if");
1819 pp_c_whitespace (pp
);
1820 pp_c_left_paren (pp
);
1821 pp_expression (pp
, IF_COND (stmt
));
1822 pp_c_right_paren (pp
);
1823 pp_newline_and_indent (pp
, 3);
1824 pp_statement (pp
, THEN_CLAUSE (stmt
));
1825 pp_newline_and_indent (pp
, -3);
1826 if (ELSE_CLAUSE (stmt
))
1828 tree else_clause
= ELSE_CLAUSE (stmt
);
1829 pp_c_identifier (pp
, "else");
1830 if (TREE_CODE (else_clause
) == IF_STMT
)
1831 pp_c_whitespace (pp
);
1833 pp_newline_and_indent (pp
, 3);
1834 pp_statement (pp
, else_clause
);
1835 if (TREE_CODE (else_clause
) != IF_STMT
)
1836 pp_newline_and_indent (pp
, -3);
1841 if (pp_needs_newline (pp
))
1842 pp_newline_and_indent (pp
, 0);
1843 pp_c_identifier (pp
, "switch");
1845 pp_c_left_paren (pp
);
1846 pp_expression (pp
, SWITCH_COND (stmt
));
1847 pp_c_right_paren (pp
);
1848 pp_indentation (pp
) += 3;
1849 pp_needs_newline (pp
) = true;
1850 pp_statement (pp
, SWITCH_BODY (stmt
));
1851 pp_newline_and_indent (pp
, -3);
1854 /* iteration-statement:
1855 while ( expression ) statement
1856 do statement while ( expression ) ;
1857 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1858 for ( declaration expression(opt) ; expression(opt) ) statement */
1860 if (pp_needs_newline (pp
))
1861 pp_newline_and_indent (pp
, 0);
1862 pp_c_identifier (pp
, "while");
1864 pp_c_left_paren (pp
);
1865 pp_expression (pp
, WHILE_COND (stmt
));
1866 pp_c_right_paren (pp
);
1867 pp_newline_and_indent (pp
, 3);
1868 pp_statement (pp
, WHILE_BODY (stmt
));
1869 pp_indentation (pp
) -= 3;
1870 pp_needs_newline (pp
) = true;
1874 if (pp_needs_newline (pp
))
1875 pp_newline_and_indent (pp
, 0);
1876 pp_c_identifier (pp
, "do");
1877 pp_newline_and_indent (pp
, 3);
1878 pp_statement (pp
, DO_BODY (stmt
));
1879 pp_newline_and_indent (pp
, -3);
1880 pp_c_identifier (pp
, "while");
1882 pp_c_left_paren (pp
);
1883 pp_expression (pp
, DO_COND (stmt
));
1884 pp_c_right_paren (pp
);
1885 pp_c_semicolon (pp
);
1886 pp_needs_newline (pp
) = true;
1890 if (pp_needs_newline (pp
))
1891 pp_newline_and_indent (pp
, 0);
1892 pp_c_identifier (pp
, "for");
1894 pp_c_left_paren (pp
);
1895 if (FOR_INIT_STMT (stmt
))
1896 pp_statement (pp
, FOR_INIT_STMT (stmt
));
1898 pp_c_semicolon (pp
);
1899 pp_needs_newline (pp
) = false;
1900 pp_c_whitespace (pp
);
1901 if (FOR_COND (stmt
))
1902 pp_expression (pp
, FOR_COND (stmt
));
1903 pp_c_semicolon (pp
);
1904 pp_needs_newline (pp
) = false;
1905 pp_c_whitespace (pp
);
1906 if (FOR_EXPR (stmt
))
1907 pp_expression (pp
, FOR_EXPR (stmt
));
1908 pp_c_right_paren (pp
);
1909 pp_newline_and_indent (pp
, 3);
1910 pp_statement (pp
, FOR_BODY (stmt
));
1911 pp_indentation (pp
) -= 3;
1912 pp_needs_newline (pp
) = true;
1918 return expression(opt) ; */
1921 if (pp_needs_newline (pp
))
1922 pp_newline_and_indent (pp
, 0);
1923 pp_identifier (pp
, code
== BREAK_STMT
? "break" : "continue");
1924 pp_c_semicolon (pp
);
1925 pp_needs_newline (pp
) = true;
1931 tree e
= code
== RETURN_STMT
1932 ? RETURN_STMT_EXPR (stmt
)
1933 : GOTO_DESTINATION (stmt
);
1934 if (pp_needs_newline (pp
))
1935 pp_newline_and_indent (pp
, 0);
1936 pp_c_identifier (pp
, code
== RETURN_STMT
? "return" : "goto");
1937 pp_c_whitespace (pp
);
1940 if (TREE_CODE (e
) == INIT_EXPR
1941 && TREE_CODE (TREE_OPERAND (e
, 0)) == RESULT_DECL
)
1942 e
= TREE_OPERAND (e
, 1);
1943 pp_expression (pp
, e
);
1945 pp_c_semicolon (pp
);
1946 pp_needs_newline (pp
) = true;
1951 if (!SCOPE_NULLIFIED_P (stmt
) && SCOPE_NO_CLEANUPS_P (stmt
))
1954 if (pp_needs_newline (pp
))
1955 pp_newline_and_indent (pp
, 0);
1956 if (SCOPE_BEGIN_P (stmt
))
1961 else if (SCOPE_END_P (stmt
))
1963 pp_right_brace (pp
);
1966 pp_indentation (pp
) += i
;
1967 pp_needs_newline (pp
) = true;
1972 if (pp_needs_newline (pp
))
1973 pp_newline_and_indent (pp
, 0);
1974 pp_declaration (pp
, DECL_STMT_DECL (stmt
));
1975 pp_needs_newline (pp
) = true;
1980 bool has_volatile_p
= ASM_VOLATILE_P (stmt
);
1981 bool is_extended
= has_volatile_p
|| ASM_INPUTS (stmt
)
1982 || ASM_OUTPUTS (stmt
) || ASM_CLOBBERS (stmt
);
1983 pp_c_identifier (pp
, is_extended
? "__asm__" : "asm");
1985 pp_c_identifier (pp
, "__volatile__");
1987 pp_c_left_paren (pp
);
1988 pp_c_string_literal (pp
, ASM_STRING (stmt
));
1992 pp_separate_with (pp
, ':');
1993 if (ASM_OUTPUTS (stmt
))
1994 pp_expression (pp
, ASM_OUTPUTS (stmt
));
1996 pp_separate_with (pp
, ':');
1997 if (ASM_INPUTS (stmt
))
1998 pp_expression (pp
, ASM_INPUTS (stmt
));
2000 pp_separate_with (pp
, ':');
2001 if (ASM_CLOBBERS (stmt
))
2002 pp_expression (pp
, ASM_CLOBBERS (stmt
));
2004 pp_c_right_paren (pp
);
2010 pp_c_identifier (pp
, "__FILE__");
2013 pp_c_whitespace (pp
);
2014 pp_c_identifier (pp
, FILE_STMT_FILENAME (stmt
));
2015 pp_c_semicolon (pp
);
2016 pp_needs_newline (pp
) = true;
2020 pp_unsupported_tree (pp
, stmt
);
2025 /* Initialize the PRETTY-PRINTER for handling C codes. */
2027 pp_c_pretty_printer_init (c_pretty_printer
*pp
)
2029 pp
->offset_list
= 0;
2031 pp
->declaration
= pp_c_declaration
;
2032 pp
->declaration_specifiers
= pp_c_declaration_specifiers
;
2033 pp
->declarator
= pp_c_declarator
;
2034 pp
->direct_declarator
= pp_c_direct_declarator
;
2035 pp
->type_specifier_seq
= pp_c_specifier_qualifier_list
;
2036 pp
->abstract_declarator
= pp_c_abstract_declarator
;
2037 pp
->direct_abstract_declarator
= pp_c_direct_abstract_declarator
;
2038 pp
->ptr_operator
= pp_c_pointer
;
2039 pp
->parameter_list
= pp_c_parameter_type_list
;
2040 pp
->type_id
= pp_c_type_id
;
2041 pp
->simple_type_specifier
= pp_c_type_specifier
;
2042 pp
->function_specifier
= pp_c_function_specifier
;
2043 pp
->storage_class_specifier
= pp_c_storage_class_specifier
;
2045 pp
->statement
= pp_c_statement
;
2047 pp
->id_expression
= pp_c_id_expression
;
2048 pp
->primary_expression
= pp_c_primary_expression
;
2049 pp
->postfix_expression
= pp_c_postfix_expression
;
2050 pp
->unary_expression
= pp_c_unary_expression
;
2051 pp
->initializer
= pp_c_initializer
;
2052 pp
->multiplicative_expression
= pp_c_multiplicative_expression
;
2053 pp
->conditional_expression
= pp_c_conditional_expression
;
2054 pp
->assignment_expression
= pp_c_assignment_expression
;
2055 pp
->expression
= pp_c_expression
;