OSDN Git Service

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