OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [c-family/] [c-pretty-print.c] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.