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