OSDN Git Service

gcc:
[pf3gnuchains/gcc-fork.git] / gcc / c-pretty-print.c
1 /* Subroutines common to both C and C++ pretty-printers.
2    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
3    Free Software Foundation, Inc.
4    Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
5
6 This file is part of GCC.
7
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
11 version.
12
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
16 for more details.
17
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/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "real.h"
27 #include "fixed-value.h"
28 #include "intl.h"
29 #include "c-pretty-print.h"
30 #include "c-tree.h"
31 #include "tree-iterator.h"
32 #include "diagnostic.h"
33
34 /* Translate if being used for diagnostics, but not for dump files or
35    __PRETTY_FUNCTION.  */
36 #define M_(msgid) (pp_translate_identifiers (pp) ? _(msgid) : (msgid))
37
38 /* The pretty-printer code is primarily designed to closely follow
39    (GNU) C and C++ grammars.  That is to be contrasted with spaghetti
40    codes we used to have in the past.  Following a structured
41    approach (preferably the official grammars) is believed to make it
42    much easier to add extensions and nifty pretty-printing effects that
43    takes expression or declaration contexts into account.  */
44
45
46 #define pp_c_maybe_whitespace(PP)            \
47    do {                                      \
48      if (pp_base (PP)->padding == pp_before) \
49        pp_c_whitespace (PP);                 \
50    } while (0)
51
52 /* literal  */
53 static void pp_c_char (c_pretty_printer *, int);
54
55 /* postfix-expression  */
56 static void pp_c_initializer_list (c_pretty_printer *, tree);
57 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer *, tree);
58
59 static void pp_c_multiplicative_expression (c_pretty_printer *, tree);
60 static void pp_c_additive_expression (c_pretty_printer *, tree);
61 static void pp_c_shift_expression (c_pretty_printer *, tree);
62 static void pp_c_relational_expression (c_pretty_printer *, tree);
63 static void pp_c_equality_expression (c_pretty_printer *, tree);
64 static void pp_c_and_expression (c_pretty_printer *, tree);
65 static void pp_c_exclusive_or_expression (c_pretty_printer *, tree);
66 static void pp_c_inclusive_or_expression (c_pretty_printer *, tree);
67 static void pp_c_logical_and_expression (c_pretty_printer *, tree);
68 static void pp_c_conditional_expression (c_pretty_printer *, tree);
69 static void pp_c_assignment_expression (c_pretty_printer *, tree);
70
71 /* declarations.  */
72
73 \f
74 /* Helper functions.  */
75
76 void
77 pp_c_whitespace (c_pretty_printer *pp)
78 {
79   pp_space (pp);
80   pp_base (pp)->padding = pp_none;
81 }
82
83 void
84 pp_c_left_paren (c_pretty_printer *pp)
85 {
86   pp_left_paren (pp);
87   pp_base (pp)->padding = pp_none;
88 }
89
90 void
91 pp_c_right_paren (c_pretty_printer *pp)
92 {
93   pp_right_paren (pp);
94   pp_base (pp)->padding = pp_none;
95 }
96
97 void
98 pp_c_left_brace (c_pretty_printer *pp)
99 {
100   pp_left_brace (pp);
101   pp_base (pp)->padding = pp_none;
102 }
103
104 void
105 pp_c_right_brace (c_pretty_printer *pp)
106 {
107   pp_right_brace (pp);
108   pp_base (pp)->padding = pp_none;
109 }
110
111 void
112 pp_c_left_bracket (c_pretty_printer *pp)
113 {
114   pp_left_bracket (pp);
115   pp_base (pp)->padding = pp_none;
116 }
117
118 void
119 pp_c_right_bracket (c_pretty_printer *pp)
120 {
121   pp_right_bracket (pp);
122   pp_base (pp)->padding = pp_none;
123 }
124
125 void
126 pp_c_dot (c_pretty_printer *pp)
127 {
128   pp_dot (pp);
129   pp_base (pp)->padding = pp_none;
130 }
131
132 void
133 pp_c_ampersand (c_pretty_printer *pp)
134 {
135   pp_ampersand (pp);
136   pp_base (pp)->padding = pp_none;
137 }
138
139 void
140 pp_c_star (c_pretty_printer *pp)
141 {
142   pp_star (pp);
143   pp_base (pp)->padding = pp_none;
144 }
145
146 void
147 pp_c_arrow (c_pretty_printer *pp)
148 {
149   pp_arrow (pp);
150   pp_base (pp)->padding = pp_none;
151 }
152
153 void
154 pp_c_semicolon (c_pretty_printer *pp)
155 {
156   pp_semicolon (pp);
157   pp_base (pp)->padding = pp_none;
158 }
159
160 void
161 pp_c_complement (c_pretty_printer *pp)
162 {
163   pp_complement (pp);
164   pp_base (pp)->padding = pp_none;
165 }
166
167 void
168 pp_c_exclamation (c_pretty_printer *pp)
169 {
170   pp_exclamation (pp);
171   pp_base (pp)->padding = pp_none;
172 }
173
174 /* Print out the external representation of CV-QUALIFIER.  */
175
176 static void
177 pp_c_cv_qualifier (c_pretty_printer *pp, const char *cv)
178 {
179   const char *p = pp_last_position_in_text (pp);
180   /* The C programming language does not have references, but it is much
181      simpler to handle those here rather than going through the same
182      logic in the C++ pretty-printer.  */
183   if (p != NULL && (*p == '*' || *p == '&'))
184     pp_c_whitespace (pp);
185   pp_c_ws_string (pp, cv);
186 }
187
188 /* Pretty-print T using the type-cast notation '( type-name )'.  */
189
190 static void
191 pp_c_type_cast (c_pretty_printer *pp, tree t)
192 {
193   pp_c_left_paren (pp);
194   pp_type_id (pp, t);
195   pp_c_right_paren (pp);
196 }
197
198 /* We're about to pretty-print a pointer type as indicated by T.
199    Output a whitespace, if needed, preparing for subsequent output.  */
200
201 void
202 pp_c_space_for_pointer_operator (c_pretty_printer *pp, tree t)
203 {
204   if (POINTER_TYPE_P (t))
205     {
206       tree pointee = strip_pointer_operator (TREE_TYPE (t));
207       if (TREE_CODE (pointee) != ARRAY_TYPE
208           && TREE_CODE (pointee) != FUNCTION_TYPE)
209         pp_c_whitespace (pp);
210     }
211 }
212
213 \f
214 /* Declarations.  */
215
216 /* C++ cv-qualifiers are called type-qualifiers in C.  Print out the
217    cv-qualifiers of T.  If T is a declaration then it is the cv-qualifier
218    of its type.  Take care of possible extensions.
219
220    type-qualifier-list:
221        type-qualifier
222        type-qualifier-list type-qualifier
223
224    type-qualifier:
225        const
226        restrict                              -- C99
227        __restrict__                          -- GNU C
228        address-space-qualifier               -- GNU C
229        volatile
230
231    address-space-qualifier:
232        identifier                            -- GNU C  */
233
234 void
235 pp_c_type_qualifier_list (c_pretty_printer *pp, tree t)
236 {
237   int qualifiers;
238
239   if (!t || t == error_mark_node)
240     return;
241
242   if (!TYPE_P (t))
243     t = TREE_TYPE (t);
244
245   qualifiers = TYPE_QUALS (t);
246   if (qualifiers & TYPE_QUAL_CONST)
247     pp_c_cv_qualifier (pp, "const");
248   if (qualifiers & TYPE_QUAL_VOLATILE)
249     pp_c_cv_qualifier (pp, "volatile");
250   if (qualifiers & TYPE_QUAL_RESTRICT)
251     pp_c_cv_qualifier (pp, flag_isoc99 ? "restrict" : "__restrict__");
252
253   if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t)))
254     {
255       const char *as = c_addr_space_name (TYPE_ADDR_SPACE (t));
256       pp_c_identifier (pp, as);
257     }
258 }
259
260 /* pointer:
261       * type-qualifier-list(opt)
262       * type-qualifier-list(opt) pointer  */
263
264 static void
265 pp_c_pointer (c_pretty_printer *pp, tree t)
266 {
267   if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
268     t = TREE_TYPE (t);
269   switch (TREE_CODE (t))
270     {
271     case POINTER_TYPE:
272       /* It is easier to handle C++ reference types here.  */
273     case REFERENCE_TYPE:
274       if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
275         pp_c_pointer (pp, TREE_TYPE (t));
276       if (TREE_CODE (t) == POINTER_TYPE)
277         pp_c_star (pp);
278       else
279         pp_c_ampersand (pp);
280       pp_c_type_qualifier_list (pp, t);
281       break;
282
283       /* ??? This node is now in GENERIC and so shouldn't be here.  But
284          we'll fix that later.  */
285     case DECL_EXPR:
286       pp_declaration (pp, DECL_EXPR_DECL (t));
287       pp_needs_newline (pp) = true;
288       break;
289
290     default:
291       pp_unsupported_tree (pp, t);
292     }
293 }
294
295 /* type-specifier:
296       void
297       char
298       short
299       int
300       long
301       float
302       double
303       signed
304       unsigned
305       _Bool                          -- C99
306       _Complex                       -- C99
307       _Imaginary                     -- C99
308       struct-or-union-specifier
309       enum-specifier
310       typedef-name.
311
312   GNU extensions.
313   simple-type-specifier:
314       __complex__
315       __vector__   */
316
317 void
318 pp_c_type_specifier (c_pretty_printer *pp, tree t)
319 {
320   const enum tree_code code = TREE_CODE (t);
321   switch (code)
322     {
323     case ERROR_MARK:
324       pp_c_ws_string (pp, M_("<type-error>"));
325       break;
326
327     case IDENTIFIER_NODE:
328       pp_c_tree_decl_identifier (pp, t);
329       break;
330
331     case VOID_TYPE:
332     case BOOLEAN_TYPE:
333     case INTEGER_TYPE:
334     case REAL_TYPE:
335     case FIXED_POINT_TYPE:
336       if (TYPE_NAME (t))
337         {
338           t = TYPE_NAME (t);
339           pp_c_type_specifier (pp, t);
340         }
341       else
342         {
343           int prec = TYPE_PRECISION (t);
344           if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t)))
345             t = c_common_type_for_mode (TYPE_MODE (t), TYPE_SATURATING (t));
346           else
347             t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t));
348           if (TYPE_NAME (t))
349             {
350               pp_c_type_specifier (pp, t);
351               if (TYPE_PRECISION (t) != prec)
352                 {
353                   pp_string (pp, ":");
354                   pp_decimal_int (pp, prec);
355                 }
356             }
357           else
358             {
359               switch (code)
360                 {
361                 case INTEGER_TYPE:
362                   pp_string (pp, (TYPE_UNSIGNED (t)
363                                   ? M_("<unnamed-unsigned:")
364                                   : M_("<unnamed-signed:")));
365                   break;
366                 case REAL_TYPE:
367                   pp_string (pp, M_("<unnamed-float:"));
368                   break;
369                 case FIXED_POINT_TYPE:
370                   pp_string (pp, M_("<unnamed-fixed:"));
371                   break;
372                 default:
373                   gcc_unreachable ();
374                 }
375               pp_decimal_int (pp, prec);
376               pp_string (pp, ">");
377             }
378         }
379       break;
380
381     case TYPE_DECL:
382       if (DECL_NAME (t))
383         pp_id_expression (pp, t);
384       else
385         pp_c_ws_string (pp, M_("<typedef-error>"));
386       break;
387
388     case UNION_TYPE:
389     case RECORD_TYPE:
390     case ENUMERAL_TYPE:
391       if (code == UNION_TYPE)
392         pp_c_ws_string (pp, "union");
393       else if (code == RECORD_TYPE)
394         pp_c_ws_string (pp, "struct");
395       else if (code == ENUMERAL_TYPE)
396         pp_c_ws_string (pp, "enum");
397       else
398         pp_c_ws_string (pp, M_("<tag-error>"));
399
400       if (TYPE_NAME (t))
401         pp_id_expression (pp, TYPE_NAME (t));
402       else
403         pp_c_ws_string (pp, M_("<anonymous>"));
404       break;
405
406     default:
407       pp_unsupported_tree (pp, t);
408       break;
409     }
410 }
411
412 /* specifier-qualifier-list:
413       type-specifier specifier-qualifier-list-opt
414       type-qualifier specifier-qualifier-list-opt
415
416
417   Implementation note:  Because of the non-linearities in array or
418   function declarations, this routine prints not just the
419   specifier-qualifier-list of such entities or types of such entities,
420   but also the 'pointer' production part of their declarators.  The
421   remaining part is done by pp_declarator or pp_c_abstract_declarator.  */
422
423 void
424 pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree t)
425 {
426   const enum tree_code code = TREE_CODE (t);
427
428   if (TREE_CODE (t) != POINTER_TYPE)
429     pp_c_type_qualifier_list (pp, t);
430   switch (code)
431     {
432     case REFERENCE_TYPE:
433     case POINTER_TYPE:
434       {
435         /* Get the types-specifier of this type.  */
436         tree pointee = strip_pointer_operator (TREE_TYPE (t));
437         pp_c_specifier_qualifier_list (pp, pointee);
438         if (TREE_CODE (pointee) == ARRAY_TYPE
439             || TREE_CODE (pointee) == FUNCTION_TYPE)
440           {
441             pp_c_whitespace (pp);
442             pp_c_left_paren (pp);
443           }
444         else if (!c_dialect_cxx ())
445           pp_c_whitespace (pp);
446         pp_ptr_operator (pp, t);
447       }
448       break;
449
450     case FUNCTION_TYPE:
451     case ARRAY_TYPE:
452       pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
453       break;
454
455     case VECTOR_TYPE:
456     case COMPLEX_TYPE:
457       pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
458       if (code == COMPLEX_TYPE)
459         pp_c_ws_string (pp, flag_isoc99 ? "_Complex" : "__complex__");
460       else if (code == VECTOR_TYPE)
461         {
462           pp_c_ws_string (pp, "__vector");
463           pp_c_left_bracket (pp);
464           pp_wide_integer (pp, TYPE_VECTOR_SUBPARTS (t));
465           pp_c_right_bracket (pp);
466         }
467       break;
468
469     default:
470       pp_simple_type_specifier (pp, t);
471       break;
472     }
473 }
474
475 /* parameter-type-list:
476       parameter-list
477       parameter-list , ...
478
479    parameter-list:
480       parameter-declaration
481       parameter-list , parameter-declaration
482
483    parameter-declaration:
484       declaration-specifiers declarator
485       declaration-specifiers abstract-declarator(opt)   */
486
487 void
488 pp_c_parameter_type_list (c_pretty_printer *pp, tree t)
489 {
490   bool want_parm_decl = DECL_P (t) && !(pp->flags & pp_c_flag_abstract);
491   tree parms = want_parm_decl ? DECL_ARGUMENTS (t) :  TYPE_ARG_TYPES (t);
492   pp_c_left_paren (pp);
493   if (parms == void_list_node)
494     pp_c_ws_string (pp, "void");
495   else
496     {
497       bool first = true;
498       for ( ; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
499         {
500           if (!first)
501             pp_separate_with (pp, ',');
502           first = false;
503           pp_declaration_specifiers
504             (pp, want_parm_decl ? parms : TREE_VALUE (parms));
505           if (want_parm_decl)
506             pp_declarator (pp, parms);
507           else
508             pp_abstract_declarator (pp, TREE_VALUE (parms));
509         }
510     }
511   pp_c_right_paren (pp);
512 }
513
514 /* abstract-declarator:
515       pointer
516       pointer(opt) direct-abstract-declarator  */
517
518 static void
519 pp_c_abstract_declarator (c_pretty_printer *pp, tree t)
520 {
521   if (TREE_CODE (t) == POINTER_TYPE)
522     {
523       if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
524           || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
525         pp_c_right_paren (pp);
526       t = TREE_TYPE (t);
527     }
528
529   pp_direct_abstract_declarator (pp, t);
530 }
531
532 /* direct-abstract-declarator:
533       ( abstract-declarator )
534       direct-abstract-declarator(opt) [ assignment-expression(opt) ]
535       direct-abstract-declarator(opt) [ * ]
536       direct-abstract-declarator(opt) ( parameter-type-list(opt) )  */
537
538 void
539 pp_c_direct_abstract_declarator (c_pretty_printer *pp, tree t)
540 {
541   switch (TREE_CODE (t))
542     {
543     case POINTER_TYPE:
544       pp_abstract_declarator (pp, t);
545       break;
546
547     case FUNCTION_TYPE:
548       pp_c_parameter_type_list (pp, t);
549       pp_direct_abstract_declarator (pp, TREE_TYPE (t));
550       break;
551
552     case ARRAY_TYPE:
553       pp_c_left_bracket (pp);
554       if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t)))
555         {
556           tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (t));
557           tree type = TREE_TYPE (maxval);
558
559           if (host_integerp (maxval, 0))
560             pp_wide_integer (pp, tree_low_cst (maxval, 0) + 1);
561           else
562             pp_expression (pp, fold_build2 (PLUS_EXPR, type, maxval,
563                                             build_int_cst (type, 1)));
564         }
565       pp_c_right_bracket (pp);
566       pp_direct_abstract_declarator (pp, TREE_TYPE (t));
567       break;
568
569     case IDENTIFIER_NODE:
570     case VOID_TYPE:
571     case BOOLEAN_TYPE:
572     case INTEGER_TYPE:
573     case REAL_TYPE:
574     case FIXED_POINT_TYPE:
575     case ENUMERAL_TYPE:
576     case RECORD_TYPE:
577     case UNION_TYPE:
578     case VECTOR_TYPE:
579     case COMPLEX_TYPE:
580     case TYPE_DECL:
581       break;
582
583     default:
584       pp_unsupported_tree (pp, t);
585       break;
586     }
587 }
588
589 /* type-name:
590       specifier-qualifier-list  abstract-declarator(opt)  */
591
592 void
593 pp_c_type_id (c_pretty_printer *pp, tree t)
594 {
595   pp_c_specifier_qualifier_list (pp, t);
596   pp_abstract_declarator (pp, t);
597 }
598
599 /* storage-class-specifier:
600       typedef
601       extern
602       static
603       auto
604       register  */
605
606 void
607 pp_c_storage_class_specifier (c_pretty_printer *pp, tree t)
608 {
609   if (TREE_CODE (t) == TYPE_DECL)
610     pp_c_ws_string (pp, "typedef");
611   else if (DECL_P (t))
612     {
613       if (DECL_REGISTER (t))
614         pp_c_ws_string (pp, "register");
615       else if (TREE_STATIC (t) && TREE_CODE (t) == VAR_DECL)
616         pp_c_ws_string (pp, "static");
617     }
618 }
619
620 /* function-specifier:
621       inline   */
622
623 void
624 pp_c_function_specifier (c_pretty_printer *pp, tree t)
625 {
626   if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t))
627     pp_c_ws_string (pp, "inline");
628 }
629
630 /* declaration-specifiers:
631       storage-class-specifier declaration-specifiers(opt)
632       type-specifier declaration-specifiers(opt)
633       type-qualifier declaration-specifiers(opt)
634       function-specifier declaration-specifiers(opt)  */
635
636 void
637 pp_c_declaration_specifiers (c_pretty_printer *pp, tree t)
638 {
639   pp_storage_class_specifier (pp, t);
640   pp_function_specifier (pp, t);
641   pp_c_specifier_qualifier_list (pp, DECL_P (t) ?  TREE_TYPE (t) : t);
642 }
643
644 /* direct-declarator
645       identifier
646       ( declarator )
647       direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
648       direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
649       direct-declarator [ type-qualifier-list static assignment-expression ]
650       direct-declarator [ type-qualifier-list * ]
651       direct-declarator ( parameter-type-list )
652       direct-declarator ( identifier-list(opt) )  */
653
654 void
655 pp_c_direct_declarator (c_pretty_printer *pp, tree t)
656 {
657   switch (TREE_CODE (t))
658     {
659     case VAR_DECL:
660     case PARM_DECL:
661     case TYPE_DECL:
662     case FIELD_DECL:
663     case LABEL_DECL:
664       pp_c_space_for_pointer_operator (pp, TREE_TYPE (t));
665       pp_c_tree_decl_identifier (pp, t);
666       break;
667
668     case ARRAY_TYPE:
669     case POINTER_TYPE:
670       pp_abstract_declarator (pp, TREE_TYPE (t));
671       break;
672
673     case FUNCTION_TYPE:
674       pp_parameter_list (pp, t);
675       pp_abstract_declarator (pp, TREE_TYPE (t));
676       break;
677
678     case FUNCTION_DECL:
679       pp_c_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
680       pp_c_tree_decl_identifier (pp, t);
681       if (pp_c_base (pp)->flags & pp_c_flag_abstract)
682         pp_abstract_declarator (pp, TREE_TYPE (t));
683       else
684         {
685           pp_parameter_list (pp, t);
686           pp_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t)));
687         }
688       break;
689
690     case INTEGER_TYPE:
691     case REAL_TYPE:
692     case FIXED_POINT_TYPE:
693     case ENUMERAL_TYPE:
694     case UNION_TYPE:
695     case RECORD_TYPE:
696       break;
697
698     default:
699       pp_unsupported_tree (pp, t);
700       break;
701     }
702 }
703
704
705 /* declarator:
706       pointer(opt)  direct-declarator   */
707
708 void
709 pp_c_declarator (c_pretty_printer *pp, tree t)
710 {
711   switch (TREE_CODE (t))
712     {
713     case INTEGER_TYPE:
714     case REAL_TYPE:
715     case FIXED_POINT_TYPE:
716     case ENUMERAL_TYPE:
717     case UNION_TYPE:
718     case RECORD_TYPE:
719       break;
720
721     case VAR_DECL:
722     case PARM_DECL:
723     case FIELD_DECL:
724     case ARRAY_TYPE:
725     case FUNCTION_TYPE:
726     case FUNCTION_DECL:
727     case TYPE_DECL:
728       pp_direct_declarator (pp, t);
729     break;
730
731
732     default:
733       pp_unsupported_tree (pp, t);
734       break;
735     }
736 }
737
738 /* declaration:
739       declaration-specifiers init-declarator-list(opt) ;  */
740
741 void
742 pp_c_declaration (c_pretty_printer *pp, tree t)
743 {
744   pp_declaration_specifiers (pp, t);
745   pp_c_init_declarator (pp, t);
746 }
747
748 /* Pretty-print ATTRIBUTES using GNU C extension syntax.  */
749
750 void
751 pp_c_attributes (c_pretty_printer *pp, tree attributes)
752 {
753   if (attributes == NULL_TREE)
754     return;
755
756   pp_c_ws_string (pp, "__attribute__");
757   pp_c_left_paren (pp);
758   pp_c_left_paren (pp);
759   for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes))
760     {
761       pp_tree_identifier (pp, TREE_PURPOSE (attributes));
762       if (TREE_VALUE (attributes))
763         pp_c_call_argument_list (pp, TREE_VALUE (attributes));
764
765       if (TREE_CHAIN (attributes))
766         pp_separate_with (pp, ',');
767     }
768   pp_c_right_paren (pp);
769   pp_c_right_paren (pp);
770 }
771
772 /* function-definition:
773       declaration-specifiers declarator compound-statement  */
774
775 void
776 pp_c_function_definition (c_pretty_printer *pp, tree t)
777 {
778   pp_declaration_specifiers (pp, t);
779   pp_declarator (pp, t);
780   pp_needs_newline (pp) = true;
781   pp_statement (pp, DECL_SAVED_TREE (t));
782   pp_newline (pp);
783   pp_flush (pp);
784 }
785
786 \f
787 /* Expressions.  */
788
789 /* Print out a c-char.  This is called solely for characters which are
790    in the *target* execution character set.  We ought to convert them
791    back to the *host* execution character set before printing, but we
792    have no way to do this at present.  A decent compromise is to print
793    all characters as if they were in the host execution character set,
794    and not attempt to recover any named escape characters, but render
795    all unprintables as octal escapes.  If the host and target character
796    sets are the same, this produces relatively readable output.  If they
797    are not the same, strings may appear as gibberish, but that's okay
798    (in fact, it may well be what the reader wants, e.g. if they are looking
799    to see if conversion to the target character set happened correctly).
800
801    A special case: we need to prefix \, ", and ' with backslashes.  It is
802    correct to do so for the *host*'s \, ", and ', because the rest of the
803    file appears in the host character set.  */
804
805 static void
806 pp_c_char (c_pretty_printer *pp, int c)
807 {
808   if (ISPRINT (c))
809     {
810       switch (c)
811         {
812         case '\\': pp_string (pp, "\\\\"); break;
813         case '\'': pp_string (pp, "\\\'"); break;
814         case '\"': pp_string (pp, "\\\""); break;
815         default:   pp_character (pp, c);
816         }
817     }
818   else
819     pp_scalar (pp, "\\%03o", (unsigned) c);
820 }
821
822 /* Print out a STRING literal.  */
823
824 void
825 pp_c_string_literal (c_pretty_printer *pp, tree s)
826 {
827   const char *p = TREE_STRING_POINTER (s);
828   int n = TREE_STRING_LENGTH (s) - 1;
829   int i;
830   pp_doublequote (pp);
831   for (i = 0; i < n; ++i)
832     pp_c_char (pp, p[i]);
833   pp_doublequote (pp);
834 }
835
836 /* Pretty-print an INTEGER literal.  */
837
838 static void
839 pp_c_integer_constant (c_pretty_printer *pp, tree i)
840 {
841   tree type = TREE_TYPE (i);
842
843   if (TREE_INT_CST_HIGH (i) == 0)
844     pp_wide_integer (pp, TREE_INT_CST_LOW (i));
845   else
846     {
847       unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (i);
848       HOST_WIDE_INT high = TREE_INT_CST_HIGH (i);
849       if (tree_int_cst_sgn (i) < 0)
850         {
851           pp_character (pp, '-');
852           high = ~high + !low;
853           low = -low;
854         }
855       sprintf (pp_buffer (pp)->digit_buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
856                (unsigned HOST_WIDE_INT) high, (unsigned HOST_WIDE_INT) low);
857       pp_string (pp, pp_buffer (pp)->digit_buffer);
858     }
859   if (TYPE_UNSIGNED (type))
860     pp_character (pp, 'u');
861   if (type == long_integer_type_node || type == long_unsigned_type_node)
862     pp_character (pp, 'l');
863   else if (type == long_long_integer_type_node
864            || type == long_long_unsigned_type_node)
865     pp_string (pp, "ll");
866 }
867
868 /* Print out a CHARACTER literal.  */
869
870 static void
871 pp_c_character_constant (c_pretty_printer *pp, tree c)
872 {
873   tree type = TREE_TYPE (c);
874   if (type == wchar_type_node)
875     pp_character (pp, 'L');
876   pp_quote (pp);
877   if (host_integerp (c, TYPE_UNSIGNED (type)))
878     pp_c_char (pp, tree_low_cst (c, TYPE_UNSIGNED (type)));
879   else
880     pp_scalar (pp, "\\x%x", (unsigned) TREE_INT_CST_LOW (c));
881   pp_quote (pp);
882 }
883
884 /* Print out a BOOLEAN literal.  */
885
886 static void
887 pp_c_bool_constant (c_pretty_printer *pp, tree b)
888 {
889   if (b == boolean_false_node)
890     {
891       if (c_dialect_cxx ())
892         pp_c_ws_string (pp, "false");
893       else if (flag_isoc99)
894         pp_c_ws_string (pp, "_False");
895       else
896         pp_unsupported_tree (pp, b);
897     }
898   else if (b == boolean_true_node)
899     {
900       if (c_dialect_cxx ())
901         pp_c_ws_string (pp, "true");
902       else if (flag_isoc99)
903         pp_c_ws_string (pp, "_True");
904       else
905         pp_unsupported_tree (pp, b);
906     }
907   else if (TREE_CODE (b) == INTEGER_CST)
908     pp_c_integer_constant (pp, b);
909   else
910     pp_unsupported_tree (pp, b);
911 }
912
913 /* Attempt to print out an ENUMERATOR.  Return true on success.  Else return
914    false; that means the value was obtained by a cast, in which case
915    print out the type-id part of the cast-expression -- the casted value
916    is then printed by pp_c_integer_literal.  */
917
918 static bool
919 pp_c_enumeration_constant (c_pretty_printer *pp, tree e)
920 {
921   bool value_is_named = true;
922   tree type = TREE_TYPE (e);
923   tree value;
924
925   /* Find the name of this constant.  */
926   for (value = TYPE_VALUES (type);
927        value != NULL_TREE && !tree_int_cst_equal (TREE_VALUE (value), e);
928        value = TREE_CHAIN (value))
929     ;
930
931   if (value != NULL_TREE)
932     pp_id_expression (pp, TREE_PURPOSE (value));
933   else
934     {
935       /* Value must have been cast.  */
936       pp_c_type_cast (pp, type);
937       value_is_named = false;
938     }
939
940   return value_is_named;
941 }
942
943 /* Print out a REAL value as a decimal-floating-constant.  */
944
945 static void
946 pp_c_floating_constant (c_pretty_printer *pp, tree r)
947 {
948   real_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_REAL_CST (r),
949                    sizeof (pp_buffer (pp)->digit_buffer), 0, 1);
950   pp_string (pp, pp_buffer(pp)->digit_buffer);
951   if (TREE_TYPE (r) == float_type_node)
952     pp_character (pp, 'f');
953   else if (TREE_TYPE (r) == long_double_type_node)
954     pp_character (pp, 'l');
955   else if (TREE_TYPE (r) == dfloat128_type_node)
956     pp_string (pp, "dl");
957   else if (TREE_TYPE (r) == dfloat64_type_node)
958     pp_string (pp, "dd");
959   else if (TREE_TYPE (r) == dfloat32_type_node)
960     pp_string (pp, "df");
961 }
962
963 /* Print out a FIXED value as a decimal-floating-constant.  */
964
965 static void
966 pp_c_fixed_constant (c_pretty_printer *pp, tree r)
967 {
968   fixed_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_FIXED_CST (r),
969                    sizeof (pp_buffer (pp)->digit_buffer));
970   pp_string (pp, pp_buffer(pp)->digit_buffer);
971 }
972
973 /* Pretty-print a compound literal expression.  GNU extensions include
974    vector constants.  */
975
976 static void
977 pp_c_compound_literal (c_pretty_printer *pp, tree e)
978 {
979   tree type = TREE_TYPE (e);
980   pp_c_type_cast (pp, type);
981
982   switch (TREE_CODE (type))
983     {
984     case RECORD_TYPE:
985     case UNION_TYPE:
986     case ARRAY_TYPE:
987     case VECTOR_TYPE:
988     case COMPLEX_TYPE:
989       pp_c_brace_enclosed_initializer_list (pp, e);
990       break;
991
992     default:
993       pp_unsupported_tree (pp, e);
994       break;
995     }
996 }
997
998 /* Pretty-print a COMPLEX_EXPR expression.  */
999
1000 static void
1001 pp_c_complex_expr (c_pretty_printer *pp, tree e)
1002 {
1003   /* Handle a few common special cases, otherwise fallback
1004      to printing it as compound literal.  */
1005   tree type = TREE_TYPE (e);
1006   tree realexpr = TREE_OPERAND (e, 0);
1007   tree imagexpr = TREE_OPERAND (e, 1);
1008
1009   /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE.  */
1010   if (TREE_CODE (realexpr) == NOP_EXPR
1011       && TREE_CODE (imagexpr) == NOP_EXPR
1012       && TREE_TYPE (realexpr) == TREE_TYPE (type)
1013       && TREE_TYPE (imagexpr) == TREE_TYPE (type)
1014       && TREE_CODE (TREE_OPERAND (realexpr, 0)) == REALPART_EXPR
1015       && TREE_CODE (TREE_OPERAND (imagexpr, 0)) == IMAGPART_EXPR
1016       && TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0)
1017          == TREE_OPERAND (TREE_OPERAND (imagexpr, 0), 0))
1018     {
1019       pp_c_type_cast (pp, type);
1020       pp_expression (pp, TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0));
1021       return;
1022     }
1023
1024   /* Cast of an scalar expression to COMPLEX_TYPE.  */
1025   if ((integer_zerop (imagexpr) || real_zerop (imagexpr))
1026       && TREE_TYPE (realexpr) == TREE_TYPE (type))
1027     {
1028       pp_c_type_cast (pp, type);
1029       if (TREE_CODE (realexpr) == NOP_EXPR)
1030         realexpr = TREE_OPERAND (realexpr, 0);
1031       pp_expression (pp, realexpr);
1032       return;
1033     }
1034
1035   pp_c_compound_literal (pp, e);
1036 }
1037
1038 /* constant:
1039       integer-constant
1040       floating-constant
1041       fixed-point-constant
1042       enumeration-constant
1043       character-constant   */
1044
1045 void
1046 pp_c_constant (c_pretty_printer *pp, tree e)
1047 {
1048   const enum tree_code code = TREE_CODE (e);
1049
1050   switch (code)
1051     {
1052     case INTEGER_CST:
1053       {
1054         tree type = TREE_TYPE (e);
1055         if (type == boolean_type_node)
1056           pp_c_bool_constant (pp, e);
1057         else if (type == char_type_node)
1058           pp_c_character_constant (pp, e);
1059         else if (TREE_CODE (type) == ENUMERAL_TYPE
1060                  && pp_c_enumeration_constant (pp, e))
1061           ;
1062         else
1063           pp_c_integer_constant (pp, e);
1064       }
1065       break;
1066
1067     case REAL_CST:
1068       pp_c_floating_constant (pp, e);
1069       break;
1070
1071     case FIXED_CST:
1072       pp_c_fixed_constant (pp, e);
1073       break;
1074
1075     case STRING_CST:
1076       pp_c_string_literal (pp, e);
1077       break;
1078
1079     case COMPLEX_CST:
1080       /* Sometimes, we are confused and we think a complex literal
1081          is a constant.  Such thing is a compound literal which
1082          grammatically belongs to postfix-expr production.  */
1083       pp_c_compound_literal (pp, e);
1084       break;
1085
1086     default:
1087       pp_unsupported_tree (pp, e);
1088       break;
1089     }
1090 }
1091
1092 /* Pretty-print a string such as an identifier, without changing its
1093    encoding, preceded by whitespace is necessary.  */
1094
1095 void
1096 pp_c_ws_string (c_pretty_printer *pp, const char *str)
1097 {
1098   pp_c_maybe_whitespace (pp);
1099   pp_string (pp, str);
1100   pp_base (pp)->padding = pp_before;
1101 }
1102
1103 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1104    that need converting to the locale encoding, preceded by whitespace
1105    is necessary.  */
1106
1107 void
1108 pp_c_identifier (c_pretty_printer *pp, const char *id)
1109 {
1110   pp_c_maybe_whitespace (pp);
1111   pp_identifier (pp, id);
1112   pp_base (pp)->padding = pp_before;
1113 }
1114
1115 /* Pretty-print a C primary-expression.
1116    primary-expression:
1117       identifier
1118       constant
1119       string-literal
1120       ( expression )   */
1121
1122 void
1123 pp_c_primary_expression (c_pretty_printer *pp, tree e)
1124 {
1125   switch (TREE_CODE (e))
1126     {
1127     case VAR_DECL:
1128     case PARM_DECL:
1129     case FIELD_DECL:
1130     case CONST_DECL:
1131     case FUNCTION_DECL:
1132     case LABEL_DECL:
1133       pp_c_tree_decl_identifier (pp, e);
1134       break;
1135
1136     case IDENTIFIER_NODE:
1137       pp_c_tree_identifier (pp, e);
1138       break;
1139
1140     case ERROR_MARK:
1141       pp_c_ws_string (pp, M_("<erroneous-expression>"));
1142       break;
1143
1144     case RESULT_DECL:
1145       pp_c_ws_string (pp, M_("<return-value>"));
1146       break;
1147
1148     case INTEGER_CST:
1149     case REAL_CST:
1150     case FIXED_CST:
1151     case STRING_CST:
1152       pp_c_constant (pp, e);
1153       break;
1154
1155     case TARGET_EXPR:
1156       pp_c_ws_string (pp, "__builtin_memcpy");
1157       pp_c_left_paren (pp);
1158       pp_ampersand (pp);
1159       pp_primary_expression (pp, TREE_OPERAND (e, 0));
1160       pp_separate_with (pp, ',');
1161       pp_ampersand (pp);
1162       pp_initializer (pp, TREE_OPERAND (e, 1));
1163       if (TREE_OPERAND (e, 2))
1164         {
1165           pp_separate_with (pp, ',');
1166           pp_c_expression (pp, TREE_OPERAND (e, 2));
1167         }
1168       pp_c_right_paren (pp);
1169       break;
1170
1171     default:
1172       /* FIXME:  Make sure we won't get into an infinite loop.  */
1173       pp_c_left_paren (pp);
1174       pp_expression (pp, e);
1175       pp_c_right_paren (pp);
1176       break;
1177     }
1178 }
1179
1180 /* Print out a C initializer -- also support C compound-literals.
1181    initializer:
1182       assignment-expression:
1183       { initializer-list }
1184       { initializer-list , }   */
1185
1186 static void
1187 pp_c_initializer (c_pretty_printer *pp, tree e)
1188 {
1189   if (TREE_CODE (e) == CONSTRUCTOR)
1190     pp_c_brace_enclosed_initializer_list (pp, e);
1191   else
1192     pp_expression (pp, e);
1193 }
1194
1195 /* init-declarator:
1196       declarator:
1197       declarator = initializer   */
1198
1199 void
1200 pp_c_init_declarator (c_pretty_printer *pp, tree t)
1201 {
1202   pp_declarator (pp, t);
1203   /* We don't want to output function definitions here.  There are handled
1204      elsewhere (and the syntactic form is bogus anyway).  */
1205   if (TREE_CODE (t) != FUNCTION_DECL && DECL_INITIAL (t))
1206     {
1207       tree init = DECL_INITIAL (t);
1208       /* This C++ bit is handled here because it is easier to do so.
1209          In templates, the C++ parser builds a TREE_LIST for a
1210          direct-initialization; the TREE_PURPOSE is the variable to
1211          initialize and the TREE_VALUE is the initializer.  */
1212       if (TREE_CODE (init) == TREE_LIST)
1213         {
1214           pp_c_left_paren (pp);
1215           pp_expression (pp, TREE_VALUE (init));
1216           pp_right_paren (pp);
1217         }
1218       else
1219         {
1220           pp_space (pp);
1221           pp_equal (pp);
1222           pp_space (pp);
1223           pp_c_initializer (pp, init);
1224         }
1225     }
1226 }
1227
1228 /* initializer-list:
1229       designation(opt) initializer
1230       initializer-list , designation(opt) initializer
1231
1232    designation:
1233       designator-list =
1234
1235    designator-list:
1236       designator
1237       designator-list designator
1238
1239    designator:
1240       [ constant-expression ]
1241       identifier   */
1242
1243 static void
1244 pp_c_initializer_list (c_pretty_printer *pp, tree e)
1245 {
1246   tree type = TREE_TYPE (e);
1247   const enum tree_code code = TREE_CODE (type);
1248
1249   if (TREE_CODE (e) == CONSTRUCTOR)
1250     {
1251       pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e));
1252       return;
1253     }
1254
1255   switch (code)
1256     {
1257     case RECORD_TYPE:
1258     case UNION_TYPE:
1259     case ARRAY_TYPE:
1260       {
1261         tree init = TREE_OPERAND (e, 0);
1262         for (; init != NULL_TREE; init = TREE_CHAIN (init))
1263           {
1264             if (code == RECORD_TYPE || code == UNION_TYPE)
1265               {
1266                 pp_c_dot (pp);
1267                 pp_c_primary_expression (pp, TREE_PURPOSE (init));
1268               }
1269             else
1270               {
1271                 pp_c_left_bracket (pp);
1272                 if (TREE_PURPOSE (init))
1273                   pp_c_constant (pp, TREE_PURPOSE (init));
1274                 pp_c_right_bracket (pp);
1275               }
1276             pp_c_whitespace (pp);
1277             pp_equal (pp);
1278             pp_c_whitespace (pp);
1279             pp_initializer (pp, TREE_VALUE (init));
1280             if (TREE_CHAIN (init))
1281               pp_separate_with (pp, ',');
1282           }
1283       }
1284       return;
1285
1286     case VECTOR_TYPE:
1287       if (TREE_CODE (e) == VECTOR_CST)
1288         pp_c_expression_list (pp, TREE_VECTOR_CST_ELTS (e));
1289       else
1290         break;
1291       return;
1292
1293     case COMPLEX_TYPE:
1294       if (TREE_CODE (e) == COMPLEX_CST || TREE_CODE (e) == COMPLEX_EXPR)
1295         {
1296           const bool cst = TREE_CODE (e) == COMPLEX_CST;
1297           pp_expression (pp, cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0));
1298           pp_separate_with (pp, ',');
1299           pp_expression (pp, cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1));
1300         }
1301       else
1302         break;
1303       return;
1304
1305     default:
1306       break;
1307     }
1308
1309   pp_unsupported_tree (pp, type);
1310 }
1311
1312 /* Pretty-print a brace-enclosed initializer-list.  */
1313
1314 static void
1315 pp_c_brace_enclosed_initializer_list (c_pretty_printer *pp, tree l)
1316 {
1317   pp_c_left_brace (pp);
1318   pp_c_initializer_list (pp, l);
1319   pp_c_right_brace (pp);
1320 }
1321
1322
1323 /*  This is a convenient function, used to bridge gap between C and C++
1324     grammars.
1325
1326     id-expression:
1327        identifier  */
1328
1329 void
1330 pp_c_id_expression (c_pretty_printer *pp, tree t)
1331 {
1332   switch (TREE_CODE (t))
1333     {
1334     case VAR_DECL:
1335     case PARM_DECL:
1336     case CONST_DECL:
1337     case TYPE_DECL:
1338     case FUNCTION_DECL:
1339     case FIELD_DECL:
1340     case LABEL_DECL:
1341       pp_c_tree_decl_identifier (pp, t);
1342       break;
1343
1344     case IDENTIFIER_NODE:
1345       pp_c_tree_identifier (pp, t);
1346       break;
1347
1348     default:
1349       pp_unsupported_tree (pp, t);
1350       break;
1351     }
1352 }
1353
1354 /* postfix-expression:
1355       primary-expression
1356       postfix-expression [ expression ]
1357       postfix-expression ( argument-expression-list(opt) )
1358       postfix-expression . identifier
1359       postfix-expression -> identifier
1360       postfix-expression ++
1361       postfix-expression --
1362       ( type-name ) { initializer-list }
1363       ( type-name ) { initializer-list , }  */
1364
1365 void
1366 pp_c_postfix_expression (c_pretty_printer *pp, tree e)
1367 {
1368   enum tree_code code = TREE_CODE (e);
1369   switch (code)
1370     {
1371     case POSTINCREMENT_EXPR:
1372     case POSTDECREMENT_EXPR:
1373       pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1374       pp_string (pp, code == POSTINCREMENT_EXPR ? "++" : "--");
1375       break;
1376
1377     case ARRAY_REF:
1378       pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1379       pp_c_left_bracket (pp);
1380       pp_expression (pp, TREE_OPERAND (e, 1));
1381       pp_c_right_bracket (pp);
1382       break;
1383
1384     case CALL_EXPR:
1385       {
1386         call_expr_arg_iterator iter;
1387         tree arg;
1388         pp_postfix_expression (pp, CALL_EXPR_FN (e));
1389         pp_c_left_paren (pp);
1390         FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
1391           {
1392             pp_expression (pp, arg);
1393             if (more_call_expr_args_p (&iter))
1394               pp_separate_with (pp, ',');
1395           }
1396         pp_c_right_paren (pp);
1397         break;
1398       }
1399
1400     case UNORDERED_EXPR:
1401       pp_c_ws_string (pp, flag_isoc99
1402                            ? "isunordered"
1403                            : "__builtin_isunordered");
1404       goto two_args_fun;
1405
1406     case ORDERED_EXPR:
1407       pp_c_ws_string (pp, flag_isoc99
1408                            ? "!isunordered"
1409                            : "!__builtin_isunordered");
1410       goto two_args_fun;
1411
1412     case UNLT_EXPR:
1413       pp_c_ws_string (pp, flag_isoc99
1414                            ? "!isgreaterequal"
1415                            : "!__builtin_isgreaterequal");
1416       goto two_args_fun;
1417
1418     case UNLE_EXPR:
1419       pp_c_ws_string (pp, flag_isoc99
1420                            ? "!isgreater"
1421                            : "!__builtin_isgreater");
1422       goto two_args_fun;
1423
1424     case UNGT_EXPR:
1425       pp_c_ws_string (pp, flag_isoc99
1426                            ? "!islessequal"
1427                            : "!__builtin_islessequal");
1428       goto two_args_fun;
1429
1430     case UNGE_EXPR:
1431       pp_c_ws_string (pp, flag_isoc99
1432                            ? "!isless"
1433                            : "!__builtin_isless");
1434       goto two_args_fun;
1435
1436     case UNEQ_EXPR:
1437       pp_c_ws_string (pp, flag_isoc99
1438                            ? "!islessgreater"
1439                            : "!__builtin_islessgreater");
1440       goto two_args_fun;
1441
1442     case LTGT_EXPR:
1443       pp_c_ws_string (pp, flag_isoc99
1444                            ? "islessgreater"
1445                            : "__builtin_islessgreater");
1446       goto two_args_fun;
1447
1448     two_args_fun:
1449       pp_c_left_paren (pp);
1450       pp_expression (pp, TREE_OPERAND (e, 0));
1451       pp_separate_with (pp, ',');
1452       pp_expression (pp, TREE_OPERAND (e, 1));
1453       pp_c_right_paren (pp);
1454       break;
1455
1456     case ABS_EXPR:
1457       pp_c_ws_string (pp, "__builtin_abs");
1458       pp_c_left_paren (pp);
1459       pp_expression (pp, TREE_OPERAND (e, 0));
1460       pp_c_right_paren (pp);
1461       break;
1462
1463     case COMPONENT_REF:
1464       {
1465         tree object = TREE_OPERAND (e, 0);
1466         if (TREE_CODE (object) == INDIRECT_REF)
1467           {
1468             pp_postfix_expression (pp, TREE_OPERAND (object, 0));
1469             pp_c_arrow (pp);
1470           }
1471         else
1472           {
1473             pp_postfix_expression (pp, object);
1474             pp_c_dot (pp);
1475           }
1476         pp_expression (pp, TREE_OPERAND (e, 1));
1477       }
1478       break;
1479
1480     case BIT_FIELD_REF:
1481       {
1482         tree type = TREE_TYPE (e);
1483
1484         type = signed_or_unsigned_type_for (TYPE_UNSIGNED (type), type);
1485         if (type
1486             && tree_int_cst_equal (TYPE_SIZE (type), TREE_OPERAND (e, 1)))
1487           {
1488             HOST_WIDE_INT bitpos = tree_low_cst (TREE_OPERAND (e, 2), 0);
1489             HOST_WIDE_INT size = tree_low_cst (TYPE_SIZE (type), 0);
1490             if ((bitpos % size) == 0)
1491               {
1492                 pp_c_left_paren (pp);
1493                 pp_c_left_paren (pp);
1494                 pp_type_id (pp, type);
1495                 pp_c_star (pp);
1496                 pp_c_right_paren (pp);
1497                 pp_c_ampersand (pp);
1498                 pp_expression (pp, TREE_OPERAND (e, 0));
1499                 pp_c_right_paren (pp);
1500                 pp_c_left_bracket (pp);
1501                 pp_wide_integer (pp, bitpos / size);
1502                 pp_c_right_bracket (pp);
1503                 break;
1504               }
1505           }
1506         pp_unsupported_tree (pp, e);
1507       }
1508       break;
1509
1510     case COMPLEX_CST:
1511     case VECTOR_CST:
1512       pp_c_compound_literal (pp, e);
1513       break;
1514
1515     case COMPLEX_EXPR:
1516       pp_c_complex_expr (pp, e);
1517       break;
1518
1519     case COMPOUND_LITERAL_EXPR:
1520       e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e));
1521       /* Fall through.  */
1522     case CONSTRUCTOR:
1523       pp_initializer (pp, e);
1524       break;
1525
1526     case VA_ARG_EXPR:
1527       pp_c_ws_string (pp, "__builtin_va_arg");
1528       pp_c_left_paren (pp);
1529       pp_assignment_expression (pp, TREE_OPERAND (e, 0));
1530       pp_separate_with (pp, ',');
1531       pp_type_id (pp, TREE_TYPE (e));
1532       pp_c_right_paren (pp);
1533       break;
1534
1535     case ADDR_EXPR:
1536       if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
1537         {
1538           pp_c_id_expression (pp, TREE_OPERAND (e, 0));
1539           break;
1540         }
1541       /* else fall through.  */
1542
1543     default:
1544       pp_primary_expression (pp, e);
1545       break;
1546     }
1547 }
1548
1549 /* Print out an expression-list; E is expected to be a TREE_LIST.  */
1550
1551 void
1552 pp_c_expression_list (c_pretty_printer *pp, tree e)
1553 {
1554   for (; e != NULL_TREE; e = TREE_CHAIN (e))
1555     {
1556       pp_expression (pp, TREE_VALUE (e));
1557       if (TREE_CHAIN (e))
1558         pp_separate_with (pp, ',');
1559     }
1560 }
1561
1562 /* Print out V, which contains the elements of a constructor.  */
1563
1564 void
1565 pp_c_constructor_elts (c_pretty_printer *pp, VEC(constructor_elt,gc) *v)
1566 {
1567   unsigned HOST_WIDE_INT ix;
1568   tree value;
1569
1570   FOR_EACH_CONSTRUCTOR_VALUE (v, ix, value)
1571     {
1572       pp_expression (pp, value);
1573       if (ix != VEC_length (constructor_elt, v) - 1)
1574         pp_separate_with (pp, ',');
1575     }
1576 }
1577
1578 /* Print out an expression-list in parens, as if it were the argument
1579    list to a function.  */
1580
1581 void
1582 pp_c_call_argument_list (c_pretty_printer *pp, tree t)
1583 {
1584   pp_c_left_paren (pp);
1585   if (t && TREE_CODE (t) == TREE_LIST)
1586     pp_c_expression_list (pp, t);
1587   pp_c_right_paren (pp);
1588 }
1589
1590 /* unary-expression:
1591       postfix-expression
1592       ++ cast-expression
1593       -- cast-expression
1594       unary-operator cast-expression
1595       sizeof unary-expression
1596       sizeof ( type-id )
1597
1598   unary-operator: one of
1599       * &  + - ! ~
1600
1601    GNU extensions.
1602    unary-expression:
1603       __alignof__ unary-expression
1604       __alignof__ ( type-id )
1605       __real__ unary-expression
1606       __imag__ unary-expression  */
1607
1608 void
1609 pp_c_unary_expression (c_pretty_printer *pp, tree e)
1610 {
1611   enum tree_code code = TREE_CODE (e);
1612   switch (code)
1613     {
1614     case PREINCREMENT_EXPR:
1615     case PREDECREMENT_EXPR:
1616       pp_string (pp, code == PREINCREMENT_EXPR ? "++" : "--");
1617       pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
1618       break;
1619
1620     case ADDR_EXPR:
1621     case INDIRECT_REF:
1622     case NEGATE_EXPR:
1623     case BIT_NOT_EXPR:
1624     case TRUTH_NOT_EXPR:
1625     case CONJ_EXPR:
1626       /* String literal are used by address.  */
1627       if (code == ADDR_EXPR && TREE_CODE (TREE_OPERAND (e, 0)) != STRING_CST)
1628         pp_ampersand (pp);
1629       else if (code == INDIRECT_REF)
1630         pp_c_star (pp);
1631       else if (code == NEGATE_EXPR)
1632         pp_minus (pp);
1633       else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
1634         pp_complement (pp);
1635       else if (code == TRUTH_NOT_EXPR)
1636         pp_exclamation (pp);
1637       pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1638       break;
1639
1640     case REALPART_EXPR:
1641     case IMAGPART_EXPR:
1642       pp_c_ws_string (pp, code == REALPART_EXPR ? "__real__" : "__imag__");
1643       pp_c_whitespace (pp);
1644       pp_unary_expression (pp, TREE_OPERAND (e, 0));
1645       break;
1646
1647     default:
1648       pp_postfix_expression (pp, e);
1649       break;
1650     }
1651 }
1652
1653 /* cast-expression:
1654       unary-expression
1655       ( type-name ) cast-expression  */
1656
1657 void
1658 pp_c_cast_expression (c_pretty_printer *pp, tree e)
1659 {
1660   switch (TREE_CODE (e))
1661     {
1662     case FLOAT_EXPR:
1663     case FIX_TRUNC_EXPR:
1664     CASE_CONVERT:
1665     case VIEW_CONVERT_EXPR:
1666       pp_c_type_cast (pp, TREE_TYPE (e));
1667       pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1668       break;
1669
1670     default:
1671       pp_unary_expression (pp, e);
1672     }
1673 }
1674
1675 /* multiplicative-expression:
1676       cast-expression
1677       multiplicative-expression * cast-expression
1678       multiplicative-expression / cast-expression
1679       multiplicative-expression % cast-expression   */
1680
1681 static void
1682 pp_c_multiplicative_expression (c_pretty_printer *pp, tree e)
1683 {
1684   enum tree_code code = TREE_CODE (e);
1685   switch (code)
1686     {
1687     case MULT_EXPR:
1688     case TRUNC_DIV_EXPR:
1689     case TRUNC_MOD_EXPR:
1690       pp_multiplicative_expression (pp, TREE_OPERAND (e, 0));
1691       pp_c_whitespace (pp);
1692       if (code == MULT_EXPR)
1693         pp_c_star (pp);
1694       else if (code == TRUNC_DIV_EXPR)
1695         pp_slash (pp);
1696       else
1697         pp_modulo (pp);
1698       pp_c_whitespace (pp);
1699       pp_c_cast_expression (pp, TREE_OPERAND (e, 1));
1700       break;
1701
1702     default:
1703       pp_c_cast_expression (pp, e);
1704       break;
1705     }
1706 }
1707
1708 /* additive-expression:
1709       multiplicative-expression
1710       additive-expression + multiplicative-expression
1711       additive-expression - multiplicative-expression   */
1712
1713 static void
1714 pp_c_additive_expression (c_pretty_printer *pp, tree e)
1715 {
1716   enum tree_code code = TREE_CODE (e);
1717   switch (code)
1718     {
1719     case POINTER_PLUS_EXPR:
1720     case PLUS_EXPR:
1721     case MINUS_EXPR:
1722       pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
1723       pp_c_whitespace (pp);
1724       if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
1725         pp_plus (pp);
1726       else
1727         pp_minus (pp);
1728       pp_c_whitespace (pp);
1729       pp_multiplicative_expression (pp, TREE_OPERAND (e, 1));
1730       break;
1731
1732     default:
1733       pp_multiplicative_expression (pp, e);
1734       break;
1735     }
1736 }
1737
1738 /* additive-expression:
1739       additive-expression
1740       shift-expression << additive-expression
1741       shift-expression >> additive-expression   */
1742
1743 static void
1744 pp_c_shift_expression (c_pretty_printer *pp, tree e)
1745 {
1746   enum tree_code code = TREE_CODE (e);
1747   switch (code)
1748     {
1749     case LSHIFT_EXPR:
1750     case RSHIFT_EXPR:
1751       pp_c_shift_expression (pp, TREE_OPERAND (e, 0));
1752       pp_c_whitespace (pp);
1753       pp_string (pp, code == LSHIFT_EXPR ? "<<" : ">>");
1754       pp_c_whitespace (pp);
1755       pp_c_additive_expression (pp, TREE_OPERAND (e, 1));
1756       break;
1757
1758     default:
1759       pp_c_additive_expression (pp, e);
1760     }
1761 }
1762
1763 /* relational-expression:
1764       shift-expression
1765       relational-expression < shift-expression
1766       relational-expression > shift-expression
1767       relational-expression <= shift-expression
1768       relational-expression >= shift-expression   */
1769
1770 static void
1771 pp_c_relational_expression (c_pretty_printer *pp, tree e)
1772 {
1773   enum tree_code code = TREE_CODE (e);
1774   switch (code)
1775     {
1776     case LT_EXPR:
1777     case GT_EXPR:
1778     case LE_EXPR:
1779     case GE_EXPR:
1780       pp_c_relational_expression (pp, TREE_OPERAND (e, 0));
1781       pp_c_whitespace (pp);
1782       if (code == LT_EXPR)
1783         pp_less (pp);
1784       else if (code == GT_EXPR)
1785         pp_greater (pp);
1786       else if (code == LE_EXPR)
1787         pp_string (pp, "<=");
1788       else if (code == GE_EXPR)
1789         pp_string (pp, ">=");
1790       pp_c_whitespace (pp);
1791       pp_c_shift_expression (pp, TREE_OPERAND (e, 1));
1792       break;
1793
1794     default:
1795       pp_c_shift_expression (pp, e);
1796       break;
1797     }
1798 }
1799
1800 /* equality-expression:
1801       relational-expression
1802       equality-expression == relational-expression
1803       equality-equality != relational-expression  */
1804
1805 static void
1806 pp_c_equality_expression (c_pretty_printer *pp, tree e)
1807 {
1808   enum tree_code code = TREE_CODE (e);
1809   switch (code)
1810     {
1811     case EQ_EXPR:
1812     case NE_EXPR:
1813       pp_c_equality_expression (pp, TREE_OPERAND (e, 0));
1814       pp_c_whitespace (pp);
1815       pp_string (pp, code == EQ_EXPR ? "==" : "!=");
1816       pp_c_whitespace (pp);
1817       pp_c_relational_expression (pp, TREE_OPERAND (e, 1));
1818       break;
1819
1820     default:
1821       pp_c_relational_expression (pp, e);
1822       break;
1823     }
1824 }
1825
1826 /* AND-expression:
1827       equality-expression
1828       AND-expression & equality-equality   */
1829
1830 static void
1831 pp_c_and_expression (c_pretty_printer *pp, tree e)
1832 {
1833   if (TREE_CODE (e) == BIT_AND_EXPR)
1834     {
1835       pp_c_and_expression (pp, TREE_OPERAND (e, 0));
1836       pp_c_whitespace (pp);
1837       pp_ampersand (pp);
1838       pp_c_whitespace (pp);
1839       pp_c_equality_expression (pp, TREE_OPERAND (e, 1));
1840     }
1841   else
1842     pp_c_equality_expression (pp, e);
1843 }
1844
1845 /* exclusive-OR-expression:
1846      AND-expression
1847      exclusive-OR-expression ^ AND-expression  */
1848
1849 static void
1850 pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e)
1851 {
1852   if (TREE_CODE (e) == BIT_XOR_EXPR
1853       || TREE_CODE (e) == TRUTH_XOR_EXPR)
1854     {
1855       pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1856       if (TREE_CODE (e) == BIT_XOR_EXPR)
1857         pp_c_maybe_whitespace (pp);
1858       else
1859         pp_c_whitespace (pp);
1860       pp_carret (pp);
1861       pp_c_whitespace (pp);
1862       pp_c_and_expression (pp, TREE_OPERAND (e, 1));
1863     }
1864   else
1865     pp_c_and_expression (pp, e);
1866 }
1867
1868 /* inclusive-OR-expression:
1869      exclusive-OR-expression
1870      inclusive-OR-expression | exclusive-OR-expression  */
1871
1872 static void
1873 pp_c_inclusive_or_expression (c_pretty_printer *pp, tree e)
1874 {
1875   if (TREE_CODE (e) == BIT_IOR_EXPR)
1876     {
1877       pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1878       pp_c_whitespace (pp);
1879       pp_bar (pp);
1880       pp_c_whitespace (pp);
1881       pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 1));
1882     }
1883   else
1884     pp_c_exclusive_or_expression (pp, e);
1885 }
1886
1887 /* logical-AND-expression:
1888       inclusive-OR-expression
1889       logical-AND-expression && inclusive-OR-expression  */
1890
1891 static void
1892 pp_c_logical_and_expression (c_pretty_printer *pp, tree e)
1893 {
1894   if (TREE_CODE (e) == TRUTH_ANDIF_EXPR
1895       || TREE_CODE (e) == TRUTH_AND_EXPR)
1896     {
1897       pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0));
1898       pp_c_whitespace (pp);
1899       pp_string (pp, "&&");
1900       pp_c_whitespace (pp);
1901       pp_c_inclusive_or_expression (pp, TREE_OPERAND (e, 1));
1902     }
1903   else
1904     pp_c_inclusive_or_expression (pp, e);
1905 }
1906
1907 /* logical-OR-expression:
1908       logical-AND-expression
1909       logical-OR-expression || logical-AND-expression  */
1910
1911 void
1912 pp_c_logical_or_expression (c_pretty_printer *pp, tree e)
1913 {
1914   if (TREE_CODE (e) == TRUTH_ORIF_EXPR
1915       || TREE_CODE (e) == TRUTH_OR_EXPR)
1916     {
1917       pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
1918       pp_c_whitespace (pp);
1919       pp_string (pp, "||");
1920       pp_c_whitespace (pp);
1921       pp_c_logical_and_expression (pp, TREE_OPERAND (e, 1));
1922     }
1923   else
1924     pp_c_logical_and_expression (pp, e);
1925 }
1926
1927 /* conditional-expression:
1928       logical-OR-expression
1929       logical-OR-expression ? expression : conditional-expression  */
1930
1931 static void
1932 pp_c_conditional_expression (c_pretty_printer *pp, tree e)
1933 {
1934   if (TREE_CODE (e) == COND_EXPR)
1935     {
1936       pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
1937       pp_c_whitespace (pp);
1938       pp_question (pp);
1939       pp_c_whitespace (pp);
1940       pp_expression (pp, TREE_OPERAND (e, 1));
1941       pp_c_whitespace (pp);
1942       pp_colon (pp);
1943       pp_c_whitespace (pp);
1944       pp_c_conditional_expression (pp, TREE_OPERAND (e, 2));
1945     }
1946   else
1947     pp_c_logical_or_expression (pp, e);
1948 }
1949
1950
1951 /* assignment-expression:
1952       conditional-expression
1953       unary-expression assignment-operator  assignment-expression
1954
1955    assignment-expression: one of
1956       =    *=    /=    %=    +=    -=    >>=    <<=    &=    ^=    |=  */
1957
1958 static void
1959 pp_c_assignment_expression (c_pretty_printer *pp, tree e)
1960 {
1961   if (TREE_CODE (e) == MODIFY_EXPR
1962       || TREE_CODE (e) == INIT_EXPR)
1963     {
1964       pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
1965       pp_c_whitespace (pp);
1966       pp_equal (pp);
1967       pp_space (pp);
1968       pp_c_expression (pp, TREE_OPERAND (e, 1));
1969     }
1970   else
1971     pp_c_conditional_expression (pp, e);
1972 }
1973
1974 /* expression:
1975        assignment-expression
1976        expression , assignment-expression
1977
1978   Implementation note:  instead of going through the usual recursion
1979   chain, I take the liberty of dispatching nodes to the appropriate
1980   functions.  This makes some redundancy, but it worths it. That also
1981   prevents a possible infinite recursion between pp_c_primary_expression ()
1982   and pp_c_expression ().  */
1983
1984 void
1985 pp_c_expression (c_pretty_printer *pp, tree e)
1986 {
1987   switch (TREE_CODE (e))
1988     {
1989     case INTEGER_CST:
1990       pp_c_integer_constant (pp, e);
1991       break;
1992
1993     case REAL_CST:
1994       pp_c_floating_constant (pp, e);
1995       break;
1996
1997     case FIXED_CST:
1998       pp_c_fixed_constant (pp, e);
1999       break;
2000
2001     case STRING_CST:
2002       pp_c_string_literal (pp, e);
2003       break;
2004
2005     case IDENTIFIER_NODE:
2006     case FUNCTION_DECL:
2007     case VAR_DECL:
2008     case CONST_DECL:
2009     case PARM_DECL:
2010     case RESULT_DECL:
2011     case FIELD_DECL:
2012     case LABEL_DECL:
2013     case ERROR_MARK:
2014       pp_primary_expression (pp, e);
2015       break;
2016
2017     case POSTINCREMENT_EXPR:
2018     case POSTDECREMENT_EXPR:
2019     case ARRAY_REF:
2020     case CALL_EXPR:
2021     case COMPONENT_REF:
2022     case BIT_FIELD_REF:
2023     case COMPLEX_CST:
2024     case COMPLEX_EXPR:
2025     case VECTOR_CST:
2026     case ORDERED_EXPR:
2027     case UNORDERED_EXPR:
2028     case LTGT_EXPR:
2029     case UNEQ_EXPR:
2030     case UNLE_EXPR:
2031     case UNLT_EXPR:
2032     case UNGE_EXPR:
2033     case UNGT_EXPR:
2034     case ABS_EXPR:
2035     case CONSTRUCTOR:
2036     case COMPOUND_LITERAL_EXPR:
2037     case VA_ARG_EXPR:
2038       pp_postfix_expression (pp, e);
2039       break;
2040
2041     case CONJ_EXPR:
2042     case ADDR_EXPR:
2043     case INDIRECT_REF:
2044     case NEGATE_EXPR:
2045     case BIT_NOT_EXPR:
2046     case TRUTH_NOT_EXPR:
2047     case PREINCREMENT_EXPR:
2048     case PREDECREMENT_EXPR:
2049     case REALPART_EXPR:
2050     case IMAGPART_EXPR:
2051       pp_c_unary_expression (pp, e);
2052       break;
2053
2054     case FLOAT_EXPR:
2055     case FIX_TRUNC_EXPR:
2056     CASE_CONVERT:
2057     case VIEW_CONVERT_EXPR:
2058       pp_c_cast_expression (pp, e);
2059       break;
2060
2061     case MULT_EXPR:
2062     case TRUNC_MOD_EXPR:
2063     case TRUNC_DIV_EXPR:
2064       pp_multiplicative_expression (pp, e);
2065       break;
2066
2067     case LSHIFT_EXPR:
2068     case RSHIFT_EXPR:
2069       pp_c_shift_expression (pp, e);
2070       break;
2071
2072     case LT_EXPR:
2073     case GT_EXPR:
2074     case LE_EXPR:
2075     case GE_EXPR:
2076       pp_c_relational_expression (pp, e);
2077       break;
2078
2079     case BIT_AND_EXPR:
2080       pp_c_and_expression (pp, e);
2081       break;
2082
2083     case BIT_XOR_EXPR:
2084     case TRUTH_XOR_EXPR:
2085       pp_c_exclusive_or_expression (pp, e);
2086       break;
2087
2088     case BIT_IOR_EXPR:
2089       pp_c_inclusive_or_expression (pp, e);
2090       break;
2091
2092     case TRUTH_ANDIF_EXPR:
2093     case TRUTH_AND_EXPR:
2094       pp_c_logical_and_expression (pp, e);
2095       break;
2096
2097     case TRUTH_ORIF_EXPR:
2098     case TRUTH_OR_EXPR:
2099       pp_c_logical_or_expression (pp, e);
2100       break;
2101
2102     case EQ_EXPR:
2103     case NE_EXPR:
2104       pp_c_equality_expression (pp, e);
2105       break;
2106
2107     case COND_EXPR:
2108       pp_conditional_expression (pp, e);
2109       break;
2110
2111     case POINTER_PLUS_EXPR:
2112     case PLUS_EXPR:
2113     case MINUS_EXPR:
2114       pp_c_additive_expression (pp, e);
2115       break;
2116
2117     case MODIFY_EXPR:
2118     case INIT_EXPR:
2119       pp_assignment_expression (pp, e);
2120       break;
2121
2122     case COMPOUND_EXPR:
2123       pp_c_left_paren (pp);
2124       pp_expression (pp, TREE_OPERAND (e, 0));
2125       pp_separate_with (pp, ',');
2126       pp_assignment_expression (pp, TREE_OPERAND (e, 1));
2127       pp_c_right_paren (pp);
2128       break;
2129
2130     case NON_LVALUE_EXPR:
2131     case SAVE_EXPR:
2132       pp_expression (pp, TREE_OPERAND (e, 0));
2133       break;
2134
2135     case TARGET_EXPR:
2136       pp_postfix_expression (pp, TREE_OPERAND (e, 1));
2137       break;
2138
2139     case BIND_EXPR:
2140     case GOTO_EXPR:
2141       /* We don't yet have a way of dumping statements in a
2142          human-readable format.  */
2143       pp_string (pp, "({...})");
2144       break;
2145
2146     default:
2147       pp_unsupported_tree (pp, e);
2148       break;
2149     }
2150 }
2151
2152
2153 \f
2154 /* Statements.  */
2155
2156 void
2157 pp_c_statement (c_pretty_printer *pp, tree stmt)
2158 {
2159   if (stmt == NULL)
2160     return;
2161
2162   if (pp_needs_newline (pp))
2163     pp_newline_and_indent (pp, 0);
2164
2165   dump_generic_node (pp_base (pp), stmt, pp_indentation (pp), 0, true);
2166 }
2167
2168 \f
2169 /* Initialize the PRETTY-PRINTER for handling C codes.  */
2170
2171 void
2172 pp_c_pretty_printer_init (c_pretty_printer *pp)
2173 {
2174   pp->offset_list               = 0;
2175
2176   pp->declaration               = pp_c_declaration;
2177   pp->declaration_specifiers    = pp_c_declaration_specifiers;
2178   pp->declarator                = pp_c_declarator;
2179   pp->direct_declarator         = pp_c_direct_declarator;
2180   pp->type_specifier_seq        = pp_c_specifier_qualifier_list;
2181   pp->abstract_declarator       = pp_c_abstract_declarator;
2182   pp->direct_abstract_declarator = pp_c_direct_abstract_declarator;
2183   pp->ptr_operator              = pp_c_pointer;
2184   pp->parameter_list            = pp_c_parameter_type_list;
2185   pp->type_id                   = pp_c_type_id;
2186   pp->simple_type_specifier     = pp_c_type_specifier;
2187   pp->function_specifier        = pp_c_function_specifier;
2188   pp->storage_class_specifier   = pp_c_storage_class_specifier;
2189
2190   pp->statement                 = pp_c_statement;
2191
2192   pp->constant                  = pp_c_constant;
2193   pp->id_expression             = pp_c_id_expression;
2194   pp->primary_expression        = pp_c_primary_expression;
2195   pp->postfix_expression        = pp_c_postfix_expression;
2196   pp->unary_expression          = pp_c_unary_expression;
2197   pp->initializer               = pp_c_initializer;
2198   pp->multiplicative_expression = pp_c_multiplicative_expression;
2199   pp->conditional_expression    = pp_c_conditional_expression;
2200   pp->assignment_expression     = pp_c_assignment_expression;
2201   pp->expression                = pp_c_expression;
2202 }
2203
2204
2205 /* Print the tree T in full, on file FILE.  */
2206
2207 void
2208 print_c_tree (FILE *file, tree t)
2209 {
2210   static c_pretty_printer pp_rec;
2211   static bool initialized = 0;
2212   c_pretty_printer *pp = &pp_rec;
2213
2214   if (!initialized)
2215     {
2216       initialized = 1;
2217       pp_construct (pp_base (pp), NULL, 0);
2218       pp_c_pretty_printer_init (pp);
2219       pp_needs_newline (pp) = true;
2220     }
2221   pp_base (pp)->buffer->stream = file;
2222
2223   pp_statement (pp, t);
2224
2225   pp_newline (pp);
2226   pp_flush (pp);
2227 }
2228
2229 /* Print the tree T in full, on stderr.  */
2230
2231 void
2232 debug_c_tree (tree t)
2233 {
2234   print_c_tree (stderr, t);
2235   fputc ('\n', stderr);
2236 }
2237
2238 /* Output the DECL_NAME of T.  If T has no DECL_NAME, output a string made
2239    up of T's memory address.  */
2240
2241 void
2242 pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t)
2243 {
2244   const char *name;
2245
2246   gcc_assert (DECL_P (t));
2247
2248   if (DECL_NAME (t))
2249     name = IDENTIFIER_POINTER (DECL_NAME (t));
2250   else
2251     {
2252       static char xname[8];
2253       sprintf (xname, "<U%4x>", ((unsigned)((uintptr_t)(t) & 0xffff)));
2254       name = xname;
2255     }
2256
2257   pp_c_identifier (pp, name);
2258 }