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