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