GCCPY: * README added
[official-gcc.git] / gcc / c-family / c-pretty-print.c
blob13dd613d84e02b6c30b6530a490ac589349d3d5b
1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
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
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "intl.h"
27 #include "c-pretty-print.h"
28 #include "tree-pretty-print.h"
29 #include "tree-iterator.h"
30 #include "diagnostic.h"
32 /* Translate if being used for diagnostics, but not for dump files or
33 __PRETTY_FUNCTION. */
34 #define M_(msgid) (pp_translate_identifiers (pp) ? _(msgid) : (msgid))
36 /* The pretty-printer code is primarily designed to closely follow
37 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
38 codes we used to have in the past. Following a structured
39 approach (preferably the official grammars) is believed to make it
40 much easier to add extensions and nifty pretty-printing effects that
41 takes expression or declaration contexts into account. */
44 #define pp_c_maybe_whitespace(PP) \
45 do { \
46 if (pp_base (PP)->padding == pp_before) \
47 pp_c_whitespace (PP); \
48 } while (0)
50 /* literal */
51 static void pp_c_char (c_pretty_printer *, int);
53 /* postfix-expression */
54 static void pp_c_initializer_list (c_pretty_printer *, tree);
55 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer *, tree);
57 static void pp_c_multiplicative_expression (c_pretty_printer *, tree);
58 static void pp_c_additive_expression (c_pretty_printer *, tree);
59 static void pp_c_shift_expression (c_pretty_printer *, tree);
60 static void pp_c_relational_expression (c_pretty_printer *, tree);
61 static void pp_c_equality_expression (c_pretty_printer *, tree);
62 static void pp_c_and_expression (c_pretty_printer *, tree);
63 static void pp_c_exclusive_or_expression (c_pretty_printer *, tree);
64 static void pp_c_inclusive_or_expression (c_pretty_printer *, tree);
65 static void pp_c_logical_and_expression (c_pretty_printer *, tree);
66 static void pp_c_conditional_expression (c_pretty_printer *, tree);
67 static void pp_c_assignment_expression (c_pretty_printer *, tree);
69 /* declarations. */
72 /* Helper functions. */
74 void
75 pp_c_whitespace (c_pretty_printer *pp)
77 pp_space (pp);
78 pp_base (pp)->padding = pp_none;
81 void
82 pp_c_left_paren (c_pretty_printer *pp)
84 pp_left_paren (pp);
85 pp_base (pp)->padding = pp_none;
88 void
89 pp_c_right_paren (c_pretty_printer *pp)
91 pp_right_paren (pp);
92 pp_base (pp)->padding = pp_none;
95 void
96 pp_c_left_brace (c_pretty_printer *pp)
98 pp_left_brace (pp);
99 pp_base (pp)->padding = pp_none;
102 void
103 pp_c_right_brace (c_pretty_printer *pp)
105 pp_right_brace (pp);
106 pp_base (pp)->padding = pp_none;
109 void
110 pp_c_left_bracket (c_pretty_printer *pp)
112 pp_left_bracket (pp);
113 pp_base (pp)->padding = pp_none;
116 void
117 pp_c_right_bracket (c_pretty_printer *pp)
119 pp_right_bracket (pp);
120 pp_base (pp)->padding = pp_none;
123 void
124 pp_c_dot (c_pretty_printer *pp)
126 pp_dot (pp);
127 pp_base (pp)->padding = pp_none;
130 void
131 pp_c_ampersand (c_pretty_printer *pp)
133 pp_ampersand (pp);
134 pp_base (pp)->padding = pp_none;
137 void
138 pp_c_star (c_pretty_printer *pp)
140 pp_star (pp);
141 pp_base (pp)->padding = pp_none;
144 void
145 pp_c_arrow (c_pretty_printer *pp)
147 pp_arrow (pp);
148 pp_base (pp)->padding = pp_none;
151 void
152 pp_c_semicolon (c_pretty_printer *pp)
154 pp_semicolon (pp);
155 pp_base (pp)->padding = pp_none;
158 void
159 pp_c_complement (c_pretty_printer *pp)
161 pp_complement (pp);
162 pp_base (pp)->padding = pp_none;
165 void
166 pp_c_exclamation (c_pretty_printer *pp)
168 pp_exclamation (pp);
169 pp_base (pp)->padding = pp_none;
172 /* Print out the external representation of QUALIFIERS. */
174 void
175 pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type)
177 const char *p = pp_last_position_in_text (pp);
178 bool previous = false;
180 if (!qualifiers)
181 return;
183 /* The C programming language does not have references, but it is much
184 simpler to handle those here rather than going through the same
185 logic in the C++ pretty-printer. */
186 if (p != NULL && (*p == '*' || *p == '&'))
187 pp_c_whitespace (pp);
189 if (qualifiers & TYPE_QUAL_CONST)
191 pp_c_ws_string (pp, func_type ? "__attribute__((const))" : "const");
192 previous = true;
195 if (qualifiers & TYPE_QUAL_VOLATILE)
197 if (previous)
198 pp_c_whitespace (pp);
199 pp_c_ws_string (pp, func_type ? "__attribute__((noreturn))" : "volatile");
200 previous = true;
203 if (qualifiers & TYPE_QUAL_RESTRICT)
205 if (previous)
206 pp_c_whitespace (pp);
207 pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
208 ? "restrict" : "__restrict__"));
212 /* Pretty-print T using the type-cast notation '( type-name )'. */
214 static void
215 pp_c_type_cast (c_pretty_printer *pp, tree t)
217 pp_c_left_paren (pp);
218 pp_type_id (pp, t);
219 pp_c_right_paren (pp);
222 /* We're about to pretty-print a pointer type as indicated by T.
223 Output a whitespace, if needed, preparing for subsequent output. */
225 void
226 pp_c_space_for_pointer_operator (c_pretty_printer *pp, tree t)
228 if (POINTER_TYPE_P (t))
230 tree pointee = strip_pointer_operator (TREE_TYPE (t));
231 if (TREE_CODE (pointee) != ARRAY_TYPE
232 && TREE_CODE (pointee) != FUNCTION_TYPE)
233 pp_c_whitespace (pp);
238 /* Declarations. */
240 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
241 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
242 of its type. Take care of possible extensions.
244 type-qualifier-list:
245 type-qualifier
246 type-qualifier-list type-qualifier
248 type-qualifier:
249 const
250 restrict -- C99
251 __restrict__ -- GNU C
252 address-space-qualifier -- GNU C
253 volatile
255 address-space-qualifier:
256 identifier -- GNU C */
258 void
259 pp_c_type_qualifier_list (c_pretty_printer *pp, tree t)
261 int qualifiers;
263 if (!t || t == error_mark_node)
264 return;
266 if (!TYPE_P (t))
267 t = TREE_TYPE (t);
269 qualifiers = TYPE_QUALS (t);
270 pp_c_cv_qualifiers (pp, qualifiers,
271 TREE_CODE (t) == FUNCTION_TYPE);
273 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t)))
275 const char *as = c_addr_space_name (TYPE_ADDR_SPACE (t));
276 pp_c_identifier (pp, as);
280 /* pointer:
281 * type-qualifier-list(opt)
282 * type-qualifier-list(opt) pointer */
284 static void
285 pp_c_pointer (c_pretty_printer *pp, tree t)
287 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
288 t = TREE_TYPE (t);
289 switch (TREE_CODE (t))
291 case POINTER_TYPE:
292 /* It is easier to handle C++ reference types here. */
293 case REFERENCE_TYPE:
294 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
295 pp_c_pointer (pp, TREE_TYPE (t));
296 if (TREE_CODE (t) == POINTER_TYPE)
297 pp_c_star (pp);
298 else
299 pp_c_ampersand (pp);
300 pp_c_type_qualifier_list (pp, t);
301 break;
303 /* ??? This node is now in GENERIC and so shouldn't be here. But
304 we'll fix that later. */
305 case DECL_EXPR:
306 pp_declaration (pp, DECL_EXPR_DECL (t));
307 pp_needs_newline (pp) = true;
308 break;
310 default:
311 pp_unsupported_tree (pp, t);
315 /* type-specifier:
316 void
317 char
318 short
320 long
321 float
322 double
323 signed
324 unsigned
325 _Bool -- C99
326 _Complex -- C99
327 _Imaginary -- C99
328 struct-or-union-specifier
329 enum-specifier
330 typedef-name.
332 GNU extensions.
333 simple-type-specifier:
334 __complex__
335 __vector__ */
337 void
338 pp_c_type_specifier (c_pretty_printer *pp, tree t)
340 const enum tree_code code = TREE_CODE (t);
341 switch (code)
343 case ERROR_MARK:
344 pp_c_ws_string (pp, M_("<type-error>"));
345 break;
347 case IDENTIFIER_NODE:
348 pp_c_identifier (pp, IDENTIFIER_POINTER (t));
349 break;
351 case VOID_TYPE:
352 case BOOLEAN_TYPE:
353 case INTEGER_TYPE:
354 case REAL_TYPE:
355 case FIXED_POINT_TYPE:
356 if (TYPE_NAME (t))
358 t = TYPE_NAME (t);
359 pp_c_type_specifier (pp, t);
361 else
363 int prec = TYPE_PRECISION (t);
364 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t)))
365 t = c_common_type_for_mode (TYPE_MODE (t), TYPE_SATURATING (t));
366 else
367 t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t));
368 if (TYPE_NAME (t))
370 pp_c_type_specifier (pp, t);
371 if (TYPE_PRECISION (t) != prec)
373 pp_string (pp, ":");
374 pp_decimal_int (pp, prec);
377 else
379 switch (code)
381 case INTEGER_TYPE:
382 pp_string (pp, (TYPE_UNSIGNED (t)
383 ? M_("<unnamed-unsigned:")
384 : M_("<unnamed-signed:")));
385 break;
386 case REAL_TYPE:
387 pp_string (pp, M_("<unnamed-float:"));
388 break;
389 case FIXED_POINT_TYPE:
390 pp_string (pp, M_("<unnamed-fixed:"));
391 break;
392 default:
393 gcc_unreachable ();
395 pp_decimal_int (pp, prec);
396 pp_string (pp, ">");
399 break;
401 case TYPE_DECL:
402 if (DECL_NAME (t))
403 pp_id_expression (pp, t);
404 else
405 pp_c_ws_string (pp, M_("<typedef-error>"));
406 break;
408 case UNION_TYPE:
409 case RECORD_TYPE:
410 case ENUMERAL_TYPE:
411 if (code == UNION_TYPE)
412 pp_c_ws_string (pp, "union");
413 else if (code == RECORD_TYPE)
414 pp_c_ws_string (pp, "struct");
415 else if (code == ENUMERAL_TYPE)
416 pp_c_ws_string (pp, "enum");
417 else
418 pp_c_ws_string (pp, M_("<tag-error>"));
420 if (TYPE_NAME (t))
421 pp_id_expression (pp, TYPE_NAME (t));
422 else
423 pp_c_ws_string (pp, M_("<anonymous>"));
424 break;
426 default:
427 pp_unsupported_tree (pp, t);
428 break;
432 /* specifier-qualifier-list:
433 type-specifier specifier-qualifier-list-opt
434 type-qualifier specifier-qualifier-list-opt
437 Implementation note: Because of the non-linearities in array or
438 function declarations, this routine prints not just the
439 specifier-qualifier-list of such entities or types of such entities,
440 but also the 'pointer' production part of their declarators. The
441 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
443 void
444 pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree t)
446 const enum tree_code code = TREE_CODE (t);
448 if (!(pp->flags & pp_c_flag_gnu_v3) && code != POINTER_TYPE)
449 pp_c_type_qualifier_list (pp, t);
450 switch (code)
452 case REFERENCE_TYPE:
453 case POINTER_TYPE:
455 /* Get the types-specifier of this type. */
456 tree pointee = strip_pointer_operator (TREE_TYPE (t));
457 pp_c_specifier_qualifier_list (pp, pointee);
458 if (TREE_CODE (pointee) == ARRAY_TYPE
459 || TREE_CODE (pointee) == FUNCTION_TYPE)
461 pp_c_whitespace (pp);
462 pp_c_left_paren (pp);
463 pp_c_attributes_display (pp, TYPE_ATTRIBUTES (pointee));
465 else if (!c_dialect_cxx ())
466 pp_c_whitespace (pp);
467 pp_ptr_operator (pp, t);
469 break;
471 case FUNCTION_TYPE:
472 case ARRAY_TYPE:
473 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
474 break;
476 case VECTOR_TYPE:
477 case COMPLEX_TYPE:
478 if (code == COMPLEX_TYPE)
479 pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
480 ? "_Complex" : "__complex__"));
481 else if (code == VECTOR_TYPE)
483 pp_c_ws_string (pp, "__vector");
484 pp_c_left_paren (pp);
485 pp_wide_integer (pp, TYPE_VECTOR_SUBPARTS (t));
486 pp_c_right_paren (pp);
487 pp_c_whitespace (pp);
489 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
490 break;
492 default:
493 pp_simple_type_specifier (pp, t);
494 break;
496 if ((pp->flags & pp_c_flag_gnu_v3) && code != POINTER_TYPE)
497 pp_c_type_qualifier_list (pp, t);
500 /* parameter-type-list:
501 parameter-list
502 parameter-list , ...
504 parameter-list:
505 parameter-declaration
506 parameter-list , parameter-declaration
508 parameter-declaration:
509 declaration-specifiers declarator
510 declaration-specifiers abstract-declarator(opt) */
512 void
513 pp_c_parameter_type_list (c_pretty_printer *pp, tree t)
515 bool want_parm_decl = DECL_P (t) && !(pp->flags & pp_c_flag_abstract);
516 tree parms = want_parm_decl ? DECL_ARGUMENTS (t) : TYPE_ARG_TYPES (t);
517 pp_c_left_paren (pp);
518 if (parms == void_list_node)
519 pp_c_ws_string (pp, "void");
520 else
522 bool first = true;
523 for ( ; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
525 if (!first)
526 pp_separate_with (pp, ',');
527 first = false;
528 pp_declaration_specifiers
529 (pp, want_parm_decl ? parms : TREE_VALUE (parms));
530 if (want_parm_decl)
531 pp_declarator (pp, parms);
532 else
533 pp_abstract_declarator (pp, TREE_VALUE (parms));
536 pp_c_right_paren (pp);
539 /* abstract-declarator:
540 pointer
541 pointer(opt) direct-abstract-declarator */
543 static void
544 pp_c_abstract_declarator (c_pretty_printer *pp, tree t)
546 if (TREE_CODE (t) == POINTER_TYPE)
548 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
549 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
550 pp_c_right_paren (pp);
551 t = TREE_TYPE (t);
554 pp_direct_abstract_declarator (pp, t);
557 /* direct-abstract-declarator:
558 ( abstract-declarator )
559 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
560 direct-abstract-declarator(opt) [ * ]
561 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
563 void
564 pp_c_direct_abstract_declarator (c_pretty_printer *pp, tree t)
566 switch (TREE_CODE (t))
568 case POINTER_TYPE:
569 pp_abstract_declarator (pp, t);
570 break;
572 case FUNCTION_TYPE:
573 pp_c_parameter_type_list (pp, t);
574 pp_direct_abstract_declarator (pp, TREE_TYPE (t));
575 break;
577 case ARRAY_TYPE:
578 pp_c_left_bracket (pp);
579 if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t)))
581 tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (t));
582 tree type = TREE_TYPE (maxval);
584 if (host_integerp (maxval, 0))
585 pp_wide_integer (pp, tree_low_cst (maxval, 0) + 1);
586 else
587 pp_expression (pp, fold_build2 (PLUS_EXPR, type, maxval,
588 build_int_cst (type, 1)));
590 pp_c_right_bracket (pp);
591 pp_direct_abstract_declarator (pp, TREE_TYPE (t));
592 break;
594 case IDENTIFIER_NODE:
595 case VOID_TYPE:
596 case BOOLEAN_TYPE:
597 case INTEGER_TYPE:
598 case REAL_TYPE:
599 case FIXED_POINT_TYPE:
600 case ENUMERAL_TYPE:
601 case RECORD_TYPE:
602 case UNION_TYPE:
603 case VECTOR_TYPE:
604 case COMPLEX_TYPE:
605 case TYPE_DECL:
606 break;
608 default:
609 pp_unsupported_tree (pp, t);
610 break;
614 /* type-name:
615 specifier-qualifier-list abstract-declarator(opt) */
617 void
618 pp_c_type_id (c_pretty_printer *pp, tree t)
620 pp_c_specifier_qualifier_list (pp, t);
621 pp_abstract_declarator (pp, t);
624 /* storage-class-specifier:
625 typedef
626 extern
627 static
628 auto
629 register */
631 void
632 pp_c_storage_class_specifier (c_pretty_printer *pp, tree t)
634 if (TREE_CODE (t) == TYPE_DECL)
635 pp_c_ws_string (pp, "typedef");
636 else if (DECL_P (t))
638 if (DECL_REGISTER (t))
639 pp_c_ws_string (pp, "register");
640 else if (TREE_STATIC (t) && TREE_CODE (t) == VAR_DECL)
641 pp_c_ws_string (pp, "static");
645 /* function-specifier:
646 inline */
648 void
649 pp_c_function_specifier (c_pretty_printer *pp, tree t)
651 if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t))
652 pp_c_ws_string (pp, "inline");
655 /* declaration-specifiers:
656 storage-class-specifier declaration-specifiers(opt)
657 type-specifier declaration-specifiers(opt)
658 type-qualifier declaration-specifiers(opt)
659 function-specifier declaration-specifiers(opt) */
661 void
662 pp_c_declaration_specifiers (c_pretty_printer *pp, tree t)
664 pp_storage_class_specifier (pp, t);
665 pp_function_specifier (pp, t);
666 pp_c_specifier_qualifier_list (pp, DECL_P (t) ? TREE_TYPE (t) : t);
669 /* direct-declarator
670 identifier
671 ( declarator )
672 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
673 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
674 direct-declarator [ type-qualifier-list static assignment-expression ]
675 direct-declarator [ type-qualifier-list * ]
676 direct-declarator ( parameter-type-list )
677 direct-declarator ( identifier-list(opt) ) */
679 void
680 pp_c_direct_declarator (c_pretty_printer *pp, tree t)
682 switch (TREE_CODE (t))
684 case VAR_DECL:
685 case PARM_DECL:
686 case TYPE_DECL:
687 case FIELD_DECL:
688 case LABEL_DECL:
689 pp_c_space_for_pointer_operator (pp, TREE_TYPE (t));
690 pp_c_tree_decl_identifier (pp, t);
691 break;
693 case ARRAY_TYPE:
694 case POINTER_TYPE:
695 pp_abstract_declarator (pp, TREE_TYPE (t));
696 break;
698 case FUNCTION_TYPE:
699 pp_parameter_list (pp, t);
700 pp_abstract_declarator (pp, TREE_TYPE (t));
701 break;
703 case FUNCTION_DECL:
704 pp_c_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
705 pp_c_tree_decl_identifier (pp, t);
706 if (pp_c_base (pp)->flags & pp_c_flag_abstract)
707 pp_abstract_declarator (pp, TREE_TYPE (t));
708 else
710 pp_parameter_list (pp, t);
711 pp_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t)));
713 break;
715 case INTEGER_TYPE:
716 case REAL_TYPE:
717 case FIXED_POINT_TYPE:
718 case ENUMERAL_TYPE:
719 case UNION_TYPE:
720 case RECORD_TYPE:
721 break;
723 default:
724 pp_unsupported_tree (pp, t);
725 break;
730 /* declarator:
731 pointer(opt) direct-declarator */
733 void
734 pp_c_declarator (c_pretty_printer *pp, tree t)
736 switch (TREE_CODE (t))
738 case INTEGER_TYPE:
739 case REAL_TYPE:
740 case FIXED_POINT_TYPE:
741 case ENUMERAL_TYPE:
742 case UNION_TYPE:
743 case RECORD_TYPE:
744 break;
746 case VAR_DECL:
747 case PARM_DECL:
748 case FIELD_DECL:
749 case ARRAY_TYPE:
750 case FUNCTION_TYPE:
751 case FUNCTION_DECL:
752 case TYPE_DECL:
753 pp_direct_declarator (pp, t);
754 break;
757 default:
758 pp_unsupported_tree (pp, t);
759 break;
763 /* declaration:
764 declaration-specifiers init-declarator-list(opt) ; */
766 void
767 pp_c_declaration (c_pretty_printer *pp, tree t)
769 pp_declaration_specifiers (pp, t);
770 pp_c_init_declarator (pp, t);
773 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
775 void
776 pp_c_attributes (c_pretty_printer *pp, tree attributes)
778 if (attributes == NULL_TREE)
779 return;
781 pp_c_ws_string (pp, "__attribute__");
782 pp_c_left_paren (pp);
783 pp_c_left_paren (pp);
784 for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes))
786 pp_tree_identifier (pp, TREE_PURPOSE (attributes));
787 if (TREE_VALUE (attributes))
788 pp_c_call_argument_list (pp, TREE_VALUE (attributes));
790 if (TREE_CHAIN (attributes))
791 pp_separate_with (pp, ',');
793 pp_c_right_paren (pp);
794 pp_c_right_paren (pp);
797 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
798 marked to be displayed on disgnostic. */
800 void
801 pp_c_attributes_display (c_pretty_printer *pp, tree a)
803 bool is_first = true;
805 if (a == NULL_TREE)
806 return;
808 for (; a != NULL_TREE; a = TREE_CHAIN (a))
810 const struct attribute_spec *as;
811 as = lookup_attribute_spec (TREE_PURPOSE (a));
812 if (!as || as->affects_type_identity == false)
813 continue;
814 if (is_first)
816 pp_c_ws_string (pp, "__attribute__");
817 pp_c_left_paren (pp);
818 pp_c_left_paren (pp);
819 is_first = false;
821 else
823 pp_separate_with (pp, ',');
825 pp_tree_identifier (pp, TREE_PURPOSE (a));
826 if (TREE_VALUE (a))
827 pp_c_call_argument_list (pp, TREE_VALUE (a));
830 if (!is_first)
832 pp_c_right_paren (pp);
833 pp_c_right_paren (pp);
834 pp_c_whitespace (pp);
838 /* function-definition:
839 declaration-specifiers declarator compound-statement */
841 void
842 pp_c_function_definition (c_pretty_printer *pp, tree t)
844 pp_declaration_specifiers (pp, t);
845 pp_declarator (pp, t);
846 pp_needs_newline (pp) = true;
847 pp_statement (pp, DECL_SAVED_TREE (t));
848 pp_newline_and_flush (pp);
852 /* Expressions. */
854 /* Print out a c-char. This is called solely for characters which are
855 in the *target* execution character set. We ought to convert them
856 back to the *host* execution character set before printing, but we
857 have no way to do this at present. A decent compromise is to print
858 all characters as if they were in the host execution character set,
859 and not attempt to recover any named escape characters, but render
860 all unprintables as octal escapes. If the host and target character
861 sets are the same, this produces relatively readable output. If they
862 are not the same, strings may appear as gibberish, but that's okay
863 (in fact, it may well be what the reader wants, e.g. if they are looking
864 to see if conversion to the target character set happened correctly).
866 A special case: we need to prefix \, ", and ' with backslashes. It is
867 correct to do so for the *host*'s \, ", and ', because the rest of the
868 file appears in the host character set. */
870 static void
871 pp_c_char (c_pretty_printer *pp, int c)
873 if (ISPRINT (c))
875 switch (c)
877 case '\\': pp_string (pp, "\\\\"); break;
878 case '\'': pp_string (pp, "\\\'"); break;
879 case '\"': pp_string (pp, "\\\""); break;
880 default: pp_character (pp, c);
883 else
884 pp_scalar (pp, "\\%03o", (unsigned) c);
887 /* Print out a STRING literal. */
889 void
890 pp_c_string_literal (c_pretty_printer *pp, tree s)
892 const char *p = TREE_STRING_POINTER (s);
893 int n = TREE_STRING_LENGTH (s) - 1;
894 int i;
895 pp_doublequote (pp);
896 for (i = 0; i < n; ++i)
897 pp_c_char (pp, p[i]);
898 pp_doublequote (pp);
901 /* Pretty-print an INTEGER literal. */
903 static void
904 pp_c_integer_constant (c_pretty_printer *pp, tree i)
906 /* We are going to compare the type of I to other types using
907 pointer comparison so we need to use its canonical type. */
908 tree type =
909 TYPE_CANONICAL (TREE_TYPE (i))
910 ? TYPE_CANONICAL (TREE_TYPE (i))
911 : TREE_TYPE (i);
913 if (host_integerp (i, 0))
914 pp_wide_integer (pp, TREE_INT_CST_LOW (i));
915 else if (host_integerp (i, 1))
916 pp_unsigned_wide_integer (pp, TREE_INT_CST_LOW (i));
917 else
919 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (i);
920 HOST_WIDE_INT high = TREE_INT_CST_HIGH (i);
921 if (tree_int_cst_sgn (i) < 0)
923 pp_character (pp, '-');
924 high = ~high + !low;
925 low = -low;
927 sprintf (pp_buffer (pp)->digit_buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
928 (unsigned HOST_WIDE_INT) high, (unsigned HOST_WIDE_INT) low);
929 pp_string (pp, pp_buffer (pp)->digit_buffer);
931 if (TYPE_UNSIGNED (type))
932 pp_character (pp, 'u');
933 if (type == long_integer_type_node || type == long_unsigned_type_node)
934 pp_character (pp, 'l');
935 else if (type == long_long_integer_type_node
936 || type == long_long_unsigned_type_node)
937 pp_string (pp, "ll");
938 else if (type == int128_integer_type_node
939 || type == int128_unsigned_type_node)
940 pp_string (pp, "I128");
943 /* Print out a CHARACTER literal. */
945 static void
946 pp_c_character_constant (c_pretty_printer *pp, tree c)
948 tree type = TREE_TYPE (c);
949 if (type == wchar_type_node)
950 pp_character (pp, 'L');
951 pp_quote (pp);
952 if (host_integerp (c, TYPE_UNSIGNED (type)))
953 pp_c_char (pp, tree_low_cst (c, TYPE_UNSIGNED (type)));
954 else
955 pp_scalar (pp, "\\x%x", (unsigned) TREE_INT_CST_LOW (c));
956 pp_quote (pp);
959 /* Print out a BOOLEAN literal. */
961 static void
962 pp_c_bool_constant (c_pretty_printer *pp, tree b)
964 if (b == boolean_false_node)
966 if (c_dialect_cxx ())
967 pp_c_ws_string (pp, "false");
968 else if (flag_isoc99)
969 pp_c_ws_string (pp, "_False");
970 else
971 pp_unsupported_tree (pp, b);
973 else if (b == boolean_true_node)
975 if (c_dialect_cxx ())
976 pp_c_ws_string (pp, "true");
977 else if (flag_isoc99)
978 pp_c_ws_string (pp, "_True");
979 else
980 pp_unsupported_tree (pp, b);
982 else if (TREE_CODE (b) == INTEGER_CST)
983 pp_c_integer_constant (pp, b);
984 else
985 pp_unsupported_tree (pp, b);
988 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
989 false; that means the value was obtained by a cast, in which case
990 print out the type-id part of the cast-expression -- the casted value
991 is then printed by pp_c_integer_literal. */
993 static bool
994 pp_c_enumeration_constant (c_pretty_printer *pp, tree e)
996 bool value_is_named = true;
997 tree type = TREE_TYPE (e);
998 tree value;
1000 /* Find the name of this constant. */
1001 for (value = TYPE_VALUES (type);
1002 value != NULL_TREE && !tree_int_cst_equal (TREE_VALUE (value), e);
1003 value = TREE_CHAIN (value))
1006 if (value != NULL_TREE)
1007 pp_id_expression (pp, TREE_PURPOSE (value));
1008 else
1010 /* Value must have been cast. */
1011 pp_c_type_cast (pp, type);
1012 value_is_named = false;
1015 return value_is_named;
1018 /* Print out a REAL value as a decimal-floating-constant. */
1020 static void
1021 pp_c_floating_constant (c_pretty_printer *pp, tree r)
1023 const struct real_format *fmt
1024 = REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (r)));
1026 REAL_VALUE_TYPE floating_cst = TREE_REAL_CST (r);
1027 bool is_decimal = floating_cst.decimal;
1029 /* See ISO C++ WG N1822. Note: The fraction 643/2136 approximates
1030 log10(2) to 7 significant digits. */
1031 int max_digits10 = 2 + (is_decimal ? fmt->p : fmt->p * 643L / 2136);
1033 real_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_REAL_CST (r),
1034 sizeof (pp_buffer (pp)->digit_buffer),
1035 max_digits10, 1);
1037 pp_string (pp, pp_buffer(pp)->digit_buffer);
1038 if (TREE_TYPE (r) == float_type_node)
1039 pp_character (pp, 'f');
1040 else if (TREE_TYPE (r) == long_double_type_node)
1041 pp_character (pp, 'l');
1042 else if (TREE_TYPE (r) == dfloat128_type_node)
1043 pp_string (pp, "dl");
1044 else if (TREE_TYPE (r) == dfloat64_type_node)
1045 pp_string (pp, "dd");
1046 else if (TREE_TYPE (r) == dfloat32_type_node)
1047 pp_string (pp, "df");
1050 /* Print out a FIXED value as a decimal-floating-constant. */
1052 static void
1053 pp_c_fixed_constant (c_pretty_printer *pp, tree r)
1055 fixed_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_FIXED_CST (r),
1056 sizeof (pp_buffer (pp)->digit_buffer));
1057 pp_string (pp, pp_buffer(pp)->digit_buffer);
1060 /* Pretty-print a compound literal expression. GNU extensions include
1061 vector constants. */
1063 static void
1064 pp_c_compound_literal (c_pretty_printer *pp, tree e)
1066 tree type = TREE_TYPE (e);
1067 pp_c_type_cast (pp, type);
1069 switch (TREE_CODE (type))
1071 case RECORD_TYPE:
1072 case UNION_TYPE:
1073 case ARRAY_TYPE:
1074 case VECTOR_TYPE:
1075 case COMPLEX_TYPE:
1076 pp_c_brace_enclosed_initializer_list (pp, e);
1077 break;
1079 default:
1080 pp_unsupported_tree (pp, e);
1081 break;
1085 /* Pretty-print a COMPLEX_EXPR expression. */
1087 static void
1088 pp_c_complex_expr (c_pretty_printer *pp, tree e)
1090 /* Handle a few common special cases, otherwise fallback
1091 to printing it as compound literal. */
1092 tree type = TREE_TYPE (e);
1093 tree realexpr = TREE_OPERAND (e, 0);
1094 tree imagexpr = TREE_OPERAND (e, 1);
1096 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1097 if (TREE_CODE (realexpr) == NOP_EXPR
1098 && TREE_CODE (imagexpr) == NOP_EXPR
1099 && TREE_TYPE (realexpr) == TREE_TYPE (type)
1100 && TREE_TYPE (imagexpr) == TREE_TYPE (type)
1101 && TREE_CODE (TREE_OPERAND (realexpr, 0)) == REALPART_EXPR
1102 && TREE_CODE (TREE_OPERAND (imagexpr, 0)) == IMAGPART_EXPR
1103 && TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0)
1104 == TREE_OPERAND (TREE_OPERAND (imagexpr, 0), 0))
1106 pp_c_type_cast (pp, type);
1107 pp_expression (pp, TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0));
1108 return;
1111 /* Cast of an scalar expression to COMPLEX_TYPE. */
1112 if ((integer_zerop (imagexpr) || real_zerop (imagexpr))
1113 && TREE_TYPE (realexpr) == TREE_TYPE (type))
1115 pp_c_type_cast (pp, type);
1116 if (TREE_CODE (realexpr) == NOP_EXPR)
1117 realexpr = TREE_OPERAND (realexpr, 0);
1118 pp_expression (pp, realexpr);
1119 return;
1122 pp_c_compound_literal (pp, e);
1125 /* constant:
1126 integer-constant
1127 floating-constant
1128 fixed-point-constant
1129 enumeration-constant
1130 character-constant */
1132 void
1133 pp_c_constant (c_pretty_printer *pp, tree e)
1135 const enum tree_code code = TREE_CODE (e);
1137 switch (code)
1139 case INTEGER_CST:
1141 tree type = TREE_TYPE (e);
1142 if (type == boolean_type_node)
1143 pp_c_bool_constant (pp, e);
1144 else if (type == char_type_node)
1145 pp_c_character_constant (pp, e);
1146 else if (TREE_CODE (type) == ENUMERAL_TYPE
1147 && pp_c_enumeration_constant (pp, e))
1149 else
1150 pp_c_integer_constant (pp, e);
1152 break;
1154 case REAL_CST:
1155 pp_c_floating_constant (pp, e);
1156 break;
1158 case FIXED_CST:
1159 pp_c_fixed_constant (pp, e);
1160 break;
1162 case STRING_CST:
1163 pp_c_string_literal (pp, e);
1164 break;
1166 case COMPLEX_CST:
1167 /* Sometimes, we are confused and we think a complex literal
1168 is a constant. Such thing is a compound literal which
1169 grammatically belongs to postfix-expr production. */
1170 pp_c_compound_literal (pp, e);
1171 break;
1173 default:
1174 pp_unsupported_tree (pp, e);
1175 break;
1179 /* Pretty-print a string such as an identifier, without changing its
1180 encoding, preceded by whitespace is necessary. */
1182 void
1183 pp_c_ws_string (c_pretty_printer *pp, const char *str)
1185 pp_c_maybe_whitespace (pp);
1186 pp_string (pp, str);
1187 pp_base (pp)->padding = pp_before;
1190 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1191 that need converting to the locale encoding, preceded by whitespace
1192 is necessary. */
1194 void
1195 pp_c_identifier (c_pretty_printer *pp, const char *id)
1197 pp_c_maybe_whitespace (pp);
1198 pp_identifier (pp, id);
1199 pp_base (pp)->padding = pp_before;
1202 /* Pretty-print a C primary-expression.
1203 primary-expression:
1204 identifier
1205 constant
1206 string-literal
1207 ( expression ) */
1209 void
1210 pp_c_primary_expression (c_pretty_printer *pp, tree e)
1212 switch (TREE_CODE (e))
1214 case VAR_DECL:
1215 case PARM_DECL:
1216 case FIELD_DECL:
1217 case CONST_DECL:
1218 case FUNCTION_DECL:
1219 case LABEL_DECL:
1220 pp_c_tree_decl_identifier (pp, e);
1221 break;
1223 case IDENTIFIER_NODE:
1224 pp_c_tree_identifier (pp, e);
1225 break;
1227 case ERROR_MARK:
1228 pp_c_ws_string (pp, M_("<erroneous-expression>"));
1229 break;
1231 case RESULT_DECL:
1232 pp_c_ws_string (pp, M_("<return-value>"));
1233 break;
1235 case INTEGER_CST:
1236 case REAL_CST:
1237 case FIXED_CST:
1238 case STRING_CST:
1239 pp_c_constant (pp, e);
1240 break;
1242 case TARGET_EXPR:
1243 pp_c_ws_string (pp, "__builtin_memcpy");
1244 pp_c_left_paren (pp);
1245 pp_ampersand (pp);
1246 pp_primary_expression (pp, TREE_OPERAND (e, 0));
1247 pp_separate_with (pp, ',');
1248 pp_ampersand (pp);
1249 pp_initializer (pp, TREE_OPERAND (e, 1));
1250 if (TREE_OPERAND (e, 2))
1252 pp_separate_with (pp, ',');
1253 pp_c_expression (pp, TREE_OPERAND (e, 2));
1255 pp_c_right_paren (pp);
1256 break;
1258 default:
1259 /* FIXME: Make sure we won't get into an infinite loop. */
1260 pp_c_left_paren (pp);
1261 pp_expression (pp, e);
1262 pp_c_right_paren (pp);
1263 break;
1267 /* Print out a C initializer -- also support C compound-literals.
1268 initializer:
1269 assignment-expression:
1270 { initializer-list }
1271 { initializer-list , } */
1273 static void
1274 pp_c_initializer (c_pretty_printer *pp, tree e)
1276 if (TREE_CODE (e) == CONSTRUCTOR)
1277 pp_c_brace_enclosed_initializer_list (pp, e);
1278 else
1279 pp_expression (pp, e);
1282 /* init-declarator:
1283 declarator:
1284 declarator = initializer */
1286 void
1287 pp_c_init_declarator (c_pretty_printer *pp, tree t)
1289 pp_declarator (pp, t);
1290 /* We don't want to output function definitions here. There are handled
1291 elsewhere (and the syntactic form is bogus anyway). */
1292 if (TREE_CODE (t) != FUNCTION_DECL && DECL_INITIAL (t))
1294 tree init = DECL_INITIAL (t);
1295 /* This C++ bit is handled here because it is easier to do so.
1296 In templates, the C++ parser builds a TREE_LIST for a
1297 direct-initialization; the TREE_PURPOSE is the variable to
1298 initialize and the TREE_VALUE is the initializer. */
1299 if (TREE_CODE (init) == TREE_LIST)
1301 pp_c_left_paren (pp);
1302 pp_expression (pp, TREE_VALUE (init));
1303 pp_right_paren (pp);
1305 else
1307 pp_space (pp);
1308 pp_equal (pp);
1309 pp_space (pp);
1310 pp_c_initializer (pp, init);
1315 /* initializer-list:
1316 designation(opt) initializer
1317 initializer-list , designation(opt) initializer
1319 designation:
1320 designator-list =
1322 designator-list:
1323 designator
1324 designator-list designator
1326 designator:
1327 [ constant-expression ]
1328 identifier */
1330 static void
1331 pp_c_initializer_list (c_pretty_printer *pp, tree e)
1333 tree type = TREE_TYPE (e);
1334 const enum tree_code code = TREE_CODE (type);
1336 if (TREE_CODE (e) == CONSTRUCTOR)
1338 pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e));
1339 return;
1342 switch (code)
1344 case RECORD_TYPE:
1345 case UNION_TYPE:
1346 case ARRAY_TYPE:
1348 tree init = TREE_OPERAND (e, 0);
1349 for (; init != NULL_TREE; init = TREE_CHAIN (init))
1351 if (code == RECORD_TYPE || code == UNION_TYPE)
1353 pp_c_dot (pp);
1354 pp_c_primary_expression (pp, TREE_PURPOSE (init));
1356 else
1358 pp_c_left_bracket (pp);
1359 if (TREE_PURPOSE (init))
1360 pp_c_constant (pp, TREE_PURPOSE (init));
1361 pp_c_right_bracket (pp);
1363 pp_c_whitespace (pp);
1364 pp_equal (pp);
1365 pp_c_whitespace (pp);
1366 pp_initializer (pp, TREE_VALUE (init));
1367 if (TREE_CHAIN (init))
1368 pp_separate_with (pp, ',');
1371 return;
1373 case VECTOR_TYPE:
1374 if (TREE_CODE (e) == VECTOR_CST)
1376 unsigned i;
1377 for (i = 0; i < VECTOR_CST_NELTS (e); ++i)
1379 if (i > 0)
1380 pp_separate_with (pp, ',');
1381 pp_expression (pp, VECTOR_CST_ELT (e, i));
1384 else
1385 break;
1386 return;
1388 case COMPLEX_TYPE:
1389 if (TREE_CODE (e) == COMPLEX_CST || TREE_CODE (e) == COMPLEX_EXPR)
1391 const bool cst = TREE_CODE (e) == COMPLEX_CST;
1392 pp_expression (pp, cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0));
1393 pp_separate_with (pp, ',');
1394 pp_expression (pp, cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1));
1396 else
1397 break;
1398 return;
1400 default:
1401 break;
1404 pp_unsupported_tree (pp, type);
1407 /* Pretty-print a brace-enclosed initializer-list. */
1409 static void
1410 pp_c_brace_enclosed_initializer_list (c_pretty_printer *pp, tree l)
1412 pp_c_left_brace (pp);
1413 pp_c_initializer_list (pp, l);
1414 pp_c_right_brace (pp);
1418 /* This is a convenient function, used to bridge gap between C and C++
1419 grammars.
1421 id-expression:
1422 identifier */
1424 void
1425 pp_c_id_expression (c_pretty_printer *pp, tree t)
1427 switch (TREE_CODE (t))
1429 case VAR_DECL:
1430 case PARM_DECL:
1431 case CONST_DECL:
1432 case TYPE_DECL:
1433 case FUNCTION_DECL:
1434 case FIELD_DECL:
1435 case LABEL_DECL:
1436 pp_c_tree_decl_identifier (pp, t);
1437 break;
1439 case IDENTIFIER_NODE:
1440 pp_c_tree_identifier (pp, t);
1441 break;
1443 default:
1444 pp_unsupported_tree (pp, t);
1445 break;
1449 /* postfix-expression:
1450 primary-expression
1451 postfix-expression [ expression ]
1452 postfix-expression ( argument-expression-list(opt) )
1453 postfix-expression . identifier
1454 postfix-expression -> identifier
1455 postfix-expression ++
1456 postfix-expression --
1457 ( type-name ) { initializer-list }
1458 ( type-name ) { initializer-list , } */
1460 void
1461 pp_c_postfix_expression (c_pretty_printer *pp, tree e)
1463 enum tree_code code = TREE_CODE (e);
1464 switch (code)
1466 case POSTINCREMENT_EXPR:
1467 case POSTDECREMENT_EXPR:
1468 pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1469 pp_string (pp, code == POSTINCREMENT_EXPR ? "++" : "--");
1470 break;
1472 case ARRAY_REF:
1473 pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1474 pp_c_left_bracket (pp);
1475 pp_expression (pp, TREE_OPERAND (e, 1));
1476 pp_c_right_bracket (pp);
1477 break;
1479 case CALL_EXPR:
1481 call_expr_arg_iterator iter;
1482 tree arg;
1483 pp_postfix_expression (pp, CALL_EXPR_FN (e));
1484 pp_c_left_paren (pp);
1485 FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
1487 pp_expression (pp, arg);
1488 if (more_call_expr_args_p (&iter))
1489 pp_separate_with (pp, ',');
1491 pp_c_right_paren (pp);
1492 break;
1495 case UNORDERED_EXPR:
1496 pp_c_ws_string (pp, flag_isoc99
1497 ? "isunordered"
1498 : "__builtin_isunordered");
1499 goto two_args_fun;
1501 case ORDERED_EXPR:
1502 pp_c_ws_string (pp, flag_isoc99
1503 ? "!isunordered"
1504 : "!__builtin_isunordered");
1505 goto two_args_fun;
1507 case UNLT_EXPR:
1508 pp_c_ws_string (pp, flag_isoc99
1509 ? "!isgreaterequal"
1510 : "!__builtin_isgreaterequal");
1511 goto two_args_fun;
1513 case UNLE_EXPR:
1514 pp_c_ws_string (pp, flag_isoc99
1515 ? "!isgreater"
1516 : "!__builtin_isgreater");
1517 goto two_args_fun;
1519 case UNGT_EXPR:
1520 pp_c_ws_string (pp, flag_isoc99
1521 ? "!islessequal"
1522 : "!__builtin_islessequal");
1523 goto two_args_fun;
1525 case UNGE_EXPR:
1526 pp_c_ws_string (pp, flag_isoc99
1527 ? "!isless"
1528 : "!__builtin_isless");
1529 goto two_args_fun;
1531 case UNEQ_EXPR:
1532 pp_c_ws_string (pp, flag_isoc99
1533 ? "!islessgreater"
1534 : "!__builtin_islessgreater");
1535 goto two_args_fun;
1537 case LTGT_EXPR:
1538 pp_c_ws_string (pp, flag_isoc99
1539 ? "islessgreater"
1540 : "__builtin_islessgreater");
1541 goto two_args_fun;
1543 two_args_fun:
1544 pp_c_left_paren (pp);
1545 pp_expression (pp, TREE_OPERAND (e, 0));
1546 pp_separate_with (pp, ',');
1547 pp_expression (pp, TREE_OPERAND (e, 1));
1548 pp_c_right_paren (pp);
1549 break;
1551 case ABS_EXPR:
1552 pp_c_ws_string (pp, "__builtin_abs");
1553 pp_c_left_paren (pp);
1554 pp_expression (pp, TREE_OPERAND (e, 0));
1555 pp_c_right_paren (pp);
1556 break;
1558 case COMPONENT_REF:
1560 tree object = TREE_OPERAND (e, 0);
1561 if (TREE_CODE (object) == INDIRECT_REF)
1563 pp_postfix_expression (pp, TREE_OPERAND (object, 0));
1564 pp_c_arrow (pp);
1566 else
1568 pp_postfix_expression (pp, object);
1569 pp_c_dot (pp);
1571 pp_expression (pp, TREE_OPERAND (e, 1));
1573 break;
1575 case BIT_FIELD_REF:
1577 tree type = TREE_TYPE (e);
1579 type = signed_or_unsigned_type_for (TYPE_UNSIGNED (type), type);
1580 if (type
1581 && tree_int_cst_equal (TYPE_SIZE (type), TREE_OPERAND (e, 1)))
1583 HOST_WIDE_INT bitpos = tree_low_cst (TREE_OPERAND (e, 2), 0);
1584 HOST_WIDE_INT size = tree_low_cst (TYPE_SIZE (type), 0);
1585 if ((bitpos % size) == 0)
1587 pp_c_left_paren (pp);
1588 pp_c_left_paren (pp);
1589 pp_type_id (pp, type);
1590 pp_c_star (pp);
1591 pp_c_right_paren (pp);
1592 pp_c_ampersand (pp);
1593 pp_expression (pp, TREE_OPERAND (e, 0));
1594 pp_c_right_paren (pp);
1595 pp_c_left_bracket (pp);
1596 pp_wide_integer (pp, bitpos / size);
1597 pp_c_right_bracket (pp);
1598 break;
1601 pp_unsupported_tree (pp, e);
1603 break;
1605 case MEM_REF:
1606 pp_c_expression (pp, e);
1607 break;
1609 case COMPLEX_CST:
1610 case VECTOR_CST:
1611 pp_c_compound_literal (pp, e);
1612 break;
1614 case COMPLEX_EXPR:
1615 pp_c_complex_expr (pp, e);
1616 break;
1618 case COMPOUND_LITERAL_EXPR:
1619 e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e));
1620 /* Fall through. */
1621 case CONSTRUCTOR:
1622 pp_initializer (pp, e);
1623 break;
1625 case VA_ARG_EXPR:
1626 pp_c_ws_string (pp, "__builtin_va_arg");
1627 pp_c_left_paren (pp);
1628 pp_assignment_expression (pp, TREE_OPERAND (e, 0));
1629 pp_separate_with (pp, ',');
1630 pp_type_id (pp, TREE_TYPE (e));
1631 pp_c_right_paren (pp);
1632 break;
1634 case ADDR_EXPR:
1635 if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
1637 pp_c_id_expression (pp, TREE_OPERAND (e, 0));
1638 break;
1640 /* else fall through. */
1642 default:
1643 pp_primary_expression (pp, e);
1644 break;
1648 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1650 void
1651 pp_c_expression_list (c_pretty_printer *pp, tree e)
1653 for (; e != NULL_TREE; e = TREE_CHAIN (e))
1655 pp_expression (pp, TREE_VALUE (e));
1656 if (TREE_CHAIN (e))
1657 pp_separate_with (pp, ',');
1661 /* Print out V, which contains the elements of a constructor. */
1663 void
1664 pp_c_constructor_elts (c_pretty_printer *pp, vec<constructor_elt, va_gc> *v)
1666 unsigned HOST_WIDE_INT ix;
1667 tree value;
1669 FOR_EACH_CONSTRUCTOR_VALUE (v, ix, value)
1671 pp_expression (pp, value);
1672 if (ix != vec_safe_length (v) - 1)
1673 pp_separate_with (pp, ',');
1677 /* Print out an expression-list in parens, as if it were the argument
1678 list to a function. */
1680 void
1681 pp_c_call_argument_list (c_pretty_printer *pp, tree t)
1683 pp_c_left_paren (pp);
1684 if (t && TREE_CODE (t) == TREE_LIST)
1685 pp_c_expression_list (pp, t);
1686 pp_c_right_paren (pp);
1689 /* unary-expression:
1690 postfix-expression
1691 ++ cast-expression
1692 -- cast-expression
1693 unary-operator cast-expression
1694 sizeof unary-expression
1695 sizeof ( type-id )
1697 unary-operator: one of
1698 * & + - ! ~
1700 GNU extensions.
1701 unary-expression:
1702 __alignof__ unary-expression
1703 __alignof__ ( type-id )
1704 __real__ unary-expression
1705 __imag__ unary-expression */
1707 void
1708 pp_c_unary_expression (c_pretty_printer *pp, tree e)
1710 enum tree_code code = TREE_CODE (e);
1711 switch (code)
1713 case PREINCREMENT_EXPR:
1714 case PREDECREMENT_EXPR:
1715 pp_string (pp, code == PREINCREMENT_EXPR ? "++" : "--");
1716 pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
1717 break;
1719 case ADDR_EXPR:
1720 case INDIRECT_REF:
1721 case NEGATE_EXPR:
1722 case BIT_NOT_EXPR:
1723 case TRUTH_NOT_EXPR:
1724 case CONJ_EXPR:
1725 /* String literal are used by address. */
1726 if (code == ADDR_EXPR && TREE_CODE (TREE_OPERAND (e, 0)) != STRING_CST)
1727 pp_ampersand (pp);
1728 else if (code == INDIRECT_REF)
1729 pp_c_star (pp);
1730 else if (code == NEGATE_EXPR)
1731 pp_minus (pp);
1732 else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
1733 pp_complement (pp);
1734 else if (code == TRUTH_NOT_EXPR)
1735 pp_exclamation (pp);
1736 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1737 break;
1739 case MEM_REF:
1740 if (TREE_CODE (TREE_OPERAND (e, 0)) == ADDR_EXPR
1741 && integer_zerop (TREE_OPERAND (e, 1)))
1742 pp_c_expression (pp, TREE_OPERAND (TREE_OPERAND (e, 0), 0));
1743 else
1745 pp_c_star (pp);
1746 if (!integer_zerop (TREE_OPERAND (e, 1)))
1748 pp_c_left_paren (pp);
1749 if (!integer_onep (TYPE_SIZE_UNIT
1750 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e, 0))))))
1751 pp_c_type_cast (pp, ptr_type_node);
1753 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1754 if (!integer_zerop (TREE_OPERAND (e, 1)))
1756 pp_plus (pp);
1757 pp_c_integer_constant (pp,
1758 fold_convert (ssizetype,
1759 TREE_OPERAND (e, 1)));
1760 pp_c_right_paren (pp);
1763 break;
1765 case REALPART_EXPR:
1766 case IMAGPART_EXPR:
1767 pp_c_ws_string (pp, code == REALPART_EXPR ? "__real__" : "__imag__");
1768 pp_c_whitespace (pp);
1769 pp_unary_expression (pp, TREE_OPERAND (e, 0));
1770 break;
1772 default:
1773 pp_postfix_expression (pp, e);
1774 break;
1778 /* cast-expression:
1779 unary-expression
1780 ( type-name ) cast-expression */
1782 void
1783 pp_c_cast_expression (c_pretty_printer *pp, tree e)
1785 switch (TREE_CODE (e))
1787 case FLOAT_EXPR:
1788 case FIX_TRUNC_EXPR:
1789 CASE_CONVERT:
1790 case VIEW_CONVERT_EXPR:
1791 pp_c_type_cast (pp, TREE_TYPE (e));
1792 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1793 break;
1795 default:
1796 pp_unary_expression (pp, e);
1800 /* multiplicative-expression:
1801 cast-expression
1802 multiplicative-expression * cast-expression
1803 multiplicative-expression / cast-expression
1804 multiplicative-expression % cast-expression */
1806 static void
1807 pp_c_multiplicative_expression (c_pretty_printer *pp, tree e)
1809 enum tree_code code = TREE_CODE (e);
1810 switch (code)
1812 case MULT_EXPR:
1813 case TRUNC_DIV_EXPR:
1814 case TRUNC_MOD_EXPR:
1815 pp_multiplicative_expression (pp, TREE_OPERAND (e, 0));
1816 pp_c_whitespace (pp);
1817 if (code == MULT_EXPR)
1818 pp_c_star (pp);
1819 else if (code == TRUNC_DIV_EXPR)
1820 pp_slash (pp);
1821 else
1822 pp_modulo (pp);
1823 pp_c_whitespace (pp);
1824 pp_c_cast_expression (pp, TREE_OPERAND (e, 1));
1825 break;
1827 default:
1828 pp_c_cast_expression (pp, e);
1829 break;
1833 /* additive-expression:
1834 multiplicative-expression
1835 additive-expression + multiplicative-expression
1836 additive-expression - multiplicative-expression */
1838 static void
1839 pp_c_additive_expression (c_pretty_printer *pp, tree e)
1841 enum tree_code code = TREE_CODE (e);
1842 switch (code)
1844 case POINTER_PLUS_EXPR:
1845 case PLUS_EXPR:
1846 case MINUS_EXPR:
1847 pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
1848 pp_c_whitespace (pp);
1849 if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
1850 pp_plus (pp);
1851 else
1852 pp_minus (pp);
1853 pp_c_whitespace (pp);
1854 pp_multiplicative_expression (pp, TREE_OPERAND (e, 1));
1855 break;
1857 default:
1858 pp_multiplicative_expression (pp, e);
1859 break;
1863 /* additive-expression:
1864 additive-expression
1865 shift-expression << additive-expression
1866 shift-expression >> additive-expression */
1868 static void
1869 pp_c_shift_expression (c_pretty_printer *pp, tree e)
1871 enum tree_code code = TREE_CODE (e);
1872 switch (code)
1874 case LSHIFT_EXPR:
1875 case RSHIFT_EXPR:
1876 pp_c_shift_expression (pp, TREE_OPERAND (e, 0));
1877 pp_c_whitespace (pp);
1878 pp_string (pp, code == LSHIFT_EXPR ? "<<" : ">>");
1879 pp_c_whitespace (pp);
1880 pp_c_additive_expression (pp, TREE_OPERAND (e, 1));
1881 break;
1883 default:
1884 pp_c_additive_expression (pp, e);
1888 /* relational-expression:
1889 shift-expression
1890 relational-expression < shift-expression
1891 relational-expression > shift-expression
1892 relational-expression <= shift-expression
1893 relational-expression >= shift-expression */
1895 static void
1896 pp_c_relational_expression (c_pretty_printer *pp, tree e)
1898 enum tree_code code = TREE_CODE (e);
1899 switch (code)
1901 case LT_EXPR:
1902 case GT_EXPR:
1903 case LE_EXPR:
1904 case GE_EXPR:
1905 pp_c_relational_expression (pp, TREE_OPERAND (e, 0));
1906 pp_c_whitespace (pp);
1907 if (code == LT_EXPR)
1908 pp_less (pp);
1909 else if (code == GT_EXPR)
1910 pp_greater (pp);
1911 else if (code == LE_EXPR)
1912 pp_string (pp, "<=");
1913 else if (code == GE_EXPR)
1914 pp_string (pp, ">=");
1915 pp_c_whitespace (pp);
1916 pp_c_shift_expression (pp, TREE_OPERAND (e, 1));
1917 break;
1919 default:
1920 pp_c_shift_expression (pp, e);
1921 break;
1925 /* equality-expression:
1926 relational-expression
1927 equality-expression == relational-expression
1928 equality-equality != relational-expression */
1930 static void
1931 pp_c_equality_expression (c_pretty_printer *pp, tree e)
1933 enum tree_code code = TREE_CODE (e);
1934 switch (code)
1936 case EQ_EXPR:
1937 case NE_EXPR:
1938 pp_c_equality_expression (pp, TREE_OPERAND (e, 0));
1939 pp_c_whitespace (pp);
1940 pp_string (pp, code == EQ_EXPR ? "==" : "!=");
1941 pp_c_whitespace (pp);
1942 pp_c_relational_expression (pp, TREE_OPERAND (e, 1));
1943 break;
1945 default:
1946 pp_c_relational_expression (pp, e);
1947 break;
1951 /* AND-expression:
1952 equality-expression
1953 AND-expression & equality-equality */
1955 static void
1956 pp_c_and_expression (c_pretty_printer *pp, tree e)
1958 if (TREE_CODE (e) == BIT_AND_EXPR)
1960 pp_c_and_expression (pp, TREE_OPERAND (e, 0));
1961 pp_c_whitespace (pp);
1962 pp_ampersand (pp);
1963 pp_c_whitespace (pp);
1964 pp_c_equality_expression (pp, TREE_OPERAND (e, 1));
1966 else
1967 pp_c_equality_expression (pp, e);
1970 /* exclusive-OR-expression:
1971 AND-expression
1972 exclusive-OR-expression ^ AND-expression */
1974 static void
1975 pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e)
1977 if (TREE_CODE (e) == BIT_XOR_EXPR
1978 || TREE_CODE (e) == TRUTH_XOR_EXPR)
1980 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1981 if (TREE_CODE (e) == BIT_XOR_EXPR)
1982 pp_c_maybe_whitespace (pp);
1983 else
1984 pp_c_whitespace (pp);
1985 pp_carret (pp);
1986 pp_c_whitespace (pp);
1987 pp_c_and_expression (pp, TREE_OPERAND (e, 1));
1989 else
1990 pp_c_and_expression (pp, e);
1993 /* inclusive-OR-expression:
1994 exclusive-OR-expression
1995 inclusive-OR-expression | exclusive-OR-expression */
1997 static void
1998 pp_c_inclusive_or_expression (c_pretty_printer *pp, tree e)
2000 if (TREE_CODE (e) == BIT_IOR_EXPR)
2002 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
2003 pp_c_whitespace (pp);
2004 pp_bar (pp);
2005 pp_c_whitespace (pp);
2006 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 1));
2008 else
2009 pp_c_exclusive_or_expression (pp, e);
2012 /* logical-AND-expression:
2013 inclusive-OR-expression
2014 logical-AND-expression && inclusive-OR-expression */
2016 static void
2017 pp_c_logical_and_expression (c_pretty_printer *pp, tree e)
2019 if (TREE_CODE (e) == TRUTH_ANDIF_EXPR
2020 || TREE_CODE (e) == TRUTH_AND_EXPR)
2022 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0));
2023 pp_c_whitespace (pp);
2024 pp_string (pp, "&&");
2025 pp_c_whitespace (pp);
2026 pp_c_inclusive_or_expression (pp, TREE_OPERAND (e, 1));
2028 else
2029 pp_c_inclusive_or_expression (pp, e);
2032 /* logical-OR-expression:
2033 logical-AND-expression
2034 logical-OR-expression || logical-AND-expression */
2036 void
2037 pp_c_logical_or_expression (c_pretty_printer *pp, tree e)
2039 if (TREE_CODE (e) == TRUTH_ORIF_EXPR
2040 || TREE_CODE (e) == TRUTH_OR_EXPR)
2042 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2043 pp_c_whitespace (pp);
2044 pp_string (pp, "||");
2045 pp_c_whitespace (pp);
2046 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 1));
2048 else
2049 pp_c_logical_and_expression (pp, e);
2052 /* conditional-expression:
2053 logical-OR-expression
2054 logical-OR-expression ? expression : conditional-expression */
2056 static void
2057 pp_c_conditional_expression (c_pretty_printer *pp, tree e)
2059 if (TREE_CODE (e) == COND_EXPR)
2061 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2062 pp_c_whitespace (pp);
2063 pp_question (pp);
2064 pp_c_whitespace (pp);
2065 pp_expression (pp, TREE_OPERAND (e, 1));
2066 pp_c_whitespace (pp);
2067 pp_colon (pp);
2068 pp_c_whitespace (pp);
2069 pp_c_conditional_expression (pp, TREE_OPERAND (e, 2));
2071 else
2072 pp_c_logical_or_expression (pp, e);
2076 /* assignment-expression:
2077 conditional-expression
2078 unary-expression assignment-operator assignment-expression
2080 assignment-expression: one of
2081 = *= /= %= += -= >>= <<= &= ^= |= */
2083 static void
2084 pp_c_assignment_expression (c_pretty_printer *pp, tree e)
2086 if (TREE_CODE (e) == MODIFY_EXPR
2087 || TREE_CODE (e) == INIT_EXPR)
2089 pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
2090 pp_c_whitespace (pp);
2091 pp_equal (pp);
2092 pp_space (pp);
2093 pp_c_expression (pp, TREE_OPERAND (e, 1));
2095 else
2096 pp_c_conditional_expression (pp, e);
2099 /* expression:
2100 assignment-expression
2101 expression , assignment-expression
2103 Implementation note: instead of going through the usual recursion
2104 chain, I take the liberty of dispatching nodes to the appropriate
2105 functions. This makes some redundancy, but it worths it. That also
2106 prevents a possible infinite recursion between pp_c_primary_expression ()
2107 and pp_c_expression (). */
2109 void
2110 pp_c_expression (c_pretty_printer *pp, tree e)
2112 switch (TREE_CODE (e))
2114 case INTEGER_CST:
2115 pp_c_integer_constant (pp, e);
2116 break;
2118 case REAL_CST:
2119 pp_c_floating_constant (pp, e);
2120 break;
2122 case FIXED_CST:
2123 pp_c_fixed_constant (pp, e);
2124 break;
2126 case STRING_CST:
2127 pp_c_string_literal (pp, e);
2128 break;
2130 case IDENTIFIER_NODE:
2131 case FUNCTION_DECL:
2132 case VAR_DECL:
2133 case CONST_DECL:
2134 case PARM_DECL:
2135 case RESULT_DECL:
2136 case FIELD_DECL:
2137 case LABEL_DECL:
2138 case ERROR_MARK:
2139 pp_primary_expression (pp, e);
2140 break;
2142 case SSA_NAME:
2143 if (SSA_NAME_VAR (e)
2144 && !DECL_ARTIFICIAL (SSA_NAME_VAR (e)))
2145 pp_c_expression (pp, SSA_NAME_VAR (e));
2146 else
2147 pp_c_ws_string (pp, M_("<unknown>"));
2148 break;
2150 case POSTINCREMENT_EXPR:
2151 case POSTDECREMENT_EXPR:
2152 case ARRAY_REF:
2153 case CALL_EXPR:
2154 case COMPONENT_REF:
2155 case BIT_FIELD_REF:
2156 case COMPLEX_CST:
2157 case COMPLEX_EXPR:
2158 case VECTOR_CST:
2159 case ORDERED_EXPR:
2160 case UNORDERED_EXPR:
2161 case LTGT_EXPR:
2162 case UNEQ_EXPR:
2163 case UNLE_EXPR:
2164 case UNLT_EXPR:
2165 case UNGE_EXPR:
2166 case UNGT_EXPR:
2167 case ABS_EXPR:
2168 case CONSTRUCTOR:
2169 case COMPOUND_LITERAL_EXPR:
2170 case VA_ARG_EXPR:
2171 pp_postfix_expression (pp, e);
2172 break;
2174 case CONJ_EXPR:
2175 case ADDR_EXPR:
2176 case INDIRECT_REF:
2177 case MEM_REF:
2178 case NEGATE_EXPR:
2179 case BIT_NOT_EXPR:
2180 case TRUTH_NOT_EXPR:
2181 case PREINCREMENT_EXPR:
2182 case PREDECREMENT_EXPR:
2183 case REALPART_EXPR:
2184 case IMAGPART_EXPR:
2185 pp_c_unary_expression (pp, e);
2186 break;
2188 case FLOAT_EXPR:
2189 case FIX_TRUNC_EXPR:
2190 CASE_CONVERT:
2191 case VIEW_CONVERT_EXPR:
2192 pp_c_cast_expression (pp, e);
2193 break;
2195 case MULT_EXPR:
2196 case TRUNC_MOD_EXPR:
2197 case TRUNC_DIV_EXPR:
2198 pp_multiplicative_expression (pp, e);
2199 break;
2201 case LSHIFT_EXPR:
2202 case RSHIFT_EXPR:
2203 pp_c_shift_expression (pp, e);
2204 break;
2206 case LT_EXPR:
2207 case GT_EXPR:
2208 case LE_EXPR:
2209 case GE_EXPR:
2210 pp_c_relational_expression (pp, e);
2211 break;
2213 case BIT_AND_EXPR:
2214 pp_c_and_expression (pp, e);
2215 break;
2217 case BIT_XOR_EXPR:
2218 case TRUTH_XOR_EXPR:
2219 pp_c_exclusive_or_expression (pp, e);
2220 break;
2222 case BIT_IOR_EXPR:
2223 pp_c_inclusive_or_expression (pp, e);
2224 break;
2226 case TRUTH_ANDIF_EXPR:
2227 case TRUTH_AND_EXPR:
2228 pp_c_logical_and_expression (pp, e);
2229 break;
2231 case TRUTH_ORIF_EXPR:
2232 case TRUTH_OR_EXPR:
2233 pp_c_logical_or_expression (pp, e);
2234 break;
2236 case EQ_EXPR:
2237 case NE_EXPR:
2238 pp_c_equality_expression (pp, e);
2239 break;
2241 case COND_EXPR:
2242 pp_conditional_expression (pp, e);
2243 break;
2245 case POINTER_PLUS_EXPR:
2246 case PLUS_EXPR:
2247 case MINUS_EXPR:
2248 pp_c_additive_expression (pp, e);
2249 break;
2251 case MODIFY_EXPR:
2252 case INIT_EXPR:
2253 pp_assignment_expression (pp, e);
2254 break;
2256 case COMPOUND_EXPR:
2257 pp_c_left_paren (pp);
2258 pp_expression (pp, TREE_OPERAND (e, 0));
2259 pp_separate_with (pp, ',');
2260 pp_assignment_expression (pp, TREE_OPERAND (e, 1));
2261 pp_c_right_paren (pp);
2262 break;
2264 case NON_LVALUE_EXPR:
2265 case SAVE_EXPR:
2266 pp_expression (pp, TREE_OPERAND (e, 0));
2267 break;
2269 case TARGET_EXPR:
2270 pp_postfix_expression (pp, TREE_OPERAND (e, 1));
2271 break;
2273 case BIND_EXPR:
2274 case GOTO_EXPR:
2275 /* We don't yet have a way of dumping statements in a
2276 human-readable format. */
2277 pp_string (pp, "({...})");
2278 break;
2280 case C_MAYBE_CONST_EXPR:
2281 pp_c_expression (pp, C_MAYBE_CONST_EXPR_EXPR (e));
2282 break;
2284 default:
2285 pp_unsupported_tree (pp, e);
2286 break;
2292 /* Statements. */
2294 void
2295 pp_c_statement (c_pretty_printer *pp, tree stmt)
2297 if (stmt == NULL)
2298 return;
2300 if (pp_needs_newline (pp))
2301 pp_newline_and_indent (pp, 0);
2303 dump_generic_node (pp_base (pp), stmt, pp_indentation (pp), 0, true);
2307 /* Initialize the PRETTY-PRINTER for handling C codes. */
2309 void
2310 pp_c_pretty_printer_init (c_pretty_printer *pp)
2312 pp->offset_list = 0;
2314 pp->flags = 0;
2316 pp->declaration = pp_c_declaration;
2317 pp->declaration_specifiers = pp_c_declaration_specifiers;
2318 pp->declarator = pp_c_declarator;
2319 pp->direct_declarator = pp_c_direct_declarator;
2320 pp->type_specifier_seq = pp_c_specifier_qualifier_list;
2321 pp->abstract_declarator = pp_c_abstract_declarator;
2322 pp->direct_abstract_declarator = pp_c_direct_abstract_declarator;
2323 pp->ptr_operator = pp_c_pointer;
2324 pp->parameter_list = pp_c_parameter_type_list;
2325 pp->type_id = pp_c_type_id;
2326 pp->simple_type_specifier = pp_c_type_specifier;
2327 pp->function_specifier = pp_c_function_specifier;
2328 pp->storage_class_specifier = pp_c_storage_class_specifier;
2330 pp->statement = pp_c_statement;
2332 pp->constant = pp_c_constant;
2333 pp->id_expression = pp_c_id_expression;
2334 pp->primary_expression = pp_c_primary_expression;
2335 pp->postfix_expression = pp_c_postfix_expression;
2336 pp->unary_expression = pp_c_unary_expression;
2337 pp->initializer = pp_c_initializer;
2338 pp->multiplicative_expression = pp_c_multiplicative_expression;
2339 pp->conditional_expression = pp_c_conditional_expression;
2340 pp->assignment_expression = pp_c_assignment_expression;
2341 pp->expression = pp_c_expression;
2345 /* Print the tree T in full, on file FILE. */
2347 void
2348 print_c_tree (FILE *file, tree t)
2350 static c_pretty_printer pp_rec;
2351 static bool initialized = 0;
2352 c_pretty_printer *pp = &pp_rec;
2354 if (!initialized)
2356 initialized = 1;
2357 pp_construct (pp_base (pp), NULL, 0);
2358 pp_c_pretty_printer_init (pp);
2359 pp_needs_newline (pp) = true;
2361 pp_base (pp)->buffer->stream = file;
2363 pp_statement (pp, t);
2365 pp_newline_and_flush (pp);
2368 /* Print the tree T in full, on stderr. */
2370 DEBUG_FUNCTION void
2371 debug_c_tree (tree t)
2373 print_c_tree (stderr, t);
2374 fputc ('\n', stderr);
2377 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2378 up of T's memory address. */
2380 void
2381 pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t)
2383 const char *name;
2385 gcc_assert (DECL_P (t));
2387 if (DECL_NAME (t))
2388 name = IDENTIFIER_POINTER (DECL_NAME (t));
2389 else
2391 static char xname[8];
2392 sprintf (xname, "<U%4x>", ((unsigned)((uintptr_t)(t) & 0xffff)));
2393 name = xname;
2396 pp_c_identifier (pp, name);