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
);
904 multiplicative_expression (TREE_OPERAND (e
, 0));
906 if (code
== MULT_EXPR
)
908 else if (code
!= TRUNC_MOD_EXPR
)
913 pp_cxx_pm_expression (this, TREE_OPERAND (e
, 1));
917 pp_cxx_pm_expression (this, e
);
922 /* conditional-expression:
923 logical-or-expression
924 logical-or-expression ? expression : assignment-expression */
927 cxx_pretty_printer::conditional_expression (tree e
)
929 if (TREE_CODE (e
) == COND_EXPR
)
931 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
935 expression (TREE_OPERAND (e
, 1));
937 assignment_expression (TREE_OPERAND (e
, 2));
940 pp_c_logical_or_expression (this, e
);
943 /* Pretty-print a compound assignment operator token as indicated by T. */
946 pp_cxx_assignment_operator (cxx_pretty_printer
*pp
, tree t
)
950 switch (TREE_CODE (t
))
973 op
= get_tree_code_name (TREE_CODE (t
));
977 pp_cxx_ws_string (pp
, op
);
981 /* assignment-expression:
982 conditional-expression
983 logical-or-expression assignment-operator assignment-expression
987 throw assignment-expression(opt)
989 assignment-operator: one of
990 = *= /= %= += -= >>= <<= &= ^= |= */
993 cxx_pretty_printer::assignment_expression (tree e
)
995 switch (TREE_CODE (e
))
999 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
1003 assignment_expression (TREE_OPERAND (e
, 1));
1007 pp_cxx_ws_string (this, "throw");
1008 if (TREE_OPERAND (e
, 0))
1009 assignment_expression (TREE_OPERAND (e
, 0));
1013 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
1014 pp_cxx_assignment_operator (this, TREE_OPERAND (e
, 1));
1015 assignment_expression (TREE_OPERAND (e
, 2));
1019 conditional_expression (e
);
1025 cxx_pretty_printer::expression (tree t
)
1027 switch (TREE_CODE (t
))
1037 case USERDEF_LITERAL
:
1038 pp_cxx_userdef_literal (this, t
);
1042 pp_cxx_unqualified_id (this, t
);
1050 pp_cxx_qualified_id (this, t
);
1063 case TEMPLATE_TYPE_PARM
:
1064 case TEMPLATE_PARM_INDEX
:
1065 case TEMPLATE_TEMPLATE_PARM
:
1068 primary_expression (t
);
1072 case DYNAMIC_CAST_EXPR
:
1073 case STATIC_CAST_EXPR
:
1074 case REINTERPRET_CAST_EXPR
:
1075 case CONST_CAST_EXPR
:
1079 case EMPTY_CLASS_EXPR
:
1081 case PSEUDO_DTOR_EXPR
:
1082 case AGGR_INIT_EXPR
:
1084 postfix_expression (t
);
1089 pp_cxx_new_expression (this, t
);
1093 case VEC_DELETE_EXPR
:
1094 pp_cxx_delete_expression (this, t
);
1100 case UNARY_PLUS_EXPR
:
1101 unary_expression (t
);
1105 case IMPLICIT_CONV_EXPR
:
1106 pp_cxx_cast_expression (this, t
);
1112 pp_cxx_pm_expression (this, t
);
1116 case TRUNC_DIV_EXPR
:
1117 case TRUNC_MOD_EXPR
:
1118 case EXACT_DIV_EXPR
:
1120 multiplicative_expression (t
);
1124 conditional_expression (t
);
1131 assignment_expression (t
);
1134 case NON_DEPENDENT_EXPR
:
1135 case MUST_NOT_THROW_EXPR
:
1136 expression (TREE_OPERAND (t
, 0));
1139 case EXPR_PACK_EXPANSION
:
1140 expression (PACK_EXPANSION_PATTERN (t
));
1141 pp_cxx_ws_string (this, "...");
1144 case UNARY_LEFT_FOLD_EXPR
:
1145 pp_cxx_unary_left_fold_expression (this, t
);
1148 case UNARY_RIGHT_FOLD_EXPR
:
1149 pp_cxx_unary_right_fold_expression (this, t
);
1152 case BINARY_LEFT_FOLD_EXPR
:
1153 case BINARY_RIGHT_FOLD_EXPR
:
1154 pp_cxx_binary_fold_expression (this, t
);
1157 case TEMPLATE_ID_EXPR
:
1158 pp_cxx_template_id (this, t
);
1161 case NONTYPE_ARGUMENT_PACK
:
1163 tree args
= ARGUMENT_PACK_ARGS (t
);
1164 int i
, len
= TREE_VEC_LENGTH (args
);
1165 for (i
= 0; i
< len
; ++i
)
1168 pp_cxx_separate_with (this, ',');
1169 expression (TREE_VEC_ELT (args
, i
));
1175 pp_cxx_ws_string (this, "<lambda>");
1179 pp_cxx_trait_expression (this, t
);
1192 pp_cxx_constraint (this, t
);
1196 pp_cxx_left_paren (this);
1197 expression (TREE_OPERAND (t
, 0));
1198 pp_cxx_right_paren (this);
1202 c_pretty_printer::expression (t
);
1210 /* function-specifier:
1216 cxx_pretty_printer::function_specifier (tree t
)
1218 switch (TREE_CODE (t
))
1221 if (DECL_VIRTUAL_P (t
))
1222 pp_cxx_ws_string (this, "virtual");
1223 else if (DECL_CONSTRUCTOR_P (t
) && DECL_NONCONVERTING_P (t
))
1224 pp_cxx_ws_string (this, "explicit");
1226 c_pretty_printer::function_specifier (t
);
1233 /* decl-specifier-seq:
1234 decl-specifier-seq(opt) decl-specifier
1237 storage-class-specifier
1244 cxx_pretty_printer::declaration_specifiers (tree t
)
1246 switch (TREE_CODE (t
))
1252 storage_class_specifier (t
);
1253 declaration_specifiers (TREE_TYPE (t
));
1257 pp_cxx_ws_string (this, "typedef");
1258 declaration_specifiers (TREE_TYPE (t
));
1262 /* Constructors don't have return types. And conversion functions
1263 do not have a type-specifier in their return types. */
1264 if (DECL_CONSTRUCTOR_P (t
) || DECL_CONV_FN_P (t
))
1265 function_specifier (t
);
1266 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1267 declaration_specifiers (TREE_TYPE (TREE_TYPE (t
)));
1269 c_pretty_printer::declaration_specifiers (t
);
1272 c_pretty_printer::declaration_specifiers (t
);
1277 /* simple-type-specifier:
1278 ::(opt) nested-name-specifier(opt) type-name
1279 ::(opt) nested-name-specifier(opt) template(opt) template-id
1293 cxx_pretty_printer::simple_type_specifier (tree t
)
1295 switch (TREE_CODE (t
))
1300 pp_cxx_qualified_id (this, t
);
1303 case TEMPLATE_TYPE_PARM
:
1304 case TEMPLATE_TEMPLATE_PARM
:
1305 case TEMPLATE_PARM_INDEX
:
1306 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1307 pp_cxx_unqualified_id (this, t
);
1311 pp_cxx_ws_string (this, "typename");
1312 pp_cxx_nested_name_specifier (this, TYPE_CONTEXT (t
));
1313 pp_cxx_unqualified_id (this, TYPE_NAME (t
));
1317 c_pretty_printer::simple_type_specifier (t
);
1322 /* type-specifier-seq:
1323 type-specifier type-specifier-seq(opt)
1326 simple-type-specifier
1329 elaborated-type-specifier
1333 pp_cxx_type_specifier_seq (cxx_pretty_printer
*pp
, tree t
)
1335 switch (TREE_CODE (t
))
1338 case TEMPLATE_TYPE_PARM
:
1339 case TEMPLATE_TEMPLATE_PARM
:
1341 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1342 pp_cxx_cv_qualifier_seq (pp
, t
);
1343 pp
->simple_type_specifier (t
);
1347 pp_cxx_type_specifier_seq (pp
, TREE_TYPE (t
));
1348 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (t
));
1349 pp_cxx_nested_name_specifier (pp
, TYPE_METHOD_BASETYPE (t
));
1353 pp_cxx_ws_string (pp
, "decltype");
1354 pp_cxx_left_paren (pp
);
1355 pp
->expression (DECLTYPE_TYPE_EXPR (t
));
1356 pp_cxx_right_paren (pp
);
1360 if (TYPE_PTRMEMFUNC_P (t
))
1362 tree pfm
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
1363 pp
->declaration_specifiers (TREE_TYPE (TREE_TYPE (pfm
)));
1364 pp_cxx_whitespace (pp
);
1365 pp_cxx_ptr_operator (pp
, t
);
1371 if (!(TREE_CODE (t
) == FUNCTION_DECL
&& DECL_CONSTRUCTOR_P (t
)))
1372 pp_c_specifier_qualifier_list (pp
, t
);
1377 * cv-qualifier-seq(opt)
1379 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1382 pp_cxx_ptr_operator (cxx_pretty_printer
*pp
, tree t
)
1384 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
1386 switch (TREE_CODE (t
))
1388 case REFERENCE_TYPE
:
1390 if (TYPE_PTR_OR_PTRMEM_P (TREE_TYPE (t
)))
1391 pp_cxx_ptr_operator (pp
, TREE_TYPE (t
));
1392 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (TREE_TYPE (t
)));
1396 pp_cxx_cv_qualifier_seq (pp
, t
);
1403 if (TYPE_PTRMEMFUNC_P (t
))
1405 pp_cxx_left_paren (pp
);
1406 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEMFUNC_OBJECT_TYPE (t
));
1412 if (TYPE_PTRMEM_P (t
))
1414 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1415 pp_cxx_left_paren (pp
);
1416 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEM_CLASS_TYPE (t
));
1418 pp_cxx_cv_qualifier_seq (pp
, t
);
1424 pp_unsupported_tree (pp
, t
);
1430 pp_cxx_implicit_parameter_type (tree mf
)
1432 return class_of_this_parm (TREE_TYPE (mf
));
1436 parameter-declaration:
1437 decl-specifier-seq declarator
1438 decl-specifier-seq declarator = assignment-expression
1439 decl-specifier-seq abstract-declarator(opt)
1440 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1443 pp_cxx_parameter_declaration (cxx_pretty_printer
*pp
, tree t
)
1445 pp
->declaration_specifiers (t
);
1447 pp
->abstract_declarator (t
);
1452 /* parameter-declaration-clause:
1453 parameter-declaration-list(opt) ...(opt)
1454 parameter-declaration-list , ...
1456 parameter-declaration-list:
1457 parameter-declaration
1458 parameter-declaration-list , parameter-declaration */
1461 pp_cxx_parameter_declaration_clause (cxx_pretty_printer
*pp
, tree t
)
1467 // For a requires clause or the explicit printing of a parameter list
1468 // we expect T to be a chain of PARM_DECLs. Otherwise, the list of
1469 // args and types are taken from the function decl T.
1470 if (TREE_CODE (t
) == PARM_DECL
)
1478 bool type_p
= TYPE_P (t
);
1479 args
= type_p
? NULL
: FUNCTION_FIRST_USER_PARM (t
);
1480 types
= type_p
? TYPE_ARG_TYPES (t
) : FUNCTION_FIRST_USER_PARMTYPE (t
);
1481 abstract
= args
== NULL
|| pp
->flags
& pp_c_flag_abstract
;
1485 /* Skip artificial parameter for nonstatic member functions. */
1486 if (TREE_CODE (t
) == METHOD_TYPE
)
1487 types
= TREE_CHAIN (types
);
1489 pp_cxx_left_paren (pp
);
1490 for (; args
; args
= TREE_CHAIN (args
), types
= TREE_CHAIN (types
))
1493 pp_cxx_separate_with (pp
, ',');
1495 pp_cxx_parameter_declaration (pp
, abstract
? TREE_VALUE (types
) : args
);
1496 if (!abstract
&& pp
->flags
& pp_cxx_flag_default_argument
)
1498 pp_cxx_whitespace (pp
);
1500 pp_cxx_whitespace (pp
);
1501 pp
->assignment_expression (TREE_PURPOSE (types
));
1504 pp_cxx_right_paren (pp
);
1507 /* exception-specification:
1508 throw ( type-id-list(opt) )
1512 type-id-list , type-id */
1515 pp_cxx_exception_specification (cxx_pretty_printer
*pp
, tree t
)
1517 tree ex_spec
= TYPE_RAISES_EXCEPTIONS (t
);
1518 bool need_comma
= false;
1520 if (ex_spec
== NULL
)
1522 if (TREE_PURPOSE (ex_spec
))
1524 pp_cxx_ws_string (pp
, "noexcept");
1525 pp_cxx_whitespace (pp
);
1526 pp_cxx_left_paren (pp
);
1527 if (DEFERRED_NOEXCEPT_SPEC_P (ex_spec
))
1528 pp_cxx_ws_string (pp
, "<uninstantiated>");
1530 pp
->expression (TREE_PURPOSE (ex_spec
));
1531 pp_cxx_right_paren (pp
);
1534 pp_cxx_ws_string (pp
, "throw");
1535 pp_cxx_left_paren (pp
);
1536 for (; ex_spec
&& TREE_VALUE (ex_spec
); ex_spec
= TREE_CHAIN (ex_spec
))
1538 tree type
= TREE_VALUE (ex_spec
);
1539 tree argpack
= NULL_TREE
;
1542 if (ARGUMENT_PACK_P (type
))
1544 argpack
= ARGUMENT_PACK_ARGS (type
);
1545 len
= TREE_VEC_LENGTH (argpack
);
1548 for (i
= 0; i
< len
; ++i
)
1551 type
= TREE_VEC_ELT (argpack
, i
);
1554 pp_cxx_separate_with (pp
, ',');
1561 pp_cxx_right_paren (pp
);
1564 /* direct-declarator:
1566 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1567 exception-specification(opt)
1568 direct-declaration [ constant-expression(opt) ]
1572 cxx_pretty_printer::direct_declarator (tree t
)
1574 switch (TREE_CODE (t
))
1582 pp_cxx_space_for_pointer_operator (this, TREE_TYPE (t
));
1584 if ((TREE_CODE (t
) == PARM_DECL
&& DECL_PACK_P (t
))
1585 || template_parameter_pack_p (t
))
1586 /* A function parameter pack or non-type template
1588 pp_cxx_ws_string (this, "...");
1590 id_expression (DECL_NAME (t
));
1592 abstract_declarator (TREE_TYPE (t
));
1596 pp_cxx_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t
)));
1598 pp_cxx_parameter_declaration_clause (this, t
);
1600 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1602 padding
= pp_before
;
1603 pp_cxx_cv_qualifier_seq (this, pp_cxx_implicit_parameter_type (t
));
1606 pp_cxx_exception_specification (this, TREE_TYPE (t
));
1611 case TEMPLATE_TYPE_PARM
:
1612 case TEMPLATE_PARM_INDEX
:
1613 case TEMPLATE_TEMPLATE_PARM
:
1617 c_pretty_printer::direct_declarator (t
);
1624 ptr-operator declarator */
1627 cxx_pretty_printer::declarator (tree t
)
1629 direct_declarator (t
);
1631 // Print a requires clause.
1633 if (tree ci
= get_constraints (t
))
1634 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1635 pp_cxx_requires_clause (this, reqs
);
1638 /* ctor-initializer:
1639 : mem-initializer-list
1641 mem-initializer-list:
1643 mem-initializer , mem-initializer-list
1646 mem-initializer-id ( expression-list(opt) )
1649 ::(opt) nested-name-specifier(opt) class-name
1653 pp_cxx_ctor_initializer (cxx_pretty_printer
*pp
, tree t
)
1655 t
= TREE_OPERAND (t
, 0);
1656 pp_cxx_whitespace (pp
);
1658 pp_cxx_whitespace (pp
);
1659 for (; t
; t
= TREE_CHAIN (t
))
1661 tree purpose
= TREE_PURPOSE (t
);
1662 bool is_pack
= PACK_EXPANSION_P (purpose
);
1665 pp
->primary_expression (PACK_EXPANSION_PATTERN (purpose
));
1667 pp
->primary_expression (purpose
);
1668 pp_cxx_call_argument_list (pp
, TREE_VALUE (t
));
1670 pp_cxx_ws_string (pp
, "...");
1672 pp_cxx_separate_with (pp
, ',');
1676 /* function-definition:
1677 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1678 decl-specifier-seq(opt) declarator function-try-block */
1681 pp_cxx_function_definition (cxx_pretty_printer
*pp
, tree t
)
1683 tree saved_scope
= pp
->enclosing_scope
;
1684 pp
->declaration_specifiers (t
);
1686 pp_needs_newline (pp
) = true;
1687 pp
->enclosing_scope
= DECL_CONTEXT (t
);
1688 if (DECL_SAVED_TREE (t
))
1689 pp
->statement (DECL_SAVED_TREE (t
));
1691 pp_cxx_semicolon (pp
);
1692 pp_newline_and_flush (pp
);
1693 pp
->enclosing_scope
= saved_scope
;
1696 /* abstract-declarator:
1697 ptr-operator abstract-declarator(opt)
1698 direct-abstract-declarator */
1701 cxx_pretty_printer::abstract_declarator (tree t
)
1703 if (TYPE_PTRMEM_P (t
))
1704 pp_cxx_right_paren (this);
1705 else if (POINTER_TYPE_P (t
))
1707 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
1708 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1709 pp_cxx_right_paren (this);
1712 direct_abstract_declarator (t
);
1715 /* direct-abstract-declarator:
1716 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1717 cv-qualifier-seq(opt) exception-specification(opt)
1718 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1719 ( abstract-declarator ) */
1722 cxx_pretty_printer::direct_abstract_declarator (tree t
)
1724 switch (TREE_CODE (t
))
1726 case REFERENCE_TYPE
:
1727 abstract_declarator (t
);
1731 if (TYPE_PTRMEMFUNC_P (t
))
1732 direct_abstract_declarator (TYPE_PTRMEMFUNC_FN_TYPE (t
));
1737 pp_cxx_parameter_declaration_clause (this, t
);
1738 direct_abstract_declarator (TREE_TYPE (t
));
1739 if (TREE_CODE (t
) == METHOD_TYPE
)
1741 padding
= pp_before
;
1742 pp_cxx_cv_qualifier_seq (this, class_of_this_parm (t
));
1744 pp_cxx_exception_specification (this, t
);
1748 case TEMPLATE_TYPE_PARM
:
1749 case TEMPLATE_TEMPLATE_PARM
:
1750 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1751 case UNBOUND_CLASS_TEMPLATE
:
1755 c_pretty_printer::direct_abstract_declarator (t
);
1761 type-specifier-seq abstract-declarator(opt) */
1764 cxx_pretty_printer::type_id (tree t
)
1766 pp_flags saved_flags
= flags
;
1767 flags
|= pp_c_flag_abstract
;
1769 switch (TREE_CODE (t
))
1776 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1777 case UNBOUND_CLASS_TEMPLATE
:
1778 case TEMPLATE_TEMPLATE_PARM
:
1779 case TEMPLATE_TYPE_PARM
:
1780 case TEMPLATE_PARM_INDEX
:
1783 case UNDERLYING_TYPE
:
1785 case TEMPLATE_ID_EXPR
:
1786 pp_cxx_type_specifier_seq (this, t
);
1789 case TYPE_PACK_EXPANSION
:
1790 type_id (PACK_EXPANSION_PATTERN (t
));
1791 pp_cxx_ws_string (this, "...");
1795 c_pretty_printer::type_id (t
);
1799 flags
= saved_flags
;
1802 /* template-argument-list:
1803 template-argument ...(opt)
1804 template-argument-list, template-argument ...(opt)
1807 assignment-expression
1812 pp_cxx_template_argument_list (cxx_pretty_printer
*pp
, tree t
)
1815 bool need_comma
= false;
1819 for (i
= 0; i
< TREE_VEC_LENGTH (t
); ++i
)
1821 tree arg
= TREE_VEC_ELT (t
, i
);
1822 tree argpack
= NULL_TREE
;
1825 if (ARGUMENT_PACK_P (arg
))
1827 argpack
= ARGUMENT_PACK_ARGS (arg
);
1828 len
= TREE_VEC_LENGTH (argpack
);
1831 for (idx
= 0; idx
< len
; idx
++)
1834 arg
= TREE_VEC_ELT (argpack
, idx
);
1837 pp_cxx_separate_with (pp
, ',');
1841 if (TYPE_P (arg
) || (TREE_CODE (arg
) == TEMPLATE_DECL
1842 && TYPE_P (DECL_TEMPLATE_RESULT (arg
))))
1845 pp
->expression (arg
);
1852 pp_cxx_exception_declaration (cxx_pretty_printer
*pp
, tree t
)
1854 t
= DECL_EXPR_DECL (t
);
1855 pp_cxx_type_specifier_seq (pp
, t
);
1857 pp
->abstract_declarator (t
);
1865 cxx_pretty_printer::statement (tree t
)
1867 switch (TREE_CODE (t
))
1869 case CTOR_INITIALIZER
:
1870 pp_cxx_ctor_initializer (this, t
);
1874 pp_cxx_ws_string (this, "using");
1875 pp_cxx_ws_string (this, "namespace");
1876 if (DECL_CONTEXT (t
))
1877 pp_cxx_nested_name_specifier (this, DECL_CONTEXT (t
));
1878 pp_cxx_qualified_id (this, USING_STMT_NAMESPACE (t
));
1882 pp_cxx_ws_string (this, "using");
1883 pp_cxx_nested_name_specifier (this, USING_DECL_SCOPE (t
));
1884 pp_cxx_unqualified_id (this, DECL_NAME (t
));
1891 try compound-statement handler-seq */
1893 pp_maybe_newline_and_indent (this, 0);
1894 pp_cxx_ws_string (this, "try");
1895 pp_newline_and_indent (this, 3);
1896 statement (TRY_STMTS (t
));
1897 pp_newline_and_indent (this, -3);
1901 statement (TRY_HANDLERS (t
));
1906 handler handler-seq(opt)
1909 catch ( exception-declaration ) compound-statement
1911 exception-declaration:
1912 type-specifier-seq declarator
1913 type-specifier-seq abstract-declarator
1916 pp_cxx_ws_string (this, "catch");
1917 pp_cxx_left_paren (this);
1918 pp_cxx_exception_declaration (this, HANDLER_PARMS (t
));
1919 pp_cxx_right_paren (this);
1920 pp_indentation (this) += 3;
1921 pp_needs_newline (this) = true;
1922 statement (HANDLER_BODY (t
));
1923 pp_indentation (this) -= 3;
1924 pp_needs_newline (this) = true;
1927 /* selection-statement:
1928 if ( expression ) statement
1929 if ( expression ) statement else statement */
1931 pp_cxx_ws_string (this, "if");
1932 pp_cxx_whitespace (this);
1933 pp_cxx_left_paren (this);
1934 expression (IF_COND (t
));
1935 pp_cxx_right_paren (this);
1936 pp_newline_and_indent (this, 2);
1937 statement (THEN_CLAUSE (t
));
1938 pp_newline_and_indent (this, -2);
1939 if (ELSE_CLAUSE (t
))
1941 tree else_clause
= ELSE_CLAUSE (t
);
1942 pp_cxx_ws_string (this, "else");
1943 if (TREE_CODE (else_clause
) == IF_STMT
)
1944 pp_cxx_whitespace (this);
1946 pp_newline_and_indent (this, 2);
1947 statement (else_clause
);
1948 if (TREE_CODE (else_clause
) != IF_STMT
)
1949 pp_newline_and_indent (this, -2);
1954 pp_cxx_ws_string (this, "switch");
1956 pp_cxx_left_paren (this);
1957 expression (SWITCH_STMT_COND (t
));
1958 pp_cxx_right_paren (this);
1959 pp_indentation (this) += 3;
1960 pp_needs_newline (this) = true;
1961 statement (SWITCH_STMT_BODY (t
));
1962 pp_newline_and_indent (this, -3);
1965 /* iteration-statement:
1966 while ( expression ) statement
1967 do statement while ( expression ) ;
1968 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1969 for ( declaration expression(opt) ; expression(opt) ) statement */
1971 pp_cxx_ws_string (this, "while");
1973 pp_cxx_left_paren (this);
1974 expression (WHILE_COND (t
));
1975 pp_cxx_right_paren (this);
1976 pp_newline_and_indent (this, 3);
1977 statement (WHILE_BODY (t
));
1978 pp_indentation (this) -= 3;
1979 pp_needs_newline (this) = true;
1983 pp_cxx_ws_string (this, "do");
1984 pp_newline_and_indent (this, 3);
1985 statement (DO_BODY (t
));
1986 pp_newline_and_indent (this, -3);
1987 pp_cxx_ws_string (this, "while");
1989 pp_cxx_left_paren (this);
1990 expression (DO_COND (t
));
1991 pp_cxx_right_paren (this);
1992 pp_cxx_semicolon (this);
1993 pp_needs_newline (this) = true;
1997 pp_cxx_ws_string (this, "for");
1999 pp_cxx_left_paren (this);
2000 if (FOR_INIT_STMT (t
))
2001 statement (FOR_INIT_STMT (t
));
2003 pp_cxx_semicolon (this);
2004 pp_needs_newline (this) = false;
2005 pp_cxx_whitespace (this);
2007 expression (FOR_COND (t
));
2008 pp_cxx_semicolon (this);
2009 pp_needs_newline (this) = false;
2010 pp_cxx_whitespace (this);
2012 expression (FOR_EXPR (t
));
2013 pp_cxx_right_paren (this);
2014 pp_newline_and_indent (this, 3);
2015 statement (FOR_BODY (t
));
2016 pp_indentation (this) -= 3;
2017 pp_needs_newline (this) = true;
2020 case RANGE_FOR_STMT
:
2021 pp_cxx_ws_string (this, "for");
2023 pp_cxx_left_paren (this);
2024 statement (RANGE_FOR_DECL (t
));
2026 pp_needs_newline (this) = false;
2029 statement (RANGE_FOR_EXPR (t
));
2030 pp_cxx_right_paren (this);
2031 pp_newline_and_indent (this, 3);
2032 statement (FOR_BODY (t
));
2033 pp_indentation (this) -= 3;
2034 pp_needs_newline (this) = true;
2040 return expression(opt) ; */
2043 pp_string (this, TREE_CODE (t
) == BREAK_STMT
? "break" : "continue");
2044 pp_cxx_semicolon (this);
2045 pp_needs_newline (this) = true;
2048 /* expression-statement:
2049 expression(opt) ; */
2051 expression (EXPR_STMT_EXPR (t
));
2052 pp_cxx_semicolon (this);
2053 pp_needs_newline (this) = true;
2057 pp_cxx_ws_string (this, "try");
2058 pp_newline_and_indent (this, 2);
2059 statement (CLEANUP_BODY (t
));
2060 pp_newline_and_indent (this, -2);
2061 pp_cxx_ws_string (this, CLEANUP_EH_ONLY (t
) ? "catch" : "finally");
2062 pp_newline_and_indent (this, 2);
2063 statement (CLEANUP_EXPR (t
));
2064 pp_newline_and_indent (this, -2);
2072 c_pretty_printer::statement (t
);
2077 /* original-namespace-definition:
2078 namespace identifier { namespace-body }
2080 As an edge case, we also handle unnamed namespace definition here. */
2083 pp_cxx_original_namespace_definition (cxx_pretty_printer
*pp
, tree t
)
2085 pp_cxx_ws_string (pp
, "namespace");
2086 if (DECL_CONTEXT (t
))
2087 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
2089 pp_cxx_unqualified_id (pp
, t
);
2090 pp_cxx_whitespace (pp
);
2091 pp_cxx_left_brace (pp
);
2092 /* We do not print the namespace-body. */
2093 pp_cxx_whitespace (pp
);
2094 pp_cxx_right_brace (pp
);
2100 namespace-alias-definition:
2101 namespace identifier = qualified-namespace-specifier ;
2103 qualified-namespace-specifier:
2104 ::(opt) nested-name-specifier(opt) namespace-name */
2107 pp_cxx_namespace_alias_definition (cxx_pretty_printer
*pp
, tree t
)
2109 pp_cxx_ws_string (pp
, "namespace");
2110 if (DECL_CONTEXT (t
))
2111 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
2112 pp_cxx_unqualified_id (pp
, t
);
2113 pp_cxx_whitespace (pp
);
2115 pp_cxx_whitespace (pp
);
2116 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t
)))
2117 pp_cxx_nested_name_specifier (pp
,
2118 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t
)));
2119 pp_cxx_qualified_id (pp
, DECL_NAMESPACE_ALIAS (t
));
2120 pp_cxx_semicolon (pp
);
2123 /* simple-declaration:
2124 decl-specifier-seq(opt) init-declarator-list(opt) */
2127 pp_cxx_simple_declaration (cxx_pretty_printer
*pp
, tree t
)
2129 pp
->declaration_specifiers (t
);
2130 pp_cxx_init_declarator (pp
, t
);
2131 pp_cxx_semicolon (pp
);
2132 pp_needs_newline (pp
) = true;
2136 template-parameter-list:
2138 template-parameter-list , template-parameter */
2141 pp_cxx_template_parameter_list (cxx_pretty_printer
*pp
, tree t
)
2143 const int n
= TREE_VEC_LENGTH (t
);
2145 for (i
= 0; i
< n
; ++i
)
2148 pp_cxx_separate_with (pp
, ',');
2149 pp_cxx_template_parameter (pp
, TREE_VEC_ELT (t
, i
));
2153 /* template-parameter:
2155 parameter-declaration
2158 class ...(opt) identifier(opt)
2159 class identifier(opt) = type-id
2160 typename identifier(opt)
2161 typename ...(opt) identifier(opt) = type-id
2162 template < template-parameter-list > class ...(opt) identifier(opt)
2163 template < template-parameter-list > class identifier(opt) = template-name */
2166 pp_cxx_template_parameter (cxx_pretty_printer
*pp
, tree t
)
2168 tree parameter
= TREE_VALUE (t
);
2169 switch (TREE_CODE (parameter
))
2172 pp_cxx_ws_string (pp
, "class");
2173 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
2174 pp_cxx_ws_string (pp
, "...");
2175 if (DECL_NAME (parameter
))
2176 pp_cxx_tree_identifier (pp
, DECL_NAME (parameter
));
2177 /* FIXME: Check if we should print also default argument. */
2181 pp_cxx_parameter_declaration (pp
, parameter
);
2188 pp_unsupported_tree (pp
, t
);
2193 /* Pretty-print a template parameter in the canonical form
2194 "template-parameter-<level>-<position in parameter list>". */
2197 pp_cxx_canonical_template_parameter (cxx_pretty_printer
*pp
, tree parm
)
2199 const enum tree_code code
= TREE_CODE (parm
);
2201 /* Brings type template parameters to the canonical forms. */
2202 if (code
== TEMPLATE_TYPE_PARM
|| code
== TEMPLATE_TEMPLATE_PARM
2203 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
)
2204 parm
= TEMPLATE_TYPE_PARM_INDEX (parm
);
2206 pp_cxx_begin_template_argument_list (pp
);
2207 pp
->translate_string ("template-parameter-");
2208 pp_wide_integer (pp
, TEMPLATE_PARM_LEVEL (parm
));
2210 pp_wide_integer (pp
, TEMPLATE_PARM_IDX (parm
) + 1);
2211 pp_cxx_end_template_argument_list (pp
);
2214 /* Print a constrained-type-specifier. */
2217 pp_cxx_constrained_type_spec (cxx_pretty_printer
*pp
, tree c
)
2220 if (c
== error_mark_node
)
2222 pp_cxx_ws_string(pp
, "<unsatisfied-constrained-placeholder>");
2225 placeholder_extract_concept_and_args (c
, t
, a
);
2226 pp
->id_expression (t
);
2227 if (TREE_VEC_LENGTH (a
) > 1)
2229 pp_cxx_begin_template_argument_list (pp
);
2230 tree args
= make_tree_vec (TREE_VEC_LENGTH (a
) - 1);
2231 for (int i
= TREE_VEC_LENGTH (a
) - 1; i
> 0; --i
)
2232 TREE_VEC_ELT (args
, i
-1) = TREE_VEC_ELT (a
, i
);
2233 pp_cxx_template_argument_list (pp
, args
);
2235 pp_cxx_end_template_argument_list (pp
);
2240 template-declaration:
2241 export(opt) template < template-parameter-list > declaration
2245 template-declaration:
2246 export(opt) template < template-parameter-list >
2247 requires-clause(opt) declaration */
2250 pp_cxx_template_declaration (cxx_pretty_printer
*pp
, tree t
)
2252 tree tmpl
= most_general_template (t
);
2255 pp_maybe_newline_and_indent (pp
, 0);
2256 for (level
= DECL_TEMPLATE_PARMS (tmpl
); level
; level
= TREE_CHAIN (level
))
2258 pp_cxx_ws_string (pp
, "template");
2259 pp_cxx_begin_template_argument_list (pp
);
2260 pp_cxx_template_parameter_list (pp
, TREE_VALUE (level
));
2261 pp_cxx_end_template_argument_list (pp
);
2262 pp_newline_and_indent (pp
, 3);
2266 if (tree ci
= get_constraints (t
))
2267 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
2269 pp_cxx_requires_clause (pp
, reqs
);
2270 pp_newline_and_indent (pp
, 6);
2273 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_SAVED_TREE (t
))
2274 pp_cxx_function_definition (pp
, t
);
2276 pp_cxx_simple_declaration (pp
, t
);
2280 pp_cxx_explicit_specialization (cxx_pretty_printer
*pp
, tree t
)
2282 pp_unsupported_tree (pp
, t
);
2286 pp_cxx_explicit_instantiation (cxx_pretty_printer
*pp
, tree t
)
2288 pp_unsupported_tree (pp
, t
);
2295 template-declaration
2296 explicit-instantiation
2297 explicit-specialization
2298 linkage-specification
2299 namespace-definition
2304 namespace-alias-definition
2307 static_assert-declaration */
2309 cxx_pretty_printer::declaration (tree t
)
2311 if (TREE_CODE (t
) == STATIC_ASSERT
)
2313 pp_cxx_ws_string (this, "static_assert");
2314 pp_cxx_left_paren (this);
2315 expression (STATIC_ASSERT_CONDITION (t
));
2316 pp_cxx_separate_with (this, ',');
2317 expression (STATIC_ASSERT_MESSAGE (t
));
2318 pp_cxx_right_paren (this);
2320 else if (!DECL_LANG_SPECIFIC (t
))
2321 pp_cxx_simple_declaration (this, t
);
2322 else if (DECL_USE_TEMPLATE (t
))
2323 switch (DECL_USE_TEMPLATE (t
))
2326 pp_cxx_template_declaration (this, t
);
2330 pp_cxx_explicit_specialization (this, t
);
2334 pp_cxx_explicit_instantiation (this, t
);
2340 else switch (TREE_CODE (t
))
2344 pp_cxx_simple_declaration (this, t
);
2348 if (DECL_SAVED_TREE (t
))
2349 pp_cxx_function_definition (this, t
);
2351 pp_cxx_simple_declaration (this, t
);
2354 case NAMESPACE_DECL
:
2355 if (DECL_NAMESPACE_ALIAS (t
))
2356 pp_cxx_namespace_alias_definition (this, t
);
2358 pp_cxx_original_namespace_definition (this, t
);
2362 pp_unsupported_tree (this, t
);
2368 pp_cxx_typeid_expression (cxx_pretty_printer
*pp
, tree t
)
2370 t
= TREE_OPERAND (t
, 0);
2371 pp_cxx_ws_string (pp
, "typeid");
2372 pp_cxx_left_paren (pp
);
2377 pp_cxx_right_paren (pp
);
2381 pp_cxx_va_arg_expression (cxx_pretty_printer
*pp
, tree t
)
2383 pp_cxx_ws_string (pp
, "va_arg");
2384 pp_cxx_left_paren (pp
);
2385 pp
->assignment_expression (TREE_OPERAND (t
, 0));
2386 pp_cxx_separate_with (pp
, ',');
2387 pp
->type_id (TREE_TYPE (t
));
2388 pp_cxx_right_paren (pp
);
2392 pp_cxx_offsetof_expression_1 (cxx_pretty_printer
*pp
, tree t
)
2394 switch (TREE_CODE (t
))
2397 if (TREE_CODE (TREE_OPERAND (t
, 0)) == STATIC_CAST_EXPR
2398 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (t
, 0))))
2400 pp
->type_id (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))));
2401 pp_cxx_separate_with (pp
, ',');
2406 if (!pp_cxx_offsetof_expression_1 (pp
, TREE_OPERAND (t
, 0)))
2408 if (TREE_CODE (TREE_OPERAND (t
, 0)) != ARROW_EXPR
)
2410 pp
->expression (TREE_OPERAND (t
, 1));
2413 if (!pp_cxx_offsetof_expression_1 (pp
, TREE_OPERAND (t
, 0)))
2415 pp_left_bracket (pp
);
2416 pp
->expression (TREE_OPERAND (t
, 1));
2417 pp_right_bracket (pp
);
2425 pp_cxx_offsetof_expression (cxx_pretty_printer
*pp
, tree t
)
2427 pp_cxx_ws_string (pp
, "offsetof");
2428 pp_cxx_left_paren (pp
);
2429 if (!pp_cxx_offsetof_expression_1 (pp
, TREE_OPERAND (t
, 0)))
2430 pp
->expression (TREE_OPERAND (t
, 0));
2431 pp_cxx_right_paren (pp
);
2435 pp_cxx_addressof_expression (cxx_pretty_printer
*pp
, tree t
)
2437 pp_cxx_ws_string (pp
, "__builtin_addressof");
2438 pp_cxx_left_paren (pp
);
2439 pp
->expression (TREE_OPERAND (t
, 0));
2440 pp_cxx_right_paren (pp
);
2444 get_fold_operator (tree t
)
2446 int op
= int_cst_value (FOLD_EXPR_OP (t
));
2447 if (FOLD_EXPR_MODIFY_P (t
))
2451 case NOP_EXPR
: return "=";
2452 case PLUS_EXPR
: return "+=";
2453 case MINUS_EXPR
: return "-=";
2454 case MULT_EXPR
: return "*=";
2455 case TRUNC_DIV_EXPR
: return "/=";
2456 case TRUNC_MOD_EXPR
: return "%=";
2457 case BIT_XOR_EXPR
: return "^=";
2458 case BIT_AND_EXPR
: return "&=";
2459 case BIT_IOR_EXPR
: return "|=";
2460 case LSHIFT_EXPR
: return "<<=";
2461 case RSHIFT_EXPR
: return ">>=";
2462 default: gcc_unreachable ();
2469 case PLUS_EXPR
: return "+";
2470 case MINUS_EXPR
: return "-";
2471 case MULT_EXPR
: return "*";
2472 case TRUNC_DIV_EXPR
: return "/";
2473 case TRUNC_MOD_EXPR
: return "%";
2474 case BIT_XOR_EXPR
: return "^";
2475 case BIT_AND_EXPR
: return "&";
2476 case BIT_IOR_EXPR
: return "|";
2477 case LSHIFT_EXPR
: return "<<";
2478 case RSHIFT_EXPR
: return ">>";
2479 case EQ_EXPR
: return "==";
2480 case NE_EXPR
: return "!=";
2481 case LT_EXPR
: return "<";
2482 case GT_EXPR
: return ">";
2483 case LE_EXPR
: return "<=";
2484 case GE_EXPR
: return ">=";
2485 case TRUTH_ANDIF_EXPR
: return "&&";
2486 case TRUTH_ORIF_EXPR
: return "||";
2487 case MEMBER_REF
: return "->*";
2488 case DOTSTAR_EXPR
: return ".*";
2489 case OFFSET_REF
: return ".*";
2490 default: return ","; /* FIXME: Not the right default. */
2496 pp_cxx_unary_left_fold_expression (cxx_pretty_printer
*pp
, tree t
)
2498 char const* op
= get_fold_operator (t
);
2499 tree expr
= PACK_EXPANSION_PATTERN (FOLD_EXPR_PACK (t
));
2500 pp_cxx_left_paren (pp
);
2501 pp_cxx_ws_string (pp
, "...");
2502 pp_cxx_ws_string (pp
, op
);
2503 pp
->expression (expr
);
2504 pp_cxx_right_paren (pp
);
2508 pp_cxx_unary_right_fold_expression (cxx_pretty_printer
*pp
, tree t
)
2510 char const* op
= get_fold_operator (t
);
2511 tree expr
= PACK_EXPANSION_PATTERN (FOLD_EXPR_PACK (t
));
2512 pp_cxx_left_paren (pp
);
2513 pp
->expression (expr
);
2515 pp_cxx_ws_string (pp
, op
);
2516 pp_cxx_ws_string (pp
, "...");
2517 pp_cxx_right_paren (pp
);
2521 pp_cxx_binary_fold_expression (cxx_pretty_printer
*pp
, tree t
)
2523 char const* op
= get_fold_operator (t
);
2524 tree t1
= TREE_OPERAND (t
, 1);
2525 tree t2
= TREE_OPERAND (t
, 2);
2526 if (t1
== FOLD_EXPR_PACK (t
))
2527 t1
= PACK_EXPANSION_PATTERN (t1
);
2529 t2
= PACK_EXPANSION_PATTERN (t2
);
2530 pp_cxx_left_paren (pp
);
2531 pp
->expression (t1
);
2532 pp_cxx_ws_string (pp
, op
);
2533 pp_cxx_ws_string (pp
, "...");
2534 pp_cxx_ws_string (pp
, op
);
2535 pp
->expression (t2
);
2536 pp_cxx_right_paren (pp
);
2540 pp_cxx_trait_expression (cxx_pretty_printer
*pp
, tree t
)
2542 cp_trait_kind kind
= TRAIT_EXPR_KIND (t
);
2546 case CPTK_HAS_NOTHROW_ASSIGN
:
2547 pp_cxx_ws_string (pp
, "__has_nothrow_assign");
2549 case CPTK_HAS_TRIVIAL_ASSIGN
:
2550 pp_cxx_ws_string (pp
, "__has_trivial_assign");
2552 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
2553 pp_cxx_ws_string (pp
, "__has_nothrow_constructor");
2555 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
2556 pp_cxx_ws_string (pp
, "__has_trivial_constructor");
2558 case CPTK_HAS_NOTHROW_COPY
:
2559 pp_cxx_ws_string (pp
, "__has_nothrow_copy");
2561 case CPTK_HAS_TRIVIAL_COPY
:
2562 pp_cxx_ws_string (pp
, "__has_trivial_copy");
2564 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
2565 pp_cxx_ws_string (pp
, "__has_trivial_destructor");
2567 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
2568 pp_cxx_ws_string (pp
, "__has_unique_object_representations");
2570 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
2571 pp_cxx_ws_string (pp
, "__has_virtual_destructor");
2573 case CPTK_IS_ABSTRACT
:
2574 pp_cxx_ws_string (pp
, "__is_abstract");
2576 case CPTK_IS_AGGREGATE
:
2577 pp_cxx_ws_string (pp
, "__is_aggregate");
2579 case CPTK_IS_BASE_OF
:
2580 pp_cxx_ws_string (pp
, "__is_base_of");
2583 pp_cxx_ws_string (pp
, "__is_class");
2586 pp_cxx_ws_string (pp
, "__is_empty");
2589 pp_cxx_ws_string (pp
, "__is_enum");
2592 pp_cxx_ws_string (pp
, "__is_final");
2595 pp_cxx_ws_string (pp
, "__is_pod");
2597 case CPTK_IS_POLYMORPHIC
:
2598 pp_cxx_ws_string (pp
, "__is_polymorphic");
2600 case CPTK_IS_SAME_AS
:
2601 pp_cxx_ws_string (pp
, "__is_same_as");
2603 case CPTK_IS_STD_LAYOUT
:
2604 pp_cxx_ws_string (pp
, "__is_std_layout");
2606 case CPTK_IS_TRIVIAL
:
2607 pp_cxx_ws_string (pp
, "__is_trivial");
2609 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
2610 pp_cxx_ws_string (pp
, "__is_trivially_assignable");
2612 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
2613 pp_cxx_ws_string (pp
, "__is_trivially_constructible");
2615 case CPTK_IS_TRIVIALLY_COPYABLE
:
2616 pp_cxx_ws_string (pp
, "__is_trivially_copyable");
2619 pp_cxx_ws_string (pp
, "__is_union");
2621 case CPTK_IS_LITERAL_TYPE
:
2622 pp_cxx_ws_string (pp
, "__is_literal_type");
2624 case CPTK_IS_ASSIGNABLE
:
2625 pp_cxx_ws_string (pp
, "__is_assignable");
2627 case CPTK_IS_CONSTRUCTIBLE
:
2628 pp_cxx_ws_string (pp
, "__is_constructible");
2635 pp_cxx_left_paren (pp
);
2636 pp
->type_id (TRAIT_EXPR_TYPE1 (t
));
2638 if (kind
== CPTK_IS_BASE_OF
|| kind
== CPTK_IS_SAME_AS
)
2640 pp_cxx_separate_with (pp
, ',');
2641 pp
->type_id (TRAIT_EXPR_TYPE2 (t
));
2644 pp_cxx_right_paren (pp
);
2648 // 'requires' logical-or-expression
2650 pp_cxx_requires_clause (cxx_pretty_printer
*pp
, tree t
)
2654 pp
->padding
= pp_before
;
2655 pp_cxx_ws_string (pp
, "requires");
2662 compound-requirement
2664 nested-requirement */
2666 pp_cxx_requirement (cxx_pretty_printer
*pp
, tree t
)
2668 switch (TREE_CODE (t
))
2671 pp_cxx_simple_requirement (pp
, t
);
2675 pp_cxx_type_requirement (pp
, t
);
2679 pp_cxx_compound_requirement (pp
, t
);
2683 pp_cxx_nested_requirement (pp
, t
);
2691 // requirement-list:
2693 // requirement-list ';' requirement[opt]
2696 pp_cxx_requirement_list (cxx_pretty_printer
*pp
, tree t
)
2698 for (; t
; t
= TREE_CHAIN (t
))
2699 pp_cxx_requirement (pp
, TREE_VALUE (t
));
2702 // requirement-body:
2703 // '{' requirement-list '}'
2705 pp_cxx_requirement_body (cxx_pretty_printer
*pp
, tree t
)
2707 pp_cxx_left_brace (pp
);
2708 pp_cxx_requirement_list (pp
, t
);
2709 pp_cxx_right_brace (pp
);
2712 // requires-expression:
2713 // 'requires' requirement-parameter-list requirement-body
2715 pp_cxx_requires_expr (cxx_pretty_printer
*pp
, tree t
)
2717 pp_string (pp
, "requires");
2718 if (tree parms
= TREE_OPERAND (t
, 0))
2720 pp_cxx_parameter_declaration_clause (pp
, parms
);
2721 pp_cxx_whitespace (pp
);
2723 pp_cxx_requirement_body (pp
, TREE_OPERAND (t
, 1));
2726 /* simple-requirement:
2729 pp_cxx_simple_requirement (cxx_pretty_printer
*pp
, tree t
)
2731 pp
->expression (TREE_OPERAND (t
, 0));
2732 pp_cxx_semicolon (pp
);
2735 /* type-requirement:
2736 typename type-name ';' */
2738 pp_cxx_type_requirement (cxx_pretty_printer
*pp
, tree t
)
2740 pp
->type_id (TREE_OPERAND (t
, 0));
2741 pp_cxx_semicolon (pp
);
2744 /* compound-requirement:
2745 '{' expression '}' 'noexcept' [opt] trailing-return-type [opt] */
2747 pp_cxx_compound_requirement (cxx_pretty_printer
*pp
, tree t
)
2749 pp_cxx_left_brace (pp
);
2750 pp
->expression (TREE_OPERAND (t
, 0));
2751 pp_cxx_right_brace (pp
);
2753 if (COMPOUND_REQ_NOEXCEPT_P (t
))
2754 pp_cxx_ws_string (pp
, "noexcept");
2756 if (tree type
= TREE_OPERAND (t
, 1))
2758 pp_cxx_ws_string (pp
, "->");
2761 pp_cxx_semicolon (pp
);
2764 /* nested requirement:
2765 'requires' constraint-expression */
2767 pp_cxx_nested_requirement (cxx_pretty_printer
*pp
, tree t
)
2769 pp_cxx_ws_string (pp
, "requires");
2770 pp
->expression (TREE_OPERAND (t
, 0));
2771 pp_cxx_semicolon (pp
);
2775 pp_cxx_predicate_constraint (cxx_pretty_printer
*pp
, tree t
)
2777 pp
->expression (TREE_OPERAND (t
, 0));
2781 pp_cxx_check_constraint (cxx_pretty_printer
*pp
, tree t
)
2783 tree decl
= CHECK_CONSTR_CONCEPT (t
);
2784 tree tmpl
= DECL_TI_TEMPLATE (decl
);
2785 tree args
= CHECK_CONSTR_ARGS (t
);
2786 tree id
= build_nt (TEMPLATE_ID_EXPR
, tmpl
, args
);
2789 pp
->expression (id
);
2790 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2792 tree call
= build_vl_exp (CALL_EXPR
, 2);
2793 TREE_OPERAND (call
, 0) = integer_two_node
;
2794 TREE_OPERAND (call
, 1) = id
;
2795 pp
->expression (call
);
2802 pp_cxx_expression_constraint (cxx_pretty_printer
*pp
, tree t
)
2804 pp_string (pp
, "<valid-expression ");
2805 pp_cxx_left_paren (pp
);
2806 pp
->expression (TREE_OPERAND (t
, 0));
2807 pp_cxx_right_paren (pp
);
2808 pp_string (pp
, ">");
2812 pp_cxx_type_constraint (cxx_pretty_printer
*pp
, tree t
)
2814 pp_string (pp
, "<valid-type ");
2815 pp
->type_id (TREE_OPERAND (t
, 0));
2816 pp_string (pp
, ">");
2820 pp_cxx_implicit_conversion_constraint (cxx_pretty_printer
*pp
, tree t
)
2822 pp_string (pp
, "<implicitly-conversion ");
2823 pp_cxx_left_paren (pp
);
2824 pp
->expression (ICONV_CONSTR_EXPR (t
));
2825 pp_cxx_right_paren (pp
);
2826 pp_cxx_ws_string (pp
, "to");
2827 pp
->type_id (ICONV_CONSTR_TYPE (t
));
2828 pp_string (pp
, ">");
2832 pp_cxx_argument_deduction_constraint (cxx_pretty_printer
*pp
, tree t
)
2834 pp_string (pp
, "<argument-deduction ");
2835 pp_cxx_left_paren (pp
);
2836 pp
->expression (DEDUCT_CONSTR_EXPR (t
));
2837 pp_cxx_right_paren (pp
);
2838 pp_cxx_ws_string (pp
, "as");
2839 pp
->expression (DEDUCT_CONSTR_PATTERN (t
));
2840 pp_string (pp
, ">");
2844 pp_cxx_exception_constraint (cxx_pretty_printer
*pp
, tree t
)
2846 pp_cxx_ws_string (pp
, "noexcept");
2847 pp_cxx_whitespace (pp
);
2848 pp_cxx_left_paren (pp
);
2849 pp
->expression (TREE_OPERAND (t
, 0));
2850 pp_cxx_right_paren (pp
);
2854 pp_cxx_parameterized_constraint (cxx_pretty_printer
*pp
, tree t
)
2857 pp_string (pp
, "<requires ");
2858 if (tree parms
= PARM_CONSTR_PARMS (t
))
2860 pp_cxx_parameter_declaration_clause (pp
, parms
);
2861 pp_cxx_whitespace (pp
);
2863 pp_cxx_constraint (pp
, PARM_CONSTR_OPERAND (t
));
2864 pp_string (pp
, ">");
2868 pp_cxx_conjunction (cxx_pretty_printer
*pp
, tree t
)
2870 pp_cxx_constraint (pp
, TREE_OPERAND (t
, 0));
2871 pp_string (pp
, " and ");
2872 pp_cxx_constraint (pp
, TREE_OPERAND (t
, 1));
2876 pp_cxx_disjunction (cxx_pretty_printer
*pp
, tree t
)
2878 pp_cxx_constraint (pp
, TREE_OPERAND (t
, 0));
2879 pp_string (pp
, " or ");
2880 pp_cxx_constraint (pp
, TREE_OPERAND (t
, 1));
2884 pp_cxx_constraint (cxx_pretty_printer
*pp
, tree t
)
2886 if (t
== error_mark_node
)
2887 return pp
->expression (t
);
2889 switch (TREE_CODE (t
))
2892 pp_cxx_predicate_constraint (pp
, t
);
2896 pp_cxx_check_constraint (pp
, t
);
2900 pp_cxx_expression_constraint (pp
, t
);
2904 pp_cxx_type_constraint (pp
, t
);
2908 pp_cxx_implicit_conversion_constraint (pp
, t
);
2912 pp_cxx_argument_deduction_constraint (pp
, t
);
2916 pp_cxx_exception_constraint (pp
, t
);
2920 pp_cxx_parameterized_constraint (pp
, t
);
2924 pp_cxx_conjunction (pp
, t
);
2928 pp_cxx_disjunction (pp
, t
);
2931 case EXPR_PACK_EXPANSION
:
2932 pp
->expression (TREE_OPERAND (t
, 0));
2942 typedef c_pretty_print_fn pp_fun
;
2944 /* Initialization of a C++ pretty-printer object. */
2946 cxx_pretty_printer::cxx_pretty_printer ()
2947 : c_pretty_printer (),
2948 enclosing_scope (global_namespace
)
2950 type_specifier_seq
= (pp_fun
) pp_cxx_type_specifier_seq
;
2951 parameter_list
= (pp_fun
) pp_cxx_parameter_declaration_clause
;