OSDN Git Service

gcc/c-family:
[pf3gnuchains/gcc-fork.git] / gcc / c-family / c-pretty-print.c
1 /* Subroutines common to both C and C++ pretty-printers.
2    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
3    Free Software Foundation, Inc.
4    Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "intl.h"
28 #include "c-pretty-print.h"
29 #include "tree-pretty-print.h"
30 #include "tree-iterator.h"
31 #include "diagnostic.h"
32
33 /* Translate if being used for diagnostics, but not for dump files or
34    __PRETTY_FUNCTION.  */
35 #define M_(msgid) (pp_translate_identifiers (pp) ? _(msgid) : (msgid))
36
37 /* The pretty-printer code is primarily designed to closely follow
38    (GNU) C and C++ grammars.  That is to be contrasted with spaghetti
39    codes we used to have in the past.  Following a structured
40    approach (preferably the official grammars) is believed to make it
41    much easier to add extensions and nifty pretty-printing effects that
42    takes expression or declaration contexts into account.  */
43
44
45 #define pp_c_maybe_whitespace(PP)            \
46    do {                                      \
47      if (pp_base (PP)->padding == pp_before) \
48        pp_c_whitespace (PP);                 \
49    } while (0)
50
51 /* literal  */
52 static void pp_c_char (c_pretty_printer *, int);
53
54 /* postfix-expression  */
55 static void pp_c_initializer_list (c_pretty_printer *, tree);
56 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer *, tree);
57
58 static void pp_c_multiplicative_expression (c_pretty_printer *, tree);
59 static void pp_c_additive_expression (c_pretty_printer *, tree);
60 static void pp_c_shift_expression (c_pretty_printer *, tree);
61 static void pp_c_relational_expression (c_pretty_printer *, tree);
62 static void pp_c_equality_expression (c_pretty_printer *, tree);
63 static void pp_c_and_expression (c_pretty_printer *, tree);
64 static void pp_c_exclusive_or_expression (c_pretty_printer *, tree);
65 static void pp_c_inclusive_or_expression (c_pretty_printer *, tree);
66 static void pp_c_logical_and_expression (c_pretty_printer *, tree);
67 static void pp_c_conditional_expression (c_pretty_printer *, tree);
68 static void pp_c_assignment_expression (c_pretty_printer *, tree);
69
70 /* declarations.  */
71
72 \f
73 /* Helper functions.  */
74
75 void
76 pp_c_whitespace (c_pretty_printer *pp)
77 {
78   pp_space (pp);
79   pp_base (pp)->padding = pp_none;
80 }
81
82 void
83 pp_c_left_paren (c_pretty_printer *pp)
84 {
85   pp_left_paren (pp);
86   pp_base (pp)->padding = pp_none;
87 }
88
89 void
90 pp_c_right_paren (c_pretty_printer *pp)
91 {
92   pp_right_paren (pp);
93   pp_base (pp)->padding = pp_none;
94 }
95
96 void
97 pp_c_left_brace (c_pretty_printer *pp)
98 {
99   pp_left_brace (pp);
100   pp_base (pp)->padding = pp_none;
101 }
102
103 void
104 pp_c_right_brace (c_pretty_printer *pp)
105 {
106   pp_right_brace (pp);
107   pp_base (pp)->padding = pp_none;
108 }
109
110 void
111 pp_c_left_bracket (c_pretty_printer *pp)
112 {
113   pp_left_bracket (pp);
114   pp_base (pp)->padding = pp_none;
115 }
116
117 void
118 pp_c_right_bracket (c_pretty_printer *pp)
119 {
120   pp_right_bracket (pp);
121   pp_base (pp)->padding = pp_none;
122 }
123
124 void
125 pp_c_dot (c_pretty_printer *pp)
126 {
127   pp_dot (pp);
128   pp_base (pp)->padding = pp_none;
129 }
130
131 void
132 pp_c_ampersand (c_pretty_printer *pp)
133 {
134   pp_ampersand (pp);
135   pp_base (pp)->padding = pp_none;
136 }
137
138 void
139 pp_c_star (c_pretty_printer *pp)
140 {
141   pp_star (pp);
142   pp_base (pp)->padding = pp_none;
143 }
144
145 void
146 pp_c_arrow (c_pretty_printer *pp)
147 {
148   pp_arrow (pp);
149   pp_base (pp)->padding = pp_none;
150 }
151
152 void
153 pp_c_semicolon (c_pretty_printer *pp)
154 {
155   pp_semicolon (pp);
156   pp_base (pp)->padding = pp_none;
157 }
158
159 void
160 pp_c_complement (c_pretty_printer *pp)
161 {
162   pp_complement (pp);
163   pp_base (pp)->padding = pp_none;
164 }
165
166 void
167 pp_c_exclamation (c_pretty_printer *pp)
168 {
169   pp_exclamation (pp);
170   pp_base (pp)->padding = pp_none;
171 }
172
173 /* Print out the external representation of QUALIFIERS.  */
174
175 void
176 pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type)
177 {
178   const char *p = pp_last_position_in_text (pp);
179   bool previous = false;
180
181   if (!qualifiers)
182     return;
183
184   /* The C programming language does not have references, but it is much
185      simpler to handle those here rather than going through the same
186      logic in the C++ pretty-printer.  */
187   if (p != NULL && (*p == '*' || *p == '&'))
188     pp_c_whitespace (pp);
189
190   if (qualifiers & TYPE_QUAL_CONST)
191     {
192       pp_c_ws_string (pp, func_type ? "__attribute__((const))" : "const");
193       previous = true;
194     }
195
196   if (qualifiers & TYPE_QUAL_VOLATILE)
197     {
198       if (previous)
199         pp_c_whitespace (pp);
200       pp_c_ws_string (pp, func_type ? "__attribute__((noreturn))" : "volatile");
201       previous = true;
202     }
203
204   if (qualifiers & TYPE_QUAL_RESTRICT)
205     {
206       if (previous)
207         pp_c_whitespace (pp);
208       pp_c_ws_string (pp, flag_isoc99 ? "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_identifier (pp, IDENTIFIER_POINTER (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   /* We are going to compare the type of I to other types using
905      pointer comparison so we need to use its canonical type.  */
906   tree type =
907     TYPE_CANONICAL (TREE_TYPE (i))
908     ? TYPE_CANONICAL (TREE_TYPE (i))
909     : TREE_TYPE (i);
910
911   if (TREE_INT_CST_HIGH (i) == 0)
912     pp_wide_integer (pp, TREE_INT_CST_LOW (i));
913   else
914     {
915       unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (i);
916       HOST_WIDE_INT high = TREE_INT_CST_HIGH (i);
917       if (tree_int_cst_sgn (i) < 0)
918         {
919           pp_character (pp, '-');
920           high = ~high + !low;
921           low = -low;
922         }
923       sprintf (pp_buffer (pp)->digit_buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
924                (unsigned HOST_WIDE_INT) high, (unsigned HOST_WIDE_INT) low);
925       pp_string (pp, pp_buffer (pp)->digit_buffer);
926     }
927   if (TYPE_UNSIGNED (type))
928     pp_character (pp, 'u');
929   if (type == long_integer_type_node || type == long_unsigned_type_node)
930     pp_character (pp, 'l');
931   else if (type == long_long_integer_type_node
932            || type == long_long_unsigned_type_node)
933     pp_string (pp, "ll");
934   else if (type == int128_integer_type_node
935            || type == int128_unsigned_type_node)
936     pp_string (pp, "I128");
937 }
938
939 /* Print out a CHARACTER literal.  */
940
941 static void
942 pp_c_character_constant (c_pretty_printer *pp, tree c)
943 {
944   tree type = TREE_TYPE (c);
945   if (type == wchar_type_node)
946     pp_character (pp, 'L');
947   pp_quote (pp);
948   if (host_integerp (c, TYPE_UNSIGNED (type)))
949     pp_c_char (pp, tree_low_cst (c, TYPE_UNSIGNED (type)));
950   else
951     pp_scalar (pp, "\\x%x", (unsigned) TREE_INT_CST_LOW (c));
952   pp_quote (pp);
953 }
954
955 /* Print out a BOOLEAN literal.  */
956
957 static void
958 pp_c_bool_constant (c_pretty_printer *pp, tree b)
959 {
960   if (b == boolean_false_node)
961     {
962       if (c_dialect_cxx ())
963         pp_c_ws_string (pp, "false");
964       else if (flag_isoc99)
965         pp_c_ws_string (pp, "_False");
966       else
967         pp_unsupported_tree (pp, b);
968     }
969   else if (b == boolean_true_node)
970     {
971       if (c_dialect_cxx ())
972         pp_c_ws_string (pp, "true");
973       else if (flag_isoc99)
974         pp_c_ws_string (pp, "_True");
975       else
976         pp_unsupported_tree (pp, b);
977     }
978   else if (TREE_CODE (b) == INTEGER_CST)
979     pp_c_integer_constant (pp, b);
980   else
981     pp_unsupported_tree (pp, b);
982 }
983
984 /* Attempt to print out an ENUMERATOR.  Return true on success.  Else return
985    false; that means the value was obtained by a cast, in which case
986    print out the type-id part of the cast-expression -- the casted value
987    is then printed by pp_c_integer_literal.  */
988
989 static bool
990 pp_c_enumeration_constant (c_pretty_printer *pp, tree e)
991 {
992   bool value_is_named = true;
993   tree type = TREE_TYPE (e);
994   tree value;
995
996   /* Find the name of this constant.  */
997   for (value = TYPE_VALUES (type);
998        value != NULL_TREE && !tree_int_cst_equal (TREE_VALUE (value), e);
999        value = TREE_CHAIN (value))
1000     ;
1001
1002   if (value != NULL_TREE)
1003     pp_id_expression (pp, TREE_PURPOSE (value));
1004   else
1005     {
1006       /* Value must have been cast.  */
1007       pp_c_type_cast (pp, type);
1008       value_is_named = false;
1009     }
1010
1011   return value_is_named;
1012 }
1013
1014 /* Print out a REAL value as a decimal-floating-constant.  */
1015
1016 static void
1017 pp_c_floating_constant (c_pretty_printer *pp, tree r)
1018 {
1019   real_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_REAL_CST (r),
1020                    sizeof (pp_buffer (pp)->digit_buffer), 0, 1);
1021   pp_string (pp, pp_buffer(pp)->digit_buffer);
1022   if (TREE_TYPE (r) == float_type_node)
1023     pp_character (pp, 'f');
1024   else if (TREE_TYPE (r) == long_double_type_node)
1025     pp_character (pp, 'l');
1026   else if (TREE_TYPE (r) == dfloat128_type_node)
1027     pp_string (pp, "dl");
1028   else if (TREE_TYPE (r) == dfloat64_type_node)
1029     pp_string (pp, "dd");
1030   else if (TREE_TYPE (r) == dfloat32_type_node)
1031     pp_string (pp, "df");
1032 }
1033
1034 /* Print out a FIXED value as a decimal-floating-constant.  */
1035
1036 static void
1037 pp_c_fixed_constant (c_pretty_printer *pp, tree r)
1038 {
1039   fixed_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_FIXED_CST (r),
1040                    sizeof (pp_buffer (pp)->digit_buffer));
1041   pp_string (pp, pp_buffer(pp)->digit_buffer);
1042 }
1043
1044 /* Pretty-print a compound literal expression.  GNU extensions include
1045    vector constants.  */
1046
1047 static void
1048 pp_c_compound_literal (c_pretty_printer *pp, tree e)
1049 {
1050   tree type = TREE_TYPE (e);
1051   pp_c_type_cast (pp, type);
1052
1053   switch (TREE_CODE (type))
1054     {
1055     case RECORD_TYPE:
1056     case UNION_TYPE:
1057     case ARRAY_TYPE:
1058     case VECTOR_TYPE:
1059     case COMPLEX_TYPE:
1060       pp_c_brace_enclosed_initializer_list (pp, e);
1061       break;
1062
1063     default:
1064       pp_unsupported_tree (pp, e);
1065       break;
1066     }
1067 }
1068
1069 /* Pretty-print a COMPLEX_EXPR expression.  */
1070
1071 static void
1072 pp_c_complex_expr (c_pretty_printer *pp, tree e)
1073 {
1074   /* Handle a few common special cases, otherwise fallback
1075      to printing it as compound literal.  */
1076   tree type = TREE_TYPE (e);
1077   tree realexpr = TREE_OPERAND (e, 0);
1078   tree imagexpr = TREE_OPERAND (e, 1);
1079
1080   /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE.  */
1081   if (TREE_CODE (realexpr) == NOP_EXPR
1082       && TREE_CODE (imagexpr) == NOP_EXPR
1083       && TREE_TYPE (realexpr) == TREE_TYPE (type)
1084       && TREE_TYPE (imagexpr) == TREE_TYPE (type)
1085       && TREE_CODE (TREE_OPERAND (realexpr, 0)) == REALPART_EXPR
1086       && TREE_CODE (TREE_OPERAND (imagexpr, 0)) == IMAGPART_EXPR
1087       && TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0)
1088          == TREE_OPERAND (TREE_OPERAND (imagexpr, 0), 0))
1089     {
1090       pp_c_type_cast (pp, type);
1091       pp_expression (pp, TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0));
1092       return;
1093     }
1094
1095   /* Cast of an scalar expression to COMPLEX_TYPE.  */
1096   if ((integer_zerop (imagexpr) || real_zerop (imagexpr))
1097       && TREE_TYPE (realexpr) == TREE_TYPE (type))
1098     {
1099       pp_c_type_cast (pp, type);
1100       if (TREE_CODE (realexpr) == NOP_EXPR)
1101         realexpr = TREE_OPERAND (realexpr, 0);
1102       pp_expression (pp, realexpr);
1103       return;
1104     }
1105
1106   pp_c_compound_literal (pp, e);
1107 }
1108
1109 /* constant:
1110       integer-constant
1111       floating-constant
1112       fixed-point-constant
1113       enumeration-constant
1114       character-constant   */
1115
1116 void
1117 pp_c_constant (c_pretty_printer *pp, tree e)
1118 {
1119   const enum tree_code code = TREE_CODE (e);
1120
1121   switch (code)
1122     {
1123     case INTEGER_CST:
1124       {
1125         tree type = TREE_TYPE (e);
1126         if (type == boolean_type_node)
1127           pp_c_bool_constant (pp, e);
1128         else if (type == char_type_node)
1129           pp_c_character_constant (pp, e);
1130         else if (TREE_CODE (type) == ENUMERAL_TYPE
1131                  && pp_c_enumeration_constant (pp, e))
1132           ;
1133         else
1134           pp_c_integer_constant (pp, e);
1135       }
1136       break;
1137
1138     case REAL_CST:
1139       pp_c_floating_constant (pp, e);
1140       break;
1141
1142     case FIXED_CST:
1143       pp_c_fixed_constant (pp, e);
1144       break;
1145
1146     case STRING_CST:
1147       pp_c_string_literal (pp, e);
1148       break;
1149
1150     case COMPLEX_CST:
1151       /* Sometimes, we are confused and we think a complex literal
1152          is a constant.  Such thing is a compound literal which
1153          grammatically belongs to postfix-expr production.  */
1154       pp_c_compound_literal (pp, e);
1155       break;
1156
1157     default:
1158       pp_unsupported_tree (pp, e);
1159       break;
1160     }
1161 }
1162
1163 /* Pretty-print a string such as an identifier, without changing its
1164    encoding, preceded by whitespace is necessary.  */
1165
1166 void
1167 pp_c_ws_string (c_pretty_printer *pp, const char *str)
1168 {
1169   pp_c_maybe_whitespace (pp);
1170   pp_string (pp, str);
1171   pp_base (pp)->padding = pp_before;
1172 }
1173
1174 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1175    that need converting to the locale encoding, preceded by whitespace
1176    is necessary.  */
1177
1178 void
1179 pp_c_identifier (c_pretty_printer *pp, const char *id)
1180 {
1181   pp_c_maybe_whitespace (pp);
1182   pp_identifier (pp, id);
1183   pp_base (pp)->padding = pp_before;
1184 }
1185
1186 /* Pretty-print a C primary-expression.
1187    primary-expression:
1188       identifier
1189       constant
1190       string-literal
1191       ( expression )   */
1192
1193 void
1194 pp_c_primary_expression (c_pretty_printer *pp, tree e)
1195 {
1196   switch (TREE_CODE (e))
1197     {
1198     case VAR_DECL:
1199     case PARM_DECL:
1200     case FIELD_DECL:
1201     case CONST_DECL:
1202     case FUNCTION_DECL:
1203     case LABEL_DECL:
1204       pp_c_tree_decl_identifier (pp, e);
1205       break;
1206
1207     case IDENTIFIER_NODE:
1208       pp_c_tree_identifier (pp, e);
1209       break;
1210
1211     case ERROR_MARK:
1212       pp_c_ws_string (pp, M_("<erroneous-expression>"));
1213       break;
1214
1215     case RESULT_DECL:
1216       pp_c_ws_string (pp, M_("<return-value>"));
1217       break;
1218
1219     case INTEGER_CST:
1220     case REAL_CST:
1221     case FIXED_CST:
1222     case STRING_CST:
1223       pp_c_constant (pp, e);
1224       break;
1225
1226     case TARGET_EXPR:
1227       pp_c_ws_string (pp, "__builtin_memcpy");
1228       pp_c_left_paren (pp);
1229       pp_ampersand (pp);
1230       pp_primary_expression (pp, TREE_OPERAND (e, 0));
1231       pp_separate_with (pp, ',');
1232       pp_ampersand (pp);
1233       pp_initializer (pp, TREE_OPERAND (e, 1));
1234       if (TREE_OPERAND (e, 2))
1235         {
1236           pp_separate_with (pp, ',');
1237           pp_c_expression (pp, TREE_OPERAND (e, 2));
1238         }
1239       pp_c_right_paren (pp);
1240       break;
1241
1242     default:
1243       /* FIXME:  Make sure we won't get into an infinite loop.  */
1244       pp_c_left_paren (pp);
1245       pp_expression (pp, e);
1246       pp_c_right_paren (pp);
1247       break;
1248     }
1249 }
1250
1251 /* Print out a C initializer -- also support C compound-literals.
1252    initializer:
1253       assignment-expression:
1254       { initializer-list }
1255       { initializer-list , }   */
1256
1257 static void
1258 pp_c_initializer (c_pretty_printer *pp, tree e)
1259 {
1260   if (TREE_CODE (e) == CONSTRUCTOR)
1261     pp_c_brace_enclosed_initializer_list (pp, e);
1262   else
1263     pp_expression (pp, e);
1264 }
1265
1266 /* init-declarator:
1267       declarator:
1268       declarator = initializer   */
1269
1270 void
1271 pp_c_init_declarator (c_pretty_printer *pp, tree t)
1272 {
1273   pp_declarator (pp, t);
1274   /* We don't want to output function definitions here.  There are handled
1275      elsewhere (and the syntactic form is bogus anyway).  */
1276   if (TREE_CODE (t) != FUNCTION_DECL && DECL_INITIAL (t))
1277     {
1278       tree init = DECL_INITIAL (t);
1279       /* This C++ bit is handled here because it is easier to do so.
1280          In templates, the C++ parser builds a TREE_LIST for a
1281          direct-initialization; the TREE_PURPOSE is the variable to
1282          initialize and the TREE_VALUE is the initializer.  */
1283       if (TREE_CODE (init) == TREE_LIST)
1284         {
1285           pp_c_left_paren (pp);
1286           pp_expression (pp, TREE_VALUE (init));
1287           pp_right_paren (pp);
1288         }
1289       else
1290         {
1291           pp_space (pp);
1292           pp_equal (pp);
1293           pp_space (pp);
1294           pp_c_initializer (pp, init);
1295         }
1296     }
1297 }
1298
1299 /* initializer-list:
1300       designation(opt) initializer
1301       initializer-list , designation(opt) initializer
1302
1303    designation:
1304       designator-list =
1305
1306    designator-list:
1307       designator
1308       designator-list designator
1309
1310    designator:
1311       [ constant-expression ]
1312       identifier   */
1313
1314 static void
1315 pp_c_initializer_list (c_pretty_printer *pp, tree e)
1316 {
1317   tree type = TREE_TYPE (e);
1318   const enum tree_code code = TREE_CODE (type);
1319
1320   if (TREE_CODE (e) == CONSTRUCTOR)
1321     {
1322       pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e));
1323       return;
1324     }
1325
1326   switch (code)
1327     {
1328     case RECORD_TYPE:
1329     case UNION_TYPE:
1330     case ARRAY_TYPE:
1331       {
1332         tree init = TREE_OPERAND (e, 0);
1333         for (; init != NULL_TREE; init = TREE_CHAIN (init))
1334           {
1335             if (code == RECORD_TYPE || code == UNION_TYPE)
1336               {
1337                 pp_c_dot (pp);
1338                 pp_c_primary_expression (pp, TREE_PURPOSE (init));
1339               }
1340             else
1341               {
1342                 pp_c_left_bracket (pp);
1343                 if (TREE_PURPOSE (init))
1344                   pp_c_constant (pp, TREE_PURPOSE (init));
1345                 pp_c_right_bracket (pp);
1346               }
1347             pp_c_whitespace (pp);
1348             pp_equal (pp);
1349             pp_c_whitespace (pp);
1350             pp_initializer (pp, TREE_VALUE (init));
1351             if (TREE_CHAIN (init))
1352               pp_separate_with (pp, ',');
1353           }
1354       }
1355       return;
1356
1357     case VECTOR_TYPE:
1358       if (TREE_CODE (e) == VECTOR_CST)
1359         pp_c_expression_list (pp, TREE_VECTOR_CST_ELTS (e));
1360       else
1361         break;
1362       return;
1363
1364     case COMPLEX_TYPE:
1365       if (TREE_CODE (e) == COMPLEX_CST || TREE_CODE (e) == COMPLEX_EXPR)
1366         {
1367           const bool cst = TREE_CODE (e) == COMPLEX_CST;
1368           pp_expression (pp, cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0));
1369           pp_separate_with (pp, ',');
1370           pp_expression (pp, cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1));
1371         }
1372       else
1373         break;
1374       return;
1375
1376     default:
1377       break;
1378     }
1379
1380   pp_unsupported_tree (pp, type);
1381 }
1382
1383 /* Pretty-print a brace-enclosed initializer-list.  */
1384
1385 static void
1386 pp_c_brace_enclosed_initializer_list (c_pretty_printer *pp, tree l)
1387 {
1388   pp_c_left_brace (pp);
1389   pp_c_initializer_list (pp, l);
1390   pp_c_right_brace (pp);
1391 }
1392
1393
1394 /*  This is a convenient function, used to bridge gap between C and C++
1395     grammars.
1396
1397     id-expression:
1398        identifier  */
1399
1400 void
1401 pp_c_id_expression (c_pretty_printer *pp, tree t)
1402 {
1403   switch (TREE_CODE (t))
1404     {
1405     case VAR_DECL:
1406     case PARM_DECL:
1407     case CONST_DECL:
1408     case TYPE_DECL:
1409     case FUNCTION_DECL:
1410     case FIELD_DECL:
1411     case LABEL_DECL:
1412       pp_c_tree_decl_identifier (pp, t);
1413       break;
1414
1415     case IDENTIFIER_NODE:
1416       pp_c_tree_identifier (pp, t);
1417       break;
1418
1419     default:
1420       pp_unsupported_tree (pp, t);
1421       break;
1422     }
1423 }
1424
1425 /* postfix-expression:
1426       primary-expression
1427       postfix-expression [ expression ]
1428       postfix-expression ( argument-expression-list(opt) )
1429       postfix-expression . identifier
1430       postfix-expression -> identifier
1431       postfix-expression ++
1432       postfix-expression --
1433       ( type-name ) { initializer-list }
1434       ( type-name ) { initializer-list , }  */
1435
1436 void
1437 pp_c_postfix_expression (c_pretty_printer *pp, tree e)
1438 {
1439   enum tree_code code = TREE_CODE (e);
1440   switch (code)
1441     {
1442     case POSTINCREMENT_EXPR:
1443     case POSTDECREMENT_EXPR:
1444       pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1445       pp_string (pp, code == POSTINCREMENT_EXPR ? "++" : "--");
1446       break;
1447
1448     case ARRAY_REF:
1449       pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1450       pp_c_left_bracket (pp);
1451       pp_expression (pp, TREE_OPERAND (e, 1));
1452       pp_c_right_bracket (pp);
1453       break;
1454
1455     case CALL_EXPR:
1456       {
1457         call_expr_arg_iterator iter;
1458         tree arg;
1459         pp_postfix_expression (pp, CALL_EXPR_FN (e));
1460         pp_c_left_paren (pp);
1461         FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
1462           {
1463             pp_expression (pp, arg);
1464             if (more_call_expr_args_p (&iter))
1465               pp_separate_with (pp, ',');
1466           }
1467         pp_c_right_paren (pp);
1468         break;
1469       }
1470
1471     case UNORDERED_EXPR:
1472       pp_c_ws_string (pp, flag_isoc99
1473                            ? "isunordered"
1474                            : "__builtin_isunordered");
1475       goto two_args_fun;
1476
1477     case ORDERED_EXPR:
1478       pp_c_ws_string (pp, flag_isoc99
1479                            ? "!isunordered"
1480                            : "!__builtin_isunordered");
1481       goto two_args_fun;
1482
1483     case UNLT_EXPR:
1484       pp_c_ws_string (pp, flag_isoc99
1485                            ? "!isgreaterequal"
1486                            : "!__builtin_isgreaterequal");
1487       goto two_args_fun;
1488
1489     case UNLE_EXPR:
1490       pp_c_ws_string (pp, flag_isoc99
1491                            ? "!isgreater"
1492                            : "!__builtin_isgreater");
1493       goto two_args_fun;
1494
1495     case UNGT_EXPR:
1496       pp_c_ws_string (pp, flag_isoc99
1497                            ? "!islessequal"
1498                            : "!__builtin_islessequal");
1499       goto two_args_fun;
1500
1501     case UNGE_EXPR:
1502       pp_c_ws_string (pp, flag_isoc99
1503                            ? "!isless"
1504                            : "!__builtin_isless");
1505       goto two_args_fun;
1506
1507     case UNEQ_EXPR:
1508       pp_c_ws_string (pp, flag_isoc99
1509                            ? "!islessgreater"
1510                            : "!__builtin_islessgreater");
1511       goto two_args_fun;
1512
1513     case LTGT_EXPR:
1514       pp_c_ws_string (pp, flag_isoc99
1515                            ? "islessgreater"
1516                            : "__builtin_islessgreater");
1517       goto two_args_fun;
1518
1519     two_args_fun:
1520       pp_c_left_paren (pp);
1521       pp_expression (pp, TREE_OPERAND (e, 0));
1522       pp_separate_with (pp, ',');
1523       pp_expression (pp, TREE_OPERAND (e, 1));
1524       pp_c_right_paren (pp);
1525       break;
1526
1527     case ABS_EXPR:
1528       pp_c_ws_string (pp, "__builtin_abs");
1529       pp_c_left_paren (pp);
1530       pp_expression (pp, TREE_OPERAND (e, 0));
1531       pp_c_right_paren (pp);
1532       break;
1533
1534     case COMPONENT_REF:
1535       {
1536         tree object = TREE_OPERAND (e, 0);
1537         if (TREE_CODE (object) == INDIRECT_REF)
1538           {
1539             pp_postfix_expression (pp, TREE_OPERAND (object, 0));
1540             pp_c_arrow (pp);
1541           }
1542         else
1543           {
1544             pp_postfix_expression (pp, object);
1545             pp_c_dot (pp);
1546           }
1547         pp_expression (pp, TREE_OPERAND (e, 1));
1548       }
1549       break;
1550
1551     case BIT_FIELD_REF:
1552       {
1553         tree type = TREE_TYPE (e);
1554
1555         type = signed_or_unsigned_type_for (TYPE_UNSIGNED (type), type);
1556         if (type
1557             && tree_int_cst_equal (TYPE_SIZE (type), TREE_OPERAND (e, 1)))
1558           {
1559             HOST_WIDE_INT bitpos = tree_low_cst (TREE_OPERAND (e, 2), 0);
1560             HOST_WIDE_INT size = tree_low_cst (TYPE_SIZE (type), 0);
1561             if ((bitpos % size) == 0)
1562               {
1563                 pp_c_left_paren (pp);
1564                 pp_c_left_paren (pp);
1565                 pp_type_id (pp, type);
1566                 pp_c_star (pp);
1567                 pp_c_right_paren (pp);
1568                 pp_c_ampersand (pp);
1569                 pp_expression (pp, TREE_OPERAND (e, 0));
1570                 pp_c_right_paren (pp);
1571                 pp_c_left_bracket (pp);
1572                 pp_wide_integer (pp, bitpos / size);
1573                 pp_c_right_bracket (pp);
1574                 break;
1575               }
1576           }
1577         pp_unsupported_tree (pp, e);
1578       }
1579       break;
1580
1581     case MEM_REF:
1582       pp_c_expression (pp, e);
1583       break;
1584
1585     case COMPLEX_CST:
1586     case VECTOR_CST:
1587       pp_c_compound_literal (pp, e);
1588       break;
1589
1590     case COMPLEX_EXPR:
1591       pp_c_complex_expr (pp, e);
1592       break;
1593
1594     case COMPOUND_LITERAL_EXPR:
1595       e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e));
1596       /* Fall through.  */
1597     case CONSTRUCTOR:
1598       pp_initializer (pp, e);
1599       break;
1600
1601     case VA_ARG_EXPR:
1602       pp_c_ws_string (pp, "__builtin_va_arg");
1603       pp_c_left_paren (pp);
1604       pp_assignment_expression (pp, TREE_OPERAND (e, 0));
1605       pp_separate_with (pp, ',');
1606       pp_type_id (pp, TREE_TYPE (e));
1607       pp_c_right_paren (pp);
1608       break;
1609
1610     case ADDR_EXPR:
1611       if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
1612         {
1613           pp_c_id_expression (pp, TREE_OPERAND (e, 0));
1614           break;
1615         }
1616       /* else fall through.  */
1617
1618     default:
1619       pp_primary_expression (pp, e);
1620       break;
1621     }
1622 }
1623
1624 /* Print out an expression-list; E is expected to be a TREE_LIST.  */
1625
1626 void
1627 pp_c_expression_list (c_pretty_printer *pp, tree e)
1628 {
1629   for (; e != NULL_TREE; e = TREE_CHAIN (e))
1630     {
1631       pp_expression (pp, TREE_VALUE (e));
1632       if (TREE_CHAIN (e))
1633         pp_separate_with (pp, ',');
1634     }
1635 }
1636
1637 /* Print out V, which contains the elements of a constructor.  */
1638
1639 void
1640 pp_c_constructor_elts (c_pretty_printer *pp, VEC(constructor_elt,gc) *v)
1641 {
1642   unsigned HOST_WIDE_INT ix;
1643   tree value;
1644
1645   FOR_EACH_CONSTRUCTOR_VALUE (v, ix, value)
1646     {
1647       pp_expression (pp, value);
1648       if (ix != VEC_length (constructor_elt, v) - 1)
1649         pp_separate_with (pp, ',');
1650     }
1651 }
1652
1653 /* Print out an expression-list in parens, as if it were the argument
1654    list to a function.  */
1655
1656 void
1657 pp_c_call_argument_list (c_pretty_printer *pp, tree t)
1658 {
1659   pp_c_left_paren (pp);
1660   if (t && TREE_CODE (t) == TREE_LIST)
1661     pp_c_expression_list (pp, t);
1662   pp_c_right_paren (pp);
1663 }
1664
1665 /* unary-expression:
1666       postfix-expression
1667       ++ cast-expression
1668       -- cast-expression
1669       unary-operator cast-expression
1670       sizeof unary-expression
1671       sizeof ( type-id )
1672
1673   unary-operator: one of
1674       * &  + - ! ~
1675
1676    GNU extensions.
1677    unary-expression:
1678       __alignof__ unary-expression
1679       __alignof__ ( type-id )
1680       __real__ unary-expression
1681       __imag__ unary-expression  */
1682
1683 void
1684 pp_c_unary_expression (c_pretty_printer *pp, tree e)
1685 {
1686   enum tree_code code = TREE_CODE (e);
1687   switch (code)
1688     {
1689     case PREINCREMENT_EXPR:
1690     case PREDECREMENT_EXPR:
1691       pp_string (pp, code == PREINCREMENT_EXPR ? "++" : "--");
1692       pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
1693       break;
1694
1695     case ADDR_EXPR:
1696     case INDIRECT_REF:
1697     case NEGATE_EXPR:
1698     case BIT_NOT_EXPR:
1699     case TRUTH_NOT_EXPR:
1700     case CONJ_EXPR:
1701       /* String literal are used by address.  */
1702       if (code == ADDR_EXPR && TREE_CODE (TREE_OPERAND (e, 0)) != STRING_CST)
1703         pp_ampersand (pp);
1704       else if (code == INDIRECT_REF)
1705         pp_c_star (pp);
1706       else if (code == NEGATE_EXPR)
1707         pp_minus (pp);
1708       else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
1709         pp_complement (pp);
1710       else if (code == TRUTH_NOT_EXPR)
1711         pp_exclamation (pp);
1712       pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1713       break;
1714
1715     case MEM_REF:
1716       if (TREE_CODE (TREE_OPERAND (e, 0)) == ADDR_EXPR
1717           && integer_zerop (TREE_OPERAND (e, 1)))
1718         pp_c_expression (pp, TREE_OPERAND (TREE_OPERAND (e, 0), 0));
1719       else
1720         {
1721           pp_c_star (pp);
1722           if (!integer_zerop (TREE_OPERAND (e, 1)))
1723             {
1724               pp_c_left_paren (pp);
1725               if (!integer_onep (TYPE_SIZE_UNIT
1726                                  (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e, 0))))))
1727                 pp_c_type_cast (pp, ptr_type_node);
1728             }
1729           pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1730           if (!integer_zerop (TREE_OPERAND (e, 1)))
1731             {
1732               pp_plus (pp);
1733               pp_c_integer_constant (pp,
1734                                      fold_convert (ssizetype,
1735                                                    TREE_OPERAND (e, 1)));
1736               pp_c_right_paren (pp);
1737             }
1738         }
1739       break;
1740
1741     case REALPART_EXPR:
1742     case IMAGPART_EXPR:
1743       pp_c_ws_string (pp, code == REALPART_EXPR ? "__real__" : "__imag__");
1744       pp_c_whitespace (pp);
1745       pp_unary_expression (pp, TREE_OPERAND (e, 0));
1746       break;
1747
1748     default:
1749       pp_postfix_expression (pp, e);
1750       break;
1751     }
1752 }
1753
1754 /* cast-expression:
1755       unary-expression
1756       ( type-name ) cast-expression  */
1757
1758 void
1759 pp_c_cast_expression (c_pretty_printer *pp, tree e)
1760 {
1761   switch (TREE_CODE (e))
1762     {
1763     case FLOAT_EXPR:
1764     case FIX_TRUNC_EXPR:
1765     CASE_CONVERT:
1766     case VIEW_CONVERT_EXPR:
1767       pp_c_type_cast (pp, TREE_TYPE (e));
1768       pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1769       break;
1770
1771     default:
1772       pp_unary_expression (pp, e);
1773     }
1774 }
1775
1776 /* multiplicative-expression:
1777       cast-expression
1778       multiplicative-expression * cast-expression
1779       multiplicative-expression / cast-expression
1780       multiplicative-expression % cast-expression   */
1781
1782 static void
1783 pp_c_multiplicative_expression (c_pretty_printer *pp, tree e)
1784 {
1785   enum tree_code code = TREE_CODE (e);
1786   switch (code)
1787     {
1788     case MULT_EXPR:
1789     case TRUNC_DIV_EXPR:
1790     case TRUNC_MOD_EXPR:
1791       pp_multiplicative_expression (pp, TREE_OPERAND (e, 0));
1792       pp_c_whitespace (pp);
1793       if (code == MULT_EXPR)
1794         pp_c_star (pp);
1795       else if (code == TRUNC_DIV_EXPR)
1796         pp_slash (pp);
1797       else
1798         pp_modulo (pp);
1799       pp_c_whitespace (pp);
1800       pp_c_cast_expression (pp, TREE_OPERAND (e, 1));
1801       break;
1802
1803     default:
1804       pp_c_cast_expression (pp, e);
1805       break;
1806     }
1807 }
1808
1809 /* additive-expression:
1810       multiplicative-expression
1811       additive-expression + multiplicative-expression
1812       additive-expression - multiplicative-expression   */
1813
1814 static void
1815 pp_c_additive_expression (c_pretty_printer *pp, tree e)
1816 {
1817   enum tree_code code = TREE_CODE (e);
1818   switch (code)
1819     {
1820     case POINTER_PLUS_EXPR:
1821     case PLUS_EXPR:
1822     case MINUS_EXPR:
1823       pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
1824       pp_c_whitespace (pp);
1825       if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
1826         pp_plus (pp);
1827       else
1828         pp_minus (pp);
1829       pp_c_whitespace (pp);
1830       pp_multiplicative_expression (pp, TREE_OPERAND (e, 1));
1831       break;
1832
1833     default:
1834       pp_multiplicative_expression (pp, e);
1835       break;
1836     }
1837 }
1838
1839 /* additive-expression:
1840       additive-expression
1841       shift-expression << additive-expression
1842       shift-expression >> additive-expression   */
1843
1844 static void
1845 pp_c_shift_expression (c_pretty_printer *pp, tree e)
1846 {
1847   enum tree_code code = TREE_CODE (e);
1848   switch (code)
1849     {
1850     case LSHIFT_EXPR:
1851     case RSHIFT_EXPR:
1852       pp_c_shift_expression (pp, TREE_OPERAND (e, 0));
1853       pp_c_whitespace (pp);
1854       pp_string (pp, code == LSHIFT_EXPR ? "<<" : ">>");
1855       pp_c_whitespace (pp);
1856       pp_c_additive_expression (pp, TREE_OPERAND (e, 1));
1857       break;
1858
1859     default:
1860       pp_c_additive_expression (pp, e);
1861     }
1862 }
1863
1864 /* relational-expression:
1865       shift-expression
1866       relational-expression < shift-expression
1867       relational-expression > shift-expression
1868       relational-expression <= shift-expression
1869       relational-expression >= shift-expression   */
1870
1871 static void
1872 pp_c_relational_expression (c_pretty_printer *pp, tree e)
1873 {
1874   enum tree_code code = TREE_CODE (e);
1875   switch (code)
1876     {
1877     case LT_EXPR:
1878     case GT_EXPR:
1879     case LE_EXPR:
1880     case GE_EXPR:
1881       pp_c_relational_expression (pp, TREE_OPERAND (e, 0));
1882       pp_c_whitespace (pp);
1883       if (code == LT_EXPR)
1884         pp_less (pp);
1885       else if (code == GT_EXPR)
1886         pp_greater (pp);
1887       else if (code == LE_EXPR)
1888         pp_string (pp, "<=");
1889       else if (code == GE_EXPR)
1890         pp_string (pp, ">=");
1891       pp_c_whitespace (pp);
1892       pp_c_shift_expression (pp, TREE_OPERAND (e, 1));
1893       break;
1894
1895     default:
1896       pp_c_shift_expression (pp, e);
1897       break;
1898     }
1899 }
1900
1901 /* equality-expression:
1902       relational-expression
1903       equality-expression == relational-expression
1904       equality-equality != relational-expression  */
1905
1906 static void
1907 pp_c_equality_expression (c_pretty_printer *pp, tree e)
1908 {
1909   enum tree_code code = TREE_CODE (e);
1910   switch (code)
1911     {
1912     case EQ_EXPR:
1913     case NE_EXPR:
1914       pp_c_equality_expression (pp, TREE_OPERAND (e, 0));
1915       pp_c_whitespace (pp);
1916       pp_string (pp, code == EQ_EXPR ? "==" : "!=");
1917       pp_c_whitespace (pp);
1918       pp_c_relational_expression (pp, TREE_OPERAND (e, 1));
1919       break;
1920
1921     default:
1922       pp_c_relational_expression (pp, e);
1923       break;
1924     }
1925 }
1926
1927 /* AND-expression:
1928       equality-expression
1929       AND-expression & equality-equality   */
1930
1931 static void
1932 pp_c_and_expression (c_pretty_printer *pp, tree e)
1933 {
1934   if (TREE_CODE (e) == BIT_AND_EXPR)
1935     {
1936       pp_c_and_expression (pp, TREE_OPERAND (e, 0));
1937       pp_c_whitespace (pp);
1938       pp_ampersand (pp);
1939       pp_c_whitespace (pp);
1940       pp_c_equality_expression (pp, TREE_OPERAND (e, 1));
1941     }
1942   else
1943     pp_c_equality_expression (pp, e);
1944 }
1945
1946 /* exclusive-OR-expression:
1947      AND-expression
1948      exclusive-OR-expression ^ AND-expression  */
1949
1950 static void
1951 pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e)
1952 {
1953   if (TREE_CODE (e) == BIT_XOR_EXPR
1954       || TREE_CODE (e) == TRUTH_XOR_EXPR)
1955     {
1956       pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1957       if (TREE_CODE (e) == BIT_XOR_EXPR)
1958         pp_c_maybe_whitespace (pp);
1959       else
1960         pp_c_whitespace (pp);
1961       pp_carret (pp);
1962       pp_c_whitespace (pp);
1963       pp_c_and_expression (pp, TREE_OPERAND (e, 1));
1964     }
1965   else
1966     pp_c_and_expression (pp, e);
1967 }
1968
1969 /* inclusive-OR-expression:
1970      exclusive-OR-expression
1971      inclusive-OR-expression | exclusive-OR-expression  */
1972
1973 static void
1974 pp_c_inclusive_or_expression (c_pretty_printer *pp, tree e)
1975 {
1976   if (TREE_CODE (e) == BIT_IOR_EXPR)
1977     {
1978       pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1979       pp_c_whitespace (pp);
1980       pp_bar (pp);
1981       pp_c_whitespace (pp);
1982       pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 1));
1983     }
1984   else
1985     pp_c_exclusive_or_expression (pp, e);
1986 }
1987
1988 /* logical-AND-expression:
1989       inclusive-OR-expression
1990       logical-AND-expression && inclusive-OR-expression  */
1991
1992 static void
1993 pp_c_logical_and_expression (c_pretty_printer *pp, tree e)
1994 {
1995   if (TREE_CODE (e) == TRUTH_ANDIF_EXPR
1996       || TREE_CODE (e) == TRUTH_AND_EXPR)
1997     {
1998       pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0));
1999       pp_c_whitespace (pp);
2000       pp_string (pp, "&&");
2001       pp_c_whitespace (pp);
2002       pp_c_inclusive_or_expression (pp, TREE_OPERAND (e, 1));
2003     }
2004   else
2005     pp_c_inclusive_or_expression (pp, e);
2006 }
2007
2008 /* logical-OR-expression:
2009       logical-AND-expression
2010       logical-OR-expression || logical-AND-expression  */
2011
2012 void
2013 pp_c_logical_or_expression (c_pretty_printer *pp, tree e)
2014 {
2015   if (TREE_CODE (e) == TRUTH_ORIF_EXPR
2016       || TREE_CODE (e) == TRUTH_OR_EXPR)
2017     {
2018       pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2019       pp_c_whitespace (pp);
2020       pp_string (pp, "||");
2021       pp_c_whitespace (pp);
2022       pp_c_logical_and_expression (pp, TREE_OPERAND (e, 1));
2023     }
2024   else
2025     pp_c_logical_and_expression (pp, e);
2026 }
2027
2028 /* conditional-expression:
2029       logical-OR-expression
2030       logical-OR-expression ? expression : conditional-expression  */
2031
2032 static void
2033 pp_c_conditional_expression (c_pretty_printer *pp, tree e)
2034 {
2035   if (TREE_CODE (e) == COND_EXPR)
2036     {
2037       pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2038       pp_c_whitespace (pp);
2039       pp_question (pp);
2040       pp_c_whitespace (pp);
2041       pp_expression (pp, TREE_OPERAND (e, 1));
2042       pp_c_whitespace (pp);
2043       pp_colon (pp);
2044       pp_c_whitespace (pp);
2045       pp_c_conditional_expression (pp, TREE_OPERAND (e, 2));
2046     }
2047   else
2048     pp_c_logical_or_expression (pp, e);
2049 }
2050
2051
2052 /* assignment-expression:
2053       conditional-expression
2054       unary-expression assignment-operator  assignment-expression
2055
2056    assignment-expression: one of
2057       =    *=    /=    %=    +=    -=    >>=    <<=    &=    ^=    |=  */
2058
2059 static void
2060 pp_c_assignment_expression (c_pretty_printer *pp, tree e)
2061 {
2062   if (TREE_CODE (e) == MODIFY_EXPR
2063       || TREE_CODE (e) == INIT_EXPR)
2064     {
2065       pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
2066       pp_c_whitespace (pp);
2067       pp_equal (pp);
2068       pp_space (pp);
2069       pp_c_expression (pp, TREE_OPERAND (e, 1));
2070     }
2071   else
2072     pp_c_conditional_expression (pp, e);
2073 }
2074
2075 /* expression:
2076        assignment-expression
2077        expression , assignment-expression
2078
2079   Implementation note:  instead of going through the usual recursion
2080   chain, I take the liberty of dispatching nodes to the appropriate
2081   functions.  This makes some redundancy, but it worths it. That also
2082   prevents a possible infinite recursion between pp_c_primary_expression ()
2083   and pp_c_expression ().  */
2084
2085 void
2086 pp_c_expression (c_pretty_printer *pp, tree e)
2087 {
2088   switch (TREE_CODE (e))
2089     {
2090     case INTEGER_CST:
2091       pp_c_integer_constant (pp, e);
2092       break;
2093
2094     case REAL_CST:
2095       pp_c_floating_constant (pp, e);
2096       break;
2097
2098     case FIXED_CST:
2099       pp_c_fixed_constant (pp, e);
2100       break;
2101
2102     case STRING_CST:
2103       pp_c_string_literal (pp, e);
2104       break;
2105
2106     case IDENTIFIER_NODE:
2107     case FUNCTION_DECL:
2108     case VAR_DECL:
2109     case CONST_DECL:
2110     case PARM_DECL:
2111     case RESULT_DECL:
2112     case FIELD_DECL:
2113     case LABEL_DECL:
2114     case ERROR_MARK:
2115       pp_primary_expression (pp, e);
2116       break;
2117
2118     case POSTINCREMENT_EXPR:
2119     case POSTDECREMENT_EXPR:
2120     case ARRAY_REF:
2121     case CALL_EXPR:
2122     case COMPONENT_REF:
2123     case BIT_FIELD_REF:
2124     case COMPLEX_CST:
2125     case COMPLEX_EXPR:
2126     case VECTOR_CST:
2127     case ORDERED_EXPR:
2128     case UNORDERED_EXPR:
2129     case LTGT_EXPR:
2130     case UNEQ_EXPR:
2131     case UNLE_EXPR:
2132     case UNLT_EXPR:
2133     case UNGE_EXPR:
2134     case UNGT_EXPR:
2135     case ABS_EXPR:
2136     case CONSTRUCTOR:
2137     case COMPOUND_LITERAL_EXPR:
2138     case VA_ARG_EXPR:
2139       pp_postfix_expression (pp, e);
2140       break;
2141
2142     case CONJ_EXPR:
2143     case ADDR_EXPR:
2144     case INDIRECT_REF:
2145     case MEM_REF:
2146     case NEGATE_EXPR:
2147     case BIT_NOT_EXPR:
2148     case TRUTH_NOT_EXPR:
2149     case PREINCREMENT_EXPR:
2150     case PREDECREMENT_EXPR:
2151     case REALPART_EXPR:
2152     case IMAGPART_EXPR:
2153       pp_c_unary_expression (pp, e);
2154       break;
2155
2156     case FLOAT_EXPR:
2157     case FIX_TRUNC_EXPR:
2158     CASE_CONVERT:
2159     case VIEW_CONVERT_EXPR:
2160       pp_c_cast_expression (pp, e);
2161       break;
2162
2163     case MULT_EXPR:
2164     case TRUNC_MOD_EXPR:
2165     case TRUNC_DIV_EXPR:
2166       pp_multiplicative_expression (pp, e);
2167       break;
2168
2169     case LSHIFT_EXPR:
2170     case RSHIFT_EXPR:
2171       pp_c_shift_expression (pp, e);
2172       break;
2173
2174     case LT_EXPR:
2175     case GT_EXPR:
2176     case LE_EXPR:
2177     case GE_EXPR:
2178       pp_c_relational_expression (pp, e);
2179       break;
2180
2181     case BIT_AND_EXPR:
2182       pp_c_and_expression (pp, e);
2183       break;
2184
2185     case BIT_XOR_EXPR:
2186     case TRUTH_XOR_EXPR:
2187       pp_c_exclusive_or_expression (pp, e);
2188       break;
2189
2190     case BIT_IOR_EXPR:
2191       pp_c_inclusive_or_expression (pp, e);
2192       break;
2193
2194     case TRUTH_ANDIF_EXPR:
2195     case TRUTH_AND_EXPR:
2196       pp_c_logical_and_expression (pp, e);
2197       break;
2198
2199     case TRUTH_ORIF_EXPR:
2200     case TRUTH_OR_EXPR:
2201       pp_c_logical_or_expression (pp, e);
2202       break;
2203
2204     case EQ_EXPR:
2205     case NE_EXPR:
2206       pp_c_equality_expression (pp, e);
2207       break;
2208
2209     case COND_EXPR:
2210       pp_conditional_expression (pp, e);
2211       break;
2212
2213     case POINTER_PLUS_EXPR:
2214     case PLUS_EXPR:
2215     case MINUS_EXPR:
2216       pp_c_additive_expression (pp, e);
2217       break;
2218
2219     case MODIFY_EXPR:
2220     case INIT_EXPR:
2221       pp_assignment_expression (pp, e);
2222       break;
2223
2224     case COMPOUND_EXPR:
2225       pp_c_left_paren (pp);
2226       pp_expression (pp, TREE_OPERAND (e, 0));
2227       pp_separate_with (pp, ',');
2228       pp_assignment_expression (pp, TREE_OPERAND (e, 1));
2229       pp_c_right_paren (pp);
2230       break;
2231
2232     case NON_LVALUE_EXPR:
2233     case SAVE_EXPR:
2234       pp_expression (pp, TREE_OPERAND (e, 0));
2235       break;
2236
2237     case TARGET_EXPR:
2238       pp_postfix_expression (pp, TREE_OPERAND (e, 1));
2239       break;
2240
2241     case BIND_EXPR:
2242     case GOTO_EXPR:
2243       /* We don't yet have a way of dumping statements in a
2244          human-readable format.  */
2245       pp_string (pp, "({...})");
2246       break;
2247
2248     case C_MAYBE_CONST_EXPR:
2249       pp_c_expression (pp, C_MAYBE_CONST_EXPR_EXPR (e));
2250       break;
2251
2252     default:
2253       pp_unsupported_tree (pp, e);
2254       break;
2255     }
2256 }
2257
2258
2259 \f
2260 /* Statements.  */
2261
2262 void
2263 pp_c_statement (c_pretty_printer *pp, tree stmt)
2264 {
2265   if (stmt == NULL)
2266     return;
2267
2268   if (pp_needs_newline (pp))
2269     pp_newline_and_indent (pp, 0);
2270
2271   dump_generic_node (pp_base (pp), stmt, pp_indentation (pp), 0, true);
2272 }
2273
2274 \f
2275 /* Initialize the PRETTY-PRINTER for handling C codes.  */
2276
2277 void
2278 pp_c_pretty_printer_init (c_pretty_printer *pp)
2279 {
2280   pp->offset_list               = 0;
2281
2282   pp->declaration               = pp_c_declaration;
2283   pp->declaration_specifiers    = pp_c_declaration_specifiers;
2284   pp->declarator                = pp_c_declarator;
2285   pp->direct_declarator         = pp_c_direct_declarator;
2286   pp->type_specifier_seq        = pp_c_specifier_qualifier_list;
2287   pp->abstract_declarator       = pp_c_abstract_declarator;
2288   pp->direct_abstract_declarator = pp_c_direct_abstract_declarator;
2289   pp->ptr_operator              = pp_c_pointer;
2290   pp->parameter_list            = pp_c_parameter_type_list;
2291   pp->type_id                   = pp_c_type_id;
2292   pp->simple_type_specifier     = pp_c_type_specifier;
2293   pp->function_specifier        = pp_c_function_specifier;
2294   pp->storage_class_specifier   = pp_c_storage_class_specifier;
2295
2296   pp->statement                 = pp_c_statement;
2297
2298   pp->constant                  = pp_c_constant;
2299   pp->id_expression             = pp_c_id_expression;
2300   pp->primary_expression        = pp_c_primary_expression;
2301   pp->postfix_expression        = pp_c_postfix_expression;
2302   pp->unary_expression          = pp_c_unary_expression;
2303   pp->initializer               = pp_c_initializer;
2304   pp->multiplicative_expression = pp_c_multiplicative_expression;
2305   pp->conditional_expression    = pp_c_conditional_expression;
2306   pp->assignment_expression     = pp_c_assignment_expression;
2307   pp->expression                = pp_c_expression;
2308 }
2309
2310
2311 /* Print the tree T in full, on file FILE.  */
2312
2313 void
2314 print_c_tree (FILE *file, tree t)
2315 {
2316   static c_pretty_printer pp_rec;
2317   static bool initialized = 0;
2318   c_pretty_printer *pp = &pp_rec;
2319
2320   if (!initialized)
2321     {
2322       initialized = 1;
2323       pp_construct (pp_base (pp), NULL, 0);
2324       pp_c_pretty_printer_init (pp);
2325       pp_needs_newline (pp) = true;
2326     }
2327   pp_base (pp)->buffer->stream = file;
2328
2329   pp_statement (pp, t);
2330
2331   pp_newline (pp);
2332   pp_flush (pp);
2333 }
2334
2335 /* Print the tree T in full, on stderr.  */
2336
2337 DEBUG_FUNCTION void
2338 debug_c_tree (tree t)
2339 {
2340   print_c_tree (stderr, t);
2341   fputc ('\n', stderr);
2342 }
2343
2344 /* Output the DECL_NAME of T.  If T has no DECL_NAME, output a string made
2345    up of T's memory address.  */
2346
2347 void
2348 pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t)
2349 {
2350   const char *name;
2351
2352   gcc_assert (DECL_P (t));
2353
2354   if (DECL_NAME (t))
2355     name = IDENTIFIER_POINTER (DECL_NAME (t));
2356   else
2357     {
2358       static char xname[8];
2359       sprintf (xname, "<U%4x>", ((unsigned)((uintptr_t)(t) & 0xffff)));
2360       name = xname;
2361     }
2362
2363   pp_c_identifier (pp, name);
2364 }