re PR c++/87364 (Pretty print of enumerator never prints the id, always falls back...
[official-gcc.git] / gcc / c-family / c-pretty-print.c
blobbdd5567614d44a2bca93df2a86c4b5cc7d23edb9
1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002-2018 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 "c-pretty-print.h"
25 #include "diagnostic.h"
26 #include "stor-layout.h"
27 #include "stringpool.h"
28 #include "attribs.h"
29 #include "intl.h"
30 #include "tree-pretty-print.h"
31 #include "selftest.h"
33 /* The pretty-printer code is primarily designed to closely follow
34 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
35 codes we used to have in the past. Following a structured
36 approach (preferably the official grammars) is believed to make it
37 much easier to add extensions and nifty pretty-printing effects that
38 takes expression or declaration contexts into account. */
41 #define pp_c_maybe_whitespace(PP) \
42 do { \
43 if ((PP)->padding == pp_before) \
44 pp_c_whitespace (PP); \
45 } while (0)
47 /* literal */
48 static void pp_c_char (c_pretty_printer *, int);
50 /* postfix-expression */
51 static void pp_c_initializer_list (c_pretty_printer *, tree);
52 static void pp_c_brace_enclosed_initializer_list (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);
63 /* declarations. */
66 /* Helper functions. */
68 void
69 pp_c_whitespace (c_pretty_printer *pp)
71 pp_space (pp);
72 pp->padding = pp_none;
75 void
76 pp_c_left_paren (c_pretty_printer *pp)
78 pp_left_paren (pp);
79 pp->padding = pp_none;
82 void
83 pp_c_right_paren (c_pretty_printer *pp)
85 pp_right_paren (pp);
86 pp->padding = pp_none;
89 void
90 pp_c_left_brace (c_pretty_printer *pp)
92 pp_left_brace (pp);
93 pp->padding = pp_none;
96 void
97 pp_c_right_brace (c_pretty_printer *pp)
99 pp_right_brace (pp);
100 pp->padding = pp_none;
103 void
104 pp_c_left_bracket (c_pretty_printer *pp)
106 pp_left_bracket (pp);
107 pp->padding = pp_none;
110 void
111 pp_c_right_bracket (c_pretty_printer *pp)
113 pp_right_bracket (pp);
114 pp->padding = pp_none;
117 void
118 pp_c_dot (c_pretty_printer *pp)
120 pp_dot (pp);
121 pp->padding = pp_none;
124 void
125 pp_c_ampersand (c_pretty_printer *pp)
127 pp_ampersand (pp);
128 pp->padding = pp_none;
131 void
132 pp_c_star (c_pretty_printer *pp)
134 pp_star (pp);
135 pp->padding = pp_none;
138 void
139 pp_c_arrow (c_pretty_printer *pp)
141 pp_arrow (pp);
142 pp->padding = pp_none;
145 void
146 pp_c_semicolon (c_pretty_printer *pp)
148 pp_semicolon (pp);
149 pp->padding = pp_none;
152 void
153 pp_c_complement (c_pretty_printer *pp)
155 pp_complement (pp);
156 pp->padding = pp_none;
159 void
160 pp_c_exclamation (c_pretty_printer *pp)
162 pp_exclamation (pp);
163 pp->padding = pp_none;
166 /* Print out the external representation of QUALIFIERS. */
168 void
169 pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type)
171 const char *p = pp_last_position_in_text (pp);
173 if (!qualifiers)
174 return;
176 /* The C programming language does not have references, but it is much
177 simpler to handle those here rather than going through the same
178 logic in the C++ pretty-printer. */
179 if (p != NULL && (*p == '*' || *p == '&'))
180 pp_c_whitespace (pp);
182 if (qualifiers & TYPE_QUAL_ATOMIC)
183 pp_c_ws_string (pp, "_Atomic");
184 if (qualifiers & TYPE_QUAL_CONST)
185 pp_c_ws_string (pp, func_type ? "__attribute__((const))" : "const");
186 if (qualifiers & TYPE_QUAL_VOLATILE)
187 pp_c_ws_string (pp, func_type ? "__attribute__((noreturn))" : "volatile");
188 if (qualifiers & TYPE_QUAL_RESTRICT)
189 pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
190 ? "restrict" : "__restrict__"));
193 /* Pretty-print T using the type-cast notation '( type-name )'. */
195 void
196 pp_c_type_cast (c_pretty_printer *pp, tree t)
198 pp_c_left_paren (pp);
199 pp->type_id (t);
200 pp_c_right_paren (pp);
203 /* We're about to pretty-print a pointer type as indicated by T.
204 Output a whitespace, if needed, preparing for subsequent output. */
206 void
207 pp_c_space_for_pointer_operator (c_pretty_printer *pp, tree t)
209 if (POINTER_TYPE_P (t))
211 tree pointee = strip_pointer_operator (TREE_TYPE (t));
212 if (TREE_CODE (pointee) != ARRAY_TYPE
213 && TREE_CODE (pointee) != FUNCTION_TYPE)
214 pp_c_whitespace (pp);
219 /* Declarations. */
221 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
222 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
223 of its type. Take care of possible extensions.
225 type-qualifier-list:
226 type-qualifier
227 type-qualifier-list type-qualifier
229 type-qualifier:
230 const
231 restrict -- C99
232 __restrict__ -- GNU C
233 address-space-qualifier -- GNU C
234 volatile
235 _Atomic -- C11
237 address-space-qualifier:
238 identifier -- GNU C */
240 void
241 pp_c_type_qualifier_list (c_pretty_printer *pp, tree t)
243 int qualifiers;
245 if (!t || t == error_mark_node)
246 return;
248 if (!TYPE_P (t))
249 t = TREE_TYPE (t);
251 qualifiers = TYPE_QUALS (t);
252 pp_c_cv_qualifiers (pp, qualifiers,
253 TREE_CODE (t) == FUNCTION_TYPE);
255 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t)))
257 const char *as = c_addr_space_name (TYPE_ADDR_SPACE (t));
258 pp_c_identifier (pp, as);
262 /* pointer:
263 * type-qualifier-list(opt)
264 * type-qualifier-list(opt) pointer */
266 static void
267 pp_c_pointer (c_pretty_printer *pp, tree t)
269 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
270 t = TREE_TYPE (t);
271 switch (TREE_CODE (t))
273 case POINTER_TYPE:
274 /* It is easier to handle C++ reference types here. */
275 case REFERENCE_TYPE:
276 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
277 pp_c_pointer (pp, TREE_TYPE (t));
278 if (TREE_CODE (t) == POINTER_TYPE)
279 pp_c_star (pp);
280 else
281 pp_c_ampersand (pp);
282 pp_c_type_qualifier_list (pp, t);
283 break;
285 /* ??? This node is now in GENERIC and so shouldn't be here. But
286 we'll fix that later. */
287 case DECL_EXPR:
288 pp->declaration (DECL_EXPR_DECL (t));
289 pp_needs_newline (pp) = true;
290 break;
292 default:
293 pp_unsupported_tree (pp, t);
297 /* simple-type-specifier:
298 type-specifier
300 type-specifier:
301 void
302 char
303 short
305 long
306 float
307 double
308 signed
309 unsigned
310 _Bool -- C99
311 _Complex -- C99
312 _Imaginary -- C99
313 struct-or-union-specifier
314 enum-specifier
315 typedef-name.
317 GNU extensions.
318 simple-type-specifier:
319 __complex__
320 __vector__ */
322 void
323 c_pretty_printer::simple_type_specifier (tree t)
325 const enum tree_code code = TREE_CODE (t);
326 switch (code)
328 case ERROR_MARK:
329 translate_string ("<type-error>");
330 break;
332 case IDENTIFIER_NODE:
333 pp_c_identifier (this, IDENTIFIER_POINTER (t));
334 break;
336 case VOID_TYPE:
337 case BOOLEAN_TYPE:
338 case INTEGER_TYPE:
339 case REAL_TYPE:
340 case FIXED_POINT_TYPE:
341 if (TYPE_NAME (t))
343 t = TYPE_NAME (t);
344 simple_type_specifier (t);
346 else
348 int prec = TYPE_PRECISION (t);
349 tree common_t;
350 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t)))
351 common_t = c_common_type_for_mode (TYPE_MODE (t),
352 TYPE_SATURATING (t));
353 else
354 common_t = c_common_type_for_mode (TYPE_MODE (t),
355 TYPE_UNSIGNED (t));
356 if (common_t && TYPE_NAME (common_t))
358 simple_type_specifier (common_t);
359 if (TYPE_PRECISION (common_t) != prec)
361 pp_colon (this);
362 pp_decimal_int (this, prec);
365 else
367 switch (code)
369 case INTEGER_TYPE:
370 translate_string (TYPE_UNSIGNED (t)
371 ? "<unnamed-unsigned:"
372 : "<unnamed-signed:");
373 break;
374 case REAL_TYPE:
375 translate_string ("<unnamed-float:");
376 break;
377 case FIXED_POINT_TYPE:
378 translate_string ("<unnamed-fixed:");
379 break;
380 default:
381 gcc_unreachable ();
383 pp_decimal_int (this, prec);
384 pp_greater (this);
387 break;
389 case TYPE_DECL:
390 if (DECL_NAME (t))
391 id_expression (t);
392 else
393 translate_string ("<typedef-error>");
394 break;
396 case UNION_TYPE:
397 case RECORD_TYPE:
398 case ENUMERAL_TYPE:
399 if (TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
400 /* Don't decorate the type if this is a typedef name. */;
401 else if (code == UNION_TYPE)
402 pp_c_ws_string (this, "union");
403 else if (code == RECORD_TYPE)
404 pp_c_ws_string (this, "struct");
405 else if (code == ENUMERAL_TYPE)
406 pp_c_ws_string (this, "enum");
407 else
408 translate_string ("<tag-error>");
410 if (TYPE_NAME (t))
411 id_expression (TYPE_NAME (t));
412 else
413 translate_string ("<anonymous>");
414 break;
416 default:
417 pp_unsupported_tree (this, t);
418 break;
422 /* specifier-qualifier-list:
423 type-specifier specifier-qualifier-list-opt
424 type-qualifier specifier-qualifier-list-opt
427 Implementation note: Because of the non-linearities in array or
428 function declarations, this routine prints not just the
429 specifier-qualifier-list of such entities or types of such entities,
430 but also the 'pointer' production part of their declarators. The
431 remaining part is done by declarator() or abstract_declarator(). */
433 void
434 pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree t)
436 const enum tree_code code = TREE_CODE (t);
438 if (!(pp->flags & pp_c_flag_gnu_v3) && code != POINTER_TYPE)
439 pp_c_type_qualifier_list (pp, t);
440 switch (code)
442 case REFERENCE_TYPE:
443 case POINTER_TYPE:
445 /* Get the types-specifier of this type. */
446 tree pointee = strip_pointer_operator (TREE_TYPE (t));
447 pp_c_specifier_qualifier_list (pp, pointee);
448 if (TREE_CODE (pointee) == ARRAY_TYPE
449 || TREE_CODE (pointee) == FUNCTION_TYPE)
451 pp_c_whitespace (pp);
452 pp_c_left_paren (pp);
453 pp_c_attributes_display (pp, TYPE_ATTRIBUTES (pointee));
455 else if (!c_dialect_cxx ())
456 pp_c_whitespace (pp);
457 pp_ptr_operator (pp, t);
459 break;
461 case FUNCTION_TYPE:
462 case ARRAY_TYPE:
463 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
464 break;
466 case VECTOR_TYPE:
467 case COMPLEX_TYPE:
468 if (code == COMPLEX_TYPE)
469 pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
470 ? "_Complex" : "__complex__"));
471 else if (code == VECTOR_TYPE)
473 pp_c_ws_string (pp, "__vector");
474 pp_c_left_paren (pp);
475 pp_wide_integer (pp, TYPE_VECTOR_SUBPARTS (t));
476 pp_c_right_paren (pp);
477 pp_c_whitespace (pp);
479 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
480 break;
482 default:
483 pp->simple_type_specifier (t);
484 break;
486 if ((pp->flags & pp_c_flag_gnu_v3) && code != POINTER_TYPE)
487 pp_c_type_qualifier_list (pp, t);
490 /* parameter-type-list:
491 parameter-list
492 parameter-list , ...
494 parameter-list:
495 parameter-declaration
496 parameter-list , parameter-declaration
498 parameter-declaration:
499 declaration-specifiers declarator
500 declaration-specifiers abstract-declarator(opt) */
502 void
503 pp_c_parameter_type_list (c_pretty_printer *pp, tree t)
505 bool want_parm_decl = DECL_P (t) && !(pp->flags & pp_c_flag_abstract);
506 tree parms = want_parm_decl ? DECL_ARGUMENTS (t) : TYPE_ARG_TYPES (t);
507 pp_c_left_paren (pp);
508 if (parms == void_list_node)
509 pp_c_ws_string (pp, "void");
510 else
512 bool first = true;
513 for ( ; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
515 if (!first)
516 pp_separate_with (pp, ',');
517 first = false;
518 pp->declaration_specifiers
519 (want_parm_decl ? parms : TREE_VALUE (parms));
520 if (want_parm_decl)
521 pp->declarator (parms);
522 else
523 pp->abstract_declarator (TREE_VALUE (parms));
525 if (!first && !parms)
527 pp_separate_with (pp, ',');
528 pp_c_ws_string (pp, "...");
531 pp_c_right_paren (pp);
534 /* abstract-declarator:
535 pointer
536 pointer(opt) direct-abstract-declarator */
538 void
539 c_pretty_printer::abstract_declarator (tree t)
541 if (TREE_CODE (t) == POINTER_TYPE)
543 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
544 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
545 pp_c_right_paren (this);
546 t = TREE_TYPE (t);
549 direct_abstract_declarator (t);
552 /* direct-abstract-declarator:
553 ( abstract-declarator )
554 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
555 direct-abstract-declarator(opt) [ * ]
556 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
558 void
559 c_pretty_printer::direct_abstract_declarator (tree t)
561 switch (TREE_CODE (t))
563 case POINTER_TYPE:
564 abstract_declarator (t);
565 break;
567 case FUNCTION_TYPE:
568 pp_c_parameter_type_list (this, t);
569 direct_abstract_declarator (TREE_TYPE (t));
570 break;
572 case ARRAY_TYPE:
573 pp_c_left_bracket (this);
574 if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t)))
576 tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (t));
577 tree type = TREE_TYPE (maxval);
579 if (tree_fits_shwi_p (maxval))
580 pp_wide_integer (this, tree_to_shwi (maxval) + 1);
581 else
582 expression (fold_build2 (PLUS_EXPR, type, maxval,
583 build_int_cst (type, 1)));
585 pp_c_right_bracket (this);
586 direct_abstract_declarator (TREE_TYPE (t));
587 break;
589 case IDENTIFIER_NODE:
590 case VOID_TYPE:
591 case BOOLEAN_TYPE:
592 case INTEGER_TYPE:
593 case REAL_TYPE:
594 case FIXED_POINT_TYPE:
595 case ENUMERAL_TYPE:
596 case RECORD_TYPE:
597 case UNION_TYPE:
598 case VECTOR_TYPE:
599 case COMPLEX_TYPE:
600 case TYPE_DECL:
601 break;
603 default:
604 pp_unsupported_tree (this, t);
605 break;
609 /* type-name:
610 specifier-qualifier-list abstract-declarator(opt) */
612 void
613 c_pretty_printer::type_id (tree t)
615 pp_c_specifier_qualifier_list (this, t);
616 abstract_declarator (t);
619 /* storage-class-specifier:
620 typedef
621 extern
622 static
623 auto
624 register */
626 void
627 c_pretty_printer::storage_class_specifier (tree t)
629 if (TREE_CODE (t) == TYPE_DECL)
630 pp_c_ws_string (this, "typedef");
631 else if (DECL_P (t))
633 if (DECL_REGISTER (t))
634 pp_c_ws_string (this, "register");
635 else if (TREE_STATIC (t) && VAR_P (t))
636 pp_c_ws_string (this, "static");
640 /* function-specifier:
641 inline */
643 void
644 c_pretty_printer::function_specifier (tree t)
646 if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t))
647 pp_c_ws_string (this, "inline");
650 /* declaration-specifiers:
651 storage-class-specifier declaration-specifiers(opt)
652 type-specifier declaration-specifiers(opt)
653 type-qualifier declaration-specifiers(opt)
654 function-specifier declaration-specifiers(opt) */
656 void
657 c_pretty_printer::declaration_specifiers (tree t)
659 storage_class_specifier (t);
660 function_specifier (t);
661 pp_c_specifier_qualifier_list (this, DECL_P (t) ? TREE_TYPE (t) : t);
664 /* direct-declarator
665 identifier
666 ( declarator )
667 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
668 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
669 direct-declarator [ type-qualifier-list static assignment-expression ]
670 direct-declarator [ type-qualifier-list * ]
671 direct-declarator ( parameter-type-list )
672 direct-declarator ( identifier-list(opt) ) */
674 void
675 c_pretty_printer::direct_declarator (tree t)
677 switch (TREE_CODE (t))
679 case VAR_DECL:
680 case PARM_DECL:
681 case TYPE_DECL:
682 case FIELD_DECL:
683 case LABEL_DECL:
684 pp_c_space_for_pointer_operator (this, TREE_TYPE (t));
685 pp_c_tree_decl_identifier (this, t);
686 break;
688 case ARRAY_TYPE:
689 case POINTER_TYPE:
690 abstract_declarator (TREE_TYPE (t));
691 break;
693 case FUNCTION_TYPE:
694 pp_parameter_list (this, t);
695 abstract_declarator (TREE_TYPE (t));
696 break;
698 case FUNCTION_DECL:
699 pp_c_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t)));
700 pp_c_tree_decl_identifier (this, t);
701 if (flags & pp_c_flag_abstract)
702 abstract_declarator (TREE_TYPE (t));
703 else
705 pp_parameter_list (this, t);
706 abstract_declarator (TREE_TYPE (TREE_TYPE (t)));
708 break;
710 case INTEGER_TYPE:
711 case REAL_TYPE:
712 case FIXED_POINT_TYPE:
713 case ENUMERAL_TYPE:
714 case UNION_TYPE:
715 case RECORD_TYPE:
716 break;
718 default:
719 pp_unsupported_tree (this, t);
720 break;
725 /* declarator:
726 pointer(opt) direct-declarator */
728 void
729 c_pretty_printer::declarator (tree t)
731 switch (TREE_CODE (t))
733 case INTEGER_TYPE:
734 case REAL_TYPE:
735 case FIXED_POINT_TYPE:
736 case ENUMERAL_TYPE:
737 case UNION_TYPE:
738 case RECORD_TYPE:
739 break;
741 case VAR_DECL:
742 case PARM_DECL:
743 case FIELD_DECL:
744 case ARRAY_TYPE:
745 case FUNCTION_TYPE:
746 case FUNCTION_DECL:
747 case TYPE_DECL:
748 direct_declarator (t);
749 break;
752 default:
753 pp_unsupported_tree (this, t);
754 break;
758 /* declaration:
759 declaration-specifiers init-declarator-list(opt) ; */
761 void
762 c_pretty_printer::declaration (tree t)
764 declaration_specifiers (t);
765 pp_c_init_declarator (this, t);
768 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
770 void
771 pp_c_attributes (c_pretty_printer *pp, tree attributes)
773 if (attributes == NULL_TREE)
774 return;
776 pp_c_ws_string (pp, "__attribute__");
777 pp_c_left_paren (pp);
778 pp_c_left_paren (pp);
779 for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes))
781 pp_tree_identifier (pp, TREE_PURPOSE (attributes));
782 if (TREE_VALUE (attributes))
783 pp_c_call_argument_list (pp, TREE_VALUE (attributes));
785 if (TREE_CHAIN (attributes))
786 pp_separate_with (pp, ',');
788 pp_c_right_paren (pp);
789 pp_c_right_paren (pp);
792 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
793 marked to be displayed on disgnostic. */
795 void
796 pp_c_attributes_display (c_pretty_printer *pp, tree a)
798 bool is_first = true;
800 if (a == NULL_TREE)
801 return;
803 for (; a != NULL_TREE; a = TREE_CHAIN (a))
805 const struct attribute_spec *as;
806 as = lookup_attribute_spec (TREE_PURPOSE (a));
807 if (!as || as->affects_type_identity == false)
808 continue;
809 if (c_dialect_cxx ()
810 && !strcmp ("transaction_safe", as->name))
811 /* In C++ transaction_safe is printed at the end of the declarator. */
812 continue;
813 if (is_first)
815 pp_c_ws_string (pp, "__attribute__");
816 pp_c_left_paren (pp);
817 pp_c_left_paren (pp);
818 is_first = false;
820 else
822 pp_separate_with (pp, ',');
824 pp_tree_identifier (pp, TREE_PURPOSE (a));
825 if (TREE_VALUE (a))
826 pp_c_call_argument_list (pp, TREE_VALUE (a));
829 if (!is_first)
831 pp_c_right_paren (pp);
832 pp_c_right_paren (pp);
833 pp_c_whitespace (pp);
837 /* function-definition:
838 declaration-specifiers declarator compound-statement */
840 void
841 pp_c_function_definition (c_pretty_printer *pp, tree t)
843 pp->declaration_specifiers (t);
844 pp->declarator (t);
845 pp_needs_newline (pp) = true;
846 pp->statement (DECL_SAVED_TREE (t));
847 pp_newline_and_flush (pp);
851 /* Expressions. */
853 /* Print out a c-char. This is called solely for characters which are
854 in the *target* execution character set. We ought to convert them
855 back to the *host* execution character set before printing, but we
856 have no way to do this at present. A decent compromise is to print
857 all characters as if they were in the host execution character set,
858 and not attempt to recover any named escape characters, but render
859 all unprintables as octal escapes. If the host and target character
860 sets are the same, this produces relatively readable output. If they
861 are not the same, strings may appear as gibberish, but that's okay
862 (in fact, it may well be what the reader wants, e.g. if they are looking
863 to see if conversion to the target character set happened correctly).
865 A special case: we need to prefix \, ", and ' with backslashes. It is
866 correct to do so for the *host*'s \, ", and ', because the rest of the
867 file appears in the host character set. */
869 static void
870 pp_c_char (c_pretty_printer *pp, int c)
872 if (ISPRINT (c))
874 switch (c)
876 case '\\': pp_string (pp, "\\\\"); break;
877 case '\'': pp_string (pp, "\\\'"); break;
878 case '\"': pp_string (pp, "\\\""); break;
879 default: pp_character (pp, c);
882 else
883 pp_scalar (pp, "\\%03o", (unsigned) c);
886 /* Print out a STRING literal. */
888 void
889 pp_c_string_literal (c_pretty_printer *pp, tree s)
891 const char *p = TREE_STRING_POINTER (s);
892 int n = TREE_STRING_LENGTH (s) - 1;
893 int i;
894 pp_doublequote (pp);
895 for (i = 0; i < n; ++i)
896 pp_c_char (pp, p[i]);
897 pp_doublequote (pp);
900 /* Pretty-print a VOID_CST (void_node). */
902 static void
903 pp_c_void_constant (c_pretty_printer *pp)
905 pp_c_type_cast (pp, void_type_node);
906 pp_string (pp, "0");
909 /* Pretty-print an INTEGER literal. */
911 void
912 pp_c_integer_constant (c_pretty_printer *pp, tree i)
914 if (tree_fits_shwi_p (i))
915 pp_wide_integer (pp, tree_to_shwi (i));
916 else if (tree_fits_uhwi_p (i))
917 pp_unsigned_wide_integer (pp, tree_to_uhwi (i));
918 else
920 wide_int wi = wi::to_wide (i);
922 if (wi::lt_p (wi::to_wide (i), 0, TYPE_SIGN (TREE_TYPE (i))))
924 pp_minus (pp);
925 wi = -wi;
927 print_hex (wi, pp_buffer (pp)->digit_buffer);
928 pp_string (pp, pp_buffer (pp)->digit_buffer);
932 /* Print out a CHARACTER literal. */
934 static void
935 pp_c_character_constant (c_pretty_printer *pp, tree c)
937 pp_quote (pp);
938 pp_c_char (pp, (unsigned) TREE_INT_CST_LOW (c));
939 pp_quote (pp);
942 /* Print out a BOOLEAN literal. */
944 static void
945 pp_c_bool_constant (c_pretty_printer *pp, tree b)
947 if (b == boolean_false_node)
949 if (c_dialect_cxx ())
950 pp_c_ws_string (pp, "false");
951 else if (flag_isoc99)
952 pp_c_ws_string (pp, "_False");
953 else
954 pp_unsupported_tree (pp, b);
956 else if (b == boolean_true_node)
958 if (c_dialect_cxx ())
959 pp_c_ws_string (pp, "true");
960 else if (flag_isoc99)
961 pp_c_ws_string (pp, "_True");
962 else
963 pp_unsupported_tree (pp, b);
965 else if (TREE_CODE (b) == INTEGER_CST)
966 pp_c_integer_constant (pp, b);
967 else
968 pp_unsupported_tree (pp, b);
971 /* Given a value e of ENUMERAL_TYPE:
972 Print out the first ENUMERATOR id with value e, if one is found,
973 else print out the value as a C-style cast (type-id)value. */
975 static void
976 pp_c_enumeration_constant (c_pretty_printer *pp, tree e)
978 tree type = TREE_TYPE (e);
979 tree value;
981 /* Find the name of this constant. */
982 for (value = TYPE_VALUES (type);
983 value != NULL_TREE
984 && !tree_int_cst_equal (DECL_INITIAL (TREE_VALUE (value)), e);
985 value = TREE_CHAIN (value))
988 if (value != NULL_TREE)
989 pp->id_expression (TREE_PURPOSE (value));
990 else
992 /* Value must have been cast. */
993 pp_c_type_cast (pp, type);
994 pp_c_integer_constant (pp, e);
998 /* Print out a REAL value as a decimal-floating-constant. */
1000 static void
1001 pp_c_floating_constant (c_pretty_printer *pp, tree r)
1003 const struct real_format *fmt
1004 = REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (r)));
1006 REAL_VALUE_TYPE floating_cst = TREE_REAL_CST (r);
1007 bool is_decimal = floating_cst.decimal;
1009 /* See ISO C++ WG N1822. Note: The fraction 643/2136 approximates
1010 log10(2) to 7 significant digits. */
1011 int max_digits10 = 2 + (is_decimal ? fmt->p : fmt->p * 643L / 2136);
1013 real_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_REAL_CST (r),
1014 sizeof (pp_buffer (pp)->digit_buffer),
1015 max_digits10, 1);
1017 pp_string (pp, pp_buffer(pp)->digit_buffer);
1018 if (TREE_TYPE (r) == float_type_node)
1019 pp_character (pp, 'f');
1020 else if (TREE_TYPE (r) == long_double_type_node)
1021 pp_character (pp, 'l');
1022 else if (TREE_TYPE (r) == dfloat128_type_node)
1023 pp_string (pp, "dl");
1024 else if (TREE_TYPE (r) == dfloat64_type_node)
1025 pp_string (pp, "dd");
1026 else if (TREE_TYPE (r) == dfloat32_type_node)
1027 pp_string (pp, "df");
1028 else if (TREE_TYPE (r) != double_type_node)
1029 for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
1030 if (TREE_TYPE (r) == FLOATN_NX_TYPE_NODE (i))
1032 pp_character (pp, 'f');
1033 pp_decimal_int (pp, floatn_nx_types[i].n);
1034 if (floatn_nx_types[i].extended)
1035 pp_character (pp, 'x');
1036 break;
1040 /* Print out a FIXED value as a decimal-floating-constant. */
1042 static void
1043 pp_c_fixed_constant (c_pretty_printer *pp, tree r)
1045 fixed_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_FIXED_CST (r),
1046 sizeof (pp_buffer (pp)->digit_buffer));
1047 pp_string (pp, pp_buffer(pp)->digit_buffer);
1050 /* Pretty-print a compound literal expression. GNU extensions include
1051 vector constants. */
1053 static void
1054 pp_c_compound_literal (c_pretty_printer *pp, tree e)
1056 tree type = TREE_TYPE (e);
1057 pp_c_type_cast (pp, type);
1059 switch (TREE_CODE (type))
1061 case RECORD_TYPE:
1062 case UNION_TYPE:
1063 case ARRAY_TYPE:
1064 case VECTOR_TYPE:
1065 case COMPLEX_TYPE:
1066 pp_c_brace_enclosed_initializer_list (pp, e);
1067 break;
1069 default:
1070 pp_unsupported_tree (pp, e);
1071 break;
1075 /* Pretty-print a COMPLEX_EXPR expression. */
1077 static void
1078 pp_c_complex_expr (c_pretty_printer *pp, tree e)
1080 /* Handle a few common special cases, otherwise fallback
1081 to printing it as compound literal. */
1082 tree type = TREE_TYPE (e);
1083 tree realexpr = TREE_OPERAND (e, 0);
1084 tree imagexpr = TREE_OPERAND (e, 1);
1086 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1087 if (TREE_CODE (realexpr) == NOP_EXPR
1088 && TREE_CODE (imagexpr) == NOP_EXPR
1089 && TREE_TYPE (realexpr) == TREE_TYPE (type)
1090 && TREE_TYPE (imagexpr) == TREE_TYPE (type)
1091 && TREE_CODE (TREE_OPERAND (realexpr, 0)) == REALPART_EXPR
1092 && TREE_CODE (TREE_OPERAND (imagexpr, 0)) == IMAGPART_EXPR
1093 && TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0)
1094 == TREE_OPERAND (TREE_OPERAND (imagexpr, 0), 0))
1096 pp_c_type_cast (pp, type);
1097 pp->expression (TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0));
1098 return;
1101 /* Cast of an scalar expression to COMPLEX_TYPE. */
1102 if ((integer_zerop (imagexpr) || real_zerop (imagexpr))
1103 && TREE_TYPE (realexpr) == TREE_TYPE (type))
1105 pp_c_type_cast (pp, type);
1106 if (TREE_CODE (realexpr) == NOP_EXPR)
1107 realexpr = TREE_OPERAND (realexpr, 0);
1108 pp->expression (realexpr);
1109 return;
1112 pp_c_compound_literal (pp, e);
1115 /* constant:
1116 integer-constant
1117 floating-constant
1118 fixed-point-constant
1119 enumeration-constant
1120 character-constant */
1122 void
1123 c_pretty_printer::constant (tree e)
1125 const enum tree_code code = TREE_CODE (e);
1127 switch (code)
1129 case VOID_CST:
1130 pp_c_void_constant (this);
1131 break;
1133 case INTEGER_CST:
1135 tree type = TREE_TYPE (e);
1136 if (type == boolean_type_node)
1137 pp_c_bool_constant (this, e);
1138 else if (type == char_type_node)
1139 pp_c_character_constant (this, e);
1140 else if (TREE_CODE (type) == ENUMERAL_TYPE)
1141 pp_c_enumeration_constant (this, e))
1142 else
1143 pp_c_integer_constant (this, e);
1145 break;
1147 case REAL_CST:
1148 pp_c_floating_constant (this, e);
1149 break;
1151 case FIXED_CST:
1152 pp_c_fixed_constant (this, e);
1153 break;
1155 case STRING_CST:
1156 pp_c_string_literal (this, e);
1157 break;
1159 case COMPLEX_CST:
1160 /* Sometimes, we are confused and we think a complex literal
1161 is a constant. Such thing is a compound literal which
1162 grammatically belongs to postfix-expr production. */
1163 pp_c_compound_literal (this, e);
1164 break;
1166 default:
1167 pp_unsupported_tree (this, e);
1168 break;
1172 /* Pretty-print a string such as an identifier, without changing its
1173 encoding, preceded by whitespace is necessary. */
1175 void
1176 pp_c_ws_string (c_pretty_printer *pp, const char *str)
1178 pp_c_maybe_whitespace (pp);
1179 pp_string (pp, str);
1180 pp->padding = pp_before;
1183 void
1184 c_pretty_printer::translate_string (const char *gmsgid)
1186 if (pp_translate_identifiers (this))
1187 pp_c_ws_string (this, _(gmsgid));
1188 else
1189 pp_c_ws_string (this, gmsgid);
1192 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1193 that need converting to the locale encoding, preceded by whitespace
1194 is necessary. */
1196 void
1197 pp_c_identifier (c_pretty_printer *pp, const char *id)
1199 pp_c_maybe_whitespace (pp);
1200 pp_identifier (pp, id);
1201 pp->padding = pp_before;
1204 /* Pretty-print a C primary-expression.
1205 primary-expression:
1206 identifier
1207 constant
1208 string-literal
1209 ( expression ) */
1211 void
1212 c_pretty_printer::primary_expression (tree e)
1214 switch (TREE_CODE (e))
1216 case VAR_DECL:
1217 case PARM_DECL:
1218 case FIELD_DECL:
1219 case CONST_DECL:
1220 case FUNCTION_DECL:
1221 case LABEL_DECL:
1222 pp_c_tree_decl_identifier (this, e);
1223 break;
1225 case IDENTIFIER_NODE:
1226 pp_c_tree_identifier (this, e);
1227 break;
1229 case ERROR_MARK:
1230 translate_string ("<erroneous-expression>");
1231 break;
1233 case RESULT_DECL:
1234 translate_string ("<return-value>");
1235 break;
1237 case VOID_CST:
1238 case INTEGER_CST:
1239 case REAL_CST:
1240 case FIXED_CST:
1241 case STRING_CST:
1242 constant (e);
1243 break;
1245 case TARGET_EXPR:
1246 pp_c_ws_string (this, "__builtin_memcpy");
1247 pp_c_left_paren (this);
1248 pp_ampersand (this);
1249 primary_expression (TREE_OPERAND (e, 0));
1250 pp_separate_with (this, ',');
1251 pp_ampersand (this);
1252 initializer (TREE_OPERAND (e, 1));
1253 if (TREE_OPERAND (e, 2))
1255 pp_separate_with (this, ',');
1256 expression (TREE_OPERAND (e, 2));
1258 pp_c_right_paren (this);
1259 break;
1261 default:
1262 /* FIXME: Make sure we won't get into an infinite loop. */
1263 pp_c_left_paren (this);
1264 expression (e);
1265 pp_c_right_paren (this);
1266 break;
1270 /* Print out a C initializer -- also support C compound-literals.
1271 initializer:
1272 assignment-expression:
1273 { initializer-list }
1274 { initializer-list , } */
1276 void
1277 c_pretty_printer::initializer (tree e)
1279 if (TREE_CODE (e) == CONSTRUCTOR)
1280 pp_c_brace_enclosed_initializer_list (this, e);
1281 else
1282 expression (e);
1285 /* init-declarator:
1286 declarator:
1287 declarator = initializer */
1289 void
1290 pp_c_init_declarator (c_pretty_printer *pp, tree t)
1292 pp->declarator (t);
1293 /* We don't want to output function definitions here. There are handled
1294 elsewhere (and the syntactic form is bogus anyway). */
1295 if (TREE_CODE (t) != FUNCTION_DECL && DECL_INITIAL (t))
1297 tree init = DECL_INITIAL (t);
1298 /* This C++ bit is handled here because it is easier to do so.
1299 In templates, the C++ parser builds a TREE_LIST for a
1300 direct-initialization; the TREE_PURPOSE is the variable to
1301 initialize and the TREE_VALUE is the initializer. */
1302 if (TREE_CODE (init) == TREE_LIST)
1304 pp_c_left_paren (pp);
1305 pp->expression (TREE_VALUE (init));
1306 pp_right_paren (pp);
1308 else
1310 pp_space (pp);
1311 pp_equal (pp);
1312 pp_space (pp);
1313 pp->initializer (init);
1318 /* initializer-list:
1319 designation(opt) initializer
1320 initializer-list , designation(opt) initializer
1322 designation:
1323 designator-list =
1325 designator-list:
1326 designator
1327 designator-list designator
1329 designator:
1330 [ constant-expression ]
1331 identifier */
1333 static void
1334 pp_c_initializer_list (c_pretty_printer *pp, tree e)
1336 tree type = TREE_TYPE (e);
1337 const enum tree_code code = TREE_CODE (type);
1339 if (TREE_CODE (e) == CONSTRUCTOR)
1341 pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e));
1342 return;
1345 switch (code)
1347 case RECORD_TYPE:
1348 case UNION_TYPE:
1349 case ARRAY_TYPE:
1351 tree init = TREE_OPERAND (e, 0);
1352 for (; init != NULL_TREE; init = TREE_CHAIN (init))
1354 if (code == RECORD_TYPE || code == UNION_TYPE)
1356 pp_c_dot (pp);
1357 pp->primary_expression (TREE_PURPOSE (init));
1359 else
1361 pp_c_left_bracket (pp);
1362 if (TREE_PURPOSE (init))
1363 pp->constant (TREE_PURPOSE (init));
1364 pp_c_right_bracket (pp);
1366 pp_c_whitespace (pp);
1367 pp_equal (pp);
1368 pp_c_whitespace (pp);
1369 pp->initializer (TREE_VALUE (init));
1370 if (TREE_CHAIN (init))
1371 pp_separate_with (pp, ',');
1374 return;
1376 case VECTOR_TYPE:
1377 if (TREE_CODE (e) == VECTOR_CST)
1379 /* We don't create variable-length VECTOR_CSTs. */
1380 unsigned int nunits = VECTOR_CST_NELTS (e).to_constant ();
1381 for (unsigned int i = 0; i < nunits; ++i)
1383 if (i > 0)
1384 pp_separate_with (pp, ',');
1385 pp->expression (VECTOR_CST_ELT (e, i));
1388 else
1389 break;
1390 return;
1392 case COMPLEX_TYPE:
1393 if (TREE_CODE (e) == COMPLEX_CST || TREE_CODE (e) == COMPLEX_EXPR)
1395 const bool cst = TREE_CODE (e) == COMPLEX_CST;
1396 pp->expression (cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0));
1397 pp_separate_with (pp, ',');
1398 pp->expression (cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1));
1400 else
1401 break;
1402 return;
1404 default:
1405 break;
1408 pp_unsupported_tree (pp, type);
1411 /* Pretty-print a brace-enclosed initializer-list. */
1413 static void
1414 pp_c_brace_enclosed_initializer_list (c_pretty_printer *pp, tree l)
1416 pp_c_left_brace (pp);
1417 pp_c_initializer_list (pp, l);
1418 pp_c_right_brace (pp);
1422 /* This is a convenient function, used to bridge gap between C and C++
1423 grammars.
1425 id-expression:
1426 identifier */
1428 void
1429 c_pretty_printer::id_expression (tree t)
1431 switch (TREE_CODE (t))
1433 case VAR_DECL:
1434 case PARM_DECL:
1435 case CONST_DECL:
1436 case TYPE_DECL:
1437 case FUNCTION_DECL:
1438 case FIELD_DECL:
1439 case LABEL_DECL:
1440 pp_c_tree_decl_identifier (this, t);
1441 break;
1443 case IDENTIFIER_NODE:
1444 pp_c_tree_identifier (this, t);
1445 break;
1447 default:
1448 pp_unsupported_tree (this, t);
1449 break;
1453 /* postfix-expression:
1454 primary-expression
1455 postfix-expression [ expression ]
1456 postfix-expression ( argument-expression-list(opt) )
1457 postfix-expression . identifier
1458 postfix-expression -> identifier
1459 postfix-expression ++
1460 postfix-expression --
1461 ( type-name ) { initializer-list }
1462 ( type-name ) { initializer-list , } */
1464 void
1465 c_pretty_printer::postfix_expression (tree e)
1467 enum tree_code code = TREE_CODE (e);
1468 switch (code)
1470 case POSTINCREMENT_EXPR:
1471 case POSTDECREMENT_EXPR:
1472 postfix_expression (TREE_OPERAND (e, 0));
1473 pp_string (this, code == POSTINCREMENT_EXPR ? "++" : "--");
1474 break;
1476 case ARRAY_REF:
1477 postfix_expression (TREE_OPERAND (e, 0));
1478 pp_c_left_bracket (this);
1479 expression (TREE_OPERAND (e, 1));
1480 pp_c_right_bracket (this);
1481 break;
1483 case CALL_EXPR:
1485 call_expr_arg_iterator iter;
1486 tree arg;
1487 postfix_expression (CALL_EXPR_FN (e));
1488 pp_c_left_paren (this);
1489 FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
1491 expression (arg);
1492 if (more_call_expr_args_p (&iter))
1493 pp_separate_with (this, ',');
1495 pp_c_right_paren (this);
1496 break;
1499 case UNORDERED_EXPR:
1500 pp_c_ws_string (this, flag_isoc99
1501 ? "isunordered"
1502 : "__builtin_isunordered");
1503 goto two_args_fun;
1505 case ORDERED_EXPR:
1506 pp_c_ws_string (this, flag_isoc99
1507 ? "!isunordered"
1508 : "!__builtin_isunordered");
1509 goto two_args_fun;
1511 case UNLT_EXPR:
1512 pp_c_ws_string (this, flag_isoc99
1513 ? "!isgreaterequal"
1514 : "!__builtin_isgreaterequal");
1515 goto two_args_fun;
1517 case UNLE_EXPR:
1518 pp_c_ws_string (this, flag_isoc99
1519 ? "!isgreater"
1520 : "!__builtin_isgreater");
1521 goto two_args_fun;
1523 case UNGT_EXPR:
1524 pp_c_ws_string (this, flag_isoc99
1525 ? "!islessequal"
1526 : "!__builtin_islessequal");
1527 goto two_args_fun;
1529 case UNGE_EXPR:
1530 pp_c_ws_string (this, flag_isoc99
1531 ? "!isless"
1532 : "!__builtin_isless");
1533 goto two_args_fun;
1535 case UNEQ_EXPR:
1536 pp_c_ws_string (this, flag_isoc99
1537 ? "!islessgreater"
1538 : "!__builtin_islessgreater");
1539 goto two_args_fun;
1541 case LTGT_EXPR:
1542 pp_c_ws_string (this, flag_isoc99
1543 ? "islessgreater"
1544 : "__builtin_islessgreater");
1545 goto two_args_fun;
1547 case MAX_EXPR:
1548 pp_c_ws_string (this, "max");
1549 goto two_args_fun;
1551 case MIN_EXPR:
1552 pp_c_ws_string (this, "min");
1553 goto two_args_fun;
1555 two_args_fun:
1556 pp_c_left_paren (this);
1557 expression (TREE_OPERAND (e, 0));
1558 pp_separate_with (this, ',');
1559 expression (TREE_OPERAND (e, 1));
1560 pp_c_right_paren (this);
1561 break;
1563 case ABS_EXPR:
1564 pp_c_ws_string (this, "__builtin_abs");
1565 pp_c_left_paren (this);
1566 expression (TREE_OPERAND (e, 0));
1567 pp_c_right_paren (this);
1568 break;
1570 case COMPONENT_REF:
1572 tree object = TREE_OPERAND (e, 0);
1573 if (INDIRECT_REF_P (object))
1575 postfix_expression (TREE_OPERAND (object, 0));
1576 pp_c_arrow (this);
1578 else
1580 postfix_expression (object);
1581 pp_c_dot (this);
1583 expression (TREE_OPERAND (e, 1));
1585 break;
1587 case BIT_FIELD_REF:
1589 tree type = TREE_TYPE (e);
1591 type = signed_or_unsigned_type_for (TYPE_UNSIGNED (type), type);
1592 if (type
1593 && tree_int_cst_equal (TYPE_SIZE (type), TREE_OPERAND (e, 1)))
1595 HOST_WIDE_INT bitpos = tree_to_shwi (TREE_OPERAND (e, 2));
1596 HOST_WIDE_INT size = tree_to_shwi (TYPE_SIZE (type));
1597 if ((bitpos % size) == 0)
1599 pp_c_left_paren (this);
1600 pp_c_left_paren (this);
1601 type_id (type);
1602 pp_c_star (this);
1603 pp_c_right_paren (this);
1604 pp_c_ampersand (this);
1605 expression (TREE_OPERAND (e, 0));
1606 pp_c_right_paren (this);
1607 pp_c_left_bracket (this);
1608 pp_wide_integer (this, bitpos / size);
1609 pp_c_right_bracket (this);
1610 break;
1613 pp_unsupported_tree (this, e);
1615 break;
1617 case MEM_REF:
1618 expression (e);
1619 break;
1621 case COMPLEX_CST:
1622 case VECTOR_CST:
1623 pp_c_compound_literal (this, e);
1624 break;
1626 case COMPLEX_EXPR:
1627 pp_c_complex_expr (this, e);
1628 break;
1630 case COMPOUND_LITERAL_EXPR:
1631 e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e));
1632 /* Fall through. */
1633 case CONSTRUCTOR:
1634 initializer (e);
1635 break;
1637 case VA_ARG_EXPR:
1638 pp_c_ws_string (this, "__builtin_va_arg");
1639 pp_c_left_paren (this);
1640 assignment_expression (TREE_OPERAND (e, 0));
1641 pp_separate_with (this, ',');
1642 type_id (TREE_TYPE (e));
1643 pp_c_right_paren (this);
1644 break;
1646 case ADDR_EXPR:
1647 if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
1649 id_expression (TREE_OPERAND (e, 0));
1650 break;
1652 /* fall through. */
1654 default:
1655 primary_expression (e);
1656 break;
1660 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1662 void
1663 pp_c_expression_list (c_pretty_printer *pp, tree e)
1665 for (; e != NULL_TREE; e = TREE_CHAIN (e))
1667 pp->expression (TREE_VALUE (e));
1668 if (TREE_CHAIN (e))
1669 pp_separate_with (pp, ',');
1673 /* Print out V, which contains the elements of a constructor. */
1675 void
1676 pp_c_constructor_elts (c_pretty_printer *pp, vec<constructor_elt, va_gc> *v)
1678 unsigned HOST_WIDE_INT ix;
1679 tree value;
1681 FOR_EACH_CONSTRUCTOR_VALUE (v, ix, value)
1683 pp->expression (value);
1684 if (ix != vec_safe_length (v) - 1)
1685 pp_separate_with (pp, ',');
1689 /* Print out an expression-list in parens, as if it were the argument
1690 list to a function. */
1692 void
1693 pp_c_call_argument_list (c_pretty_printer *pp, tree t)
1695 pp_c_left_paren (pp);
1696 if (t && TREE_CODE (t) == TREE_LIST)
1697 pp_c_expression_list (pp, t);
1698 pp_c_right_paren (pp);
1701 /* unary-expression:
1702 postfix-expression
1703 ++ cast-expression
1704 -- cast-expression
1705 unary-operator cast-expression
1706 sizeof unary-expression
1707 sizeof ( type-id )
1709 unary-operator: one of
1710 * & + - ! ~
1712 GNU extensions.
1713 unary-expression:
1714 __alignof__ unary-expression
1715 __alignof__ ( type-id )
1716 __real__ unary-expression
1717 __imag__ unary-expression */
1719 void
1720 c_pretty_printer::unary_expression (tree e)
1722 enum tree_code code = TREE_CODE (e);
1723 switch (code)
1725 case PREINCREMENT_EXPR:
1726 case PREDECREMENT_EXPR:
1727 pp_string (this, code == PREINCREMENT_EXPR ? "++" : "--");
1728 unary_expression (TREE_OPERAND (e, 0));
1729 break;
1731 case ADDR_EXPR:
1732 case INDIRECT_REF:
1733 case NEGATE_EXPR:
1734 case BIT_NOT_EXPR:
1735 case TRUTH_NOT_EXPR:
1736 case CONJ_EXPR:
1737 /* String literal are used by address. */
1738 if (code == ADDR_EXPR && TREE_CODE (TREE_OPERAND (e, 0)) != STRING_CST)
1739 pp_ampersand (this);
1740 else if (code == INDIRECT_REF)
1742 tree type = TREE_TYPE (TREE_OPERAND (e, 0));
1743 if (type && TREE_CODE (type) == REFERENCE_TYPE)
1744 /* Reference decay is implicit, don't print anything. */;
1745 else
1746 pp_c_star (this);
1748 else if (code == NEGATE_EXPR)
1749 pp_minus (this);
1750 else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
1751 pp_complement (this);
1752 else if (code == TRUTH_NOT_EXPR)
1753 pp_exclamation (this);
1754 pp_c_cast_expression (this, TREE_OPERAND (e, 0));
1755 break;
1757 case MEM_REF:
1758 if (TREE_CODE (TREE_OPERAND (e, 0)) == ADDR_EXPR
1759 && integer_zerop (TREE_OPERAND (e, 1)))
1760 expression (TREE_OPERAND (TREE_OPERAND (e, 0), 0));
1761 else
1763 pp_c_star (this);
1764 if (!integer_zerop (TREE_OPERAND (e, 1)))
1766 pp_c_left_paren (this);
1767 if (!integer_onep (TYPE_SIZE_UNIT
1768 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e, 0))))))
1769 pp_c_type_cast (this, ptr_type_node);
1771 pp_c_cast_expression (this, TREE_OPERAND (e, 0));
1772 if (!integer_zerop (TREE_OPERAND (e, 1)))
1774 pp_plus (this);
1775 pp_c_integer_constant (this,
1776 fold_convert (ssizetype,
1777 TREE_OPERAND (e, 1)));
1778 pp_c_right_paren (this);
1781 break;
1783 case REALPART_EXPR:
1784 case IMAGPART_EXPR:
1785 pp_c_ws_string (this, code == REALPART_EXPR ? "__real__" : "__imag__");
1786 pp_c_whitespace (this);
1787 unary_expression (TREE_OPERAND (e, 0));
1788 break;
1790 default:
1791 postfix_expression (e);
1792 break;
1796 /* cast-expression:
1797 unary-expression
1798 ( type-name ) cast-expression */
1800 void
1801 pp_c_cast_expression (c_pretty_printer *pp, tree e)
1803 switch (TREE_CODE (e))
1805 case FLOAT_EXPR:
1806 case FIX_TRUNC_EXPR:
1807 CASE_CONVERT:
1808 case VIEW_CONVERT_EXPR:
1809 if (!location_wrapper_p (e))
1810 pp_c_type_cast (pp, TREE_TYPE (e));
1811 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1812 break;
1814 default:
1815 pp->unary_expression (e);
1819 /* multiplicative-expression:
1820 cast-expression
1821 multiplicative-expression * cast-expression
1822 multiplicative-expression / cast-expression
1823 multiplicative-expression % cast-expression */
1825 void
1826 c_pretty_printer::multiplicative_expression (tree e)
1828 enum tree_code code = TREE_CODE (e);
1829 switch (code)
1831 case MULT_EXPR:
1832 case TRUNC_DIV_EXPR:
1833 case TRUNC_MOD_EXPR:
1834 case EXACT_DIV_EXPR:
1835 case RDIV_EXPR:
1836 multiplicative_expression (TREE_OPERAND (e, 0));
1837 pp_c_whitespace (this);
1838 if (code == MULT_EXPR)
1839 pp_c_star (this);
1840 else if (code != TRUNC_MOD_EXPR)
1841 pp_slash (this);
1842 else
1843 pp_modulo (this);
1844 pp_c_whitespace (this);
1845 pp_c_cast_expression (this, TREE_OPERAND (e, 1));
1846 break;
1848 default:
1849 pp_c_cast_expression (this, e);
1850 break;
1854 /* additive-expression:
1855 multiplicative-expression
1856 additive-expression + multiplicative-expression
1857 additive-expression - multiplicative-expression */
1859 static void
1860 pp_c_additive_expression (c_pretty_printer *pp, tree e)
1862 enum tree_code code = TREE_CODE (e);
1863 switch (code)
1865 case POINTER_PLUS_EXPR:
1866 case PLUS_EXPR:
1867 case POINTER_DIFF_EXPR:
1868 case MINUS_EXPR:
1869 pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
1870 pp_c_whitespace (pp);
1871 if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
1872 pp_plus (pp);
1873 else
1874 pp_minus (pp);
1875 pp_c_whitespace (pp);
1876 pp->multiplicative_expression (TREE_OPERAND (e, 1));
1877 break;
1879 default:
1880 pp->multiplicative_expression (e);
1881 break;
1885 /* additive-expression:
1886 additive-expression
1887 shift-expression << additive-expression
1888 shift-expression >> additive-expression */
1890 static void
1891 pp_c_shift_expression (c_pretty_printer *pp, tree e)
1893 enum tree_code code = TREE_CODE (e);
1894 switch (code)
1896 case LSHIFT_EXPR:
1897 case RSHIFT_EXPR:
1898 case LROTATE_EXPR:
1899 case RROTATE_EXPR:
1900 pp_c_shift_expression (pp, TREE_OPERAND (e, 0));
1901 pp_c_whitespace (pp);
1902 pp_string (pp, code == LSHIFT_EXPR ? "<<" :
1903 code == RSHIFT_EXPR ? ">>" :
1904 code == LROTATE_EXPR ? "<<<" : ">>>");
1905 pp_c_whitespace (pp);
1906 pp_c_additive_expression (pp, TREE_OPERAND (e, 1));
1907 break;
1909 default:
1910 pp_c_additive_expression (pp, e);
1914 /* relational-expression:
1915 shift-expression
1916 relational-expression < shift-expression
1917 relational-expression > shift-expression
1918 relational-expression <= shift-expression
1919 relational-expression >= shift-expression */
1921 static void
1922 pp_c_relational_expression (c_pretty_printer *pp, tree e)
1924 enum tree_code code = TREE_CODE (e);
1925 switch (code)
1927 case LT_EXPR:
1928 case GT_EXPR:
1929 case LE_EXPR:
1930 case GE_EXPR:
1931 pp_c_relational_expression (pp, TREE_OPERAND (e, 0));
1932 pp_c_whitespace (pp);
1933 if (code == LT_EXPR)
1934 pp_less (pp);
1935 else if (code == GT_EXPR)
1936 pp_greater (pp);
1937 else if (code == LE_EXPR)
1938 pp_less_equal (pp);
1939 else if (code == GE_EXPR)
1940 pp_greater_equal (pp);
1941 pp_c_whitespace (pp);
1942 pp_c_shift_expression (pp, TREE_OPERAND (e, 1));
1943 break;
1945 default:
1946 pp_c_shift_expression (pp, e);
1947 break;
1951 /* equality-expression:
1952 relational-expression
1953 equality-expression == relational-expression
1954 equality-equality != relational-expression */
1956 static void
1957 pp_c_equality_expression (c_pretty_printer *pp, tree e)
1959 enum tree_code code = TREE_CODE (e);
1960 switch (code)
1962 case EQ_EXPR:
1963 case NE_EXPR:
1964 pp_c_equality_expression (pp, TREE_OPERAND (e, 0));
1965 pp_c_whitespace (pp);
1966 pp_string (pp, code == EQ_EXPR ? "==" : "!=");
1967 pp_c_whitespace (pp);
1968 pp_c_relational_expression (pp, TREE_OPERAND (e, 1));
1969 break;
1971 default:
1972 pp_c_relational_expression (pp, e);
1973 break;
1977 /* AND-expression:
1978 equality-expression
1979 AND-expression & equality-equality */
1981 static void
1982 pp_c_and_expression (c_pretty_printer *pp, tree e)
1984 if (TREE_CODE (e) == BIT_AND_EXPR)
1986 pp_c_and_expression (pp, TREE_OPERAND (e, 0));
1987 pp_c_whitespace (pp);
1988 pp_ampersand (pp);
1989 pp_c_whitespace (pp);
1990 pp_c_equality_expression (pp, TREE_OPERAND (e, 1));
1992 else
1993 pp_c_equality_expression (pp, e);
1996 /* exclusive-OR-expression:
1997 AND-expression
1998 exclusive-OR-expression ^ AND-expression */
2000 static void
2001 pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e)
2003 if (TREE_CODE (e) == BIT_XOR_EXPR
2004 || TREE_CODE (e) == TRUTH_XOR_EXPR)
2006 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
2007 if (TREE_CODE (e) == BIT_XOR_EXPR)
2008 pp_c_maybe_whitespace (pp);
2009 else
2010 pp_c_whitespace (pp);
2011 pp_carret (pp);
2012 pp_c_whitespace (pp);
2013 pp_c_and_expression (pp, TREE_OPERAND (e, 1));
2015 else
2016 pp_c_and_expression (pp, e);
2019 /* inclusive-OR-expression:
2020 exclusive-OR-expression
2021 inclusive-OR-expression | exclusive-OR-expression */
2023 static void
2024 pp_c_inclusive_or_expression (c_pretty_printer *pp, tree e)
2026 if (TREE_CODE (e) == BIT_IOR_EXPR)
2028 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
2029 pp_c_whitespace (pp);
2030 pp_bar (pp);
2031 pp_c_whitespace (pp);
2032 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 1));
2034 else
2035 pp_c_exclusive_or_expression (pp, e);
2038 /* logical-AND-expression:
2039 inclusive-OR-expression
2040 logical-AND-expression && inclusive-OR-expression */
2042 static void
2043 pp_c_logical_and_expression (c_pretty_printer *pp, tree e)
2045 if (TREE_CODE (e) == TRUTH_ANDIF_EXPR
2046 || TREE_CODE (e) == TRUTH_AND_EXPR)
2048 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0));
2049 pp_c_whitespace (pp);
2050 pp_ampersand_ampersand (pp);
2051 pp_c_whitespace (pp);
2052 pp_c_inclusive_or_expression (pp, TREE_OPERAND (e, 1));
2054 else
2055 pp_c_inclusive_or_expression (pp, e);
2058 /* logical-OR-expression:
2059 logical-AND-expression
2060 logical-OR-expression || logical-AND-expression */
2062 void
2063 pp_c_logical_or_expression (c_pretty_printer *pp, tree e)
2065 if (TREE_CODE (e) == TRUTH_ORIF_EXPR
2066 || TREE_CODE (e) == TRUTH_OR_EXPR)
2068 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2069 pp_c_whitespace (pp);
2070 pp_bar_bar (pp);
2071 pp_c_whitespace (pp);
2072 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 1));
2074 else
2075 pp_c_logical_and_expression (pp, e);
2078 /* conditional-expression:
2079 logical-OR-expression
2080 logical-OR-expression ? expression : conditional-expression */
2082 void
2083 c_pretty_printer::conditional_expression (tree e)
2085 if (TREE_CODE (e) == COND_EXPR)
2087 pp_c_logical_or_expression (this, TREE_OPERAND (e, 0));
2088 pp_c_whitespace (this);
2089 pp_question (this);
2090 pp_c_whitespace (this);
2091 expression (TREE_OPERAND (e, 1));
2092 pp_c_whitespace (this);
2093 pp_colon (this);
2094 pp_c_whitespace (this);
2095 conditional_expression (TREE_OPERAND (e, 2));
2097 else
2098 pp_c_logical_or_expression (this, e);
2102 /* assignment-expression:
2103 conditional-expression
2104 unary-expression assignment-operator assignment-expression
2106 assignment-expression: one of
2107 = *= /= %= += -= >>= <<= &= ^= |= */
2109 void
2110 c_pretty_printer::assignment_expression (tree e)
2112 if (TREE_CODE (e) == MODIFY_EXPR
2113 || TREE_CODE (e) == INIT_EXPR)
2115 unary_expression (TREE_OPERAND (e, 0));
2116 pp_c_whitespace (this);
2117 pp_equal (this);
2118 pp_space (this);
2119 expression (TREE_OPERAND (e, 1));
2121 else
2122 conditional_expression (e);
2125 /* expression:
2126 assignment-expression
2127 expression , assignment-expression
2129 Implementation note: instead of going through the usual recursion
2130 chain, I take the liberty of dispatching nodes to the appropriate
2131 functions. This makes some redundancy, but it worths it. That also
2132 prevents a possible infinite recursion between primary_expression ()
2133 and expression (). */
2135 void
2136 c_pretty_printer::expression (tree e)
2138 switch (TREE_CODE (e))
2140 case VOID_CST:
2141 pp_c_void_constant (this);
2142 break;
2144 case INTEGER_CST:
2145 pp_c_integer_constant (this, e);
2146 break;
2148 case REAL_CST:
2149 pp_c_floating_constant (this, e);
2150 break;
2152 case FIXED_CST:
2153 pp_c_fixed_constant (this, e);
2154 break;
2156 case STRING_CST:
2157 pp_c_string_literal (this, e);
2158 break;
2160 case IDENTIFIER_NODE:
2161 case FUNCTION_DECL:
2162 case VAR_DECL:
2163 case CONST_DECL:
2164 case PARM_DECL:
2165 case RESULT_DECL:
2166 case FIELD_DECL:
2167 case LABEL_DECL:
2168 case ERROR_MARK:
2169 primary_expression (e);
2170 break;
2172 case SSA_NAME:
2173 if (SSA_NAME_VAR (e)
2174 && !DECL_ARTIFICIAL (SSA_NAME_VAR (e)))
2175 expression (SSA_NAME_VAR (e));
2176 else
2177 translate_string ("<unknown>");
2178 break;
2180 case POSTINCREMENT_EXPR:
2181 case POSTDECREMENT_EXPR:
2182 case ARRAY_REF:
2183 case CALL_EXPR:
2184 case COMPONENT_REF:
2185 case BIT_FIELD_REF:
2186 case COMPLEX_CST:
2187 case COMPLEX_EXPR:
2188 case VECTOR_CST:
2189 case ORDERED_EXPR:
2190 case UNORDERED_EXPR:
2191 case LTGT_EXPR:
2192 case UNEQ_EXPR:
2193 case UNLE_EXPR:
2194 case UNLT_EXPR:
2195 case UNGE_EXPR:
2196 case UNGT_EXPR:
2197 case MAX_EXPR:
2198 case MIN_EXPR:
2199 case ABS_EXPR:
2200 case CONSTRUCTOR:
2201 case COMPOUND_LITERAL_EXPR:
2202 case VA_ARG_EXPR:
2203 postfix_expression (e);
2204 break;
2206 case CONJ_EXPR:
2207 case ADDR_EXPR:
2208 case INDIRECT_REF:
2209 case MEM_REF:
2210 case NEGATE_EXPR:
2211 case BIT_NOT_EXPR:
2212 case TRUTH_NOT_EXPR:
2213 case PREINCREMENT_EXPR:
2214 case PREDECREMENT_EXPR:
2215 case REALPART_EXPR:
2216 case IMAGPART_EXPR:
2217 unary_expression (e);
2218 break;
2220 case FLOAT_EXPR:
2221 case FIX_TRUNC_EXPR:
2222 CASE_CONVERT:
2223 case VIEW_CONVERT_EXPR:
2224 pp_c_cast_expression (this, e);
2225 break;
2227 case MULT_EXPR:
2228 case TRUNC_MOD_EXPR:
2229 case TRUNC_DIV_EXPR:
2230 case EXACT_DIV_EXPR:
2231 case RDIV_EXPR:
2232 multiplicative_expression (e);
2233 break;
2235 case LSHIFT_EXPR:
2236 case RSHIFT_EXPR:
2237 case LROTATE_EXPR:
2238 case RROTATE_EXPR:
2239 pp_c_shift_expression (this, e);
2240 break;
2242 case LT_EXPR:
2243 case GT_EXPR:
2244 case LE_EXPR:
2245 case GE_EXPR:
2246 pp_c_relational_expression (this, e);
2247 break;
2249 case BIT_AND_EXPR:
2250 pp_c_and_expression (this, e);
2251 break;
2253 case BIT_XOR_EXPR:
2254 case TRUTH_XOR_EXPR:
2255 pp_c_exclusive_or_expression (this, e);
2256 break;
2258 case BIT_IOR_EXPR:
2259 pp_c_inclusive_or_expression (this, e);
2260 break;
2262 case TRUTH_ANDIF_EXPR:
2263 case TRUTH_AND_EXPR:
2264 pp_c_logical_and_expression (this, e);
2265 break;
2267 case TRUTH_ORIF_EXPR:
2268 case TRUTH_OR_EXPR:
2269 pp_c_logical_or_expression (this, e);
2270 break;
2272 case EQ_EXPR:
2273 case NE_EXPR:
2274 pp_c_equality_expression (this, e);
2275 break;
2277 case COND_EXPR:
2278 conditional_expression (e);
2279 break;
2281 case POINTER_PLUS_EXPR:
2282 case PLUS_EXPR:
2283 case POINTER_DIFF_EXPR:
2284 case MINUS_EXPR:
2285 pp_c_additive_expression (this, e);
2286 break;
2288 case MODIFY_EXPR:
2289 case INIT_EXPR:
2290 assignment_expression (e);
2291 break;
2293 case COMPOUND_EXPR:
2294 pp_c_left_paren (this);
2295 expression (TREE_OPERAND (e, 0));
2296 pp_separate_with (this, ',');
2297 assignment_expression (TREE_OPERAND (e, 1));
2298 pp_c_right_paren (this);
2299 break;
2301 case NON_LVALUE_EXPR:
2302 case SAVE_EXPR:
2303 expression (TREE_OPERAND (e, 0));
2304 break;
2306 case TARGET_EXPR:
2307 postfix_expression (TREE_OPERAND (e, 1));
2308 break;
2310 case BIND_EXPR:
2311 case GOTO_EXPR:
2312 /* We don't yet have a way of dumping statements in a
2313 human-readable format. */
2314 pp_string (this, "({...})");
2315 break;
2317 case C_MAYBE_CONST_EXPR:
2318 expression (C_MAYBE_CONST_EXPR_EXPR (e));
2319 break;
2321 default:
2322 pp_unsupported_tree (this, e);
2323 break;
2329 /* Statements. */
2331 void
2332 c_pretty_printer::statement (tree stmt)
2334 if (stmt == NULL)
2335 return;
2337 if (pp_needs_newline (this))
2338 pp_newline_and_indent (this, 0);
2340 dump_generic_node (this, stmt, pp_indentation (this), TDF_NONE, true);
2344 /* Initialize the PRETTY-PRINTER for handling C codes. */
2346 c_pretty_printer::c_pretty_printer ()
2347 : pretty_printer (),
2348 offset_list (),
2349 flags ()
2351 type_specifier_seq = pp_c_specifier_qualifier_list;
2352 ptr_operator = pp_c_pointer;
2353 parameter_list = pp_c_parameter_type_list;
2357 /* Print the tree T in full, on file FILE. */
2359 void
2360 print_c_tree (FILE *file, tree t)
2362 c_pretty_printer pp;
2364 pp_needs_newline (&pp) = true;
2365 pp.buffer->stream = file;
2366 pp.statement (t);
2367 pp_newline_and_flush (&pp);
2370 /* Print the tree T in full, on stderr. */
2372 DEBUG_FUNCTION void
2373 debug_c_tree (tree t)
2375 print_c_tree (stderr, t);
2376 fputc ('\n', stderr);
2379 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2380 up of T's memory address. */
2382 void
2383 pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t)
2385 const char *name;
2387 gcc_assert (DECL_P (t));
2389 if (DECL_NAME (t))
2390 name = IDENTIFIER_POINTER (DECL_NAME (t));
2391 else
2393 static char xname[8];
2394 sprintf (xname, "<U%4hx>", ((unsigned short) ((uintptr_t) (t)
2395 & 0xffff)));
2396 name = xname;
2399 pp_c_identifier (pp, name);
2402 #if CHECKING_P
2404 namespace selftest {
2406 /* Selftests for pretty-printing trees. */
2408 /* Verify that EXPR printed by c_pretty_printer is EXPECTED, using
2409 LOC as the effective location for any failures. */
2411 static void
2412 assert_c_pretty_printer_output (const location &loc, const char *expected,
2413 tree expr)
2415 c_pretty_printer pp;
2416 pp.expression (expr);
2417 ASSERT_STREQ_AT (loc, expected, pp_formatted_text (&pp));
2420 /* Helper function for calling assert_c_pretty_printer_output.
2421 This is to avoid having to write SELFTEST_LOCATION. */
2423 #define ASSERT_C_PRETTY_PRINTER_OUTPUT(EXPECTED, EXPR) \
2424 SELFTEST_BEGIN_STMT \
2425 assert_c_pretty_printer_output ((SELFTEST_LOCATION), \
2426 (EXPECTED), \
2427 (EXPR)); \
2428 SELFTEST_END_STMT
2430 /* Verify that location wrappers don't show up in pretty-printed output. */
2432 static void
2433 test_location_wrappers ()
2435 /* VAR_DECL. */
2436 tree id = get_identifier ("foo");
2437 tree decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, id,
2438 integer_type_node);
2439 tree wrapped_decl = maybe_wrap_with_location (decl, BUILTINS_LOCATION);
2440 ASSERT_NE (wrapped_decl, decl);
2441 ASSERT_C_PRETTY_PRINTER_OUTPUT ("foo", decl);
2442 ASSERT_C_PRETTY_PRINTER_OUTPUT ("foo", wrapped_decl);
2444 /* INTEGER_CST. */
2445 tree int_cst = build_int_cst (integer_type_node, 42);
2446 tree wrapped_cst = maybe_wrap_with_location (int_cst, BUILTINS_LOCATION);
2447 ASSERT_NE (wrapped_cst, int_cst);
2448 ASSERT_C_PRETTY_PRINTER_OUTPUT ("42", int_cst);
2449 ASSERT_C_PRETTY_PRINTER_OUTPUT ("42", wrapped_cst);
2452 /* Run all of the selftests within this file. */
2454 void
2455 c_pretty_print_c_tests ()
2457 test_location_wrappers ();
2460 } // namespace selftest
2462 #endif /* CHECKING_P */