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