]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/cxx-pretty-print.c
re PR fortran/53310 (EOSHIFT leaks memory)
[thirdparty/gcc.git] / gcc / cp / cxx-pretty-print.c
CommitLineData
e1a4dd13 1/* Implementation of subroutines for the GNU C++ pretty-printer.
b02cec6e 2 Copyright (C) 2003, 2004, 2005, 2007, 2008,
a0d260fc 3 2009, 2010, 2011 Free Software Foundation, Inc.
e1a4dd13
GDR
4 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
e77f031d 10Software Foundation; either version 3, or (at your option) any later
e1a4dd13
GDR
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
e77f031d
NC
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
e1a4dd13
GDR
21
22#include "config.h"
23#include "system.h"
24#include "coretypes.h"
25#include "tm.h"
b02cec6e 26#include "intl.h"
e1a4dd13 27#include "cp-tree.h"
40013784 28#include "cxx-pretty-print.h"
5d127eeb 29#include "tree-pretty-print.h"
4b780675 30
f41c4af3
JM
31/* Translate if being used for diagnostics, but not for dump files or
32 __PRETTY_FUNCTION. */
33#define M_(msgid) (pp_translate_identifiers (pp) ? _(msgid) : (msgid))
34
4b780675 35static void pp_cxx_unqualified_id (cxx_pretty_printer *, tree);
12ea3302 36static void pp_cxx_nested_name_specifier (cxx_pretty_printer *, tree);
4b780675
GDR
37static void pp_cxx_qualified_id (cxx_pretty_printer *, tree);
38static void pp_cxx_assignment_expression (cxx_pretty_printer *, tree);
12ea3302 39static void pp_cxx_expression (cxx_pretty_printer *, tree);
4b780675 40static void pp_cxx_template_argument_list (cxx_pretty_printer *, tree);
12ea3302
GDR
41static void pp_cxx_type_specifier_seq (cxx_pretty_printer *, tree);
42static void pp_cxx_ptr_operator (cxx_pretty_printer *, tree);
43static void pp_cxx_type_id (cxx_pretty_printer *, tree);
44static void pp_cxx_direct_abstract_declarator (cxx_pretty_printer *, tree);
45static void pp_cxx_declarator (cxx_pretty_printer *, tree);
7090f4b3 46static void pp_cxx_parameter_declaration_clause (cxx_pretty_printer *, tree);
12ea3302 47static void pp_cxx_abstract_declarator (cxx_pretty_printer *, tree);
b01150a2 48static void pp_cxx_statement (cxx_pretty_printer *, tree);
12ea3302 49static void pp_cxx_template_parameter (cxx_pretty_printer *, tree);
392e3d51 50static void pp_cxx_cast_expression (cxx_pretty_printer *, tree);
066f956c 51static void pp_cxx_typeid_expression (cxx_pretty_printer *, tree);
e1a4dd13 52\f
4b780675
GDR
53
54static inline void
55pp_cxx_nonconsecutive_character (cxx_pretty_printer *pp, int c)
56{
57 const char *p = pp_last_position_in_text (pp);
58
59 if (p != NULL && *p == c)
12ea3302 60 pp_cxx_whitespace (pp);
4b780675 61 pp_character (pp, c);
12ea3302 62 pp_base (pp)->padding = pp_none;
4b780675
GDR
63}
64
12ea3302
GDR
65#define pp_cxx_storage_class_specifier(PP, T) \
66 pp_c_storage_class_specifier (pp_c_base (PP), T)
67#define pp_cxx_expression_list(PP, T) \
68 pp_c_expression_list (pp_c_base (PP), T)
69#define pp_cxx_space_for_pointer_operator(PP, T) \
70 pp_c_space_for_pointer_operator (pp_c_base (PP), T)
71#define pp_cxx_init_declarator(PP, T) \
72 pp_c_init_declarator (pp_c_base (PP), T)
73#define pp_cxx_call_argument_list(PP, T) \
74 pp_c_call_argument_list (pp_c_base (PP), T)
e1a4dd13 75
41fd3bac 76void
12ea3302 77pp_cxx_colon_colon (cxx_pretty_printer *pp)
e1a4dd13 78{
12ea3302
GDR
79 pp_colon_colon (pp);
80 pp_base (pp)->padding = pp_none;
e1a4dd13
GDR
81}
82
41fd3bac
GDR
83void
84pp_cxx_begin_template_argument_list (cxx_pretty_printer *pp)
85{
86 pp_cxx_nonconsecutive_character (pp, '<');
87}
88
89void
90pp_cxx_end_template_argument_list (cxx_pretty_printer *pp)
91{
92 pp_cxx_nonconsecutive_character (pp, '>');
93}
94
95void
96pp_cxx_separate_with (cxx_pretty_printer *pp, int c)
97{
98 pp_separate_with (pp, c);
99 pp_base (pp)->padding = pp_none;
100}
e1a4dd13 101
04c06002 102/* Expressions. */
e1a4dd13 103
12ea3302
GDR
104static inline bool
105is_destructor_name (tree name)
e1a4dd13 106{
12ea3302
GDR
107 return name == complete_dtor_identifier
108 || name == base_dtor_identifier
109 || name == deleting_dtor_identifier;
e1a4dd13
GDR
110}
111
12ea3302
GDR
112/* conversion-function-id:
113 operator conversion-type-id
4b780675 114
12ea3302
GDR
115 conversion-type-id:
116 type-specifier-seq conversion-declarator(opt)
4b780675 117
12ea3302
GDR
118 conversion-declarator:
119 ptr-operator conversion-declarator(opt) */
b9b44fb9 120
12ea3302
GDR
121static inline void
122pp_cxx_conversion_function_id (cxx_pretty_printer *pp, tree t)
4b780675 123{
b02cec6e 124 pp_cxx_ws_string (pp, "operator");
12ea3302 125 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
4b780675
GDR
126}
127
12ea3302
GDR
128static inline void
129pp_cxx_template_id (cxx_pretty_printer *pp, tree t)
e1a4dd13 130{
12ea3302
GDR
131 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
132 pp_cxx_begin_template_argument_list (pp);
133 pp_cxx_template_argument_list (pp, TREE_OPERAND (t, 1));
134 pp_cxx_end_template_argument_list (pp);
e1a4dd13
GDR
135}
136
5a023baa
GDR
137/* Prints the unqualified part of the id-expression T.
138
139 unqualified-id:
4b780675
GDR
140 identifier
141 operator-function-id
142 conversion-function-id
143 ~ class-name
144 template-id */
b9b44fb9 145
4b780675
GDR
146static void
147pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t)
148{
149 enum tree_code code = TREE_CODE (t);
150 switch (code)
151 {
12ea3302 152 case RESULT_DECL:
f41c4af3 153 pp_cxx_ws_string (pp, M_("<return-value>"));
12ea3302
GDR
154 break;
155
156 case OVERLOAD:
c8094d83 157 t = OVL_CURRENT (t);
4b780675
GDR
158 case VAR_DECL:
159 case PARM_DECL:
160 case CONST_DECL:
161 case TYPE_DECL:
162 case FUNCTION_DECL:
163 case NAMESPACE_DECL:
164 case FIELD_DECL:
165 case LABEL_DECL:
166 case USING_DECL:
12ea3302 167 case TEMPLATE_DECL:
4b780675 168 t = DECL_NAME (t);
c8094d83 169
4b780675 170 case IDENTIFIER_NODE:
12ea3302 171 if (t == NULL)
f41c4af3 172 pp_cxx_ws_string (pp, M_("<unnamed>"));
12ea3302 173 else if (IDENTIFIER_TYPENAME_P (t))
0cbd7506 174 pp_cxx_conversion_function_id (pp, t);
4b780675 175 else
0cbd7506
MS
176 {
177 if (is_destructor_name (t))
178 {
179 pp_complement (pp);
180 /* FIXME: Why is this necessary? */
181 if (TREE_TYPE (t))
182 t = constructor_name (TREE_TYPE (t));
183 }
184 pp_cxx_tree_identifier (pp, t);
185 }
4b780675
GDR
186 break;
187
188 case TEMPLATE_ID_EXPR:
12ea3302
GDR
189 pp_cxx_template_id (pp, t);
190 break;
191
3601f003
KL
192 case BASELINK:
193 pp_cxx_unqualified_id (pp, BASELINK_FUNCTIONS (t));
194 break;
195
12ea3302
GDR
196 case RECORD_TYPE:
197 case UNION_TYPE:
198 case ENUMERAL_TYPE:
c8c00613
PC
199 case TYPENAME_TYPE:
200 case UNBOUND_CLASS_TEMPLATE:
12ea3302 201 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
e1faa105
JM
202 if (CLASS_TYPE_P (t) && CLASSTYPE_USE_TEMPLATE (t))
203 {
204 pp_cxx_begin_template_argument_list (pp);
38a15b40
DS
205 pp_cxx_template_argument_list (pp, INNERMOST_TEMPLATE_ARGS
206 (CLASSTYPE_TI_ARGS (t)));
e1faa105
JM
207 pp_cxx_end_template_argument_list (pp);
208 }
12ea3302
GDR
209 break;
210
6735e374
PC
211 case BIT_NOT_EXPR:
212 pp_cxx_complement (pp);
213 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
214 break;
215
12ea3302 216 case TEMPLATE_TYPE_PARM:
41fd3bac
GDR
217 case TEMPLATE_TEMPLATE_PARM:
218 if (TYPE_IDENTIFIER (t))
0cbd7506 219 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
41fd3bac 220 else
0cbd7506 221 pp_cxx_canonical_template_parameter (pp, t);
41fd3bac
GDR
222 break;
223
12ea3302
GDR
224 case TEMPLATE_PARM_INDEX:
225 pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t));
4b780675
GDR
226 break;
227
c8c00613
PC
228 case BOUND_TEMPLATE_TEMPLATE_PARM:
229 pp_cxx_cv_qualifier_seq (pp, t);
230 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
231 pp_cxx_begin_template_argument_list (pp);
232 pp_cxx_template_argument_list (pp, TYPE_TI_ARGS (t));
233 pp_cxx_end_template_argument_list (pp);
5a023baa
GDR
234 break;
235
4b780675
GDR
236 default:
237 pp_unsupported_tree (pp, t);
12ea3302
GDR
238 break;
239 }
240}
241
b9b44fb9
GDR
242/* Pretty-print out the token sequence ":: template" in template codes
243 where it is needed to "inline declare" the (following) member as
666c27b9 244 a template. This situation arises when SCOPE of T is dependent
b9b44fb9
GDR
245 on template parameters. */
246
12ea3302
GDR
247static inline void
248pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
249{
250 if (TREE_CODE (t) == TEMPLATE_ID_EXPR
251 && TYPE_P (scope) && dependent_type_p (scope))
b02cec6e 252 pp_cxx_ws_string (pp, "template");
12ea3302
GDR
253}
254
255/* nested-name-specifier:
256 class-or-namespace-name :: nested-name-specifier(opt)
257 class-or-namespace-name :: template nested-name-specifier */
b9b44fb9 258
12ea3302
GDR
259static void
260pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
261{
725214ac 262 if (!SCOPE_FILE_SCOPE_P (t) && t != pp->enclosing_scope)
12ea3302
GDR
263 {
264 tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
265 pp_cxx_nested_name_specifier (pp, scope);
266 pp_cxx_template_keyword_if_needed (pp, scope, t);
267 pp_cxx_unqualified_id (pp, t);
268 pp_cxx_colon_colon (pp);
4b780675
GDR
269 }
270}
271
272/* qualified-id:
273 nested-name-specifier template(opt) unqualified-id */
b9b44fb9 274
4b780675
GDR
275static void
276pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t)
277{
278 switch (TREE_CODE (t))
279 {
b9b44fb9 280 /* A pointer-to-member is always qualified. */
4b780675 281 case PTRMEM_CST:
12ea3302 282 pp_cxx_nested_name_specifier (pp, PTRMEM_CST_CLASS (t));
4b780675
GDR
283 pp_cxx_unqualified_id (pp, PTRMEM_CST_MEMBER (t));
284 break;
285
b9b44fb9 286 /* In Standard C++, functions cannot possibly be used as
0cbd7506
MS
287 nested-name-specifiers. However, there are situations where
288 is "makes sense" to output the surrounding function name for the
289 purpose of emphasizing on the scope kind. Just printing the
290 function name might not be sufficient as it may be overloaded; so,
291 we decorate the function with its signature too.
292 FIXME: This is probably the wrong pretty-printing for conversion
293 functions and some function templates. */
12ea3302
GDR
294 case OVERLOAD:
295 t = OVL_CURRENT (t);
296 case FUNCTION_DECL:
297 if (DECL_FUNCTION_MEMBER_P (t))
0cbd7506 298 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
12ea3302 299 pp_cxx_unqualified_id
0cbd7506 300 (pp, DECL_CONSTRUCTOR_P (t) ? DECL_CONTEXT (t) : t);
b9b44fb9 301 pp_cxx_parameter_declaration_clause (pp, TREE_TYPE (t));
12ea3302
GDR
302 break;
303
4b780675
GDR
304 case OFFSET_REF:
305 case SCOPE_REF:
12ea3302 306 pp_cxx_nested_name_specifier (pp, TREE_OPERAND (t, 0));
4b780675
GDR
307 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 1));
308 break;
309
310 default:
311 {
0cbd7506
MS
312 tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
313 if (scope != pp->enclosing_scope)
314 {
315 pp_cxx_nested_name_specifier (pp, scope);
316 pp_cxx_template_keyword_if_needed (pp, scope, t);
317 }
318 pp_cxx_unqualified_id (pp, t);
4b780675
GDR
319 }
320 break;
321 }
322}
323
a176426f
GDR
324
325static void
326pp_cxx_constant (cxx_pretty_printer *pp, tree t)
327{
328 switch (TREE_CODE (t))
329 {
330 case STRING_CST:
331 {
3db45ab5
MS
332 const bool in_parens = PAREN_STRING_LITERAL_P (t);
333 if (in_parens)
334 pp_cxx_left_paren (pp);
335 pp_c_constant (pp_c_base (pp), t);
336 if (in_parens)
337 pp_cxx_right_paren (pp);
a176426f
GDR
338 }
339 break;
340
14c2101d 341 case INTEGER_CST:
5116acc6 342 if (NULLPTR_TYPE_P (TREE_TYPE (t)))
14c2101d
JM
343 {
344 pp_string (pp, "nullptr");
345 break;
346 }
347 /* else fall through. */
348
a176426f
GDR
349 default:
350 pp_c_constant (pp_c_base (pp), t);
351 break;
352 }
353}
354
4b780675 355/* id-expression:
cd0be382 356 unqualified-id
4b780675 357 qualified-id */
b9b44fb9 358
4b780675
GDR
359static inline void
360pp_cxx_id_expression (cxx_pretty_printer *pp, tree t)
361{
12ea3302
GDR
362 if (TREE_CODE (t) == OVERLOAD)
363 t = OVL_CURRENT (t);
d04a575f 364 if (DECL_P (t) && DECL_CONTEXT (t))
4b780675
GDR
365 pp_cxx_qualified_id (pp, t);
366 else
367 pp_cxx_unqualified_id (pp, t);
368}
369
3ce4f9e4
ESR
370/* user-defined literal:
371 literal ud-suffix */
372
373void
374pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
375{
376 pp_cxx_constant (pp, USERDEF_LITERAL_VALUE (t));
377 pp_cxx_id_expression (pp, USERDEF_LITERAL_SUFFIX_ID (t));
378}
379
380
4b780675
GDR
381/* primary-expression:
382 literal
383 this
384 :: identifier
385 :: operator-function-id
386 :: qualifier-id
387 ( expression )
e74392f0
PC
388 id-expression
389
390 GNU Extensions:
fdb8f418 391 __builtin_va_arg ( assignment-expression , type-id )
094a5fe2 392 __builtin_offsetof ( type-id, offsetof-expression )
fdb8f418 393
e74392f0
PC
394 __has_nothrow_assign ( type-id )
395 __has_nothrow_constructor ( type-id )
396 __has_nothrow_copy ( type-id )
397 __has_trivial_assign ( type-id )
398 __has_trivial_constructor ( type-id )
399 __has_trivial_copy ( type-id )
400 __has_trivial_destructor ( type-id )
401 __has_virtual_destructor ( type-id )
402 __is_abstract ( type-id )
403 __is_base_of ( type-id , type-id )
404 __is_class ( type-id )
405 __is_convertible_to ( type-id , type-id )
406 __is_empty ( type-id )
407 __is_enum ( type-id )
3c0d13bf 408 __is_literal_type ( type-id )
e74392f0
PC
409 __is_pod ( type-id )
410 __is_polymorphic ( type-id )
3c0d13bf
PC
411 __is_std_layout ( type-id )
412 __is_trivial ( type-id )
e74392f0 413 __is_union ( type-id ) */
b9b44fb9 414
e1a4dd13
GDR
415static void
416pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
417{
4b780675
GDR
418 switch (TREE_CODE (t))
419 {
4b780675
GDR
420 case INTEGER_CST:
421 case REAL_CST:
7368348c 422 case COMPLEX_CST:
a176426f
GDR
423 case STRING_CST:
424 pp_cxx_constant (pp, t);
4b780675
GDR
425 break;
426
3ce4f9e4
ESR
427 case USERDEF_LITERAL:
428 pp_cxx_userdef_literal (pp, t);
429 break;
430
12ea3302
GDR
431 case BASELINK:
432 t = BASELINK_FUNCTIONS (t);
433 case VAR_DECL:
434 case PARM_DECL:
435 case FIELD_DECL:
436 case FUNCTION_DECL:
437 case OVERLOAD:
438 case CONST_DECL:
439 case TEMPLATE_DECL:
440 pp_cxx_id_expression (pp, t);
441 break;
442
443 case RESULT_DECL:
444 case TEMPLATE_TYPE_PARM:
41fd3bac 445 case TEMPLATE_TEMPLATE_PARM:
12ea3302
GDR
446 case TEMPLATE_PARM_INDEX:
447 pp_cxx_unqualified_id (pp, t);
448 break;
449
c3e5898b
ILT
450 case STMT_EXPR:
451 pp_cxx_left_paren (pp);
452 pp_cxx_statement (pp, STMT_EXPR_STMT (t));
453 pp_cxx_right_paren (pp);
454 break;
455
e74392f0
PC
456 case TRAIT_EXPR:
457 pp_cxx_trait_expression (pp, t);
458 break;
459
fdb8f418
PC
460 case VA_ARG_EXPR:
461 pp_cxx_va_arg_expression (pp, t);
462 break;
463
094a5fe2
JJ
464 case OFFSETOF_EXPR:
465 pp_cxx_offsetof_expression (pp, t);
466 break;
467
4b780675 468 default:
12ea3302 469 pp_c_primary_expression (pp_c_base (pp), t);
4b780675
GDR
470 break;
471 }
e1a4dd13
GDR
472}
473
4b780675
GDR
474/* postfix-expression:
475 primary-expression
476 postfix-expression [ expression ]
477 postfix-expression ( expression-list(opt) )
478 simple-type-specifier ( expression-list(opt) )
479 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
480 typename ::(opt) nested-name-specifier template(opt)
0cbd7506 481 template-id ( expression-list(opt) )
4b780675
GDR
482 postfix-expression . template(opt) ::(opt) id-expression
483 postfix-expression -> template(opt) ::(opt) id-expression
484 postfix-expression . pseudo-destructor-name
485 postfix-expression -> pseudo-destructor-name
486 postfix-expression ++
487 postfix-expression --
488 dynamic_cast < type-id > ( expression )
489 static_cast < type-id > ( expression )
490 reinterpret_cast < type-id > ( expression )
491 const_cast < type-id > ( expression )
492 typeid ( expression )
39a13be5 493 typeid ( type-id ) */
4b780675 494
e1a4dd13
GDR
495static void
496pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t)
497{
4b780675 498 enum tree_code code = TREE_CODE (t);
c8094d83 499
4b780675
GDR
500 switch (code)
501 {
12ea3302
GDR
502 case AGGR_INIT_EXPR:
503 case CALL_EXPR:
504 {
5039610b
SL
505 tree fun = (code == AGGR_INIT_EXPR ? AGGR_INIT_EXPR_FN (t)
506 : CALL_EXPR_FN (t));
0cbd7506 507 tree saved_scope = pp->enclosing_scope;
5039610b
SL
508 bool skipfirst = false;
509 tree arg;
0cbd7506
MS
510
511 if (TREE_CODE (fun) == ADDR_EXPR)
512 fun = TREE_OPERAND (fun, 0);
513
514 /* In templates, where there is no way to tell whether a given
515 call uses an actual member function. So the parser builds
516 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
517 instantiation time. */
518 if (TREE_CODE (fun) != FUNCTION_DECL)
519 ;
520 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun))
521 {
5039610b
SL
522 tree object = (code == AGGR_INIT_EXPR
523 ? (AGGR_INIT_VIA_CTOR_P (t)
524 ? AGGR_INIT_EXPR_SLOT (t)
525 : AGGR_INIT_EXPR_ARG (t, 0))
526 : CALL_EXPR_ARG (t, 0));
0cbd7506
MS
527
528 while (TREE_CODE (object) == NOP_EXPR)
529 object = TREE_OPERAND (object, 0);
530
531 if (TREE_CODE (object) == ADDR_EXPR)
532 object = TREE_OPERAND (object, 0);
533
534 if (TREE_CODE (TREE_TYPE (object)) != POINTER_TYPE)
535 {
536 pp_cxx_postfix_expression (pp, object);
537 pp_cxx_dot (pp);
538 }
539 else
540 {
541 pp_cxx_postfix_expression (pp, object);
542 pp_cxx_arrow (pp);
543 }
5039610b 544 skipfirst = true;
0cbd7506
MS
545 pp->enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
546 }
547
548 pp_cxx_postfix_expression (pp, fun);
549 pp->enclosing_scope = saved_scope;
5039610b
SL
550 pp_cxx_left_paren (pp);
551 if (code == AGGR_INIT_EXPR)
552 {
553 aggr_init_expr_arg_iterator iter;
554 FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t)
555 {
556 if (skipfirst)
557 skipfirst = false;
558 else
559 {
560 pp_cxx_expression (pp, arg);
561 if (more_aggr_init_expr_args_p (&iter))
562 pp_cxx_separate_with (pp, ',');
563 }
564 }
565 }
566 else
567 {
568 call_expr_arg_iterator iter;
569 FOR_EACH_CALL_EXPR_ARG (arg, iter, t)
570 {
571 if (skipfirst)
572 skipfirst = false;
573 else
574 {
575 pp_cxx_expression (pp, arg);
576 if (more_call_expr_args_p (&iter))
577 pp_cxx_separate_with (pp, ',');
578 }
579 }
580 }
581 pp_cxx_right_paren (pp);
12ea3302
GDR
582 }
583 if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
0cbd7506
MS
584 {
585 pp_cxx_separate_with (pp, ',');
5039610b 586 pp_cxx_postfix_expression (pp, AGGR_INIT_EXPR_SLOT (t));
0cbd7506 587 }
12ea3302
GDR
588 break;
589
590 case BASELINK:
591 case VAR_DECL:
592 case PARM_DECL:
593 case FIELD_DECL:
594 case FUNCTION_DECL:
595 case OVERLOAD:
596 case CONST_DECL:
597 case TEMPLATE_DECL:
598 case RESULT_DECL:
599 pp_cxx_primary_expression (pp, t);
600 break;
601
4b780675
GDR
602 case DYNAMIC_CAST_EXPR:
603 case STATIC_CAST_EXPR:
604 case REINTERPRET_CAST_EXPR:
605 case CONST_CAST_EXPR:
606 if (code == DYNAMIC_CAST_EXPR)
b02cec6e 607 pp_cxx_ws_string (pp, "dynamic_cast");
4b780675 608 else if (code == STATIC_CAST_EXPR)
b02cec6e 609 pp_cxx_ws_string (pp, "static_cast");
4b780675 610 else if (code == REINTERPRET_CAST_EXPR)
b02cec6e 611 pp_cxx_ws_string (pp, "reinterpret_cast");
4b780675 612 else
b02cec6e 613 pp_cxx_ws_string (pp, "const_cast");
4b780675
GDR
614 pp_cxx_begin_template_argument_list (pp);
615 pp_cxx_type_id (pp, TREE_TYPE (t));
616 pp_cxx_end_template_argument_list (pp);
617 pp_left_paren (pp);
12ea3302 618 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
4b780675
GDR
619 pp_right_paren (pp);
620 break;
621
622 case EMPTY_CLASS_EXPR:
623 pp_cxx_type_id (pp, TREE_TYPE (t));
624 pp_left_paren (pp);
625 pp_right_paren (pp);
626 break;
627
628 case TYPEID_EXPR:
2d65b828 629 pp_cxx_typeid_expression (pp, t);
4b780675
GDR
630 break;
631
632 case PSEUDO_DTOR_EXPR:
633 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
12ea3302 634 pp_cxx_dot (pp);
4b780675 635 pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1));
12ea3302 636 pp_cxx_colon_colon (pp);
4b780675
GDR
637 pp_complement (pp);
638 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2));
639 break;
640
03a08664
ILT
641 case ARROW_EXPR:
642 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
643 pp_cxx_arrow (pp);
644 break;
645
4b780675
GDR
646 default:
647 pp_c_postfix_expression (pp_c_base (pp), t);
648 break;
649 }
e1a4dd13
GDR
650}
651
4b780675
GDR
652/* new-expression:
653 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
654 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
655
656 new-placement:
657 ( expression-list )
658
659 new-type-id:
660 type-specifier-seq new-declarator(opt)
661
662 new-declarator:
663 ptr-operator new-declarator(opt)
664 direct-new-declarator
665
666 direct-new-declarator
667 [ expression ]
668 direct-new-declarator [ constant-expression ]
669
670 new-initializer:
671 ( expression-list(opt) ) */
b9b44fb9 672
e1a4dd13 673static void
4b780675 674pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
e1a4dd13 675{
4b780675 676 enum tree_code code = TREE_CODE (t);
a84a98ca
PC
677 tree type = TREE_OPERAND (t, 1);
678 tree init = TREE_OPERAND (t, 2);
4b780675
GDR
679 switch (code)
680 {
681 case NEW_EXPR:
682 case VEC_NEW_EXPR:
683 if (NEW_EXPR_USE_GLOBAL (t))
0cbd7506 684 pp_cxx_colon_colon (pp);
b02cec6e 685 pp_cxx_ws_string (pp, "new");
4b780675 686 if (TREE_OPERAND (t, 0))
0cbd7506
MS
687 {
688 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
689 pp_space (pp);
690 }
a84a98ca
PC
691 if (TREE_CODE (type) == ARRAY_REF)
692 type = build_cplus_array_type
693 (TREE_OPERAND (type, 0),
db3927fb
AH
694 build_index_type (fold_build2_loc (input_location,
695 MINUS_EXPR, integer_type_node,
a84a98ca
PC
696 TREE_OPERAND (type, 1),
697 integer_one_node)));
698 pp_cxx_type_id (pp, type);
699 if (init)
0cbd7506
MS
700 {
701 pp_left_paren (pp);
a84a98ca
PC
702 if (TREE_CODE (init) == TREE_LIST)
703 pp_c_expression_list (pp_c_base (pp), init);
704 else if (init == void_zero_node)
0cbd7506
MS
705 ; /* OK, empty initializer list. */
706 else
a84a98ca 707 pp_cxx_expression (pp, init);
0cbd7506
MS
708 pp_right_paren (pp);
709 }
4b780675
GDR
710 break;
711
712 default:
713 pp_unsupported_tree (pp, t);
714 }
e1a4dd13
GDR
715}
716
4b780675
GDR
717/* delete-expression:
718 ::(opt) delete cast-expression
719 ::(opt) delete [ ] cast-expression */
b9b44fb9 720
066f956c 721static void
4b780675 722pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
e1a4dd13 723{
4b780675
GDR
724 enum tree_code code = TREE_CODE (t);
725 switch (code)
726 {
727 case DELETE_EXPR:
728 case VEC_DELETE_EXPR:
729 if (DELETE_EXPR_USE_GLOBAL (t))
0cbd7506 730 pp_cxx_colon_colon (pp);
b02cec6e 731 pp_cxx_ws_string (pp, "delete");
62081704
PC
732 pp_space (pp);
733 if (code == VEC_DELETE_EXPR
734 || DELETE_EXPR_USE_VEC (t))
0cbd7506
MS
735 {
736 pp_left_bracket (pp);
737 pp_right_bracket (pp);
62081704 738 pp_space (pp);
0cbd7506 739 }
4b780675 740 pp_c_cast_expression (pp_c_base (pp), TREE_OPERAND (t, 0));
c8094d83
MS
741 break;
742
4b780675
GDR
743 default:
744 pp_unsupported_tree (pp, t);
745 }
e1a4dd13
GDR
746}
747
4b780675
GDR
748/* unary-expression:
749 postfix-expression
750 ++ cast-expression
751 -- cast-expression
752 unary-operator cast-expression
753 sizeof unary-expression
754 sizeof ( type-id )
5d80a306 755 sizeof ... ( identifier )
4b780675
GDR
756 new-expression
757 delete-expression
758
759 unary-operator: one of
760 * & + - !
761
762 GNU extensions:
763 __alignof__ unary-expression
764 __alignof__ ( type-id ) */
b9b44fb9 765
e1a4dd13 766static void
4b780675 767pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
e1a4dd13 768{
4b780675
GDR
769 enum tree_code code = TREE_CODE (t);
770 switch (code)
771 {
772 case NEW_EXPR:
773 case VEC_NEW_EXPR:
774 pp_cxx_new_expression (pp, t);
775 break;
776
777 case DELETE_EXPR:
778 case VEC_DELETE_EXPR:
779 pp_cxx_delete_expression (pp, t);
780 break;
c8094d83 781
03a08664 782 case SIZEOF_EXPR:
5d80a306
DG
783 if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
784 {
b02cec6e
JM
785 pp_cxx_ws_string (pp, "sizeof");
786 pp_cxx_ws_string (pp, "...");
5d80a306
DG
787 pp_cxx_whitespace (pp);
788 pp_cxx_left_paren (pp);
789 if (TYPE_P (TREE_OPERAND (t, 0)))
790 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
791 else
792 pp_unary_expression (pp, TREE_OPERAND (t, 0));
793 pp_cxx_right_paren (pp);
794 break;
795 }
796 /* Fall through */
797
03a08664 798 case ALIGNOF_EXPR:
b02cec6e 799 pp_cxx_ws_string (pp, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
03a08664
ILT
800 pp_cxx_whitespace (pp);
801 if (TYPE_P (TREE_OPERAND (t, 0)))
802 {
803 pp_cxx_left_paren (pp);
804 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
805 pp_cxx_right_paren (pp);
806 }
807 else
808 pp_unary_expression (pp, TREE_OPERAND (t, 0));
809 break;
810
c154b3d8
NP
811 case AT_ENCODE_EXPR:
812 pp_cxx_ws_string (pp, "@encode");
813 pp_cxx_whitespace (pp);
814 pp_cxx_left_paren (pp);
815 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
816 pp_cxx_right_paren (pp);
817 break;
818
c56ba354
JM
819 case NOEXCEPT_EXPR:
820 pp_cxx_ws_string (pp, "noexcept");
821 pp_cxx_whitespace (pp);
822 pp_cxx_left_paren (pp);
823 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
824 pp_cxx_right_paren (pp);
825 break;
826
392e3d51
RS
827 case UNARY_PLUS_EXPR:
828 pp_plus (pp);
829 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0));
830 break;
831
4b780675
GDR
832 default:
833 pp_c_unary_expression (pp_c_base (pp), t);
834 break;
835 }
e1a4dd13
GDR
836}
837
12ea3302
GDR
838/* cast-expression:
839 unary-expression
840 ( type-id ) cast-expression */
b9b44fb9 841
12ea3302
GDR
842static void
843pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
844{
845 switch (TREE_CODE (t))
846 {
847 case CAST_EXPR:
a4474a38 848 case IMPLICIT_CONV_EXPR:
12ea3302
GDR
849 pp_cxx_type_id (pp, TREE_TYPE (t));
850 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
851 break;
852
853 default:
854 pp_c_cast_expression (pp_c_base (pp), t);
855 break;
856 }
857}
858
4b780675
GDR
859/* pm-expression:
860 cast-expression
861 pm-expression .* cast-expression
862 pm-expression ->* cast-expression */
b9b44fb9 863
e1a4dd13 864static void
4b780675 865pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t)
e1a4dd13 866{
4b780675
GDR
867 switch (TREE_CODE (t))
868 {
39a13be5 869 /* Handle unfortunate OFFSET_REF overloading here. */
4b780675
GDR
870 case OFFSET_REF:
871 if (TYPE_P (TREE_OPERAND (t, 0)))
0cbd7506
MS
872 {
873 pp_cxx_qualified_id (pp, t);
874 break;
875 }
f4f206f4 876 /* Else fall through. */
4b780675
GDR
877 case MEMBER_REF:
878 case DOTSTAR_EXPR:
879 pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
1e3eacc7
JJ
880 if (TREE_CODE (t) == MEMBER_REF)
881 pp_cxx_arrow (pp);
882 else
883 pp_cxx_dot (pp);
4b780675 884 pp_star(pp);
12ea3302 885 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1));
4b780675
GDR
886 break;
887
888
889 default:
12ea3302 890 pp_cxx_cast_expression (pp, t);
4b780675
GDR
891 break;
892 }
e1a4dd13
GDR
893}
894
4b780675
GDR
895/* multiplicative-expression:
896 pm-expression
897 multiplicative-expression * pm-expression
898 multiplicative-expression / pm-expression
899 multiplicative-expression % pm-expression */
b9b44fb9 900
e1a4dd13 901static void
4b780675 902pp_cxx_multiplicative_expression (cxx_pretty_printer *pp, tree e)
e1a4dd13 903{
4b780675
GDR
904 enum tree_code code = TREE_CODE (e);
905 switch (code)
906 {
907 case MULT_EXPR:
908 case TRUNC_DIV_EXPR:
909 case TRUNC_MOD_EXPR:
910 pp_cxx_multiplicative_expression (pp, TREE_OPERAND (e, 0));
911 pp_space (pp);
912 if (code == MULT_EXPR)
913 pp_star (pp);
914 else if (code == TRUNC_DIV_EXPR)
915 pp_slash (pp);
916 else
917 pp_modulo (pp);
918 pp_space (pp);
919 pp_cxx_pm_expression (pp, TREE_OPERAND (e, 1));
920 break;
921
922 default:
923 pp_cxx_pm_expression (pp, e);
924 break;
925 }
e1a4dd13
GDR
926}
927
4b780675
GDR
928/* conditional-expression:
929 logical-or-expression
930 logical-or-expression ? expression : assignment-expression */
b9b44fb9 931
4b780675
GDR
932static void
933pp_cxx_conditional_expression (cxx_pretty_printer *pp, tree e)
e1a4dd13 934{
4b780675
GDR
935 if (TREE_CODE (e) == COND_EXPR)
936 {
937 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
938 pp_space (pp);
939 pp_question (pp);
940 pp_space (pp);
12ea3302 941 pp_cxx_expression (pp, TREE_OPERAND (e, 1));
4b780675
GDR
942 pp_space (pp);
943 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
944 }
945 else
946 pp_c_logical_or_expression (pp_c_base (pp), e);
947}
948
b9b44fb9
GDR
949/* Pretty-print a compound assignment operator token as indicated by T. */
950
12ea3302
GDR
951static void
952pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t)
953{
954 const char *op;
955
956 switch (TREE_CODE (t))
957 {
958 case NOP_EXPR:
959 op = "=";
960 break;
961
962 case PLUS_EXPR:
963 op = "+=";
964 break;
965
966 case MINUS_EXPR:
967 op = "-=";
968 break;
969
970 case TRUNC_DIV_EXPR:
971 op = "/=";
972 break;
973
974 case TRUNC_MOD_EXPR:
975 op = "%=";
976 break;
977
978 default:
979 op = tree_code_name[TREE_CODE (t)];
980 break;
981 }
982
b02cec6e 983 pp_cxx_ws_string (pp, op);
12ea3302
GDR
984}
985
986
4b780675
GDR
987/* assignment-expression:
988 conditional-expression
989 logical-or-expression assignment-operator assignment-expression
12ea3302
GDR
990 throw-expression
991
992 throw-expression:
993 throw assignment-expression(opt)
4b780675 994
12ea3302 995 assignment-operator: one of
4b780675 996 = *= /= %= += -= >>= <<= &= ^= |= */
b9b44fb9 997
4b780675
GDR
998static void
999pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e)
1000{
12ea3302 1001 switch (TREE_CODE (e))
4b780675 1002 {
12ea3302
GDR
1003 case MODIFY_EXPR:
1004 case INIT_EXPR:
4b780675
GDR
1005 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
1006 pp_space (pp);
1007 pp_equal (pp);
1008 pp_space (pp);
1009 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 1));
12ea3302 1010 break;
e1a4dd13 1011
12ea3302 1012 case THROW_EXPR:
b02cec6e 1013 pp_cxx_ws_string (pp, "throw");
12ea3302 1014 if (TREE_OPERAND (e, 0))
0cbd7506 1015 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 0));
12ea3302 1016 break;
e1a4dd13 1017
12ea3302
GDR
1018 case MODOP_EXPR:
1019 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
1020 pp_cxx_assignment_operator (pp, TREE_OPERAND (e, 1));
1021 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
1022 break;
e1a4dd13 1023
12ea3302
GDR
1024 default:
1025 pp_cxx_conditional_expression (pp, e);
1026 break;
1027 }
1028}
1029
1030static void
1031pp_cxx_expression (cxx_pretty_printer *pp, tree t)
1032{
1033 switch (TREE_CODE (t))
1034 {
1035 case STRING_CST:
1036 case INTEGER_CST:
1037 case REAL_CST:
7368348c 1038 case COMPLEX_CST:
a176426f 1039 pp_cxx_constant (pp, t);
12ea3302
GDR
1040 break;
1041
3ce4f9e4
ESR
1042 case USERDEF_LITERAL:
1043 pp_cxx_userdef_literal (pp, t);
1044 break;
1045
12ea3302
GDR
1046 case RESULT_DECL:
1047 pp_cxx_unqualified_id (pp, t);
1048 break;
1049
c8094d83 1050#if 0
12ea3302 1051 case OFFSET_REF:
c8094d83 1052#endif
12ea3302
GDR
1053 case SCOPE_REF:
1054 case PTRMEM_CST:
1055 pp_cxx_qualified_id (pp, t);
1056 break;
1057
1058 case OVERLOAD:
1059 t = OVL_CURRENT (t);
1060 case VAR_DECL:
1061 case PARM_DECL:
1062 case FIELD_DECL:
1063 case CONST_DECL:
1064 case FUNCTION_DECL:
1065 case BASELINK:
1066 case TEMPLATE_DECL:
1067 case TEMPLATE_TYPE_PARM:
1068 case TEMPLATE_PARM_INDEX:
41fd3bac 1069 case TEMPLATE_TEMPLATE_PARM:
c3e5898b 1070 case STMT_EXPR:
12ea3302
GDR
1071 pp_cxx_primary_expression (pp, t);
1072 break;
1073
1074 case CALL_EXPR:
1075 case DYNAMIC_CAST_EXPR:
1076 case STATIC_CAST_EXPR:
1077 case REINTERPRET_CAST_EXPR:
1078 case CONST_CAST_EXPR:
c8094d83 1079#if 0
12ea3302 1080 case MEMBER_REF:
c8094d83 1081#endif
12ea3302
GDR
1082 case EMPTY_CLASS_EXPR:
1083 case TYPEID_EXPR:
1084 case PSEUDO_DTOR_EXPR:
1085 case AGGR_INIT_EXPR:
03a08664 1086 case ARROW_EXPR:
12ea3302
GDR
1087 pp_cxx_postfix_expression (pp, t);
1088 break;
1089
1090 case NEW_EXPR:
1091 case VEC_NEW_EXPR:
1092 pp_cxx_new_expression (pp, t);
1093 break;
1094
1095 case DELETE_EXPR:
1096 case VEC_DELETE_EXPR:
1097 pp_cxx_delete_expression (pp, t);
1098 break;
1099
03a08664
ILT
1100 case SIZEOF_EXPR:
1101 case ALIGNOF_EXPR:
c56ba354 1102 case NOEXCEPT_EXPR:
03a08664
ILT
1103 pp_cxx_unary_expression (pp, t);
1104 break;
1105
12ea3302 1106 case CAST_EXPR:
a4474a38 1107 case IMPLICIT_CONV_EXPR:
12ea3302
GDR
1108 pp_cxx_cast_expression (pp, t);
1109 break;
1110
1111 case OFFSET_REF:
1112 case MEMBER_REF:
1113 case DOTSTAR_EXPR:
1114 pp_cxx_pm_expression (pp, t);
1115 break;
1116
1117 case MULT_EXPR:
1118 case TRUNC_DIV_EXPR:
1119 case TRUNC_MOD_EXPR:
1120 pp_cxx_multiplicative_expression (pp, t);
1121 break;
1122
1123 case COND_EXPR:
1124 pp_cxx_conditional_expression (pp, t);
1125 break;
1126
1127 case MODIFY_EXPR:
1128 case INIT_EXPR:
1129 case THROW_EXPR:
1130 case MODOP_EXPR:
1131 pp_cxx_assignment_expression (pp, t);
1132 break;
1133
b9b44fb9
GDR
1134 case NON_DEPENDENT_EXPR:
1135 case MUST_NOT_THROW_EXPR:
066f956c 1136 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
b9b44fb9
GDR
1137 break;
1138
5d80a306
DG
1139 case EXPR_PACK_EXPANSION:
1140 pp_cxx_expression (pp, PACK_EXPANSION_PATTERN (t));
b02cec6e 1141 pp_cxx_ws_string (pp, "...");
5d80a306
DG
1142 break;
1143
c7f06e13
PC
1144 case TEMPLATE_ID_EXPR:
1145 pp_cxx_template_id (pp, t);
1146 break;
1147
5d80a306
DG
1148 case NONTYPE_ARGUMENT_PACK:
1149 {
1150 tree args = ARGUMENT_PACK_ARGS (t);
1151 int i, len = TREE_VEC_LENGTH (args);
1152 for (i = 0; i < len; ++i)
1153 {
1154 if (i > 0)
1155 pp_cxx_separate_with (pp, ',');
1156 pp_cxx_expression (pp, TREE_VEC_ELT (args, i));
1157 }
1158 }
1159 break;
1160
12ea3302
GDR
1161 default:
1162 pp_c_expression (pp_c_base (pp), t);
c8094d83 1163 break;
12ea3302
GDR
1164 }
1165}
1166
1167
1168/* Declarations. */
1169
1170/* function-specifier:
1171 inline
1172 virtual
1173 explicit */
b9b44fb9 1174
12ea3302
GDR
1175static void
1176pp_cxx_function_specifier (cxx_pretty_printer *pp, tree t)
1177{
1178 switch (TREE_CODE (t))
1179 {
1180 case FUNCTION_DECL:
1181 if (DECL_VIRTUAL_P (t))
b02cec6e 1182 pp_cxx_ws_string (pp, "virtual");
12ea3302 1183 else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
b02cec6e 1184 pp_cxx_ws_string (pp, "explicit");
12ea3302 1185 else
0cbd7506 1186 pp_c_function_specifier (pp_c_base (pp), t);
12ea3302
GDR
1187
1188 default:
1189 break;
1190 }
1191}
1192
1193/* decl-specifier-seq:
1194 decl-specifier-seq(opt) decl-specifier
1195
1196 decl-specifier:
1197 storage-class-specifier
1198 type-specifier
1199 function-specifier
1200 friend
1201 typedef */
b9b44fb9 1202
12ea3302
GDR
1203static void
1204pp_cxx_decl_specifier_seq (cxx_pretty_printer *pp, tree t)
1205{
1206 switch (TREE_CODE (t))
1207 {
1208 case VAR_DECL:
1209 case PARM_DECL:
1210 case CONST_DECL:
1211 case FIELD_DECL:
1212 pp_cxx_storage_class_specifier (pp, t);
1213 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1214 break;
c8094d83 1215
12ea3302 1216 case TYPE_DECL:
b02cec6e 1217 pp_cxx_ws_string (pp, "typedef");
12ea3302
GDR
1218 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1219 break;
1220
12ea3302
GDR
1221 case FUNCTION_DECL:
1222 /* Constructors don't have return types. And conversion functions
0cbd7506 1223 do not have a type-specifier in their return types. */
12ea3302 1224 if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t))
0cbd7506 1225 pp_cxx_function_specifier (pp, t);
12ea3302 1226 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
0cbd7506 1227 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (t)));
12ea3302 1228 else
0cbd7506 1229 default:
12ea3302
GDR
1230 pp_c_declaration_specifiers (pp_c_base (pp), t);
1231 break;
1232 }
1233}
1234
1235/* simple-type-specifier:
1236 ::(opt) nested-name-specifier(opt) type-name
1237 ::(opt) nested-name-specifier(opt) template(opt) template-id
1238 char
1239 wchar_t
1240 bool
1241 short
1242 int
1243 long
1244 signed
1245 unsigned
1246 float
1247 double
1248 void */
b9b44fb9 1249
12ea3302
GDR
1250static void
1251pp_cxx_simple_type_specifier (cxx_pretty_printer *pp, tree t)
1252{
1253 switch (TREE_CODE (t))
1254 {
1255 case RECORD_TYPE:
1256 case UNION_TYPE:
1257 case ENUMERAL_TYPE:
1258 pp_cxx_qualified_id (pp, t);
1259 break;
1260
1261 case TEMPLATE_TYPE_PARM:
41fd3bac 1262 case TEMPLATE_TEMPLATE_PARM:
12ea3302
GDR
1263 case TEMPLATE_PARM_INDEX:
1264 pp_cxx_unqualified_id (pp, t);
1265 break;
1266
1267 case TYPENAME_TYPE:
b02cec6e 1268 pp_cxx_ws_string (pp, "typename");
12ea3302
GDR
1269 pp_cxx_nested_name_specifier (pp, TYPE_CONTEXT (t));
1270 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
1271 break;
1272
1273 default:
1274 pp_c_type_specifier (pp_c_base (pp), t);
1275 break;
1276 }
1277}
1278
1279/* type-specifier-seq:
1280 type-specifier type-specifier-seq(opt)
1281
1282 type-specifier:
1283 simple-type-specifier
1284 class-specifier
1285 enum-specifier
1286 elaborated-type-specifier
cd0be382 1287 cv-qualifier */
12ea3302
GDR
1288
1289static void
1290pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
1291{
12ea3302
GDR
1292 switch (TREE_CODE (t))
1293 {
1294 case TEMPLATE_DECL:
1295 case TEMPLATE_TYPE_PARM:
41fd3bac 1296 case TEMPLATE_TEMPLATE_PARM:
12ea3302
GDR
1297 case TYPE_DECL:
1298 case BOUND_TEMPLATE_TEMPLATE_PARM:
41fd3bac 1299 pp_cxx_cv_qualifier_seq (pp, t);
12ea3302
GDR
1300 pp_cxx_simple_type_specifier (pp, t);
1301 break;
1302
1303 case METHOD_TYPE:
1304 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
1305 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1306 pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t));
1307 break;
1308
3ad6a8e1 1309 case DECLTYPE_TYPE:
b02cec6e 1310 pp_cxx_ws_string (pp, "decltype");
3ad6a8e1
DG
1311 pp_cxx_left_paren (pp);
1312 pp_cxx_expression (pp, DECLTYPE_TYPE_EXPR (t));
1313 pp_cxx_right_paren (pp);
1314 break;
1315
5cb6410a
JM
1316 case RECORD_TYPE:
1317 if (TYPE_PTRMEMFUNC_P (t))
1318 {
1319 tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t);
1320 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (pfm)));
1321 pp_cxx_whitespace (pp);
1322 pp_cxx_ptr_operator (pp, t);
1323 break;
1324 }
1325 /* else fall through */
1326
12ea3302
GDR
1327 default:
1328 if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
0cbd7506 1329 pp_c_specifier_qualifier_list (pp_c_base (pp), t);
12ea3302
GDR
1330 }
1331}
1332
1333/* ptr-operator:
1334 * cv-qualifier-seq(opt)
1335 &
1336 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1337
1338static void
1339pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
1340{
1341 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
1342 t = TREE_TYPE (t);
1343 switch (TREE_CODE (t))
1344 {
1345 case REFERENCE_TYPE:
1346 case POINTER_TYPE:
1347 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
0cbd7506
MS
1348 || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t)))
1349 pp_cxx_ptr_operator (pp, TREE_TYPE (t));
5050afdf
KT
1350 pp_c_attributes_display (pp_c_base (pp),
1351 TYPE_ATTRIBUTES (TREE_TYPE (t)));
12ea3302 1352 if (TREE_CODE (t) == POINTER_TYPE)
0cbd7506
MS
1353 {
1354 pp_star (pp);
1355 pp_cxx_cv_qualifier_seq (pp, t);
1356 }
12ea3302 1357 else
0cbd7506 1358 pp_ampersand (pp);
12ea3302
GDR
1359 break;
1360
1361 case RECORD_TYPE:
1362 if (TYPE_PTRMEMFUNC_P (t))
0cbd7506
MS
1363 {
1364 pp_cxx_left_paren (pp);
1365 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t));
1366 pp_star (pp);
1367 break;
1368 }
12ea3302
GDR
1369 case OFFSET_TYPE:
1370 if (TYPE_PTR_TO_MEMBER_P (t))
0cbd7506
MS
1371 {
1372 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1373 pp_cxx_left_paren (pp);
1374 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t));
1375 pp_star (pp);
1376 pp_cxx_cv_qualifier_seq (pp, t);
1377 break;
1378 }
da1d7781 1379 /* else fall through. */
12ea3302
GDR
1380
1381 default:
1382 pp_unsupported_tree (pp, t);
1383 break;
1384 }
1385}
1386
1387static inline tree
1388pp_cxx_implicit_parameter_type (tree mf)
1389{
7e1352fe 1390 return class_of_this_parm (TREE_TYPE (mf));
12ea3302
GDR
1391}
1392
1393/*
1394 parameter-declaration:
1395 decl-specifier-seq declarator
1396 decl-specifier-seq declarator = assignment-expression
1397 decl-specifier-seq abstract-declarator(opt)
1398 decl-specifier-seq abstract-declarator(opt) assignment-expression */
b9b44fb9 1399
12ea3302
GDR
1400static inline void
1401pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
1402{
1403 pp_cxx_decl_specifier_seq (pp, t);
1404 if (TYPE_P (t))
1405 pp_cxx_abstract_declarator (pp, t);
1406 else
1407 pp_cxx_declarator (pp, t);
1408}
1409
1410/* parameter-declaration-clause:
1411 parameter-declaration-list(opt) ...(opt)
1412 parameter-declaration-list , ...
1413
1414 parameter-declaration-list:
1415 parameter-declaration
1416 parameter-declaration-list , parameter-declaration */
b9b44fb9 1417
12ea3302
GDR
1418static void
1419pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
1420{
1421 tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t);
c8094d83 1422 tree types =
6615c446 1423 TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
12ea3302
GDR
1424 const bool abstract = args == NULL
1425 || pp_c_base (pp)->flags & pp_c_flag_abstract;
1426 bool first = true;
1427
1428 /* Skip artificial parameter for nonstatic member functions. */
1429 if (TREE_CODE (t) == METHOD_TYPE)
1430 types = TREE_CHAIN (types);
1431
1432 pp_cxx_left_paren (pp);
1433 for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
1434 {
1435 if (!first)
0cbd7506 1436 pp_cxx_separate_with (pp, ',');
12ea3302
GDR
1437 first = false;
1438 pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
1439 if (!abstract && pp_c_base (pp)->flags & pp_cxx_flag_default_argument)
0cbd7506
MS
1440 {
1441 pp_cxx_whitespace (pp);
1442 pp_equal (pp);
1443 pp_cxx_whitespace (pp);
1444 pp_cxx_assignment_expression (pp, TREE_PURPOSE (types));
1445 }
12ea3302
GDR
1446 }
1447 pp_cxx_right_paren (pp);
1448}
1449
1450/* exception-specification:
1451 throw ( type-id-list(opt) )
1452
1453 type-id-list
1454 type-id
1455 type-id-list , type-id */
b9b44fb9 1456
12ea3302
GDR
1457static void
1458pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
1459{
1460 tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
5d80a306 1461 bool need_comma = false;
12ea3302 1462
3a55fb4c 1463 if (ex_spec == NULL)
12ea3302 1464 return;
3a55fb4c
JM
1465 if (TREE_PURPOSE (ex_spec))
1466 {
1467 pp_cxx_ws_string (pp, "noexcept");
1468 pp_cxx_whitespace (pp);
1469 pp_cxx_left_paren (pp);
10261728
JM
1470 if (DEFERRED_NOEXCEPT_SPEC_P (ex_spec))
1471 pp_cxx_ws_string (pp, "<uninstantiated>");
1472 else
1473 pp_cxx_expression (pp, TREE_PURPOSE (ex_spec));
3a55fb4c
JM
1474 pp_cxx_right_paren (pp);
1475 return;
1476 }
b02cec6e 1477 pp_cxx_ws_string (pp, "throw");
12ea3302
GDR
1478 pp_cxx_left_paren (pp);
1479 for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
1480 {
5d80a306
DG
1481 tree type = TREE_VALUE (ex_spec);
1482 tree argpack = NULL_TREE;
1483 int i, len = 1;
1484
1485 if (ARGUMENT_PACK_P (type))
1486 {
1487 argpack = ARGUMENT_PACK_ARGS (type);
1488 len = TREE_VEC_LENGTH (argpack);
1489 }
1490
1491 for (i = 0; i < len; ++i)
1492 {
1493 if (argpack)
1494 type = TREE_VEC_ELT (argpack, i);
1495
1496 if (need_comma)
1497 pp_cxx_separate_with (pp, ',');
1498 else
1499 need_comma = true;
1500
1501 pp_cxx_type_id (pp, type);
1502 }
12ea3302
GDR
1503 }
1504 pp_cxx_right_paren (pp);
1505}
1506
1507/* direct-declarator:
1508 declarator-id
1509 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
0cbd7506 1510 exception-specification(opt)
12ea3302
GDR
1511 direct-declaration [ constant-expression(opt) ]
1512 ( declarator ) */
b9b44fb9 1513
12ea3302
GDR
1514static void
1515pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t)
1516{
1517 switch (TREE_CODE (t))
1518 {
1519 case VAR_DECL:
1520 case PARM_DECL:
1521 case CONST_DECL:
1522 case FIELD_DECL:
1523 if (DECL_NAME (t))
0cbd7506
MS
1524 {
1525 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
5d80a306
DG
1526
1527 if ((TREE_CODE (t) == PARM_DECL && FUNCTION_PARAMETER_PACK_P (t))
1528 || template_parameter_pack_p (t))
1529 /* A function parameter pack or non-type template
1530 parameter pack. */
b02cec6e 1531 pp_cxx_ws_string (pp, "...");
5d80a306 1532
0cbd7506
MS
1533 pp_cxx_id_expression (pp, DECL_NAME (t));
1534 }
12ea3302
GDR
1535 pp_cxx_abstract_declarator (pp, TREE_TYPE (t));
1536 break;
c8094d83 1537
12ea3302
GDR
1538 case FUNCTION_DECL:
1539 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
1540 pp_cxx_id_expression (pp, t);
1541 pp_cxx_parameter_declaration_clause (pp, t);
c8094d83 1542
12ea3302 1543 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
0cbd7506
MS
1544 {
1545 pp_base (pp)->padding = pp_before;
1546 pp_cxx_cv_qualifier_seq (pp, pp_cxx_implicit_parameter_type (t));
1547 }
12ea3302
GDR
1548
1549 pp_cxx_exception_specification (pp, TREE_TYPE (t));
1550 break;
1551
1552 case TYPENAME_TYPE:
1553 case TEMPLATE_DECL:
1554 case TEMPLATE_TYPE_PARM:
1555 case TEMPLATE_PARM_INDEX:
41fd3bac 1556 case TEMPLATE_TEMPLATE_PARM:
12ea3302
GDR
1557 break;
1558
1559 default:
1560 pp_c_direct_declarator (pp_c_base (pp), t);
1561 break;
1562 }
1563}
1564
1565/* declarator:
1566 direct-declarator
1567 ptr-operator declarator */
b9b44fb9 1568
12ea3302
GDR
1569static void
1570pp_cxx_declarator (cxx_pretty_printer *pp, tree t)
1571{
1572 pp_cxx_direct_declarator (pp, t);
1573}
1574
1575/* ctor-initializer:
1576 : mem-initializer-list
1577
1578 mem-initializer-list:
1579 mem-initializer
1580 mem-initializer , mem-initializer-list
1581
1582 mem-initializer:
1583 mem-initializer-id ( expression-list(opt) )
1584
1585 mem-initializer-id:
1586 ::(opt) nested-name-specifier(opt) class-name
1587 identifier */
b9b44fb9 1588
12ea3302
GDR
1589static void
1590pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
1591{
1592 t = TREE_OPERAND (t, 0);
1593 pp_cxx_whitespace (pp);
1594 pp_colon (pp);
1595 pp_cxx_whitespace (pp);
1596 for (; t; t = TREE_CHAIN (t))
1597 {
5d80a306
DG
1598 tree purpose = TREE_PURPOSE (t);
1599 bool is_pack = PACK_EXPANSION_P (purpose);
1600
1601 if (is_pack)
1602 pp_cxx_primary_expression (pp, PACK_EXPANSION_PATTERN (purpose));
1603 else
1604 pp_cxx_primary_expression (pp, purpose);
12ea3302 1605 pp_cxx_call_argument_list (pp, TREE_VALUE (t));
5d80a306 1606 if (is_pack)
b02cec6e 1607 pp_cxx_ws_string (pp, "...");
12ea3302 1608 if (TREE_CHAIN (t))
0cbd7506 1609 pp_cxx_separate_with (pp, ',');
12ea3302
GDR
1610 }
1611}
1612
1613/* function-definition:
1614 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1615 decl-specifier-seq(opt) declarator function-try-block */
1616
b01150a2 1617static void
12ea3302
GDR
1618pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
1619{
1620 tree saved_scope = pp->enclosing_scope;
1621 pp_cxx_decl_specifier_seq (pp, t);
1622 pp_cxx_declarator (pp, t);
1623 pp_needs_newline (pp) = true;
1624 pp->enclosing_scope = DECL_CONTEXT (t);
1625 if (DECL_SAVED_TREE (t))
5882f0f3 1626 pp_cxx_statement (pp, DECL_SAVED_TREE (t));
12ea3302
GDR
1627 else
1628 {
1629 pp_cxx_semicolon (pp);
1630 pp_needs_newline (pp) = true;
1631 }
1632 pp_flush (pp);
1633 pp->enclosing_scope = saved_scope;
1634}
1635
1636/* abstract-declarator:
1637 ptr-operator abstract-declarator(opt)
1638 direct-abstract-declarator */
b9b44fb9 1639
12ea3302
GDR
1640static void
1641pp_cxx_abstract_declarator (cxx_pretty_printer *pp, tree t)
1642{
1643 if (TYPE_PTRMEM_P (t) || TYPE_PTRMEMFUNC_P (t))
1644 pp_cxx_right_paren (pp);
1645 else if (POINTER_TYPE_P (t))
1646 {
1647 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
0cbd7506
MS
1648 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1649 pp_cxx_right_paren (pp);
12ea3302
GDR
1650 t = TREE_TYPE (t);
1651 }
1652 pp_cxx_direct_abstract_declarator (pp, t);
1653}
1654
1655/* direct-abstract-declarator:
1656 direct-abstract-declarator(opt) ( parameter-declaration-clause )
0cbd7506 1657 cv-qualifier-seq(opt) exception-specification(opt)
12ea3302
GDR
1658 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1659 ( abstract-declarator ) */
b9b44fb9 1660
12ea3302
GDR
1661static void
1662pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
1663{
1664 switch (TREE_CODE (t))
1665 {
1666 case REFERENCE_TYPE:
1667 pp_cxx_abstract_declarator (pp, t);
1668 break;
1669
1670 case RECORD_TYPE:
1671 if (TYPE_PTRMEMFUNC_P (t))
0cbd7506 1672 pp_cxx_direct_abstract_declarator (pp, TYPE_PTRMEMFUNC_FN_TYPE (t));
12ea3302
GDR
1673 break;
1674
1675 case METHOD_TYPE:
1676 case FUNCTION_TYPE:
1677 pp_cxx_parameter_declaration_clause (pp, t);
1678 pp_cxx_direct_abstract_declarator (pp, TREE_TYPE (t));
1679 if (TREE_CODE (t) == METHOD_TYPE)
0cbd7506
MS
1680 {
1681 pp_base (pp)->padding = pp_before;
7e1352fe 1682 pp_cxx_cv_qualifier_seq (pp, class_of_this_parm (t));
0cbd7506 1683 }
12ea3302
GDR
1684 pp_cxx_exception_specification (pp, t);
1685 break;
1686
1687 case TYPENAME_TYPE:
1688 case TEMPLATE_TYPE_PARM:
1689 case TEMPLATE_TEMPLATE_PARM:
1690 case BOUND_TEMPLATE_TEMPLATE_PARM:
1691 case UNBOUND_CLASS_TEMPLATE:
1692 break;
1693
1694 default:
1695 pp_c_direct_abstract_declarator (pp_c_base (pp), t);
c8094d83 1696 break;
12ea3302
GDR
1697 }
1698}
1699
1700/* type-id:
1701 type-specifier-seq abstract-declarator(opt) */
b9b44fb9 1702
12ea3302
GDR
1703static void
1704pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
1705{
1706 pp_flags saved_flags = pp_c_base (pp)->flags;
1707 pp_c_base (pp)->flags |= pp_c_flag_abstract;
1708
1709 switch (TREE_CODE (t))
1710 {
1711 case TYPE_DECL:
1712 case UNION_TYPE:
1713 case RECORD_TYPE:
1714 case ENUMERAL_TYPE:
1715 case TYPENAME_TYPE:
1716 case BOUND_TEMPLATE_TEMPLATE_PARM:
1717 case UNBOUND_CLASS_TEMPLATE:
1718 case TEMPLATE_TEMPLATE_PARM:
1719 case TEMPLATE_TYPE_PARM:
1720 case TEMPLATE_PARM_INDEX:
1721 case TEMPLATE_DECL:
1722 case TYPEOF_TYPE:
a0d260fc 1723 case UNDERLYING_TYPE:
3ad6a8e1 1724 case DECLTYPE_TYPE:
12ea3302 1725 case TEMPLATE_ID_EXPR:
12ea3302 1726 pp_cxx_type_specifier_seq (pp, t);
12ea3302
GDR
1727 break;
1728
5d80a306
DG
1729 case TYPE_PACK_EXPANSION:
1730 pp_cxx_type_id (pp, PACK_EXPANSION_PATTERN (t));
b02cec6e 1731 pp_cxx_ws_string (pp, "...");
5d80a306
DG
1732 break;
1733
12ea3302
GDR
1734 default:
1735 pp_c_type_id (pp_c_base (pp), t);
1736 break;
1737 }
1738
1739 pp_c_base (pp)->flags = saved_flags;
1740}
1741
1742/* template-argument-list:
5d80a306
DG
1743 template-argument ...(opt)
1744 template-argument-list, template-argument ...(opt)
12ea3302
GDR
1745
1746 template-argument:
1747 assignment-expression
1748 type-id
5d80a306 1749 template-name */
b9b44fb9 1750
12ea3302
GDR
1751static void
1752pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
1753{
1754 int i;
5d80a306
DG
1755 bool need_comma = false;
1756
12ea3302
GDR
1757 if (t == NULL)
1758 return;
1759 for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
1760 {
1761 tree arg = TREE_VEC_ELT (t, i);
5d80a306
DG
1762 tree argpack = NULL_TREE;
1763 int idx, len = 1;
1764
1765 if (ARGUMENT_PACK_P (arg))
1766 {
1767 argpack = ARGUMENT_PACK_ARGS (arg);
1768 len = TREE_VEC_LENGTH (argpack);
1769 }
1770
1771 for (idx = 0; idx < len; idx++)
1772 {
1773 if (argpack)
1774 arg = TREE_VEC_ELT (argpack, idx);
1775
1776 if (need_comma)
1777 pp_cxx_separate_with (pp, ',');
1778 else
1779 need_comma = true;
1780
1781 if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
1782 && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
1783 pp_cxx_type_id (pp, arg);
1784 else
1785 pp_cxx_expression (pp, arg);
1786 }
12ea3302
GDR
1787 }
1788}
1789
1790
1791static void
1792pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
1793{
350fae66 1794 t = DECL_EXPR_DECL (t);
12ea3302
GDR
1795 pp_cxx_type_specifier_seq (pp, t);
1796 if (TYPE_P (t))
1797 pp_cxx_abstract_declarator (pp, t);
1798 else
1799 pp_cxx_declarator (pp, t);
1800}
1801
1802/* Statements. */
1803
b01150a2 1804static void
12ea3302
GDR
1805pp_cxx_statement (cxx_pretty_printer *pp, tree t)
1806{
1807 switch (TREE_CODE (t))
1808 {
5882f0f3
RH
1809 case CTOR_INITIALIZER:
1810 pp_cxx_ctor_initializer (pp, t);
1811 break;
1812
12ea3302 1813 case USING_STMT:
b02cec6e
JM
1814 pp_cxx_ws_string (pp, "using");
1815 pp_cxx_ws_string (pp, "namespace");
91b1ca65
MM
1816 if (DECL_CONTEXT (t))
1817 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
12ea3302
GDR
1818 pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t));
1819 break;
1820
1821 case USING_DECL:
b02cec6e 1822 pp_cxx_ws_string (pp, "using");
98ed9dae 1823 pp_cxx_nested_name_specifier (pp, USING_DECL_SCOPE (t));
12ea3302
GDR
1824 pp_cxx_unqualified_id (pp, DECL_NAME (t));
1825 break;
1826
1827 case EH_SPEC_BLOCK:
1828 break;
1829
1830 /* try-block:
0cbd7506 1831 try compound-statement handler-seq */
12ea3302
GDR
1832 case TRY_BLOCK:
1833 pp_maybe_newline_and_indent (pp, 0);
b02cec6e 1834 pp_cxx_ws_string (pp, "try");
12ea3302
GDR
1835 pp_newline_and_indent (pp, 3);
1836 pp_cxx_statement (pp, TRY_STMTS (t));
1837 pp_newline_and_indent (pp, -3);
1838 if (CLEANUP_P (t))
0cbd7506 1839 ;
12ea3302 1840 else
0cbd7506 1841 pp_cxx_statement (pp, TRY_HANDLERS (t));
12ea3302
GDR
1842 break;
1843
1844 /*
0cbd7506
MS
1845 handler-seq:
1846 handler handler-seq(opt)
12ea3302 1847
0cbd7506
MS
1848 handler:
1849 catch ( exception-declaration ) compound-statement
12ea3302 1850
0cbd7506
MS
1851 exception-declaration:
1852 type-specifier-seq declarator
1853 type-specifier-seq abstract-declarator
1854 ... */
12ea3302 1855 case HANDLER:
b02cec6e 1856 pp_cxx_ws_string (pp, "catch");
12ea3302
GDR
1857 pp_cxx_left_paren (pp);
1858 pp_cxx_exception_declaration (pp, HANDLER_PARMS (t));
1859 pp_cxx_right_paren (pp);
1860 pp_indentation (pp) += 3;
1861 pp_needs_newline (pp) = true;
1862 pp_cxx_statement (pp, HANDLER_BODY (t));
1863 pp_indentation (pp) -= 3;
1864 pp_needs_newline (pp) = true;
1865 break;
1866
5a508662 1867 /* selection-statement:
0cbd7506
MS
1868 if ( expression ) statement
1869 if ( expression ) statement else statement */
5a508662 1870 case IF_STMT:
b02cec6e 1871 pp_cxx_ws_string (pp, "if");
5a508662
RH
1872 pp_cxx_whitespace (pp);
1873 pp_cxx_left_paren (pp);
1874 pp_cxx_expression (pp, IF_COND (t));
1875 pp_cxx_right_paren (pp);
1876 pp_newline_and_indent (pp, 2);
1877 pp_cxx_statement (pp, THEN_CLAUSE (t));
1878 pp_newline_and_indent (pp, -2);
1879 if (ELSE_CLAUSE (t))
1880 {
1881 tree else_clause = ELSE_CLAUSE (t);
b02cec6e 1882 pp_cxx_ws_string (pp, "else");
5a508662
RH
1883 if (TREE_CODE (else_clause) == IF_STMT)
1884 pp_cxx_whitespace (pp);
1885 else
1886 pp_newline_and_indent (pp, 2);
1887 pp_cxx_statement (pp, else_clause);
1888 if (TREE_CODE (else_clause) != IF_STMT)
1889 pp_newline_and_indent (pp, -2);
1890 }
1891 break;
1892
fbc315db 1893 case SWITCH_STMT:
b02cec6e 1894 pp_cxx_ws_string (pp, "switch");
fbc315db
ILT
1895 pp_space (pp);
1896 pp_cxx_left_paren (pp);
934790cc 1897 pp_cxx_expression (pp, SWITCH_STMT_COND (t));
fbc315db
ILT
1898 pp_cxx_right_paren (pp);
1899 pp_indentation (pp) += 3;
1900 pp_needs_newline (pp) = true;
c3e5898b 1901 pp_cxx_statement (pp, SWITCH_STMT_BODY (t));
fbc315db
ILT
1902 pp_newline_and_indent (pp, -3);
1903 break;
1904
1905 /* iteration-statement:
0cbd7506
MS
1906 while ( expression ) statement
1907 do statement while ( expression ) ;
1908 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1909 for ( declaration expression(opt) ; expression(opt) ) statement */
fbc315db 1910 case WHILE_STMT:
b02cec6e 1911 pp_cxx_ws_string (pp, "while");
fbc315db
ILT
1912 pp_space (pp);
1913 pp_cxx_left_paren (pp);
934790cc 1914 pp_cxx_expression (pp, WHILE_COND (t));
fbc315db
ILT
1915 pp_cxx_right_paren (pp);
1916 pp_newline_and_indent (pp, 3);
c3e5898b 1917 pp_cxx_statement (pp, WHILE_BODY (t));
fbc315db
ILT
1918 pp_indentation (pp) -= 3;
1919 pp_needs_newline (pp) = true;
1920 break;
1921
1922 case DO_STMT:
b02cec6e 1923 pp_cxx_ws_string (pp, "do");
fbc315db 1924 pp_newline_and_indent (pp, 3);
c3e5898b 1925 pp_cxx_statement (pp, DO_BODY (t));
fbc315db 1926 pp_newline_and_indent (pp, -3);
b02cec6e 1927 pp_cxx_ws_string (pp, "while");
fbc315db
ILT
1928 pp_space (pp);
1929 pp_cxx_left_paren (pp);
934790cc 1930 pp_cxx_expression (pp, DO_COND (t));
fbc315db
ILT
1931 pp_cxx_right_paren (pp);
1932 pp_cxx_semicolon (pp);
1933 pp_needs_newline (pp) = true;
1934 break;
1935
1936 case FOR_STMT:
b02cec6e 1937 pp_cxx_ws_string (pp, "for");
fbc315db
ILT
1938 pp_space (pp);
1939 pp_cxx_left_paren (pp);
1940 if (FOR_INIT_STMT (t))
0cbd7506 1941 pp_cxx_statement (pp, FOR_INIT_STMT (t));
fbc315db 1942 else
0cbd7506 1943 pp_cxx_semicolon (pp);
fbc315db
ILT
1944 pp_needs_newline (pp) = false;
1945 pp_cxx_whitespace (pp);
1946 if (FOR_COND (t))
934790cc 1947 pp_cxx_expression (pp, FOR_COND (t));
fbc315db
ILT
1948 pp_cxx_semicolon (pp);
1949 pp_needs_newline (pp) = false;
1950 pp_cxx_whitespace (pp);
1951 if (FOR_EXPR (t))
934790cc 1952 pp_cxx_expression (pp, FOR_EXPR (t));
fbc315db 1953 pp_cxx_right_paren (pp);
f9132eb7
RRC
1954 pp_newline_and_indent (pp, 3);
1955 pp_cxx_statement (pp, FOR_BODY (t));
1956 pp_indentation (pp) -= 3;
1957 pp_needs_newline (pp) = true;
1958 break;
1959
1960 case RANGE_FOR_STMT:
1961 pp_cxx_ws_string (pp, "for");
1962 pp_space (pp);
1963 pp_cxx_left_paren (pp);
1964 pp_cxx_statement (pp, RANGE_FOR_DECL (t));
1965 pp_space (pp);
1966 pp_needs_newline (pp) = false;
1967 pp_colon (pp);
1968 pp_space (pp);
1969 pp_cxx_statement (pp, RANGE_FOR_EXPR (t));
1970 pp_cxx_right_paren (pp);
fbc315db 1971 pp_newline_and_indent (pp, 3);
c3e5898b 1972 pp_cxx_statement (pp, FOR_BODY (t));
fbc315db
ILT
1973 pp_indentation (pp) -= 3;
1974 pp_needs_newline (pp) = true;
1975 break;
1976
1977 /* jump-statement:
0cbd7506
MS
1978 goto identifier;
1979 continue ;
1980 return expression(opt) ; */
fbc315db
ILT
1981 case BREAK_STMT:
1982 case CONTINUE_STMT:
b02cec6e 1983 pp_string (pp, TREE_CODE (t) == BREAK_STMT ? "break" : "continue");
fbc315db
ILT
1984 pp_cxx_semicolon (pp);
1985 pp_needs_newline (pp) = true;
1986 break;
1987
934790cc 1988 /* expression-statement:
0cbd7506 1989 expression(opt) ; */
934790cc
ILT
1990 case EXPR_STMT:
1991 pp_cxx_expression (pp, EXPR_STMT_EXPR (t));
1992 pp_cxx_semicolon (pp);
1993 pp_needs_newline (pp) = true;
1994 break;
1995
5a508662 1996 case CLEANUP_STMT:
b02cec6e 1997 pp_cxx_ws_string (pp, "try");
5a508662
RH
1998 pp_newline_and_indent (pp, 2);
1999 pp_cxx_statement (pp, CLEANUP_BODY (t));
2000 pp_newline_and_indent (pp, -2);
b02cec6e 2001 pp_cxx_ws_string (pp, CLEANUP_EH_ONLY (t) ? "catch" : "finally");
5a508662
RH
2002 pp_newline_and_indent (pp, 2);
2003 pp_cxx_statement (pp, CLEANUP_EXPR (t));
2004 pp_newline_and_indent (pp, -2);
2005 break;
2006
55a3debe
DG
2007 case STATIC_ASSERT:
2008 pp_cxx_declaration (pp, t);
2009 break;
2010
12ea3302
GDR
2011 default:
2012 pp_c_statement (pp_c_base (pp), t);
2013 break;
2014 }
2015}
2016
a2a9e21c
GDR
2017/* original-namespace-definition:
2018 namespace identifier { namespace-body }
2019
2020 As an edge case, we also handle unnamed namespace definition here. */
2021
2022static void
2023pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t)
2024{
b02cec6e 2025 pp_cxx_ws_string (pp, "namespace");
91b1ca65
MM
2026 if (DECL_CONTEXT (t))
2027 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
ed36980c 2028 if (DECL_NAME (t))
a2a9e21c
GDR
2029 pp_cxx_unqualified_id (pp, t);
2030 pp_cxx_whitespace (pp);
2031 pp_cxx_left_brace (pp);
2032 /* We do not print the namespace-body. */
2033 pp_cxx_whitespace (pp);
2034 pp_cxx_right_brace (pp);
2035}
2036
2037/* namespace-alias:
2038 identifier
2039
2040 namespace-alias-definition:
2041 namespace identifier = qualified-namespace-specifier ;
2042
2043 qualified-namespace-specifier:
2044 ::(opt) nested-name-specifier(opt) namespace-name */
2045
2046static void
2047pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t)
2048{
b02cec6e 2049 pp_cxx_ws_string (pp, "namespace");
91b1ca65
MM
2050 if (DECL_CONTEXT (t))
2051 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
a2a9e21c
GDR
2052 pp_cxx_unqualified_id (pp, t);
2053 pp_cxx_whitespace (pp);
2054 pp_equal (pp);
2055 pp_cxx_whitespace (pp);
91b1ca65 2056 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)))
3db45ab5 2057 pp_cxx_nested_name_specifier (pp,
91b1ca65 2058 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)));
a2a9e21c
GDR
2059 pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t));
2060 pp_cxx_semicolon (pp);
2061}
2062
12ea3302
GDR
2063/* simple-declaration:
2064 decl-specifier-seq(opt) init-declarator-list(opt) */
b9b44fb9 2065
12ea3302
GDR
2066static void
2067pp_cxx_simple_declaration (cxx_pretty_printer *pp, tree t)
2068{
2069 pp_cxx_decl_specifier_seq (pp, t);
2070 pp_cxx_init_declarator (pp, t);
2071 pp_cxx_semicolon (pp);
2072 pp_needs_newline (pp) = true;
2073}
2074
2075/*
2076 template-parameter-list:
2077 template-parameter
2078 template-parameter-list , template-parameter */
2079
2080static inline void
2081pp_cxx_template_parameter_list (cxx_pretty_printer *pp, tree t)
2082{
2083 const int n = TREE_VEC_LENGTH (t);
2084 int i;
2085 for (i = 0; i < n; ++i)
2086 {
2087 if (i)
0cbd7506 2088 pp_cxx_separate_with (pp, ',');
12ea3302
GDR
2089 pp_cxx_template_parameter (pp, TREE_VEC_ELT (t, i));
2090 }
2091}
2092
2093/* template-parameter:
2094 type-parameter
2095 parameter-declaration
2096
2097 type-parameter:
5d80a306
DG
2098 class ...(opt) identifier(opt)
2099 class identifier(opt) = type-id
12ea3302 2100 typename identifier(opt)
5d80a306
DG
2101 typename ...(opt) identifier(opt) = type-id
2102 template < template-parameter-list > class ...(opt) identifier(opt)
3db45ab5 2103 template < template-parameter-list > class identifier(opt) = template-name */
b9b44fb9 2104
12ea3302
GDR
2105static void
2106pp_cxx_template_parameter (cxx_pretty_printer *pp, tree t)
2107{
2108 tree parameter = TREE_VALUE (t);
2109 switch (TREE_CODE (parameter))
2110 {
2111 case TYPE_DECL:
b02cec6e 2112 pp_cxx_ws_string (pp, "class");
5d80a306 2113 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t)))
b02cec6e 2114 pp_cxx_ws_string (pp, "...");
12ea3302 2115 if (DECL_NAME (parameter))
0cbd7506 2116 pp_cxx_tree_identifier (pp, DECL_NAME (parameter));
39a13be5 2117 /* FIXME: Check if we should print also default argument. */
12ea3302
GDR
2118 break;
2119
2120 case PARM_DECL:
2121 pp_cxx_parameter_declaration (pp, parameter);
2122 break;
2123
2124 case TEMPLATE_DECL:
2125 break;
2126
2127 default:
2128 pp_unsupported_tree (pp, t);
2129 break;
2130 }
2131}
2132
b2517173
GDR
2133/* Pretty-print a template parameter in the canonical form
2134 "template-parameter-<level>-<position in parameter list>". */
2135
2136void
2137pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm)
2138{
2139 const enum tree_code code = TREE_CODE (parm);
2140
04c06002 2141 /* Brings type template parameters to the canonical forms. */
b2517173
GDR
2142 if (code == TEMPLATE_TYPE_PARM || code == TEMPLATE_TEMPLATE_PARM
2143 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
2144 parm = TEMPLATE_TYPE_PARM_INDEX (parm);
c8094d83 2145
b2517173 2146 pp_cxx_begin_template_argument_list (pp);
f41c4af3 2147 pp_cxx_ws_string (pp, M_("template-parameter-"));
b2517173
GDR
2148 pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm));
2149 pp_minus (pp);
2150 pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1);
2151 pp_cxx_end_template_argument_list (pp);
2152}
2153
12ea3302
GDR
2154/*
2155 template-declaration:
2156 export(opt) template < template-parameter-list > declaration */
b9b44fb9 2157
12ea3302
GDR
2158static void
2159pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t)
2160{
2161 tree tmpl = most_general_template (t);
2162 tree level;
12ea3302
GDR
2163
2164 pp_maybe_newline_and_indent (pp, 0);
2165 for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level))
2166 {
b02cec6e 2167 pp_cxx_ws_string (pp, "template");
12ea3302
GDR
2168 pp_cxx_begin_template_argument_list (pp);
2169 pp_cxx_template_parameter_list (pp, TREE_VALUE (level));
2170 pp_cxx_end_template_argument_list (pp);
2171 pp_newline_and_indent (pp, 3);
12ea3302
GDR
2172 }
2173 if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t))
2174 pp_cxx_function_definition (pp, t);
2175 else
2176 pp_cxx_simple_declaration (pp, t);
2177}
2178
2179static void
2180pp_cxx_explicit_specialization (cxx_pretty_printer *pp, tree t)
2181{
2182 pp_unsupported_tree (pp, t);
2183}
2184
2185static void
2186pp_cxx_explicit_instantiation (cxx_pretty_printer *pp, tree t)
2187{
2188 pp_unsupported_tree (pp, t);
2189}
2190
2191/*
2192 declaration:
2193 block-declaration
2194 function-definition
2195 template-declaration
2196 explicit-instantiation
2197 explicit-specialization
2198 linkage-specification
2199 namespace-definition
2200
2201 block-declaration:
2202 simple-declaration
2203 asm-definition
2204 namespace-alias-definition
2205 using-declaration
55a3debe
DG
2206 using-directive
2207 static_assert-declaration */
12ea3302
GDR
2208void
2209pp_cxx_declaration (cxx_pretty_printer *pp, tree t)
2210{
55a3debe
DG
2211 if (TREE_CODE (t) == STATIC_ASSERT)
2212 {
b02cec6e 2213 pp_cxx_ws_string (pp, "static_assert");
55a3debe
DG
2214 pp_cxx_left_paren (pp);
2215 pp_cxx_expression (pp, STATIC_ASSERT_CONDITION (t));
2216 pp_cxx_separate_with (pp, ',');
2217 pp_cxx_expression (pp, STATIC_ASSERT_MESSAGE (t));
2218 pp_cxx_right_paren (pp);
2219 }
2220 else if (!DECL_LANG_SPECIFIC (t))
12ea3302 2221 pp_cxx_simple_declaration (pp, t);
a2a9e21c 2222 else if (DECL_USE_TEMPLATE (t))
12ea3302
GDR
2223 switch (DECL_USE_TEMPLATE (t))
2224 {
a2a9e21c 2225 case 1:
0cbd7506
MS
2226 pp_cxx_template_declaration (pp, t);
2227 break;
c8094d83 2228
12ea3302 2229 case 2:
0cbd7506
MS
2230 pp_cxx_explicit_specialization (pp, t);
2231 break;
12ea3302
GDR
2232
2233 case 3:
0cbd7506
MS
2234 pp_cxx_explicit_instantiation (pp, t);
2235 break;
12ea3302
GDR
2236
2237 default:
0cbd7506 2238 break;
12ea3302 2239 }
12ea3302
GDR
2240 else switch (TREE_CODE (t))
2241 {
2242 case VAR_DECL:
2243 case TYPE_DECL:
2244 pp_cxx_simple_declaration (pp, t);
2245 break;
c8094d83 2246
12ea3302
GDR
2247 case FUNCTION_DECL:
2248 if (DECL_SAVED_TREE (t))
0cbd7506 2249 pp_cxx_function_definition (pp, t);
12ea3302 2250 else
0cbd7506 2251 pp_cxx_simple_declaration (pp, t);
12ea3302
GDR
2252 break;
2253
a2a9e21c
GDR
2254 case NAMESPACE_DECL:
2255 if (DECL_NAMESPACE_ALIAS (t))
0cbd7506 2256 pp_cxx_namespace_alias_definition (pp, t);
a2a9e21c 2257 else
0cbd7506 2258 pp_cxx_original_namespace_definition (pp, t);
a2a9e21c
GDR
2259 break;
2260
12ea3302
GDR
2261 default:
2262 pp_unsupported_tree (pp, t);
2263 break;
2264 }
2265}
2266
066f956c 2267static void
2d65b828
PC
2268pp_cxx_typeid_expression (cxx_pretty_printer *pp, tree t)
2269{
2270 t = TREE_OPERAND (t, 0);
b02cec6e 2271 pp_cxx_ws_string (pp, "typeid");
2d65b828
PC
2272 pp_cxx_left_paren (pp);
2273 if (TYPE_P (t))
2274 pp_cxx_type_id (pp, t);
2275 else
2276 pp_cxx_expression (pp, t);
2277 pp_cxx_right_paren (pp);
2278}
2279
fdb8f418
PC
2280void
2281pp_cxx_va_arg_expression (cxx_pretty_printer *pp, tree t)
2282{
b02cec6e 2283 pp_cxx_ws_string (pp, "va_arg");
fdb8f418
PC
2284 pp_cxx_left_paren (pp);
2285 pp_cxx_assignment_expression (pp, TREE_OPERAND (t, 0));
2286 pp_cxx_separate_with (pp, ',');
2287 pp_cxx_type_id (pp, TREE_TYPE (t));
2288 pp_cxx_right_paren (pp);
2289}
2290
094a5fe2
JJ
2291static bool
2292pp_cxx_offsetof_expression_1 (cxx_pretty_printer *pp, tree t)
2293{
2294 switch (TREE_CODE (t))
2295 {
2296 case ARROW_EXPR:
2297 if (TREE_CODE (TREE_OPERAND (t, 0)) == STATIC_CAST_EXPR
2298 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
2299 {
2300 pp_cxx_type_id (pp, TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))));
2301 pp_cxx_separate_with (pp, ',');
2302 return true;
2303 }
2304 return false;
2305 case COMPONENT_REF:
2306 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
2307 return false;
2308 if (TREE_CODE (TREE_OPERAND (t, 0)) != ARROW_EXPR)
2309 pp_cxx_dot (pp);
2310 pp_cxx_expression (pp, TREE_OPERAND (t, 1));
2311 return true;
2312 case ARRAY_REF:
2313 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
2314 return false;
2315 pp_left_bracket (pp);
2316 pp_cxx_expression (pp, TREE_OPERAND (t, 1));
2317 pp_right_bracket (pp);
2318 return true;
2319 default:
2320 return false;
2321 }
2322}
2323
2324void
2325pp_cxx_offsetof_expression (cxx_pretty_printer *pp, tree t)
2326{
b02cec6e 2327 pp_cxx_ws_string (pp, "offsetof");
094a5fe2
JJ
2328 pp_cxx_left_paren (pp);
2329 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
2330 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
2331 pp_cxx_right_paren (pp);
2332}
2333
e74392f0
PC
2334void
2335pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t)
2336{
2337 cp_trait_kind kind = TRAIT_EXPR_KIND (t);
2338
2339 switch (kind)
2340 {
2341 case CPTK_HAS_NOTHROW_ASSIGN:
b02cec6e 2342 pp_cxx_ws_string (pp, "__has_nothrow_assign");
e74392f0
PC
2343 break;
2344 case CPTK_HAS_TRIVIAL_ASSIGN:
b02cec6e 2345 pp_cxx_ws_string (pp, "__has_trivial_assign");
e74392f0
PC
2346 break;
2347 case CPTK_HAS_NOTHROW_CONSTRUCTOR:
b02cec6e 2348 pp_cxx_ws_string (pp, "__has_nothrow_constructor");
e74392f0
PC
2349 break;
2350 case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
b02cec6e 2351 pp_cxx_ws_string (pp, "__has_trivial_constructor");
e74392f0
PC
2352 break;
2353 case CPTK_HAS_NOTHROW_COPY:
b02cec6e 2354 pp_cxx_ws_string (pp, "__has_nothrow_copy");
e74392f0
PC
2355 break;
2356 case CPTK_HAS_TRIVIAL_COPY:
b02cec6e 2357 pp_cxx_ws_string (pp, "__has_trivial_copy");
e74392f0
PC
2358 break;
2359 case CPTK_HAS_TRIVIAL_DESTRUCTOR:
b02cec6e 2360 pp_cxx_ws_string (pp, "__has_trivial_destructor");
e74392f0
PC
2361 break;
2362 case CPTK_HAS_VIRTUAL_DESTRUCTOR:
b02cec6e 2363 pp_cxx_ws_string (pp, "__has_virtual_destructor");
e74392f0
PC
2364 break;
2365 case CPTK_IS_ABSTRACT:
b02cec6e 2366 pp_cxx_ws_string (pp, "__is_abstract");
e74392f0
PC
2367 break;
2368 case CPTK_IS_BASE_OF:
b02cec6e 2369 pp_cxx_ws_string (pp, "__is_base_of");
e74392f0
PC
2370 break;
2371 case CPTK_IS_CLASS:
b02cec6e 2372 pp_cxx_ws_string (pp, "__is_class");
e74392f0
PC
2373 break;
2374 case CPTK_IS_CONVERTIBLE_TO:
b02cec6e 2375 pp_cxx_ws_string (pp, "__is_convertible_to");
e74392f0
PC
2376 break;
2377 case CPTK_IS_EMPTY:
b02cec6e 2378 pp_cxx_ws_string (pp, "__is_empty");
e74392f0
PC
2379 break;
2380 case CPTK_IS_ENUM:
b02cec6e 2381 pp_cxx_ws_string (pp, "__is_enum");
e74392f0 2382 break;
b3908fcc
JW
2383 case CPTK_IS_FINAL:
2384 pp_cxx_ws_string (pp, "__is_final");
2385 break;
e74392f0 2386 case CPTK_IS_POD:
b02cec6e 2387 pp_cxx_ws_string (pp, "__is_pod");
e74392f0
PC
2388 break;
2389 case CPTK_IS_POLYMORPHIC:
b02cec6e 2390 pp_cxx_ws_string (pp, "__is_polymorphic");
e74392f0 2391 break;
c32097d8
JM
2392 case CPTK_IS_STD_LAYOUT:
2393 pp_cxx_ws_string (pp, "__is_std_layout");
2394 break;
2395 case CPTK_IS_TRIVIAL:
2396 pp_cxx_ws_string (pp, "__is_trivial");
2397 break;
e74392f0 2398 case CPTK_IS_UNION:
b02cec6e 2399 pp_cxx_ws_string (pp, "__is_union");
e74392f0 2400 break;
2b08f2c5
JM
2401 case CPTK_IS_LITERAL_TYPE:
2402 pp_cxx_ws_string (pp, "__is_literal_type");
2403 break;
e74392f0
PC
2404
2405 default:
2406 gcc_unreachable ();
2407 }
2408
2409 pp_cxx_left_paren (pp);
2410 pp_cxx_type_id (pp, TRAIT_EXPR_TYPE1 (t));
2411
2412 if (kind == CPTK_IS_BASE_OF || kind == CPTK_IS_CONVERTIBLE_TO)
2413 {
2414 pp_cxx_separate_with (pp, ',');
2415 pp_cxx_type_id (pp, TRAIT_EXPR_TYPE2 (t));
2416 }
2417
2418 pp_cxx_right_paren (pp);
2419}
12ea3302
GDR
2420\f
2421typedef c_pretty_print_fn pp_fun;
2422
b9b44fb9
GDR
2423/* Initialization of a C++ pretty-printer object. */
2424
12ea3302
GDR
2425void
2426pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
2427{
2428 pp_c_pretty_printer_init (pp_c_base (pp));
2429 pp_set_line_maximum_length (pp, 0);
e1a4dd13
GDR
2430
2431 pp->c_base.declaration = (pp_fun) pp_cxx_declaration;
12ea3302
GDR
2432 pp->c_base.declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
2433 pp->c_base.function_specifier = (pp_fun) pp_cxx_function_specifier;
2434 pp->c_base.type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
e1a4dd13
GDR
2435 pp->c_base.declarator = (pp_fun) pp_cxx_declarator;
2436 pp->c_base.direct_declarator = (pp_fun) pp_cxx_direct_declarator;
12ea3302 2437 pp->c_base.parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
e1a4dd13 2438 pp->c_base.type_id = (pp_fun) pp_cxx_type_id;
12ea3302
GDR
2439 pp->c_base.abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
2440 pp->c_base.direct_abstract_declarator =
2441 (pp_fun) pp_cxx_direct_abstract_declarator;
2442 pp->c_base.simple_type_specifier = (pp_fun)pp_cxx_simple_type_specifier;
2443
2444 /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
2445
a176426f 2446 pp->c_base.constant = (pp_fun) pp_cxx_constant;
4b780675 2447 pp->c_base.id_expression = (pp_fun) pp_cxx_id_expression;
e1a4dd13
GDR
2448 pp->c_base.primary_expression = (pp_fun) pp_cxx_primary_expression;
2449 pp->c_base.postfix_expression = (pp_fun) pp_cxx_postfix_expression;
2450 pp->c_base.unary_expression = (pp_fun) pp_cxx_unary_expression;
4b780675 2451 pp->c_base.multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
e1a4dd13
GDR
2452 pp->c_base.conditional_expression = (pp_fun) pp_cxx_conditional_expression;
2453 pp->c_base.assignment_expression = (pp_fun) pp_cxx_assignment_expression;
12ea3302
GDR
2454 pp->c_base.expression = (pp_fun) pp_cxx_expression;
2455 pp->enclosing_scope = global_namespace;
e1a4dd13 2456}