1 /* Implementation of subroutines for the GNU C++ pretty-printer.
2 Copyright (C) 2003-2014 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"
27 #include "cxx-pretty-print.h"
28 #include "tree-pretty-print.h"
30 static void pp_cxx_unqualified_id (cxx_pretty_printer
*, tree
);
31 static void pp_cxx_nested_name_specifier (cxx_pretty_printer
*, tree
);
32 static void pp_cxx_qualified_id (cxx_pretty_printer
*, tree
);
33 static void pp_cxx_template_argument_list (cxx_pretty_printer
*, tree
);
34 static void pp_cxx_type_specifier_seq (cxx_pretty_printer
*, tree
);
35 static void pp_cxx_ptr_operator (cxx_pretty_printer
*, tree
);
36 static void pp_cxx_parameter_declaration_clause (cxx_pretty_printer
*, tree
);
37 static void pp_cxx_template_parameter (cxx_pretty_printer
*, tree
);
38 static void pp_cxx_cast_expression (cxx_pretty_printer
*, tree
);
39 static void pp_cxx_typeid_expression (cxx_pretty_printer
*, tree
);
43 pp_cxx_nonconsecutive_character (cxx_pretty_printer
*pp
, int c
)
45 const char *p
= pp_last_position_in_text (pp
);
47 if (p
!= NULL
&& *p
== c
)
48 pp_cxx_whitespace (pp
);
50 pp
->padding
= pp_none
;
53 #define pp_cxx_expression_list(PP, T) \
54 pp_c_expression_list (PP, T)
55 #define pp_cxx_space_for_pointer_operator(PP, T) \
56 pp_c_space_for_pointer_operator (PP, T)
57 #define pp_cxx_init_declarator(PP, T) \
58 pp_c_init_declarator (PP, T)
59 #define pp_cxx_call_argument_list(PP, T) \
60 pp_c_call_argument_list (PP, T)
63 pp_cxx_colon_colon (cxx_pretty_printer
*pp
)
66 pp
->padding
= pp_none
;
70 pp_cxx_begin_template_argument_list (cxx_pretty_printer
*pp
)
72 pp_cxx_nonconsecutive_character (pp
, '<');
76 pp_cxx_end_template_argument_list (cxx_pretty_printer
*pp
)
78 pp_cxx_nonconsecutive_character (pp
, '>');
82 pp_cxx_separate_with (cxx_pretty_printer
*pp
, int c
)
84 pp_separate_with (pp
, c
);
85 pp
->padding
= pp_none
;
91 is_destructor_name (tree name
)
93 return name
== complete_dtor_identifier
94 || name
== base_dtor_identifier
95 || name
== deleting_dtor_identifier
;
98 /* conversion-function-id:
99 operator conversion-type-id
102 type-specifier-seq conversion-declarator(opt)
104 conversion-declarator:
105 ptr-operator conversion-declarator(opt) */
108 pp_cxx_conversion_function_id (cxx_pretty_printer
*pp
, tree t
)
110 pp_cxx_ws_string (pp
, "operator");
111 pp_cxx_type_specifier_seq (pp
, TREE_TYPE (t
));
115 pp_cxx_template_id (cxx_pretty_printer
*pp
, tree t
)
117 pp_cxx_unqualified_id (pp
, TREE_OPERAND (t
, 0));
118 pp_cxx_begin_template_argument_list (pp
);
119 pp_cxx_template_argument_list (pp
, TREE_OPERAND (t
, 1));
120 pp_cxx_end_template_argument_list (pp
);
123 /* Prints the unqualified part of the id-expression T.
128 conversion-function-id
133 pp_cxx_unqualified_id (cxx_pretty_printer
*pp
, tree t
)
135 enum tree_code code
= TREE_CODE (t
);
139 pp
->translate_string ("<return-value>");
156 case IDENTIFIER_NODE
:
158 pp
->translate_string ("<unnamed>");
159 else if (IDENTIFIER_TYPENAME_P (t
))
160 pp_cxx_conversion_function_id (pp
, t
);
163 if (is_destructor_name (t
))
166 /* FIXME: Why is this necessary? */
168 t
= constructor_name (TREE_TYPE (t
));
170 pp_cxx_tree_identifier (pp
, t
);
174 case TEMPLATE_ID_EXPR
:
175 pp_cxx_template_id (pp
, t
);
179 pp_cxx_unqualified_id (pp
, BASELINK_FUNCTIONS (t
));
186 case UNBOUND_CLASS_TEMPLATE
:
187 pp_cxx_unqualified_id (pp
, TYPE_NAME (t
));
188 if (CLASS_TYPE_P (t
) && CLASSTYPE_USE_TEMPLATE (t
))
190 pp_cxx_begin_template_argument_list (pp
);
191 pp_cxx_template_argument_list (pp
, INNERMOST_TEMPLATE_ARGS
192 (CLASSTYPE_TI_ARGS (t
)));
193 pp_cxx_end_template_argument_list (pp
);
198 pp_cxx_complement (pp
);
199 pp_cxx_unqualified_id (pp
, TREE_OPERAND (t
, 0));
202 case TEMPLATE_TYPE_PARM
:
203 case TEMPLATE_TEMPLATE_PARM
:
204 if (TYPE_IDENTIFIER (t
))
205 pp_cxx_unqualified_id (pp
, TYPE_IDENTIFIER (t
));
207 pp_cxx_canonical_template_parameter (pp
, t
);
210 case TEMPLATE_PARM_INDEX
:
211 pp_cxx_unqualified_id (pp
, TEMPLATE_PARM_DECL (t
));
214 case BOUND_TEMPLATE_TEMPLATE_PARM
:
215 pp_cxx_cv_qualifier_seq (pp
, t
);
216 pp_cxx_unqualified_id (pp
, TYPE_IDENTIFIER (t
));
217 pp_cxx_begin_template_argument_list (pp
);
218 pp_cxx_template_argument_list (pp
, TYPE_TI_ARGS (t
));
219 pp_cxx_end_template_argument_list (pp
);
223 pp_unsupported_tree (pp
, t
);
228 /* Pretty-print out the token sequence ":: template" in template codes
229 where it is needed to "inline declare" the (following) member as
230 a template. This situation arises when SCOPE of T is dependent
231 on template parameters. */
234 pp_cxx_template_keyword_if_needed (cxx_pretty_printer
*pp
, tree scope
, tree t
)
236 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
237 && TYPE_P (scope
) && dependent_type_p (scope
))
238 pp_cxx_ws_string (pp
, "template");
241 /* nested-name-specifier:
242 class-or-namespace-name :: nested-name-specifier(opt)
243 class-or-namespace-name :: template nested-name-specifier */
246 pp_cxx_nested_name_specifier (cxx_pretty_printer
*pp
, tree t
)
248 if (!SCOPE_FILE_SCOPE_P (t
) && t
!= pp
->enclosing_scope
)
250 tree scope
= get_containing_scope (t
);
251 pp_cxx_nested_name_specifier (pp
, scope
);
252 pp_cxx_template_keyword_if_needed (pp
, scope
, t
);
253 pp_cxx_unqualified_id (pp
, t
);
254 pp_cxx_colon_colon (pp
);
259 nested-name-specifier template(opt) unqualified-id */
262 pp_cxx_qualified_id (cxx_pretty_printer
*pp
, tree t
)
264 switch (TREE_CODE (t
))
266 /* A pointer-to-member is always qualified. */
268 pp_cxx_nested_name_specifier (pp
, PTRMEM_CST_CLASS (t
));
269 pp_cxx_unqualified_id (pp
, PTRMEM_CST_MEMBER (t
));
272 /* In Standard C++, functions cannot possibly be used as
273 nested-name-specifiers. However, there are situations where
274 is "makes sense" to output the surrounding function name for the
275 purpose of emphasizing on the scope kind. Just printing the
276 function name might not be sufficient as it may be overloaded; so,
277 we decorate the function with its signature too.
278 FIXME: This is probably the wrong pretty-printing for conversion
279 functions and some function templates. */
283 if (DECL_FUNCTION_MEMBER_P (t
))
284 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
285 pp_cxx_unqualified_id
286 (pp
, DECL_CONSTRUCTOR_P (t
) ? DECL_CONTEXT (t
) : t
);
287 pp_cxx_parameter_declaration_clause (pp
, TREE_TYPE (t
));
292 pp_cxx_nested_name_specifier (pp
, TREE_OPERAND (t
, 0));
293 pp_cxx_unqualified_id (pp
, TREE_OPERAND (t
, 1));
298 tree scope
= get_containing_scope (t
);
299 if (scope
!= pp
->enclosing_scope
)
301 pp_cxx_nested_name_specifier (pp
, scope
);
302 pp_cxx_template_keyword_if_needed (pp
, scope
, t
);
304 pp_cxx_unqualified_id (pp
, t
);
312 cxx_pretty_printer::constant (tree t
)
314 switch (TREE_CODE (t
))
318 const bool in_parens
= PAREN_STRING_LITERAL_P (t
);
320 pp_cxx_left_paren (this);
321 c_pretty_printer::constant (t
);
323 pp_cxx_right_paren (this);
328 if (NULLPTR_TYPE_P (TREE_TYPE (t
)))
330 pp_string (this, "nullptr");
333 /* else fall through. */
336 c_pretty_printer::constant (t
);
346 cxx_pretty_printer::id_expression (tree t
)
348 if (TREE_CODE (t
) == OVERLOAD
)
350 if (DECL_P (t
) && DECL_CONTEXT (t
))
351 pp_cxx_qualified_id (this, t
);
353 pp_cxx_unqualified_id (this, t
);
356 /* user-defined literal:
360 pp_cxx_userdef_literal (cxx_pretty_printer
*pp
, tree t
)
362 pp
->constant (USERDEF_LITERAL_VALUE (t
));
363 pp
->id_expression (USERDEF_LITERAL_SUFFIX_ID (t
));
367 /* primary-expression:
371 :: operator-function-id
377 __builtin_va_arg ( assignment-expression , type-id )
378 __builtin_offsetof ( type-id, offsetof-expression )
380 __has_nothrow_assign ( type-id )
381 __has_nothrow_constructor ( type-id )
382 __has_nothrow_copy ( type-id )
383 __has_trivial_assign ( type-id )
384 __has_trivial_constructor ( type-id )
385 __has_trivial_copy ( type-id )
386 __has_trivial_destructor ( type-id )
387 __has_virtual_destructor ( type-id )
388 __is_abstract ( type-id )
389 __is_base_of ( type-id , type-id )
390 __is_class ( type-id )
391 __is_empty ( type-id )
392 __is_enum ( type-id )
393 __is_literal_type ( type-id )
395 __is_polymorphic ( type-id )
396 __is_std_layout ( type-id )
397 __is_trivial ( type-id )
398 __is_union ( type-id ) */
401 cxx_pretty_printer::primary_expression (tree t
)
403 switch (TREE_CODE (t
))
413 case USERDEF_LITERAL
:
414 pp_cxx_userdef_literal (this, t
);
418 t
= BASELINK_FUNCTIONS (t
);
430 case TEMPLATE_TYPE_PARM
:
431 case TEMPLATE_TEMPLATE_PARM
:
432 case TEMPLATE_PARM_INDEX
:
433 pp_cxx_unqualified_id (this, t
);
437 pp_cxx_left_paren (this);
438 statement (STMT_EXPR_STMT (t
));
439 pp_cxx_right_paren (this);
443 pp_cxx_trait_expression (this, t
);
447 pp_cxx_va_arg_expression (this, t
);
451 pp_cxx_offsetof_expression (this, t
);
455 c_pretty_printer::primary_expression (t
);
460 /* postfix-expression:
462 postfix-expression [ expression ]
463 postfix-expression ( expression-list(opt) )
464 simple-type-specifier ( expression-list(opt) )
465 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
466 typename ::(opt) nested-name-specifier template(opt)
467 template-id ( expression-list(opt) )
468 postfix-expression . template(opt) ::(opt) id-expression
469 postfix-expression -> template(opt) ::(opt) id-expression
470 postfix-expression . pseudo-destructor-name
471 postfix-expression -> pseudo-destructor-name
472 postfix-expression ++
473 postfix-expression --
474 dynamic_cast < type-id > ( expression )
475 static_cast < type-id > ( expression )
476 reinterpret_cast < type-id > ( expression )
477 const_cast < type-id > ( expression )
478 typeid ( expression )
479 typeid ( type-id ) */
482 cxx_pretty_printer::postfix_expression (tree t
)
484 enum tree_code code
= TREE_CODE (t
);
491 tree fun
= (code
== AGGR_INIT_EXPR
? AGGR_INIT_EXPR_FN (t
)
493 tree saved_scope
= enclosing_scope
;
494 bool skipfirst
= false;
497 if (TREE_CODE (fun
) == ADDR_EXPR
)
498 fun
= TREE_OPERAND (fun
, 0);
500 /* In templates, where there is no way to tell whether a given
501 call uses an actual member function. So the parser builds
502 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
503 instantiation time. */
504 if (TREE_CODE (fun
) != FUNCTION_DECL
)
506 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun
))
508 tree object
= (code
== AGGR_INIT_EXPR
509 ? (AGGR_INIT_VIA_CTOR_P (t
)
510 ? AGGR_INIT_EXPR_SLOT (t
)
511 : AGGR_INIT_EXPR_ARG (t
, 0))
512 : CALL_EXPR_ARG (t
, 0));
514 while (TREE_CODE (object
) == NOP_EXPR
)
515 object
= TREE_OPERAND (object
, 0);
517 if (TREE_CODE (object
) == ADDR_EXPR
)
518 object
= TREE_OPERAND (object
, 0);
520 if (!TYPE_PTR_P (TREE_TYPE (object
)))
522 postfix_expression (object
);
527 postfix_expression (object
);
531 enclosing_scope
= strip_pointer_operator (TREE_TYPE (object
));
534 postfix_expression (fun
);
535 enclosing_scope
= saved_scope
;
536 pp_cxx_left_paren (this);
537 if (code
== AGGR_INIT_EXPR
)
539 aggr_init_expr_arg_iterator iter
;
540 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
547 if (more_aggr_init_expr_args_p (&iter
))
548 pp_cxx_separate_with (this, ',');
554 call_expr_arg_iterator iter
;
555 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
562 if (more_call_expr_args_p (&iter
))
563 pp_cxx_separate_with (this, ',');
567 pp_cxx_right_paren (this);
569 if (code
== AGGR_INIT_EXPR
&& AGGR_INIT_VIA_CTOR_P (t
))
571 pp_cxx_separate_with (this, ',');
572 postfix_expression (AGGR_INIT_EXPR_SLOT (t
));
585 primary_expression (t
);
588 case DYNAMIC_CAST_EXPR
:
589 case STATIC_CAST_EXPR
:
590 case REINTERPRET_CAST_EXPR
:
591 case CONST_CAST_EXPR
:
592 if (code
== DYNAMIC_CAST_EXPR
)
593 pp_cxx_ws_string (this, "dynamic_cast");
594 else if (code
== STATIC_CAST_EXPR
)
595 pp_cxx_ws_string (this, "static_cast");
596 else if (code
== REINTERPRET_CAST_EXPR
)
597 pp_cxx_ws_string (this, "reinterpret_cast");
599 pp_cxx_ws_string (this, "const_cast");
600 pp_cxx_begin_template_argument_list (this);
601 type_id (TREE_TYPE (t
));
602 pp_cxx_end_template_argument_list (this);
603 pp_left_paren (this);
604 expression (TREE_OPERAND (t
, 0));
605 pp_right_paren (this);
608 case EMPTY_CLASS_EXPR
:
609 type_id (TREE_TYPE (t
));
610 pp_left_paren (this);
611 pp_right_paren (this);
615 pp_cxx_typeid_expression (this, t
);
618 case PSEUDO_DTOR_EXPR
:
619 postfix_expression (TREE_OPERAND (t
, 0));
621 if (TREE_OPERAND (t
, 1))
623 pp_cxx_qualified_id (this, TREE_OPERAND (t
, 1));
624 pp_cxx_colon_colon (this);
626 pp_complement (this);
627 pp_cxx_unqualified_id (this, TREE_OPERAND (t
, 2));
631 postfix_expression (TREE_OPERAND (t
, 0));
636 c_pretty_printer::postfix_expression (t
);
642 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
643 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
649 type-specifier-seq new-declarator(opt)
652 ptr-operator new-declarator(opt)
653 direct-new-declarator
655 direct-new-declarator
657 direct-new-declarator [ constant-expression ]
660 ( expression-list(opt) ) */
663 pp_cxx_new_expression (cxx_pretty_printer
*pp
, tree t
)
665 enum tree_code code
= TREE_CODE (t
);
666 tree type
= TREE_OPERAND (t
, 1);
667 tree init
= TREE_OPERAND (t
, 2);
672 if (NEW_EXPR_USE_GLOBAL (t
))
673 pp_cxx_colon_colon (pp
);
674 pp_cxx_ws_string (pp
, "new");
675 if (TREE_OPERAND (t
, 0))
677 pp_cxx_call_argument_list (pp
, TREE_OPERAND (t
, 0));
680 if (TREE_CODE (type
) == ARRAY_REF
)
681 type
= build_cplus_array_type
682 (TREE_OPERAND (type
, 0),
683 build_index_type (fold_build2_loc (input_location
,
684 MINUS_EXPR
, integer_type_node
,
685 TREE_OPERAND (type
, 1),
691 if (TREE_CODE (init
) == TREE_LIST
)
692 pp_c_expression_list (pp
, init
);
693 else if (init
== void_node
)
694 ; /* OK, empty initializer list. */
696 pp
->expression (init
);
702 pp_unsupported_tree (pp
, t
);
706 /* delete-expression:
707 ::(opt) delete cast-expression
708 ::(opt) delete [ ] cast-expression */
711 pp_cxx_delete_expression (cxx_pretty_printer
*pp
, tree t
)
713 enum tree_code code
= TREE_CODE (t
);
717 case VEC_DELETE_EXPR
:
718 if (DELETE_EXPR_USE_GLOBAL (t
))
719 pp_cxx_colon_colon (pp
);
720 pp_cxx_ws_string (pp
, "delete");
722 if (code
== VEC_DELETE_EXPR
723 || DELETE_EXPR_USE_VEC (t
))
725 pp_left_bracket (pp
);
726 pp_right_bracket (pp
);
729 pp_c_cast_expression (pp
, TREE_OPERAND (t
, 0));
733 pp_unsupported_tree (pp
, t
);
741 unary-operator cast-expression
742 sizeof unary-expression
744 sizeof ... ( identifier )
748 unary-operator: one of
752 __alignof__ unary-expression
753 __alignof__ ( type-id ) */
756 cxx_pretty_printer::unary_expression (tree t
)
758 enum tree_code code
= TREE_CODE (t
);
763 pp_cxx_new_expression (this, t
);
767 case VEC_DELETE_EXPR
:
768 pp_cxx_delete_expression (this, t
);
772 if (PACK_EXPANSION_P (TREE_OPERAND (t
, 0)))
774 pp_cxx_ws_string (this, "sizeof");
775 pp_cxx_ws_string (this, "...");
776 pp_cxx_whitespace (this);
777 pp_cxx_left_paren (this);
778 if (TYPE_P (TREE_OPERAND (t
, 0)))
779 type_id (TREE_OPERAND (t
, 0));
781 unary_expression (TREE_OPERAND (t
, 0));
782 pp_cxx_right_paren (this);
788 pp_cxx_ws_string (this, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
789 pp_cxx_whitespace (this);
790 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
792 pp_cxx_left_paren (this);
793 type_id (TREE_TYPE (TREE_OPERAND (t
, 0)));
794 pp_cxx_right_paren (this);
796 else if (TYPE_P (TREE_OPERAND (t
, 0)))
798 pp_cxx_left_paren (this);
799 type_id (TREE_OPERAND (t
, 0));
800 pp_cxx_right_paren (this);
803 unary_expression (TREE_OPERAND (t
, 0));
807 pp_cxx_ws_string (this, "@encode");
808 pp_cxx_whitespace (this);
809 pp_cxx_left_paren (this);
810 type_id (TREE_OPERAND (t
, 0));
811 pp_cxx_right_paren (this);
815 pp_cxx_ws_string (this, "noexcept");
816 pp_cxx_whitespace (this);
817 pp_cxx_left_paren (this);
818 expression (TREE_OPERAND (t
, 0));
819 pp_cxx_right_paren (this);
822 case UNARY_PLUS_EXPR
:
824 pp_cxx_cast_expression (this, TREE_OPERAND (t
, 0));
828 c_pretty_printer::unary_expression (t
);
835 ( type-id ) cast-expression */
838 pp_cxx_cast_expression (cxx_pretty_printer
*pp
, tree t
)
840 switch (TREE_CODE (t
))
843 case IMPLICIT_CONV_EXPR
:
844 pp
->type_id (TREE_TYPE (t
));
845 pp_cxx_call_argument_list (pp
, TREE_OPERAND (t
, 0));
849 pp_c_cast_expression (pp
, t
);
856 pm-expression .* cast-expression
857 pm-expression ->* cast-expression */
860 pp_cxx_pm_expression (cxx_pretty_printer
*pp
, tree t
)
862 switch (TREE_CODE (t
))
864 /* Handle unfortunate OFFSET_REF overloading here. */
866 if (TYPE_P (TREE_OPERAND (t
, 0)))
868 pp_cxx_qualified_id (pp
, t
);
871 /* Else fall through. */
874 pp_cxx_pm_expression (pp
, TREE_OPERAND (t
, 0));
875 if (TREE_CODE (t
) == MEMBER_REF
)
880 pp_cxx_cast_expression (pp
, TREE_OPERAND (t
, 1));
885 pp_cxx_cast_expression (pp
, t
);
890 /* multiplicative-expression:
892 multiplicative-expression * pm-expression
893 multiplicative-expression / pm-expression
894 multiplicative-expression % pm-expression */
897 cxx_pretty_printer::multiplicative_expression (tree e
)
899 enum tree_code code
= TREE_CODE (e
);
905 multiplicative_expression (TREE_OPERAND (e
, 0));
907 if (code
== MULT_EXPR
)
909 else if (code
== TRUNC_DIV_EXPR
)
914 pp_cxx_pm_expression (this, TREE_OPERAND (e
, 1));
918 pp_cxx_pm_expression (this, e
);
923 /* conditional-expression:
924 logical-or-expression
925 logical-or-expression ? expression : assignment-expression */
928 cxx_pretty_printer::conditional_expression (tree e
)
930 if (TREE_CODE (e
) == COND_EXPR
)
932 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
936 expression (TREE_OPERAND (e
, 1));
938 assignment_expression (TREE_OPERAND (e
, 2));
941 pp_c_logical_or_expression (this, e
);
944 /* Pretty-print a compound assignment operator token as indicated by T. */
947 pp_cxx_assignment_operator (cxx_pretty_printer
*pp
, tree t
)
951 switch (TREE_CODE (t
))
974 op
= get_tree_code_name (TREE_CODE (t
));
978 pp_cxx_ws_string (pp
, op
);
982 /* assignment-expression:
983 conditional-expression
984 logical-or-expression assignment-operator assignment-expression
988 throw assignment-expression(opt)
990 assignment-operator: one of
991 = *= /= %= += -= >>= <<= &= ^= |= */
994 cxx_pretty_printer::assignment_expression (tree e
)
996 switch (TREE_CODE (e
))
1000 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
1004 assignment_expression (TREE_OPERAND (e
, 1));
1008 pp_cxx_ws_string (this, "throw");
1009 if (TREE_OPERAND (e
, 0))
1010 assignment_expression (TREE_OPERAND (e
, 0));
1014 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
1015 pp_cxx_assignment_operator (this, TREE_OPERAND (e
, 1));
1016 assignment_expression (TREE_OPERAND (e
, 2));
1020 conditional_expression (e
);
1026 cxx_pretty_printer::expression (tree t
)
1028 switch (TREE_CODE (t
))
1038 case USERDEF_LITERAL
:
1039 pp_cxx_userdef_literal (this, t
);
1043 pp_cxx_unqualified_id (this, t
);
1051 pp_cxx_qualified_id (this, t
);
1055 t
= OVL_CURRENT (t
);
1063 case TEMPLATE_TYPE_PARM
:
1064 case TEMPLATE_PARM_INDEX
:
1065 case TEMPLATE_TEMPLATE_PARM
:
1067 primary_expression (t
);
1071 case DYNAMIC_CAST_EXPR
:
1072 case STATIC_CAST_EXPR
:
1073 case REINTERPRET_CAST_EXPR
:
1074 case CONST_CAST_EXPR
:
1078 case EMPTY_CLASS_EXPR
:
1080 case PSEUDO_DTOR_EXPR
:
1081 case AGGR_INIT_EXPR
:
1083 postfix_expression (t
);
1088 pp_cxx_new_expression (this, t
);
1092 case VEC_DELETE_EXPR
:
1093 pp_cxx_delete_expression (this, t
);
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 TEMPLATE_ID_EXPR
:
1141 pp_cxx_template_id (this, t
);
1144 case NONTYPE_ARGUMENT_PACK
:
1146 tree args
= ARGUMENT_PACK_ARGS (t
);
1147 int i
, len
= TREE_VEC_LENGTH (args
);
1148 for (i
= 0; i
< len
; ++i
)
1151 pp_cxx_separate_with (this, ',');
1152 expression (TREE_VEC_ELT (args
, i
));
1158 pp_cxx_ws_string (this, "<lambda>");
1162 pp_cxx_left_paren (this);
1163 expression (TREE_OPERAND (t
, 0));
1164 pp_cxx_right_paren (this);
1168 c_pretty_printer::expression (t
);
1176 /* function-specifier:
1182 cxx_pretty_printer::function_specifier (tree t
)
1184 switch (TREE_CODE (t
))
1187 if (DECL_VIRTUAL_P (t
))
1188 pp_cxx_ws_string (this, "virtual");
1189 else if (DECL_CONSTRUCTOR_P (t
) && DECL_NONCONVERTING_P (t
))
1190 pp_cxx_ws_string (this, "explicit");
1192 c_pretty_printer::function_specifier (t
);
1199 /* decl-specifier-seq:
1200 decl-specifier-seq(opt) decl-specifier
1203 storage-class-specifier
1210 cxx_pretty_printer::declaration_specifiers (tree t
)
1212 switch (TREE_CODE (t
))
1218 storage_class_specifier (t
);
1219 declaration_specifiers (TREE_TYPE (t
));
1223 pp_cxx_ws_string (this, "typedef");
1224 declaration_specifiers (TREE_TYPE (t
));
1228 /* Constructors don't have return types. And conversion functions
1229 do not have a type-specifier in their return types. */
1230 if (DECL_CONSTRUCTOR_P (t
) || DECL_CONV_FN_P (t
))
1231 function_specifier (t
);
1232 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1233 declaration_specifiers (TREE_TYPE (TREE_TYPE (t
)));
1236 c_pretty_printer::declaration_specifiers (t
);
1241 /* simple-type-specifier:
1242 ::(opt) nested-name-specifier(opt) type-name
1243 ::(opt) nested-name-specifier(opt) template(opt) template-id
1257 cxx_pretty_printer::simple_type_specifier (tree t
)
1259 switch (TREE_CODE (t
))
1264 pp_cxx_qualified_id (this, t
);
1267 case TEMPLATE_TYPE_PARM
:
1268 case TEMPLATE_TEMPLATE_PARM
:
1269 case TEMPLATE_PARM_INDEX
:
1270 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1271 pp_cxx_unqualified_id (this, t
);
1275 pp_cxx_ws_string (this, "typename");
1276 pp_cxx_nested_name_specifier (this, TYPE_CONTEXT (t
));
1277 pp_cxx_unqualified_id (this, TYPE_NAME (t
));
1281 c_pretty_printer::simple_type_specifier (t
);
1286 /* type-specifier-seq:
1287 type-specifier type-specifier-seq(opt)
1290 simple-type-specifier
1293 elaborated-type-specifier
1297 pp_cxx_type_specifier_seq (cxx_pretty_printer
*pp
, tree t
)
1299 switch (TREE_CODE (t
))
1302 case TEMPLATE_TYPE_PARM
:
1303 case TEMPLATE_TEMPLATE_PARM
:
1305 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1306 pp_cxx_cv_qualifier_seq (pp
, t
);
1307 pp
->simple_type_specifier (t
);
1311 pp_cxx_type_specifier_seq (pp
, TREE_TYPE (t
));
1312 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (t
));
1313 pp_cxx_nested_name_specifier (pp
, TYPE_METHOD_BASETYPE (t
));
1317 pp_cxx_ws_string (pp
, "decltype");
1318 pp_cxx_left_paren (pp
);
1319 pp
->expression (DECLTYPE_TYPE_EXPR (t
));
1320 pp_cxx_right_paren (pp
);
1324 if (TYPE_PTRMEMFUNC_P (t
))
1326 tree pfm
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
1327 pp
->declaration_specifiers (TREE_TYPE (TREE_TYPE (pfm
)));
1328 pp_cxx_whitespace (pp
);
1329 pp_cxx_ptr_operator (pp
, t
);
1332 /* else fall through */
1335 if (!(TREE_CODE (t
) == FUNCTION_DECL
&& DECL_CONSTRUCTOR_P (t
)))
1336 pp_c_specifier_qualifier_list (pp
, t
);
1341 * cv-qualifier-seq(opt)
1343 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1346 pp_cxx_ptr_operator (cxx_pretty_printer
*pp
, tree t
)
1348 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
1350 switch (TREE_CODE (t
))
1352 case REFERENCE_TYPE
:
1354 if (TYPE_PTR_OR_PTRMEM_P (TREE_TYPE (t
)))
1355 pp_cxx_ptr_operator (pp
, TREE_TYPE (t
));
1356 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (TREE_TYPE (t
)));
1360 pp_cxx_cv_qualifier_seq (pp
, t
);
1367 if (TYPE_PTRMEMFUNC_P (t
))
1369 pp_cxx_left_paren (pp
);
1370 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEMFUNC_OBJECT_TYPE (t
));
1375 if (TYPE_PTRMEM_P (t
))
1377 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1378 pp_cxx_left_paren (pp
);
1379 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEM_CLASS_TYPE (t
));
1381 pp_cxx_cv_qualifier_seq (pp
, t
);
1384 /* else fall through. */
1387 pp_unsupported_tree (pp
, t
);
1393 pp_cxx_implicit_parameter_type (tree mf
)
1395 return class_of_this_parm (TREE_TYPE (mf
));
1399 parameter-declaration:
1400 decl-specifier-seq declarator
1401 decl-specifier-seq declarator = assignment-expression
1402 decl-specifier-seq abstract-declarator(opt)
1403 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1406 pp_cxx_parameter_declaration (cxx_pretty_printer
*pp
, tree t
)
1408 pp
->declaration_specifiers (t
);
1410 pp
->abstract_declarator (t
);
1415 /* parameter-declaration-clause:
1416 parameter-declaration-list(opt) ...(opt)
1417 parameter-declaration-list , ...
1419 parameter-declaration-list:
1420 parameter-declaration
1421 parameter-declaration-list , parameter-declaration */
1424 pp_cxx_parameter_declaration_clause (cxx_pretty_printer
*pp
, tree t
)
1426 tree args
= TYPE_P (t
) ? NULL
: FUNCTION_FIRST_USER_PARM (t
);
1428 TYPE_P (t
) ? TYPE_ARG_TYPES (t
) : FUNCTION_FIRST_USER_PARMTYPE (t
);
1429 const bool abstract
= args
== NULL
|| pp
->flags
& pp_c_flag_abstract
;
1432 /* Skip artificial parameter for nonstatic member functions. */
1433 if (TREE_CODE (t
) == METHOD_TYPE
)
1434 types
= TREE_CHAIN (types
);
1436 pp_cxx_left_paren (pp
);
1437 for (; args
; args
= TREE_CHAIN (args
), types
= TREE_CHAIN (types
))
1440 pp_cxx_separate_with (pp
, ',');
1442 pp_cxx_parameter_declaration (pp
, abstract
? TREE_VALUE (types
) : args
);
1443 if (!abstract
&& pp
->flags
& pp_cxx_flag_default_argument
)
1445 pp_cxx_whitespace (pp
);
1447 pp_cxx_whitespace (pp
);
1448 pp
->assignment_expression (TREE_PURPOSE (types
));
1451 pp_cxx_right_paren (pp
);
1454 /* exception-specification:
1455 throw ( type-id-list(opt) )
1459 type-id-list , type-id */
1462 pp_cxx_exception_specification (cxx_pretty_printer
*pp
, tree t
)
1464 tree ex_spec
= TYPE_RAISES_EXCEPTIONS (t
);
1465 bool need_comma
= false;
1467 if (ex_spec
== NULL
)
1469 if (TREE_PURPOSE (ex_spec
))
1471 pp_cxx_ws_string (pp
, "noexcept");
1472 pp_cxx_whitespace (pp
);
1473 pp_cxx_left_paren (pp
);
1474 if (DEFERRED_NOEXCEPT_SPEC_P (ex_spec
))
1475 pp_cxx_ws_string (pp
, "<uninstantiated>");
1477 pp
->expression (TREE_PURPOSE (ex_spec
));
1478 pp_cxx_right_paren (pp
);
1481 pp_cxx_ws_string (pp
, "throw");
1482 pp_cxx_left_paren (pp
);
1483 for (; ex_spec
&& TREE_VALUE (ex_spec
); ex_spec
= TREE_CHAIN (ex_spec
))
1485 tree type
= TREE_VALUE (ex_spec
);
1486 tree argpack
= NULL_TREE
;
1489 if (ARGUMENT_PACK_P (type
))
1491 argpack
= ARGUMENT_PACK_ARGS (type
);
1492 len
= TREE_VEC_LENGTH (argpack
);
1495 for (i
= 0; i
< len
; ++i
)
1498 type
= TREE_VEC_ELT (argpack
, i
);
1501 pp_cxx_separate_with (pp
, ',');
1508 pp_cxx_right_paren (pp
);
1511 /* direct-declarator:
1513 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1514 exception-specification(opt)
1515 direct-declaration [ constant-expression(opt) ]
1519 cxx_pretty_printer::direct_declarator (tree t
)
1521 switch (TREE_CODE (t
))
1529 pp_cxx_space_for_pointer_operator (this, TREE_TYPE (t
));
1531 if ((TREE_CODE (t
) == PARM_DECL
&& DECL_PACK_P (t
))
1532 || template_parameter_pack_p (t
))
1533 /* A function parameter pack or non-type template
1535 pp_cxx_ws_string (this, "...");
1537 id_expression (DECL_NAME (t
));
1539 abstract_declarator (TREE_TYPE (t
));
1543 pp_cxx_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t
)));
1545 pp_cxx_parameter_declaration_clause (this, t
);
1547 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1549 padding
= pp_before
;
1550 pp_cxx_cv_qualifier_seq (this, pp_cxx_implicit_parameter_type (t
));
1553 pp_cxx_exception_specification (this, TREE_TYPE (t
));
1558 case TEMPLATE_TYPE_PARM
:
1559 case TEMPLATE_PARM_INDEX
:
1560 case TEMPLATE_TEMPLATE_PARM
:
1564 c_pretty_printer::direct_declarator (t
);
1571 ptr-operator declarator */
1574 cxx_pretty_printer::declarator (tree t
)
1576 direct_declarator (t
);
1579 /* ctor-initializer:
1580 : mem-initializer-list
1582 mem-initializer-list:
1584 mem-initializer , mem-initializer-list
1587 mem-initializer-id ( expression-list(opt) )
1590 ::(opt) nested-name-specifier(opt) class-name
1594 pp_cxx_ctor_initializer (cxx_pretty_printer
*pp
, tree t
)
1596 t
= TREE_OPERAND (t
, 0);
1597 pp_cxx_whitespace (pp
);
1599 pp_cxx_whitespace (pp
);
1600 for (; t
; t
= TREE_CHAIN (t
))
1602 tree purpose
= TREE_PURPOSE (t
);
1603 bool is_pack
= PACK_EXPANSION_P (purpose
);
1606 pp
->primary_expression (PACK_EXPANSION_PATTERN (purpose
));
1608 pp
->primary_expression (purpose
);
1609 pp_cxx_call_argument_list (pp
, TREE_VALUE (t
));
1611 pp_cxx_ws_string (pp
, "...");
1613 pp_cxx_separate_with (pp
, ',');
1617 /* function-definition:
1618 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1619 decl-specifier-seq(opt) declarator function-try-block */
1622 pp_cxx_function_definition (cxx_pretty_printer
*pp
, tree t
)
1624 tree saved_scope
= pp
->enclosing_scope
;
1625 pp
->declaration_specifiers (t
);
1627 pp_needs_newline (pp
) = true;
1628 pp
->enclosing_scope
= DECL_CONTEXT (t
);
1629 if (DECL_SAVED_TREE (t
))
1630 pp
->statement (DECL_SAVED_TREE (t
));
1632 pp_cxx_semicolon (pp
);
1633 pp_newline_and_flush (pp
);
1634 pp
->enclosing_scope
= saved_scope
;
1637 /* abstract-declarator:
1638 ptr-operator abstract-declarator(opt)
1639 direct-abstract-declarator */
1642 cxx_pretty_printer::abstract_declarator (tree t
)
1644 if (TYPE_PTRMEM_P (t
))
1645 pp_cxx_right_paren (this);
1646 else if (POINTER_TYPE_P (t
))
1648 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
1649 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1650 pp_cxx_right_paren (this);
1653 direct_abstract_declarator (t
);
1656 /* direct-abstract-declarator:
1657 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1658 cv-qualifier-seq(opt) exception-specification(opt)
1659 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1660 ( abstract-declarator ) */
1663 cxx_pretty_printer::direct_abstract_declarator (tree t
)
1665 switch (TREE_CODE (t
))
1667 case REFERENCE_TYPE
:
1668 abstract_declarator (t
);
1672 if (TYPE_PTRMEMFUNC_P (t
))
1673 direct_abstract_declarator (TYPE_PTRMEMFUNC_FN_TYPE (t
));
1678 pp_cxx_parameter_declaration_clause (this, t
);
1679 direct_abstract_declarator (TREE_TYPE (t
));
1680 if (TREE_CODE (t
) == METHOD_TYPE
)
1682 padding
= pp_before
;
1683 pp_cxx_cv_qualifier_seq (this, class_of_this_parm (t
));
1685 pp_cxx_exception_specification (this, t
);
1689 case TEMPLATE_TYPE_PARM
:
1690 case TEMPLATE_TEMPLATE_PARM
:
1691 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1692 case UNBOUND_CLASS_TEMPLATE
:
1696 c_pretty_printer::direct_abstract_declarator (t
);
1702 type-specifier-seq abstract-declarator(opt) */
1705 cxx_pretty_printer::type_id (tree t
)
1707 pp_flags saved_flags
= flags
;
1708 flags
|= pp_c_flag_abstract
;
1710 switch (TREE_CODE (t
))
1717 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1718 case UNBOUND_CLASS_TEMPLATE
:
1719 case TEMPLATE_TEMPLATE_PARM
:
1720 case TEMPLATE_TYPE_PARM
:
1721 case TEMPLATE_PARM_INDEX
:
1724 case UNDERLYING_TYPE
:
1726 case TEMPLATE_ID_EXPR
:
1727 pp_cxx_type_specifier_seq (this, t
);
1730 case TYPE_PACK_EXPANSION
:
1731 type_id (PACK_EXPANSION_PATTERN (t
));
1732 pp_cxx_ws_string (this, "...");
1736 c_pretty_printer::type_id (t
);
1740 flags
= saved_flags
;
1743 /* template-argument-list:
1744 template-argument ...(opt)
1745 template-argument-list, template-argument ...(opt)
1748 assignment-expression
1753 pp_cxx_template_argument_list (cxx_pretty_printer
*pp
, tree t
)
1756 bool need_comma
= false;
1760 for (i
= 0; i
< TREE_VEC_LENGTH (t
); ++i
)
1762 tree arg
= TREE_VEC_ELT (t
, i
);
1763 tree argpack
= NULL_TREE
;
1766 if (ARGUMENT_PACK_P (arg
))
1768 argpack
= ARGUMENT_PACK_ARGS (arg
);
1769 len
= TREE_VEC_LENGTH (argpack
);
1772 for (idx
= 0; idx
< len
; idx
++)
1775 arg
= TREE_VEC_ELT (argpack
, idx
);
1778 pp_cxx_separate_with (pp
, ',');
1782 if (TYPE_P (arg
) || (TREE_CODE (arg
) == TEMPLATE_DECL
1783 && TYPE_P (DECL_TEMPLATE_RESULT (arg
))))
1786 pp
->expression (arg
);
1793 pp_cxx_exception_declaration (cxx_pretty_printer
*pp
, tree t
)
1795 t
= DECL_EXPR_DECL (t
);
1796 pp_cxx_type_specifier_seq (pp
, t
);
1798 pp
->abstract_declarator (t
);
1806 cxx_pretty_printer::statement (tree t
)
1808 switch (TREE_CODE (t
))
1810 case CTOR_INITIALIZER
:
1811 pp_cxx_ctor_initializer (this, t
);
1815 pp_cxx_ws_string (this, "using");
1816 pp_cxx_ws_string (this, "namespace");
1817 if (DECL_CONTEXT (t
))
1818 pp_cxx_nested_name_specifier (this, DECL_CONTEXT (t
));
1819 pp_cxx_qualified_id (this, USING_STMT_NAMESPACE (t
));
1823 pp_cxx_ws_string (this, "using");
1824 pp_cxx_nested_name_specifier (this, USING_DECL_SCOPE (t
));
1825 pp_cxx_unqualified_id (this, DECL_NAME (t
));
1832 try compound-statement handler-seq */
1834 pp_maybe_newline_and_indent (this, 0);
1835 pp_cxx_ws_string (this, "try");
1836 pp_newline_and_indent (this, 3);
1837 statement (TRY_STMTS (t
));
1838 pp_newline_and_indent (this, -3);
1842 statement (TRY_HANDLERS (t
));
1847 handler handler-seq(opt)
1850 catch ( exception-declaration ) compound-statement
1852 exception-declaration:
1853 type-specifier-seq declarator
1854 type-specifier-seq abstract-declarator
1857 pp_cxx_ws_string (this, "catch");
1858 pp_cxx_left_paren (this);
1859 pp_cxx_exception_declaration (this, HANDLER_PARMS (t
));
1860 pp_cxx_right_paren (this);
1861 pp_indentation (this) += 3;
1862 pp_needs_newline (this) = true;
1863 statement (HANDLER_BODY (t
));
1864 pp_indentation (this) -= 3;
1865 pp_needs_newline (this) = true;
1868 /* selection-statement:
1869 if ( expression ) statement
1870 if ( expression ) statement else statement */
1872 pp_cxx_ws_string (this, "if");
1873 pp_cxx_whitespace (this);
1874 pp_cxx_left_paren (this);
1875 expression (IF_COND (t
));
1876 pp_cxx_right_paren (this);
1877 pp_newline_and_indent (this, 2);
1878 statement (THEN_CLAUSE (t
));
1879 pp_newline_and_indent (this, -2);
1880 if (ELSE_CLAUSE (t
))
1882 tree else_clause
= ELSE_CLAUSE (t
);
1883 pp_cxx_ws_string (this, "else");
1884 if (TREE_CODE (else_clause
) == IF_STMT
)
1885 pp_cxx_whitespace (this);
1887 pp_newline_and_indent (this, 2);
1888 statement (else_clause
);
1889 if (TREE_CODE (else_clause
) != IF_STMT
)
1890 pp_newline_and_indent (this, -2);
1895 pp_cxx_ws_string (this, "switch");
1897 pp_cxx_left_paren (this);
1898 expression (SWITCH_STMT_COND (t
));
1899 pp_cxx_right_paren (this);
1900 pp_indentation (this) += 3;
1901 pp_needs_newline (this) = true;
1902 statement (SWITCH_STMT_BODY (t
));
1903 pp_newline_and_indent (this, -3);
1906 /* iteration-statement:
1907 while ( expression ) statement
1908 do statement while ( expression ) ;
1909 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1910 for ( declaration expression(opt) ; expression(opt) ) statement */
1912 pp_cxx_ws_string (this, "while");
1914 pp_cxx_left_paren (this);
1915 expression (WHILE_COND (t
));
1916 pp_cxx_right_paren (this);
1917 pp_newline_and_indent (this, 3);
1918 statement (WHILE_BODY (t
));
1919 pp_indentation (this) -= 3;
1920 pp_needs_newline (this) = true;
1924 pp_cxx_ws_string (this, "do");
1925 pp_newline_and_indent (this, 3);
1926 statement (DO_BODY (t
));
1927 pp_newline_and_indent (this, -3);
1928 pp_cxx_ws_string (this, "while");
1930 pp_cxx_left_paren (this);
1931 expression (DO_COND (t
));
1932 pp_cxx_right_paren (this);
1933 pp_cxx_semicolon (this);
1934 pp_needs_newline (this) = true;
1938 pp_cxx_ws_string (this, "for");
1940 pp_cxx_left_paren (this);
1941 if (FOR_INIT_STMT (t
))
1942 statement (FOR_INIT_STMT (t
));
1944 pp_cxx_semicolon (this);
1945 pp_needs_newline (this) = false;
1946 pp_cxx_whitespace (this);
1948 expression (FOR_COND (t
));
1949 pp_cxx_semicolon (this);
1950 pp_needs_newline (this) = false;
1951 pp_cxx_whitespace (this);
1953 expression (FOR_EXPR (t
));
1954 pp_cxx_right_paren (this);
1955 pp_newline_and_indent (this, 3);
1956 statement (FOR_BODY (t
));
1957 pp_indentation (this) -= 3;
1958 pp_needs_newline (this) = true;
1961 case RANGE_FOR_STMT
:
1962 pp_cxx_ws_string (this, "for");
1964 pp_cxx_left_paren (this);
1965 statement (RANGE_FOR_DECL (t
));
1967 pp_needs_newline (this) = false;
1970 statement (RANGE_FOR_EXPR (t
));
1971 pp_cxx_right_paren (this);
1972 pp_newline_and_indent (this, 3);
1973 statement (FOR_BODY (t
));
1974 pp_indentation (this) -= 3;
1975 pp_needs_newline (this) = true;
1981 return expression(opt) ; */
1984 pp_string (this, TREE_CODE (t
) == BREAK_STMT
? "break" : "continue");
1985 pp_cxx_semicolon (this);
1986 pp_needs_newline (this) = true;
1989 /* expression-statement:
1990 expression(opt) ; */
1992 expression (EXPR_STMT_EXPR (t
));
1993 pp_cxx_semicolon (this);
1994 pp_needs_newline (this) = true;
1998 pp_cxx_ws_string (this, "try");
1999 pp_newline_and_indent (this, 2);
2000 statement (CLEANUP_BODY (t
));
2001 pp_newline_and_indent (this, -2);
2002 pp_cxx_ws_string (this, CLEANUP_EH_ONLY (t
) ? "catch" : "finally");
2003 pp_newline_and_indent (this, 2);
2004 statement (CLEANUP_EXPR (t
));
2005 pp_newline_and_indent (this, -2);
2013 c_pretty_printer::statement (t
);
2018 /* original-namespace-definition:
2019 namespace identifier { namespace-body }
2021 As an edge case, we also handle unnamed namespace definition here. */
2024 pp_cxx_original_namespace_definition (cxx_pretty_printer
*pp
, tree t
)
2026 pp_cxx_ws_string (pp
, "namespace");
2027 if (DECL_CONTEXT (t
))
2028 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
2030 pp_cxx_unqualified_id (pp
, t
);
2031 pp_cxx_whitespace (pp
);
2032 pp_cxx_left_brace (pp
);
2033 /* We do not print the namespace-body. */
2034 pp_cxx_whitespace (pp
);
2035 pp_cxx_right_brace (pp
);
2041 namespace-alias-definition:
2042 namespace identifier = qualified-namespace-specifier ;
2044 qualified-namespace-specifier:
2045 ::(opt) nested-name-specifier(opt) namespace-name */
2048 pp_cxx_namespace_alias_definition (cxx_pretty_printer
*pp
, tree t
)
2050 pp_cxx_ws_string (pp
, "namespace");
2051 if (DECL_CONTEXT (t
))
2052 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
2053 pp_cxx_unqualified_id (pp
, t
);
2054 pp_cxx_whitespace (pp
);
2056 pp_cxx_whitespace (pp
);
2057 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t
)))
2058 pp_cxx_nested_name_specifier (pp
,
2059 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t
)));
2060 pp_cxx_qualified_id (pp
, DECL_NAMESPACE_ALIAS (t
));
2061 pp_cxx_semicolon (pp
);
2064 /* simple-declaration:
2065 decl-specifier-seq(opt) init-declarator-list(opt) */
2068 pp_cxx_simple_declaration (cxx_pretty_printer
*pp
, tree t
)
2070 pp
->declaration_specifiers (t
);
2071 pp_cxx_init_declarator (pp
, t
);
2072 pp_cxx_semicolon (pp
);
2073 pp_needs_newline (pp
) = true;
2077 template-parameter-list:
2079 template-parameter-list , template-parameter */
2082 pp_cxx_template_parameter_list (cxx_pretty_printer
*pp
, tree t
)
2084 const int n
= TREE_VEC_LENGTH (t
);
2086 for (i
= 0; i
< n
; ++i
)
2089 pp_cxx_separate_with (pp
, ',');
2090 pp_cxx_template_parameter (pp
, TREE_VEC_ELT (t
, i
));
2094 /* template-parameter:
2096 parameter-declaration
2099 class ...(opt) identifier(opt)
2100 class identifier(opt) = type-id
2101 typename identifier(opt)
2102 typename ...(opt) identifier(opt) = type-id
2103 template < template-parameter-list > class ...(opt) identifier(opt)
2104 template < template-parameter-list > class identifier(opt) = template-name */
2107 pp_cxx_template_parameter (cxx_pretty_printer
*pp
, tree t
)
2109 tree parameter
= TREE_VALUE (t
);
2110 switch (TREE_CODE (parameter
))
2113 pp_cxx_ws_string (pp
, "class");
2114 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
2115 pp_cxx_ws_string (pp
, "...");
2116 if (DECL_NAME (parameter
))
2117 pp_cxx_tree_identifier (pp
, DECL_NAME (parameter
));
2118 /* FIXME: Check if we should print also default argument. */
2122 pp_cxx_parameter_declaration (pp
, parameter
);
2129 pp_unsupported_tree (pp
, t
);
2134 /* Pretty-print a template parameter in the canonical form
2135 "template-parameter-<level>-<position in parameter list>". */
2138 pp_cxx_canonical_template_parameter (cxx_pretty_printer
*pp
, tree parm
)
2140 const enum tree_code code
= TREE_CODE (parm
);
2142 /* Brings type template parameters to the canonical forms. */
2143 if (code
== TEMPLATE_TYPE_PARM
|| code
== TEMPLATE_TEMPLATE_PARM
2144 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
)
2145 parm
= TEMPLATE_TYPE_PARM_INDEX (parm
);
2147 pp_cxx_begin_template_argument_list (pp
);
2148 pp
->translate_string ("template-parameter-");
2149 pp_wide_integer (pp
, TEMPLATE_PARM_LEVEL (parm
));
2151 pp_wide_integer (pp
, TEMPLATE_PARM_IDX (parm
) + 1);
2152 pp_cxx_end_template_argument_list (pp
);
2156 template-declaration:
2157 export(opt) template < template-parameter-list > declaration */
2160 pp_cxx_template_declaration (cxx_pretty_printer
*pp
, tree t
)
2162 tree tmpl
= most_general_template (t
);
2165 pp_maybe_newline_and_indent (pp
, 0);
2166 for (level
= DECL_TEMPLATE_PARMS (tmpl
); level
; level
= TREE_CHAIN (level
))
2168 pp_cxx_ws_string (pp
, "template");
2169 pp_cxx_begin_template_argument_list (pp
);
2170 pp_cxx_template_parameter_list (pp
, TREE_VALUE (level
));
2171 pp_cxx_end_template_argument_list (pp
);
2172 pp_newline_and_indent (pp
, 3);
2174 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_SAVED_TREE (t
))
2175 pp_cxx_function_definition (pp
, t
);
2177 pp_cxx_simple_declaration (pp
, t
);
2181 pp_cxx_explicit_specialization (cxx_pretty_printer
*pp
, tree t
)
2183 pp_unsupported_tree (pp
, t
);
2187 pp_cxx_explicit_instantiation (cxx_pretty_printer
*pp
, tree t
)
2189 pp_unsupported_tree (pp
, t
);
2196 template-declaration
2197 explicit-instantiation
2198 explicit-specialization
2199 linkage-specification
2200 namespace-definition
2205 namespace-alias-definition
2208 static_assert-declaration */
2210 cxx_pretty_printer::declaration (tree t
)
2212 if (TREE_CODE (t
) == STATIC_ASSERT
)
2214 pp_cxx_ws_string (this, "static_assert");
2215 pp_cxx_left_paren (this);
2216 expression (STATIC_ASSERT_CONDITION (t
));
2217 pp_cxx_separate_with (this, ',');
2218 expression (STATIC_ASSERT_MESSAGE (t
));
2219 pp_cxx_right_paren (this);
2221 else if (!DECL_LANG_SPECIFIC (t
))
2222 pp_cxx_simple_declaration (this, t
);
2223 else if (DECL_USE_TEMPLATE (t
))
2224 switch (DECL_USE_TEMPLATE (t
))
2227 pp_cxx_template_declaration (this, t
);
2231 pp_cxx_explicit_specialization (this, t
);
2235 pp_cxx_explicit_instantiation (this, t
);
2241 else switch (TREE_CODE (t
))
2245 pp_cxx_simple_declaration (this, t
);
2249 if (DECL_SAVED_TREE (t
))
2250 pp_cxx_function_definition (this, t
);
2252 pp_cxx_simple_declaration (this, t
);
2255 case NAMESPACE_DECL
:
2256 if (DECL_NAMESPACE_ALIAS (t
))
2257 pp_cxx_namespace_alias_definition (this, t
);
2259 pp_cxx_original_namespace_definition (this, t
);
2263 pp_unsupported_tree (this, t
);
2269 pp_cxx_typeid_expression (cxx_pretty_printer
*pp
, tree t
)
2271 t
= TREE_OPERAND (t
, 0);
2272 pp_cxx_ws_string (pp
, "typeid");
2273 pp_cxx_left_paren (pp
);
2278 pp_cxx_right_paren (pp
);
2282 pp_cxx_va_arg_expression (cxx_pretty_printer
*pp
, tree t
)
2284 pp_cxx_ws_string (pp
, "va_arg");
2285 pp_cxx_left_paren (pp
);
2286 pp
->assignment_expression (TREE_OPERAND (t
, 0));
2287 pp_cxx_separate_with (pp
, ',');
2288 pp
->type_id (TREE_TYPE (t
));
2289 pp_cxx_right_paren (pp
);
2293 pp_cxx_offsetof_expression_1 (cxx_pretty_printer
*pp
, tree t
)
2295 switch (TREE_CODE (t
))
2298 if (TREE_CODE (TREE_OPERAND (t
, 0)) == STATIC_CAST_EXPR
2299 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (t
, 0))))
2301 pp
->type_id (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))));
2302 pp_cxx_separate_with (pp
, ',');
2307 if (!pp_cxx_offsetof_expression_1 (pp
, TREE_OPERAND (t
, 0)))
2309 if (TREE_CODE (TREE_OPERAND (t
, 0)) != ARROW_EXPR
)
2311 pp
->expression (TREE_OPERAND (t
, 1));
2314 if (!pp_cxx_offsetof_expression_1 (pp
, TREE_OPERAND (t
, 0)))
2316 pp_left_bracket (pp
);
2317 pp
->expression (TREE_OPERAND (t
, 1));
2318 pp_right_bracket (pp
);
2326 pp_cxx_offsetof_expression (cxx_pretty_printer
*pp
, tree t
)
2328 pp_cxx_ws_string (pp
, "offsetof");
2329 pp_cxx_left_paren (pp
);
2330 if (!pp_cxx_offsetof_expression_1 (pp
, TREE_OPERAND (t
, 0)))
2331 pp
->expression (TREE_OPERAND (t
, 0));
2332 pp_cxx_right_paren (pp
);
2336 pp_cxx_trait_expression (cxx_pretty_printer
*pp
, tree t
)
2338 cp_trait_kind kind
= TRAIT_EXPR_KIND (t
);
2342 case CPTK_HAS_NOTHROW_ASSIGN
:
2343 pp_cxx_ws_string (pp
, "__has_nothrow_assign");
2345 case CPTK_HAS_TRIVIAL_ASSIGN
:
2346 pp_cxx_ws_string (pp
, "__has_trivial_assign");
2348 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
2349 pp_cxx_ws_string (pp
, "__has_nothrow_constructor");
2351 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
2352 pp_cxx_ws_string (pp
, "__has_trivial_constructor");
2354 case CPTK_HAS_NOTHROW_COPY
:
2355 pp_cxx_ws_string (pp
, "__has_nothrow_copy");
2357 case CPTK_HAS_TRIVIAL_COPY
:
2358 pp_cxx_ws_string (pp
, "__has_trivial_copy");
2360 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
2361 pp_cxx_ws_string (pp
, "__has_trivial_destructor");
2363 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
2364 pp_cxx_ws_string (pp
, "__has_virtual_destructor");
2366 case CPTK_IS_ABSTRACT
:
2367 pp_cxx_ws_string (pp
, "__is_abstract");
2369 case CPTK_IS_BASE_OF
:
2370 pp_cxx_ws_string (pp
, "__is_base_of");
2373 pp_cxx_ws_string (pp
, "__is_class");
2376 pp_cxx_ws_string (pp
, "__is_empty");
2379 pp_cxx_ws_string (pp
, "__is_enum");
2382 pp_cxx_ws_string (pp
, "__is_final");
2385 pp_cxx_ws_string (pp
, "__is_pod");
2387 case CPTK_IS_POLYMORPHIC
:
2388 pp_cxx_ws_string (pp
, "__is_polymorphic");
2390 case CPTK_IS_STD_LAYOUT
:
2391 pp_cxx_ws_string (pp
, "__is_std_layout");
2393 case CPTK_IS_TRIVIAL
:
2394 pp_cxx_ws_string (pp
, "__is_trivial");
2396 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
2397 pp_cxx_ws_string (pp
, "__is_trivially_assignable");
2399 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
2400 pp_cxx_ws_string (pp
, "__is_trivially_constructible");
2402 case CPTK_IS_TRIVIALLY_COPYABLE
:
2403 pp_cxx_ws_string (pp
, "__is_trivially_copyable");
2406 pp_cxx_ws_string (pp
, "__is_union");
2408 case CPTK_IS_LITERAL_TYPE
:
2409 pp_cxx_ws_string (pp
, "__is_literal_type");
2416 pp_cxx_left_paren (pp
);
2417 pp
->type_id (TRAIT_EXPR_TYPE1 (t
));
2419 if (kind
== CPTK_IS_BASE_OF
)
2421 pp_cxx_separate_with (pp
, ',');
2422 pp
->type_id (TRAIT_EXPR_TYPE2 (t
));
2425 pp_cxx_right_paren (pp
);
2428 typedef c_pretty_print_fn pp_fun
;
2430 /* Initialization of a C++ pretty-printer object. */
2432 cxx_pretty_printer::cxx_pretty_printer ()
2433 : c_pretty_printer (),
2434 enclosing_scope (global_namespace
)
2436 type_specifier_seq
= (pp_fun
) pp_cxx_type_specifier_seq
;
2437 parameter_list
= (pp_fun
) pp_cxx_parameter_declaration_clause
;