OSDN Git Service

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