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