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