OSDN Git Service

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