c-pretty-print.h (c_pretty_printer::postfix_expression): Now a virtual member function.
[official-gcc.git] / gcc / c-family / c-pretty-print.c
blob3e2abadc975d2d1fb71af41c593fb7581cf89d07
1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
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.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "intl.h"
27 #include "c-pretty-print.h"
28 #include "tree-pretty-print.h"
29 #include "tree-iterator.h"
30 #include "diagnostic.h"
32 /* The pretty-printer code is primarily designed to closely follow
33 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
34 codes we used to have in the past. Following a structured
35 approach (preferably the official grammars) is believed to make it
36 much easier to add extensions and nifty pretty-printing effects that
37 takes expression or declaration contexts into account. */
40 #define pp_c_maybe_whitespace(PP) \
41 do { \
42 if ((PP)->padding == pp_before) \
43 pp_c_whitespace (PP); \
44 } while (0)
46 /* literal */
47 static void pp_c_char (c_pretty_printer *, int);
49 /* postfix-expression */
50 static void pp_c_initializer_list (c_pretty_printer *, tree);
51 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer *, tree);
53 static void pp_c_multiplicative_expression (c_pretty_printer *, tree);
54 static void pp_c_additive_expression (c_pretty_printer *, tree);
55 static void pp_c_shift_expression (c_pretty_printer *, tree);
56 static void pp_c_relational_expression (c_pretty_printer *, tree);
57 static void pp_c_equality_expression (c_pretty_printer *, tree);
58 static void pp_c_and_expression (c_pretty_printer *, tree);
59 static void pp_c_exclusive_or_expression (c_pretty_printer *, tree);
60 static void pp_c_inclusive_or_expression (c_pretty_printer *, tree);
61 static void pp_c_logical_and_expression (c_pretty_printer *, tree);
62 static void pp_c_conditional_expression (c_pretty_printer *, tree);
63 static void pp_c_assignment_expression (c_pretty_printer *, tree);
65 /* declarations. */
68 /* Helper functions. */
70 void
71 pp_c_whitespace (c_pretty_printer *pp)
73 pp_space (pp);
74 pp->padding = pp_none;
77 void
78 pp_c_left_paren (c_pretty_printer *pp)
80 pp_left_paren (pp);
81 pp->padding = pp_none;
84 void
85 pp_c_right_paren (c_pretty_printer *pp)
87 pp_right_paren (pp);
88 pp->padding = pp_none;
91 void
92 pp_c_left_brace (c_pretty_printer *pp)
94 pp_left_brace (pp);
95 pp->padding = pp_none;
98 void
99 pp_c_right_brace (c_pretty_printer *pp)
101 pp_right_brace (pp);
102 pp->padding = pp_none;
105 void
106 pp_c_left_bracket (c_pretty_printer *pp)
108 pp_left_bracket (pp);
109 pp->padding = pp_none;
112 void
113 pp_c_right_bracket (c_pretty_printer *pp)
115 pp_right_bracket (pp);
116 pp->padding = pp_none;
119 void
120 pp_c_dot (c_pretty_printer *pp)
122 pp_dot (pp);
123 pp->padding = pp_none;
126 void
127 pp_c_ampersand (c_pretty_printer *pp)
129 pp_ampersand (pp);
130 pp->padding = pp_none;
133 void
134 pp_c_star (c_pretty_printer *pp)
136 pp_star (pp);
137 pp->padding = pp_none;
140 void
141 pp_c_arrow (c_pretty_printer *pp)
143 pp_arrow (pp);
144 pp->padding = pp_none;
147 void
148 pp_c_semicolon (c_pretty_printer *pp)
150 pp_semicolon (pp);
151 pp->padding = pp_none;
154 void
155 pp_c_complement (c_pretty_printer *pp)
157 pp_complement (pp);
158 pp->padding = pp_none;
161 void
162 pp_c_exclamation (c_pretty_printer *pp)
164 pp_exclamation (pp);
165 pp->padding = pp_none;
168 /* Print out the external representation of QUALIFIERS. */
170 void
171 pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type)
173 const char *p = pp_last_position_in_text (pp);
174 bool previous = false;
176 if (!qualifiers)
177 return;
179 /* The C programming language does not have references, but it is much
180 simpler to handle those here rather than going through the same
181 logic in the C++ pretty-printer. */
182 if (p != NULL && (*p == '*' || *p == '&'))
183 pp_c_whitespace (pp);
185 if (qualifiers & TYPE_QUAL_CONST)
187 pp_c_ws_string (pp, func_type ? "__attribute__((const))" : "const");
188 previous = true;
191 if (qualifiers & TYPE_QUAL_VOLATILE)
193 if (previous)
194 pp_c_whitespace (pp);
195 pp_c_ws_string (pp, func_type ? "__attribute__((noreturn))" : "volatile");
196 previous = true;
199 if (qualifiers & TYPE_QUAL_RESTRICT)
201 if (previous)
202 pp_c_whitespace (pp);
203 pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
204 ? "restrict" : "__restrict__"));
208 /* Pretty-print T using the type-cast notation '( type-name )'. */
210 static void
211 pp_c_type_cast (c_pretty_printer *pp, tree t)
213 pp_c_left_paren (pp);
214 pp_type_id (pp, t);
215 pp_c_right_paren (pp);
218 /* We're about to pretty-print a pointer type as indicated by T.
219 Output a whitespace, if needed, preparing for subsequent output. */
221 void
222 pp_c_space_for_pointer_operator (c_pretty_printer *pp, tree t)
224 if (POINTER_TYPE_P (t))
226 tree pointee = strip_pointer_operator (TREE_TYPE (t));
227 if (TREE_CODE (pointee) != ARRAY_TYPE
228 && TREE_CODE (pointee) != FUNCTION_TYPE)
229 pp_c_whitespace (pp);
234 /* Declarations. */
236 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
237 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
238 of its type. Take care of possible extensions.
240 type-qualifier-list:
241 type-qualifier
242 type-qualifier-list type-qualifier
244 type-qualifier:
245 const
246 restrict -- C99
247 __restrict__ -- GNU C
248 address-space-qualifier -- GNU C
249 volatile
251 address-space-qualifier:
252 identifier -- GNU C */
254 void
255 pp_c_type_qualifier_list (c_pretty_printer *pp, tree t)
257 int qualifiers;
259 if (!t || t == error_mark_node)
260 return;
262 if (!TYPE_P (t))
263 t = TREE_TYPE (t);
265 qualifiers = TYPE_QUALS (t);
266 pp_c_cv_qualifiers (pp, qualifiers,
267 TREE_CODE (t) == FUNCTION_TYPE);
269 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t)))
271 const char *as = c_addr_space_name (TYPE_ADDR_SPACE (t));
272 pp_c_identifier (pp, as);
276 /* pointer:
277 * type-qualifier-list(opt)
278 * type-qualifier-list(opt) pointer */
280 static void
281 pp_c_pointer (c_pretty_printer *pp, tree t)
283 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
284 t = TREE_TYPE (t);
285 switch (TREE_CODE (t))
287 case POINTER_TYPE:
288 /* It is easier to handle C++ reference types here. */
289 case REFERENCE_TYPE:
290 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
291 pp_c_pointer (pp, TREE_TYPE (t));
292 if (TREE_CODE (t) == POINTER_TYPE)
293 pp_c_star (pp);
294 else
295 pp_c_ampersand (pp);
296 pp_c_type_qualifier_list (pp, t);
297 break;
299 /* ??? This node is now in GENERIC and so shouldn't be here. But
300 we'll fix that later. */
301 case DECL_EXPR:
302 pp_declaration (pp, DECL_EXPR_DECL (t));
303 pp_needs_newline (pp) = true;
304 break;
306 default:
307 pp_unsupported_tree (pp, t);
311 /* type-specifier:
312 void
313 char
314 short
316 long
317 float
318 double
319 signed
320 unsigned
321 _Bool -- C99
322 _Complex -- C99
323 _Imaginary -- C99
324 struct-or-union-specifier
325 enum-specifier
326 typedef-name.
328 GNU extensions.
329 simple-type-specifier:
330 __complex__
331 __vector__ */
333 void
334 pp_c_type_specifier (c_pretty_printer *pp, tree t)
336 const enum tree_code code = TREE_CODE (t);
337 switch (code)
339 case ERROR_MARK:
340 pp->translate_string ("<type-error>");
341 break;
343 case IDENTIFIER_NODE:
344 pp_c_identifier (pp, IDENTIFIER_POINTER (t));
345 break;
347 case VOID_TYPE:
348 case BOOLEAN_TYPE:
349 case INTEGER_TYPE:
350 case REAL_TYPE:
351 case FIXED_POINT_TYPE:
352 if (TYPE_NAME (t))
354 t = TYPE_NAME (t);
355 pp_c_type_specifier (pp, t);
357 else
359 int prec = TYPE_PRECISION (t);
360 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t)))
361 t = c_common_type_for_mode (TYPE_MODE (t), TYPE_SATURATING (t));
362 else
363 t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t));
364 if (TYPE_NAME (t))
366 pp_c_type_specifier (pp, t);
367 if (TYPE_PRECISION (t) != prec)
369 pp_colon (pp);
370 pp_decimal_int (pp, prec);
373 else
375 switch (code)
377 case INTEGER_TYPE:
378 pp->translate_string (TYPE_UNSIGNED (t)
379 ? "<unnamed-unsigned:"
380 : "<unnamed-signed:");
381 break;
382 case REAL_TYPE:
383 pp->translate_string ("<unnamed-float:");
384 break;
385 case FIXED_POINT_TYPE:
386 pp->translate_string ("<unnamed-fixed:");
387 break;
388 default:
389 gcc_unreachable ();
391 pp_decimal_int (pp, prec);
392 pp_greater (pp);
395 break;
397 case TYPE_DECL:
398 if (DECL_NAME (t))
399 pp_id_expression (pp, t);
400 else
401 pp->translate_string ("<typedef-error>");
402 break;
404 case UNION_TYPE:
405 case RECORD_TYPE:
406 case ENUMERAL_TYPE:
407 if (code == UNION_TYPE)
408 pp_c_ws_string (pp, "union");
409 else if (code == RECORD_TYPE)
410 pp_c_ws_string (pp, "struct");
411 else if (code == ENUMERAL_TYPE)
412 pp_c_ws_string (pp, "enum");
413 else
414 pp->translate_string ("<tag-error>");
416 if (TYPE_NAME (t))
417 pp_id_expression (pp, TYPE_NAME (t));
418 else
419 pp->translate_string ("<anonymous>");
420 break;
422 default:
423 pp_unsupported_tree (pp, t);
424 break;
428 /* specifier-qualifier-list:
429 type-specifier specifier-qualifier-list-opt
430 type-qualifier specifier-qualifier-list-opt
433 Implementation note: Because of the non-linearities in array or
434 function declarations, this routine prints not just the
435 specifier-qualifier-list of such entities or types of such entities,
436 but also the 'pointer' production part of their declarators. The
437 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
439 void
440 pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree t)
442 const enum tree_code code = TREE_CODE (t);
444 if (!(pp->flags & pp_c_flag_gnu_v3) && code != POINTER_TYPE)
445 pp_c_type_qualifier_list (pp, t);
446 switch (code)
448 case REFERENCE_TYPE:
449 case POINTER_TYPE:
451 /* Get the types-specifier of this type. */
452 tree pointee = strip_pointer_operator (TREE_TYPE (t));
453 pp_c_specifier_qualifier_list (pp, pointee);
454 if (TREE_CODE (pointee) == ARRAY_TYPE
455 || TREE_CODE (pointee) == FUNCTION_TYPE)
457 pp_c_whitespace (pp);
458 pp_c_left_paren (pp);
459 pp_c_attributes_display (pp, TYPE_ATTRIBUTES (pointee));
461 else if (!c_dialect_cxx ())
462 pp_c_whitespace (pp);
463 pp_ptr_operator (pp, t);
465 break;
467 case FUNCTION_TYPE:
468 case ARRAY_TYPE:
469 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
470 break;
472 case VECTOR_TYPE:
473 case COMPLEX_TYPE:
474 if (code == COMPLEX_TYPE)
475 pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
476 ? "_Complex" : "__complex__"));
477 else if (code == VECTOR_TYPE)
479 pp_c_ws_string (pp, "__vector");
480 pp_c_left_paren (pp);
481 pp_wide_integer (pp, TYPE_VECTOR_SUBPARTS (t));
482 pp_c_right_paren (pp);
483 pp_c_whitespace (pp);
485 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
486 break;
488 default:
489 pp_simple_type_specifier (pp, t);
490 break;
492 if ((pp->flags & pp_c_flag_gnu_v3) && code != POINTER_TYPE)
493 pp_c_type_qualifier_list (pp, t);
496 /* parameter-type-list:
497 parameter-list
498 parameter-list , ...
500 parameter-list:
501 parameter-declaration
502 parameter-list , parameter-declaration
504 parameter-declaration:
505 declaration-specifiers declarator
506 declaration-specifiers abstract-declarator(opt) */
508 void
509 pp_c_parameter_type_list (c_pretty_printer *pp, tree t)
511 bool want_parm_decl = DECL_P (t) && !(pp->flags & pp_c_flag_abstract);
512 tree parms = want_parm_decl ? DECL_ARGUMENTS (t) : TYPE_ARG_TYPES (t);
513 pp_c_left_paren (pp);
514 if (parms == void_list_node)
515 pp_c_ws_string (pp, "void");
516 else
518 bool first = true;
519 for ( ; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
521 if (!first)
522 pp_separate_with (pp, ',');
523 first = false;
524 pp_declaration_specifiers
525 (pp, want_parm_decl ? parms : TREE_VALUE (parms));
526 if (want_parm_decl)
527 pp_declarator (pp, parms);
528 else
529 pp_abstract_declarator (pp, TREE_VALUE (parms));
532 pp_c_right_paren (pp);
535 /* abstract-declarator:
536 pointer
537 pointer(opt) direct-abstract-declarator */
539 static void
540 pp_c_abstract_declarator (c_pretty_printer *pp, tree t)
542 if (TREE_CODE (t) == POINTER_TYPE)
544 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
545 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
546 pp_c_right_paren (pp);
547 t = TREE_TYPE (t);
550 pp_direct_abstract_declarator (pp, t);
553 /* direct-abstract-declarator:
554 ( abstract-declarator )
555 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
556 direct-abstract-declarator(opt) [ * ]
557 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
559 void
560 pp_c_direct_abstract_declarator (c_pretty_printer *pp, tree t)
562 switch (TREE_CODE (t))
564 case POINTER_TYPE:
565 pp_abstract_declarator (pp, t);
566 break;
568 case FUNCTION_TYPE:
569 pp_c_parameter_type_list (pp, t);
570 pp_direct_abstract_declarator (pp, TREE_TYPE (t));
571 break;
573 case ARRAY_TYPE:
574 pp_c_left_bracket (pp);
575 if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t)))
577 tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (t));
578 tree type = TREE_TYPE (maxval);
580 if (host_integerp (maxval, 0))
581 pp_wide_integer (pp, tree_low_cst (maxval, 0) + 1);
582 else
583 pp_expression (pp, fold_build2 (PLUS_EXPR, type, maxval,
584 build_int_cst (type, 1)));
586 pp_c_right_bracket (pp);
587 pp_direct_abstract_declarator (pp, TREE_TYPE (t));
588 break;
590 case IDENTIFIER_NODE:
591 case VOID_TYPE:
592 case BOOLEAN_TYPE:
593 case INTEGER_TYPE:
594 case REAL_TYPE:
595 case FIXED_POINT_TYPE:
596 case ENUMERAL_TYPE:
597 case RECORD_TYPE:
598 case UNION_TYPE:
599 case VECTOR_TYPE:
600 case COMPLEX_TYPE:
601 case TYPE_DECL:
602 break;
604 default:
605 pp_unsupported_tree (pp, t);
606 break;
610 /* type-name:
611 specifier-qualifier-list abstract-declarator(opt) */
613 void
614 pp_c_type_id (c_pretty_printer *pp, tree t)
616 pp_c_specifier_qualifier_list (pp, t);
617 pp_abstract_declarator (pp, t);
620 /* storage-class-specifier:
621 typedef
622 extern
623 static
624 auto
625 register */
627 void
628 pp_c_storage_class_specifier (c_pretty_printer *pp, tree t)
630 if (TREE_CODE (t) == TYPE_DECL)
631 pp_c_ws_string (pp, "typedef");
632 else if (DECL_P (t))
634 if (DECL_REGISTER (t))
635 pp_c_ws_string (pp, "register");
636 else if (TREE_STATIC (t) && TREE_CODE (t) == VAR_DECL)
637 pp_c_ws_string (pp, "static");
641 /* function-specifier:
642 inline */
644 void
645 pp_c_function_specifier (c_pretty_printer *pp, tree t)
647 if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t))
648 pp_c_ws_string (pp, "inline");
651 /* declaration-specifiers:
652 storage-class-specifier declaration-specifiers(opt)
653 type-specifier declaration-specifiers(opt)
654 type-qualifier declaration-specifiers(opt)
655 function-specifier declaration-specifiers(opt) */
657 void
658 pp_c_declaration_specifiers (c_pretty_printer *pp, tree t)
660 pp_storage_class_specifier (pp, t);
661 pp_function_specifier (pp, t);
662 pp_c_specifier_qualifier_list (pp, DECL_P (t) ? TREE_TYPE (t) : t);
665 /* direct-declarator
666 identifier
667 ( declarator )
668 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
669 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
670 direct-declarator [ type-qualifier-list static assignment-expression ]
671 direct-declarator [ type-qualifier-list * ]
672 direct-declarator ( parameter-type-list )
673 direct-declarator ( identifier-list(opt) ) */
675 void
676 pp_c_direct_declarator (c_pretty_printer *pp, tree t)
678 switch (TREE_CODE (t))
680 case VAR_DECL:
681 case PARM_DECL:
682 case TYPE_DECL:
683 case FIELD_DECL:
684 case LABEL_DECL:
685 pp_c_space_for_pointer_operator (pp, TREE_TYPE (t));
686 pp_c_tree_decl_identifier (pp, t);
687 break;
689 case ARRAY_TYPE:
690 case POINTER_TYPE:
691 pp_abstract_declarator (pp, TREE_TYPE (t));
692 break;
694 case FUNCTION_TYPE:
695 pp_parameter_list (pp, t);
696 pp_abstract_declarator (pp, TREE_TYPE (t));
697 break;
699 case FUNCTION_DECL:
700 pp_c_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
701 pp_c_tree_decl_identifier (pp, t);
702 if (pp->flags & pp_c_flag_abstract)
703 pp_abstract_declarator (pp, TREE_TYPE (t));
704 else
706 pp_parameter_list (pp, t);
707 pp_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t)));
709 break;
711 case INTEGER_TYPE:
712 case REAL_TYPE:
713 case FIXED_POINT_TYPE:
714 case ENUMERAL_TYPE:
715 case UNION_TYPE:
716 case RECORD_TYPE:
717 break;
719 default:
720 pp_unsupported_tree (pp, t);
721 break;
726 /* declarator:
727 pointer(opt) direct-declarator */
729 void
730 pp_c_declarator (c_pretty_printer *pp, tree t)
732 switch (TREE_CODE (t))
734 case INTEGER_TYPE:
735 case REAL_TYPE:
736 case FIXED_POINT_TYPE:
737 case ENUMERAL_TYPE:
738 case UNION_TYPE:
739 case RECORD_TYPE:
740 break;
742 case VAR_DECL:
743 case PARM_DECL:
744 case FIELD_DECL:
745 case ARRAY_TYPE:
746 case FUNCTION_TYPE:
747 case FUNCTION_DECL:
748 case TYPE_DECL:
749 pp_direct_declarator (pp, t);
750 break;
753 default:
754 pp_unsupported_tree (pp, t);
755 break;
759 /* declaration:
760 declaration-specifiers init-declarator-list(opt) ; */
762 void
763 pp_c_declaration (c_pretty_printer *pp, tree t)
765 pp_declaration_specifiers (pp, t);
766 pp_c_init_declarator (pp, t);
769 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
771 void
772 pp_c_attributes (c_pretty_printer *pp, tree attributes)
774 if (attributes == NULL_TREE)
775 return;
777 pp_c_ws_string (pp, "__attribute__");
778 pp_c_left_paren (pp);
779 pp_c_left_paren (pp);
780 for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes))
782 pp_tree_identifier (pp, TREE_PURPOSE (attributes));
783 if (TREE_VALUE (attributes))
784 pp_c_call_argument_list (pp, TREE_VALUE (attributes));
786 if (TREE_CHAIN (attributes))
787 pp_separate_with (pp, ',');
789 pp_c_right_paren (pp);
790 pp_c_right_paren (pp);
793 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
794 marked to be displayed on disgnostic. */
796 void
797 pp_c_attributes_display (c_pretty_printer *pp, tree a)
799 bool is_first = true;
801 if (a == NULL_TREE)
802 return;
804 for (; a != NULL_TREE; a = TREE_CHAIN (a))
806 const struct attribute_spec *as;
807 as = lookup_attribute_spec (TREE_PURPOSE (a));
808 if (!as || as->affects_type_identity == false)
809 continue;
810 if (is_first)
812 pp_c_ws_string (pp, "__attribute__");
813 pp_c_left_paren (pp);
814 pp_c_left_paren (pp);
815 is_first = false;
817 else
819 pp_separate_with (pp, ',');
821 pp_tree_identifier (pp, TREE_PURPOSE (a));
822 if (TREE_VALUE (a))
823 pp_c_call_argument_list (pp, TREE_VALUE (a));
826 if (!is_first)
828 pp_c_right_paren (pp);
829 pp_c_right_paren (pp);
830 pp_c_whitespace (pp);
834 /* function-definition:
835 declaration-specifiers declarator compound-statement */
837 void
838 pp_c_function_definition (c_pretty_printer *pp, tree t)
840 pp_declaration_specifiers (pp, t);
841 pp_declarator (pp, t);
842 pp_needs_newline (pp) = true;
843 pp_statement (pp, DECL_SAVED_TREE (t));
844 pp_newline_and_flush (pp);
848 /* Expressions. */
850 /* Print out a c-char. This is called solely for characters which are
851 in the *target* execution character set. We ought to convert them
852 back to the *host* execution character set before printing, but we
853 have no way to do this at present. A decent compromise is to print
854 all characters as if they were in the host execution character set,
855 and not attempt to recover any named escape characters, but render
856 all unprintables as octal escapes. If the host and target character
857 sets are the same, this produces relatively readable output. If they
858 are not the same, strings may appear as gibberish, but that's okay
859 (in fact, it may well be what the reader wants, e.g. if they are looking
860 to see if conversion to the target character set happened correctly).
862 A special case: we need to prefix \, ", and ' with backslashes. It is
863 correct to do so for the *host*'s \, ", and ', because the rest of the
864 file appears in the host character set. */
866 static void
867 pp_c_char (c_pretty_printer *pp, int c)
869 if (ISPRINT (c))
871 switch (c)
873 case '\\': pp_string (pp, "\\\\"); break;
874 case '\'': pp_string (pp, "\\\'"); break;
875 case '\"': pp_string (pp, "\\\""); break;
876 default: pp_character (pp, c);
879 else
880 pp_scalar (pp, "\\%03o", (unsigned) c);
883 /* Print out a STRING literal. */
885 void
886 pp_c_string_literal (c_pretty_printer *pp, tree s)
888 const char *p = TREE_STRING_POINTER (s);
889 int n = TREE_STRING_LENGTH (s) - 1;
890 int i;
891 pp_doublequote (pp);
892 for (i = 0; i < n; ++i)
893 pp_c_char (pp, p[i]);
894 pp_doublequote (pp);
897 /* Pretty-print an INTEGER literal. */
899 static void
900 pp_c_integer_constant (c_pretty_printer *pp, tree i)
902 /* We are going to compare the type of I to other types using
903 pointer comparison so we need to use its canonical type. */
904 tree type =
905 TYPE_CANONICAL (TREE_TYPE (i))
906 ? TYPE_CANONICAL (TREE_TYPE (i))
907 : TREE_TYPE (i);
909 if (host_integerp (i, 0))
910 pp_wide_integer (pp, TREE_INT_CST_LOW (i));
911 else if (host_integerp (i, 1))
912 pp_unsigned_wide_integer (pp, TREE_INT_CST_LOW (i));
913 else
915 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (i);
916 HOST_WIDE_INT high = TREE_INT_CST_HIGH (i);
917 if (tree_int_cst_sgn (i) < 0)
919 pp_minus (pp);
920 high = ~high + !low;
921 low = -low;
923 sprintf (pp_buffer (pp)->digit_buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
924 (unsigned HOST_WIDE_INT) high, (unsigned HOST_WIDE_INT) low);
925 pp_string (pp, pp_buffer (pp)->digit_buffer);
927 if (TYPE_UNSIGNED (type))
928 pp_character (pp, 'u');
929 if (type == long_integer_type_node || type == long_unsigned_type_node)
930 pp_character (pp, 'l');
931 else if (type == long_long_integer_type_node
932 || type == long_long_unsigned_type_node)
933 pp_string (pp, "ll");
934 else if (type == int128_integer_type_node
935 || type == int128_unsigned_type_node)
936 pp_string (pp, "I128");
939 /* Print out a CHARACTER literal. */
941 static void
942 pp_c_character_constant (c_pretty_printer *pp, tree c)
944 tree type = TREE_TYPE (c);
945 if (type == wchar_type_node)
946 pp_character (pp, 'L');
947 pp_quote (pp);
948 if (host_integerp (c, TYPE_UNSIGNED (type)))
949 pp_c_char (pp, tree_low_cst (c, TYPE_UNSIGNED (type)));
950 else
951 pp_scalar (pp, "\\x%x", (unsigned) TREE_INT_CST_LOW (c));
952 pp_quote (pp);
955 /* Print out a BOOLEAN literal. */
957 static void
958 pp_c_bool_constant (c_pretty_printer *pp, tree b)
960 if (b == boolean_false_node)
962 if (c_dialect_cxx ())
963 pp_c_ws_string (pp, "false");
964 else if (flag_isoc99)
965 pp_c_ws_string (pp, "_False");
966 else
967 pp_unsupported_tree (pp, b);
969 else if (b == boolean_true_node)
971 if (c_dialect_cxx ())
972 pp_c_ws_string (pp, "true");
973 else if (flag_isoc99)
974 pp_c_ws_string (pp, "_True");
975 else
976 pp_unsupported_tree (pp, b);
978 else if (TREE_CODE (b) == INTEGER_CST)
979 pp_c_integer_constant (pp, b);
980 else
981 pp_unsupported_tree (pp, b);
984 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
985 false; that means the value was obtained by a cast, in which case
986 print out the type-id part of the cast-expression -- the casted value
987 is then printed by pp_c_integer_literal. */
989 static bool
990 pp_c_enumeration_constant (c_pretty_printer *pp, tree e)
992 bool value_is_named = true;
993 tree type = TREE_TYPE (e);
994 tree value;
996 /* Find the name of this constant. */
997 for (value = TYPE_VALUES (type);
998 value != NULL_TREE && !tree_int_cst_equal (TREE_VALUE (value), e);
999 value = TREE_CHAIN (value))
1002 if (value != NULL_TREE)
1003 pp_id_expression (pp, TREE_PURPOSE (value));
1004 else
1006 /* Value must have been cast. */
1007 pp_c_type_cast (pp, type);
1008 value_is_named = false;
1011 return value_is_named;
1014 /* Print out a REAL value as a decimal-floating-constant. */
1016 static void
1017 pp_c_floating_constant (c_pretty_printer *pp, tree r)
1019 const struct real_format *fmt
1020 = REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (r)));
1022 REAL_VALUE_TYPE floating_cst = TREE_REAL_CST (r);
1023 bool is_decimal = floating_cst.decimal;
1025 /* See ISO C++ WG N1822. Note: The fraction 643/2136 approximates
1026 log10(2) to 7 significant digits. */
1027 int max_digits10 = 2 + (is_decimal ? fmt->p : fmt->p * 643L / 2136);
1029 real_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_REAL_CST (r),
1030 sizeof (pp_buffer (pp)->digit_buffer),
1031 max_digits10, 1);
1033 pp_string (pp, pp_buffer(pp)->digit_buffer);
1034 if (TREE_TYPE (r) == float_type_node)
1035 pp_character (pp, 'f');
1036 else if (TREE_TYPE (r) == long_double_type_node)
1037 pp_character (pp, 'l');
1038 else if (TREE_TYPE (r) == dfloat128_type_node)
1039 pp_string (pp, "dl");
1040 else if (TREE_TYPE (r) == dfloat64_type_node)
1041 pp_string (pp, "dd");
1042 else if (TREE_TYPE (r) == dfloat32_type_node)
1043 pp_string (pp, "df");
1046 /* Print out a FIXED value as a decimal-floating-constant. */
1048 static void
1049 pp_c_fixed_constant (c_pretty_printer *pp, tree r)
1051 fixed_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_FIXED_CST (r),
1052 sizeof (pp_buffer (pp)->digit_buffer));
1053 pp_string (pp, pp_buffer(pp)->digit_buffer);
1056 /* Pretty-print a compound literal expression. GNU extensions include
1057 vector constants. */
1059 static void
1060 pp_c_compound_literal (c_pretty_printer *pp, tree e)
1062 tree type = TREE_TYPE (e);
1063 pp_c_type_cast (pp, type);
1065 switch (TREE_CODE (type))
1067 case RECORD_TYPE:
1068 case UNION_TYPE:
1069 case ARRAY_TYPE:
1070 case VECTOR_TYPE:
1071 case COMPLEX_TYPE:
1072 pp_c_brace_enclosed_initializer_list (pp, e);
1073 break;
1075 default:
1076 pp_unsupported_tree (pp, e);
1077 break;
1081 /* Pretty-print a COMPLEX_EXPR expression. */
1083 static void
1084 pp_c_complex_expr (c_pretty_printer *pp, tree e)
1086 /* Handle a few common special cases, otherwise fallback
1087 to printing it as compound literal. */
1088 tree type = TREE_TYPE (e);
1089 tree realexpr = TREE_OPERAND (e, 0);
1090 tree imagexpr = TREE_OPERAND (e, 1);
1092 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1093 if (TREE_CODE (realexpr) == NOP_EXPR
1094 && TREE_CODE (imagexpr) == NOP_EXPR
1095 && TREE_TYPE (realexpr) == TREE_TYPE (type)
1096 && TREE_TYPE (imagexpr) == TREE_TYPE (type)
1097 && TREE_CODE (TREE_OPERAND (realexpr, 0)) == REALPART_EXPR
1098 && TREE_CODE (TREE_OPERAND (imagexpr, 0)) == IMAGPART_EXPR
1099 && TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0)
1100 == TREE_OPERAND (TREE_OPERAND (imagexpr, 0), 0))
1102 pp_c_type_cast (pp, type);
1103 pp_expression (pp, TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0));
1104 return;
1107 /* Cast of an scalar expression to COMPLEX_TYPE. */
1108 if ((integer_zerop (imagexpr) || real_zerop (imagexpr))
1109 && TREE_TYPE (realexpr) == TREE_TYPE (type))
1111 pp_c_type_cast (pp, type);
1112 if (TREE_CODE (realexpr) == NOP_EXPR)
1113 realexpr = TREE_OPERAND (realexpr, 0);
1114 pp_expression (pp, realexpr);
1115 return;
1118 pp_c_compound_literal (pp, e);
1121 /* constant:
1122 integer-constant
1123 floating-constant
1124 fixed-point-constant
1125 enumeration-constant
1126 character-constant */
1128 void
1129 c_pretty_printer::constant (tree e)
1131 const enum tree_code code = TREE_CODE (e);
1133 switch (code)
1135 case INTEGER_CST:
1137 tree type = TREE_TYPE (e);
1138 if (type == boolean_type_node)
1139 pp_c_bool_constant (this, e);
1140 else if (type == char_type_node)
1141 pp_c_character_constant (this, e);
1142 else if (TREE_CODE (type) == ENUMERAL_TYPE
1143 && pp_c_enumeration_constant (this, e))
1145 else
1146 pp_c_integer_constant (this, e);
1148 break;
1150 case REAL_CST:
1151 pp_c_floating_constant (this, e);
1152 break;
1154 case FIXED_CST:
1155 pp_c_fixed_constant (this, e);
1156 break;
1158 case STRING_CST:
1159 pp_c_string_literal (this, e);
1160 break;
1162 case COMPLEX_CST:
1163 /* Sometimes, we are confused and we think a complex literal
1164 is a constant. Such thing is a compound literal which
1165 grammatically belongs to postfix-expr production. */
1166 pp_c_compound_literal (this, e);
1167 break;
1169 default:
1170 pp_unsupported_tree (this, e);
1171 break;
1175 /* Pretty-print a string such as an identifier, without changing its
1176 encoding, preceded by whitespace is necessary. */
1178 void
1179 pp_c_ws_string (c_pretty_printer *pp, const char *str)
1181 pp_c_maybe_whitespace (pp);
1182 pp_string (pp, str);
1183 pp->padding = pp_before;
1186 void
1187 c_pretty_printer::translate_string (const char *gmsgid)
1189 if (pp_translate_identifiers (this))
1190 pp_c_ws_string (this, _(gmsgid));
1191 else
1192 pp_c_ws_string (this, gmsgid);
1195 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1196 that need converting to the locale encoding, preceded by whitespace
1197 is necessary. */
1199 void
1200 pp_c_identifier (c_pretty_printer *pp, const char *id)
1202 pp_c_maybe_whitespace (pp);
1203 pp_identifier (pp, id);
1204 pp->padding = pp_before;
1207 /* Pretty-print a C primary-expression.
1208 primary-expression:
1209 identifier
1210 constant
1211 string-literal
1212 ( expression ) */
1214 void
1215 c_pretty_printer::primary_expression (tree e)
1217 switch (TREE_CODE (e))
1219 case VAR_DECL:
1220 case PARM_DECL:
1221 case FIELD_DECL:
1222 case CONST_DECL:
1223 case FUNCTION_DECL:
1224 case LABEL_DECL:
1225 pp_c_tree_decl_identifier (this, e);
1226 break;
1228 case IDENTIFIER_NODE:
1229 pp_c_tree_identifier (this, e);
1230 break;
1232 case ERROR_MARK:
1233 translate_string ("<erroneous-expression>");
1234 break;
1236 case RESULT_DECL:
1237 translate_string ("<return-value>");
1238 break;
1240 case INTEGER_CST:
1241 case REAL_CST:
1242 case FIXED_CST:
1243 case STRING_CST:
1244 constant (e);
1245 break;
1247 case TARGET_EXPR:
1248 pp_c_ws_string (this, "__builtin_memcpy");
1249 pp_c_left_paren (this);
1250 pp_ampersand (this);
1251 primary_expression (TREE_OPERAND (e, 0));
1252 pp_separate_with (this, ',');
1253 pp_ampersand (this);
1254 pp_initializer (this, TREE_OPERAND (e, 1));
1255 if (TREE_OPERAND (e, 2))
1257 pp_separate_with (this, ',');
1258 pp_c_expression (this, TREE_OPERAND (e, 2));
1260 pp_c_right_paren (this);
1261 break;
1263 default:
1264 /* FIXME: Make sure we won't get into an infinite loop. */
1265 pp_c_left_paren (this);
1266 pp_expression (this, e);
1267 pp_c_right_paren (this);
1268 break;
1272 /* Print out a C initializer -- also support C compound-literals.
1273 initializer:
1274 assignment-expression:
1275 { initializer-list }
1276 { initializer-list , } */
1278 static void
1279 pp_c_initializer (c_pretty_printer *pp, tree e)
1281 if (TREE_CODE (e) == CONSTRUCTOR)
1282 pp_c_brace_enclosed_initializer_list (pp, e);
1283 else
1284 pp_expression (pp, e);
1287 /* init-declarator:
1288 declarator:
1289 declarator = initializer */
1291 void
1292 pp_c_init_declarator (c_pretty_printer *pp, tree t)
1294 pp_declarator (pp, t);
1295 /* We don't want to output function definitions here. There are handled
1296 elsewhere (and the syntactic form is bogus anyway). */
1297 if (TREE_CODE (t) != FUNCTION_DECL && DECL_INITIAL (t))
1299 tree init = DECL_INITIAL (t);
1300 /* This C++ bit is handled here because it is easier to do so.
1301 In templates, the C++ parser builds a TREE_LIST for a
1302 direct-initialization; the TREE_PURPOSE is the variable to
1303 initialize and the TREE_VALUE is the initializer. */
1304 if (TREE_CODE (init) == TREE_LIST)
1306 pp_c_left_paren (pp);
1307 pp_expression (pp, TREE_VALUE (init));
1308 pp_right_paren (pp);
1310 else
1312 pp_space (pp);
1313 pp_equal (pp);
1314 pp_space (pp);
1315 pp_c_initializer (pp, init);
1320 /* initializer-list:
1321 designation(opt) initializer
1322 initializer-list , designation(opt) initializer
1324 designation:
1325 designator-list =
1327 designator-list:
1328 designator
1329 designator-list designator
1331 designator:
1332 [ constant-expression ]
1333 identifier */
1335 static void
1336 pp_c_initializer_list (c_pretty_printer *pp, tree e)
1338 tree type = TREE_TYPE (e);
1339 const enum tree_code code = TREE_CODE (type);
1341 if (TREE_CODE (e) == CONSTRUCTOR)
1343 pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e));
1344 return;
1347 switch (code)
1349 case RECORD_TYPE:
1350 case UNION_TYPE:
1351 case ARRAY_TYPE:
1353 tree init = TREE_OPERAND (e, 0);
1354 for (; init != NULL_TREE; init = TREE_CHAIN (init))
1356 if (code == RECORD_TYPE || code == UNION_TYPE)
1358 pp_c_dot (pp);
1359 pp_primary_expression (pp, TREE_PURPOSE (init));
1361 else
1363 pp_c_left_bracket (pp);
1364 if (TREE_PURPOSE (init))
1365 pp_constant (pp, TREE_PURPOSE (init));
1366 pp_c_right_bracket (pp);
1368 pp_c_whitespace (pp);
1369 pp_equal (pp);
1370 pp_c_whitespace (pp);
1371 pp_initializer (pp, TREE_VALUE (init));
1372 if (TREE_CHAIN (init))
1373 pp_separate_with (pp, ',');
1376 return;
1378 case VECTOR_TYPE:
1379 if (TREE_CODE (e) == VECTOR_CST)
1381 unsigned i;
1382 for (i = 0; i < VECTOR_CST_NELTS (e); ++i)
1384 if (i > 0)
1385 pp_separate_with (pp, ',');
1386 pp_expression (pp, VECTOR_CST_ELT (e, i));
1389 else
1390 break;
1391 return;
1393 case COMPLEX_TYPE:
1394 if (TREE_CODE (e) == COMPLEX_CST || TREE_CODE (e) == COMPLEX_EXPR)
1396 const bool cst = TREE_CODE (e) == COMPLEX_CST;
1397 pp_expression (pp, cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0));
1398 pp_separate_with (pp, ',');
1399 pp_expression (pp, cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1));
1401 else
1402 break;
1403 return;
1405 default:
1406 break;
1409 pp_unsupported_tree (pp, type);
1412 /* Pretty-print a brace-enclosed initializer-list. */
1414 static void
1415 pp_c_brace_enclosed_initializer_list (c_pretty_printer *pp, tree l)
1417 pp_c_left_brace (pp);
1418 pp_c_initializer_list (pp, l);
1419 pp_c_right_brace (pp);
1423 /* This is a convenient function, used to bridge gap between C and C++
1424 grammars.
1426 id-expression:
1427 identifier */
1429 void
1430 c_pretty_printer::id_expression (tree t)
1432 switch (TREE_CODE (t))
1434 case VAR_DECL:
1435 case PARM_DECL:
1436 case CONST_DECL:
1437 case TYPE_DECL:
1438 case FUNCTION_DECL:
1439 case FIELD_DECL:
1440 case LABEL_DECL:
1441 pp_c_tree_decl_identifier (this, t);
1442 break;
1444 case IDENTIFIER_NODE:
1445 pp_c_tree_identifier (this, t);
1446 break;
1448 default:
1449 pp_unsupported_tree (this, t);
1450 break;
1454 /* postfix-expression:
1455 primary-expression
1456 postfix-expression [ expression ]
1457 postfix-expression ( argument-expression-list(opt) )
1458 postfix-expression . identifier
1459 postfix-expression -> identifier
1460 postfix-expression ++
1461 postfix-expression --
1462 ( type-name ) { initializer-list }
1463 ( type-name ) { initializer-list , } */
1465 void
1466 c_pretty_printer::postfix_expression (tree e)
1468 enum tree_code code = TREE_CODE (e);
1469 switch (code)
1471 case POSTINCREMENT_EXPR:
1472 case POSTDECREMENT_EXPR:
1473 postfix_expression (TREE_OPERAND (e, 0));
1474 pp_string (this, code == POSTINCREMENT_EXPR ? "++" : "--");
1475 break;
1477 case ARRAY_REF:
1478 postfix_expression (TREE_OPERAND (e, 0));
1479 pp_c_left_bracket (this);
1480 pp_expression (this, TREE_OPERAND (e, 1));
1481 pp_c_right_bracket (this);
1482 break;
1484 case ARRAY_NOTATION_REF:
1485 postfix_expression (ARRAY_NOTATION_ARRAY (e));
1486 pp_c_left_bracket (this);
1487 pp_expression (this, ARRAY_NOTATION_START (e));
1488 pp_colon (this);
1489 pp_expression (this, ARRAY_NOTATION_LENGTH (e));
1490 pp_colon (this);
1491 pp_expression (this, ARRAY_NOTATION_STRIDE (e));
1492 pp_c_right_bracket (this);
1493 break;
1495 case CALL_EXPR:
1497 call_expr_arg_iterator iter;
1498 tree arg;
1499 postfix_expression (CALL_EXPR_FN (e));
1500 pp_c_left_paren (this);
1501 FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
1503 pp_expression (this, arg);
1504 if (more_call_expr_args_p (&iter))
1505 pp_separate_with (this, ',');
1507 pp_c_right_paren (this);
1508 break;
1511 case UNORDERED_EXPR:
1512 pp_c_ws_string (this, flag_isoc99
1513 ? "isunordered"
1514 : "__builtin_isunordered");
1515 goto two_args_fun;
1517 case ORDERED_EXPR:
1518 pp_c_ws_string (this, flag_isoc99
1519 ? "!isunordered"
1520 : "!__builtin_isunordered");
1521 goto two_args_fun;
1523 case UNLT_EXPR:
1524 pp_c_ws_string (this, flag_isoc99
1525 ? "!isgreaterequal"
1526 : "!__builtin_isgreaterequal");
1527 goto two_args_fun;
1529 case UNLE_EXPR:
1530 pp_c_ws_string (this, flag_isoc99
1531 ? "!isgreater"
1532 : "!__builtin_isgreater");
1533 goto two_args_fun;
1535 case UNGT_EXPR:
1536 pp_c_ws_string (this, flag_isoc99
1537 ? "!islessequal"
1538 : "!__builtin_islessequal");
1539 goto two_args_fun;
1541 case UNGE_EXPR:
1542 pp_c_ws_string (this, flag_isoc99
1543 ? "!isless"
1544 : "!__builtin_isless");
1545 goto two_args_fun;
1547 case UNEQ_EXPR:
1548 pp_c_ws_string (this, flag_isoc99
1549 ? "!islessgreater"
1550 : "!__builtin_islessgreater");
1551 goto two_args_fun;
1553 case LTGT_EXPR:
1554 pp_c_ws_string (this, flag_isoc99
1555 ? "islessgreater"
1556 : "__builtin_islessgreater");
1557 goto two_args_fun;
1559 two_args_fun:
1560 pp_c_left_paren (this);
1561 pp_expression (this, TREE_OPERAND (e, 0));
1562 pp_separate_with (this, ',');
1563 pp_expression (this, TREE_OPERAND (e, 1));
1564 pp_c_right_paren (this);
1565 break;
1567 case ABS_EXPR:
1568 pp_c_ws_string (this, "__builtin_abs");
1569 pp_c_left_paren (this);
1570 pp_expression (this, TREE_OPERAND (e, 0));
1571 pp_c_right_paren (this);
1572 break;
1574 case COMPONENT_REF:
1576 tree object = TREE_OPERAND (e, 0);
1577 if (TREE_CODE (object) == INDIRECT_REF)
1579 postfix_expression (TREE_OPERAND (object, 0));
1580 pp_c_arrow (this);
1582 else
1584 postfix_expression (object);
1585 pp_c_dot (this);
1587 pp_expression (this, TREE_OPERAND (e, 1));
1589 break;
1591 case BIT_FIELD_REF:
1593 tree type = TREE_TYPE (e);
1595 type = signed_or_unsigned_type_for (TYPE_UNSIGNED (type), type);
1596 if (type
1597 && tree_int_cst_equal (TYPE_SIZE (type), TREE_OPERAND (e, 1)))
1599 HOST_WIDE_INT bitpos = tree_low_cst (TREE_OPERAND (e, 2), 0);
1600 HOST_WIDE_INT size = tree_low_cst (TYPE_SIZE (type), 0);
1601 if ((bitpos % size) == 0)
1603 pp_c_left_paren (this);
1604 pp_c_left_paren (this);
1605 pp_type_id (this, type);
1606 pp_c_star (this);
1607 pp_c_right_paren (this);
1608 pp_c_ampersand (this);
1609 pp_expression (this, TREE_OPERAND (e, 0));
1610 pp_c_right_paren (this);
1611 pp_c_left_bracket (this);
1612 pp_wide_integer (this, bitpos / size);
1613 pp_c_right_bracket (this);
1614 break;
1617 pp_unsupported_tree (this, e);
1619 break;
1621 case MEM_REF:
1622 pp_c_expression (this, e);
1623 break;
1625 case COMPLEX_CST:
1626 case VECTOR_CST:
1627 pp_c_compound_literal (this, e);
1628 break;
1630 case COMPLEX_EXPR:
1631 pp_c_complex_expr (this, e);
1632 break;
1634 case COMPOUND_LITERAL_EXPR:
1635 e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e));
1636 /* Fall through. */
1637 case CONSTRUCTOR:
1638 pp_initializer (this, e);
1639 break;
1641 case VA_ARG_EXPR:
1642 pp_c_ws_string (this, "__builtin_va_arg");
1643 pp_c_left_paren (this);
1644 pp_assignment_expression (this, TREE_OPERAND (e, 0));
1645 pp_separate_with (this, ',');
1646 pp_type_id (this, TREE_TYPE (e));
1647 pp_c_right_paren (this);
1648 break;
1650 case ADDR_EXPR:
1651 if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
1653 id_expression (TREE_OPERAND (e, 0));
1654 break;
1656 /* else fall through. */
1658 default:
1659 primary_expression (e);
1660 break;
1664 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1666 void
1667 pp_c_expression_list (c_pretty_printer *pp, tree e)
1669 for (; e != NULL_TREE; e = TREE_CHAIN (e))
1671 pp_expression (pp, TREE_VALUE (e));
1672 if (TREE_CHAIN (e))
1673 pp_separate_with (pp, ',');
1677 /* Print out V, which contains the elements of a constructor. */
1679 void
1680 pp_c_constructor_elts (c_pretty_printer *pp, vec<constructor_elt, va_gc> *v)
1682 unsigned HOST_WIDE_INT ix;
1683 tree value;
1685 FOR_EACH_CONSTRUCTOR_VALUE (v, ix, value)
1687 pp_expression (pp, value);
1688 if (ix != vec_safe_length (v) - 1)
1689 pp_separate_with (pp, ',');
1693 /* Print out an expression-list in parens, as if it were the argument
1694 list to a function. */
1696 void
1697 pp_c_call_argument_list (c_pretty_printer *pp, tree t)
1699 pp_c_left_paren (pp);
1700 if (t && TREE_CODE (t) == TREE_LIST)
1701 pp_c_expression_list (pp, t);
1702 pp_c_right_paren (pp);
1705 /* unary-expression:
1706 postfix-expression
1707 ++ cast-expression
1708 -- cast-expression
1709 unary-operator cast-expression
1710 sizeof unary-expression
1711 sizeof ( type-id )
1713 unary-operator: one of
1714 * & + - ! ~
1716 GNU extensions.
1717 unary-expression:
1718 __alignof__ unary-expression
1719 __alignof__ ( type-id )
1720 __real__ unary-expression
1721 __imag__ unary-expression */
1723 void
1724 pp_c_unary_expression (c_pretty_printer *pp, tree e)
1726 enum tree_code code = TREE_CODE (e);
1727 switch (code)
1729 case PREINCREMENT_EXPR:
1730 case PREDECREMENT_EXPR:
1731 pp_string (pp, code == PREINCREMENT_EXPR ? "++" : "--");
1732 pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
1733 break;
1735 case ADDR_EXPR:
1736 case INDIRECT_REF:
1737 case NEGATE_EXPR:
1738 case BIT_NOT_EXPR:
1739 case TRUTH_NOT_EXPR:
1740 case CONJ_EXPR:
1741 /* String literal are used by address. */
1742 if (code == ADDR_EXPR && TREE_CODE (TREE_OPERAND (e, 0)) != STRING_CST)
1743 pp_ampersand (pp);
1744 else if (code == INDIRECT_REF)
1745 pp_c_star (pp);
1746 else if (code == NEGATE_EXPR)
1747 pp_minus (pp);
1748 else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
1749 pp_complement (pp);
1750 else if (code == TRUTH_NOT_EXPR)
1751 pp_exclamation (pp);
1752 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1753 break;
1755 case MEM_REF:
1756 if (TREE_CODE (TREE_OPERAND (e, 0)) == ADDR_EXPR
1757 && integer_zerop (TREE_OPERAND (e, 1)))
1758 pp_c_expression (pp, TREE_OPERAND (TREE_OPERAND (e, 0), 0));
1759 else
1761 pp_c_star (pp);
1762 if (!integer_zerop (TREE_OPERAND (e, 1)))
1764 pp_c_left_paren (pp);
1765 if (!integer_onep (TYPE_SIZE_UNIT
1766 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e, 0))))))
1767 pp_c_type_cast (pp, ptr_type_node);
1769 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1770 if (!integer_zerop (TREE_OPERAND (e, 1)))
1772 pp_plus (pp);
1773 pp_c_integer_constant (pp,
1774 fold_convert (ssizetype,
1775 TREE_OPERAND (e, 1)));
1776 pp_c_right_paren (pp);
1779 break;
1781 case REALPART_EXPR:
1782 case IMAGPART_EXPR:
1783 pp_c_ws_string (pp, code == REALPART_EXPR ? "__real__" : "__imag__");
1784 pp_c_whitespace (pp);
1785 pp_unary_expression (pp, TREE_OPERAND (e, 0));
1786 break;
1788 default:
1789 pp_postfix_expression (pp, e);
1790 break;
1794 /* cast-expression:
1795 unary-expression
1796 ( type-name ) cast-expression */
1798 void
1799 pp_c_cast_expression (c_pretty_printer *pp, tree e)
1801 switch (TREE_CODE (e))
1803 case FLOAT_EXPR:
1804 case FIX_TRUNC_EXPR:
1805 CASE_CONVERT:
1806 case VIEW_CONVERT_EXPR:
1807 pp_c_type_cast (pp, TREE_TYPE (e));
1808 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1809 break;
1811 default:
1812 pp_unary_expression (pp, e);
1816 /* multiplicative-expression:
1817 cast-expression
1818 multiplicative-expression * cast-expression
1819 multiplicative-expression / cast-expression
1820 multiplicative-expression % cast-expression */
1822 static void
1823 pp_c_multiplicative_expression (c_pretty_printer *pp, tree e)
1825 enum tree_code code = TREE_CODE (e);
1826 switch (code)
1828 case MULT_EXPR:
1829 case TRUNC_DIV_EXPR:
1830 case TRUNC_MOD_EXPR:
1831 pp_multiplicative_expression (pp, TREE_OPERAND (e, 0));
1832 pp_c_whitespace (pp);
1833 if (code == MULT_EXPR)
1834 pp_c_star (pp);
1835 else if (code == TRUNC_DIV_EXPR)
1836 pp_slash (pp);
1837 else
1838 pp_modulo (pp);
1839 pp_c_whitespace (pp);
1840 pp_c_cast_expression (pp, TREE_OPERAND (e, 1));
1841 break;
1843 default:
1844 pp_c_cast_expression (pp, e);
1845 break;
1849 /* additive-expression:
1850 multiplicative-expression
1851 additive-expression + multiplicative-expression
1852 additive-expression - multiplicative-expression */
1854 static void
1855 pp_c_additive_expression (c_pretty_printer *pp, tree e)
1857 enum tree_code code = TREE_CODE (e);
1858 switch (code)
1860 case POINTER_PLUS_EXPR:
1861 case PLUS_EXPR:
1862 case MINUS_EXPR:
1863 pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
1864 pp_c_whitespace (pp);
1865 if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
1866 pp_plus (pp);
1867 else
1868 pp_minus (pp);
1869 pp_c_whitespace (pp);
1870 pp_multiplicative_expression (pp, TREE_OPERAND (e, 1));
1871 break;
1873 default:
1874 pp_multiplicative_expression (pp, e);
1875 break;
1879 /* additive-expression:
1880 additive-expression
1881 shift-expression << additive-expression
1882 shift-expression >> additive-expression */
1884 static void
1885 pp_c_shift_expression (c_pretty_printer *pp, tree e)
1887 enum tree_code code = TREE_CODE (e);
1888 switch (code)
1890 case LSHIFT_EXPR:
1891 case RSHIFT_EXPR:
1892 pp_c_shift_expression (pp, TREE_OPERAND (e, 0));
1893 pp_c_whitespace (pp);
1894 pp_string (pp, code == LSHIFT_EXPR ? "<<" : ">>");
1895 pp_c_whitespace (pp);
1896 pp_c_additive_expression (pp, TREE_OPERAND (e, 1));
1897 break;
1899 default:
1900 pp_c_additive_expression (pp, e);
1904 /* relational-expression:
1905 shift-expression
1906 relational-expression < shift-expression
1907 relational-expression > shift-expression
1908 relational-expression <= shift-expression
1909 relational-expression >= shift-expression */
1911 static void
1912 pp_c_relational_expression (c_pretty_printer *pp, tree e)
1914 enum tree_code code = TREE_CODE (e);
1915 switch (code)
1917 case LT_EXPR:
1918 case GT_EXPR:
1919 case LE_EXPR:
1920 case GE_EXPR:
1921 pp_c_relational_expression (pp, TREE_OPERAND (e, 0));
1922 pp_c_whitespace (pp);
1923 if (code == LT_EXPR)
1924 pp_less (pp);
1925 else if (code == GT_EXPR)
1926 pp_greater (pp);
1927 else if (code == LE_EXPR)
1928 pp_less_equal (pp);
1929 else if (code == GE_EXPR)
1930 pp_greater_equal (pp);
1931 pp_c_whitespace (pp);
1932 pp_c_shift_expression (pp, TREE_OPERAND (e, 1));
1933 break;
1935 default:
1936 pp_c_shift_expression (pp, e);
1937 break;
1941 /* equality-expression:
1942 relational-expression
1943 equality-expression == relational-expression
1944 equality-equality != relational-expression */
1946 static void
1947 pp_c_equality_expression (c_pretty_printer *pp, tree e)
1949 enum tree_code code = TREE_CODE (e);
1950 switch (code)
1952 case EQ_EXPR:
1953 case NE_EXPR:
1954 pp_c_equality_expression (pp, TREE_OPERAND (e, 0));
1955 pp_c_whitespace (pp);
1956 pp_string (pp, code == EQ_EXPR ? "==" : "!=");
1957 pp_c_whitespace (pp);
1958 pp_c_relational_expression (pp, TREE_OPERAND (e, 1));
1959 break;
1961 default:
1962 pp_c_relational_expression (pp, e);
1963 break;
1967 /* AND-expression:
1968 equality-expression
1969 AND-expression & equality-equality */
1971 static void
1972 pp_c_and_expression (c_pretty_printer *pp, tree e)
1974 if (TREE_CODE (e) == BIT_AND_EXPR)
1976 pp_c_and_expression (pp, TREE_OPERAND (e, 0));
1977 pp_c_whitespace (pp);
1978 pp_ampersand (pp);
1979 pp_c_whitespace (pp);
1980 pp_c_equality_expression (pp, TREE_OPERAND (e, 1));
1982 else
1983 pp_c_equality_expression (pp, e);
1986 /* exclusive-OR-expression:
1987 AND-expression
1988 exclusive-OR-expression ^ AND-expression */
1990 static void
1991 pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e)
1993 if (TREE_CODE (e) == BIT_XOR_EXPR
1994 || TREE_CODE (e) == TRUTH_XOR_EXPR)
1996 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1997 if (TREE_CODE (e) == BIT_XOR_EXPR)
1998 pp_c_maybe_whitespace (pp);
1999 else
2000 pp_c_whitespace (pp);
2001 pp_carret (pp);
2002 pp_c_whitespace (pp);
2003 pp_c_and_expression (pp, TREE_OPERAND (e, 1));
2005 else
2006 pp_c_and_expression (pp, e);
2009 /* inclusive-OR-expression:
2010 exclusive-OR-expression
2011 inclusive-OR-expression | exclusive-OR-expression */
2013 static void
2014 pp_c_inclusive_or_expression (c_pretty_printer *pp, tree e)
2016 if (TREE_CODE (e) == BIT_IOR_EXPR)
2018 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
2019 pp_c_whitespace (pp);
2020 pp_bar (pp);
2021 pp_c_whitespace (pp);
2022 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 1));
2024 else
2025 pp_c_exclusive_or_expression (pp, e);
2028 /* logical-AND-expression:
2029 inclusive-OR-expression
2030 logical-AND-expression && inclusive-OR-expression */
2032 static void
2033 pp_c_logical_and_expression (c_pretty_printer *pp, tree e)
2035 if (TREE_CODE (e) == TRUTH_ANDIF_EXPR
2036 || TREE_CODE (e) == TRUTH_AND_EXPR)
2038 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0));
2039 pp_c_whitespace (pp);
2040 pp_ampersand_ampersand (pp);
2041 pp_c_whitespace (pp);
2042 pp_c_inclusive_or_expression (pp, TREE_OPERAND (e, 1));
2044 else
2045 pp_c_inclusive_or_expression (pp, e);
2048 /* logical-OR-expression:
2049 logical-AND-expression
2050 logical-OR-expression || logical-AND-expression */
2052 void
2053 pp_c_logical_or_expression (c_pretty_printer *pp, tree e)
2055 if (TREE_CODE (e) == TRUTH_ORIF_EXPR
2056 || TREE_CODE (e) == TRUTH_OR_EXPR)
2058 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2059 pp_c_whitespace (pp);
2060 pp_bar_bar (pp);
2061 pp_c_whitespace (pp);
2062 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 1));
2064 else
2065 pp_c_logical_and_expression (pp, e);
2068 /* conditional-expression:
2069 logical-OR-expression
2070 logical-OR-expression ? expression : conditional-expression */
2072 static void
2073 pp_c_conditional_expression (c_pretty_printer *pp, tree e)
2075 if (TREE_CODE (e) == COND_EXPR)
2077 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2078 pp_c_whitespace (pp);
2079 pp_question (pp);
2080 pp_c_whitespace (pp);
2081 pp_expression (pp, TREE_OPERAND (e, 1));
2082 pp_c_whitespace (pp);
2083 pp_colon (pp);
2084 pp_c_whitespace (pp);
2085 pp_c_conditional_expression (pp, TREE_OPERAND (e, 2));
2087 else
2088 pp_c_logical_or_expression (pp, e);
2092 /* assignment-expression:
2093 conditional-expression
2094 unary-expression assignment-operator assignment-expression
2096 assignment-expression: one of
2097 = *= /= %= += -= >>= <<= &= ^= |= */
2099 static void
2100 pp_c_assignment_expression (c_pretty_printer *pp, tree e)
2102 if (TREE_CODE (e) == MODIFY_EXPR
2103 || TREE_CODE (e) == INIT_EXPR)
2105 pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
2106 pp_c_whitespace (pp);
2107 pp_equal (pp);
2108 pp_space (pp);
2109 pp_c_expression (pp, TREE_OPERAND (e, 1));
2111 else
2112 pp_c_conditional_expression (pp, e);
2115 /* expression:
2116 assignment-expression
2117 expression , assignment-expression
2119 Implementation note: instead of going through the usual recursion
2120 chain, I take the liberty of dispatching nodes to the appropriate
2121 functions. This makes some redundancy, but it worths it. That also
2122 prevents a possible infinite recursion between pp_primary_expression ()
2123 and pp_c_expression (). */
2125 void
2126 pp_c_expression (c_pretty_printer *pp, tree e)
2128 switch (TREE_CODE (e))
2130 case INTEGER_CST:
2131 pp_c_integer_constant (pp, e);
2132 break;
2134 case REAL_CST:
2135 pp_c_floating_constant (pp, e);
2136 break;
2138 case FIXED_CST:
2139 pp_c_fixed_constant (pp, e);
2140 break;
2142 case STRING_CST:
2143 pp_c_string_literal (pp, e);
2144 break;
2146 case IDENTIFIER_NODE:
2147 case FUNCTION_DECL:
2148 case VAR_DECL:
2149 case CONST_DECL:
2150 case PARM_DECL:
2151 case RESULT_DECL:
2152 case FIELD_DECL:
2153 case LABEL_DECL:
2154 case ERROR_MARK:
2155 pp_primary_expression (pp, e);
2156 break;
2158 case SSA_NAME:
2159 if (SSA_NAME_VAR (e)
2160 && !DECL_ARTIFICIAL (SSA_NAME_VAR (e)))
2161 pp_c_expression (pp, SSA_NAME_VAR (e));
2162 else
2163 pp->translate_string ("<unknown>");
2164 break;
2166 case POSTINCREMENT_EXPR:
2167 case POSTDECREMENT_EXPR:
2168 case ARRAY_REF:
2169 case ARRAY_NOTATION_REF:
2170 case CALL_EXPR:
2171 case COMPONENT_REF:
2172 case BIT_FIELD_REF:
2173 case COMPLEX_CST:
2174 case COMPLEX_EXPR:
2175 case VECTOR_CST:
2176 case ORDERED_EXPR:
2177 case UNORDERED_EXPR:
2178 case LTGT_EXPR:
2179 case UNEQ_EXPR:
2180 case UNLE_EXPR:
2181 case UNLT_EXPR:
2182 case UNGE_EXPR:
2183 case UNGT_EXPR:
2184 case ABS_EXPR:
2185 case CONSTRUCTOR:
2186 case COMPOUND_LITERAL_EXPR:
2187 case VA_ARG_EXPR:
2188 pp_postfix_expression (pp, e);
2189 break;
2191 case CONJ_EXPR:
2192 case ADDR_EXPR:
2193 case INDIRECT_REF:
2194 case MEM_REF:
2195 case NEGATE_EXPR:
2196 case BIT_NOT_EXPR:
2197 case TRUTH_NOT_EXPR:
2198 case PREINCREMENT_EXPR:
2199 case PREDECREMENT_EXPR:
2200 case REALPART_EXPR:
2201 case IMAGPART_EXPR:
2202 pp_c_unary_expression (pp, e);
2203 break;
2205 case FLOAT_EXPR:
2206 case FIX_TRUNC_EXPR:
2207 CASE_CONVERT:
2208 case VIEW_CONVERT_EXPR:
2209 pp_c_cast_expression (pp, e);
2210 break;
2212 case MULT_EXPR:
2213 case TRUNC_MOD_EXPR:
2214 case TRUNC_DIV_EXPR:
2215 pp_multiplicative_expression (pp, e);
2216 break;
2218 case LSHIFT_EXPR:
2219 case RSHIFT_EXPR:
2220 pp_c_shift_expression (pp, e);
2221 break;
2223 case LT_EXPR:
2224 case GT_EXPR:
2225 case LE_EXPR:
2226 case GE_EXPR:
2227 pp_c_relational_expression (pp, e);
2228 break;
2230 case BIT_AND_EXPR:
2231 pp_c_and_expression (pp, e);
2232 break;
2234 case BIT_XOR_EXPR:
2235 case TRUTH_XOR_EXPR:
2236 pp_c_exclusive_or_expression (pp, e);
2237 break;
2239 case BIT_IOR_EXPR:
2240 pp_c_inclusive_or_expression (pp, e);
2241 break;
2243 case TRUTH_ANDIF_EXPR:
2244 case TRUTH_AND_EXPR:
2245 pp_c_logical_and_expression (pp, e);
2246 break;
2248 case TRUTH_ORIF_EXPR:
2249 case TRUTH_OR_EXPR:
2250 pp_c_logical_or_expression (pp, e);
2251 break;
2253 case EQ_EXPR:
2254 case NE_EXPR:
2255 pp_c_equality_expression (pp, e);
2256 break;
2258 case COND_EXPR:
2259 pp_conditional_expression (pp, e);
2260 break;
2262 case POINTER_PLUS_EXPR:
2263 case PLUS_EXPR:
2264 case MINUS_EXPR:
2265 pp_c_additive_expression (pp, e);
2266 break;
2268 case MODIFY_EXPR:
2269 case INIT_EXPR:
2270 pp_assignment_expression (pp, e);
2271 break;
2273 case COMPOUND_EXPR:
2274 pp_c_left_paren (pp);
2275 pp_expression (pp, TREE_OPERAND (e, 0));
2276 pp_separate_with (pp, ',');
2277 pp_assignment_expression (pp, TREE_OPERAND (e, 1));
2278 pp_c_right_paren (pp);
2279 break;
2281 case NON_LVALUE_EXPR:
2282 case SAVE_EXPR:
2283 pp_expression (pp, TREE_OPERAND (e, 0));
2284 break;
2286 case TARGET_EXPR:
2287 pp_postfix_expression (pp, TREE_OPERAND (e, 1));
2288 break;
2290 case BIND_EXPR:
2291 case GOTO_EXPR:
2292 /* We don't yet have a way of dumping statements in a
2293 human-readable format. */
2294 pp_string (pp, "({...})");
2295 break;
2297 case C_MAYBE_CONST_EXPR:
2298 pp_c_expression (pp, C_MAYBE_CONST_EXPR_EXPR (e));
2299 break;
2301 default:
2302 pp_unsupported_tree (pp, e);
2303 break;
2309 /* Statements. */
2311 void
2312 pp_c_statement (c_pretty_printer *pp, tree stmt)
2314 if (stmt == NULL)
2315 return;
2317 if (pp_needs_newline (pp))
2318 pp_newline_and_indent (pp, 0);
2320 dump_generic_node (pp, stmt, pp_indentation (pp), 0, true);
2324 /* Initialize the PRETTY-PRINTER for handling C codes. */
2326 c_pretty_printer::c_pretty_printer ()
2327 : pretty_printer ()
2329 offset_list = 0;
2330 flags = 0;
2331 declaration = pp_c_declaration;
2332 declaration_specifiers = pp_c_declaration_specifiers;
2333 declarator = pp_c_declarator;
2334 direct_declarator = pp_c_direct_declarator;
2335 type_specifier_seq = pp_c_specifier_qualifier_list;
2336 abstract_declarator = pp_c_abstract_declarator;
2337 direct_abstract_declarator = pp_c_direct_abstract_declarator;
2338 ptr_operator = pp_c_pointer;
2339 parameter_list = pp_c_parameter_type_list;
2340 type_id = pp_c_type_id;
2341 simple_type_specifier = pp_c_type_specifier;
2342 function_specifier = pp_c_function_specifier;
2343 storage_class_specifier = pp_c_storage_class_specifier;
2345 statement = pp_c_statement;
2347 unary_expression = pp_c_unary_expression;
2348 initializer = pp_c_initializer;
2349 multiplicative_expression = pp_c_multiplicative_expression;
2350 conditional_expression = pp_c_conditional_expression;
2351 assignment_expression = pp_c_assignment_expression;
2352 expression = pp_c_expression;
2356 /* Print the tree T in full, on file FILE. */
2358 void
2359 print_c_tree (FILE *file, tree t)
2361 c_pretty_printer pp;
2363 pp_needs_newline (&pp) = true;
2364 pp.buffer->stream = file;
2365 pp_statement (&pp, t);
2366 pp_newline_and_flush (&pp);
2369 /* Print the tree T in full, on stderr. */
2371 DEBUG_FUNCTION void
2372 debug_c_tree (tree t)
2374 print_c_tree (stderr, t);
2375 fputc ('\n', stderr);
2378 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2379 up of T's memory address. */
2381 void
2382 pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t)
2384 const char *name;
2386 gcc_assert (DECL_P (t));
2388 if (DECL_NAME (t))
2389 name = IDENTIFIER_POINTER (DECL_NAME (t));
2390 else
2392 static char xname[8];
2393 sprintf (xname, "<U%4x>", ((unsigned)((uintptr_t)(t) & 0xffff)));
2394 name = xname;
2397 pp_c_identifier (pp, name);