1 /* Implementation of subroutines for the GNU C++ pretty-printer.
2 Copyright (C) 2003, 2004, 2005, 2007 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"
26 #include "cxx-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_assignment_expression (cxx_pretty_printer *, tree);
34 static void pp_cxx_expression (cxx_pretty_printer *, tree);
35 static void pp_cxx_template_argument_list (cxx_pretty_printer *, tree);
36 static void pp_cxx_type_specifier_seq (cxx_pretty_printer *, tree);
37 static void pp_cxx_ptr_operator (cxx_pretty_printer *, tree);
38 static void pp_cxx_type_id (cxx_pretty_printer *, tree);
39 static void pp_cxx_direct_abstract_declarator (cxx_pretty_printer *, tree);
40 static void pp_cxx_declarator (cxx_pretty_printer *, tree);
41 static void pp_cxx_parameter_declaration_clause (cxx_pretty_printer *, tree);
42 static void pp_cxx_abstract_declarator (cxx_pretty_printer *, tree);
43 static void pp_cxx_statement (cxx_pretty_printer *, tree);
44 static void pp_cxx_template_parameter (cxx_pretty_printer *, tree);
45 static void pp_cxx_cast_expression (cxx_pretty_printer *, tree);
49 pp_cxx_nonconsecutive_character (cxx_pretty_printer *pp, int c)
51 const char *p = pp_last_position_in_text (pp);
53 if (p != NULL && *p == c)
54 pp_cxx_whitespace (pp);
56 pp_base (pp)->padding = pp_none;
59 #define pp_cxx_storage_class_specifier(PP, T) \
60 pp_c_storage_class_specifier (pp_c_base (PP), T)
61 #define pp_cxx_expression_list(PP, T) \
62 pp_c_expression_list (pp_c_base (PP), T)
63 #define pp_cxx_space_for_pointer_operator(PP, T) \
64 pp_c_space_for_pointer_operator (pp_c_base (PP), T)
65 #define pp_cxx_init_declarator(PP, T) \
66 pp_c_init_declarator (pp_c_base (PP), T)
67 #define pp_cxx_call_argument_list(PP, T) \
68 pp_c_call_argument_list (pp_c_base (PP), T)
71 pp_cxx_colon_colon (cxx_pretty_printer *pp)
74 pp_base (pp)->padding = pp_none;
78 pp_cxx_begin_template_argument_list (cxx_pretty_printer *pp)
80 pp_cxx_nonconsecutive_character (pp, '<');
84 pp_cxx_end_template_argument_list (cxx_pretty_printer *pp)
86 pp_cxx_nonconsecutive_character (pp, '>');
90 pp_cxx_separate_with (cxx_pretty_printer *pp, int c)
92 pp_separate_with (pp, c);
93 pp_base (pp)->padding = pp_none;
99 is_destructor_name (tree name)
101 return name == complete_dtor_identifier
102 || name == base_dtor_identifier
103 || name == deleting_dtor_identifier;
106 /* conversion-function-id:
107 operator conversion-type-id
110 type-specifier-seq conversion-declarator(opt)
112 conversion-declarator:
113 ptr-operator conversion-declarator(opt) */
116 pp_cxx_conversion_function_id (cxx_pretty_printer *pp, tree t)
118 pp_cxx_identifier (pp, "operator");
119 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
123 pp_cxx_template_id (cxx_pretty_printer *pp, tree t)
125 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
126 pp_cxx_begin_template_argument_list (pp);
127 pp_cxx_template_argument_list (pp, TREE_OPERAND (t, 1));
128 pp_cxx_end_template_argument_list (pp);
131 /* Prints the unqualified part of the id-expression T.
136 conversion-function-id
141 pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t)
143 enum tree_code code = TREE_CODE (t);
147 pp_cxx_identifier (pp, "<return-value>");
164 case IDENTIFIER_NODE:
166 pp_cxx_identifier (pp, "<unnamed>");
167 else if (IDENTIFIER_TYPENAME_P (t))
168 pp_cxx_conversion_function_id (pp, t);
171 if (is_destructor_name (t))
174 /* FIXME: Why is this necessary? */
176 t = constructor_name (TREE_TYPE (t));
178 pp_cxx_tree_identifier (pp, t);
182 case TEMPLATE_ID_EXPR:
183 pp_cxx_template_id (pp, t);
187 pp_cxx_unqualified_id (pp, BASELINK_FUNCTIONS (t));
194 case UNBOUND_CLASS_TEMPLATE:
195 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
199 pp_cxx_complement (pp);
200 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
203 case TEMPLATE_TYPE_PARM:
204 case TEMPLATE_TEMPLATE_PARM:
205 if (TYPE_IDENTIFIER (t))
206 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
208 pp_cxx_canonical_template_parameter (pp, t);
211 case TEMPLATE_PARM_INDEX:
212 pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t));
215 case BOUND_TEMPLATE_TEMPLATE_PARM:
216 pp_cxx_cv_qualifier_seq (pp, t);
217 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
218 pp_cxx_begin_template_argument_list (pp);
219 pp_cxx_template_argument_list (pp, TYPE_TI_ARGS (t));
220 pp_cxx_end_template_argument_list (pp);
224 pp_unsupported_tree (pp, t);
229 /* Pretty-print out the token sequence ":: template" in template codes
230 where it is needed to "inline declare" the (following) member as
231 a template. This situation arises when SCOPE of T is dependent
232 on template parameters. */
235 pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
237 if (TREE_CODE (t) == TEMPLATE_ID_EXPR
238 && TYPE_P (scope) && dependent_type_p (scope))
239 pp_cxx_identifier (pp, "template");
242 /* nested-name-specifier:
243 class-or-namespace-name :: nested-name-specifier(opt)
244 class-or-namespace-name :: template nested-name-specifier */
247 pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
249 if (t != NULL && t != pp->enclosing_scope)
251 tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
252 pp_cxx_nested_name_specifier (pp, scope);
253 pp_cxx_template_keyword_if_needed (pp, scope, t);
254 pp_cxx_unqualified_id (pp, t);
255 pp_cxx_colon_colon (pp);
260 nested-name-specifier template(opt) unqualified-id */
263 pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t)
265 switch (TREE_CODE (t))
267 /* A pointer-to-member is always qualified. */
269 pp_cxx_nested_name_specifier (pp, PTRMEM_CST_CLASS (t));
270 pp_cxx_unqualified_id (pp, PTRMEM_CST_MEMBER (t));
273 /* In Standard C++, functions cannot possibly be used as
274 nested-name-specifiers. However, there are situations where
275 is "makes sense" to output the surrounding function name for the
276 purpose of emphasizing on the scope kind. Just printing the
277 function name might not be sufficient as it may be overloaded; so,
278 we decorate the function with its signature too.
279 FIXME: This is probably the wrong pretty-printing for conversion
280 functions and some function templates. */
284 if (DECL_FUNCTION_MEMBER_P (t))
285 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
286 pp_cxx_unqualified_id
287 (pp, DECL_CONSTRUCTOR_P (t) ? DECL_CONTEXT (t) : t);
288 pp_cxx_parameter_declaration_clause (pp, TREE_TYPE (t));
293 pp_cxx_nested_name_specifier (pp, TREE_OPERAND (t, 0));
294 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 1));
299 tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
300 if (scope != pp->enclosing_scope)
302 pp_cxx_nested_name_specifier (pp, scope);
303 pp_cxx_template_keyword_if_needed (pp, scope, t);
305 pp_cxx_unqualified_id (pp, t);
313 pp_cxx_constant (cxx_pretty_printer *pp, tree t)
315 switch (TREE_CODE (t))
319 const bool in_parens = PAREN_STRING_LITERAL_P (t);
321 pp_cxx_left_paren (pp);
322 pp_c_constant (pp_c_base (pp), t);
324 pp_cxx_right_paren (pp);
329 pp_c_constant (pp_c_base (pp), t);
339 pp_cxx_id_expression (cxx_pretty_printer *pp, tree t)
341 if (TREE_CODE (t) == OVERLOAD)
343 if (DECL_P (t) && DECL_CONTEXT (t))
344 pp_cxx_qualified_id (pp, t);
346 pp_cxx_unqualified_id (pp, t);
349 /* primary-expression:
353 :: operator-function-id
359 __builtin_va_arg ( assignment-expression , type-id )
361 __has_nothrow_assign ( type-id )
362 __has_nothrow_constructor ( type-id )
363 __has_nothrow_copy ( type-id )
364 __has_trivial_assign ( type-id )
365 __has_trivial_constructor ( type-id )
366 __has_trivial_copy ( type-id )
367 __has_trivial_destructor ( type-id )
368 __has_virtual_destructor ( type-id )
369 __is_abstract ( type-id )
370 __is_base_of ( type-id , type-id )
371 __is_class ( type-id )
372 __is_convertible_to ( type-id , type-id )
373 __is_empty ( type-id )
374 __is_enum ( type-id )
376 __is_polymorphic ( type-id )
377 __is_union ( type-id ) */
380 pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
382 switch (TREE_CODE (t))
388 pp_cxx_constant (pp, t);
392 t = BASELINK_FUNCTIONS (t);
400 pp_cxx_id_expression (pp, t);
404 case TEMPLATE_TYPE_PARM:
405 case TEMPLATE_TEMPLATE_PARM:
406 case TEMPLATE_PARM_INDEX:
407 pp_cxx_unqualified_id (pp, t);
411 pp_cxx_left_paren (pp);
412 pp_cxx_statement (pp, STMT_EXPR_STMT (t));
413 pp_cxx_right_paren (pp);
417 pp_cxx_trait_expression (pp, t);
421 pp_cxx_va_arg_expression (pp, t);
425 pp_c_primary_expression (pp_c_base (pp), t);
430 /* postfix-expression:
432 postfix-expression [ expression ]
433 postfix-expression ( expression-list(opt) )
434 simple-type-specifier ( expression-list(opt) )
435 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
436 typename ::(opt) nested-name-specifier template(opt)
437 template-id ( expression-list(opt) )
438 postfix-expression . template(opt) ::(opt) id-expression
439 postfix-expression -> template(opt) ::(opt) id-expression
440 postfix-expression . pseudo-destructor-name
441 postfix-expression -> pseudo-destructor-name
442 postfix-expression ++
443 postfix-expression --
444 dynamic_cast < type-id > ( expression )
445 static_cast < type-id > ( expression )
446 reinterpret_cast < type-id > ( expression )
447 const_cast < type-id > ( expression )
448 typeid ( expression )
449 typeif ( type-id ) */
452 pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t)
454 enum tree_code code = TREE_CODE (t);
461 tree fun = (code == AGGR_INIT_EXPR ? AGGR_INIT_EXPR_FN (t)
463 tree saved_scope = pp->enclosing_scope;
464 bool skipfirst = false;
467 if (TREE_CODE (fun) == ADDR_EXPR)
468 fun = TREE_OPERAND (fun, 0);
470 /* In templates, where there is no way to tell whether a given
471 call uses an actual member function. So the parser builds
472 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
473 instantiation time. */
474 if (TREE_CODE (fun) != FUNCTION_DECL)
476 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun))
478 tree object = (code == AGGR_INIT_EXPR
479 ? (AGGR_INIT_VIA_CTOR_P (t)
480 ? AGGR_INIT_EXPR_SLOT (t)
481 : AGGR_INIT_EXPR_ARG (t, 0))
482 : CALL_EXPR_ARG (t, 0));
484 while (TREE_CODE (object) == NOP_EXPR)
485 object = TREE_OPERAND (object, 0);
487 if (TREE_CODE (object) == ADDR_EXPR)
488 object = TREE_OPERAND (object, 0);
490 if (TREE_CODE (TREE_TYPE (object)) != POINTER_TYPE)
492 pp_cxx_postfix_expression (pp, object);
497 pp_cxx_postfix_expression (pp, object);
501 pp->enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
504 pp_cxx_postfix_expression (pp, fun);
505 pp->enclosing_scope = saved_scope;
506 pp_cxx_left_paren (pp);
507 if (code == AGGR_INIT_EXPR)
509 aggr_init_expr_arg_iterator iter;
510 FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t)
516 pp_cxx_expression (pp, arg);
517 if (more_aggr_init_expr_args_p (&iter))
518 pp_cxx_separate_with (pp, ',');
524 call_expr_arg_iterator iter;
525 FOR_EACH_CALL_EXPR_ARG (arg, iter, t)
531 pp_cxx_expression (pp, arg);
532 if (more_call_expr_args_p (&iter))
533 pp_cxx_separate_with (pp, ',');
537 pp_cxx_right_paren (pp);
539 if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
541 pp_cxx_separate_with (pp, ',');
542 pp_cxx_postfix_expression (pp, AGGR_INIT_EXPR_SLOT (t));
555 pp_cxx_primary_expression (pp, t);
558 case DYNAMIC_CAST_EXPR:
559 case STATIC_CAST_EXPR:
560 case REINTERPRET_CAST_EXPR:
561 case CONST_CAST_EXPR:
562 if (code == DYNAMIC_CAST_EXPR)
563 pp_cxx_identifier (pp, "dynamic_cast");
564 else if (code == STATIC_CAST_EXPR)
565 pp_cxx_identifier (pp, "static_cast");
566 else if (code == REINTERPRET_CAST_EXPR)
567 pp_cxx_identifier (pp, "reinterpret_cast");
569 pp_cxx_identifier (pp, "const_cast");
570 pp_cxx_begin_template_argument_list (pp);
571 pp_cxx_type_id (pp, TREE_TYPE (t));
572 pp_cxx_end_template_argument_list (pp);
574 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
578 case EMPTY_CLASS_EXPR:
579 pp_cxx_type_id (pp, TREE_TYPE (t));
585 pp_cxx_typeid_expression (pp, t);
588 case PSEUDO_DTOR_EXPR:
589 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
591 pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1));
592 pp_cxx_colon_colon (pp);
594 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2));
598 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
603 pp_c_postfix_expression (pp_c_base (pp), t);
609 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
610 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
616 type-specifier-seq new-declarator(opt)
619 ptr-operator new-declarator(opt)
620 direct-new-declarator
622 direct-new-declarator
624 direct-new-declarator [ constant-expression ]
627 ( expression-list(opt) ) */
630 pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
632 enum tree_code code = TREE_CODE (t);
637 if (NEW_EXPR_USE_GLOBAL (t))
638 pp_cxx_colon_colon (pp);
639 pp_cxx_identifier (pp, "new");
640 if (TREE_OPERAND (t, 0))
642 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
645 /* FIXME: array-types are built with one more element. */
646 pp_cxx_type_id (pp, TREE_OPERAND (t, 1));
647 if (TREE_OPERAND (t, 2))
650 t = TREE_OPERAND (t, 2);
651 if (TREE_CODE (t) == TREE_LIST)
652 pp_c_expression_list (pp_c_base (pp), t);
653 else if (t == void_zero_node)
654 ; /* OK, empty initializer list. */
656 pp_cxx_expression (pp, t);
662 pp_unsupported_tree (pp, t);
666 /* delete-expression:
667 ::(opt) delete cast-expression
668 ::(opt) delete [ ] cast-expression */
671 pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
673 enum tree_code code = TREE_CODE (t);
677 case VEC_DELETE_EXPR:
678 if (DELETE_EXPR_USE_GLOBAL (t))
679 pp_cxx_colon_colon (pp);
680 pp_cxx_identifier (pp, "delete");
682 if (code == VEC_DELETE_EXPR
683 || DELETE_EXPR_USE_VEC (t))
685 pp_left_bracket (pp);
686 pp_right_bracket (pp);
689 pp_c_cast_expression (pp_c_base (pp), TREE_OPERAND (t, 0));
693 pp_unsupported_tree (pp, t);
701 unary-operator cast-expression
702 sizeof unary-expression
704 sizeof ... ( identifier )
708 unary-operator: one of
712 __alignof__ unary-expression
713 __alignof__ ( type-id ) */
716 pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
718 enum tree_code code = TREE_CODE (t);
723 pp_cxx_new_expression (pp, t);
727 case VEC_DELETE_EXPR:
728 pp_cxx_delete_expression (pp, t);
732 if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
734 pp_cxx_identifier (pp, "sizeof");
735 pp_cxx_identifier (pp, "...");
736 pp_cxx_whitespace (pp);
737 pp_cxx_left_paren (pp);
738 if (TYPE_P (TREE_OPERAND (t, 0)))
739 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
741 pp_unary_expression (pp, TREE_OPERAND (t, 0));
742 pp_cxx_right_paren (pp);
748 pp_cxx_identifier (pp, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
749 pp_cxx_whitespace (pp);
750 if (TYPE_P (TREE_OPERAND (t, 0)))
752 pp_cxx_left_paren (pp);
753 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
754 pp_cxx_right_paren (pp);
757 pp_unary_expression (pp, TREE_OPERAND (t, 0));
760 case UNARY_PLUS_EXPR:
762 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0));
766 pp_c_unary_expression (pp_c_base (pp), t);
773 ( type-id ) cast-expression */
776 pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
778 switch (TREE_CODE (t))
781 pp_cxx_type_id (pp, TREE_TYPE (t));
782 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
786 pp_c_cast_expression (pp_c_base (pp), t);
793 pm-expression .* cast-expression
794 pm-expression ->* cast-expression */
797 pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t)
799 switch (TREE_CODE (t))
801 /* Handle unfortunate OFFESET_REF overloading here. */
803 if (TYPE_P (TREE_OPERAND (t, 0)))
805 pp_cxx_qualified_id (pp, t);
808 /* Else fall through. */
811 pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
814 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1));
819 pp_cxx_cast_expression (pp, t);
824 /* multiplicative-expression:
826 multiplicative-expression * pm-expression
827 multiplicative-expression / pm-expression
828 multiplicative-expression % pm-expression */
831 pp_cxx_multiplicative_expression (cxx_pretty_printer *pp, tree e)
833 enum tree_code code = TREE_CODE (e);
839 pp_cxx_multiplicative_expression (pp, TREE_OPERAND (e, 0));
841 if (code == MULT_EXPR)
843 else if (code == TRUNC_DIV_EXPR)
848 pp_cxx_pm_expression (pp, TREE_OPERAND (e, 1));
852 pp_cxx_pm_expression (pp, e);
857 /* conditional-expression:
858 logical-or-expression
859 logical-or-expression ? expression : assignment-expression */
862 pp_cxx_conditional_expression (cxx_pretty_printer *pp, tree e)
864 if (TREE_CODE (e) == COND_EXPR)
866 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
870 pp_cxx_expression (pp, TREE_OPERAND (e, 1));
872 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
875 pp_c_logical_or_expression (pp_c_base (pp), e);
878 /* Pretty-print a compound assignment operator token as indicated by T. */
881 pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t)
885 switch (TREE_CODE (t))
908 op = tree_code_name[TREE_CODE (t)];
912 pp_cxx_identifier (pp, op);
916 /* assignment-expression:
917 conditional-expression
918 logical-or-expression assignment-operator assignment-expression
922 throw assignment-expression(opt)
924 assignment-operator: one of
925 = *= /= %= += -= >>= <<= &= ^= |= */
928 pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e)
930 switch (TREE_CODE (e))
934 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
938 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 1));
942 pp_cxx_identifier (pp, "throw");
943 if (TREE_OPERAND (e, 0))
944 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 0));
948 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
949 pp_cxx_assignment_operator (pp, TREE_OPERAND (e, 1));
950 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
954 pp_cxx_conditional_expression (pp, e);
960 pp_cxx_expression (cxx_pretty_printer *pp, tree t)
962 switch (TREE_CODE (t))
968 pp_cxx_constant (pp, t);
972 pp_cxx_unqualified_id (pp, t);
980 pp_cxx_qualified_id (pp, t);
992 case TEMPLATE_TYPE_PARM:
993 case TEMPLATE_PARM_INDEX:
994 case TEMPLATE_TEMPLATE_PARM:
996 pp_cxx_primary_expression (pp, t);
1000 case DYNAMIC_CAST_EXPR:
1001 case STATIC_CAST_EXPR:
1002 case REINTERPRET_CAST_EXPR:
1003 case CONST_CAST_EXPR:
1007 case EMPTY_CLASS_EXPR:
1009 case PSEUDO_DTOR_EXPR:
1010 case AGGR_INIT_EXPR:
1012 pp_cxx_postfix_expression (pp, t);
1017 pp_cxx_new_expression (pp, t);
1021 case VEC_DELETE_EXPR:
1022 pp_cxx_delete_expression (pp, t);
1027 pp_cxx_unary_expression (pp, t);
1031 pp_cxx_cast_expression (pp, t);
1037 pp_cxx_pm_expression (pp, t);
1041 case TRUNC_DIV_EXPR:
1042 case TRUNC_MOD_EXPR:
1043 pp_cxx_multiplicative_expression (pp, t);
1047 pp_cxx_conditional_expression (pp, t);
1054 pp_cxx_assignment_expression (pp, t);
1057 case NON_DEPENDENT_EXPR:
1058 case MUST_NOT_THROW_EXPR:
1059 pp_cxx_expression (pp, t);
1062 case EXPR_PACK_EXPANSION:
1063 pp_cxx_expression (pp, PACK_EXPANSION_PATTERN (t));
1064 pp_cxx_identifier (pp, "...");
1067 case NONTYPE_ARGUMENT_PACK:
1069 tree args = ARGUMENT_PACK_ARGS (t);
1070 int i, len = TREE_VEC_LENGTH (args);
1071 for (i = 0; i < len; ++i)
1074 pp_cxx_separate_with (pp, ',');
1075 pp_cxx_expression (pp, TREE_VEC_ELT (args, i));
1081 pp_c_expression (pp_c_base (pp), t);
1089 /* function-specifier:
1095 pp_cxx_function_specifier (cxx_pretty_printer *pp, tree t)
1097 switch (TREE_CODE (t))
1100 if (DECL_VIRTUAL_P (t))
1101 pp_cxx_identifier (pp, "virtual");
1102 else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
1103 pp_cxx_identifier (pp, "explicit");
1105 pp_c_function_specifier (pp_c_base (pp), t);
1112 /* decl-specifier-seq:
1113 decl-specifier-seq(opt) decl-specifier
1116 storage-class-specifier
1123 pp_cxx_decl_specifier_seq (cxx_pretty_printer *pp, tree t)
1125 switch (TREE_CODE (t))
1131 pp_cxx_storage_class_specifier (pp, t);
1132 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1136 pp_cxx_identifier (pp, "typedef");
1137 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1141 if (TYPE_PTRMEMFUNC_P (t))
1143 tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t);
1144 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (pfm)));
1145 pp_cxx_whitespace (pp);
1146 pp_cxx_ptr_operator (pp, t);
1151 /* Constructors don't have return types. And conversion functions
1152 do not have a type-specifier in their return types. */
1153 if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t))
1154 pp_cxx_function_specifier (pp, t);
1155 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
1156 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (t)));
1159 pp_c_declaration_specifiers (pp_c_base (pp), t);
1164 /* simple-type-specifier:
1165 ::(opt) nested-name-specifier(opt) type-name
1166 ::(opt) nested-name-specifier(opt) template(opt) template-id
1180 pp_cxx_simple_type_specifier (cxx_pretty_printer *pp, tree t)
1182 switch (TREE_CODE (t))
1187 pp_cxx_qualified_id (pp, t);
1190 case TEMPLATE_TYPE_PARM:
1191 case TEMPLATE_TEMPLATE_PARM:
1192 case TEMPLATE_PARM_INDEX:
1193 pp_cxx_unqualified_id (pp, t);
1197 pp_cxx_identifier (pp, "typename");
1198 pp_cxx_nested_name_specifier (pp, TYPE_CONTEXT (t));
1199 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
1203 pp_c_type_specifier (pp_c_base (pp), t);
1208 /* type-specifier-seq:
1209 type-specifier type-specifier-seq(opt)
1212 simple-type-specifier
1215 elaborated-type-specifier
1219 pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
1221 switch (TREE_CODE (t))
1224 case TEMPLATE_TYPE_PARM:
1225 case TEMPLATE_TEMPLATE_PARM:
1227 case BOUND_TEMPLATE_TEMPLATE_PARM:
1228 pp_cxx_cv_qualifier_seq (pp, t);
1229 pp_cxx_simple_type_specifier (pp, t);
1233 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
1234 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1235 pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t));
1239 pp_cxx_identifier (pp, "decltype");
1240 pp_cxx_left_paren (pp);
1241 pp_cxx_expression (pp, DECLTYPE_TYPE_EXPR (t));
1242 pp_cxx_right_paren (pp);
1246 if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
1247 pp_c_specifier_qualifier_list (pp_c_base (pp), t);
1252 * cv-qualifier-seq(opt)
1254 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1257 pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
1259 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
1261 switch (TREE_CODE (t))
1263 case REFERENCE_TYPE:
1265 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
1266 || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t)))
1267 pp_cxx_ptr_operator (pp, TREE_TYPE (t));
1268 if (TREE_CODE (t) == POINTER_TYPE)
1271 pp_cxx_cv_qualifier_seq (pp, t);
1278 if (TYPE_PTRMEMFUNC_P (t))
1280 pp_cxx_left_paren (pp);
1281 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t));
1286 if (TYPE_PTR_TO_MEMBER_P (t))
1288 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1289 pp_cxx_left_paren (pp);
1290 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t));
1292 pp_cxx_cv_qualifier_seq (pp, t);
1295 /* else fall through. */
1298 pp_unsupported_tree (pp, t);
1304 pp_cxx_implicit_parameter_type (tree mf)
1306 return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf))));
1310 parameter-declaration:
1311 decl-specifier-seq declarator
1312 decl-specifier-seq declarator = assignment-expression
1313 decl-specifier-seq abstract-declarator(opt)
1314 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1317 pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
1319 pp_cxx_decl_specifier_seq (pp, t);
1321 pp_cxx_abstract_declarator (pp, t);
1323 pp_cxx_declarator (pp, t);
1326 /* parameter-declaration-clause:
1327 parameter-declaration-list(opt) ...(opt)
1328 parameter-declaration-list , ...
1330 parameter-declaration-list:
1331 parameter-declaration
1332 parameter-declaration-list , parameter-declaration */
1335 pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
1337 tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t);
1339 TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
1340 const bool abstract = args == NULL
1341 || pp_c_base (pp)->flags & pp_c_flag_abstract;
1344 /* Skip artificial parameter for nonstatic member functions. */
1345 if (TREE_CODE (t) == METHOD_TYPE)
1346 types = TREE_CHAIN (types);
1348 pp_cxx_left_paren (pp);
1349 for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
1352 pp_cxx_separate_with (pp, ',');
1354 pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
1355 if (!abstract && pp_c_base (pp)->flags & pp_cxx_flag_default_argument)
1357 pp_cxx_whitespace (pp);
1359 pp_cxx_whitespace (pp);
1360 pp_cxx_assignment_expression (pp, TREE_PURPOSE (types));
1363 pp_cxx_right_paren (pp);
1366 /* exception-specification:
1367 throw ( type-id-list(opt) )
1371 type-id-list , type-id */
1374 pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
1376 tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
1377 bool need_comma = false;
1379 if (!TYPE_NOTHROW_P (t) && ex_spec == NULL)
1381 pp_cxx_identifier (pp, "throw");
1382 pp_cxx_left_paren (pp);
1383 for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
1385 tree type = TREE_VALUE (ex_spec);
1386 tree argpack = NULL_TREE;
1389 if (ARGUMENT_PACK_P (type))
1391 argpack = ARGUMENT_PACK_ARGS (type);
1392 len = TREE_VEC_LENGTH (argpack);
1395 for (i = 0; i < len; ++i)
1398 type = TREE_VEC_ELT (argpack, i);
1401 pp_cxx_separate_with (pp, ',');
1405 pp_cxx_type_id (pp, type);
1408 pp_cxx_right_paren (pp);
1411 /* direct-declarator:
1413 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1414 exception-specification(opt)
1415 direct-declaration [ constant-expression(opt) ]
1419 pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t)
1421 switch (TREE_CODE (t))
1429 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1431 if ((TREE_CODE (t) == PARM_DECL && FUNCTION_PARAMETER_PACK_P (t))
1432 || template_parameter_pack_p (t))
1433 /* A function parameter pack or non-type template
1435 pp_cxx_identifier (pp, "...");
1437 pp_cxx_id_expression (pp, DECL_NAME (t));
1439 pp_cxx_abstract_declarator (pp, TREE_TYPE (t));
1443 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
1444 pp_cxx_id_expression (pp, t);
1445 pp_cxx_parameter_declaration_clause (pp, t);
1447 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
1449 pp_base (pp)->padding = pp_before;
1450 pp_cxx_cv_qualifier_seq (pp, pp_cxx_implicit_parameter_type (t));
1453 pp_cxx_exception_specification (pp, TREE_TYPE (t));
1458 case TEMPLATE_TYPE_PARM:
1459 case TEMPLATE_PARM_INDEX:
1460 case TEMPLATE_TEMPLATE_PARM:
1464 pp_c_direct_declarator (pp_c_base (pp), t);
1471 ptr-operator declarator */
1474 pp_cxx_declarator (cxx_pretty_printer *pp, tree t)
1476 pp_cxx_direct_declarator (pp, t);
1479 /* ctor-initializer:
1480 : mem-initializer-list
1482 mem-initializer-list:
1484 mem-initializer , mem-initializer-list
1487 mem-initializer-id ( expression-list(opt) )
1490 ::(opt) nested-name-specifier(opt) class-name
1494 pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
1496 t = TREE_OPERAND (t, 0);
1497 pp_cxx_whitespace (pp);
1499 pp_cxx_whitespace (pp);
1500 for (; t; t = TREE_CHAIN (t))
1502 tree purpose = TREE_PURPOSE (t);
1503 bool is_pack = PACK_EXPANSION_P (purpose);
1506 pp_cxx_primary_expression (pp, PACK_EXPANSION_PATTERN (purpose));
1508 pp_cxx_primary_expression (pp, purpose);
1509 pp_cxx_call_argument_list (pp, TREE_VALUE (t));
1511 pp_cxx_identifier (pp, "...");
1513 pp_cxx_separate_with (pp, ',');
1517 /* function-definition:
1518 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1519 decl-specifier-seq(opt) declarator function-try-block */
1522 pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
1524 tree saved_scope = pp->enclosing_scope;
1525 pp_cxx_decl_specifier_seq (pp, t);
1526 pp_cxx_declarator (pp, t);
1527 pp_needs_newline (pp) = true;
1528 pp->enclosing_scope = DECL_CONTEXT (t);
1529 if (DECL_SAVED_TREE (t))
1530 pp_cxx_statement (pp, DECL_SAVED_TREE (t));
1533 pp_cxx_semicolon (pp);
1534 pp_needs_newline (pp) = true;
1537 pp->enclosing_scope = saved_scope;
1540 /* abstract-declarator:
1541 ptr-operator abstract-declarator(opt)
1542 direct-abstract-declarator */
1545 pp_cxx_abstract_declarator (cxx_pretty_printer *pp, tree t)
1547 if (TYPE_PTRMEM_P (t) || TYPE_PTRMEMFUNC_P (t))
1548 pp_cxx_right_paren (pp);
1549 else if (POINTER_TYPE_P (t))
1551 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
1552 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1553 pp_cxx_right_paren (pp);
1556 pp_cxx_direct_abstract_declarator (pp, t);
1559 /* direct-abstract-declarator:
1560 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1561 cv-qualifier-seq(opt) exception-specification(opt)
1562 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1563 ( abstract-declarator ) */
1566 pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
1568 switch (TREE_CODE (t))
1570 case REFERENCE_TYPE:
1571 pp_cxx_abstract_declarator (pp, t);
1575 if (TYPE_PTRMEMFUNC_P (t))
1576 pp_cxx_direct_abstract_declarator (pp, TYPE_PTRMEMFUNC_FN_TYPE (t));
1581 pp_cxx_parameter_declaration_clause (pp, t);
1582 pp_cxx_direct_abstract_declarator (pp, TREE_TYPE (t));
1583 if (TREE_CODE (t) == METHOD_TYPE)
1585 pp_base (pp)->padding = pp_before;
1586 pp_cxx_cv_qualifier_seq
1587 (pp, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))));
1589 pp_cxx_exception_specification (pp, t);
1593 case TEMPLATE_TYPE_PARM:
1594 case TEMPLATE_TEMPLATE_PARM:
1595 case BOUND_TEMPLATE_TEMPLATE_PARM:
1596 case UNBOUND_CLASS_TEMPLATE:
1600 pp_c_direct_abstract_declarator (pp_c_base (pp), t);
1606 type-specifier-seq abstract-declarator(opt) */
1609 pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
1611 pp_flags saved_flags = pp_c_base (pp)->flags;
1612 pp_c_base (pp)->flags |= pp_c_flag_abstract;
1614 switch (TREE_CODE (t))
1621 case BOUND_TEMPLATE_TEMPLATE_PARM:
1622 case UNBOUND_CLASS_TEMPLATE:
1623 case TEMPLATE_TEMPLATE_PARM:
1624 case TEMPLATE_TYPE_PARM:
1625 case TEMPLATE_PARM_INDEX:
1629 case TEMPLATE_ID_EXPR:
1630 pp_cxx_type_specifier_seq (pp, t);
1633 case TYPE_PACK_EXPANSION:
1634 pp_cxx_type_id (pp, PACK_EXPANSION_PATTERN (t));
1635 pp_cxx_identifier (pp, "...");
1639 pp_c_type_id (pp_c_base (pp), t);
1643 pp_c_base (pp)->flags = saved_flags;
1646 /* template-argument-list:
1647 template-argument ...(opt)
1648 template-argument-list, template-argument ...(opt)
1651 assignment-expression
1656 pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
1659 bool need_comma = false;
1663 for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
1665 tree arg = TREE_VEC_ELT (t, i);
1666 tree argpack = NULL_TREE;
1669 if (ARGUMENT_PACK_P (arg))
1671 argpack = ARGUMENT_PACK_ARGS (arg);
1672 len = TREE_VEC_LENGTH (argpack);
1675 for (idx = 0; idx < len; idx++)
1678 arg = TREE_VEC_ELT (argpack, idx);
1681 pp_cxx_separate_with (pp, ',');
1685 if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
1686 && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
1687 pp_cxx_type_id (pp, arg);
1689 pp_cxx_expression (pp, arg);
1696 pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
1698 t = DECL_EXPR_DECL (t);
1699 pp_cxx_type_specifier_seq (pp, t);
1701 pp_cxx_abstract_declarator (pp, t);
1703 pp_cxx_declarator (pp, t);
1709 pp_cxx_statement (cxx_pretty_printer *pp, tree t)
1711 switch (TREE_CODE (t))
1713 case CTOR_INITIALIZER:
1714 pp_cxx_ctor_initializer (pp, t);
1718 pp_cxx_identifier (pp, "using");
1719 pp_cxx_identifier (pp, "namespace");
1720 if (DECL_CONTEXT (t))
1721 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1722 pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t));
1726 pp_cxx_identifier (pp, "using");
1727 pp_cxx_nested_name_specifier (pp, USING_DECL_SCOPE (t));
1728 pp_cxx_unqualified_id (pp, DECL_NAME (t));
1735 try compound-statement handler-seq */
1737 pp_maybe_newline_and_indent (pp, 0);
1738 pp_cxx_identifier (pp, "try");
1739 pp_newline_and_indent (pp, 3);
1740 pp_cxx_statement (pp, TRY_STMTS (t));
1741 pp_newline_and_indent (pp, -3);
1745 pp_cxx_statement (pp, TRY_HANDLERS (t));
1750 handler handler-seq(opt)
1753 catch ( exception-declaration ) compound-statement
1755 exception-declaration:
1756 type-specifier-seq declarator
1757 type-specifier-seq abstract-declarator
1760 pp_cxx_identifier (pp, "catch");
1761 pp_cxx_left_paren (pp);
1762 pp_cxx_exception_declaration (pp, HANDLER_PARMS (t));
1763 pp_cxx_right_paren (pp);
1764 pp_indentation (pp) += 3;
1765 pp_needs_newline (pp) = true;
1766 pp_cxx_statement (pp, HANDLER_BODY (t));
1767 pp_indentation (pp) -= 3;
1768 pp_needs_newline (pp) = true;
1771 /* selection-statement:
1772 if ( expression ) statement
1773 if ( expression ) statement else statement */
1775 pp_cxx_identifier (pp, "if");
1776 pp_cxx_whitespace (pp);
1777 pp_cxx_left_paren (pp);
1778 pp_cxx_expression (pp, IF_COND (t));
1779 pp_cxx_right_paren (pp);
1780 pp_newline_and_indent (pp, 2);
1781 pp_cxx_statement (pp, THEN_CLAUSE (t));
1782 pp_newline_and_indent (pp, -2);
1783 if (ELSE_CLAUSE (t))
1785 tree else_clause = ELSE_CLAUSE (t);
1786 pp_cxx_identifier (pp, "else");
1787 if (TREE_CODE (else_clause) == IF_STMT)
1788 pp_cxx_whitespace (pp);
1790 pp_newline_and_indent (pp, 2);
1791 pp_cxx_statement (pp, else_clause);
1792 if (TREE_CODE (else_clause) != IF_STMT)
1793 pp_newline_and_indent (pp, -2);
1798 pp_cxx_identifier (pp, "switch");
1800 pp_cxx_left_paren (pp);
1801 pp_cxx_expression (pp, SWITCH_STMT_COND (t));
1802 pp_cxx_right_paren (pp);
1803 pp_indentation (pp) += 3;
1804 pp_needs_newline (pp) = true;
1805 pp_cxx_statement (pp, SWITCH_STMT_BODY (t));
1806 pp_newline_and_indent (pp, -3);
1809 /* iteration-statement:
1810 while ( expression ) statement
1811 do statement while ( expression ) ;
1812 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1813 for ( declaration expression(opt) ; expression(opt) ) statement */
1815 pp_cxx_identifier (pp, "while");
1817 pp_cxx_left_paren (pp);
1818 pp_cxx_expression (pp, WHILE_COND (t));
1819 pp_cxx_right_paren (pp);
1820 pp_newline_and_indent (pp, 3);
1821 pp_cxx_statement (pp, WHILE_BODY (t));
1822 pp_indentation (pp) -= 3;
1823 pp_needs_newline (pp) = true;
1827 pp_cxx_identifier (pp, "do");
1828 pp_newline_and_indent (pp, 3);
1829 pp_cxx_statement (pp, DO_BODY (t));
1830 pp_newline_and_indent (pp, -3);
1831 pp_cxx_identifier (pp, "while");
1833 pp_cxx_left_paren (pp);
1834 pp_cxx_expression (pp, DO_COND (t));
1835 pp_cxx_right_paren (pp);
1836 pp_cxx_semicolon (pp);
1837 pp_needs_newline (pp) = true;
1841 pp_cxx_identifier (pp, "for");
1843 pp_cxx_left_paren (pp);
1844 if (FOR_INIT_STMT (t))
1845 pp_cxx_statement (pp, FOR_INIT_STMT (t));
1847 pp_cxx_semicolon (pp);
1848 pp_needs_newline (pp) = false;
1849 pp_cxx_whitespace (pp);
1851 pp_cxx_expression (pp, FOR_COND (t));
1852 pp_cxx_semicolon (pp);
1853 pp_needs_newline (pp) = false;
1854 pp_cxx_whitespace (pp);
1856 pp_cxx_expression (pp, FOR_EXPR (t));
1857 pp_cxx_right_paren (pp);
1858 pp_newline_and_indent (pp, 3);
1859 pp_cxx_statement (pp, FOR_BODY (t));
1860 pp_indentation (pp) -= 3;
1861 pp_needs_newline (pp) = true;
1867 return expression(opt) ; */
1870 pp_identifier (pp, TREE_CODE (t) == BREAK_STMT ? "break" : "continue");
1871 pp_cxx_semicolon (pp);
1872 pp_needs_newline (pp) = true;
1875 /* expression-statement:
1876 expression(opt) ; */
1878 pp_cxx_expression (pp, EXPR_STMT_EXPR (t));
1879 pp_cxx_semicolon (pp);
1880 pp_needs_newline (pp) = true;
1884 pp_cxx_identifier (pp, "try");
1885 pp_newline_and_indent (pp, 2);
1886 pp_cxx_statement (pp, CLEANUP_BODY (t));
1887 pp_newline_and_indent (pp, -2);
1888 pp_cxx_identifier (pp, CLEANUP_EH_ONLY (t) ? "catch" : "finally");
1889 pp_newline_and_indent (pp, 2);
1890 pp_cxx_statement (pp, CLEANUP_EXPR (t));
1891 pp_newline_and_indent (pp, -2);
1895 pp_cxx_declaration (pp, t);
1899 pp_c_statement (pp_c_base (pp), t);
1904 /* original-namespace-definition:
1905 namespace identifier { namespace-body }
1907 As an edge case, we also handle unnamed namespace definition here. */
1910 pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t)
1912 pp_cxx_identifier (pp, "namespace");
1913 if (DECL_CONTEXT (t))
1914 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1916 pp_cxx_unqualified_id (pp, t);
1917 pp_cxx_whitespace (pp);
1918 pp_cxx_left_brace (pp);
1919 /* We do not print the namespace-body. */
1920 pp_cxx_whitespace (pp);
1921 pp_cxx_right_brace (pp);
1927 namespace-alias-definition:
1928 namespace identifier = qualified-namespace-specifier ;
1930 qualified-namespace-specifier:
1931 ::(opt) nested-name-specifier(opt) namespace-name */
1934 pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t)
1936 pp_cxx_identifier (pp, "namespace");
1937 if (DECL_CONTEXT (t))
1938 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1939 pp_cxx_unqualified_id (pp, t);
1940 pp_cxx_whitespace (pp);
1942 pp_cxx_whitespace (pp);
1943 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)))
1944 pp_cxx_nested_name_specifier (pp,
1945 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)));
1946 pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t));
1947 pp_cxx_semicolon (pp);
1950 /* simple-declaration:
1951 decl-specifier-seq(opt) init-declarator-list(opt) */
1954 pp_cxx_simple_declaration (cxx_pretty_printer *pp, tree t)
1956 pp_cxx_decl_specifier_seq (pp, t);
1957 pp_cxx_init_declarator (pp, t);
1958 pp_cxx_semicolon (pp);
1959 pp_needs_newline (pp) = true;
1963 template-parameter-list:
1965 template-parameter-list , template-parameter */
1968 pp_cxx_template_parameter_list (cxx_pretty_printer *pp, tree t)
1970 const int n = TREE_VEC_LENGTH (t);
1972 for (i = 0; i < n; ++i)
1975 pp_cxx_separate_with (pp, ',');
1976 pp_cxx_template_parameter (pp, TREE_VEC_ELT (t, i));
1980 /* template-parameter:
1982 parameter-declaration
1985 class ...(opt) identifier(opt)
1986 class identifier(opt) = type-id
1987 typename identifier(opt)
1988 typename ...(opt) identifier(opt) = type-id
1989 template < template-parameter-list > class ...(opt) identifier(opt)
1990 template < template-parameter-list > class identifier(opt) = template-name */
1993 pp_cxx_template_parameter (cxx_pretty_printer *pp, tree t)
1995 tree parameter = TREE_VALUE (t);
1996 switch (TREE_CODE (parameter))
1999 pp_cxx_identifier (pp, "class");
2000 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t)))
2001 pp_cxx_identifier (pp, "...");
2002 if (DECL_NAME (parameter))
2003 pp_cxx_tree_identifier (pp, DECL_NAME (parameter));
2004 /* FIXME: Chech if we should print also default argument. */
2008 pp_cxx_parameter_declaration (pp, parameter);
2015 pp_unsupported_tree (pp, t);
2020 /* Pretty-print a template parameter in the canonical form
2021 "template-parameter-<level>-<position in parameter list>". */
2024 pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm)
2026 const enum tree_code code = TREE_CODE (parm);
2028 /* Brings type template parameters to the canonical forms. */
2029 if (code == TEMPLATE_TYPE_PARM || code == TEMPLATE_TEMPLATE_PARM
2030 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
2031 parm = TEMPLATE_TYPE_PARM_INDEX (parm);
2033 pp_cxx_begin_template_argument_list (pp);
2034 pp_cxx_identifier (pp, "template-parameter-");
2035 pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm));
2037 pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1);
2038 pp_cxx_end_template_argument_list (pp);
2042 template-declaration:
2043 export(opt) template < template-parameter-list > declaration */
2046 pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t)
2048 tree tmpl = most_general_template (t);
2052 pp_maybe_newline_and_indent (pp, 0);
2053 for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level))
2055 pp_cxx_identifier (pp, "template");
2056 pp_cxx_begin_template_argument_list (pp);
2057 pp_cxx_template_parameter_list (pp, TREE_VALUE (level));
2058 pp_cxx_end_template_argument_list (pp);
2059 pp_newline_and_indent (pp, 3);
2062 if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t))
2063 pp_cxx_function_definition (pp, t);
2065 pp_cxx_simple_declaration (pp, t);
2069 pp_cxx_explicit_specialization (cxx_pretty_printer *pp, tree t)
2071 pp_unsupported_tree (pp, t);
2075 pp_cxx_explicit_instantiation (cxx_pretty_printer *pp, tree t)
2077 pp_unsupported_tree (pp, t);
2084 template-declaration
2085 explicit-instantiation
2086 explicit-specialization
2087 linkage-specification
2088 namespace-definition
2093 namespace-alias-definition
2096 static_assert-declaration */
2098 pp_cxx_declaration (cxx_pretty_printer *pp, tree t)
2100 if (TREE_CODE (t) == STATIC_ASSERT)
2102 pp_cxx_identifier (pp, "static_assert");
2103 pp_cxx_left_paren (pp);
2104 pp_cxx_expression (pp, STATIC_ASSERT_CONDITION (t));
2105 pp_cxx_separate_with (pp, ',');
2106 pp_cxx_expression (pp, STATIC_ASSERT_MESSAGE (t));
2107 pp_cxx_right_paren (pp);
2109 else if (!DECL_LANG_SPECIFIC (t))
2110 pp_cxx_simple_declaration (pp, t);
2111 else if (DECL_USE_TEMPLATE (t))
2112 switch (DECL_USE_TEMPLATE (t))
2115 pp_cxx_template_declaration (pp, t);
2119 pp_cxx_explicit_specialization (pp, t);
2123 pp_cxx_explicit_instantiation (pp, t);
2129 else switch (TREE_CODE (t))
2133 pp_cxx_simple_declaration (pp, t);
2137 if (DECL_SAVED_TREE (t))
2138 pp_cxx_function_definition (pp, t);
2140 pp_cxx_simple_declaration (pp, t);
2143 case NAMESPACE_DECL:
2144 if (DECL_NAMESPACE_ALIAS (t))
2145 pp_cxx_namespace_alias_definition (pp, t);
2147 pp_cxx_original_namespace_definition (pp, t);
2151 pp_unsupported_tree (pp, t);
2157 pp_cxx_typeid_expression (cxx_pretty_printer *pp, tree t)
2159 t = TREE_OPERAND (t, 0);
2160 pp_cxx_identifier (pp, "typeid");
2161 pp_cxx_left_paren (pp);
2163 pp_cxx_type_id (pp, t);
2165 pp_cxx_expression (pp, t);
2166 pp_cxx_right_paren (pp);
2170 pp_cxx_va_arg_expression (cxx_pretty_printer *pp, tree t)
2172 pp_cxx_identifier (pp, "va_arg");
2173 pp_cxx_left_paren (pp);
2174 pp_cxx_assignment_expression (pp, TREE_OPERAND (t, 0));
2175 pp_cxx_separate_with (pp, ',');
2176 pp_cxx_type_id (pp, TREE_TYPE (t));
2177 pp_cxx_right_paren (pp);
2181 pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t)
2183 cp_trait_kind kind = TRAIT_EXPR_KIND (t);
2187 case CPTK_HAS_NOTHROW_ASSIGN:
2188 pp_cxx_identifier (pp, "__has_nothrow_assign");
2190 case CPTK_HAS_TRIVIAL_ASSIGN:
2191 pp_cxx_identifier (pp, "__has_trivial_assign");
2193 case CPTK_HAS_NOTHROW_CONSTRUCTOR:
2194 pp_cxx_identifier (pp, "__has_nothrow_constructor");
2196 case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
2197 pp_cxx_identifier (pp, "__has_trivial_constructor");
2199 case CPTK_HAS_NOTHROW_COPY:
2200 pp_cxx_identifier (pp, "__has_nothrow_copy");
2202 case CPTK_HAS_TRIVIAL_COPY:
2203 pp_cxx_identifier (pp, "__has_trivial_copy");
2205 case CPTK_HAS_TRIVIAL_DESTRUCTOR:
2206 pp_cxx_identifier (pp, "__has_trivial_destructor");
2208 case CPTK_HAS_VIRTUAL_DESTRUCTOR:
2209 pp_cxx_identifier (pp, "__has_virtual_destructor");
2211 case CPTK_IS_ABSTRACT:
2212 pp_cxx_identifier (pp, "__is_abstract");
2214 case CPTK_IS_BASE_OF:
2215 pp_cxx_identifier (pp, "__is_base_of");
2218 pp_cxx_identifier (pp, "__is_class");
2220 case CPTK_IS_CONVERTIBLE_TO:
2221 pp_cxx_identifier (pp, "__is_convertible_to");
2224 pp_cxx_identifier (pp, "__is_empty");
2227 pp_cxx_identifier (pp, "__is_enum");
2230 pp_cxx_identifier (pp, "__is_pod");
2232 case CPTK_IS_POLYMORPHIC:
2233 pp_cxx_identifier (pp, "__is_polymorphic");
2236 pp_cxx_identifier (pp, "__is_union");
2243 pp_cxx_left_paren (pp);
2244 pp_cxx_type_id (pp, TRAIT_EXPR_TYPE1 (t));
2246 if (kind == CPTK_IS_BASE_OF || kind == CPTK_IS_CONVERTIBLE_TO)
2248 pp_cxx_separate_with (pp, ',');
2249 pp_cxx_type_id (pp, TRAIT_EXPR_TYPE2 (t));
2252 pp_cxx_right_paren (pp);
2255 typedef c_pretty_print_fn pp_fun;
2257 /* Initialization of a C++ pretty-printer object. */
2260 pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
2262 pp_c_pretty_printer_init (pp_c_base (pp));
2263 pp_set_line_maximum_length (pp, 0);
2265 pp->c_base.declaration = (pp_fun) pp_cxx_declaration;
2266 pp->c_base.declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
2267 pp->c_base.function_specifier = (pp_fun) pp_cxx_function_specifier;
2268 pp->c_base.type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
2269 pp->c_base.declarator = (pp_fun) pp_cxx_declarator;
2270 pp->c_base.direct_declarator = (pp_fun) pp_cxx_direct_declarator;
2271 pp->c_base.parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
2272 pp->c_base.type_id = (pp_fun) pp_cxx_type_id;
2273 pp->c_base.abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
2274 pp->c_base.direct_abstract_declarator =
2275 (pp_fun) pp_cxx_direct_abstract_declarator;
2276 pp->c_base.simple_type_specifier = (pp_fun)pp_cxx_simple_type_specifier;
2278 /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
2280 pp->c_base.constant = (pp_fun) pp_cxx_constant;
2281 pp->c_base.id_expression = (pp_fun) pp_cxx_id_expression;
2282 pp->c_base.primary_expression = (pp_fun) pp_cxx_primary_expression;
2283 pp->c_base.postfix_expression = (pp_fun) pp_cxx_postfix_expression;
2284 pp->c_base.unary_expression = (pp_fun) pp_cxx_unary_expression;
2285 pp->c_base.multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
2286 pp->c_base.conditional_expression = (pp_fun) pp_cxx_conditional_expression;
2287 pp->c_base.assignment_expression = (pp_fun) pp_cxx_assignment_expression;
2288 pp->c_base.expression = (pp_fun) pp_cxx_expression;
2289 pp->enclosing_scope = global_namespace;