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