1 /* Implementation of subroutines for the GNU C++ pretty-printer.
2 Copyright (C) 2003-2018 Free Software Foundation, Inc.
3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
5 This file is part of GCC.
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
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
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/>. */
23 #include "coretypes.h"
25 #include "cxx-pretty-print.h"
26 #include "tree-pretty-print.h"
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
);
44 pp_cxx_nonconsecutive_character (cxx_pretty_printer
*pp
, int c
)
46 const char *p
= pp_last_position_in_text (pp
);
48 if (p
!= NULL
&& *p
== c
)
49 pp_cxx_whitespace (pp
);
51 pp
->padding
= pp_none
;
54 #define pp_cxx_expression_list(PP, T) \
55 pp_c_expression_list (PP, T)
56 #define pp_cxx_space_for_pointer_operator(PP, T) \
57 pp_c_space_for_pointer_operator (PP, T)
58 #define pp_cxx_init_declarator(PP, T) \
59 pp_c_init_declarator (PP, T)
60 #define pp_cxx_call_argument_list(PP, T) \
61 pp_c_call_argument_list (PP, T)
64 pp_cxx_colon_colon (cxx_pretty_printer
*pp
)
67 pp
->padding
= pp_none
;
71 pp_cxx_begin_template_argument_list (cxx_pretty_printer
*pp
)
73 pp_cxx_nonconsecutive_character (pp
, '<');
77 pp_cxx_end_template_argument_list (cxx_pretty_printer
*pp
)
79 pp_cxx_nonconsecutive_character (pp
, '>');
83 pp_cxx_separate_with (cxx_pretty_printer
*pp
, int c
)
85 pp_separate_with (pp
, c
);
86 pp
->padding
= pp_none
;
91 /* conversion-function-id:
92 operator conversion-type-id
95 type-specifier-seq conversion-declarator(opt)
97 conversion-declarator:
98 ptr-operator conversion-declarator(opt) */
101 pp_cxx_conversion_function_id (cxx_pretty_printer
*pp
, tree t
)
103 pp_cxx_ws_string (pp
, "operator");
104 pp_cxx_type_specifier_seq (pp
, TREE_TYPE (t
));
108 pp_cxx_template_id (cxx_pretty_printer
*pp
, tree t
)
110 pp_cxx_unqualified_id (pp
, TREE_OPERAND (t
, 0));
111 pp_cxx_begin_template_argument_list (pp
);
112 pp_cxx_template_argument_list (pp
, TREE_OPERAND (t
, 1));
113 pp_cxx_end_template_argument_list (pp
);
116 /* Prints the unqualified part of the id-expression T.
121 conversion-function-id
126 pp_cxx_unqualified_id (cxx_pretty_printer
*pp
, tree t
)
128 enum tree_code code
= TREE_CODE (t
);
132 pp
->translate_string ("<return-value>");
151 case IDENTIFIER_NODE
:
153 pp
->translate_string ("<unnamed>");
154 else if (IDENTIFIER_CONV_OP_P (t
))
155 pp_cxx_conversion_function_id (pp
, t
);
157 pp_cxx_tree_identifier (pp
, t
);
160 case TEMPLATE_ID_EXPR
:
161 pp_cxx_template_id (pp
, t
);
165 pp_cxx_unqualified_id (pp
, BASELINK_FUNCTIONS (t
));
172 case UNBOUND_CLASS_TEMPLATE
:
173 pp_cxx_unqualified_id (pp
, TYPE_NAME (t
));
174 if (CLASS_TYPE_P (t
) && CLASSTYPE_USE_TEMPLATE (t
))
176 pp_cxx_begin_template_argument_list (pp
);
177 pp_cxx_template_argument_list (pp
, INNERMOST_TEMPLATE_ARGS
178 (CLASSTYPE_TI_ARGS (t
)));
179 pp_cxx_end_template_argument_list (pp
);
184 pp_cxx_complement (pp
);
185 pp_cxx_unqualified_id (pp
, TREE_OPERAND (t
, 0));
188 case TEMPLATE_TYPE_PARM
:
189 case TEMPLATE_TEMPLATE_PARM
:
190 if (TYPE_IDENTIFIER (t
))
191 pp_cxx_unqualified_id (pp
, TYPE_IDENTIFIER (t
));
193 pp_cxx_canonical_template_parameter (pp
, t
);
196 case TEMPLATE_PARM_INDEX
:
197 pp_cxx_unqualified_id (pp
, TEMPLATE_PARM_DECL (t
));
200 case BOUND_TEMPLATE_TEMPLATE_PARM
:
201 pp_cxx_cv_qualifier_seq (pp
, t
);
202 pp_cxx_unqualified_id (pp
, TYPE_IDENTIFIER (t
));
203 pp_cxx_begin_template_argument_list (pp
);
204 pp_cxx_template_argument_list (pp
, TYPE_TI_ARGS (t
));
205 pp_cxx_end_template_argument_list (pp
);
209 pp_unsupported_tree (pp
, t
);
214 /* Pretty-print out the token sequence ":: template" in template codes
215 where it is needed to "inline declare" the (following) member as
216 a template. This situation arises when SCOPE of T is dependent
217 on template parameters. */
220 pp_cxx_template_keyword_if_needed (cxx_pretty_printer
*pp
, tree scope
, tree t
)
222 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
223 && TYPE_P (scope
) && dependent_type_p (scope
))
224 pp_cxx_ws_string (pp
, "template");
227 /* nested-name-specifier:
228 class-or-namespace-name :: nested-name-specifier(opt)
229 class-or-namespace-name :: template nested-name-specifier */
232 pp_cxx_nested_name_specifier (cxx_pretty_printer
*pp
, tree t
)
234 if (!SCOPE_FILE_SCOPE_P (t
) && t
!= pp
->enclosing_scope
)
236 tree scope
= get_containing_scope (t
);
237 pp_cxx_nested_name_specifier (pp
, scope
);
238 pp_cxx_template_keyword_if_needed (pp
, scope
, t
);
239 pp_cxx_unqualified_id (pp
, t
);
240 pp_cxx_colon_colon (pp
);
245 nested-name-specifier template(opt) unqualified-id */
248 pp_cxx_qualified_id (cxx_pretty_printer
*pp
, tree t
)
250 switch (TREE_CODE (t
))
252 /* A pointer-to-member is always qualified. */
254 pp_cxx_nested_name_specifier (pp
, PTRMEM_CST_CLASS (t
));
255 pp_cxx_unqualified_id (pp
, PTRMEM_CST_MEMBER (t
));
258 /* In Standard C++, functions cannot possibly be used as
259 nested-name-specifiers. However, there are situations where
260 is "makes sense" to output the surrounding function name for the
261 purpose of emphasizing on the scope kind. Just printing the
262 function name might not be sufficient as it may be overloaded; so,
263 we decorate the function with its signature too.
264 FIXME: This is probably the wrong pretty-printing for conversion
265 functions and some function templates. */
270 if (DECL_FUNCTION_MEMBER_P (t
))
271 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
272 pp_cxx_unqualified_id
273 (pp
, DECL_CONSTRUCTOR_P (t
) ? DECL_CONTEXT (t
) : t
);
274 pp_cxx_parameter_declaration_clause (pp
, TREE_TYPE (t
));
279 pp_cxx_nested_name_specifier (pp
, TREE_OPERAND (t
, 0));
280 pp_cxx_unqualified_id (pp
, TREE_OPERAND (t
, 1));
285 tree scope
= get_containing_scope (t
);
286 if (scope
!= pp
->enclosing_scope
)
288 pp_cxx_nested_name_specifier (pp
, scope
);
289 pp_cxx_template_keyword_if_needed (pp
, scope
, t
);
291 pp_cxx_unqualified_id (pp
, t
);
299 cxx_pretty_printer::constant (tree t
)
301 switch (TREE_CODE (t
))
305 const bool in_parens
= PAREN_STRING_LITERAL_P (t
);
307 pp_cxx_left_paren (this);
308 c_pretty_printer::constant (t
);
310 pp_cxx_right_paren (this);
315 if (NULLPTR_TYPE_P (TREE_TYPE (t
)))
317 pp_string (this, "nullptr");
323 c_pretty_printer::constant (t
);
333 cxx_pretty_printer::id_expression (tree t
)
335 if (TREE_CODE (t
) == OVERLOAD
)
337 if (DECL_P (t
) && DECL_CONTEXT (t
))
338 pp_cxx_qualified_id (this, t
);
340 pp_cxx_unqualified_id (this, t
);
343 /* user-defined literal:
347 pp_cxx_userdef_literal (cxx_pretty_printer
*pp
, tree t
)
349 pp
->constant (USERDEF_LITERAL_VALUE (t
));
350 pp
->id_expression (USERDEF_LITERAL_SUFFIX_ID (t
));
354 /* primary-expression:
358 :: operator-function-id
364 __builtin_va_arg ( assignment-expression , type-id )
365 __builtin_offsetof ( type-id, offsetof-expression )
366 __builtin_addressof ( expression )
368 __has_nothrow_assign ( type-id )
369 __has_nothrow_constructor ( type-id )
370 __has_nothrow_copy ( type-id )
371 __has_trivial_assign ( type-id )
372 __has_trivial_constructor ( type-id )
373 __has_trivial_copy ( type-id )
374 __has_unique_object_representations ( type-id )
375 __has_trivial_destructor ( type-id )
376 __has_virtual_destructor ( type-id )
377 __is_abstract ( type-id )
378 __is_base_of ( type-id , type-id )
379 __is_class ( type-id )
380 __is_empty ( type-id )
381 __is_enum ( type-id )
382 __is_literal_type ( type-id )
384 __is_polymorphic ( type-id )
385 __is_std_layout ( type-id )
386 __is_trivial ( type-id )
387 __is_union ( type-id ) */
390 cxx_pretty_printer::primary_expression (tree t
)
392 switch (TREE_CODE (t
))
402 case USERDEF_LITERAL
:
403 pp_cxx_userdef_literal (this, t
);
407 t
= BASELINK_FUNCTIONS (t
);
420 case TEMPLATE_TYPE_PARM
:
421 case TEMPLATE_TEMPLATE_PARM
:
422 case TEMPLATE_PARM_INDEX
:
423 pp_cxx_unqualified_id (this, t
);
427 pp_cxx_left_paren (this);
428 statement (STMT_EXPR_STMT (t
));
429 pp_cxx_right_paren (this);
433 pp_cxx_trait_expression (this, t
);
437 pp_cxx_va_arg_expression (this, t
);
441 pp_cxx_offsetof_expression (this, t
);
445 pp_cxx_addressof_expression (this, t
);
449 pp_cxx_requires_expr (this, t
);
453 c_pretty_printer::primary_expression (t
);
458 /* postfix-expression:
460 postfix-expression [ expression ]
461 postfix-expression ( expression-list(opt) )
462 simple-type-specifier ( expression-list(opt) )
463 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
464 typename ::(opt) nested-name-specifier template(opt)
465 template-id ( expression-list(opt) )
466 postfix-expression . template(opt) ::(opt) id-expression
467 postfix-expression -> template(opt) ::(opt) id-expression
468 postfix-expression . pseudo-destructor-name
469 postfix-expression -> pseudo-destructor-name
470 postfix-expression ++
471 postfix-expression --
472 dynamic_cast < type-id > ( expression )
473 static_cast < type-id > ( expression )
474 reinterpret_cast < type-id > ( expression )
475 const_cast < type-id > ( expression )
476 typeid ( expression )
477 typeid ( type-id ) */
480 cxx_pretty_printer::postfix_expression (tree t
)
482 enum tree_code code
= TREE_CODE (t
);
489 tree fun
= cp_get_callee (t
);
490 tree saved_scope
= enclosing_scope
;
491 bool skipfirst
= false;
494 if (TREE_CODE (fun
) == ADDR_EXPR
)
495 fun
= TREE_OPERAND (fun
, 0);
497 /* In templates, where there is no way to tell whether a given
498 call uses an actual member function. So the parser builds
499 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
500 instantiation time. */
501 if (TREE_CODE (fun
) != FUNCTION_DECL
)
503 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun
))
505 tree object
= (code
== AGGR_INIT_EXPR
506 ? (AGGR_INIT_VIA_CTOR_P (t
)
507 ? AGGR_INIT_EXPR_SLOT (t
)
508 : AGGR_INIT_EXPR_ARG (t
, 0))
509 : CALL_EXPR_ARG (t
, 0));
511 while (TREE_CODE (object
) == NOP_EXPR
)
512 object
= TREE_OPERAND (object
, 0);
514 if (TREE_CODE (object
) == ADDR_EXPR
)
515 object
= TREE_OPERAND (object
, 0);
517 if (!TYPE_PTR_P (TREE_TYPE (object
)))
519 postfix_expression (object
);
524 postfix_expression (object
);
528 enclosing_scope
= strip_pointer_operator (TREE_TYPE (object
));
531 postfix_expression (fun
);
532 enclosing_scope
= saved_scope
;
533 pp_cxx_left_paren (this);
534 if (code
== AGGR_INIT_EXPR
)
536 aggr_init_expr_arg_iterator iter
;
537 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
544 if (more_aggr_init_expr_args_p (&iter
))
545 pp_cxx_separate_with (this, ',');
551 call_expr_arg_iterator iter
;
552 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
559 if (more_call_expr_args_p (&iter
))
560 pp_cxx_separate_with (this, ',');
564 pp_cxx_right_paren (this);
566 if (code
== AGGR_INIT_EXPR
&& AGGR_INIT_VIA_CTOR_P (t
))
568 pp_cxx_separate_with (this, ',');
569 postfix_expression (AGGR_INIT_EXPR_SLOT (t
));
582 primary_expression (t
);
585 case DYNAMIC_CAST_EXPR
:
586 case STATIC_CAST_EXPR
:
587 case REINTERPRET_CAST_EXPR
:
588 case CONST_CAST_EXPR
:
589 if (code
== DYNAMIC_CAST_EXPR
)
590 pp_cxx_ws_string (this, "dynamic_cast");
591 else if (code
== STATIC_CAST_EXPR
)
592 pp_cxx_ws_string (this, "static_cast");
593 else if (code
== REINTERPRET_CAST_EXPR
)
594 pp_cxx_ws_string (this, "reinterpret_cast");
596 pp_cxx_ws_string (this, "const_cast");
597 pp_cxx_begin_template_argument_list (this);
598 type_id (TREE_TYPE (t
));
599 pp_cxx_end_template_argument_list (this);
600 pp_left_paren (this);
601 expression (TREE_OPERAND (t
, 0));
602 pp_right_paren (this);
605 case EMPTY_CLASS_EXPR
:
606 type_id (TREE_TYPE (t
));
607 pp_left_paren (this);
608 pp_right_paren (this);
612 pp_cxx_typeid_expression (this, t
);
615 case PSEUDO_DTOR_EXPR
:
616 postfix_expression (TREE_OPERAND (t
, 0));
618 if (TREE_OPERAND (t
, 1))
620 pp_cxx_qualified_id (this, TREE_OPERAND (t
, 1));
621 pp_cxx_colon_colon (this);
623 pp_complement (this);
624 pp_cxx_unqualified_id (this, TREE_OPERAND (t
, 2));
628 postfix_expression (TREE_OPERAND (t
, 0));
633 c_pretty_printer::postfix_expression (t
);
639 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
640 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
646 type-specifier-seq new-declarator(opt)
649 ptr-operator new-declarator(opt)
650 direct-new-declarator
652 direct-new-declarator
654 direct-new-declarator [ constant-expression ]
657 ( expression-list(opt) ) */
660 pp_cxx_new_expression (cxx_pretty_printer
*pp
, tree t
)
662 enum tree_code code
= TREE_CODE (t
);
663 tree type
= TREE_OPERAND (t
, 1);
664 tree init
= TREE_OPERAND (t
, 2);
669 if (NEW_EXPR_USE_GLOBAL (t
))
670 pp_cxx_colon_colon (pp
);
671 pp_cxx_ws_string (pp
, "new");
672 if (TREE_OPERAND (t
, 0))
674 pp_cxx_call_argument_list (pp
, TREE_OPERAND (t
, 0));
677 if (TREE_CODE (type
) == ARRAY_REF
)
678 type
= build_cplus_array_type
679 (TREE_OPERAND (type
, 0),
680 build_index_type (fold_build2_loc (input_location
,
681 MINUS_EXPR
, integer_type_node
,
682 TREE_OPERAND (type
, 1),
688 if (TREE_CODE (init
) == TREE_LIST
)
689 pp_c_expression_list (pp
, init
);
690 else if (init
== void_node
)
691 ; /* OK, empty initializer list. */
693 pp
->expression (init
);
699 pp_unsupported_tree (pp
, t
);
703 /* delete-expression:
704 ::(opt) delete cast-expression
705 ::(opt) delete [ ] cast-expression */
708 pp_cxx_delete_expression (cxx_pretty_printer
*pp
, tree t
)
710 enum tree_code code
= TREE_CODE (t
);
714 case VEC_DELETE_EXPR
:
715 if (DELETE_EXPR_USE_GLOBAL (t
))
716 pp_cxx_colon_colon (pp
);
717 pp_cxx_ws_string (pp
, "delete");
719 if (code
== VEC_DELETE_EXPR
720 || DELETE_EXPR_USE_VEC (t
))
722 pp_left_bracket (pp
);
723 pp_right_bracket (pp
);
726 pp_c_cast_expression (pp
, TREE_OPERAND (t
, 0));
730 pp_unsupported_tree (pp
, t
);
738 unary-operator cast-expression
739 sizeof unary-expression
741 sizeof ... ( identifier )
745 unary-operator: one of
749 __alignof__ unary-expression
750 __alignof__ ( type-id ) */
753 cxx_pretty_printer::unary_expression (tree t
)
755 enum tree_code code
= TREE_CODE (t
);
760 pp_cxx_new_expression (this, t
);
764 case VEC_DELETE_EXPR
:
765 pp_cxx_delete_expression (this, t
);
769 if (PACK_EXPANSION_P (TREE_OPERAND (t
, 0)))
771 pp_cxx_ws_string (this, "sizeof");
772 pp_cxx_ws_string (this, "...");
773 pp_cxx_whitespace (this);
774 pp_cxx_left_paren (this);
775 if (TYPE_P (TREE_OPERAND (t
, 0)))
776 type_id (TREE_OPERAND (t
, 0));
778 unary_expression (TREE_OPERAND (t
, 0));
779 pp_cxx_right_paren (this);
785 pp_cxx_ws_string (this, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
786 pp_cxx_whitespace (this);
787 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
789 pp_cxx_left_paren (this);
790 type_id (TREE_TYPE (TREE_OPERAND (t
, 0)));
791 pp_cxx_right_paren (this);
793 else if (TYPE_P (TREE_OPERAND (t
, 0)))
795 pp_cxx_left_paren (this);
796 type_id (TREE_OPERAND (t
, 0));
797 pp_cxx_right_paren (this);
800 unary_expression (TREE_OPERAND (t
, 0));
804 pp_cxx_ws_string (this, "@encode");
805 pp_cxx_whitespace (this);
806 pp_cxx_left_paren (this);
807 type_id (TREE_OPERAND (t
, 0));
808 pp_cxx_right_paren (this);
812 pp_cxx_ws_string (this, "noexcept");
813 pp_cxx_whitespace (this);
814 pp_cxx_left_paren (this);
815 expression (TREE_OPERAND (t
, 0));
816 pp_cxx_right_paren (this);
819 case UNARY_PLUS_EXPR
:
821 pp_cxx_cast_expression (this, TREE_OPERAND (t
, 0));
825 c_pretty_printer::unary_expression (t
);
832 ( type-id ) cast-expression */
835 pp_cxx_cast_expression (cxx_pretty_printer
*pp
, tree t
)
837 switch (TREE_CODE (t
))
840 case IMPLICIT_CONV_EXPR
:
841 pp
->type_id (TREE_TYPE (t
));
842 pp_cxx_call_argument_list (pp
, TREE_OPERAND (t
, 0));
846 pp_c_cast_expression (pp
, t
);
853 pm-expression .* cast-expression
854 pm-expression ->* cast-expression */
857 pp_cxx_pm_expression (cxx_pretty_printer
*pp
, tree t
)
859 switch (TREE_CODE (t
))
861 /* Handle unfortunate OFFSET_REF overloading here. */
863 if (TYPE_P (TREE_OPERAND (t
, 0)))
865 pp_cxx_qualified_id (pp
, t
);
871 pp_cxx_pm_expression (pp
, TREE_OPERAND (t
, 0));
872 if (TREE_CODE (t
) == MEMBER_REF
)
877 pp_cxx_cast_expression (pp
, TREE_OPERAND (t
, 1));
882 pp_cxx_cast_expression (pp
, t
);
887 /* multiplicative-expression:
889 multiplicative-expression * pm-expression
890 multiplicative-expression / pm-expression
891 multiplicative-expression % pm-expression */
894 cxx_pretty_printer::multiplicative_expression (tree e
)
896 enum tree_code code
= TREE_CODE (e
);
902 multiplicative_expression (TREE_OPERAND (e
, 0));
904 if (code
== MULT_EXPR
)
906 else if (code
== TRUNC_DIV_EXPR
)
911 pp_cxx_pm_expression (this, TREE_OPERAND (e
, 1));
915 pp_cxx_pm_expression (this, e
);
920 /* conditional-expression:
921 logical-or-expression
922 logical-or-expression ? expression : assignment-expression */
925 cxx_pretty_printer::conditional_expression (tree e
)
927 if (TREE_CODE (e
) == COND_EXPR
)
929 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
933 expression (TREE_OPERAND (e
, 1));
935 assignment_expression (TREE_OPERAND (e
, 2));
938 pp_c_logical_or_expression (this, e
);
941 /* Pretty-print a compound assignment operator token as indicated by T. */
944 pp_cxx_assignment_operator (cxx_pretty_printer
*pp
, tree t
)
948 switch (TREE_CODE (t
))
971 op
= get_tree_code_name (TREE_CODE (t
));
975 pp_cxx_ws_string (pp
, op
);
979 /* assignment-expression:
980 conditional-expression
981 logical-or-expression assignment-operator assignment-expression
985 throw assignment-expression(opt)
987 assignment-operator: one of
988 = *= /= %= += -= >>= <<= &= ^= |= */
991 cxx_pretty_printer::assignment_expression (tree e
)
993 switch (TREE_CODE (e
))
997 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
1001 assignment_expression (TREE_OPERAND (e
, 1));
1005 pp_cxx_ws_string (this, "throw");
1006 if (TREE_OPERAND (e
, 0))
1007 assignment_expression (TREE_OPERAND (e
, 0));
1011 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
1012 pp_cxx_assignment_operator (this, TREE_OPERAND (e
, 1));
1013 assignment_expression (TREE_OPERAND (e
, 2));
1017 conditional_expression (e
);
1023 cxx_pretty_printer::expression (tree t
)
1025 switch (TREE_CODE (t
))
1035 case USERDEF_LITERAL
:
1036 pp_cxx_userdef_literal (this, t
);
1040 pp_cxx_unqualified_id (this, t
);
1048 pp_cxx_qualified_id (this, t
);
1061 case TEMPLATE_TYPE_PARM
:
1062 case TEMPLATE_PARM_INDEX
:
1063 case TEMPLATE_TEMPLATE_PARM
:
1066 primary_expression (t
);
1070 case DYNAMIC_CAST_EXPR
:
1071 case STATIC_CAST_EXPR
:
1072 case REINTERPRET_CAST_EXPR
:
1073 case CONST_CAST_EXPR
:
1077 case EMPTY_CLASS_EXPR
:
1079 case PSEUDO_DTOR_EXPR
:
1080 case AGGR_INIT_EXPR
:
1082 postfix_expression (t
);
1087 pp_cxx_new_expression (this, t
);
1091 case VEC_DELETE_EXPR
:
1092 pp_cxx_delete_expression (this, t
);
1098 case UNARY_PLUS_EXPR
:
1099 unary_expression (t
);
1103 case IMPLICIT_CONV_EXPR
:
1104 pp_cxx_cast_expression (this, t
);
1110 pp_cxx_pm_expression (this, t
);
1114 case TRUNC_DIV_EXPR
:
1115 case TRUNC_MOD_EXPR
:
1116 multiplicative_expression (t
);
1120 conditional_expression (t
);
1127 assignment_expression (t
);
1130 case NON_DEPENDENT_EXPR
:
1131 case MUST_NOT_THROW_EXPR
:
1132 expression (TREE_OPERAND (t
, 0));
1135 case EXPR_PACK_EXPANSION
:
1136 expression (PACK_EXPANSION_PATTERN (t
));
1137 pp_cxx_ws_string (this, "...");
1140 case UNARY_LEFT_FOLD_EXPR
:
1141 pp_cxx_unary_left_fold_expression (this, t
);
1144 case UNARY_RIGHT_FOLD_EXPR
:
1145 pp_cxx_unary_right_fold_expression (this, t
);
1148 case BINARY_LEFT_FOLD_EXPR
:
1149 case BINARY_RIGHT_FOLD_EXPR
:
1150 pp_cxx_binary_fold_expression (this, t
);
1153 case TEMPLATE_ID_EXPR
:
1154 pp_cxx_template_id (this, t
);
1157 case NONTYPE_ARGUMENT_PACK
:
1159 tree args
= ARGUMENT_PACK_ARGS (t
);
1160 int i
, len
= TREE_VEC_LENGTH (args
);
1161 for (i
= 0; i
< len
; ++i
)
1164 pp_cxx_separate_with (this, ',');
1165 expression (TREE_VEC_ELT (args
, i
));
1171 pp_cxx_ws_string (this, "<lambda>");
1175 pp_cxx_trait_expression (this, t
);
1188 pp_cxx_constraint (this, t
);
1192 pp_cxx_left_paren (this);
1193 expression (TREE_OPERAND (t
, 0));
1194 pp_cxx_right_paren (this);
1198 c_pretty_printer::expression (t
);
1206 /* function-specifier:
1212 cxx_pretty_printer::function_specifier (tree t
)
1214 switch (TREE_CODE (t
))
1217 if (DECL_VIRTUAL_P (t
))
1218 pp_cxx_ws_string (this, "virtual");
1219 else if (DECL_CONSTRUCTOR_P (t
) && DECL_NONCONVERTING_P (t
))
1220 pp_cxx_ws_string (this, "explicit");
1222 c_pretty_printer::function_specifier (t
);
1229 /* decl-specifier-seq:
1230 decl-specifier-seq(opt) decl-specifier
1233 storage-class-specifier
1240 cxx_pretty_printer::declaration_specifiers (tree t
)
1242 switch (TREE_CODE (t
))
1248 storage_class_specifier (t
);
1249 declaration_specifiers (TREE_TYPE (t
));
1253 pp_cxx_ws_string (this, "typedef");
1254 declaration_specifiers (TREE_TYPE (t
));
1258 /* Constructors don't have return types. And conversion functions
1259 do not have a type-specifier in their return types. */
1260 if (DECL_CONSTRUCTOR_P (t
) || DECL_CONV_FN_P (t
))
1261 function_specifier (t
);
1262 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1263 declaration_specifiers (TREE_TYPE (TREE_TYPE (t
)));
1265 c_pretty_printer::declaration_specifiers (t
);
1268 c_pretty_printer::declaration_specifiers (t
);
1273 /* simple-type-specifier:
1274 ::(opt) nested-name-specifier(opt) type-name
1275 ::(opt) nested-name-specifier(opt) template(opt) template-id
1289 cxx_pretty_printer::simple_type_specifier (tree t
)
1291 switch (TREE_CODE (t
))
1296 pp_cxx_qualified_id (this, t
);
1299 case TEMPLATE_TYPE_PARM
:
1300 case TEMPLATE_TEMPLATE_PARM
:
1301 case TEMPLATE_PARM_INDEX
:
1302 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1303 pp_cxx_unqualified_id (this, t
);
1307 pp_cxx_ws_string (this, "typename");
1308 pp_cxx_nested_name_specifier (this, TYPE_CONTEXT (t
));
1309 pp_cxx_unqualified_id (this, TYPE_NAME (t
));
1313 c_pretty_printer::simple_type_specifier (t
);
1318 /* type-specifier-seq:
1319 type-specifier type-specifier-seq(opt)
1322 simple-type-specifier
1325 elaborated-type-specifier
1329 pp_cxx_type_specifier_seq (cxx_pretty_printer
*pp
, tree t
)
1331 switch (TREE_CODE (t
))
1334 case TEMPLATE_TYPE_PARM
:
1335 case TEMPLATE_TEMPLATE_PARM
:
1337 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1338 pp_cxx_cv_qualifier_seq (pp
, t
);
1339 pp
->simple_type_specifier (t
);
1343 pp_cxx_type_specifier_seq (pp
, TREE_TYPE (t
));
1344 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (t
));
1345 pp_cxx_nested_name_specifier (pp
, TYPE_METHOD_BASETYPE (t
));
1349 pp_cxx_ws_string (pp
, "decltype");
1350 pp_cxx_left_paren (pp
);
1351 pp
->expression (DECLTYPE_TYPE_EXPR (t
));
1352 pp_cxx_right_paren (pp
);
1356 if (TYPE_PTRMEMFUNC_P (t
))
1358 tree pfm
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
1359 pp
->declaration_specifiers (TREE_TYPE (TREE_TYPE (pfm
)));
1360 pp_cxx_whitespace (pp
);
1361 pp_cxx_ptr_operator (pp
, t
);
1367 if (!(TREE_CODE (t
) == FUNCTION_DECL
&& DECL_CONSTRUCTOR_P (t
)))
1368 pp_c_specifier_qualifier_list (pp
, t
);
1373 * cv-qualifier-seq(opt)
1375 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1378 pp_cxx_ptr_operator (cxx_pretty_printer
*pp
, tree t
)
1380 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
1382 switch (TREE_CODE (t
))
1384 case REFERENCE_TYPE
:
1386 if (TYPE_PTR_OR_PTRMEM_P (TREE_TYPE (t
)))
1387 pp_cxx_ptr_operator (pp
, TREE_TYPE (t
));
1388 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (TREE_TYPE (t
)));
1392 pp_cxx_cv_qualifier_seq (pp
, t
);
1399 if (TYPE_PTRMEMFUNC_P (t
))
1401 pp_cxx_left_paren (pp
);
1402 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEMFUNC_OBJECT_TYPE (t
));
1408 if (TYPE_PTRMEM_P (t
))
1410 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1411 pp_cxx_left_paren (pp
);
1412 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEM_CLASS_TYPE (t
));
1414 pp_cxx_cv_qualifier_seq (pp
, t
);
1420 pp_unsupported_tree (pp
, t
);
1426 pp_cxx_implicit_parameter_type (tree mf
)
1428 return class_of_this_parm (TREE_TYPE (mf
));
1432 parameter-declaration:
1433 decl-specifier-seq declarator
1434 decl-specifier-seq declarator = assignment-expression
1435 decl-specifier-seq abstract-declarator(opt)
1436 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1439 pp_cxx_parameter_declaration (cxx_pretty_printer
*pp
, tree t
)
1441 pp
->declaration_specifiers (t
);
1443 pp
->abstract_declarator (t
);
1448 /* parameter-declaration-clause:
1449 parameter-declaration-list(opt) ...(opt)
1450 parameter-declaration-list , ...
1452 parameter-declaration-list:
1453 parameter-declaration
1454 parameter-declaration-list , parameter-declaration */
1457 pp_cxx_parameter_declaration_clause (cxx_pretty_printer
*pp
, tree t
)
1463 // For a requires clause or the explicit printing of a parameter list
1464 // we expect T to be a chain of PARM_DECLs. Otherwise, the list of
1465 // args and types are taken from the function decl T.
1466 if (TREE_CODE (t
) == PARM_DECL
)
1474 bool type_p
= TYPE_P (t
);
1475 args
= type_p
? NULL
: FUNCTION_FIRST_USER_PARM (t
);
1476 types
= type_p
? TYPE_ARG_TYPES (t
) : FUNCTION_FIRST_USER_PARMTYPE (t
);
1477 abstract
= args
== NULL
|| pp
->flags
& pp_c_flag_abstract
;
1481 /* Skip artificial parameter for nonstatic member functions. */
1482 if (TREE_CODE (t
) == METHOD_TYPE
)
1483 types
= TREE_CHAIN (types
);
1485 pp_cxx_left_paren (pp
);
1486 for (; args
; args
= TREE_CHAIN (args
), types
= TREE_CHAIN (types
))
1489 pp_cxx_separate_with (pp
, ',');
1491 pp_cxx_parameter_declaration (pp
, abstract
? TREE_VALUE (types
) : args
);
1492 if (!abstract
&& pp
->flags
& pp_cxx_flag_default_argument
)
1494 pp_cxx_whitespace (pp
);
1496 pp_cxx_whitespace (pp
);
1497 pp
->assignment_expression (TREE_PURPOSE (types
));
1500 pp_cxx_right_paren (pp
);
1503 /* exception-specification:
1504 throw ( type-id-list(opt) )
1508 type-id-list , type-id */
1511 pp_cxx_exception_specification (cxx_pretty_printer
*pp
, tree t
)
1513 tree ex_spec
= TYPE_RAISES_EXCEPTIONS (t
);
1514 bool need_comma
= false;
1516 if (ex_spec
== NULL
)
1518 if (TREE_PURPOSE (ex_spec
))
1520 pp_cxx_ws_string (pp
, "noexcept");
1521 pp_cxx_whitespace (pp
);
1522 pp_cxx_left_paren (pp
);
1523 if (DEFERRED_NOEXCEPT_SPEC_P (ex_spec
))
1524 pp_cxx_ws_string (pp
, "<uninstantiated>");
1526 pp
->expression (TREE_PURPOSE (ex_spec
));
1527 pp_cxx_right_paren (pp
);
1530 pp_cxx_ws_string (pp
, "throw");
1531 pp_cxx_left_paren (pp
);
1532 for (; ex_spec
&& TREE_VALUE (ex_spec
); ex_spec
= TREE_CHAIN (ex_spec
))
1534 tree type
= TREE_VALUE (ex_spec
);
1535 tree argpack
= NULL_TREE
;
1538 if (ARGUMENT_PACK_P (type
))
1540 argpack
= ARGUMENT_PACK_ARGS (type
);
1541 len
= TREE_VEC_LENGTH (argpack
);
1544 for (i
= 0; i
< len
; ++i
)
1547 type
= TREE_VEC_ELT (argpack
, i
);
1550 pp_cxx_separate_with (pp
, ',');
1557 pp_cxx_right_paren (pp
);
1560 /* direct-declarator:
1562 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1563 exception-specification(opt)
1564 direct-declaration [ constant-expression(opt) ]
1568 cxx_pretty_printer::direct_declarator (tree t
)
1570 switch (TREE_CODE (t
))
1578 pp_cxx_space_for_pointer_operator (this, TREE_TYPE (t
));
1580 if ((TREE_CODE (t
) == PARM_DECL
&& DECL_PACK_P (t
))
1581 || template_parameter_pack_p (t
))
1582 /* A function parameter pack or non-type template
1584 pp_cxx_ws_string (this, "...");
1586 id_expression (DECL_NAME (t
));
1588 abstract_declarator (TREE_TYPE (t
));
1592 pp_cxx_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t
)));
1594 pp_cxx_parameter_declaration_clause (this, t
);
1596 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1598 padding
= pp_before
;
1599 pp_cxx_cv_qualifier_seq (this, pp_cxx_implicit_parameter_type (t
));
1602 pp_cxx_exception_specification (this, TREE_TYPE (t
));
1607 case TEMPLATE_TYPE_PARM
:
1608 case TEMPLATE_PARM_INDEX
:
1609 case TEMPLATE_TEMPLATE_PARM
:
1613 c_pretty_printer::direct_declarator (t
);
1620 ptr-operator declarator */
1623 cxx_pretty_printer::declarator (tree t
)
1625 direct_declarator (t
);
1627 // Print a requires clause.
1629 if (tree ci
= get_constraints (t
))
1630 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1631 pp_cxx_requires_clause (this, reqs
);
1634 /* ctor-initializer:
1635 : mem-initializer-list
1637 mem-initializer-list:
1639 mem-initializer , mem-initializer-list
1642 mem-initializer-id ( expression-list(opt) )
1645 ::(opt) nested-name-specifier(opt) class-name
1649 pp_cxx_ctor_initializer (cxx_pretty_printer
*pp
, tree t
)
1651 t
= TREE_OPERAND (t
, 0);
1652 pp_cxx_whitespace (pp
);
1654 pp_cxx_whitespace (pp
);
1655 for (; t
; t
= TREE_CHAIN (t
))
1657 tree purpose
= TREE_PURPOSE (t
);
1658 bool is_pack
= PACK_EXPANSION_P (purpose
);
1661 pp
->primary_expression (PACK_EXPANSION_PATTERN (purpose
));
1663 pp
->primary_expression (purpose
);
1664 pp_cxx_call_argument_list (pp
, TREE_VALUE (t
));
1666 pp_cxx_ws_string (pp
, "...");
1668 pp_cxx_separate_with (pp
, ',');
1672 /* function-definition:
1673 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1674 decl-specifier-seq(opt) declarator function-try-block */
1677 pp_cxx_function_definition (cxx_pretty_printer
*pp
, tree t
)
1679 tree saved_scope
= pp
->enclosing_scope
;
1680 pp
->declaration_specifiers (t
);
1682 pp_needs_newline (pp
) = true;
1683 pp
->enclosing_scope
= DECL_CONTEXT (t
);
1684 if (DECL_SAVED_TREE (t
))
1685 pp
->statement (DECL_SAVED_TREE (t
));
1687 pp_cxx_semicolon (pp
);
1688 pp_newline_and_flush (pp
);
1689 pp
->enclosing_scope
= saved_scope
;
1692 /* abstract-declarator:
1693 ptr-operator abstract-declarator(opt)
1694 direct-abstract-declarator */
1697 cxx_pretty_printer::abstract_declarator (tree t
)
1699 if (TYPE_PTRMEM_P (t
))
1700 pp_cxx_right_paren (this);
1701 else if (POINTER_TYPE_P (t
))
1703 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
1704 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1705 pp_cxx_right_paren (this);
1708 direct_abstract_declarator (t
);
1711 /* direct-abstract-declarator:
1712 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1713 cv-qualifier-seq(opt) exception-specification(opt)
1714 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1715 ( abstract-declarator ) */
1718 cxx_pretty_printer::direct_abstract_declarator (tree t
)
1720 switch (TREE_CODE (t
))
1722 case REFERENCE_TYPE
:
1723 abstract_declarator (t
);
1727 if (TYPE_PTRMEMFUNC_P (t
))
1728 direct_abstract_declarator (TYPE_PTRMEMFUNC_FN_TYPE (t
));
1733 pp_cxx_parameter_declaration_clause (this, t
);
1734 direct_abstract_declarator (TREE_TYPE (t
));
1735 if (TREE_CODE (t
) == METHOD_TYPE
)
1737 padding
= pp_before
;
1738 pp_cxx_cv_qualifier_seq (this, class_of_this_parm (t
));
1740 pp_cxx_exception_specification (this, t
);
1744 case TEMPLATE_TYPE_PARM
:
1745 case TEMPLATE_TEMPLATE_PARM
:
1746 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1747 case UNBOUND_CLASS_TEMPLATE
:
1751 c_pretty_printer::direct_abstract_declarator (t
);
1757 type-specifier-seq abstract-declarator(opt) */
1760 cxx_pretty_printer::type_id (tree t
)
1762 pp_flags saved_flags
= flags
;
1763 flags
|= pp_c_flag_abstract
;
1765 switch (TREE_CODE (t
))
1772 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1773 case UNBOUND_CLASS_TEMPLATE
:
1774 case TEMPLATE_TEMPLATE_PARM
:
1775 case TEMPLATE_TYPE_PARM
:
1776 case TEMPLATE_PARM_INDEX
:
1779 case UNDERLYING_TYPE
:
1781 case TEMPLATE_ID_EXPR
:
1782 pp_cxx_type_specifier_seq (this, t
);
1785 case TYPE_PACK_EXPANSION
:
1786 type_id (PACK_EXPANSION_PATTERN (t
));
1787 pp_cxx_ws_string (this, "...");
1791 c_pretty_printer::type_id (t
);
1795 flags
= saved_flags
;
1798 /* template-argument-list:
1799 template-argument ...(opt)
1800 template-argument-list, template-argument ...(opt)
1803 assignment-expression
1808 pp_cxx_template_argument_list (cxx_pretty_printer
*pp
, tree t
)
1811 bool need_comma
= false;
1815 for (i
= 0; i
< TREE_VEC_LENGTH (t
); ++i
)
1817 tree arg
= TREE_VEC_ELT (t
, i
);
1818 tree argpack
= NULL_TREE
;
1821 if (ARGUMENT_PACK_P (arg
))
1823 argpack
= ARGUMENT_PACK_ARGS (arg
);
1824 len
= TREE_VEC_LENGTH (argpack
);
1827 for (idx
= 0; idx
< len
; idx
++)
1830 arg
= TREE_VEC_ELT (argpack
, idx
);
1833 pp_cxx_separate_with (pp
, ',');
1837 if (TYPE_P (arg
) || (TREE_CODE (arg
) == TEMPLATE_DECL
1838 && TYPE_P (DECL_TEMPLATE_RESULT (arg
))))
1841 pp
->expression (arg
);
1848 pp_cxx_exception_declaration (cxx_pretty_printer
*pp
, tree t
)
1850 t
= DECL_EXPR_DECL (t
);
1851 pp_cxx_type_specifier_seq (pp
, t
);
1853 pp
->abstract_declarator (t
);
1861 cxx_pretty_printer::statement (tree t
)
1863 switch (TREE_CODE (t
))
1865 case CTOR_INITIALIZER
:
1866 pp_cxx_ctor_initializer (this, t
);
1870 pp_cxx_ws_string (this, "using");
1871 pp_cxx_ws_string (this, "namespace");
1872 if (DECL_CONTEXT (t
))
1873 pp_cxx_nested_name_specifier (this, DECL_CONTEXT (t
));
1874 pp_cxx_qualified_id (this, USING_STMT_NAMESPACE (t
));
1878 pp_cxx_ws_string (this, "using");
1879 pp_cxx_nested_name_specifier (this, USING_DECL_SCOPE (t
));
1880 pp_cxx_unqualified_id (this, DECL_NAME (t
));
1887 try compound-statement handler-seq */
1889 pp_maybe_newline_and_indent (this, 0);
1890 pp_cxx_ws_string (this, "try");
1891 pp_newline_and_indent (this, 3);
1892 statement (TRY_STMTS (t
));
1893 pp_newline_and_indent (this, -3);
1897 statement (TRY_HANDLERS (t
));
1902 handler handler-seq(opt)
1905 catch ( exception-declaration ) compound-statement
1907 exception-declaration:
1908 type-specifier-seq declarator
1909 type-specifier-seq abstract-declarator
1912 pp_cxx_ws_string (this, "catch");
1913 pp_cxx_left_paren (this);
1914 pp_cxx_exception_declaration (this, HANDLER_PARMS (t
));
1915 pp_cxx_right_paren (this);
1916 pp_indentation (this) += 3;
1917 pp_needs_newline (this) = true;
1918 statement (HANDLER_BODY (t
));
1919 pp_indentation (this) -= 3;
1920 pp_needs_newline (this) = true;
1923 /* selection-statement:
1924 if ( expression ) statement
1925 if ( expression ) statement else statement */
1927 pp_cxx_ws_string (this, "if");
1928 pp_cxx_whitespace (this);
1929 pp_cxx_left_paren (this);
1930 expression (IF_COND (t
));
1931 pp_cxx_right_paren (this);
1932 pp_newline_and_indent (this, 2);
1933 statement (THEN_CLAUSE (t
));
1934 pp_newline_and_indent (this, -2);
1935 if (ELSE_CLAUSE (t
))
1937 tree else_clause
= ELSE_CLAUSE (t
);
1938 pp_cxx_ws_string (this, "else");
1939 if (TREE_CODE (else_clause
) == IF_STMT
)
1940 pp_cxx_whitespace (this);
1942 pp_newline_and_indent (this, 2);
1943 statement (else_clause
);
1944 if (TREE_CODE (else_clause
) != IF_STMT
)
1945 pp_newline_and_indent (this, -2);
1950 pp_cxx_ws_string (this, "switch");
1952 pp_cxx_left_paren (this);
1953 expression (SWITCH_STMT_COND (t
));
1954 pp_cxx_right_paren (this);
1955 pp_indentation (this) += 3;
1956 pp_needs_newline (this) = true;
1957 statement (SWITCH_STMT_BODY (t
));
1958 pp_newline_and_indent (this, -3);
1961 /* iteration-statement:
1962 while ( expression ) statement
1963 do statement while ( expression ) ;
1964 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1965 for ( declaration expression(opt) ; expression(opt) ) statement */
1967 pp_cxx_ws_string (this, "while");
1969 pp_cxx_left_paren (this);
1970 expression (WHILE_COND (t
));
1971 pp_cxx_right_paren (this);
1972 pp_newline_and_indent (this, 3);
1973 statement (WHILE_BODY (t
));
1974 pp_indentation (this) -= 3;
1975 pp_needs_newline (this) = true;
1979 pp_cxx_ws_string (this, "do");
1980 pp_newline_and_indent (this, 3);
1981 statement (DO_BODY (t
));
1982 pp_newline_and_indent (this, -3);
1983 pp_cxx_ws_string (this, "while");
1985 pp_cxx_left_paren (this);
1986 expression (DO_COND (t
));
1987 pp_cxx_right_paren (this);
1988 pp_cxx_semicolon (this);
1989 pp_needs_newline (this) = true;
1993 pp_cxx_ws_string (this, "for");
1995 pp_cxx_left_paren (this);
1996 if (FOR_INIT_STMT (t
))
1997 statement (FOR_INIT_STMT (t
));
1999 pp_cxx_semicolon (this);
2000 pp_needs_newline (this) = false;
2001 pp_cxx_whitespace (this);
2003 expression (FOR_COND (t
));
2004 pp_cxx_semicolon (this);
2005 pp_needs_newline (this) = false;
2006 pp_cxx_whitespace (this);
2008 expression (FOR_EXPR (t
));
2009 pp_cxx_right_paren (this);
2010 pp_newline_and_indent (this, 3);
2011 statement (FOR_BODY (t
));
2012 pp_indentation (this) -= 3;
2013 pp_needs_newline (this) = true;
2016 case RANGE_FOR_STMT
:
2017 pp_cxx_ws_string (this, "for");
2019 pp_cxx_left_paren (this);
2020 statement (RANGE_FOR_DECL (t
));
2022 pp_needs_newline (this) = false;
2025 statement (RANGE_FOR_EXPR (t
));
2026 pp_cxx_right_paren (this);
2027 pp_newline_and_indent (this, 3);
2028 statement (FOR_BODY (t
));
2029 pp_indentation (this) -= 3;
2030 pp_needs_newline (this) = true;
2036 return expression(opt) ; */
2039 pp_string (this, TREE_CODE (t
) == BREAK_STMT
? "break" : "continue");
2040 pp_cxx_semicolon (this);
2041 pp_needs_newline (this) = true;
2044 /* expression-statement:
2045 expression(opt) ; */
2047 expression (EXPR_STMT_EXPR (t
));
2048 pp_cxx_semicolon (this);
2049 pp_needs_newline (this) = true;
2053 pp_cxx_ws_string (this, "try");
2054 pp_newline_and_indent (this, 2);
2055 statement (CLEANUP_BODY (t
));
2056 pp_newline_and_indent (this, -2);
2057 pp_cxx_ws_string (this, CLEANUP_EH_ONLY (t
) ? "catch" : "finally");
2058 pp_newline_and_indent (this, 2);
2059 statement (CLEANUP_EXPR (t
));
2060 pp_newline_and_indent (this, -2);
2068 c_pretty_printer::statement (t
);
2073 /* original-namespace-definition:
2074 namespace identifier { namespace-body }
2076 As an edge case, we also handle unnamed namespace definition here. */
2079 pp_cxx_original_namespace_definition (cxx_pretty_printer
*pp
, tree t
)
2081 pp_cxx_ws_string (pp
, "namespace");
2082 if (DECL_CONTEXT (t
))
2083 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
2085 pp_cxx_unqualified_id (pp
, t
);
2086 pp_cxx_whitespace (pp
);
2087 pp_cxx_left_brace (pp
);
2088 /* We do not print the namespace-body. */
2089 pp_cxx_whitespace (pp
);
2090 pp_cxx_right_brace (pp
);
2096 namespace-alias-definition:
2097 namespace identifier = qualified-namespace-specifier ;
2099 qualified-namespace-specifier:
2100 ::(opt) nested-name-specifier(opt) namespace-name */
2103 pp_cxx_namespace_alias_definition (cxx_pretty_printer
*pp
, tree t
)
2105 pp_cxx_ws_string (pp
, "namespace");
2106 if (DECL_CONTEXT (t
))
2107 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
2108 pp_cxx_unqualified_id (pp
, t
);
2109 pp_cxx_whitespace (pp
);
2111 pp_cxx_whitespace (pp
);
2112 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t
)))
2113 pp_cxx_nested_name_specifier (pp
,
2114 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t
)));
2115 pp_cxx_qualified_id (pp
, DECL_NAMESPACE_ALIAS (t
));
2116 pp_cxx_semicolon (pp
);
2119 /* simple-declaration:
2120 decl-specifier-seq(opt) init-declarator-list(opt) */
2123 pp_cxx_simple_declaration (cxx_pretty_printer
*pp
, tree t
)
2125 pp
->declaration_specifiers (t
);
2126 pp_cxx_init_declarator (pp
, t
);
2127 pp_cxx_semicolon (pp
);
2128 pp_needs_newline (pp
) = true;
2132 template-parameter-list:
2134 template-parameter-list , template-parameter */
2137 pp_cxx_template_parameter_list (cxx_pretty_printer
*pp
, tree t
)
2139 const int n
= TREE_VEC_LENGTH (t
);
2141 for (i
= 0; i
< n
; ++i
)
2144 pp_cxx_separate_with (pp
, ',');
2145 pp_cxx_template_parameter (pp
, TREE_VEC_ELT (t
, i
));
2149 /* template-parameter:
2151 parameter-declaration
2154 class ...(opt) identifier(opt)
2155 class identifier(opt) = type-id
2156 typename identifier(opt)
2157 typename ...(opt) identifier(opt) = type-id
2158 template < template-parameter-list > class ...(opt) identifier(opt)
2159 template < template-parameter-list > class identifier(opt) = template-name */
2162 pp_cxx_template_parameter (cxx_pretty_printer
*pp
, tree t
)
2164 tree parameter
= TREE_VALUE (t
);
2165 switch (TREE_CODE (parameter
))
2168 pp_cxx_ws_string (pp
, "class");
2169 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
2170 pp_cxx_ws_string (pp
, "...");
2171 if (DECL_NAME (parameter
))
2172 pp_cxx_tree_identifier (pp
, DECL_NAME (parameter
));
2173 /* FIXME: Check if we should print also default argument. */
2177 pp_cxx_parameter_declaration (pp
, parameter
);
2184 pp_unsupported_tree (pp
, t
);
2189 /* Pretty-print a template parameter in the canonical form
2190 "template-parameter-<level>-<position in parameter list>". */
2193 pp_cxx_canonical_template_parameter (cxx_pretty_printer
*pp
, tree parm
)
2195 const enum tree_code code
= TREE_CODE (parm
);
2197 /* Brings type template parameters to the canonical forms. */
2198 if (code
== TEMPLATE_TYPE_PARM
|| code
== TEMPLATE_TEMPLATE_PARM
2199 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
)
2200 parm
= TEMPLATE_TYPE_PARM_INDEX (parm
);
2202 pp_cxx_begin_template_argument_list (pp
);
2203 pp
->translate_string ("template-parameter-");
2204 pp_wide_integer (pp
, TEMPLATE_PARM_LEVEL (parm
));
2206 pp_wide_integer (pp
, TEMPLATE_PARM_IDX (parm
) + 1);
2207 pp_cxx_end_template_argument_list (pp
);
2210 /* Print a constrained-type-specifier. */
2213 pp_cxx_constrained_type_spec (cxx_pretty_printer
*pp
, tree c
)
2216 if (c
== error_mark_node
)
2218 pp_cxx_ws_string(pp
, "<unsatisfied-constrained-placeholder>");
2221 placeholder_extract_concept_and_args (c
, t
, a
);
2222 pp
->id_expression (t
);
2223 if (TREE_VEC_LENGTH (a
) > 1)
2225 pp_cxx_begin_template_argument_list (pp
);
2226 tree args
= make_tree_vec (TREE_VEC_LENGTH (a
) - 1);
2227 for (int i
= TREE_VEC_LENGTH (a
) - 1; i
> 0; --i
)
2228 TREE_VEC_ELT (args
, i
-1) = TREE_VEC_ELT (a
, i
);
2229 pp_cxx_template_argument_list (pp
, args
);
2231 pp_cxx_end_template_argument_list (pp
);
2236 template-declaration:
2237 export(opt) template < template-parameter-list > declaration
2241 template-declaration:
2242 export(opt) template < template-parameter-list >
2243 requires-clause(opt) declaration */
2246 pp_cxx_template_declaration (cxx_pretty_printer
*pp
, tree t
)
2248 tree tmpl
= most_general_template (t
);
2251 pp_maybe_newline_and_indent (pp
, 0);
2252 for (level
= DECL_TEMPLATE_PARMS (tmpl
); level
; level
= TREE_CHAIN (level
))
2254 pp_cxx_ws_string (pp
, "template");
2255 pp_cxx_begin_template_argument_list (pp
);
2256 pp_cxx_template_parameter_list (pp
, TREE_VALUE (level
));
2257 pp_cxx_end_template_argument_list (pp
);
2258 pp_newline_and_indent (pp
, 3);
2262 if (tree ci
= get_constraints (t
))
2263 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
2265 pp_cxx_requires_clause (pp
, reqs
);
2266 pp_newline_and_indent (pp
, 6);
2269 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_SAVED_TREE (t
))
2270 pp_cxx_function_definition (pp
, t
);
2272 pp_cxx_simple_declaration (pp
, t
);
2276 pp_cxx_explicit_specialization (cxx_pretty_printer
*pp
, tree t
)
2278 pp_unsupported_tree (pp
, t
);
2282 pp_cxx_explicit_instantiation (cxx_pretty_printer
*pp
, tree t
)
2284 pp_unsupported_tree (pp
, t
);
2291 template-declaration
2292 explicit-instantiation
2293 explicit-specialization
2294 linkage-specification
2295 namespace-definition
2300 namespace-alias-definition
2303 static_assert-declaration */
2305 cxx_pretty_printer::declaration (tree t
)
2307 if (TREE_CODE (t
) == STATIC_ASSERT
)
2309 pp_cxx_ws_string (this, "static_assert");
2310 pp_cxx_left_paren (this);
2311 expression (STATIC_ASSERT_CONDITION (t
));
2312 pp_cxx_separate_with (this, ',');
2313 expression (STATIC_ASSERT_MESSAGE (t
));
2314 pp_cxx_right_paren (this);
2316 else if (!DECL_LANG_SPECIFIC (t
))
2317 pp_cxx_simple_declaration (this, t
);
2318 else if (DECL_USE_TEMPLATE (t
))
2319 switch (DECL_USE_TEMPLATE (t
))
2322 pp_cxx_template_declaration (this, t
);
2326 pp_cxx_explicit_specialization (this, t
);
2330 pp_cxx_explicit_instantiation (this, t
);
2336 else switch (TREE_CODE (t
))
2340 pp_cxx_simple_declaration (this, t
);
2344 if (DECL_SAVED_TREE (t
))
2345 pp_cxx_function_definition (this, t
);
2347 pp_cxx_simple_declaration (this, t
);
2350 case NAMESPACE_DECL
:
2351 if (DECL_NAMESPACE_ALIAS (t
))
2352 pp_cxx_namespace_alias_definition (this, t
);
2354 pp_cxx_original_namespace_definition (this, t
);
2358 pp_unsupported_tree (this, t
);
2364 pp_cxx_typeid_expression (cxx_pretty_printer
*pp
, tree t
)
2366 t
= TREE_OPERAND (t
, 0);
2367 pp_cxx_ws_string (pp
, "typeid");
2368 pp_cxx_left_paren (pp
);
2373 pp_cxx_right_paren (pp
);
2377 pp_cxx_va_arg_expression (cxx_pretty_printer
*pp
, tree t
)
2379 pp_cxx_ws_string (pp
, "va_arg");
2380 pp_cxx_left_paren (pp
);
2381 pp
->assignment_expression (TREE_OPERAND (t
, 0));
2382 pp_cxx_separate_with (pp
, ',');
2383 pp
->type_id (TREE_TYPE (t
));
2384 pp_cxx_right_paren (pp
);
2388 pp_cxx_offsetof_expression_1 (cxx_pretty_printer
*pp
, tree t
)
2390 switch (TREE_CODE (t
))
2393 if (TREE_CODE (TREE_OPERAND (t
, 0)) == STATIC_CAST_EXPR
2394 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (t
, 0))))
2396 pp
->type_id (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))));
2397 pp_cxx_separate_with (pp
, ',');
2402 if (!pp_cxx_offsetof_expression_1 (pp
, TREE_OPERAND (t
, 0)))
2404 if (TREE_CODE (TREE_OPERAND (t
, 0)) != ARROW_EXPR
)
2406 pp
->expression (TREE_OPERAND (t
, 1));
2409 if (!pp_cxx_offsetof_expression_1 (pp
, TREE_OPERAND (t
, 0)))
2411 pp_left_bracket (pp
);
2412 pp
->expression (TREE_OPERAND (t
, 1));
2413 pp_right_bracket (pp
);
2421 pp_cxx_offsetof_expression (cxx_pretty_printer
*pp
, tree t
)
2423 pp_cxx_ws_string (pp
, "offsetof");
2424 pp_cxx_left_paren (pp
);
2425 if (!pp_cxx_offsetof_expression_1 (pp
, TREE_OPERAND (t
, 0)))
2426 pp
->expression (TREE_OPERAND (t
, 0));
2427 pp_cxx_right_paren (pp
);
2431 pp_cxx_addressof_expression (cxx_pretty_printer
*pp
, tree t
)
2433 pp_cxx_ws_string (pp
, "__builtin_addressof");
2434 pp_cxx_left_paren (pp
);
2435 pp
->expression (TREE_OPERAND (t
, 0));
2436 pp_cxx_right_paren (pp
);
2440 get_fold_operator (tree t
)
2442 int op
= int_cst_value (FOLD_EXPR_OP (t
));
2443 if (FOLD_EXPR_MODIFY_P (t
))
2447 case NOP_EXPR
: return "=";
2448 case PLUS_EXPR
: return "+=";
2449 case MINUS_EXPR
: return "-=";
2450 case MULT_EXPR
: return "*=";
2451 case TRUNC_DIV_EXPR
: return "/=";
2452 case TRUNC_MOD_EXPR
: return "%=";
2453 case BIT_XOR_EXPR
: return "^=";
2454 case BIT_AND_EXPR
: return "&=";
2455 case BIT_IOR_EXPR
: return "|=";
2456 case LSHIFT_EXPR
: return "<<=";
2457 case RSHIFT_EXPR
: return ">>=";
2458 default: gcc_unreachable ();
2465 case PLUS_EXPR
: return "+";
2466 case MINUS_EXPR
: return "-";
2467 case MULT_EXPR
: return "*";
2468 case TRUNC_DIV_EXPR
: return "/";
2469 case TRUNC_MOD_EXPR
: return "%";
2470 case BIT_XOR_EXPR
: return "^";
2471 case BIT_AND_EXPR
: return "&";
2472 case BIT_IOR_EXPR
: return "|";
2473 case LSHIFT_EXPR
: return "<<";
2474 case RSHIFT_EXPR
: return ">>";
2475 case EQ_EXPR
: return "==";
2476 case NE_EXPR
: return "!=";
2477 case LT_EXPR
: return "<";
2478 case GT_EXPR
: return ">";
2479 case LE_EXPR
: return "<=";
2480 case GE_EXPR
: return ">=";
2481 case TRUTH_ANDIF_EXPR
: return "&&";
2482 case TRUTH_ORIF_EXPR
: return "||";
2483 case MEMBER_REF
: return "->*";
2484 case DOTSTAR_EXPR
: return ".*";
2485 case OFFSET_REF
: return ".*";
2486 default: return ","; /* FIXME: Not the right default. */
2492 pp_cxx_unary_left_fold_expression (cxx_pretty_printer
*pp
, tree t
)
2494 char const* op
= get_fold_operator (t
);
2495 tree expr
= PACK_EXPANSION_PATTERN (FOLD_EXPR_PACK (t
));
2496 pp_cxx_left_paren (pp
);
2497 pp_cxx_ws_string (pp
, "...");
2498 pp_cxx_ws_string (pp
, op
);
2499 pp
->expression (expr
);
2500 pp_cxx_right_paren (pp
);
2504 pp_cxx_unary_right_fold_expression (cxx_pretty_printer
*pp
, tree t
)
2506 char const* op
= get_fold_operator (t
);
2507 tree expr
= PACK_EXPANSION_PATTERN (FOLD_EXPR_PACK (t
));
2508 pp_cxx_left_paren (pp
);
2509 pp
->expression (expr
);
2511 pp_cxx_ws_string (pp
, op
);
2512 pp_cxx_ws_string (pp
, "...");
2513 pp_cxx_right_paren (pp
);
2517 pp_cxx_binary_fold_expression (cxx_pretty_printer
*pp
, tree t
)
2519 char const* op
= get_fold_operator (t
);
2520 tree t1
= TREE_OPERAND (t
, 1);
2521 tree t2
= TREE_OPERAND (t
, 2);
2522 if (t1
== FOLD_EXPR_PACK (t
))
2523 t1
= PACK_EXPANSION_PATTERN (t1
);
2525 t2
= PACK_EXPANSION_PATTERN (t2
);
2526 pp_cxx_left_paren (pp
);
2527 pp
->expression (t1
);
2528 pp_cxx_ws_string (pp
, op
);
2529 pp_cxx_ws_string (pp
, "...");
2530 pp_cxx_ws_string (pp
, op
);
2531 pp
->expression (t2
);
2532 pp_cxx_right_paren (pp
);
2536 pp_cxx_trait_expression (cxx_pretty_printer
*pp
, tree t
)
2538 cp_trait_kind kind
= TRAIT_EXPR_KIND (t
);
2542 case CPTK_HAS_NOTHROW_ASSIGN
:
2543 pp_cxx_ws_string (pp
, "__has_nothrow_assign");
2545 case CPTK_HAS_TRIVIAL_ASSIGN
:
2546 pp_cxx_ws_string (pp
, "__has_trivial_assign");
2548 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
2549 pp_cxx_ws_string (pp
, "__has_nothrow_constructor");
2551 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
2552 pp_cxx_ws_string (pp
, "__has_trivial_constructor");
2554 case CPTK_HAS_NOTHROW_COPY
:
2555 pp_cxx_ws_string (pp
, "__has_nothrow_copy");
2557 case CPTK_HAS_TRIVIAL_COPY
:
2558 pp_cxx_ws_string (pp
, "__has_trivial_copy");
2560 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
2561 pp_cxx_ws_string (pp
, "__has_trivial_destructor");
2563 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
2564 pp_cxx_ws_string (pp
, "__has_unique_object_representations");
2566 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
2567 pp_cxx_ws_string (pp
, "__has_virtual_destructor");
2569 case CPTK_IS_ABSTRACT
:
2570 pp_cxx_ws_string (pp
, "__is_abstract");
2572 case CPTK_IS_AGGREGATE
:
2573 pp_cxx_ws_string (pp
, "__is_aggregate");
2575 case CPTK_IS_BASE_OF
:
2576 pp_cxx_ws_string (pp
, "__is_base_of");
2579 pp_cxx_ws_string (pp
, "__is_class");
2582 pp_cxx_ws_string (pp
, "__is_empty");
2585 pp_cxx_ws_string (pp
, "__is_enum");
2588 pp_cxx_ws_string (pp
, "__is_final");
2591 pp_cxx_ws_string (pp
, "__is_pod");
2593 case CPTK_IS_POLYMORPHIC
:
2594 pp_cxx_ws_string (pp
, "__is_polymorphic");
2596 case CPTK_IS_SAME_AS
:
2597 pp_cxx_ws_string (pp
, "__is_same_as");
2599 case CPTK_IS_STD_LAYOUT
:
2600 pp_cxx_ws_string (pp
, "__is_std_layout");
2602 case CPTK_IS_TRIVIAL
:
2603 pp_cxx_ws_string (pp
, "__is_trivial");
2605 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
2606 pp_cxx_ws_string (pp
, "__is_trivially_assignable");
2608 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
2609 pp_cxx_ws_string (pp
, "__is_trivially_constructible");
2611 case CPTK_IS_TRIVIALLY_COPYABLE
:
2612 pp_cxx_ws_string (pp
, "__is_trivially_copyable");
2615 pp_cxx_ws_string (pp
, "__is_union");
2617 case CPTK_IS_LITERAL_TYPE
:
2618 pp_cxx_ws_string (pp
, "__is_literal_type");
2620 case CPTK_IS_ASSIGNABLE
:
2621 pp_cxx_ws_string (pp
, "__is_assignable");
2623 case CPTK_IS_CONSTRUCTIBLE
:
2624 pp_cxx_ws_string (pp
, "__is_constructible");
2631 pp_cxx_left_paren (pp
);
2632 pp
->type_id (TRAIT_EXPR_TYPE1 (t
));
2634 if (kind
== CPTK_IS_BASE_OF
|| kind
== CPTK_IS_SAME_AS
)
2636 pp_cxx_separate_with (pp
, ',');
2637 pp
->type_id (TRAIT_EXPR_TYPE2 (t
));
2640 pp_cxx_right_paren (pp
);
2644 // 'requires' logical-or-expression
2646 pp_cxx_requires_clause (cxx_pretty_printer
*pp
, tree t
)
2650 pp
->padding
= pp_before
;
2651 pp_cxx_ws_string (pp
, "requires");
2658 compound-requirement
2660 nested-requirement */
2662 pp_cxx_requirement (cxx_pretty_printer
*pp
, tree t
)
2664 switch (TREE_CODE (t
))
2667 pp_cxx_simple_requirement (pp
, t
);
2671 pp_cxx_type_requirement (pp
, t
);
2675 pp_cxx_compound_requirement (pp
, t
);
2679 pp_cxx_nested_requirement (pp
, t
);
2687 // requirement-list:
2689 // requirement-list ';' requirement[opt]
2692 pp_cxx_requirement_list (cxx_pretty_printer
*pp
, tree t
)
2694 for (; t
; t
= TREE_CHAIN (t
))
2695 pp_cxx_requirement (pp
, TREE_VALUE (t
));
2698 // requirement-body:
2699 // '{' requirement-list '}'
2701 pp_cxx_requirement_body (cxx_pretty_printer
*pp
, tree t
)
2703 pp_cxx_left_brace (pp
);
2704 pp_cxx_requirement_list (pp
, t
);
2705 pp_cxx_right_brace (pp
);
2708 // requires-expression:
2709 // 'requires' requirement-parameter-list requirement-body
2711 pp_cxx_requires_expr (cxx_pretty_printer
*pp
, tree t
)
2713 pp_string (pp
, "requires");
2714 if (tree parms
= TREE_OPERAND (t
, 0))
2716 pp_cxx_parameter_declaration_clause (pp
, parms
);
2717 pp_cxx_whitespace (pp
);
2719 pp_cxx_requirement_body (pp
, TREE_OPERAND (t
, 1));
2722 /* simple-requirement:
2725 pp_cxx_simple_requirement (cxx_pretty_printer
*pp
, tree t
)
2727 pp
->expression (TREE_OPERAND (t
, 0));
2728 pp_cxx_semicolon (pp
);
2731 /* type-requirement:
2732 typename type-name ';' */
2734 pp_cxx_type_requirement (cxx_pretty_printer
*pp
, tree t
)
2736 pp
->type_id (TREE_OPERAND (t
, 0));
2737 pp_cxx_semicolon (pp
);
2740 /* compound-requirement:
2741 '{' expression '}' 'noexcept' [opt] trailing-return-type [opt] */
2743 pp_cxx_compound_requirement (cxx_pretty_printer
*pp
, tree t
)
2745 pp_cxx_left_brace (pp
);
2746 pp
->expression (TREE_OPERAND (t
, 0));
2747 pp_cxx_right_brace (pp
);
2749 if (COMPOUND_REQ_NOEXCEPT_P (t
))
2750 pp_cxx_ws_string (pp
, "noexcept");
2752 if (tree type
= TREE_OPERAND (t
, 1))
2754 pp_cxx_ws_string (pp
, "->");
2757 pp_cxx_semicolon (pp
);
2760 /* nested requirement:
2761 'requires' constraint-expression */
2763 pp_cxx_nested_requirement (cxx_pretty_printer
*pp
, tree t
)
2765 pp_cxx_ws_string (pp
, "requires");
2766 pp
->expression (TREE_OPERAND (t
, 0));
2767 pp_cxx_semicolon (pp
);
2771 pp_cxx_predicate_constraint (cxx_pretty_printer
*pp
, tree t
)
2773 pp
->expression (TREE_OPERAND (t
, 0));
2777 pp_cxx_check_constraint (cxx_pretty_printer
*pp
, tree t
)
2779 tree decl
= CHECK_CONSTR_CONCEPT (t
);
2780 tree tmpl
= DECL_TI_TEMPLATE (decl
);
2781 tree args
= CHECK_CONSTR_ARGS (t
);
2782 tree id
= build_nt (TEMPLATE_ID_EXPR
, tmpl
, args
);
2785 pp
->expression (id
);
2786 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2788 tree call
= build_vl_exp (CALL_EXPR
, 2);
2789 TREE_OPERAND (call
, 0) = integer_two_node
;
2790 TREE_OPERAND (call
, 1) = id
;
2791 pp
->expression (call
);
2798 pp_cxx_expression_constraint (cxx_pretty_printer
*pp
, tree t
)
2800 pp_string (pp
, "<valid-expression ");
2801 pp_cxx_left_paren (pp
);
2802 pp
->expression (TREE_OPERAND (t
, 0));
2803 pp_cxx_right_paren (pp
);
2804 pp_string (pp
, ">");
2808 pp_cxx_type_constraint (cxx_pretty_printer
*pp
, tree t
)
2810 pp_string (pp
, "<valid-type ");
2811 pp
->type_id (TREE_OPERAND (t
, 0));
2812 pp_string (pp
, ">");
2816 pp_cxx_implicit_conversion_constraint (cxx_pretty_printer
*pp
, tree t
)
2818 pp_string (pp
, "<implicitly-conversion ");
2819 pp_cxx_left_paren (pp
);
2820 pp
->expression (ICONV_CONSTR_EXPR (t
));
2821 pp_cxx_right_paren (pp
);
2822 pp_cxx_ws_string (pp
, "to");
2823 pp
->type_id (ICONV_CONSTR_TYPE (t
));
2824 pp_string (pp
, ">");
2828 pp_cxx_argument_deduction_constraint (cxx_pretty_printer
*pp
, tree t
)
2830 pp_string (pp
, "<argument-deduction ");
2831 pp_cxx_left_paren (pp
);
2832 pp
->expression (DEDUCT_CONSTR_EXPR (t
));
2833 pp_cxx_right_paren (pp
);
2834 pp_cxx_ws_string (pp
, "as");
2835 pp
->expression (DEDUCT_CONSTR_PATTERN (t
));
2836 pp_string (pp
, ">");
2840 pp_cxx_exception_constraint (cxx_pretty_printer
*pp
, tree t
)
2842 pp_cxx_ws_string (pp
, "noexcept");
2843 pp_cxx_whitespace (pp
);
2844 pp_cxx_left_paren (pp
);
2845 pp
->expression (TREE_OPERAND (t
, 0));
2846 pp_cxx_right_paren (pp
);
2850 pp_cxx_parameterized_constraint (cxx_pretty_printer
*pp
, tree t
)
2853 pp_string (pp
, "<requires ");
2854 if (tree parms
= PARM_CONSTR_PARMS (t
))
2856 pp_cxx_parameter_declaration_clause (pp
, parms
);
2857 pp_cxx_whitespace (pp
);
2859 pp_cxx_constraint (pp
, PARM_CONSTR_OPERAND (t
));
2860 pp_string (pp
, ">");
2864 pp_cxx_conjunction (cxx_pretty_printer
*pp
, tree t
)
2866 pp_cxx_constraint (pp
, TREE_OPERAND (t
, 0));
2867 pp_string (pp
, " and ");
2868 pp_cxx_constraint (pp
, TREE_OPERAND (t
, 1));
2872 pp_cxx_disjunction (cxx_pretty_printer
*pp
, tree t
)
2874 pp_cxx_constraint (pp
, TREE_OPERAND (t
, 0));
2875 pp_string (pp
, " or ");
2876 pp_cxx_constraint (pp
, TREE_OPERAND (t
, 1));
2880 pp_cxx_constraint (cxx_pretty_printer
*pp
, tree t
)
2882 if (t
== error_mark_node
)
2883 return pp
->expression (t
);
2885 switch (TREE_CODE (t
))
2888 pp_cxx_predicate_constraint (pp
, t
);
2892 pp_cxx_check_constraint (pp
, t
);
2896 pp_cxx_expression_constraint (pp
, t
);
2900 pp_cxx_type_constraint (pp
, t
);
2904 pp_cxx_implicit_conversion_constraint (pp
, t
);
2908 pp_cxx_argument_deduction_constraint (pp
, t
);
2912 pp_cxx_exception_constraint (pp
, t
);
2916 pp_cxx_parameterized_constraint (pp
, t
);
2920 pp_cxx_conjunction (pp
, t
);
2924 pp_cxx_disjunction (pp
, t
);
2927 case EXPR_PACK_EXPANSION
:
2928 pp
->expression (TREE_OPERAND (t
, 0));
2938 typedef c_pretty_print_fn pp_fun
;
2940 /* Initialization of a C++ pretty-printer object. */
2942 cxx_pretty_printer::cxx_pretty_printer ()
2943 : c_pretty_printer (),
2944 enclosing_scope (global_namespace
)
2946 type_specifier_seq
= (pp_fun
) pp_cxx_type_specifier_seq
;
2947 parameter_list
= (pp_fun
) pp_cxx_parameter_declaration_clause
;