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