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