OSDN Git Service

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