1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
27 #include "fixed-value.h"
28 #include "c-pretty-print.h"
30 #include "tree-iterator.h"
31 #include "diagnostic.h"
33 /* The pretty-printer code is primarily designed to closely follow
34 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
35 codes we used to have in the past. Following a structured
36 approach (preferably the official grammars) is believed to make it
37 much easier to add extensions and nifty pretty-printing effects that
38 takes expression or declaration contexts into account. */
41 #define pp_c_maybe_whitespace(PP) \
43 if (pp_base (PP)->padding == pp_before) \
44 pp_c_whitespace (PP); \
48 static void pp_c_char (c_pretty_printer *, int);
50 /* postfix-expression */
51 static void pp_c_initializer_list (c_pretty_printer *, tree);
52 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer *, tree);
54 static void pp_c_multiplicative_expression (c_pretty_printer *, tree);
55 static void pp_c_additive_expression (c_pretty_printer *, tree);
56 static void pp_c_shift_expression (c_pretty_printer *, tree);
57 static void pp_c_relational_expression (c_pretty_printer *, tree);
58 static void pp_c_equality_expression (c_pretty_printer *, tree);
59 static void pp_c_and_expression (c_pretty_printer *, tree);
60 static void pp_c_exclusive_or_expression (c_pretty_printer *, tree);
61 static void pp_c_inclusive_or_expression (c_pretty_printer *, tree);
62 static void pp_c_logical_and_expression (c_pretty_printer *, tree);
63 static void pp_c_conditional_expression (c_pretty_printer *, tree);
64 static void pp_c_assignment_expression (c_pretty_printer *, tree);
69 /* Helper functions. */
72 pp_c_whitespace (c_pretty_printer *pp)
75 pp_base (pp)->padding = pp_none;
79 pp_c_left_paren (c_pretty_printer *pp)
82 pp_base (pp)->padding = pp_none;
86 pp_c_right_paren (c_pretty_printer *pp)
89 pp_base (pp)->padding = pp_none;
93 pp_c_left_brace (c_pretty_printer *pp)
96 pp_base (pp)->padding = pp_none;
100 pp_c_right_brace (c_pretty_printer *pp)
103 pp_base (pp)->padding = pp_none;
107 pp_c_left_bracket (c_pretty_printer *pp)
109 pp_left_bracket (pp);
110 pp_base (pp)->padding = pp_none;
114 pp_c_right_bracket (c_pretty_printer *pp)
116 pp_right_bracket (pp);
117 pp_base (pp)->padding = pp_none;
121 pp_c_dot (c_pretty_printer *pp)
124 pp_base (pp)->padding = pp_none;
128 pp_c_ampersand (c_pretty_printer *pp)
131 pp_base (pp)->padding = pp_none;
135 pp_c_star (c_pretty_printer *pp)
138 pp_base (pp)->padding = pp_none;
142 pp_c_arrow (c_pretty_printer *pp)
145 pp_base (pp)->padding = pp_none;
149 pp_c_semicolon (c_pretty_printer *pp)
152 pp_base (pp)->padding = pp_none;
156 pp_c_complement (c_pretty_printer *pp)
159 pp_base (pp)->padding = pp_none;
163 pp_c_exclamation (c_pretty_printer *pp)
166 pp_base (pp)->padding = pp_none;
169 /* Print out the external representation of CV-QUALIFIER. */
172 pp_c_cv_qualifier (c_pretty_printer *pp, const char *cv)
174 const char *p = pp_last_position_in_text (pp);
175 /* The C programming language does not have references, but it is much
176 simpler to handle those here rather than going through the same
177 logic in the C++ pretty-printer. */
178 if (p != NULL && (*p == '*' || *p == '&'))
179 pp_c_whitespace (pp);
180 pp_c_identifier (pp, cv);
183 /* Pretty-print T using the type-cast notation '( type-name )'. */
186 pp_c_type_cast (c_pretty_printer *pp, tree t)
188 pp_c_left_paren (pp);
190 pp_c_right_paren (pp);
193 /* We're about to pretty-print a pointer type as indicated by T.
194 Output a whitespace, if needed, preparing for subsequent output. */
197 pp_c_space_for_pointer_operator (c_pretty_printer *pp, tree t)
199 if (POINTER_TYPE_P (t))
201 tree pointee = strip_pointer_operator (TREE_TYPE (t));
202 if (TREE_CODE (pointee) != ARRAY_TYPE
203 && TREE_CODE (pointee) != FUNCTION_TYPE)
204 pp_c_whitespace (pp);
211 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
212 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
213 of its type. Take care of possible extensions.
217 type-qualifier-list type-qualifier
222 __restrict__ -- GNU C
226 pp_c_type_qualifier_list (c_pretty_printer *pp, tree t)
230 if (!t || t == error_mark_node)
236 qualifiers = TYPE_QUALS (t);
237 if (qualifiers & TYPE_QUAL_CONST)
238 pp_c_cv_qualifier (pp, "const");
239 if (qualifiers & TYPE_QUAL_VOLATILE)
240 pp_c_cv_qualifier (pp, "volatile");
241 if (qualifiers & TYPE_QUAL_RESTRICT)
242 pp_c_cv_qualifier (pp, flag_isoc99 ? "restrict" : "__restrict__");
246 * type-qualifier-list(opt)
247 * type-qualifier-list(opt) pointer */
250 pp_c_pointer (c_pretty_printer *pp, tree t)
252 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
254 switch (TREE_CODE (t))
257 /* It is easier to handle C++ reference types here. */
259 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
260 pp_c_pointer (pp, TREE_TYPE (t));
261 if (TREE_CODE (t) == POINTER_TYPE)
265 pp_c_type_qualifier_list (pp, t);
268 /* ??? This node is now in GENERIC and so shouldn't be here. But
269 we'll fix that later. */
271 pp_declaration (pp, DECL_EXPR_DECL (t));
272 pp_needs_newline (pp) = true;
276 pp_unsupported_tree (pp, t);
293 struct-or-union-specifier
298 simple-type-specifier:
303 pp_c_type_specifier (c_pretty_printer *pp, tree t)
305 const enum tree_code code = TREE_CODE (t);
309 pp_c_identifier (pp, "<type-error>");
312 case IDENTIFIER_NODE:
313 pp_c_tree_decl_identifier (pp, t);
320 case FIXED_POINT_TYPE:
324 pp_c_type_specifier (pp, t);
328 int prec = TYPE_PRECISION (t);
329 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t)))
330 t = c_common_type_for_mode (TYPE_MODE (t), TYPE_SATURATING (t));
332 t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t));
335 pp_c_type_specifier (pp, t);
336 if (TYPE_PRECISION (t) != prec)
339 pp_decimal_int (pp, prec);
347 pp_string (pp, (TYPE_UNSIGNED (t)
348 ? "<unnamed-unsigned:"
349 : "<unnamed-signed:"));
352 pp_string (pp, "<unnamed-float:");
354 case FIXED_POINT_TYPE:
355 pp_string (pp, "<unnamed-fixed:");
360 pp_decimal_int (pp, prec);
368 pp_id_expression (pp, t);
370 pp_c_identifier (pp, "<typedef-error>");
376 if (code == UNION_TYPE)
377 pp_c_identifier (pp, "union");
378 else if (code == RECORD_TYPE)
379 pp_c_identifier (pp, "struct");
380 else if (code == ENUMERAL_TYPE)
381 pp_c_identifier (pp, "enum");
383 pp_c_identifier (pp, "<tag-error>");
386 pp_id_expression (pp, TYPE_NAME (t));
388 pp_c_identifier (pp, "<anonymous>");
392 pp_unsupported_tree (pp, t);
397 /* specifier-qualifier-list:
398 type-specifier specifier-qualifier-list-opt
399 type-qualifier specifier-qualifier-list-opt
402 Implementation note: Because of the non-linearities in array or
403 function declarations, this routine prints not just the
404 specifier-qualifier-list of such entities or types of such entities,
405 but also the 'pointer' production part of their declarators. The
406 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
409 pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree t)
411 const enum tree_code code = TREE_CODE (t);
413 if (TREE_CODE (t) != POINTER_TYPE)
414 pp_c_type_qualifier_list (pp, t);
420 /* Get the types-specifier of this type. */
421 tree pointee = strip_pointer_operator (TREE_TYPE (t));
422 pp_c_specifier_qualifier_list (pp, pointee);
423 if (TREE_CODE (pointee) == ARRAY_TYPE
424 || TREE_CODE (pointee) == FUNCTION_TYPE)
426 pp_c_whitespace (pp);
427 pp_c_left_paren (pp);
429 else if (!c_dialect_cxx ())
430 pp_c_whitespace (pp);
431 pp_ptr_operator (pp, t);
437 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
442 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
443 if (code == COMPLEX_TYPE)
444 pp_c_identifier (pp, flag_isoc99 ? "_Complex" : "__complex__");
445 else if (code == VECTOR_TYPE)
446 pp_c_identifier (pp, "__vector__");
450 pp_simple_type_specifier (pp, t);
455 /* parameter-type-list:
460 parameter-declaration
461 parameter-list , parameter-declaration
463 parameter-declaration:
464 declaration-specifiers declarator
465 declaration-specifiers abstract-declarator(opt) */
468 pp_c_parameter_type_list (c_pretty_printer *pp, tree t)
470 bool want_parm_decl = DECL_P (t) && !(pp->flags & pp_c_flag_abstract);
471 tree parms = want_parm_decl ? DECL_ARGUMENTS (t) : TYPE_ARG_TYPES (t);
472 pp_c_left_paren (pp);
473 if (parms == void_list_node)
474 pp_c_identifier (pp, "void");
478 for ( ; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
481 pp_separate_with (pp, ',');
483 pp_declaration_specifiers
484 (pp, want_parm_decl ? parms : TREE_VALUE (parms));
486 pp_declarator (pp, parms);
488 pp_abstract_declarator (pp, TREE_VALUE (parms));
491 pp_c_right_paren (pp);
494 /* abstract-declarator:
496 pointer(opt) direct-abstract-declarator */
499 pp_c_abstract_declarator (c_pretty_printer *pp, tree t)
501 if (TREE_CODE (t) == POINTER_TYPE)
503 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
504 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
505 pp_c_right_paren (pp);
509 pp_direct_abstract_declarator (pp, t);
512 /* direct-abstract-declarator:
513 ( abstract-declarator )
514 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
515 direct-abstract-declarator(opt) [ * ]
516 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
519 pp_c_direct_abstract_declarator (c_pretty_printer *pp, tree t)
521 switch (TREE_CODE (t))
524 pp_abstract_declarator (pp, t);
528 pp_c_parameter_type_list (pp, t);
529 pp_direct_abstract_declarator (pp, TREE_TYPE (t));
533 pp_c_left_bracket (pp);
534 if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t)))
536 tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (t));
537 tree type = TREE_TYPE (maxval);
539 if (host_integerp (maxval, 0))
540 pp_wide_integer (pp, tree_low_cst (maxval, 0) + 1);
542 pp_expression (pp, fold_build2 (PLUS_EXPR, type, maxval,
543 build_int_cst (type, 1)));
545 pp_c_right_bracket (pp);
546 pp_direct_abstract_declarator (pp, TREE_TYPE (t));
549 case IDENTIFIER_NODE:
554 case FIXED_POINT_TYPE:
564 pp_unsupported_tree (pp, t);
570 specifier-qualifier-list abstract-declarator(opt) */
573 pp_c_type_id (c_pretty_printer *pp, tree t)
575 pp_c_specifier_qualifier_list (pp, t);
576 pp_abstract_declarator (pp, t);
579 /* storage-class-specifier:
587 pp_c_storage_class_specifier (c_pretty_printer *pp, tree t)
589 if (TREE_CODE (t) == TYPE_DECL)
590 pp_c_identifier (pp, "typedef");
593 if (DECL_REGISTER (t))
594 pp_c_identifier (pp, "register");
595 else if (TREE_STATIC (t) && TREE_CODE (t) == VAR_DECL)
596 pp_c_identifier (pp, "static");
600 /* function-specifier:
604 pp_c_function_specifier (c_pretty_printer *pp, tree t)
606 if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t))
607 pp_c_identifier (pp, "inline");
610 /* declaration-specifiers:
611 storage-class-specifier declaration-specifiers(opt)
612 type-specifier declaration-specifiers(opt)
613 type-qualifier declaration-specifiers(opt)
614 function-specifier declaration-specifiers(opt) */
617 pp_c_declaration_specifiers (c_pretty_printer *pp, tree t)
619 pp_storage_class_specifier (pp, t);
620 pp_function_specifier (pp, t);
621 pp_c_specifier_qualifier_list (pp, DECL_P (t) ? TREE_TYPE (t) : t);
627 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
628 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
629 direct-declarator [ type-qualifier-list static assignment-expression ]
630 direct-declarator [ type-qualifier-list * ]
631 direct-declarator ( parameter-type-list )
632 direct-declarator ( identifier-list(opt) ) */
635 pp_c_direct_declarator (c_pretty_printer *pp, tree t)
637 switch (TREE_CODE (t))
644 pp_c_space_for_pointer_operator (pp, TREE_TYPE (t));
645 pp_c_tree_decl_identifier (pp, t);
650 pp_abstract_declarator (pp, TREE_TYPE (t));
654 pp_parameter_list (pp, t);
655 pp_abstract_declarator (pp, TREE_TYPE (t));
659 pp_c_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
660 pp_c_tree_decl_identifier (pp, t);
661 if (pp_c_base (pp)->flags & pp_c_flag_abstract)
662 pp_abstract_declarator (pp, TREE_TYPE (t));
665 pp_parameter_list (pp, t);
666 pp_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t)));
672 case FIXED_POINT_TYPE:
679 pp_unsupported_tree (pp, t);
686 pointer(opt) direct-declarator */
689 pp_c_declarator (c_pretty_printer *pp, tree t)
691 switch (TREE_CODE (t))
695 case FIXED_POINT_TYPE:
708 pp_direct_declarator (pp, t);
713 pp_unsupported_tree (pp, t);
719 declaration-specifiers init-declarator-list(opt) ; */
722 pp_c_declaration (c_pretty_printer *pp, tree t)
724 pp_declaration_specifiers (pp, t);
725 pp_c_init_declarator (pp, t);
728 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
731 pp_c_attributes (c_pretty_printer *pp, tree attributes)
733 if (attributes == NULL_TREE)
736 pp_c_identifier (pp, "__attribute__");
737 pp_c_left_paren (pp);
738 pp_c_left_paren (pp);
739 for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes))
741 pp_tree_identifier (pp, TREE_PURPOSE (attributes));
742 if (TREE_VALUE (attributes))
743 pp_c_call_argument_list (pp, TREE_VALUE (attributes));
745 if (TREE_CHAIN (attributes))
746 pp_separate_with (pp, ',');
748 pp_c_right_paren (pp);
749 pp_c_right_paren (pp);
752 /* function-definition:
753 declaration-specifiers declarator compound-statement */
756 pp_c_function_definition (c_pretty_printer *pp, tree t)
758 pp_declaration_specifiers (pp, t);
759 pp_declarator (pp, t);
760 pp_needs_newline (pp) = true;
761 pp_statement (pp, DECL_SAVED_TREE (t));
769 /* Print out a c-char. This is called solely for characters which are
770 in the *target* execution character set. We ought to convert them
771 back to the *host* execution character set before printing, but we
772 have no way to do this at present. A decent compromise is to print
773 all characters as if they were in the host execution character set,
774 and not attempt to recover any named escape characters, but render
775 all unprintables as octal escapes. If the host and target character
776 sets are the same, this produces relatively readable output. If they
777 are not the same, strings may appear as gibberish, but that's okay
778 (in fact, it may well be what the reader wants, e.g. if they are looking
779 to see if conversion to the target character set happened correctly).
781 A special case: we need to prefix \, ", and ' with backslashes. It is
782 correct to do so for the *host*'s \, ", and ', because the rest of the
783 file appears in the host character set. */
786 pp_c_char (c_pretty_printer *pp, int c)
792 case '\\': pp_string (pp, "\\\\"); break;
793 case '\'': pp_string (pp, "\\\'"); break;
794 case '\"': pp_string (pp, "\\\""); break;
795 default: pp_character (pp, c);
799 pp_scalar (pp, "\\%03o", (unsigned) c);
802 /* Print out a STRING literal. */
805 pp_c_string_literal (c_pretty_printer *pp, tree s)
807 const char *p = TREE_STRING_POINTER (s);
808 int n = TREE_STRING_LENGTH (s) - 1;
811 for (i = 0; i < n; ++i)
812 pp_c_char (pp, p[i]);
816 /* Pretty-print an INTEGER literal. */
819 pp_c_integer_constant (c_pretty_printer *pp, tree i)
821 tree type = TREE_TYPE (i);
823 if (TREE_INT_CST_HIGH (i) == 0)
824 pp_wide_integer (pp, TREE_INT_CST_LOW (i));
827 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (i);
828 HOST_WIDE_INT high = TREE_INT_CST_HIGH (i);
829 if (tree_int_cst_sgn (i) < 0)
831 pp_character (pp, '-');
835 sprintf (pp_buffer (pp)->digit_buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
836 (unsigned HOST_WIDE_INT) high, (unsigned HOST_WIDE_INT) low);
837 pp_string (pp, pp_buffer (pp)->digit_buffer);
839 if (TYPE_UNSIGNED (type))
840 pp_character (pp, 'u');
841 if (type == long_integer_type_node || type == long_unsigned_type_node)
842 pp_character (pp, 'l');
843 else if (type == long_long_integer_type_node
844 || type == long_long_unsigned_type_node)
845 pp_string (pp, "ll");
848 /* Print out a CHARACTER literal. */
851 pp_c_character_constant (c_pretty_printer *pp, tree c)
853 tree type = TREE_TYPE (c);
854 if (type == wchar_type_node)
855 pp_character (pp, 'L');
857 if (host_integerp (c, TYPE_UNSIGNED (type)))
858 pp_c_char (pp, tree_low_cst (c, TYPE_UNSIGNED (type)));
860 pp_scalar (pp, "\\x%x", (unsigned) TREE_INT_CST_LOW (c));
864 /* Print out a BOOLEAN literal. */
867 pp_c_bool_constant (c_pretty_printer *pp, tree b)
869 if (b == boolean_false_node)
871 if (c_dialect_cxx ())
872 pp_c_identifier (pp, "false");
873 else if (flag_isoc99)
874 pp_c_identifier (pp, "_False");
876 pp_unsupported_tree (pp, b);
878 else if (b == boolean_true_node)
880 if (c_dialect_cxx ())
881 pp_c_identifier (pp, "true");
882 else if (flag_isoc99)
883 pp_c_identifier (pp, "_True");
885 pp_unsupported_tree (pp, b);
887 else if (TREE_CODE (b) == INTEGER_CST)
888 pp_c_integer_constant (pp, b);
890 pp_unsupported_tree (pp, b);
893 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
894 false; that means the value was obtained by a cast, in which case
895 print out the type-id part of the cast-expression -- the casted value
896 is then printed by pp_c_integer_literal. */
899 pp_c_enumeration_constant (c_pretty_printer *pp, tree e)
901 bool value_is_named = true;
902 tree type = TREE_TYPE (e);
905 /* Find the name of this constant. */
906 for (value = TYPE_VALUES (type);
907 value != NULL_TREE && !tree_int_cst_equal (TREE_VALUE (value), e);
908 value = TREE_CHAIN (value))
911 if (value != NULL_TREE)
912 pp_id_expression (pp, TREE_PURPOSE (value));
915 /* Value must have been cast. */
916 pp_c_type_cast (pp, type);
917 value_is_named = false;
920 return value_is_named;
923 /* Print out a REAL value as a decimal-floating-constant. */
926 pp_c_floating_constant (c_pretty_printer *pp, tree r)
928 real_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_REAL_CST (r),
929 sizeof (pp_buffer (pp)->digit_buffer), 0, 1);
930 pp_string (pp, pp_buffer(pp)->digit_buffer);
931 if (TREE_TYPE (r) == float_type_node)
932 pp_character (pp, 'f');
933 else if (TREE_TYPE (r) == long_double_type_node)
934 pp_character (pp, 'l');
935 else if (TREE_TYPE (r) == dfloat128_type_node)
936 pp_string (pp, "dl");
937 else if (TREE_TYPE (r) == dfloat64_type_node)
938 pp_string (pp, "dd");
939 else if (TREE_TYPE (r) == dfloat32_type_node)
940 pp_string (pp, "df");
943 /* Print out a FIXED value as a decimal-floating-constant. */
946 pp_c_fixed_constant (c_pretty_printer *pp, tree r)
948 fixed_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_FIXED_CST (r),
949 sizeof (pp_buffer (pp)->digit_buffer));
950 pp_string (pp, pp_buffer(pp)->digit_buffer);
953 /* Pretty-print a compound literal expression. GNU extensions include
957 pp_c_compound_literal (c_pretty_printer *pp, tree e)
959 tree type = TREE_TYPE (e);
960 pp_c_type_cast (pp, type);
962 switch (TREE_CODE (type))
969 pp_c_brace_enclosed_initializer_list (pp, e);
973 pp_unsupported_tree (pp, e);
978 /* Pretty-print a COMPLEX_EXPR expression. */
981 pp_c_complex_expr (c_pretty_printer *pp, tree e)
983 /* Handle a few common special cases, otherwise fallback
984 to printing it as compound literal. */
985 tree type = TREE_TYPE (e);
986 tree realexpr = TREE_OPERAND (e, 0);
987 tree imagexpr = TREE_OPERAND (e, 1);
989 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
990 if (TREE_CODE (realexpr) == NOP_EXPR
991 && TREE_CODE (imagexpr) == NOP_EXPR
992 && TREE_TYPE (realexpr) == TREE_TYPE (type)
993 && TREE_TYPE (imagexpr) == TREE_TYPE (type)
994 && TREE_CODE (TREE_OPERAND (realexpr, 0)) == REALPART_EXPR
995 && TREE_CODE (TREE_OPERAND (imagexpr, 0)) == IMAGPART_EXPR
996 && TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0)
997 == TREE_OPERAND (TREE_OPERAND (imagexpr, 0), 0))
999 pp_c_type_cast (pp, type);
1000 pp_expression (pp, TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0));
1004 /* Cast of an scalar expression to COMPLEX_TYPE. */
1005 if ((integer_zerop (imagexpr) || real_zerop (imagexpr))
1006 && TREE_TYPE (realexpr) == TREE_TYPE (type))
1008 pp_c_type_cast (pp, type);
1009 if (TREE_CODE (realexpr) == NOP_EXPR)
1010 realexpr = TREE_OPERAND (realexpr, 0);
1011 pp_expression (pp, realexpr);
1015 pp_c_compound_literal (pp, e);
1021 fixed-point-constant
1022 enumeration-constant
1023 character-constant */
1026 pp_c_constant (c_pretty_printer *pp, tree e)
1028 const enum tree_code code = TREE_CODE (e);
1034 tree type = TREE_TYPE (e);
1035 if (type == boolean_type_node)
1036 pp_c_bool_constant (pp, e);
1037 else if (type == char_type_node)
1038 pp_c_character_constant (pp, e);
1039 else if (TREE_CODE (type) == ENUMERAL_TYPE
1040 && pp_c_enumeration_constant (pp, e))
1043 pp_c_integer_constant (pp, e);
1048 pp_c_floating_constant (pp, e);
1052 pp_c_fixed_constant (pp, e);
1056 pp_c_string_literal (pp, e);
1060 /* Sometimes, we are confused and we think a complex literal
1061 is a constant. Such thing is a compound literal which
1062 grammatically belongs to postfix-expr production. */
1063 pp_c_compound_literal (pp, e);
1067 pp_unsupported_tree (pp, e);
1072 /* Pretty-print an IDENTIFIER_NODE, preceded by whitespace is necessary. */
1075 pp_c_identifier (c_pretty_printer *pp, const char *id)
1077 pp_c_maybe_whitespace (pp);
1078 pp_identifier (pp, id);
1079 pp_base (pp)->padding = pp_before;
1082 /* Pretty-print a C primary-expression.
1090 pp_c_primary_expression (c_pretty_printer *pp, tree e)
1092 switch (TREE_CODE (e))
1100 pp_c_tree_decl_identifier (pp, e);
1103 case IDENTIFIER_NODE:
1104 pp_c_tree_identifier (pp, e);
1108 pp_c_identifier (pp, "<erroneous-expression>");
1112 pp_c_identifier (pp, "<return-value>");
1119 pp_c_constant (pp, e);
1123 pp_c_identifier (pp, "__builtin_memcpy");
1124 pp_c_left_paren (pp);
1126 pp_primary_expression (pp, TREE_OPERAND (e, 0));
1127 pp_separate_with (pp, ',');
1129 pp_initializer (pp, TREE_OPERAND (e, 1));
1130 if (TREE_OPERAND (e, 2))
1132 pp_separate_with (pp, ',');
1133 pp_c_expression (pp, TREE_OPERAND (e, 2));
1135 pp_c_right_paren (pp);
1139 /* FIXME: Make sure we won't get into an infinite loop. */
1140 pp_c_left_paren (pp);
1141 pp_expression (pp, e);
1142 pp_c_right_paren (pp);
1147 /* Print out a C initializer -- also support C compound-literals.
1149 assignment-expression:
1150 { initializer-list }
1151 { initializer-list , } */
1154 pp_c_initializer (c_pretty_printer *pp, tree e)
1156 if (TREE_CODE (e) == CONSTRUCTOR)
1157 pp_c_brace_enclosed_initializer_list (pp, e);
1159 pp_expression (pp, e);
1164 declarator = initializer */
1167 pp_c_init_declarator (c_pretty_printer *pp, tree t)
1169 pp_declarator (pp, t);
1170 /* We don't want to output function definitions here. There are handled
1171 elsewhere (and the syntactic form is bogus anyway). */
1172 if (TREE_CODE (t) != FUNCTION_DECL && DECL_INITIAL (t))
1174 tree init = DECL_INITIAL (t);
1175 /* This C++ bit is handled here because it is easier to do so.
1176 In templates, the C++ parser builds a TREE_LIST for a
1177 direct-initialization; the TREE_PURPOSE is the variable to
1178 initialize and the TREE_VALUE is the initializer. */
1179 if (TREE_CODE (init) == TREE_LIST)
1181 pp_c_left_paren (pp);
1182 pp_expression (pp, TREE_VALUE (init));
1183 pp_right_paren (pp);
1190 pp_c_initializer (pp, init);
1195 /* initializer-list:
1196 designation(opt) initializer
1197 initializer-list , designation(opt) initializer
1204 designator-list designator
1207 [ constant-expression ]
1211 pp_c_initializer_list (c_pretty_printer *pp, tree e)
1213 tree type = TREE_TYPE (e);
1214 const enum tree_code code = TREE_CODE (type);
1216 if (TREE_CODE (e) == CONSTRUCTOR)
1218 pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e));
1228 tree init = TREE_OPERAND (e, 0);
1229 for (; init != NULL_TREE; init = TREE_CHAIN (init))
1231 if (code == RECORD_TYPE || code == UNION_TYPE)
1234 pp_c_primary_expression (pp, TREE_PURPOSE (init));
1238 pp_c_left_bracket (pp);
1239 if (TREE_PURPOSE (init))
1240 pp_c_constant (pp, TREE_PURPOSE (init));
1241 pp_c_right_bracket (pp);
1243 pp_c_whitespace (pp);
1245 pp_c_whitespace (pp);
1246 pp_initializer (pp, TREE_VALUE (init));
1247 if (TREE_CHAIN (init))
1248 pp_separate_with (pp, ',');
1254 if (TREE_CODE (e) == VECTOR_CST)
1255 pp_c_expression_list (pp, TREE_VECTOR_CST_ELTS (e));
1261 if (TREE_CODE (e) == COMPLEX_CST || TREE_CODE (e) == COMPLEX_EXPR)
1263 const bool cst = TREE_CODE (e) == COMPLEX_CST;
1264 pp_expression (pp, cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0));
1265 pp_separate_with (pp, ',');
1266 pp_expression (pp, cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1));
1276 pp_unsupported_tree (pp, type);
1279 /* Pretty-print a brace-enclosed initializer-list. */
1282 pp_c_brace_enclosed_initializer_list (c_pretty_printer *pp, tree l)
1284 pp_c_left_brace (pp);
1285 pp_c_initializer_list (pp, l);
1286 pp_c_right_brace (pp);
1290 /* This is a convenient function, used to bridge gap between C and C++
1297 pp_c_id_expression (c_pretty_printer *pp, tree t)
1299 switch (TREE_CODE (t))
1308 pp_c_tree_decl_identifier (pp, t);
1311 case IDENTIFIER_NODE:
1312 pp_c_tree_identifier (pp, t);
1316 pp_unsupported_tree (pp, t);
1321 /* postfix-expression:
1323 postfix-expression [ expression ]
1324 postfix-expression ( argument-expression-list(opt) )
1325 postfix-expression . identifier
1326 postfix-expression -> identifier
1327 postfix-expression ++
1328 postfix-expression --
1329 ( type-name ) { initializer-list }
1330 ( type-name ) { initializer-list , } */
1333 pp_c_postfix_expression (c_pretty_printer *pp, tree e)
1335 enum tree_code code = TREE_CODE (e);
1338 case POSTINCREMENT_EXPR:
1339 case POSTDECREMENT_EXPR:
1340 pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1341 pp_identifier (pp, code == POSTINCREMENT_EXPR ? "++" : "--");
1345 pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1346 pp_c_left_bracket (pp);
1347 pp_expression (pp, TREE_OPERAND (e, 1));
1348 pp_c_right_bracket (pp);
1353 call_expr_arg_iterator iter;
1355 pp_postfix_expression (pp, CALL_EXPR_FN (e));
1356 pp_c_left_paren (pp);
1357 FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
1359 pp_expression (pp, arg);
1360 if (more_call_expr_args_p (&iter))
1361 pp_separate_with (pp, ',');
1363 pp_c_right_paren (pp);
1367 case UNORDERED_EXPR:
1368 pp_c_identifier (pp, flag_isoc99
1370 : "__builtin_isunordered");
1374 pp_c_identifier (pp, flag_isoc99
1376 : "!__builtin_isunordered");
1380 pp_c_identifier (pp, flag_isoc99
1382 : "!__builtin_isgreaterequal");
1386 pp_c_identifier (pp, flag_isoc99
1388 : "!__builtin_isgreater");
1392 pp_c_identifier (pp, flag_isoc99
1394 : "!__builtin_islessequal");
1398 pp_c_identifier (pp, flag_isoc99
1400 : "!__builtin_isless");
1404 pp_c_identifier (pp, flag_isoc99
1406 : "!__builtin_islessgreater");
1410 pp_c_identifier (pp, flag_isoc99
1412 : "__builtin_islessgreater");
1416 pp_c_left_paren (pp);
1417 pp_expression (pp, TREE_OPERAND (e, 0));
1418 pp_separate_with (pp, ',');
1419 pp_expression (pp, TREE_OPERAND (e, 1));
1420 pp_c_right_paren (pp);
1424 pp_c_identifier (pp, "__builtin_abs");
1425 pp_c_left_paren (pp);
1426 pp_expression (pp, TREE_OPERAND (e, 0));
1427 pp_c_right_paren (pp);
1432 tree object = TREE_OPERAND (e, 0);
1433 if (TREE_CODE (object) == INDIRECT_REF)
1435 pp_postfix_expression (pp, TREE_OPERAND (object, 0));
1440 pp_postfix_expression (pp, object);
1443 pp_expression (pp, TREE_OPERAND (e, 1));
1449 pp_c_compound_literal (pp, e);
1453 pp_c_complex_expr (pp, e);
1456 case COMPOUND_LITERAL_EXPR:
1457 e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e));
1460 pp_initializer (pp, e);
1464 pp_c_identifier (pp, "__builtin_va_arg");
1465 pp_c_left_paren (pp);
1466 pp_assignment_expression (pp, TREE_OPERAND (e, 0));
1467 pp_separate_with (pp, ',');
1468 pp_type_id (pp, TREE_TYPE (e));
1469 pp_c_right_paren (pp);
1473 if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
1475 pp_c_id_expression (pp, TREE_OPERAND (e, 0));
1478 /* else fall through. */
1481 pp_primary_expression (pp, e);
1486 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1489 pp_c_expression_list (c_pretty_printer *pp, tree e)
1491 for (; e != NULL_TREE; e = TREE_CHAIN (e))
1493 pp_expression (pp, TREE_VALUE (e));
1495 pp_separate_with (pp, ',');
1499 /* Print out V, which contains the elements of a constructor. */
1502 pp_c_constructor_elts (c_pretty_printer *pp, VEC(constructor_elt,gc) *v)
1504 unsigned HOST_WIDE_INT ix;
1507 FOR_EACH_CONSTRUCTOR_VALUE (v, ix, value)
1509 pp_expression (pp, value);
1510 if (ix != VEC_length (constructor_elt, v) - 1)
1511 pp_separate_with (pp, ',');
1515 /* Print out an expression-list in parens, as if it were the argument
1516 list to a function. */
1519 pp_c_call_argument_list (c_pretty_printer *pp, tree t)
1521 pp_c_left_paren (pp);
1522 if (t && TREE_CODE (t) == TREE_LIST)
1523 pp_c_expression_list (pp, t);
1524 pp_c_right_paren (pp);
1527 /* unary-expression:
1531 unary-operator cast-expression
1532 sizeof unary-expression
1535 unary-operator: one of
1540 __alignof__ unary-expression
1541 __alignof__ ( type-id )
1542 __real__ unary-expression
1543 __imag__ unary-expression */
1546 pp_c_unary_expression (c_pretty_printer *pp, tree e)
1548 enum tree_code code = TREE_CODE (e);
1551 case PREINCREMENT_EXPR:
1552 case PREDECREMENT_EXPR:
1553 pp_identifier (pp, code == PREINCREMENT_EXPR ? "++" : "--");
1554 pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
1561 case TRUTH_NOT_EXPR:
1563 /* String literal are used by address. */
1564 if (code == ADDR_EXPR && TREE_CODE (TREE_OPERAND (e, 0)) != STRING_CST)
1566 else if (code == INDIRECT_REF)
1568 else if (code == NEGATE_EXPR)
1570 else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
1572 else if (code == TRUTH_NOT_EXPR)
1573 pp_exclamation (pp);
1574 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1579 pp_c_identifier (pp, code == REALPART_EXPR ? "__real__" : "__imag__");
1580 pp_c_whitespace (pp);
1581 pp_unary_expression (pp, TREE_OPERAND (e, 0));
1585 pp_postfix_expression (pp, e);
1592 ( type-name ) cast-expression */
1595 pp_c_cast_expression (c_pretty_printer *pp, tree e)
1597 switch (TREE_CODE (e))
1600 case FIX_TRUNC_EXPR:
1602 pp_c_type_cast (pp, TREE_TYPE (e));
1603 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1607 pp_unary_expression (pp, e);
1611 /* multiplicative-expression:
1613 multiplicative-expression * cast-expression
1614 multiplicative-expression / cast-expression
1615 multiplicative-expression % cast-expression */
1618 pp_c_multiplicative_expression (c_pretty_printer *pp, tree e)
1620 enum tree_code code = TREE_CODE (e);
1624 case TRUNC_DIV_EXPR:
1625 case TRUNC_MOD_EXPR:
1626 pp_multiplicative_expression (pp, TREE_OPERAND (e, 0));
1627 pp_c_whitespace (pp);
1628 if (code == MULT_EXPR)
1630 else if (code == TRUNC_DIV_EXPR)
1634 pp_c_whitespace (pp);
1635 pp_c_cast_expression (pp, TREE_OPERAND (e, 1));
1639 pp_c_cast_expression (pp, e);
1644 /* additive-expression:
1645 multiplicative-expression
1646 additive-expression + multiplicative-expression
1647 additive-expression - multiplicative-expression */
1650 pp_c_additive_expression (c_pretty_printer *pp, tree e)
1652 enum tree_code code = TREE_CODE (e);
1655 case POINTER_PLUS_EXPR:
1658 pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
1659 pp_c_whitespace (pp);
1660 if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
1664 pp_c_whitespace (pp);
1665 pp_multiplicative_expression (pp, TREE_OPERAND (e, 1));
1669 pp_multiplicative_expression (pp, e);
1674 /* additive-expression:
1676 shift-expression << additive-expression
1677 shift-expression >> additive-expression */
1680 pp_c_shift_expression (c_pretty_printer *pp, tree e)
1682 enum tree_code code = TREE_CODE (e);
1687 pp_c_shift_expression (pp, TREE_OPERAND (e, 0));
1688 pp_c_whitespace (pp);
1689 pp_identifier (pp, code == LSHIFT_EXPR ? "<<" : ">>");
1690 pp_c_whitespace (pp);
1691 pp_c_additive_expression (pp, TREE_OPERAND (e, 1));
1695 pp_c_additive_expression (pp, e);
1699 /* relational-expression:
1701 relational-expression < shift-expression
1702 relational-expression > shift-expression
1703 relational-expression <= shift-expression
1704 relational-expression >= shift-expression */
1707 pp_c_relational_expression (c_pretty_printer *pp, tree e)
1709 enum tree_code code = TREE_CODE (e);
1716 pp_c_relational_expression (pp, TREE_OPERAND (e, 0));
1717 pp_c_whitespace (pp);
1718 if (code == LT_EXPR)
1720 else if (code == GT_EXPR)
1722 else if (code == LE_EXPR)
1723 pp_identifier (pp, "<=");
1724 else if (code == GE_EXPR)
1725 pp_identifier (pp, ">=");
1726 pp_c_whitespace (pp);
1727 pp_c_shift_expression (pp, TREE_OPERAND (e, 1));
1731 pp_c_shift_expression (pp, e);
1736 /* equality-expression:
1737 relational-expression
1738 equality-expression == relational-expression
1739 equality-equality != relational-expression */
1742 pp_c_equality_expression (c_pretty_printer *pp, tree e)
1744 enum tree_code code = TREE_CODE (e);
1749 pp_c_equality_expression (pp, TREE_OPERAND (e, 0));
1750 pp_c_whitespace (pp);
1751 pp_identifier (pp, code == EQ_EXPR ? "==" : "!=");
1752 pp_c_whitespace (pp);
1753 pp_c_relational_expression (pp, TREE_OPERAND (e, 1));
1757 pp_c_relational_expression (pp, e);
1764 AND-expression & equality-equality */
1767 pp_c_and_expression (c_pretty_printer *pp, tree e)
1769 if (TREE_CODE (e) == BIT_AND_EXPR)
1771 pp_c_and_expression (pp, TREE_OPERAND (e, 0));
1772 pp_c_whitespace (pp);
1774 pp_c_whitespace (pp);
1775 pp_c_equality_expression (pp, TREE_OPERAND (e, 1));
1778 pp_c_equality_expression (pp, e);
1781 /* exclusive-OR-expression:
1783 exclusive-OR-expression ^ AND-expression */
1786 pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e)
1788 if (TREE_CODE (e) == BIT_XOR_EXPR
1789 || TREE_CODE (e) == TRUTH_XOR_EXPR)
1791 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1792 if (TREE_CODE (e) == BIT_XOR_EXPR)
1793 pp_c_maybe_whitespace (pp);
1795 pp_c_whitespace (pp);
1797 pp_c_whitespace (pp);
1798 pp_c_and_expression (pp, TREE_OPERAND (e, 1));
1801 pp_c_and_expression (pp, e);
1804 /* inclusive-OR-expression:
1805 exclusive-OR-expression
1806 inclusive-OR-expression | exclusive-OR-expression */
1809 pp_c_inclusive_or_expression (c_pretty_printer *pp, tree e)
1811 if (TREE_CODE (e) == BIT_IOR_EXPR)
1813 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1814 pp_c_whitespace (pp);
1816 pp_c_whitespace (pp);
1817 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 1));
1820 pp_c_exclusive_or_expression (pp, e);
1823 /* logical-AND-expression:
1824 inclusive-OR-expression
1825 logical-AND-expression && inclusive-OR-expression */
1828 pp_c_logical_and_expression (c_pretty_printer *pp, tree e)
1830 if (TREE_CODE (e) == TRUTH_ANDIF_EXPR
1831 || TREE_CODE (e) == TRUTH_AND_EXPR)
1833 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0));
1834 pp_c_whitespace (pp);
1835 pp_identifier (pp, "&&");
1836 pp_c_whitespace (pp);
1837 pp_c_inclusive_or_expression (pp, TREE_OPERAND (e, 1));
1840 pp_c_inclusive_or_expression (pp, e);
1843 /* logical-OR-expression:
1844 logical-AND-expression
1845 logical-OR-expression || logical-AND-expression */
1848 pp_c_logical_or_expression (c_pretty_printer *pp, tree e)
1850 if (TREE_CODE (e) == TRUTH_ORIF_EXPR
1851 || TREE_CODE (e) == TRUTH_OR_EXPR)
1853 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
1854 pp_c_whitespace (pp);
1855 pp_identifier (pp, "||");
1856 pp_c_whitespace (pp);
1857 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 1));
1860 pp_c_logical_and_expression (pp, e);
1863 /* conditional-expression:
1864 logical-OR-expression
1865 logical-OR-expression ? expression : conditional-expression */
1868 pp_c_conditional_expression (c_pretty_printer *pp, tree e)
1870 if (TREE_CODE (e) == COND_EXPR)
1872 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
1873 pp_c_whitespace (pp);
1875 pp_c_whitespace (pp);
1876 pp_expression (pp, TREE_OPERAND (e, 1));
1877 pp_c_whitespace (pp);
1879 pp_c_whitespace (pp);
1880 pp_c_conditional_expression (pp, TREE_OPERAND (e, 2));
1883 pp_c_logical_or_expression (pp, e);
1887 /* assignment-expression:
1888 conditional-expression
1889 unary-expression assignment-operator assignment-expression
1891 assignment-expression: one of
1892 = *= /= %= += -= >>= <<= &= ^= |= */
1895 pp_c_assignment_expression (c_pretty_printer *pp, tree e)
1897 if (TREE_CODE (e) == MODIFY_EXPR
1898 || TREE_CODE (e) == INIT_EXPR)
1900 pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
1901 pp_c_whitespace (pp);
1904 pp_c_expression (pp, TREE_OPERAND (e, 1));
1907 pp_c_conditional_expression (pp, e);
1911 assignment-expression
1912 expression , assignment-expression
1914 Implementation note: instead of going through the usual recursion
1915 chain, I take the liberty of dispatching nodes to the appropriate
1916 functions. This makes some redundancy, but it worths it. That also
1917 prevents a possible infinite recursion between pp_c_primary_expression ()
1918 and pp_c_expression (). */
1921 pp_c_expression (c_pretty_printer *pp, tree e)
1923 switch (TREE_CODE (e))
1926 pp_c_integer_constant (pp, e);
1930 pp_c_floating_constant (pp, e);
1934 pp_c_fixed_constant (pp, e);
1938 pp_c_string_literal (pp, e);
1941 case IDENTIFIER_NODE:
1950 pp_primary_expression (pp, e);
1953 case POSTINCREMENT_EXPR:
1954 case POSTDECREMENT_EXPR:
1962 case UNORDERED_EXPR:
1971 case COMPOUND_LITERAL_EXPR:
1973 pp_postfix_expression (pp, e);
1981 case TRUTH_NOT_EXPR:
1982 case PREINCREMENT_EXPR:
1983 case PREDECREMENT_EXPR:
1986 pp_c_unary_expression (pp, e);
1990 case FIX_TRUNC_EXPR:
1992 pp_c_cast_expression (pp, e);
1996 case TRUNC_MOD_EXPR:
1997 case TRUNC_DIV_EXPR:
1998 pp_multiplicative_expression (pp, e);
2003 pp_c_shift_expression (pp, e);
2010 pp_c_relational_expression (pp, e);
2014 pp_c_and_expression (pp, e);
2018 case TRUTH_XOR_EXPR:
2019 pp_c_exclusive_or_expression (pp, e);
2023 pp_c_inclusive_or_expression (pp, e);
2026 case TRUTH_ANDIF_EXPR:
2027 case TRUTH_AND_EXPR:
2028 pp_c_logical_and_expression (pp, e);
2031 case TRUTH_ORIF_EXPR:
2033 pp_c_logical_or_expression (pp, e);
2038 pp_c_equality_expression (pp, e);
2042 pp_conditional_expression (pp, e);
2045 case POINTER_PLUS_EXPR:
2048 pp_c_additive_expression (pp, e);
2053 pp_assignment_expression (pp, e);
2057 pp_c_left_paren (pp);
2058 pp_expression (pp, TREE_OPERAND (e, 0));
2059 pp_separate_with (pp, ',');
2060 pp_assignment_expression (pp, TREE_OPERAND (e, 1));
2061 pp_c_right_paren (pp);
2064 case NON_LVALUE_EXPR:
2066 pp_expression (pp, TREE_OPERAND (e, 0));
2070 pp_postfix_expression (pp, TREE_OPERAND (e, 1));
2074 pp_unsupported_tree (pp, e);
2084 pp_c_statement (c_pretty_printer *pp, tree stmt)
2089 if (pp_needs_newline (pp))
2090 pp_newline_and_indent (pp, 0);
2092 dump_generic_node (pp_base (pp), stmt, pp_indentation (pp), 0, true);
2096 /* Initialize the PRETTY-PRINTER for handling C codes. */
2099 pp_c_pretty_printer_init (c_pretty_printer *pp)
2101 pp->offset_list = 0;
2103 pp->declaration = pp_c_declaration;
2104 pp->declaration_specifiers = pp_c_declaration_specifiers;
2105 pp->declarator = pp_c_declarator;
2106 pp->direct_declarator = pp_c_direct_declarator;
2107 pp->type_specifier_seq = pp_c_specifier_qualifier_list;
2108 pp->abstract_declarator = pp_c_abstract_declarator;
2109 pp->direct_abstract_declarator = pp_c_direct_abstract_declarator;
2110 pp->ptr_operator = pp_c_pointer;
2111 pp->parameter_list = pp_c_parameter_type_list;
2112 pp->type_id = pp_c_type_id;
2113 pp->simple_type_specifier = pp_c_type_specifier;
2114 pp->function_specifier = pp_c_function_specifier;
2115 pp->storage_class_specifier = pp_c_storage_class_specifier;
2117 pp->statement = pp_c_statement;
2119 pp->constant = pp_c_constant;
2120 pp->id_expression = pp_c_id_expression;
2121 pp->primary_expression = pp_c_primary_expression;
2122 pp->postfix_expression = pp_c_postfix_expression;
2123 pp->unary_expression = pp_c_unary_expression;
2124 pp->initializer = pp_c_initializer;
2125 pp->multiplicative_expression = pp_c_multiplicative_expression;
2126 pp->conditional_expression = pp_c_conditional_expression;
2127 pp->assignment_expression = pp_c_assignment_expression;
2128 pp->expression = pp_c_expression;
2132 /* Print the tree T in full, on file FILE. */
2135 print_c_tree (FILE *file, tree t)
2137 static c_pretty_printer pp_rec;
2138 static bool initialized = 0;
2139 c_pretty_printer *pp = &pp_rec;
2144 pp_construct (pp_base (pp), NULL, 0);
2145 pp_c_pretty_printer_init (pp);
2146 pp_needs_newline (pp) = true;
2148 pp_base (pp)->buffer->stream = file;
2150 pp_statement (pp, t);
2156 /* Print the tree T in full, on stderr. */
2159 debug_c_tree (tree t)
2161 print_c_tree (stderr, t);
2162 fputc ('\n', stderr);
2165 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2166 up of T's memory address. */
2169 pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t)
2173 gcc_assert (DECL_P (t));
2176 name = IDENTIFIER_POINTER (DECL_NAME (t));
2179 static char xname[8];
2180 sprintf (xname, "<U%4x>", ((unsigned)((unsigned long)(t) & 0xffff)));
2184 pp_c_identifier (pp, name);