]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/cxx-pretty-print.c
Update copyright years.
[thirdparty/gcc.git] / gcc / cp / cxx-pretty-print.c
CommitLineData
e1a4dd13 1/* Implementation of subroutines for the GNU C++ pretty-printer.
8d9254fc 2 Copyright (C) 2003-2020 Free Software Foundation, Inc.
e1a4dd13
GDR
3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
e77f031d 9Software Foundation; either version 3, or (at your option) any later
e1a4dd13
GDR
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
e77f031d
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
e1a4dd13
GDR
20
21#include "config.h"
22#include "system.h"
23#include "coretypes.h"
e1a4dd13 24#include "cp-tree.h"
40013784 25#include "cxx-pretty-print.h"
5d127eeb 26#include "tree-pretty-print.h"
4b780675
GDR
27
28static void pp_cxx_unqualified_id (cxx_pretty_printer *, tree);
12ea3302 29static void pp_cxx_nested_name_specifier (cxx_pretty_printer *, tree);
4b780675 30static void pp_cxx_qualified_id (cxx_pretty_printer *, tree);
4b780675 31static void pp_cxx_template_argument_list (cxx_pretty_printer *, tree);
12ea3302
GDR
32static void pp_cxx_type_specifier_seq (cxx_pretty_printer *, tree);
33static void pp_cxx_ptr_operator (cxx_pretty_printer *, tree);
7090f4b3 34static void pp_cxx_parameter_declaration_clause (cxx_pretty_printer *, tree);
12ea3302 35static void pp_cxx_template_parameter (cxx_pretty_printer *, tree);
392e3d51 36static void pp_cxx_cast_expression (cxx_pretty_printer *, tree);
066f956c 37static void pp_cxx_typeid_expression (cxx_pretty_printer *, tree);
f078dc7d
AS
38static void pp_cxx_unary_left_fold_expression (cxx_pretty_printer *, tree);
39static void pp_cxx_unary_right_fold_expression (cxx_pretty_printer *, tree);
40static void pp_cxx_binary_fold_expression (cxx_pretty_printer *, tree);
cb57504a 41static void pp_cxx_concept_definition (cxx_pretty_printer *, tree);
e1a4dd13 42\f
4b780675
GDR
43
44static inline void
45pp_cxx_nonconsecutive_character (cxx_pretty_printer *pp, int c)
46{
47 const char *p = pp_last_position_in_text (pp);
48
49 if (p != NULL && *p == c)
12ea3302 50 pp_cxx_whitespace (pp);
4b780675 51 pp_character (pp, c);
b066401f 52 pp->padding = pp_none;
4b780675
GDR
53}
54
12ea3302 55#define pp_cxx_expression_list(PP, T) \
b066401f 56 pp_c_expression_list (PP, T)
12ea3302 57#define pp_cxx_space_for_pointer_operator(PP, T) \
b066401f 58 pp_c_space_for_pointer_operator (PP, T)
12ea3302 59#define pp_cxx_init_declarator(PP, T) \
b066401f 60 pp_c_init_declarator (PP, T)
12ea3302 61#define pp_cxx_call_argument_list(PP, T) \
b066401f 62 pp_c_call_argument_list (PP, T)
e1a4dd13 63
41fd3bac 64void
12ea3302 65pp_cxx_colon_colon (cxx_pretty_printer *pp)
e1a4dd13 66{
12ea3302 67 pp_colon_colon (pp);
b066401f 68 pp->padding = pp_none;
e1a4dd13
GDR
69}
70
41fd3bac
GDR
71void
72pp_cxx_begin_template_argument_list (cxx_pretty_printer *pp)
73{
74 pp_cxx_nonconsecutive_character (pp, '<');
75}
76
77void
78pp_cxx_end_template_argument_list (cxx_pretty_printer *pp)
79{
80 pp_cxx_nonconsecutive_character (pp, '>');
81}
82
83void
84pp_cxx_separate_with (cxx_pretty_printer *pp, int c)
85{
86 pp_separate_with (pp, c);
b066401f 87 pp->padding = pp_none;
41fd3bac 88}
e1a4dd13 89
04c06002 90/* Expressions. */
e1a4dd13 91
12ea3302
GDR
92/* conversion-function-id:
93 operator conversion-type-id
4b780675 94
12ea3302
GDR
95 conversion-type-id:
96 type-specifier-seq conversion-declarator(opt)
4b780675 97
12ea3302
GDR
98 conversion-declarator:
99 ptr-operator conversion-declarator(opt) */
b9b44fb9 100
12ea3302
GDR
101static inline void
102pp_cxx_conversion_function_id (cxx_pretty_printer *pp, tree t)
4b780675 103{
b02cec6e 104 pp_cxx_ws_string (pp, "operator");
12ea3302 105 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
4b780675
GDR
106}
107
12ea3302
GDR
108static inline void
109pp_cxx_template_id (cxx_pretty_printer *pp, tree t)
e1a4dd13 110{
12ea3302
GDR
111 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
112 pp_cxx_begin_template_argument_list (pp);
113 pp_cxx_template_argument_list (pp, TREE_OPERAND (t, 1));
114 pp_cxx_end_template_argument_list (pp);
e1a4dd13
GDR
115}
116
5a023baa
GDR
117/* Prints the unqualified part of the id-expression T.
118
119 unqualified-id:
4b780675
GDR
120 identifier
121 operator-function-id
122 conversion-function-id
123 ~ class-name
124 template-id */
b9b44fb9 125
4b780675
GDR
126static void
127pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t)
128{
129 enum tree_code code = TREE_CODE (t);
130 switch (code)
131 {
12ea3302 132 case RESULT_DECL:
0691175f 133 pp->translate_string ("<return-value>");
12ea3302
GDR
134 break;
135
136 case OVERLOAD:
a736411a 137 t = OVL_FIRST (t);
9c62c873 138 /* FALLTHRU */
4b780675
GDR
139 case VAR_DECL:
140 case PARM_DECL:
141 case CONST_DECL:
142 case TYPE_DECL:
143 case FUNCTION_DECL:
144 case NAMESPACE_DECL:
145 case FIELD_DECL:
146 case LABEL_DECL:
147 case USING_DECL:
12ea3302 148 case TEMPLATE_DECL:
4b780675 149 t = DECL_NAME (t);
191816a3 150 /* FALLTHRU */
c8094d83 151
4b780675 152 case IDENTIFIER_NODE:
12ea3302 153 if (t == NULL)
0691175f 154 pp->translate_string ("<unnamed>");
84c0088f 155 else if (IDENTIFIER_CONV_OP_P (t))
0cbd7506 156 pp_cxx_conversion_function_id (pp, t);
4b780675 157 else
79a2e690 158 pp_cxx_tree_identifier (pp, t);
4b780675
GDR
159 break;
160
161 case TEMPLATE_ID_EXPR:
12ea3302
GDR
162 pp_cxx_template_id (pp, t);
163 break;
164
3601f003
KL
165 case BASELINK:
166 pp_cxx_unqualified_id (pp, BASELINK_FUNCTIONS (t));
167 break;
168
12ea3302
GDR
169 case RECORD_TYPE:
170 case UNION_TYPE:
171 case ENUMERAL_TYPE:
c8c00613
PC
172 case TYPENAME_TYPE:
173 case UNBOUND_CLASS_TEMPLATE:
12ea3302 174 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
1f41df91 175 if (tree ti = TYPE_TEMPLATE_INFO_MAYBE_ALIAS (t))
e1faa105
JM
176 {
177 pp_cxx_begin_template_argument_list (pp);
1f41df91
JM
178 tree args = INNERMOST_TEMPLATE_ARGS (TI_ARGS (ti));
179 pp_cxx_template_argument_list (pp, args);
e1faa105
JM
180 pp_cxx_end_template_argument_list (pp);
181 }
12ea3302
GDR
182 break;
183
6735e374
PC
184 case BIT_NOT_EXPR:
185 pp_cxx_complement (pp);
186 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
187 break;
188
12ea3302 189 case TEMPLATE_TYPE_PARM:
41fd3bac 190 case TEMPLATE_TEMPLATE_PARM:
33f746e5
AO
191 if (template_placeholder_p (t))
192 {
193 t = TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t));
194 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
195 pp_string (pp, "<...auto...>");
196 }
197 else if (TYPE_IDENTIFIER (t))
0cbd7506 198 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
41fd3bac 199 else
0cbd7506 200 pp_cxx_canonical_template_parameter (pp, t);
41fd3bac
GDR
201 break;
202
12ea3302
GDR
203 case TEMPLATE_PARM_INDEX:
204 pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t));
4b780675
GDR
205 break;
206
c8c00613
PC
207 case BOUND_TEMPLATE_TEMPLATE_PARM:
208 pp_cxx_cv_qualifier_seq (pp, t);
209 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
210 pp_cxx_begin_template_argument_list (pp);
211 pp_cxx_template_argument_list (pp, TYPE_TI_ARGS (t));
212 pp_cxx_end_template_argument_list (pp);
5a023baa
GDR
213 break;
214
4b780675
GDR
215 default:
216 pp_unsupported_tree (pp, t);
12ea3302
GDR
217 break;
218 }
219}
220
b9b44fb9
GDR
221/* Pretty-print out the token sequence ":: template" in template codes
222 where it is needed to "inline declare" the (following) member as
666c27b9 223 a template. This situation arises when SCOPE of T is dependent
b9b44fb9
GDR
224 on template parameters. */
225
12ea3302
GDR
226static inline void
227pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
228{
229 if (TREE_CODE (t) == TEMPLATE_ID_EXPR
230 && TYPE_P (scope) && dependent_type_p (scope))
b02cec6e 231 pp_cxx_ws_string (pp, "template");
12ea3302
GDR
232}
233
234/* nested-name-specifier:
235 class-or-namespace-name :: nested-name-specifier(opt)
236 class-or-namespace-name :: template nested-name-specifier */
b9b44fb9 237
12ea3302
GDR
238static void
239pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
240{
cb57504a
JM
241 /* FIXME: When diagnosing references to concepts (especially as types?)
242 we end up adding too many '::' to the name. This is partially due
243 to the fact that pp->enclosing_namespace is null. */
244 if (t == global_namespace)
245 {
246 pp_cxx_colon_colon (pp);
247 }
248 else if (!SCOPE_FILE_SCOPE_P (t) && t != pp->enclosing_scope)
12ea3302 249 {
5bc08e85 250 tree scope = get_containing_scope (t);
12ea3302
GDR
251 pp_cxx_nested_name_specifier (pp, scope);
252 pp_cxx_template_keyword_if_needed (pp, scope, t);
253 pp_cxx_unqualified_id (pp, t);
254 pp_cxx_colon_colon (pp);
4b780675
GDR
255 }
256}
257
258/* qualified-id:
259 nested-name-specifier template(opt) unqualified-id */
b9b44fb9 260
4b780675
GDR
261static void
262pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t)
263{
264 switch (TREE_CODE (t))
265 {
b9b44fb9 266 /* A pointer-to-member is always qualified. */
4b780675 267 case PTRMEM_CST:
12ea3302 268 pp_cxx_nested_name_specifier (pp, PTRMEM_CST_CLASS (t));
4b780675
GDR
269 pp_cxx_unqualified_id (pp, PTRMEM_CST_MEMBER (t));
270 break;
271
b9b44fb9 272 /* In Standard C++, functions cannot possibly be used as
0cbd7506
MS
273 nested-name-specifiers. However, there are situations where
274 is "makes sense" to output the surrounding function name for the
275 purpose of emphasizing on the scope kind. Just printing the
276 function name might not be sufficient as it may be overloaded; so,
277 we decorate the function with its signature too.
278 FIXME: This is probably the wrong pretty-printing for conversion
279 functions and some function templates. */
12ea3302 280 case OVERLOAD:
a736411a 281 t = OVL_FIRST (t);
191816a3 282 /* FALLTHRU */
12ea3302
GDR
283 case FUNCTION_DECL:
284 if (DECL_FUNCTION_MEMBER_P (t))
0cbd7506 285 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
12ea3302 286 pp_cxx_unqualified_id
0cbd7506 287 (pp, DECL_CONSTRUCTOR_P (t) ? DECL_CONTEXT (t) : t);
b9b44fb9 288 pp_cxx_parameter_declaration_clause (pp, TREE_TYPE (t));
12ea3302
GDR
289 break;
290
4b780675
GDR
291 case OFFSET_REF:
292 case SCOPE_REF:
12ea3302 293 pp_cxx_nested_name_specifier (pp, TREE_OPERAND (t, 0));
4b780675
GDR
294 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 1));
295 break;
296
297 default:
298 {
5bc08e85 299 tree scope = get_containing_scope (t);
0cbd7506
MS
300 if (scope != pp->enclosing_scope)
301 {
302 pp_cxx_nested_name_specifier (pp, scope);
303 pp_cxx_template_keyword_if_needed (pp, scope, t);
304 }
305 pp_cxx_unqualified_id (pp, t);
4b780675
GDR
306 }
307 break;
308 }
309}
310
79371671
WW
311/* Given a value e of ENUMERAL_TYPE:
312 Print out the first ENUMERATOR id with value e, if one is found,
313 (including nested names but excluding the enum name if unscoped)
314 else print out the value as a C-style cast (type-id)value. */
315
316static void
317pp_cxx_enumeration_constant (cxx_pretty_printer *pp, tree e)
318{
319 tree type = TREE_TYPE (e);
8936f047 320 tree value = NULL_TREE;
79371671
WW
321
322 /* Find the name of this constant. */
8936f047
JJ
323 if ((pp->flags & pp_c_flag_gnu_v3) == 0)
324 for (value = TYPE_VALUES (type); value != NULL_TREE;
325 value = TREE_CHAIN (value))
326 if (tree_int_cst_equal (DECL_INITIAL (TREE_VALUE (value)), e))
327 break;
79371671
WW
328
329 if (value != NULL_TREE)
330 {
331 if (!ENUM_IS_SCOPED (type))
332 type = get_containing_scope (type);
333 pp_cxx_nested_name_specifier (pp, type);
334 pp->id_expression (TREE_PURPOSE (value));
335 }
336 else
337 {
338 /* Value must have been cast. */
339 pp_c_type_cast (pp, type);
340 pp_c_integer_constant (pp, e);
341 }
342}
343
a176426f 344
ca43e9d5
GDR
345void
346cxx_pretty_printer::constant (tree t)
a176426f
GDR
347{
348 switch (TREE_CODE (t))
349 {
350 case STRING_CST:
351 {
3db45ab5
MS
352 const bool in_parens = PAREN_STRING_LITERAL_P (t);
353 if (in_parens)
ca43e9d5
GDR
354 pp_cxx_left_paren (this);
355 c_pretty_printer::constant (t);
3db45ab5 356 if (in_parens)
ca43e9d5 357 pp_cxx_right_paren (this);
a176426f
GDR
358 }
359 break;
360
14c2101d 361 case INTEGER_CST:
5116acc6 362 if (NULLPTR_TYPE_P (TREE_TYPE (t)))
14c2101d 363 {
ca43e9d5 364 pp_string (this, "nullptr");
14c2101d
JM
365 break;
366 }
79371671
WW
367 else if (TREE_CODE (TREE_TYPE (t)) == ENUMERAL_TYPE)
368 {
369 pp_cxx_enumeration_constant (this, t);
370 break;
371 }
191816a3 372 /* fall through. */
14c2101d 373
a176426f 374 default:
ca43e9d5 375 c_pretty_printer::constant (t);
a176426f
GDR
376 break;
377 }
378}
379
4b780675 380/* id-expression:
cd0be382 381 unqualified-id
4b780675 382 qualified-id */
b9b44fb9 383
66dfe4c4
GDR
384void
385cxx_pretty_printer::id_expression (tree t)
4b780675 386{
12ea3302 387 if (TREE_CODE (t) == OVERLOAD)
a736411a 388 t = OVL_FIRST (t);
d04a575f 389 if (DECL_P (t) && DECL_CONTEXT (t))
66dfe4c4 390 pp_cxx_qualified_id (this, t);
4b780675 391 else
66dfe4c4 392 pp_cxx_unqualified_id (this, t);
4b780675
GDR
393}
394
3ce4f9e4
ESR
395/* user-defined literal:
396 literal ud-suffix */
397
398void
399pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
400{
20059c8b
GDR
401 pp->constant (USERDEF_LITERAL_VALUE (t));
402 pp->id_expression (USERDEF_LITERAL_SUFFIX_ID (t));
3ce4f9e4
ESR
403}
404
405
4b780675
GDR
406/* primary-expression:
407 literal
408 this
409 :: identifier
410 :: operator-function-id
411 :: qualifier-id
412 ( expression )
e74392f0
PC
413 id-expression
414
415 GNU Extensions:
fdb8f418 416 __builtin_va_arg ( assignment-expression , type-id )
094a5fe2 417 __builtin_offsetof ( type-id, offsetof-expression )
be845b04 418 __builtin_addressof ( expression )
fdb8f418 419
e74392f0
PC
420 __has_nothrow_assign ( type-id )
421 __has_nothrow_constructor ( type-id )
422 __has_nothrow_copy ( type-id )
423 __has_trivial_assign ( type-id )
424 __has_trivial_constructor ( type-id )
425 __has_trivial_copy ( type-id )
be845b04 426 __has_unique_object_representations ( type-id )
e74392f0
PC
427 __has_trivial_destructor ( type-id )
428 __has_virtual_destructor ( type-id )
429 __is_abstract ( type-id )
430 __is_base_of ( type-id , type-id )
431 __is_class ( type-id )
e74392f0
PC
432 __is_empty ( type-id )
433 __is_enum ( type-id )
3c0d13bf 434 __is_literal_type ( type-id )
e74392f0
PC
435 __is_pod ( type-id )
436 __is_polymorphic ( type-id )
3c0d13bf
PC
437 __is_std_layout ( type-id )
438 __is_trivial ( type-id )
e74392f0 439 __is_union ( type-id ) */
b9b44fb9 440
7ecc2600
GDR
441void
442cxx_pretty_printer::primary_expression (tree t)
e1a4dd13 443{
4b780675
GDR
444 switch (TREE_CODE (t))
445 {
632f2871 446 case VOID_CST:
4b780675
GDR
447 case INTEGER_CST:
448 case REAL_CST:
7368348c 449 case COMPLEX_CST:
a176426f 450 case STRING_CST:
7ecc2600 451 constant (t);
4b780675
GDR
452 break;
453
3ce4f9e4 454 case USERDEF_LITERAL:
7ecc2600 455 pp_cxx_userdef_literal (this, t);
3ce4f9e4
ESR
456 break;
457
12ea3302
GDR
458 case BASELINK:
459 t = BASELINK_FUNCTIONS (t);
191816a3 460 /* FALLTHRU */
12ea3302
GDR
461 case VAR_DECL:
462 case PARM_DECL:
463 case FIELD_DECL:
464 case FUNCTION_DECL:
465 case OVERLOAD:
466 case CONST_DECL:
467 case TEMPLATE_DECL:
7ecc2600 468 id_expression (t);
12ea3302
GDR
469 break;
470
471 case RESULT_DECL:
472 case TEMPLATE_TYPE_PARM:
41fd3bac 473 case TEMPLATE_TEMPLATE_PARM:
12ea3302 474 case TEMPLATE_PARM_INDEX:
7ecc2600 475 pp_cxx_unqualified_id (this, t);
12ea3302
GDR
476 break;
477
c3e5898b 478 case STMT_EXPR:
7ecc2600 479 pp_cxx_left_paren (this);
8dc70667 480 statement (STMT_EXPR_STMT (t));
7ecc2600 481 pp_cxx_right_paren (this);
c3e5898b
ILT
482 break;
483
e74392f0 484 case TRAIT_EXPR:
7ecc2600 485 pp_cxx_trait_expression (this, t);
e74392f0
PC
486 break;
487
fdb8f418 488 case VA_ARG_EXPR:
7ecc2600 489 pp_cxx_va_arg_expression (this, t);
fdb8f418
PC
490 break;
491
094a5fe2 492 case OFFSETOF_EXPR:
7ecc2600 493 pp_cxx_offsetof_expression (this, t);
094a5fe2
JJ
494 break;
495
be845b04
JJ
496 case ADDRESSOF_EXPR:
497 pp_cxx_addressof_expression (this, t);
498 break;
499
971e17ff
AS
500 case REQUIRES_EXPR:
501 pp_cxx_requires_expr (this, t);
502 break;
503
4b780675 504 default:
7ecc2600 505 c_pretty_printer::primary_expression (t);
4b780675
GDR
506 break;
507 }
e1a4dd13
GDR
508}
509
4b780675
GDR
510/* postfix-expression:
511 primary-expression
512 postfix-expression [ expression ]
513 postfix-expression ( expression-list(opt) )
514 simple-type-specifier ( expression-list(opt) )
515 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
516 typename ::(opt) nested-name-specifier template(opt)
0cbd7506 517 template-id ( expression-list(opt) )
4b780675
GDR
518 postfix-expression . template(opt) ::(opt) id-expression
519 postfix-expression -> template(opt) ::(opt) id-expression
520 postfix-expression . pseudo-destructor-name
521 postfix-expression -> pseudo-destructor-name
522 postfix-expression ++
523 postfix-expression --
524 dynamic_cast < type-id > ( expression )
525 static_cast < type-id > ( expression )
526 reinterpret_cast < type-id > ( expression )
527 const_cast < type-id > ( expression )
528 typeid ( expression )
39a13be5 529 typeid ( type-id ) */
4b780675 530
fb22178f
GDR
531void
532cxx_pretty_printer::postfix_expression (tree t)
e1a4dd13 533{
4b780675 534 enum tree_code code = TREE_CODE (t);
c8094d83 535
4b780675
GDR
536 switch (code)
537 {
12ea3302
GDR
538 case AGGR_INIT_EXPR:
539 case CALL_EXPR:
540 {
babaa9df 541 tree fun = cp_get_callee (t);
fb22178f 542 tree saved_scope = enclosing_scope;
5039610b
SL
543 bool skipfirst = false;
544 tree arg;
0cbd7506
MS
545
546 if (TREE_CODE (fun) == ADDR_EXPR)
547 fun = TREE_OPERAND (fun, 0);
548
549 /* In templates, where there is no way to tell whether a given
550 call uses an actual member function. So the parser builds
551 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
552 instantiation time. */
553 if (TREE_CODE (fun) != FUNCTION_DECL)
554 ;
555 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun))
556 {
5039610b
SL
557 tree object = (code == AGGR_INIT_EXPR
558 ? (AGGR_INIT_VIA_CTOR_P (t)
559 ? AGGR_INIT_EXPR_SLOT (t)
560 : AGGR_INIT_EXPR_ARG (t, 0))
561 : CALL_EXPR_ARG (t, 0));
0cbd7506
MS
562
563 while (TREE_CODE (object) == NOP_EXPR)
564 object = TREE_OPERAND (object, 0);
565
566 if (TREE_CODE (object) == ADDR_EXPR)
567 object = TREE_OPERAND (object, 0);
568
50e10fa8 569 if (!TYPE_PTR_P (TREE_TYPE (object)))
0cbd7506 570 {
fb22178f
GDR
571 postfix_expression (object);
572 pp_cxx_dot (this);
0cbd7506
MS
573 }
574 else
575 {
fb22178f
GDR
576 postfix_expression (object);
577 pp_cxx_arrow (this);
0cbd7506 578 }
5039610b 579 skipfirst = true;
fb22178f 580 enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
0cbd7506
MS
581 }
582
fb22178f
GDR
583 postfix_expression (fun);
584 enclosing_scope = saved_scope;
585 pp_cxx_left_paren (this);
5039610b
SL
586 if (code == AGGR_INIT_EXPR)
587 {
588 aggr_init_expr_arg_iterator iter;
589 FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t)
590 {
591 if (skipfirst)
592 skipfirst = false;
593 else
594 {
00d34d3a 595 expression (arg);
5039610b 596 if (more_aggr_init_expr_args_p (&iter))
fb22178f 597 pp_cxx_separate_with (this, ',');
5039610b
SL
598 }
599 }
600 }
601 else
602 {
603 call_expr_arg_iterator iter;
604 FOR_EACH_CALL_EXPR_ARG (arg, iter, t)
605 {
606 if (skipfirst)
607 skipfirst = false;
608 else
609 {
00d34d3a 610 expression (arg);
5039610b 611 if (more_call_expr_args_p (&iter))
fb22178f 612 pp_cxx_separate_with (this, ',');
5039610b
SL
613 }
614 }
615 }
fb22178f 616 pp_cxx_right_paren (this);
12ea3302
GDR
617 }
618 if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
0cbd7506 619 {
fb22178f
GDR
620 pp_cxx_separate_with (this, ',');
621 postfix_expression (AGGR_INIT_EXPR_SLOT (t));
0cbd7506 622 }
12ea3302
GDR
623 break;
624
625 case BASELINK:
626 case VAR_DECL:
627 case PARM_DECL:
628 case FIELD_DECL:
629 case FUNCTION_DECL:
630 case OVERLOAD:
631 case CONST_DECL:
632 case TEMPLATE_DECL:
633 case RESULT_DECL:
fb22178f 634 primary_expression (t);
12ea3302
GDR
635 break;
636
4b780675
GDR
637 case DYNAMIC_CAST_EXPR:
638 case STATIC_CAST_EXPR:
639 case REINTERPRET_CAST_EXPR:
640 case CONST_CAST_EXPR:
641 if (code == DYNAMIC_CAST_EXPR)
fb22178f 642 pp_cxx_ws_string (this, "dynamic_cast");
4b780675 643 else if (code == STATIC_CAST_EXPR)
fb22178f 644 pp_cxx_ws_string (this, "static_cast");
4b780675 645 else if (code == REINTERPRET_CAST_EXPR)
fb22178f 646 pp_cxx_ws_string (this, "reinterpret_cast");
4b780675 647 else
fb22178f
GDR
648 pp_cxx_ws_string (this, "const_cast");
649 pp_cxx_begin_template_argument_list (this);
20059c8b 650 type_id (TREE_TYPE (t));
fb22178f
GDR
651 pp_cxx_end_template_argument_list (this);
652 pp_left_paren (this);
00d34d3a 653 expression (TREE_OPERAND (t, 0));
fb22178f 654 pp_right_paren (this);
4b780675
GDR
655 break;
656
657 case EMPTY_CLASS_EXPR:
20059c8b 658 type_id (TREE_TYPE (t));
fb22178f
GDR
659 pp_left_paren (this);
660 pp_right_paren (this);
4b780675
GDR
661 break;
662
663 case TYPEID_EXPR:
fb22178f 664 pp_cxx_typeid_expression (this, t);
4b780675
GDR
665 break;
666
667 case PSEUDO_DTOR_EXPR:
fb22178f
GDR
668 postfix_expression (TREE_OPERAND (t, 0));
669 pp_cxx_dot (this);
c0c66032
PC
670 if (TREE_OPERAND (t, 1))
671 {
672 pp_cxx_qualified_id (this, TREE_OPERAND (t, 1));
673 pp_cxx_colon_colon (this);
674 }
fb22178f
GDR
675 pp_complement (this);
676 pp_cxx_unqualified_id (this, TREE_OPERAND (t, 2));
4b780675
GDR
677 break;
678
03a08664 679 case ARROW_EXPR:
fb22178f
GDR
680 postfix_expression (TREE_OPERAND (t, 0));
681 pp_cxx_arrow (this);
03a08664
ILT
682 break;
683
4b780675 684 default:
fb22178f 685 c_pretty_printer::postfix_expression (t);
4b780675
GDR
686 break;
687 }
e1a4dd13
GDR
688}
689
4b780675
GDR
690/* new-expression:
691 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
692 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
693
694 new-placement:
695 ( expression-list )
696
697 new-type-id:
698 type-specifier-seq new-declarator(opt)
699
700 new-declarator:
701 ptr-operator new-declarator(opt)
702 direct-new-declarator
703
704 direct-new-declarator
705 [ expression ]
706 direct-new-declarator [ constant-expression ]
707
708 new-initializer:
709 ( expression-list(opt) ) */
b9b44fb9 710
e1a4dd13 711static void
4b780675 712pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
e1a4dd13 713{
4b780675 714 enum tree_code code = TREE_CODE (t);
a84a98ca
PC
715 tree type = TREE_OPERAND (t, 1);
716 tree init = TREE_OPERAND (t, 2);
4b780675
GDR
717 switch (code)
718 {
719 case NEW_EXPR:
720 case VEC_NEW_EXPR:
721 if (NEW_EXPR_USE_GLOBAL (t))
0cbd7506 722 pp_cxx_colon_colon (pp);
b02cec6e 723 pp_cxx_ws_string (pp, "new");
4b780675 724 if (TREE_OPERAND (t, 0))
0cbd7506
MS
725 {
726 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
727 pp_space (pp);
728 }
a84a98ca
PC
729 if (TREE_CODE (type) == ARRAY_REF)
730 type = build_cplus_array_type
731 (TREE_OPERAND (type, 0),
db3927fb
AH
732 build_index_type (fold_build2_loc (input_location,
733 MINUS_EXPR, integer_type_node,
a84a98ca
PC
734 TREE_OPERAND (type, 1),
735 integer_one_node)));
20059c8b 736 pp->type_id (type);
a84a98ca 737 if (init)
0cbd7506
MS
738 {
739 pp_left_paren (pp);
a84a98ca 740 if (TREE_CODE (init) == TREE_LIST)
b066401f 741 pp_c_expression_list (pp, init);
632f2871 742 else if (init == void_node)
0cbd7506
MS
743 ; /* OK, empty initializer list. */
744 else
20059c8b 745 pp->expression (init);
0cbd7506
MS
746 pp_right_paren (pp);
747 }
4b780675
GDR
748 break;
749
750 default:
751 pp_unsupported_tree (pp, t);
752 }
e1a4dd13
GDR
753}
754
4b780675
GDR
755/* delete-expression:
756 ::(opt) delete cast-expression
757 ::(opt) delete [ ] cast-expression */
b9b44fb9 758
066f956c 759static void
4b780675 760pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
e1a4dd13 761{
4b780675
GDR
762 enum tree_code code = TREE_CODE (t);
763 switch (code)
764 {
765 case DELETE_EXPR:
766 case VEC_DELETE_EXPR:
767 if (DELETE_EXPR_USE_GLOBAL (t))
0cbd7506 768 pp_cxx_colon_colon (pp);
b02cec6e 769 pp_cxx_ws_string (pp, "delete");
62081704
PC
770 pp_space (pp);
771 if (code == VEC_DELETE_EXPR
772 || DELETE_EXPR_USE_VEC (t))
0cbd7506
MS
773 {
774 pp_left_bracket (pp);
775 pp_right_bracket (pp);
62081704 776 pp_space (pp);
0cbd7506 777 }
b066401f 778 pp_c_cast_expression (pp, TREE_OPERAND (t, 0));
c8094d83
MS
779 break;
780
4b780675
GDR
781 default:
782 pp_unsupported_tree (pp, t);
783 }
e1a4dd13
GDR
784}
785
4b780675
GDR
786/* unary-expression:
787 postfix-expression
788 ++ cast-expression
789 -- cast-expression
790 unary-operator cast-expression
791 sizeof unary-expression
792 sizeof ( type-id )
5d80a306 793 sizeof ... ( identifier )
4b780675
GDR
794 new-expression
795 delete-expression
796
797 unary-operator: one of
798 * & + - !
799
800 GNU extensions:
801 __alignof__ unary-expression
802 __alignof__ ( type-id ) */
b9b44fb9 803
00d34d3a
GDR
804void
805cxx_pretty_printer::unary_expression (tree t)
e1a4dd13 806{
4b780675
GDR
807 enum tree_code code = TREE_CODE (t);
808 switch (code)
809 {
810 case NEW_EXPR:
811 case VEC_NEW_EXPR:
00d34d3a 812 pp_cxx_new_expression (this, t);
4b780675
GDR
813 break;
814
815 case DELETE_EXPR:
816 case VEC_DELETE_EXPR:
00d34d3a 817 pp_cxx_delete_expression (this, t);
4b780675 818 break;
c8094d83 819
03a08664 820 case SIZEOF_EXPR:
5d80a306
DG
821 if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
822 {
00d34d3a
GDR
823 pp_cxx_ws_string (this, "sizeof");
824 pp_cxx_ws_string (this, "...");
825 pp_cxx_whitespace (this);
826 pp_cxx_left_paren (this);
5d80a306 827 if (TYPE_P (TREE_OPERAND (t, 0)))
20059c8b 828 type_id (TREE_OPERAND (t, 0));
5d80a306 829 else
00d34d3a
GDR
830 unary_expression (TREE_OPERAND (t, 0));
831 pp_cxx_right_paren (this);
5d80a306
DG
832 break;
833 }
834 /* Fall through */
835
03a08664 836 case ALIGNOF_EXPR:
00d34d3a
GDR
837 pp_cxx_ws_string (this, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
838 pp_cxx_whitespace (this);
0d23cf7a
JJ
839 if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t))
840 {
00d34d3a 841 pp_cxx_left_paren (this);
20059c8b 842 type_id (TREE_TYPE (TREE_OPERAND (t, 0)));
00d34d3a 843 pp_cxx_right_paren (this);
0d23cf7a
JJ
844 }
845 else if (TYPE_P (TREE_OPERAND (t, 0)))
03a08664 846 {
00d34d3a 847 pp_cxx_left_paren (this);
20059c8b 848 type_id (TREE_OPERAND (t, 0));
00d34d3a 849 pp_cxx_right_paren (this);
03a08664
ILT
850 }
851 else
00d34d3a 852 unary_expression (TREE_OPERAND (t, 0));
03a08664
ILT
853 break;
854
c154b3d8 855 case AT_ENCODE_EXPR:
00d34d3a
GDR
856 pp_cxx_ws_string (this, "@encode");
857 pp_cxx_whitespace (this);
858 pp_cxx_left_paren (this);
20059c8b 859 type_id (TREE_OPERAND (t, 0));
00d34d3a 860 pp_cxx_right_paren (this);
c154b3d8
NP
861 break;
862
c56ba354 863 case NOEXCEPT_EXPR:
00d34d3a
GDR
864 pp_cxx_ws_string (this, "noexcept");
865 pp_cxx_whitespace (this);
866 pp_cxx_left_paren (this);
867 expression (TREE_OPERAND (t, 0));
868 pp_cxx_right_paren (this);
c56ba354
JM
869 break;
870
392e3d51 871 case UNARY_PLUS_EXPR:
00d34d3a
GDR
872 pp_plus (this);
873 pp_cxx_cast_expression (this, TREE_OPERAND (t, 0));
392e3d51
RS
874 break;
875
4b780675 876 default:
00d34d3a 877 c_pretty_printer::unary_expression (t);
4b780675
GDR
878 break;
879 }
e1a4dd13
GDR
880}
881
12ea3302
GDR
882/* cast-expression:
883 unary-expression
884 ( type-id ) cast-expression */
b9b44fb9 885
12ea3302
GDR
886static void
887pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
888{
889 switch (TREE_CODE (t))
890 {
891 case CAST_EXPR:
a4474a38 892 case IMPLICIT_CONV_EXPR:
20059c8b 893 pp->type_id (TREE_TYPE (t));
12ea3302
GDR
894 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
895 break;
896
897 default:
b066401f 898 pp_c_cast_expression (pp, t);
12ea3302
GDR
899 break;
900 }
901}
902
4b780675
GDR
903/* pm-expression:
904 cast-expression
905 pm-expression .* cast-expression
906 pm-expression ->* cast-expression */
b9b44fb9 907
e1a4dd13 908static void
4b780675 909pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t)
e1a4dd13 910{
4b780675
GDR
911 switch (TREE_CODE (t))
912 {
39a13be5 913 /* Handle unfortunate OFFSET_REF overloading here. */
4b780675
GDR
914 case OFFSET_REF:
915 if (TYPE_P (TREE_OPERAND (t, 0)))
0cbd7506
MS
916 {
917 pp_cxx_qualified_id (pp, t);
918 break;
919 }
191816a3 920 /* Fall through. */
4b780675
GDR
921 case MEMBER_REF:
922 case DOTSTAR_EXPR:
923 pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
1e3eacc7
JJ
924 if (TREE_CODE (t) == MEMBER_REF)
925 pp_cxx_arrow (pp);
926 else
927 pp_cxx_dot (pp);
4b780675 928 pp_star(pp);
12ea3302 929 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1));
4b780675
GDR
930 break;
931
932
933 default:
12ea3302 934 pp_cxx_cast_expression (pp, t);
4b780675
GDR
935 break;
936 }
e1a4dd13
GDR
937}
938
4b780675
GDR
939/* multiplicative-expression:
940 pm-expression
941 multiplicative-expression * pm-expression
942 multiplicative-expression / pm-expression
943 multiplicative-expression % pm-expression */
b9b44fb9 944
00d34d3a
GDR
945void
946cxx_pretty_printer::multiplicative_expression (tree e)
e1a4dd13 947{
4b780675
GDR
948 enum tree_code code = TREE_CODE (e);
949 switch (code)
950 {
951 case MULT_EXPR:
952 case TRUNC_DIV_EXPR:
953 case TRUNC_MOD_EXPR:
889a3a30
MP
954 case EXACT_DIV_EXPR:
955 case RDIV_EXPR:
00d34d3a
GDR
956 multiplicative_expression (TREE_OPERAND (e, 0));
957 pp_space (this);
4b780675 958 if (code == MULT_EXPR)
00d34d3a 959 pp_star (this);
889a3a30 960 else if (code != TRUNC_MOD_EXPR)
00d34d3a 961 pp_slash (this);
4b780675 962 else
00d34d3a
GDR
963 pp_modulo (this);
964 pp_space (this);
965 pp_cxx_pm_expression (this, TREE_OPERAND (e, 1));
4b780675
GDR
966 break;
967
968 default:
00d34d3a 969 pp_cxx_pm_expression (this, e);
4b780675
GDR
970 break;
971 }
e1a4dd13
GDR
972}
973
4b780675
GDR
974/* conditional-expression:
975 logical-or-expression
976 logical-or-expression ? expression : assignment-expression */
b9b44fb9 977
00d34d3a
GDR
978void
979cxx_pretty_printer::conditional_expression (tree e)
e1a4dd13 980{
4b780675
GDR
981 if (TREE_CODE (e) == COND_EXPR)
982 {
00d34d3a
GDR
983 pp_c_logical_or_expression (this, TREE_OPERAND (e, 0));
984 pp_space (this);
985 pp_question (this);
986 pp_space (this);
987 expression (TREE_OPERAND (e, 1));
988 pp_space (this);
989 assignment_expression (TREE_OPERAND (e, 2));
4b780675
GDR
990 }
991 else
00d34d3a 992 pp_c_logical_or_expression (this, e);
4b780675
GDR
993}
994
b9b44fb9
GDR
995/* Pretty-print a compound assignment operator token as indicated by T. */
996
12ea3302
GDR
997static void
998pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t)
999{
1000 const char *op;
1001
1002 switch (TREE_CODE (t))
1003 {
1004 case NOP_EXPR:
1005 op = "=";
1006 break;
1007
1008 case PLUS_EXPR:
1009 op = "+=";
1010 break;
1011
1012 case MINUS_EXPR:
1013 op = "-=";
1014 break;
1015
1016 case TRUNC_DIV_EXPR:
1017 op = "/=";
1018 break;
1019
1020 case TRUNC_MOD_EXPR:
1021 op = "%=";
1022 break;
1023
1024 default:
5806f481 1025 op = get_tree_code_name (TREE_CODE (t));
12ea3302
GDR
1026 break;
1027 }
1028
b02cec6e 1029 pp_cxx_ws_string (pp, op);
12ea3302
GDR
1030}
1031
1032
4b780675
GDR
1033/* assignment-expression:
1034 conditional-expression
1035 logical-or-expression assignment-operator assignment-expression
12ea3302
GDR
1036 throw-expression
1037
1038 throw-expression:
1039 throw assignment-expression(opt)
4b780675 1040
12ea3302 1041 assignment-operator: one of
4b780675 1042 = *= /= %= += -= >>= <<= &= ^= |= */
b9b44fb9 1043
00d34d3a
GDR
1044void
1045cxx_pretty_printer::assignment_expression (tree e)
4b780675 1046{
12ea3302 1047 switch (TREE_CODE (e))
4b780675 1048 {
12ea3302
GDR
1049 case MODIFY_EXPR:
1050 case INIT_EXPR:
00d34d3a
GDR
1051 pp_c_logical_or_expression (this, TREE_OPERAND (e, 0));
1052 pp_space (this);
1053 pp_equal (this);
1054 pp_space (this);
1055 assignment_expression (TREE_OPERAND (e, 1));
12ea3302 1056 break;
e1a4dd13 1057
12ea3302 1058 case THROW_EXPR:
00d34d3a 1059 pp_cxx_ws_string (this, "throw");
12ea3302 1060 if (TREE_OPERAND (e, 0))
00d34d3a 1061 assignment_expression (TREE_OPERAND (e, 0));
12ea3302 1062 break;
e1a4dd13 1063
12ea3302 1064 case MODOP_EXPR:
00d34d3a
GDR
1065 pp_c_logical_or_expression (this, TREE_OPERAND (e, 0));
1066 pp_cxx_assignment_operator (this, TREE_OPERAND (e, 1));
1067 assignment_expression (TREE_OPERAND (e, 2));
12ea3302 1068 break;
e1a4dd13 1069
12ea3302 1070 default:
00d34d3a 1071 conditional_expression (e);
12ea3302
GDR
1072 break;
1073 }
1074}
1075
00d34d3a
GDR
1076void
1077cxx_pretty_printer::expression (tree t)
12ea3302
GDR
1078{
1079 switch (TREE_CODE (t))
1080 {
1081 case STRING_CST:
632f2871 1082 case VOID_CST:
12ea3302
GDR
1083 case INTEGER_CST:
1084 case REAL_CST:
7368348c 1085 case COMPLEX_CST:
00d34d3a 1086 constant (t);
12ea3302
GDR
1087 break;
1088
3ce4f9e4 1089 case USERDEF_LITERAL:
00d34d3a 1090 pp_cxx_userdef_literal (this, t);
3ce4f9e4
ESR
1091 break;
1092
12ea3302 1093 case RESULT_DECL:
00d34d3a 1094 pp_cxx_unqualified_id (this, t);
12ea3302
GDR
1095 break;
1096
c8094d83 1097#if 0
12ea3302 1098 case OFFSET_REF:
c8094d83 1099#endif
12ea3302
GDR
1100 case SCOPE_REF:
1101 case PTRMEM_CST:
00d34d3a 1102 pp_cxx_qualified_id (this, t);
12ea3302
GDR
1103 break;
1104
1105 case OVERLOAD:
a736411a 1106 t = OVL_FIRST (t);
191816a3 1107 /* FALLTHRU */
12ea3302
GDR
1108 case VAR_DECL:
1109 case PARM_DECL:
1110 case FIELD_DECL:
1111 case CONST_DECL:
1112 case FUNCTION_DECL:
1113 case BASELINK:
1114 case TEMPLATE_DECL:
1115 case TEMPLATE_TYPE_PARM:
1116 case TEMPLATE_PARM_INDEX:
41fd3bac 1117 case TEMPLATE_TEMPLATE_PARM:
c3e5898b 1118 case STMT_EXPR:
971e17ff 1119 case REQUIRES_EXPR:
00d34d3a 1120 primary_expression (t);
12ea3302
GDR
1121 break;
1122
1123 case CALL_EXPR:
1124 case DYNAMIC_CAST_EXPR:
1125 case STATIC_CAST_EXPR:
1126 case REINTERPRET_CAST_EXPR:
1127 case CONST_CAST_EXPR:
c8094d83 1128#if 0
12ea3302 1129 case MEMBER_REF:
c8094d83 1130#endif
12ea3302
GDR
1131 case EMPTY_CLASS_EXPR:
1132 case TYPEID_EXPR:
1133 case PSEUDO_DTOR_EXPR:
1134 case AGGR_INIT_EXPR:
03a08664 1135 case ARROW_EXPR:
00d34d3a 1136 postfix_expression (t);
12ea3302
GDR
1137 break;
1138
1139 case NEW_EXPR:
1140 case VEC_NEW_EXPR:
00d34d3a 1141 pp_cxx_new_expression (this, t);
12ea3302
GDR
1142 break;
1143
1144 case DELETE_EXPR:
1145 case VEC_DELETE_EXPR:
00d34d3a 1146 pp_cxx_delete_expression (this, t);
12ea3302
GDR
1147 break;
1148
03a08664
ILT
1149 case SIZEOF_EXPR:
1150 case ALIGNOF_EXPR:
c56ba354 1151 case NOEXCEPT_EXPR:
c0ea338b 1152 case UNARY_PLUS_EXPR:
00d34d3a 1153 unary_expression (t);
03a08664
ILT
1154 break;
1155
12ea3302 1156 case CAST_EXPR:
a4474a38 1157 case IMPLICIT_CONV_EXPR:
00d34d3a 1158 pp_cxx_cast_expression (this, t);
12ea3302
GDR
1159 break;
1160
1161 case OFFSET_REF:
1162 case MEMBER_REF:
1163 case DOTSTAR_EXPR:
00d34d3a 1164 pp_cxx_pm_expression (this, t);
12ea3302
GDR
1165 break;
1166
1167 case MULT_EXPR:
1168 case TRUNC_DIV_EXPR:
1169 case TRUNC_MOD_EXPR:
889a3a30
MP
1170 case EXACT_DIV_EXPR:
1171 case RDIV_EXPR:
00d34d3a 1172 multiplicative_expression (t);
12ea3302
GDR
1173 break;
1174
1175 case COND_EXPR:
00d34d3a 1176 conditional_expression (t);
12ea3302
GDR
1177 break;
1178
1179 case MODIFY_EXPR:
1180 case INIT_EXPR:
1181 case THROW_EXPR:
1182 case MODOP_EXPR:
00d34d3a 1183 assignment_expression (t);
12ea3302
GDR
1184 break;
1185
b9b44fb9
GDR
1186 case NON_DEPENDENT_EXPR:
1187 case MUST_NOT_THROW_EXPR:
00d34d3a 1188 expression (TREE_OPERAND (t, 0));
b9b44fb9
GDR
1189 break;
1190
5d80a306 1191 case EXPR_PACK_EXPANSION:
00d34d3a
GDR
1192 expression (PACK_EXPANSION_PATTERN (t));
1193 pp_cxx_ws_string (this, "...");
5d80a306
DG
1194 break;
1195
f078dc7d
AS
1196 case UNARY_LEFT_FOLD_EXPR:
1197 pp_cxx_unary_left_fold_expression (this, t);
1198 break;
1199
1200 case UNARY_RIGHT_FOLD_EXPR:
1201 pp_cxx_unary_right_fold_expression (this, t);
1202 break;
1203
1204 case BINARY_LEFT_FOLD_EXPR:
1205 case BINARY_RIGHT_FOLD_EXPR:
1206 pp_cxx_binary_fold_expression (this, t);
1207 break;
1208
c7f06e13 1209 case TEMPLATE_ID_EXPR:
00d34d3a 1210 pp_cxx_template_id (this, t);
c7f06e13
PC
1211 break;
1212
5d80a306
DG
1213 case NONTYPE_ARGUMENT_PACK:
1214 {
1215 tree args = ARGUMENT_PACK_ARGS (t);
1216 int i, len = TREE_VEC_LENGTH (args);
1217 for (i = 0; i < len; ++i)
1218 {
1219 if (i > 0)
00d34d3a
GDR
1220 pp_cxx_separate_with (this, ',');
1221 expression (TREE_VEC_ELT (args, i));
5d80a306
DG
1222 }
1223 }
1224 break;
cb57504a 1225
f030a1dc 1226 case LAMBDA_EXPR:
00d34d3a 1227 pp_cxx_ws_string (this, "<lambda>");
f030a1dc 1228 break;
5d80a306 1229
971e17ff
AS
1230 case TRAIT_EXPR:
1231 pp_cxx_trait_expression (this, t);
1232 break;
1233
cb57504a 1234 case ATOMIC_CONSTR:
f078dc7d 1235 case CHECK_CONSTR:
971e17ff
AS
1236 case CONJ_CONSTR:
1237 case DISJ_CONSTR:
1238 pp_cxx_constraint (this, t);
1239 break;
1240
10c6dc8e 1241 case PAREN_EXPR:
00d34d3a
GDR
1242 pp_cxx_left_paren (this);
1243 expression (TREE_OPERAND (t, 0));
1244 pp_cxx_right_paren (this);
10c6dc8e
JM
1245 break;
1246
12ea3302 1247 default:
00d34d3a 1248 c_pretty_printer::expression (t);
c8094d83 1249 break;
12ea3302
GDR
1250 }
1251}
1252
1253
1254/* Declarations. */
1255
1256/* function-specifier:
1257 inline
1258 virtual
1259 explicit */
b9b44fb9 1260
8f0e4d72
GDR
1261void
1262cxx_pretty_printer::function_specifier (tree t)
12ea3302
GDR
1263{
1264 switch (TREE_CODE (t))
1265 {
1266 case FUNCTION_DECL:
1267 if (DECL_VIRTUAL_P (t))
8f0e4d72 1268 pp_cxx_ws_string (this, "virtual");
12ea3302 1269 else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
8f0e4d72 1270 pp_cxx_ws_string (this, "explicit");
12ea3302 1271 else
8f0e4d72 1272 c_pretty_printer::function_specifier (t);
12ea3302
GDR
1273
1274 default:
1275 break;
1276 }
1277}
1278
1279/* decl-specifier-seq:
1280 decl-specifier-seq(opt) decl-specifier
1281
1282 decl-specifier:
1283 storage-class-specifier
1284 type-specifier
1285 function-specifier
1286 friend
1287 typedef */
b9b44fb9 1288
8f0e4d72
GDR
1289void
1290cxx_pretty_printer::declaration_specifiers (tree t)
12ea3302
GDR
1291{
1292 switch (TREE_CODE (t))
1293 {
1294 case VAR_DECL:
1295 case PARM_DECL:
1296 case CONST_DECL:
1297 case FIELD_DECL:
20059c8b 1298 storage_class_specifier (t);
8f0e4d72 1299 declaration_specifiers (TREE_TYPE (t));
12ea3302 1300 break;
c8094d83 1301
12ea3302 1302 case TYPE_DECL:
8f0e4d72
GDR
1303 pp_cxx_ws_string (this, "typedef");
1304 declaration_specifiers (TREE_TYPE (t));
12ea3302
GDR
1305 break;
1306
12ea3302
GDR
1307 case FUNCTION_DECL:
1308 /* Constructors don't have return types. And conversion functions
0cbd7506 1309 do not have a type-specifier in their return types. */
12ea3302 1310 if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t))
8f0e4d72 1311 function_specifier (t);
12ea3302 1312 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
8f0e4d72 1313 declaration_specifiers (TREE_TYPE (TREE_TYPE (t)));
12ea3302 1314 else
191816a3
MP
1315 c_pretty_printer::declaration_specifiers (t);
1316 break;
1317 default:
8f0e4d72 1318 c_pretty_printer::declaration_specifiers (t);
12ea3302
GDR
1319 break;
1320 }
1321}
1322
1323/* simple-type-specifier:
1324 ::(opt) nested-name-specifier(opt) type-name
1325 ::(opt) nested-name-specifier(opt) template(opt) template-id
1326 char
1327 wchar_t
1328 bool
1329 short
1330 int
1331 long
1332 signed
1333 unsigned
1334 float
1335 double
1336 void */
b9b44fb9 1337
7c26172c
GDR
1338void
1339cxx_pretty_printer::simple_type_specifier (tree t)
12ea3302
GDR
1340{
1341 switch (TREE_CODE (t))
1342 {
1343 case RECORD_TYPE:
1344 case UNION_TYPE:
1345 case ENUMERAL_TYPE:
7c26172c 1346 pp_cxx_qualified_id (this, t);
12ea3302
GDR
1347 break;
1348
1349 case TEMPLATE_TYPE_PARM:
41fd3bac 1350 case TEMPLATE_TEMPLATE_PARM:
12ea3302 1351 case TEMPLATE_PARM_INDEX:
d1093817 1352 case BOUND_TEMPLATE_TEMPLATE_PARM:
7c26172c 1353 pp_cxx_unqualified_id (this, t);
cb57504a
JM
1354 if (tree c = PLACEHOLDER_TYPE_CONSTRAINTS (t))
1355 pp_cxx_constrained_type_spec (this, c);
12ea3302
GDR
1356 break;
1357
1358 case TYPENAME_TYPE:
7c26172c
GDR
1359 pp_cxx_ws_string (this, "typename");
1360 pp_cxx_nested_name_specifier (this, TYPE_CONTEXT (t));
1361 pp_cxx_unqualified_id (this, TYPE_NAME (t));
12ea3302
GDR
1362 break;
1363
1364 default:
7c26172c 1365 c_pretty_printer::simple_type_specifier (t);
12ea3302
GDR
1366 break;
1367 }
1368}
1369
1370/* type-specifier-seq:
1371 type-specifier type-specifier-seq(opt)
1372
1373 type-specifier:
1374 simple-type-specifier
1375 class-specifier
1376 enum-specifier
1377 elaborated-type-specifier
cd0be382 1378 cv-qualifier */
12ea3302
GDR
1379
1380static void
1381pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
1382{
12ea3302
GDR
1383 switch (TREE_CODE (t))
1384 {
1385 case TEMPLATE_DECL:
1386 case TEMPLATE_TYPE_PARM:
41fd3bac 1387 case TEMPLATE_TEMPLATE_PARM:
12ea3302
GDR
1388 case TYPE_DECL:
1389 case BOUND_TEMPLATE_TEMPLATE_PARM:
41fd3bac 1390 pp_cxx_cv_qualifier_seq (pp, t);
7c26172c 1391 pp->simple_type_specifier (t);
12ea3302
GDR
1392 break;
1393
1394 case METHOD_TYPE:
1395 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
1396 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1397 pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t));
1398 break;
1399
3ad6a8e1 1400 case DECLTYPE_TYPE:
b02cec6e 1401 pp_cxx_ws_string (pp, "decltype");
3ad6a8e1 1402 pp_cxx_left_paren (pp);
20059c8b 1403 pp->expression (DECLTYPE_TYPE_EXPR (t));
3ad6a8e1
DG
1404 pp_cxx_right_paren (pp);
1405 break;
1406
5cb6410a
JM
1407 case RECORD_TYPE:
1408 if (TYPE_PTRMEMFUNC_P (t))
1409 {
1410 tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t);
8f0e4d72 1411 pp->declaration_specifiers (TREE_TYPE (TREE_TYPE (pfm)));
5cb6410a
JM
1412 pp_cxx_whitespace (pp);
1413 pp_cxx_ptr_operator (pp, t);
1414 break;
1415 }
191816a3 1416 /* fall through */
5cb6410a 1417
12ea3302
GDR
1418 default:
1419 if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
b066401f 1420 pp_c_specifier_qualifier_list (pp, t);
12ea3302
GDR
1421 }
1422}
1423
1424/* ptr-operator:
1425 * cv-qualifier-seq(opt)
1426 &
1427 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1428
1429static void
1430pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
1431{
1432 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
1433 t = TREE_TYPE (t);
1434 switch (TREE_CODE (t))
1435 {
1436 case REFERENCE_TYPE:
1437 case POINTER_TYPE:
66b1156a 1438 if (TYPE_PTR_OR_PTRMEM_P (TREE_TYPE (t)))
0cbd7506 1439 pp_cxx_ptr_operator (pp, TREE_TYPE (t));
b066401f 1440 pp_c_attributes_display (pp, TYPE_ATTRIBUTES (TREE_TYPE (t)));
50e10fa8 1441 if (TYPE_PTR_P (t))
0cbd7506
MS
1442 {
1443 pp_star (pp);
1444 pp_cxx_cv_qualifier_seq (pp, t);
1445 }
12ea3302 1446 else
0cbd7506 1447 pp_ampersand (pp);
12ea3302
GDR
1448 break;
1449
1450 case RECORD_TYPE:
1451 if (TYPE_PTRMEMFUNC_P (t))
0cbd7506
MS
1452 {
1453 pp_cxx_left_paren (pp);
1454 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t));
1455 pp_star (pp);
1456 break;
1457 }
191816a3 1458 /* FALLTHRU */
12ea3302 1459 case OFFSET_TYPE:
66b1156a 1460 if (TYPE_PTRMEM_P (t))
0cbd7506
MS
1461 {
1462 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1463 pp_cxx_left_paren (pp);
1464 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t));
1465 pp_star (pp);
1466 pp_cxx_cv_qualifier_seq (pp, t);
1467 break;
1468 }
191816a3 1469 /* fall through. */
12ea3302
GDR
1470
1471 default:
1472 pp_unsupported_tree (pp, t);
1473 break;
1474 }
1475}
1476
1477static inline tree
1478pp_cxx_implicit_parameter_type (tree mf)
1479{
7e1352fe 1480 return class_of_this_parm (TREE_TYPE (mf));
12ea3302
GDR
1481}
1482
1483/*
1484 parameter-declaration:
1485 decl-specifier-seq declarator
1486 decl-specifier-seq declarator = assignment-expression
1487 decl-specifier-seq abstract-declarator(opt)
1488 decl-specifier-seq abstract-declarator(opt) assignment-expression */
b9b44fb9 1489
12ea3302
GDR
1490static inline void
1491pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
1492{
8f0e4d72 1493 pp->declaration_specifiers (t);
12ea3302 1494 if (TYPE_P (t))
20059c8b 1495 pp->abstract_declarator (t);
12ea3302 1496 else
20059c8b 1497 pp->declarator (t);
12ea3302
GDR
1498}
1499
1500/* parameter-declaration-clause:
1501 parameter-declaration-list(opt) ...(opt)
1502 parameter-declaration-list , ...
1503
1504 parameter-declaration-list:
1505 parameter-declaration
1506 parameter-declaration-list , parameter-declaration */
b9b44fb9 1507
12ea3302
GDR
1508static void
1509pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
1510{
971e17ff
AS
1511 tree args;
1512 tree types;
1513 bool abstract;
1514
1515 // For a requires clause or the explicit printing of a parameter list
1516 // we expect T to be a chain of PARM_DECLs. Otherwise, the list of
1517 // args and types are taken from the function decl T.
1518 if (TREE_CODE (t) == PARM_DECL)
1519 {
1520 args = t;
1521 types = t;
1522 abstract = false;
1523 }
1524 else
1525 {
1526 bool type_p = TYPE_P (t);
1527 args = type_p ? NULL : FUNCTION_FIRST_USER_PARM (t);
1528 types = type_p ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
1529 abstract = args == NULL || pp->flags & pp_c_flag_abstract;
1530 }
12ea3302
GDR
1531 bool first = true;
1532
1533 /* Skip artificial parameter for nonstatic member functions. */
1534 if (TREE_CODE (t) == METHOD_TYPE)
1535 types = TREE_CHAIN (types);
1536
1537 pp_cxx_left_paren (pp);
1538 for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
1539 {
1540 if (!first)
0cbd7506 1541 pp_cxx_separate_with (pp, ',');
12ea3302
GDR
1542 first = false;
1543 pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
b066401f 1544 if (!abstract && pp->flags & pp_cxx_flag_default_argument)
0cbd7506
MS
1545 {
1546 pp_cxx_whitespace (pp);
1547 pp_equal (pp);
1548 pp_cxx_whitespace (pp);
20059c8b 1549 pp->assignment_expression (TREE_PURPOSE (types));
0cbd7506 1550 }
12ea3302
GDR
1551 }
1552 pp_cxx_right_paren (pp);
1553}
1554
1555/* exception-specification:
1556 throw ( type-id-list(opt) )
1557
1558 type-id-list
1559 type-id
1560 type-id-list , type-id */
b9b44fb9 1561
12ea3302
GDR
1562static void
1563pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
1564{
1565 tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
5d80a306 1566 bool need_comma = false;
12ea3302 1567
3a55fb4c 1568 if (ex_spec == NULL)
12ea3302 1569 return;
3a55fb4c
JM
1570 if (TREE_PURPOSE (ex_spec))
1571 {
1572 pp_cxx_ws_string (pp, "noexcept");
1573 pp_cxx_whitespace (pp);
1574 pp_cxx_left_paren (pp);
10261728
JM
1575 if (DEFERRED_NOEXCEPT_SPEC_P (ex_spec))
1576 pp_cxx_ws_string (pp, "<uninstantiated>");
1577 else
20059c8b 1578 pp->expression (TREE_PURPOSE (ex_spec));
3a55fb4c
JM
1579 pp_cxx_right_paren (pp);
1580 return;
1581 }
b02cec6e 1582 pp_cxx_ws_string (pp, "throw");
12ea3302
GDR
1583 pp_cxx_left_paren (pp);
1584 for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
1585 {
5d80a306
DG
1586 tree type = TREE_VALUE (ex_spec);
1587 tree argpack = NULL_TREE;
1588 int i, len = 1;
1589
1590 if (ARGUMENT_PACK_P (type))
1591 {
1592 argpack = ARGUMENT_PACK_ARGS (type);
1593 len = TREE_VEC_LENGTH (argpack);
1594 }
1595
1596 for (i = 0; i < len; ++i)
1597 {
1598 if (argpack)
1599 type = TREE_VEC_ELT (argpack, i);
1600
1601 if (need_comma)
1602 pp_cxx_separate_with (pp, ',');
1603 else
1604 need_comma = true;
1605
20059c8b 1606 pp->type_id (type);
5d80a306 1607 }
12ea3302
GDR
1608 }
1609 pp_cxx_right_paren (pp);
1610}
1611
1612/* direct-declarator:
1613 declarator-id
1614 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
0cbd7506 1615 exception-specification(opt)
12ea3302
GDR
1616 direct-declaration [ constant-expression(opt) ]
1617 ( declarator ) */
b9b44fb9 1618
8f0e4d72
GDR
1619void
1620cxx_pretty_printer::direct_declarator (tree t)
12ea3302
GDR
1621{
1622 switch (TREE_CODE (t))
1623 {
1624 case VAR_DECL:
1625 case PARM_DECL:
1626 case CONST_DECL:
1627 case FIELD_DECL:
1628 if (DECL_NAME (t))
0cbd7506 1629 {
8f0e4d72 1630 pp_cxx_space_for_pointer_operator (this, TREE_TYPE (t));
5d80a306 1631
73f4e2d2 1632 if ((TREE_CODE (t) == PARM_DECL && DECL_PACK_P (t))
5d80a306
DG
1633 || template_parameter_pack_p (t))
1634 /* A function parameter pack or non-type template
1635 parameter pack. */
8f0e4d72 1636 pp_cxx_ws_string (this, "...");
5d80a306 1637
8f0e4d72 1638 id_expression (DECL_NAME (t));
0cbd7506 1639 }
8f0e4d72 1640 abstract_declarator (TREE_TYPE (t));
12ea3302 1641 break;
c8094d83 1642
12ea3302 1643 case FUNCTION_DECL:
8f0e4d72
GDR
1644 pp_cxx_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t)));
1645 expression (t);
1646 pp_cxx_parameter_declaration_clause (this, t);
c8094d83 1647
12ea3302 1648 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
0cbd7506 1649 {
8f0e4d72
GDR
1650 padding = pp_before;
1651 pp_cxx_cv_qualifier_seq (this, pp_cxx_implicit_parameter_type (t));
0cbd7506 1652 }
12ea3302 1653
8f0e4d72 1654 pp_cxx_exception_specification (this, TREE_TYPE (t));
12ea3302
GDR
1655 break;
1656
1657 case TYPENAME_TYPE:
1658 case TEMPLATE_DECL:
1659 case TEMPLATE_TYPE_PARM:
1660 case TEMPLATE_PARM_INDEX:
41fd3bac 1661 case TEMPLATE_TEMPLATE_PARM:
12ea3302
GDR
1662 break;
1663
1664 default:
8f0e4d72 1665 c_pretty_printer::direct_declarator (t);
12ea3302
GDR
1666 break;
1667 }
1668}
1669
1670/* declarator:
1671 direct-declarator
1672 ptr-operator declarator */
b9b44fb9 1673
8f0e4d72
GDR
1674void
1675cxx_pretty_printer::declarator (tree t)
12ea3302 1676{
8f0e4d72 1677 direct_declarator (t);
971e17ff
AS
1678
1679 // Print a requires clause.
1680 if (flag_concepts)
1681 if (tree ci = get_constraints (t))
1682 if (tree reqs = CI_DECLARATOR_REQS (ci))
1683 pp_cxx_requires_clause (this, reqs);
12ea3302
GDR
1684}
1685
1686/* ctor-initializer:
1687 : mem-initializer-list
1688
1689 mem-initializer-list:
1690 mem-initializer
1691 mem-initializer , mem-initializer-list
1692
1693 mem-initializer:
1694 mem-initializer-id ( expression-list(opt) )
1695
1696 mem-initializer-id:
1697 ::(opt) nested-name-specifier(opt) class-name
1698 identifier */
b9b44fb9 1699
12ea3302
GDR
1700static void
1701pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
1702{
1703 t = TREE_OPERAND (t, 0);
1704 pp_cxx_whitespace (pp);
1705 pp_colon (pp);
1706 pp_cxx_whitespace (pp);
1707 for (; t; t = TREE_CHAIN (t))
1708 {
5d80a306
DG
1709 tree purpose = TREE_PURPOSE (t);
1710 bool is_pack = PACK_EXPANSION_P (purpose);
1711
1712 if (is_pack)
20059c8b 1713 pp->primary_expression (PACK_EXPANSION_PATTERN (purpose));
5d80a306 1714 else
20059c8b 1715 pp->primary_expression (purpose);
12ea3302 1716 pp_cxx_call_argument_list (pp, TREE_VALUE (t));
5d80a306 1717 if (is_pack)
b02cec6e 1718 pp_cxx_ws_string (pp, "...");
12ea3302 1719 if (TREE_CHAIN (t))
0cbd7506 1720 pp_cxx_separate_with (pp, ',');
12ea3302
GDR
1721 }
1722}
1723
1724/* function-definition:
1725 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1726 decl-specifier-seq(opt) declarator function-try-block */
1727
b01150a2 1728static void
12ea3302
GDR
1729pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
1730{
1731 tree saved_scope = pp->enclosing_scope;
8f0e4d72 1732 pp->declaration_specifiers (t);
20059c8b 1733 pp->declarator (t);
12ea3302
GDR
1734 pp_needs_newline (pp) = true;
1735 pp->enclosing_scope = DECL_CONTEXT (t);
1736 if (DECL_SAVED_TREE (t))
8dc70667 1737 pp->statement (DECL_SAVED_TREE (t));
12ea3302 1738 else
f8923f7e
SB
1739 pp_cxx_semicolon (pp);
1740 pp_newline_and_flush (pp);
12ea3302
GDR
1741 pp->enclosing_scope = saved_scope;
1742}
1743
1744/* abstract-declarator:
1745 ptr-operator abstract-declarator(opt)
1746 direct-abstract-declarator */
b9b44fb9 1747
8f0e4d72
GDR
1748void
1749cxx_pretty_printer::abstract_declarator (tree t)
12ea3302 1750{
66b1156a 1751 if (TYPE_PTRMEM_P (t))
8f0e4d72 1752 pp_cxx_right_paren (this);
71a93b08 1753 else if (INDIRECT_TYPE_P (t))
12ea3302
GDR
1754 {
1755 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
0cbd7506 1756 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
8f0e4d72 1757 pp_cxx_right_paren (this);
12ea3302
GDR
1758 t = TREE_TYPE (t);
1759 }
8f0e4d72 1760 direct_abstract_declarator (t);
12ea3302
GDR
1761}
1762
1763/* direct-abstract-declarator:
1764 direct-abstract-declarator(opt) ( parameter-declaration-clause )
0cbd7506 1765 cv-qualifier-seq(opt) exception-specification(opt)
12ea3302
GDR
1766 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1767 ( abstract-declarator ) */
b9b44fb9 1768
8f0e4d72
GDR
1769void
1770cxx_pretty_printer::direct_abstract_declarator (tree t)
12ea3302
GDR
1771{
1772 switch (TREE_CODE (t))
1773 {
1774 case REFERENCE_TYPE:
8f0e4d72 1775 abstract_declarator (t);
12ea3302
GDR
1776 break;
1777
1778 case RECORD_TYPE:
1779 if (TYPE_PTRMEMFUNC_P (t))
8f0e4d72 1780 direct_abstract_declarator (TYPE_PTRMEMFUNC_FN_TYPE (t));
12ea3302
GDR
1781 break;
1782
1783 case METHOD_TYPE:
1784 case FUNCTION_TYPE:
8f0e4d72
GDR
1785 pp_cxx_parameter_declaration_clause (this, t);
1786 direct_abstract_declarator (TREE_TYPE (t));
12ea3302 1787 if (TREE_CODE (t) == METHOD_TYPE)
0cbd7506 1788 {
8f0e4d72
GDR
1789 padding = pp_before;
1790 pp_cxx_cv_qualifier_seq (this, class_of_this_parm (t));
0cbd7506 1791 }
8f0e4d72 1792 pp_cxx_exception_specification (this, t);
12ea3302
GDR
1793 break;
1794
1795 case TYPENAME_TYPE:
1796 case TEMPLATE_TYPE_PARM:
1797 case TEMPLATE_TEMPLATE_PARM:
1798 case BOUND_TEMPLATE_TEMPLATE_PARM:
1799 case UNBOUND_CLASS_TEMPLATE:
1800 break;
1801
1802 default:
8f0e4d72 1803 c_pretty_printer::direct_abstract_declarator (t);
c8094d83 1804 break;
12ea3302
GDR
1805 }
1806}
1807
1808/* type-id:
1809 type-specifier-seq abstract-declarator(opt) */
b9b44fb9 1810
20059c8b
GDR
1811void
1812cxx_pretty_printer::type_id (tree t)
12ea3302 1813{
20059c8b
GDR
1814 pp_flags saved_flags = flags;
1815 flags |= pp_c_flag_abstract;
12ea3302
GDR
1816
1817 switch (TREE_CODE (t))
1818 {
1819 case TYPE_DECL:
1820 case UNION_TYPE:
1821 case RECORD_TYPE:
1822 case ENUMERAL_TYPE:
1823 case TYPENAME_TYPE:
1824 case BOUND_TEMPLATE_TEMPLATE_PARM:
1825 case UNBOUND_CLASS_TEMPLATE:
1826 case TEMPLATE_TEMPLATE_PARM:
1827 case TEMPLATE_TYPE_PARM:
1828 case TEMPLATE_PARM_INDEX:
1829 case TEMPLATE_DECL:
1830 case TYPEOF_TYPE:
a0d260fc 1831 case UNDERLYING_TYPE:
3ad6a8e1 1832 case DECLTYPE_TYPE:
12ea3302 1833 case TEMPLATE_ID_EXPR:
20059c8b 1834 pp_cxx_type_specifier_seq (this, t);
12ea3302
GDR
1835 break;
1836
5d80a306 1837 case TYPE_PACK_EXPANSION:
20059c8b
GDR
1838 type_id (PACK_EXPANSION_PATTERN (t));
1839 pp_cxx_ws_string (this, "...");
5d80a306
DG
1840 break;
1841
12ea3302 1842 default:
20059c8b 1843 c_pretty_printer::type_id (t);
12ea3302
GDR
1844 break;
1845 }
1846
20059c8b 1847 flags = saved_flags;
12ea3302
GDR
1848}
1849
1850/* template-argument-list:
5d80a306
DG
1851 template-argument ...(opt)
1852 template-argument-list, template-argument ...(opt)
12ea3302
GDR
1853
1854 template-argument:
1855 assignment-expression
1856 type-id
5d80a306 1857 template-name */
b9b44fb9 1858
12ea3302
GDR
1859static void
1860pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
1861{
1862 int i;
5d80a306
DG
1863 bool need_comma = false;
1864
12ea3302
GDR
1865 if (t == NULL)
1866 return;
1867 for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
1868 {
1869 tree arg = TREE_VEC_ELT (t, i);
5d80a306
DG
1870 tree argpack = NULL_TREE;
1871 int idx, len = 1;
1872
1873 if (ARGUMENT_PACK_P (arg))
1874 {
1875 argpack = ARGUMENT_PACK_ARGS (arg);
1876 len = TREE_VEC_LENGTH (argpack);
1877 }
1878
1879 for (idx = 0; idx < len; idx++)
1880 {
1881 if (argpack)
1882 arg = TREE_VEC_ELT (argpack, idx);
cb57504a 1883
5d80a306
DG
1884 if (need_comma)
1885 pp_cxx_separate_with (pp, ',');
1886 else
1887 need_comma = true;
1888
1889 if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
1890 && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
20059c8b 1891 pp->type_id (arg);
5d80a306 1892 else
20059c8b 1893 pp->expression (arg);
5d80a306 1894 }
12ea3302
GDR
1895 }
1896}
1897
1898
1899static void
1900pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
1901{
350fae66 1902 t = DECL_EXPR_DECL (t);
12ea3302
GDR
1903 pp_cxx_type_specifier_seq (pp, t);
1904 if (TYPE_P (t))
20059c8b 1905 pp->abstract_declarator (t);
12ea3302 1906 else
20059c8b 1907 pp->declarator (t);
12ea3302
GDR
1908}
1909
1910/* Statements. */
1911
8dc70667
GDR
1912void
1913cxx_pretty_printer::statement (tree t)
12ea3302
GDR
1914{
1915 switch (TREE_CODE (t))
1916 {
5882f0f3 1917 case CTOR_INITIALIZER:
8dc70667 1918 pp_cxx_ctor_initializer (this, t);
5882f0f3
RH
1919 break;
1920
12ea3302 1921 case USING_STMT:
8dc70667
GDR
1922 pp_cxx_ws_string (this, "using");
1923 pp_cxx_ws_string (this, "namespace");
91b1ca65 1924 if (DECL_CONTEXT (t))
8dc70667
GDR
1925 pp_cxx_nested_name_specifier (this, DECL_CONTEXT (t));
1926 pp_cxx_qualified_id (this, USING_STMT_NAMESPACE (t));
12ea3302
GDR
1927 break;
1928
1929 case USING_DECL:
8dc70667
GDR
1930 pp_cxx_ws_string (this, "using");
1931 pp_cxx_nested_name_specifier (this, USING_DECL_SCOPE (t));
1932 pp_cxx_unqualified_id (this, DECL_NAME (t));
12ea3302
GDR
1933 break;
1934
1935 case EH_SPEC_BLOCK:
1936 break;
1937
1938 /* try-block:
0cbd7506 1939 try compound-statement handler-seq */
12ea3302 1940 case TRY_BLOCK:
8dc70667
GDR
1941 pp_maybe_newline_and_indent (this, 0);
1942 pp_cxx_ws_string (this, "try");
1943 pp_newline_and_indent (this, 3);
1944 statement (TRY_STMTS (t));
1945 pp_newline_and_indent (this, -3);
12ea3302 1946 if (CLEANUP_P (t))
0cbd7506 1947 ;
12ea3302 1948 else
8dc70667 1949 statement (TRY_HANDLERS (t));
12ea3302
GDR
1950 break;
1951
1952 /*
0cbd7506
MS
1953 handler-seq:
1954 handler handler-seq(opt)
12ea3302 1955
0cbd7506
MS
1956 handler:
1957 catch ( exception-declaration ) compound-statement
12ea3302 1958
0cbd7506
MS
1959 exception-declaration:
1960 type-specifier-seq declarator
1961 type-specifier-seq abstract-declarator
1962 ... */
12ea3302 1963 case HANDLER:
8dc70667
GDR
1964 pp_cxx_ws_string (this, "catch");
1965 pp_cxx_left_paren (this);
1966 pp_cxx_exception_declaration (this, HANDLER_PARMS (t));
1967 pp_cxx_right_paren (this);
1968 pp_indentation (this) += 3;
1969 pp_needs_newline (this) = true;
1970 statement (HANDLER_BODY (t));
1971 pp_indentation (this) -= 3;
1972 pp_needs_newline (this) = true;
12ea3302
GDR
1973 break;
1974
5a508662 1975 /* selection-statement:
0cbd7506
MS
1976 if ( expression ) statement
1977 if ( expression ) statement else statement */
5a508662 1978 case IF_STMT:
8dc70667
GDR
1979 pp_cxx_ws_string (this, "if");
1980 pp_cxx_whitespace (this);
1981 pp_cxx_left_paren (this);
20059c8b 1982 expression (IF_COND (t));
8dc70667
GDR
1983 pp_cxx_right_paren (this);
1984 pp_newline_and_indent (this, 2);
1985 statement (THEN_CLAUSE (t));
1986 pp_newline_and_indent (this, -2);
5a508662
RH
1987 if (ELSE_CLAUSE (t))
1988 {
1989 tree else_clause = ELSE_CLAUSE (t);
8dc70667 1990 pp_cxx_ws_string (this, "else");
5a508662 1991 if (TREE_CODE (else_clause) == IF_STMT)
8dc70667 1992 pp_cxx_whitespace (this);
5a508662 1993 else
8dc70667
GDR
1994 pp_newline_and_indent (this, 2);
1995 statement (else_clause);
5a508662 1996 if (TREE_CODE (else_clause) != IF_STMT)
8dc70667 1997 pp_newline_and_indent (this, -2);
5a508662
RH
1998 }
1999 break;
2000
fbc315db 2001 case SWITCH_STMT:
8dc70667
GDR
2002 pp_cxx_ws_string (this, "switch");
2003 pp_space (this);
2004 pp_cxx_left_paren (this);
20059c8b 2005 expression (SWITCH_STMT_COND (t));
8dc70667
GDR
2006 pp_cxx_right_paren (this);
2007 pp_indentation (this) += 3;
2008 pp_needs_newline (this) = true;
2009 statement (SWITCH_STMT_BODY (t));
2010 pp_newline_and_indent (this, -3);
fbc315db
ILT
2011 break;
2012
2013 /* iteration-statement:
0cbd7506
MS
2014 while ( expression ) statement
2015 do statement while ( expression ) ;
2016 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
2017 for ( declaration expression(opt) ; expression(opt) ) statement */
fbc315db 2018 case WHILE_STMT:
8dc70667
GDR
2019 pp_cxx_ws_string (this, "while");
2020 pp_space (this);
2021 pp_cxx_left_paren (this);
20059c8b 2022 expression (WHILE_COND (t));
8dc70667
GDR
2023 pp_cxx_right_paren (this);
2024 pp_newline_and_indent (this, 3);
2025 statement (WHILE_BODY (t));
2026 pp_indentation (this) -= 3;
2027 pp_needs_newline (this) = true;
fbc315db
ILT
2028 break;
2029
2030 case DO_STMT:
8dc70667
GDR
2031 pp_cxx_ws_string (this, "do");
2032 pp_newline_and_indent (this, 3);
2033 statement (DO_BODY (t));
2034 pp_newline_and_indent (this, -3);
2035 pp_cxx_ws_string (this, "while");
2036 pp_space (this);
2037 pp_cxx_left_paren (this);
20059c8b 2038 expression (DO_COND (t));
8dc70667
GDR
2039 pp_cxx_right_paren (this);
2040 pp_cxx_semicolon (this);
2041 pp_needs_newline (this) = true;
fbc315db
ILT
2042 break;
2043
2044 case FOR_STMT:
8dc70667
GDR
2045 pp_cxx_ws_string (this, "for");
2046 pp_space (this);
2047 pp_cxx_left_paren (this);
fbc315db 2048 if (FOR_INIT_STMT (t))
8dc70667 2049 statement (FOR_INIT_STMT (t));
fbc315db 2050 else
8dc70667
GDR
2051 pp_cxx_semicolon (this);
2052 pp_needs_newline (this) = false;
2053 pp_cxx_whitespace (this);
fbc315db 2054 if (FOR_COND (t))
20059c8b 2055 expression (FOR_COND (t));
8dc70667
GDR
2056 pp_cxx_semicolon (this);
2057 pp_needs_newline (this) = false;
2058 pp_cxx_whitespace (this);
fbc315db 2059 if (FOR_EXPR (t))
20059c8b 2060 expression (FOR_EXPR (t));
8dc70667
GDR
2061 pp_cxx_right_paren (this);
2062 pp_newline_and_indent (this, 3);
2063 statement (FOR_BODY (t));
2064 pp_indentation (this) -= 3;
2065 pp_needs_newline (this) = true;
f9132eb7
RRC
2066 break;
2067
2068 case RANGE_FOR_STMT:
8dc70667
GDR
2069 pp_cxx_ws_string (this, "for");
2070 pp_space (this);
2071 pp_cxx_left_paren (this);
61856507
MP
2072 if (RANGE_FOR_INIT_STMT (t))
2073 {
2074 statement (RANGE_FOR_INIT_STMT (t));
2075 pp_needs_newline (this) = false;
2076 pp_cxx_whitespace (this);
2077 }
8dc70667
GDR
2078 statement (RANGE_FOR_DECL (t));
2079 pp_space (this);
2080 pp_needs_newline (this) = false;
2081 pp_colon (this);
2082 pp_space (this);
2083 statement (RANGE_FOR_EXPR (t));
2084 pp_cxx_right_paren (this);
2085 pp_newline_and_indent (this, 3);
2086 statement (FOR_BODY (t));
2087 pp_indentation (this) -= 3;
2088 pp_needs_newline (this) = true;
fbc315db
ILT
2089 break;
2090
2091 /* jump-statement:
0cbd7506
MS
2092 goto identifier;
2093 continue ;
2094 return expression(opt) ; */
fbc315db
ILT
2095 case BREAK_STMT:
2096 case CONTINUE_STMT:
8dc70667
GDR
2097 pp_string (this, TREE_CODE (t) == BREAK_STMT ? "break" : "continue");
2098 pp_cxx_semicolon (this);
2099 pp_needs_newline (this) = true;
fbc315db
ILT
2100 break;
2101
934790cc 2102 /* expression-statement:
0cbd7506 2103 expression(opt) ; */
934790cc 2104 case EXPR_STMT:
20059c8b 2105 expression (EXPR_STMT_EXPR (t));
8dc70667
GDR
2106 pp_cxx_semicolon (this);
2107 pp_needs_newline (this) = true;
934790cc
ILT
2108 break;
2109
5a508662 2110 case CLEANUP_STMT:
8dc70667
GDR
2111 pp_cxx_ws_string (this, "try");
2112 pp_newline_and_indent (this, 2);
2113 statement (CLEANUP_BODY (t));
2114 pp_newline_and_indent (this, -2);
2115 pp_cxx_ws_string (this, CLEANUP_EH_ONLY (t) ? "catch" : "finally");
2116 pp_newline_and_indent (this, 2);
2117 statement (CLEANUP_EXPR (t));
2118 pp_newline_and_indent (this, -2);
5a508662
RH
2119 break;
2120
55a3debe 2121 case STATIC_ASSERT:
8f0e4d72 2122 declaration (t);
55a3debe
DG
2123 break;
2124
28567c40
JJ
2125 case OMP_DEPOBJ:
2126 pp_cxx_ws_string (this, "#pragma omp depobj");
2127 pp_space (this);
2128 pp_cxx_left_paren (this);
2129 expression (OMP_DEPOBJ_DEPOBJ (t));
2130 pp_cxx_right_paren (this);
2131 if (OMP_DEPOBJ_CLAUSES (t) && OMP_DEPOBJ_CLAUSES (t) != error_mark_node)
2132 {
2133 if (TREE_CODE (OMP_DEPOBJ_CLAUSES (t)) == OMP_CLAUSE)
2134 dump_omp_clauses (this, OMP_DEPOBJ_CLAUSES (t),
2135 pp_indentation (this), TDF_NONE);
2136 else
2137 switch (tree_to_uhwi (OMP_DEPOBJ_CLAUSES (t)))
2138 {
2139 case OMP_CLAUSE_DEPEND_IN:
2140 pp_cxx_ws_string (this, " update(in)");
2141 break;
2142 case OMP_CLAUSE_DEPEND_INOUT:
2143 pp_cxx_ws_string (this, " update(inout)");
2144 break;
2145 case OMP_CLAUSE_DEPEND_OUT:
2146 pp_cxx_ws_string (this, " update(out)");
2147 break;
2148 case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
2149 pp_cxx_ws_string (this, " update(mutexinoutset)");
2150 break;
2151 case OMP_CLAUSE_DEPEND_LAST:
2152 pp_cxx_ws_string (this, " destroy");
2153 break;
2154 default:
2155 break;
2156 }
2157 }
2158 pp_needs_newline (this) = true;
2159 break;
2160
12ea3302 2161 default:
8dc70667 2162 c_pretty_printer::statement (t);
12ea3302
GDR
2163 break;
2164 }
2165}
2166
a2a9e21c
GDR
2167/* original-namespace-definition:
2168 namespace identifier { namespace-body }
2169
2170 As an edge case, we also handle unnamed namespace definition here. */
2171
2172static void
2173pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t)
2174{
b02cec6e 2175 pp_cxx_ws_string (pp, "namespace");
91b1ca65
MM
2176 if (DECL_CONTEXT (t))
2177 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
ed36980c 2178 if (DECL_NAME (t))
a2a9e21c
GDR
2179 pp_cxx_unqualified_id (pp, t);
2180 pp_cxx_whitespace (pp);
2181 pp_cxx_left_brace (pp);
2182 /* We do not print the namespace-body. */
2183 pp_cxx_whitespace (pp);
2184 pp_cxx_right_brace (pp);
2185}
2186
2187/* namespace-alias:
2188 identifier
2189
2190 namespace-alias-definition:
2191 namespace identifier = qualified-namespace-specifier ;
2192
2193 qualified-namespace-specifier:
2194 ::(opt) nested-name-specifier(opt) namespace-name */
2195
2196static void
2197pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t)
2198{
b02cec6e 2199 pp_cxx_ws_string (pp, "namespace");
91b1ca65
MM
2200 if (DECL_CONTEXT (t))
2201 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
a2a9e21c
GDR
2202 pp_cxx_unqualified_id (pp, t);
2203 pp_cxx_whitespace (pp);
2204 pp_equal (pp);
2205 pp_cxx_whitespace (pp);
91b1ca65 2206 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)))
3db45ab5 2207 pp_cxx_nested_name_specifier (pp,
91b1ca65 2208 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)));
a2a9e21c
GDR
2209 pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t));
2210 pp_cxx_semicolon (pp);
2211}
2212
12ea3302
GDR
2213/* simple-declaration:
2214 decl-specifier-seq(opt) init-declarator-list(opt) */
b9b44fb9 2215
12ea3302
GDR
2216static void
2217pp_cxx_simple_declaration (cxx_pretty_printer *pp, tree t)
2218{
8f0e4d72 2219 pp->declaration_specifiers (t);
12ea3302
GDR
2220 pp_cxx_init_declarator (pp, t);
2221 pp_cxx_semicolon (pp);
2222 pp_needs_newline (pp) = true;
2223}
2224
2225/*
2226 template-parameter-list:
2227 template-parameter
2228 template-parameter-list , template-parameter */
2229
2230static inline void
2231pp_cxx_template_parameter_list (cxx_pretty_printer *pp, tree t)
2232{
2233 const int n = TREE_VEC_LENGTH (t);
2234 int i;
2235 for (i = 0; i < n; ++i)
2236 {
2237 if (i)
0cbd7506 2238 pp_cxx_separate_with (pp, ',');
12ea3302
GDR
2239 pp_cxx_template_parameter (pp, TREE_VEC_ELT (t, i));
2240 }
2241}
2242
2243/* template-parameter:
2244 type-parameter
2245 parameter-declaration
2246
2247 type-parameter:
5d80a306
DG
2248 class ...(opt) identifier(opt)
2249 class identifier(opt) = type-id
12ea3302 2250 typename identifier(opt)
5d80a306
DG
2251 typename ...(opt) identifier(opt) = type-id
2252 template < template-parameter-list > class ...(opt) identifier(opt)
3db45ab5 2253 template < template-parameter-list > class identifier(opt) = template-name */
b9b44fb9 2254
12ea3302
GDR
2255static void
2256pp_cxx_template_parameter (cxx_pretty_printer *pp, tree t)
2257{
2258 tree parameter = TREE_VALUE (t);
2259 switch (TREE_CODE (parameter))
2260 {
2261 case TYPE_DECL:
b02cec6e 2262 pp_cxx_ws_string (pp, "class");
5d80a306 2263 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t)))
b02cec6e 2264 pp_cxx_ws_string (pp, "...");
12ea3302 2265 if (DECL_NAME (parameter))
0cbd7506 2266 pp_cxx_tree_identifier (pp, DECL_NAME (parameter));
39a13be5 2267 /* FIXME: Check if we should print also default argument. */
12ea3302
GDR
2268 break;
2269
2270 case PARM_DECL:
2271 pp_cxx_parameter_declaration (pp, parameter);
2272 break;
2273
2274 case TEMPLATE_DECL:
2275 break;
2276
2277 default:
2278 pp_unsupported_tree (pp, t);
2279 break;
2280 }
2281}
2282
b2517173
GDR
2283/* Pretty-print a template parameter in the canonical form
2284 "template-parameter-<level>-<position in parameter list>". */
2285
2286void
2287pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm)
2288{
2289 const enum tree_code code = TREE_CODE (parm);
2290
04c06002 2291 /* Brings type template parameters to the canonical forms. */
b2517173
GDR
2292 if (code == TEMPLATE_TYPE_PARM || code == TEMPLATE_TEMPLATE_PARM
2293 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
2294 parm = TEMPLATE_TYPE_PARM_INDEX (parm);
c8094d83 2295
b2517173 2296 pp_cxx_begin_template_argument_list (pp);
0691175f 2297 pp->translate_string ("template-parameter-");
b2517173
GDR
2298 pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm));
2299 pp_minus (pp);
2300 pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1);
2301 pp_cxx_end_template_argument_list (pp);
2302}
2303
4fea442d
JM
2304/* Print a constrained-type-specifier. */
2305
2306void
2307pp_cxx_constrained_type_spec (cxx_pretty_printer *pp, tree c)
2308{
cb57504a
JM
2309 pp_cxx_whitespace (pp);
2310 pp_cxx_left_bracket (pp);
2311 pp->translate_string ("requires");
2312 pp_cxx_whitespace (pp);
f078dc7d
AS
2313 if (c == error_mark_node)
2314 {
cb57504a 2315 pp_cxx_ws_string(pp, "<unsatisfied-type-constraint>");
f078dc7d
AS
2316 return;
2317 }
cb57504a 2318 tree t, a;
4fea442d
JM
2319 placeholder_extract_concept_and_args (c, t, a);
2320 pp->id_expression (t);
cb57504a
JM
2321 pp_cxx_begin_template_argument_list (pp);
2322 pp_cxx_ws_string (pp, "<placeholder>");
2323 pp_cxx_separate_with (pp, ',');
2324 tree args = make_tree_vec (TREE_VEC_LENGTH (a) - 1);
2325 for (int i = 0; i < TREE_VEC_LENGTH (a) - 1; ++i)
2326 TREE_VEC_ELT (args, i) = TREE_VEC_ELT (a, i + 1);
2327 pp_cxx_template_argument_list (pp, args);
2328 ggc_free (args);
2329 pp_cxx_end_template_argument_list (pp);
2330 pp_cxx_right_bracket (pp);
4fea442d
JM
2331}
2332
12ea3302
GDR
2333/*
2334 template-declaration:
971e17ff
AS
2335 export(opt) template < template-parameter-list > declaration
2336
2337 Concept extensions:
2338
2339 template-declaration:
2340 export(opt) template < template-parameter-list >
2341 requires-clause(opt) declaration */
b9b44fb9 2342
12ea3302
GDR
2343static void
2344pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t)
2345{
2346 tree tmpl = most_general_template (t);
2347 tree level;
12ea3302
GDR
2348
2349 pp_maybe_newline_and_indent (pp, 0);
2350 for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level))
2351 {
b02cec6e 2352 pp_cxx_ws_string (pp, "template");
12ea3302
GDR
2353 pp_cxx_begin_template_argument_list (pp);
2354 pp_cxx_template_parameter_list (pp, TREE_VALUE (level));
2355 pp_cxx_end_template_argument_list (pp);
2356 pp_newline_and_indent (pp, 3);
12ea3302 2357 }
971e17ff
AS
2358
2359 if (flag_concepts)
2360 if (tree ci = get_constraints (t))
2361 if (tree reqs = CI_TEMPLATE_REQS (ci))
2362 {
2363 pp_cxx_requires_clause (pp, reqs);
2364 pp_newline_and_indent (pp, 6);
2365 }
2366
12ea3302
GDR
2367 if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t))
2368 pp_cxx_function_definition (pp, t);
cb57504a
JM
2369 else if (TREE_CODE (t) == CONCEPT_DECL)
2370 pp_cxx_concept_definition (pp, t);
12ea3302
GDR
2371 else
2372 pp_cxx_simple_declaration (pp, t);
2373}
2374
2375static void
2376pp_cxx_explicit_specialization (cxx_pretty_printer *pp, tree t)
2377{
2378 pp_unsupported_tree (pp, t);
2379}
2380
2381static void
2382pp_cxx_explicit_instantiation (cxx_pretty_printer *pp, tree t)
2383{
2384 pp_unsupported_tree (pp, t);
2385}
2386
cb57504a
JM
2387static void
2388pp_cxx_concept_definition (cxx_pretty_printer *pp, tree t)
2389{
2390 pp_cxx_unqualified_id (pp, DECL_NAME (t));
2391 pp_cxx_whitespace (pp);
2392 pp_cxx_ws_string (pp, "=");
2393 pp_cxx_whitespace (pp);
2394 pp->expression (DECL_INITIAL (t));
2395 pp_cxx_semicolon (pp);
2396}
2397
12ea3302
GDR
2398/*
2399 declaration:
2400 block-declaration
2401 function-definition
2402 template-declaration
2403 explicit-instantiation
2404 explicit-specialization
2405 linkage-specification
2406 namespace-definition
2407
2408 block-declaration:
2409 simple-declaration
2410 asm-definition
2411 namespace-alias-definition
2412 using-declaration
55a3debe
DG
2413 using-directive
2414 static_assert-declaration */
12ea3302 2415void
8f0e4d72 2416cxx_pretty_printer::declaration (tree t)
12ea3302 2417{
55a3debe
DG
2418 if (TREE_CODE (t) == STATIC_ASSERT)
2419 {
8f0e4d72
GDR
2420 pp_cxx_ws_string (this, "static_assert");
2421 pp_cxx_left_paren (this);
2422 expression (STATIC_ASSERT_CONDITION (t));
2423 pp_cxx_separate_with (this, ',');
2424 expression (STATIC_ASSERT_MESSAGE (t));
2425 pp_cxx_right_paren (this);
55a3debe
DG
2426 }
2427 else if (!DECL_LANG_SPECIFIC (t))
8f0e4d72 2428 pp_cxx_simple_declaration (this, t);
a2a9e21c 2429 else if (DECL_USE_TEMPLATE (t))
12ea3302
GDR
2430 switch (DECL_USE_TEMPLATE (t))
2431 {
a2a9e21c 2432 case 1:
8f0e4d72 2433 pp_cxx_template_declaration (this, t);
0cbd7506 2434 break;
c8094d83 2435
12ea3302 2436 case 2:
8f0e4d72 2437 pp_cxx_explicit_specialization (this, t);
0cbd7506 2438 break;
12ea3302
GDR
2439
2440 case 3:
8f0e4d72 2441 pp_cxx_explicit_instantiation (this, t);
0cbd7506 2442 break;
12ea3302
GDR
2443
2444 default:
0cbd7506 2445 break;
12ea3302 2446 }
12ea3302
GDR
2447 else switch (TREE_CODE (t))
2448 {
2449 case VAR_DECL:
2450 case TYPE_DECL:
8f0e4d72 2451 pp_cxx_simple_declaration (this, t);
12ea3302 2452 break;
c8094d83 2453
12ea3302
GDR
2454 case FUNCTION_DECL:
2455 if (DECL_SAVED_TREE (t))
8f0e4d72 2456 pp_cxx_function_definition (this, t);
12ea3302 2457 else
8f0e4d72 2458 pp_cxx_simple_declaration (this, t);
12ea3302
GDR
2459 break;
2460
a2a9e21c
GDR
2461 case NAMESPACE_DECL:
2462 if (DECL_NAMESPACE_ALIAS (t))
8f0e4d72 2463 pp_cxx_namespace_alias_definition (this, t);
a2a9e21c 2464 else
8f0e4d72 2465 pp_cxx_original_namespace_definition (this, t);
a2a9e21c
GDR
2466 break;
2467
12ea3302 2468 default:
8f0e4d72 2469 pp_unsupported_tree (this, t);
12ea3302
GDR
2470 break;
2471 }
2472}
2473
066f956c 2474static void
2d65b828
PC
2475pp_cxx_typeid_expression (cxx_pretty_printer *pp, tree t)
2476{
2477 t = TREE_OPERAND (t, 0);
b02cec6e 2478 pp_cxx_ws_string (pp, "typeid");
2d65b828
PC
2479 pp_cxx_left_paren (pp);
2480 if (TYPE_P (t))
20059c8b 2481 pp->type_id (t);
2d65b828 2482 else
20059c8b 2483 pp->expression (t);
2d65b828
PC
2484 pp_cxx_right_paren (pp);
2485}
2486
fdb8f418
PC
2487void
2488pp_cxx_va_arg_expression (cxx_pretty_printer *pp, tree t)
2489{
b02cec6e 2490 pp_cxx_ws_string (pp, "va_arg");
fdb8f418 2491 pp_cxx_left_paren (pp);
20059c8b 2492 pp->assignment_expression (TREE_OPERAND (t, 0));
fdb8f418 2493 pp_cxx_separate_with (pp, ',');
20059c8b 2494 pp->type_id (TREE_TYPE (t));
fdb8f418
PC
2495 pp_cxx_right_paren (pp);
2496}
2497
094a5fe2
JJ
2498static bool
2499pp_cxx_offsetof_expression_1 (cxx_pretty_printer *pp, tree t)
2500{
2501 switch (TREE_CODE (t))
2502 {
2503 case ARROW_EXPR:
2504 if (TREE_CODE (TREE_OPERAND (t, 0)) == STATIC_CAST_EXPR
71a93b08 2505 && INDIRECT_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
094a5fe2 2506 {
20059c8b 2507 pp->type_id (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))));
094a5fe2
JJ
2508 pp_cxx_separate_with (pp, ',');
2509 return true;
2510 }
2511 return false;
2512 case COMPONENT_REF:
2513 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
2514 return false;
2515 if (TREE_CODE (TREE_OPERAND (t, 0)) != ARROW_EXPR)
2516 pp_cxx_dot (pp);
20059c8b 2517 pp->expression (TREE_OPERAND (t, 1));
094a5fe2
JJ
2518 return true;
2519 case ARRAY_REF:
2520 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
2521 return false;
2522 pp_left_bracket (pp);
20059c8b 2523 pp->expression (TREE_OPERAND (t, 1));
094a5fe2
JJ
2524 pp_right_bracket (pp);
2525 return true;
2526 default:
2527 return false;
2528 }
2529}
2530
2531void
2532pp_cxx_offsetof_expression (cxx_pretty_printer *pp, tree t)
2533{
b02cec6e 2534 pp_cxx_ws_string (pp, "offsetof");
094a5fe2
JJ
2535 pp_cxx_left_paren (pp);
2536 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
20059c8b 2537 pp->expression (TREE_OPERAND (t, 0));
094a5fe2
JJ
2538 pp_cxx_right_paren (pp);
2539}
2540
be845b04
JJ
2541void
2542pp_cxx_addressof_expression (cxx_pretty_printer *pp, tree t)
2543{
2544 pp_cxx_ws_string (pp, "__builtin_addressof");
2545 pp_cxx_left_paren (pp);
2546 pp->expression (TREE_OPERAND (t, 0));
2547 pp_cxx_right_paren (pp);
2548}
2549
f078dc7d
AS
2550static char const*
2551get_fold_operator (tree t)
2552{
2553 int op = int_cst_value (FOLD_EXPR_OP (t));
c7667624
JM
2554 ovl_op_info_t *info = OVL_OP_INFO (FOLD_EXPR_MODIFY_P (t), op);
2555 return info->name;
f078dc7d
AS
2556}
2557
2558void
2559pp_cxx_unary_left_fold_expression (cxx_pretty_printer *pp, tree t)
2560{
2561 char const* op = get_fold_operator (t);
2562 tree expr = PACK_EXPANSION_PATTERN (FOLD_EXPR_PACK (t));
2563 pp_cxx_left_paren (pp);
2564 pp_cxx_ws_string (pp, "...");
2565 pp_cxx_ws_string (pp, op);
2566 pp->expression (expr);
2567 pp_cxx_right_paren (pp);
2568}
2569
2570void
2571pp_cxx_unary_right_fold_expression (cxx_pretty_printer *pp, tree t)
2572{
2573 char const* op = get_fold_operator (t);
2574 tree expr = PACK_EXPANSION_PATTERN (FOLD_EXPR_PACK (t));
2575 pp_cxx_left_paren (pp);
2576 pp->expression (expr);
2577 pp_space (pp);
2578 pp_cxx_ws_string (pp, op);
2579 pp_cxx_ws_string (pp, "...");
2580 pp_cxx_right_paren (pp);
2581}
2582
2583void
2584pp_cxx_binary_fold_expression (cxx_pretty_printer *pp, tree t)
2585{
2586 char const* op = get_fold_operator (t);
2587 tree t1 = TREE_OPERAND (t, 1);
2588 tree t2 = TREE_OPERAND (t, 2);
2589 if (t1 == FOLD_EXPR_PACK (t))
2590 t1 = PACK_EXPANSION_PATTERN (t1);
2591 else
2592 t2 = PACK_EXPANSION_PATTERN (t2);
2593 pp_cxx_left_paren (pp);
2594 pp->expression (t1);
2595 pp_cxx_ws_string (pp, op);
2596 pp_cxx_ws_string (pp, "...");
2597 pp_cxx_ws_string (pp, op);
2598 pp->expression (t2);
2599 pp_cxx_right_paren (pp);
2600}
2601
e74392f0
PC
2602void
2603pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t)
2604{
2605 cp_trait_kind kind = TRAIT_EXPR_KIND (t);
2606
2607 switch (kind)
2608 {
2609 case CPTK_HAS_NOTHROW_ASSIGN:
b02cec6e 2610 pp_cxx_ws_string (pp, "__has_nothrow_assign");
e74392f0
PC
2611 break;
2612 case CPTK_HAS_TRIVIAL_ASSIGN:
b02cec6e 2613 pp_cxx_ws_string (pp, "__has_trivial_assign");
e74392f0
PC
2614 break;
2615 case CPTK_HAS_NOTHROW_CONSTRUCTOR:
b02cec6e 2616 pp_cxx_ws_string (pp, "__has_nothrow_constructor");
e74392f0
PC
2617 break;
2618 case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
b02cec6e 2619 pp_cxx_ws_string (pp, "__has_trivial_constructor");
e74392f0
PC
2620 break;
2621 case CPTK_HAS_NOTHROW_COPY:
b02cec6e 2622 pp_cxx_ws_string (pp, "__has_nothrow_copy");
e74392f0
PC
2623 break;
2624 case CPTK_HAS_TRIVIAL_COPY:
b02cec6e 2625 pp_cxx_ws_string (pp, "__has_trivial_copy");
e74392f0
PC
2626 break;
2627 case CPTK_HAS_TRIVIAL_DESTRUCTOR:
b02cec6e 2628 pp_cxx_ws_string (pp, "__has_trivial_destructor");
e74392f0 2629 break;
342cfb3e
JJ
2630 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
2631 pp_cxx_ws_string (pp, "__has_unique_object_representations");
2632 break;
e74392f0 2633 case CPTK_HAS_VIRTUAL_DESTRUCTOR:
b02cec6e 2634 pp_cxx_ws_string (pp, "__has_virtual_destructor");
e74392f0
PC
2635 break;
2636 case CPTK_IS_ABSTRACT:
b02cec6e 2637 pp_cxx_ws_string (pp, "__is_abstract");
e74392f0 2638 break;
af88f557
JJ
2639 case CPTK_IS_AGGREGATE:
2640 pp_cxx_ws_string (pp, "__is_aggregate");
2641 break;
e74392f0 2642 case CPTK_IS_BASE_OF:
b02cec6e 2643 pp_cxx_ws_string (pp, "__is_base_of");
e74392f0
PC
2644 break;
2645 case CPTK_IS_CLASS:
b02cec6e 2646 pp_cxx_ws_string (pp, "__is_class");
e74392f0 2647 break;
e74392f0 2648 case CPTK_IS_EMPTY:
b02cec6e 2649 pp_cxx_ws_string (pp, "__is_empty");
e74392f0
PC
2650 break;
2651 case CPTK_IS_ENUM:
b02cec6e 2652 pp_cxx_ws_string (pp, "__is_enum");
e74392f0 2653 break;
b3908fcc
JW
2654 case CPTK_IS_FINAL:
2655 pp_cxx_ws_string (pp, "__is_final");
2656 break;
e74392f0 2657 case CPTK_IS_POD:
b02cec6e 2658 pp_cxx_ws_string (pp, "__is_pod");
e74392f0
PC
2659 break;
2660 case CPTK_IS_POLYMORPHIC:
b02cec6e 2661 pp_cxx_ws_string (pp, "__is_polymorphic");
e74392f0 2662 break;
971e17ff 2663 case CPTK_IS_SAME_AS:
5c04da88 2664 pp_cxx_ws_string (pp, "__is_same");
971e17ff 2665 break;
c32097d8
JM
2666 case CPTK_IS_STD_LAYOUT:
2667 pp_cxx_ws_string (pp, "__is_std_layout");
2668 break;
2669 case CPTK_IS_TRIVIAL:
2670 pp_cxx_ws_string (pp, "__is_trivial");
2671 break;
dd5d5481
JM
2672 case CPTK_IS_TRIVIALLY_ASSIGNABLE:
2673 pp_cxx_ws_string (pp, "__is_trivially_assignable");
2674 break;
2675 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
2676 pp_cxx_ws_string (pp, "__is_trivially_constructible");
2677 break;
b752325e
JM
2678 case CPTK_IS_TRIVIALLY_COPYABLE:
2679 pp_cxx_ws_string (pp, "__is_trivially_copyable");
2680 break;
e74392f0 2681 case CPTK_IS_UNION:
b02cec6e 2682 pp_cxx_ws_string (pp, "__is_union");
e74392f0 2683 break;
2b08f2c5
JM
2684 case CPTK_IS_LITERAL_TYPE:
2685 pp_cxx_ws_string (pp, "__is_literal_type");
2686 break;
b42cc3ca
VV
2687 case CPTK_IS_ASSIGNABLE:
2688 pp_cxx_ws_string (pp, "__is_assignable");
2689 break;
2690 case CPTK_IS_CONSTRUCTIBLE:
2691 pp_cxx_ws_string (pp, "__is_constructible");
2692 break;
e74392f0
PC
2693
2694 default:
2695 gcc_unreachable ();
2696 }
2697
2698 pp_cxx_left_paren (pp);
20059c8b 2699 pp->type_id (TRAIT_EXPR_TYPE1 (t));
e74392f0 2700
971e17ff 2701 if (kind == CPTK_IS_BASE_OF || kind == CPTK_IS_SAME_AS)
e74392f0
PC
2702 {
2703 pp_cxx_separate_with (pp, ',');
20059c8b 2704 pp->type_id (TRAIT_EXPR_TYPE2 (t));
e74392f0
PC
2705 }
2706
2707 pp_cxx_right_paren (pp);
2708}
971e17ff
AS
2709
2710// requires-clause:
2711// 'requires' logical-or-expression
2712void
2713pp_cxx_requires_clause (cxx_pretty_printer *pp, tree t)
2714{
2715 if (!t)
2716 return;
2717 pp->padding = pp_before;
2718 pp_cxx_ws_string (pp, "requires");
2719 pp_space (pp);
2720 pp->expression (t);
2721}
2722
2723/* requirement:
2724 simple-requirement
2725 compound-requirement
2726 type-requirement
2727 nested-requirement */
2728static void
2729pp_cxx_requirement (cxx_pretty_printer *pp, tree t)
2730{
2731 switch (TREE_CODE (t))
2732 {
2733 case SIMPLE_REQ:
2734 pp_cxx_simple_requirement (pp, t);
2735 break;
2736
2737 case TYPE_REQ:
2738 pp_cxx_type_requirement (pp, t);
2739 break;
2740
2741 case COMPOUND_REQ:
2742 pp_cxx_compound_requirement (pp, t);
2743 break;
2744
2745 case NESTED_REQ:
2746 pp_cxx_nested_requirement (pp, t);
2747 break;
2748
2749 default:
2750 gcc_unreachable ();
2751 }
2752}
2753
2754// requirement-list:
2755// requirement
2756// requirement-list ';' requirement[opt]
2757//
2758static void
2759pp_cxx_requirement_list (cxx_pretty_printer *pp, tree t)
2760{
2761 for (; t; t = TREE_CHAIN (t))
2762 pp_cxx_requirement (pp, TREE_VALUE (t));
2763}
2764
2765// requirement-body:
2766// '{' requirement-list '}'
2767static void
2768pp_cxx_requirement_body (cxx_pretty_printer *pp, tree t)
2769{
2770 pp_cxx_left_brace (pp);
2771 pp_cxx_requirement_list (pp, t);
2772 pp_cxx_right_brace (pp);
2773}
2774
2775// requires-expression:
2776// 'requires' requirement-parameter-list requirement-body
2777void
2778pp_cxx_requires_expr (cxx_pretty_printer *pp, tree t)
2779{
2780 pp_string (pp, "requires");
2781 if (tree parms = TREE_OPERAND (t, 0))
2782 {
2783 pp_cxx_parameter_declaration_clause (pp, parms);
2784 pp_cxx_whitespace (pp);
2785 }
2786 pp_cxx_requirement_body (pp, TREE_OPERAND (t, 1));
2787}
2788
2789/* simple-requirement:
2790 expression ';' */
2791void
2792pp_cxx_simple_requirement (cxx_pretty_printer *pp, tree t)
2793{
2794 pp->expression (TREE_OPERAND (t, 0));
2795 pp_cxx_semicolon (pp);
2796}
2797
2798/* type-requirement:
2799 typename type-name ';' */
2800void
2801pp_cxx_type_requirement (cxx_pretty_printer *pp, tree t)
2802{
2803 pp->type_id (TREE_OPERAND (t, 0));
2804 pp_cxx_semicolon (pp);
2805}
2806
2807/* compound-requirement:
2808 '{' expression '}' 'noexcept' [opt] trailing-return-type [opt] */
2809void
2810pp_cxx_compound_requirement (cxx_pretty_printer *pp, tree t)
2811{
2812 pp_cxx_left_brace (pp);
2813 pp->expression (TREE_OPERAND (t, 0));
2814 pp_cxx_right_brace (pp);
2815
2816 if (COMPOUND_REQ_NOEXCEPT_P (t))
2817 pp_cxx_ws_string (pp, "noexcept");
2818
2819 if (tree type = TREE_OPERAND (t, 1))
2820 {
cb57504a 2821 pp_cxx_whitespace (pp);
971e17ff
AS
2822 pp_cxx_ws_string (pp, "->");
2823 pp->type_id (type);
2824 }
f078dc7d 2825 pp_cxx_semicolon (pp);
971e17ff
AS
2826}
2827
2828/* nested requirement:
2829 'requires' constraint-expression */
2830void
2831pp_cxx_nested_requirement (cxx_pretty_printer *pp, tree t)
2832{
2833 pp_cxx_ws_string (pp, "requires");
2834 pp->expression (TREE_OPERAND (t, 0));
2835 pp_cxx_semicolon (pp);
2836}
2837
f078dc7d
AS
2838void
2839pp_cxx_check_constraint (cxx_pretty_printer *pp, tree t)
2840{
2841 tree decl = CHECK_CONSTR_CONCEPT (t);
2842 tree tmpl = DECL_TI_TEMPLATE (decl);
2843 tree args = CHECK_CONSTR_ARGS (t);
2844 tree id = build_nt (TEMPLATE_ID_EXPR, tmpl, args);
2845
cb57504a
JM
2846 if (TREE_CODE (decl) == CONCEPT_DECL)
2847 pp->expression (id);
2848 else if (VAR_P (decl))
f078dc7d
AS
2849 pp->expression (id);
2850 else if (TREE_CODE (decl) == FUNCTION_DECL)
2851 {
2852 tree call = build_vl_exp (CALL_EXPR, 2);
2853 TREE_OPERAND (call, 0) = integer_two_node;
2854 TREE_OPERAND (call, 1) = id;
2855 pp->expression (call);
2856 }
2857 else
2858 gcc_unreachable ();
971e17ff
AS
2859}
2860
cb57504a
JM
2861/* Output the "[with ...]" clause for a parameter mapping of an atomic
2862 constraint. */
971e17ff 2863
cb57504a
JM
2864static void
2865pp_cxx_parameter_mapping (cxx_pretty_printer *pp, tree map)
971e17ff 2866{
cb57504a
JM
2867 for (tree p = map; p; p = TREE_CHAIN (p))
2868 {
2869 tree parm = TREE_VALUE (p);
2870 tree arg = TREE_PURPOSE (p);
971e17ff 2871
cb57504a
JM
2872 if (TYPE_P (parm))
2873 pp->type_id (parm);
2874 else
2875 pp_cxx_tree_identifier (pp, DECL_NAME (TEMPLATE_PARM_DECL (parm)));
971e17ff 2876
cb57504a
JM
2877 pp_cxx_whitespace (pp);
2878 pp_equal (pp);
2879 pp_cxx_whitespace (pp);
971e17ff 2880
cb57504a
JM
2881 if (TYPE_P (arg) || DECL_TEMPLATE_TEMPLATE_PARM_P (arg))
2882 pp->type_id (arg);
2883 else
2884 pp->expression (arg);
2885
2886 if (TREE_CHAIN (p) != NULL_TREE)
2887 pp_cxx_separate_with (pp, ';');
2888 }
971e17ff
AS
2889}
2890
2891void
cb57504a 2892pp_cxx_atomic_constraint (cxx_pretty_printer *pp, tree t)
971e17ff 2893{
cb57504a
JM
2894 /* Emit the expression. */
2895 pp->expression (ATOMIC_CONSTR_EXPR (t));
2896
2897 /* Emit the parameter mapping. */
2898 tree map = ATOMIC_CONSTR_MAP (t);
2899 if (map && map != error_mark_node)
971e17ff 2900 {
971e17ff 2901 pp_cxx_whitespace (pp);
cb57504a
JM
2902 pp_cxx_left_bracket (pp);
2903 pp->translate_string ("with");
2904 pp_cxx_whitespace (pp);
2905 pp_cxx_parameter_mapping (pp, map);
2906 pp_cxx_right_bracket (pp);
2907 }
971e17ff
AS
2908}
2909
2910void
2911pp_cxx_conjunction (cxx_pretty_printer *pp, tree t)
2912{
2913 pp_cxx_constraint (pp, TREE_OPERAND (t, 0));
cb57504a 2914 pp_string (pp, " /\\ ");
971e17ff
AS
2915 pp_cxx_constraint (pp, TREE_OPERAND (t, 1));
2916}
2917
2918void
2919pp_cxx_disjunction (cxx_pretty_printer *pp, tree t)
2920{
2921 pp_cxx_constraint (pp, TREE_OPERAND (t, 0));
cb57504a 2922 pp_string (pp, " \\/ ");
971e17ff
AS
2923 pp_cxx_constraint (pp, TREE_OPERAND (t, 1));
2924}
2925
2926void
2927pp_cxx_constraint (cxx_pretty_printer *pp, tree t)
2928{
2929 if (t == error_mark_node)
2930 return pp->expression (t);
2931
2932 switch (TREE_CODE (t))
2933 {
cb57504a
JM
2934 case ATOMIC_CONSTR:
2935 pp_cxx_atomic_constraint (pp, t);
971e17ff
AS
2936 break;
2937
f078dc7d
AS
2938 case CHECK_CONSTR:
2939 pp_cxx_check_constraint (pp, t);
2940 break;
2941
971e17ff
AS
2942 case CONJ_CONSTR:
2943 pp_cxx_conjunction (pp, t);
2944 break;
2945
2946 case DISJ_CONSTR:
2947 pp_cxx_disjunction (pp, t);
2948 break;
2949
f078dc7d
AS
2950 case EXPR_PACK_EXPANSION:
2951 pp->expression (TREE_OPERAND (t, 0));
2952 break;
2953
971e17ff
AS
2954 default:
2955 gcc_unreachable ();
2956 }
2957}
2958
12ea3302
GDR
2959\f
2960typedef c_pretty_print_fn pp_fun;
2961
b9b44fb9
GDR
2962/* Initialization of a C++ pretty-printer object. */
2963
da6ca2b5
GDR
2964cxx_pretty_printer::cxx_pretty_printer ()
2965 : c_pretty_printer (),
2966 enclosing_scope (global_namespace)
12ea3302 2967{
da6ca2b5 2968 type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
da6ca2b5 2969 parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
e1a4dd13 2970}
368877a1
DM
2971
2972/* cxx_pretty_printer's implementation of pretty_printer::clone vfunc. */
2973
2974pretty_printer *
2975cxx_pretty_printer::clone () const
2976{
2977 return new cxx_pretty_printer (*this);
2978}