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);
46 static void pp_cxx_typeid_expression (cxx_pretty_printer *, tree);
50 pp_cxx_nonconsecutive_character (cxx_pretty_printer *pp, int c)
52 const char *p = pp_last_position_in_text (pp);
54 if (p != NULL && *p == c)
55 pp_cxx_whitespace (pp);
57 pp_base (pp)->padding = pp_none;
60 #define pp_cxx_storage_class_specifier(PP, T) \
61 pp_c_storage_class_specifier (pp_c_base (PP), T)
62 #define pp_cxx_expression_list(PP, T) \
63 pp_c_expression_list (pp_c_base (PP), T)
64 #define pp_cxx_space_for_pointer_operator(PP, T) \
65 pp_c_space_for_pointer_operator (pp_c_base (PP), T)
66 #define pp_cxx_init_declarator(PP, T) \
67 pp_c_init_declarator (pp_c_base (PP), T)
68 #define pp_cxx_call_argument_list(PP, T) \
69 pp_c_call_argument_list (pp_c_base (PP), T)
72 pp_cxx_colon_colon (cxx_pretty_printer *pp)
75 pp_base (pp)->padding = pp_none;
79 pp_cxx_begin_template_argument_list (cxx_pretty_printer *pp)
81 pp_cxx_nonconsecutive_character (pp, '<');
85 pp_cxx_end_template_argument_list (cxx_pretty_printer *pp)
87 pp_cxx_nonconsecutive_character (pp, '>');
91 pp_cxx_separate_with (cxx_pretty_printer *pp, int c)
93 pp_separate_with (pp, c);
94 pp_base (pp)->padding = pp_none;
100 is_destructor_name (tree name)
102 return name == complete_dtor_identifier
103 || name == base_dtor_identifier
104 || name == deleting_dtor_identifier;
107 /* conversion-function-id:
108 operator conversion-type-id
111 type-specifier-seq conversion-declarator(opt)
113 conversion-declarator:
114 ptr-operator conversion-declarator(opt) */
117 pp_cxx_conversion_function_id (cxx_pretty_printer *pp, tree t)
119 pp_cxx_identifier (pp, "operator");
120 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
124 pp_cxx_template_id (cxx_pretty_printer *pp, tree t)
126 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
127 pp_cxx_begin_template_argument_list (pp);
128 pp_cxx_template_argument_list (pp, TREE_OPERAND (t, 1));
129 pp_cxx_end_template_argument_list (pp);
132 /* Prints the unqualified part of the id-expression T.
137 conversion-function-id
142 pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t)
144 enum tree_code code = TREE_CODE (t);
148 pp_cxx_identifier (pp, "<return-value>");
165 case IDENTIFIER_NODE:
167 pp_cxx_identifier (pp, "<unnamed>");
168 else if (IDENTIFIER_TYPENAME_P (t))
169 pp_cxx_conversion_function_id (pp, t);
172 if (is_destructor_name (t))
175 /* FIXME: Why is this necessary? */
177 t = constructor_name (TREE_TYPE (t));
179 pp_cxx_tree_identifier (pp, t);
183 case TEMPLATE_ID_EXPR:
184 pp_cxx_template_id (pp, t);
188 pp_cxx_unqualified_id (pp, BASELINK_FUNCTIONS (t));
195 case UNBOUND_CLASS_TEMPLATE:
196 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
200 pp_cxx_complement (pp);
201 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
204 case TEMPLATE_TYPE_PARM:
205 case TEMPLATE_TEMPLATE_PARM:
206 if (TYPE_IDENTIFIER (t))
207 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
209 pp_cxx_canonical_template_parameter (pp, t);
212 case TEMPLATE_PARM_INDEX:
213 pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t));
216 case BOUND_TEMPLATE_TEMPLATE_PARM:
217 pp_cxx_cv_qualifier_seq (pp, t);
218 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
219 pp_cxx_begin_template_argument_list (pp);
220 pp_cxx_template_argument_list (pp, TYPE_TI_ARGS (t));
221 pp_cxx_end_template_argument_list (pp);
225 pp_unsupported_tree (pp, t);
230 /* Pretty-print out the token sequence ":: template" in template codes
231 where it is needed to "inline declare" the (following) member as
232 a template. This situation arises when SCOPE of T is dependent
233 on template parameters. */
236 pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
238 if (TREE_CODE (t) == TEMPLATE_ID_EXPR
239 && TYPE_P (scope) && dependent_type_p (scope))
240 pp_cxx_identifier (pp, "template");
243 /* nested-name-specifier:
244 class-or-namespace-name :: nested-name-specifier(opt)
245 class-or-namespace-name :: template nested-name-specifier */
248 pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
250 if (t != NULL && t != pp->enclosing_scope)
252 tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
253 pp_cxx_nested_name_specifier (pp, scope);
254 pp_cxx_template_keyword_if_needed (pp, scope, t);
255 pp_cxx_unqualified_id (pp, t);
256 pp_cxx_colon_colon (pp);
261 nested-name-specifier template(opt) unqualified-id */
264 pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t)
266 switch (TREE_CODE (t))
268 /* A pointer-to-member is always qualified. */
270 pp_cxx_nested_name_specifier (pp, PTRMEM_CST_CLASS (t));
271 pp_cxx_unqualified_id (pp, PTRMEM_CST_MEMBER (t));
274 /* In Standard C++, functions cannot possibly be used as
275 nested-name-specifiers. However, there are situations where
276 is "makes sense" to output the surrounding function name for the
277 purpose of emphasizing on the scope kind. Just printing the
278 function name might not be sufficient as it may be overloaded; so,
279 we decorate the function with its signature too.
280 FIXME: This is probably the wrong pretty-printing for conversion
281 functions and some function templates. */
285 if (DECL_FUNCTION_MEMBER_P (t))
286 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
287 pp_cxx_unqualified_id
288 (pp, DECL_CONSTRUCTOR_P (t) ? DECL_CONTEXT (t) : t);
289 pp_cxx_parameter_declaration_clause (pp, TREE_TYPE (t));
294 pp_cxx_nested_name_specifier (pp, TREE_OPERAND (t, 0));
295 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 1));
300 tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
301 if (scope != pp->enclosing_scope)
303 pp_cxx_nested_name_specifier (pp, scope);
304 pp_cxx_template_keyword_if_needed (pp, scope, t);
306 pp_cxx_unqualified_id (pp, t);
314 pp_cxx_constant (cxx_pretty_printer *pp, tree t)
316 switch (TREE_CODE (t))
320 const bool in_parens = PAREN_STRING_LITERAL_P (t);
322 pp_cxx_left_paren (pp);
323 pp_c_constant (pp_c_base (pp), t);
325 pp_cxx_right_paren (pp);
330 pp_c_constant (pp_c_base (pp), t);
340 pp_cxx_id_expression (cxx_pretty_printer *pp, tree t)
342 if (TREE_CODE (t) == OVERLOAD)
344 if (DECL_P (t) && DECL_CONTEXT (t))
345 pp_cxx_qualified_id (pp, t);
347 pp_cxx_unqualified_id (pp, t);
350 /* primary-expression:
354 :: operator-function-id
360 __builtin_va_arg ( assignment-expression , type-id )
361 __builtin_offsetof ( type-id, offsetof-expression )
363 __has_nothrow_assign ( type-id )
364 __has_nothrow_constructor ( type-id )
365 __has_nothrow_copy ( type-id )
366 __has_trivial_assign ( type-id )
367 __has_trivial_constructor ( type-id )
368 __has_trivial_copy ( type-id )
369 __has_trivial_destructor ( type-id )
370 __has_virtual_destructor ( type-id )
371 __is_abstract ( type-id )
372 __is_base_of ( type-id , type-id )
373 __is_class ( type-id )
374 __is_convertible_to ( type-id , type-id )
375 __is_empty ( type-id )
376 __is_enum ( type-id )
378 __is_polymorphic ( type-id )
379 __is_union ( type-id ) */
382 pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
384 switch (TREE_CODE (t))
390 pp_cxx_constant (pp, t);
394 t = BASELINK_FUNCTIONS (t);
402 pp_cxx_id_expression (pp, t);
406 case TEMPLATE_TYPE_PARM:
407 case TEMPLATE_TEMPLATE_PARM:
408 case TEMPLATE_PARM_INDEX:
409 pp_cxx_unqualified_id (pp, t);
413 pp_cxx_left_paren (pp);
414 pp_cxx_statement (pp, STMT_EXPR_STMT (t));
415 pp_cxx_right_paren (pp);
419 pp_cxx_trait_expression (pp, t);
423 pp_cxx_va_arg_expression (pp, t);
427 pp_cxx_offsetof_expression (pp, t);
431 pp_c_primary_expression (pp_c_base (pp), t);
436 /* postfix-expression:
438 postfix-expression [ expression ]
439 postfix-expression ( expression-list(opt) )
440 simple-type-specifier ( expression-list(opt) )
441 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
442 typename ::(opt) nested-name-specifier template(opt)
443 template-id ( expression-list(opt) )
444 postfix-expression . template(opt) ::(opt) id-expression
445 postfix-expression -> template(opt) ::(opt) id-expression
446 postfix-expression . pseudo-destructor-name
447 postfix-expression -> pseudo-destructor-name
448 postfix-expression ++
449 postfix-expression --
450 dynamic_cast < type-id > ( expression )
451 static_cast < type-id > ( expression )
452 reinterpret_cast < type-id > ( expression )
453 const_cast < type-id > ( expression )
454 typeid ( expression )
455 typeif ( type-id ) */
458 pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t)
460 enum tree_code code = TREE_CODE (t);
467 tree fun = (code == AGGR_INIT_EXPR ? AGGR_INIT_EXPR_FN (t)
469 tree saved_scope = pp->enclosing_scope;
470 bool skipfirst = false;
473 if (TREE_CODE (fun) == ADDR_EXPR)
474 fun = TREE_OPERAND (fun, 0);
476 /* In templates, where there is no way to tell whether a given
477 call uses an actual member function. So the parser builds
478 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
479 instantiation time. */
480 if (TREE_CODE (fun) != FUNCTION_DECL)
482 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun))
484 tree object = (code == AGGR_INIT_EXPR
485 ? (AGGR_INIT_VIA_CTOR_P (t)
486 ? AGGR_INIT_EXPR_SLOT (t)
487 : AGGR_INIT_EXPR_ARG (t, 0))
488 : CALL_EXPR_ARG (t, 0));
490 while (TREE_CODE (object) == NOP_EXPR)
491 object = TREE_OPERAND (object, 0);
493 if (TREE_CODE (object) == ADDR_EXPR)
494 object = TREE_OPERAND (object, 0);
496 if (TREE_CODE (TREE_TYPE (object)) != POINTER_TYPE)
498 pp_cxx_postfix_expression (pp, object);
503 pp_cxx_postfix_expression (pp, object);
507 pp->enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
510 pp_cxx_postfix_expression (pp, fun);
511 pp->enclosing_scope = saved_scope;
512 pp_cxx_left_paren (pp);
513 if (code == AGGR_INIT_EXPR)
515 aggr_init_expr_arg_iterator iter;
516 FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t)
522 pp_cxx_expression (pp, arg);
523 if (more_aggr_init_expr_args_p (&iter))
524 pp_cxx_separate_with (pp, ',');
530 call_expr_arg_iterator iter;
531 FOR_EACH_CALL_EXPR_ARG (arg, iter, t)
537 pp_cxx_expression (pp, arg);
538 if (more_call_expr_args_p (&iter))
539 pp_cxx_separate_with (pp, ',');
543 pp_cxx_right_paren (pp);
545 if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
547 pp_cxx_separate_with (pp, ',');
548 pp_cxx_postfix_expression (pp, AGGR_INIT_EXPR_SLOT (t));
561 pp_cxx_primary_expression (pp, t);
564 case DYNAMIC_CAST_EXPR:
565 case STATIC_CAST_EXPR:
566 case REINTERPRET_CAST_EXPR:
567 case CONST_CAST_EXPR:
568 if (code == DYNAMIC_CAST_EXPR)
569 pp_cxx_identifier (pp, "dynamic_cast");
570 else if (code == STATIC_CAST_EXPR)
571 pp_cxx_identifier (pp, "static_cast");
572 else if (code == REINTERPRET_CAST_EXPR)
573 pp_cxx_identifier (pp, "reinterpret_cast");
575 pp_cxx_identifier (pp, "const_cast");
576 pp_cxx_begin_template_argument_list (pp);
577 pp_cxx_type_id (pp, TREE_TYPE (t));
578 pp_cxx_end_template_argument_list (pp);
580 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
584 case EMPTY_CLASS_EXPR:
585 pp_cxx_type_id (pp, TREE_TYPE (t));
591 pp_cxx_typeid_expression (pp, t);
594 case PSEUDO_DTOR_EXPR:
595 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
597 pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1));
598 pp_cxx_colon_colon (pp);
600 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2));
604 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
609 pp_c_postfix_expression (pp_c_base (pp), t);
615 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
616 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
622 type-specifier-seq new-declarator(opt)
625 ptr-operator new-declarator(opt)
626 direct-new-declarator
628 direct-new-declarator
630 direct-new-declarator [ constant-expression ]
633 ( expression-list(opt) ) */
636 pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
638 enum tree_code code = TREE_CODE (t);
643 if (NEW_EXPR_USE_GLOBAL (t))
644 pp_cxx_colon_colon (pp);
645 pp_cxx_identifier (pp, "new");
646 if (TREE_OPERAND (t, 0))
648 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
651 /* FIXME: array-types are built with one more element. */
652 pp_cxx_type_id (pp, TREE_OPERAND (t, 1));
653 if (TREE_OPERAND (t, 2))
656 t = TREE_OPERAND (t, 2);
657 if (TREE_CODE (t) == TREE_LIST)
658 pp_c_expression_list (pp_c_base (pp), t);
659 else if (t == void_zero_node)
660 ; /* OK, empty initializer list. */
662 pp_cxx_expression (pp, t);
668 pp_unsupported_tree (pp, t);
672 /* delete-expression:
673 ::(opt) delete cast-expression
674 ::(opt) delete [ ] cast-expression */
677 pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
679 enum tree_code code = TREE_CODE (t);
683 case VEC_DELETE_EXPR:
684 if (DELETE_EXPR_USE_GLOBAL (t))
685 pp_cxx_colon_colon (pp);
686 pp_cxx_identifier (pp, "delete");
688 if (code == VEC_DELETE_EXPR
689 || DELETE_EXPR_USE_VEC (t))
691 pp_left_bracket (pp);
692 pp_right_bracket (pp);
695 pp_c_cast_expression (pp_c_base (pp), TREE_OPERAND (t, 0));
699 pp_unsupported_tree (pp, t);
707 unary-operator cast-expression
708 sizeof unary-expression
710 sizeof ... ( identifier )
714 unary-operator: one of
718 __alignof__ unary-expression
719 __alignof__ ( type-id ) */
722 pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
724 enum tree_code code = TREE_CODE (t);
729 pp_cxx_new_expression (pp, t);
733 case VEC_DELETE_EXPR:
734 pp_cxx_delete_expression (pp, t);
738 if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
740 pp_cxx_identifier (pp, "sizeof");
741 pp_cxx_identifier (pp, "...");
742 pp_cxx_whitespace (pp);
743 pp_cxx_left_paren (pp);
744 if (TYPE_P (TREE_OPERAND (t, 0)))
745 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
747 pp_unary_expression (pp, TREE_OPERAND (t, 0));
748 pp_cxx_right_paren (pp);
754 pp_cxx_identifier (pp, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
755 pp_cxx_whitespace (pp);
756 if (TYPE_P (TREE_OPERAND (t, 0)))
758 pp_cxx_left_paren (pp);
759 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
760 pp_cxx_right_paren (pp);
763 pp_unary_expression (pp, TREE_OPERAND (t, 0));
766 case UNARY_PLUS_EXPR:
768 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0));
772 pp_c_unary_expression (pp_c_base (pp), t);
779 ( type-id ) cast-expression */
782 pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
784 switch (TREE_CODE (t))
787 pp_cxx_type_id (pp, TREE_TYPE (t));
788 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
792 pp_c_cast_expression (pp_c_base (pp), t);
799 pm-expression .* cast-expression
800 pm-expression ->* cast-expression */
803 pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t)
805 switch (TREE_CODE (t))
807 /* Handle unfortunate OFFESET_REF overloading here. */
809 if (TYPE_P (TREE_OPERAND (t, 0)))
811 pp_cxx_qualified_id (pp, t);
814 /* Else fall through. */
817 pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
818 if (TREE_CODE (t) == MEMBER_REF)
823 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1));
828 pp_cxx_cast_expression (pp, t);
833 /* multiplicative-expression:
835 multiplicative-expression * pm-expression
836 multiplicative-expression / pm-expression
837 multiplicative-expression % pm-expression */
840 pp_cxx_multiplicative_expression (cxx_pretty_printer *pp, tree e)
842 enum tree_code code = TREE_CODE (e);
848 pp_cxx_multiplicative_expression (pp, TREE_OPERAND (e, 0));
850 if (code == MULT_EXPR)
852 else if (code == TRUNC_DIV_EXPR)
857 pp_cxx_pm_expression (pp, TREE_OPERAND (e, 1));
861 pp_cxx_pm_expression (pp, e);
866 /* conditional-expression:
867 logical-or-expression
868 logical-or-expression ? expression : assignment-expression */
871 pp_cxx_conditional_expression (cxx_pretty_printer *pp, tree e)
873 if (TREE_CODE (e) == COND_EXPR)
875 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
879 pp_cxx_expression (pp, TREE_OPERAND (e, 1));
881 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
884 pp_c_logical_or_expression (pp_c_base (pp), e);
887 /* Pretty-print a compound assignment operator token as indicated by T. */
890 pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t)
894 switch (TREE_CODE (t))
917 op = tree_code_name[TREE_CODE (t)];
921 pp_cxx_identifier (pp, op);
925 /* assignment-expression:
926 conditional-expression
927 logical-or-expression assignment-operator assignment-expression
931 throw assignment-expression(opt)
933 assignment-operator: one of
934 = *= /= %= += -= >>= <<= &= ^= |= */
937 pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e)
939 switch (TREE_CODE (e))
943 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
947 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 1));
951 pp_cxx_identifier (pp, "throw");
952 if (TREE_OPERAND (e, 0))
953 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 0));
957 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
958 pp_cxx_assignment_operator (pp, TREE_OPERAND (e, 1));
959 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
963 pp_cxx_conditional_expression (pp, e);
969 pp_cxx_expression (cxx_pretty_printer *pp, tree t)
971 switch (TREE_CODE (t))
977 pp_cxx_constant (pp, t);
981 pp_cxx_unqualified_id (pp, t);
989 pp_cxx_qualified_id (pp, t);
1001 case TEMPLATE_TYPE_PARM:
1002 case TEMPLATE_PARM_INDEX:
1003 case TEMPLATE_TEMPLATE_PARM:
1005 pp_cxx_primary_expression (pp, t);
1009 case DYNAMIC_CAST_EXPR:
1010 case STATIC_CAST_EXPR:
1011 case REINTERPRET_CAST_EXPR:
1012 case CONST_CAST_EXPR:
1016 case EMPTY_CLASS_EXPR:
1018 case PSEUDO_DTOR_EXPR:
1019 case AGGR_INIT_EXPR:
1021 pp_cxx_postfix_expression (pp, t);
1026 pp_cxx_new_expression (pp, t);
1030 case VEC_DELETE_EXPR:
1031 pp_cxx_delete_expression (pp, t);
1036 pp_cxx_unary_expression (pp, t);
1040 pp_cxx_cast_expression (pp, t);
1046 pp_cxx_pm_expression (pp, t);
1050 case TRUNC_DIV_EXPR:
1051 case TRUNC_MOD_EXPR:
1052 pp_cxx_multiplicative_expression (pp, t);
1056 pp_cxx_conditional_expression (pp, t);
1063 pp_cxx_assignment_expression (pp, t);
1066 case NON_DEPENDENT_EXPR:
1067 case MUST_NOT_THROW_EXPR:
1068 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
1071 case EXPR_PACK_EXPANSION:
1072 pp_cxx_expression (pp, PACK_EXPANSION_PATTERN (t));
1073 pp_cxx_identifier (pp, "...");
1076 case NONTYPE_ARGUMENT_PACK:
1078 tree args = ARGUMENT_PACK_ARGS (t);
1079 int i, len = TREE_VEC_LENGTH (args);
1080 for (i = 0; i < len; ++i)
1083 pp_cxx_separate_with (pp, ',');
1084 pp_cxx_expression (pp, TREE_VEC_ELT (args, i));
1090 pp_c_expression (pp_c_base (pp), t);
1098 /* function-specifier:
1104 pp_cxx_function_specifier (cxx_pretty_printer *pp, tree t)
1106 switch (TREE_CODE (t))
1109 if (DECL_VIRTUAL_P (t))
1110 pp_cxx_identifier (pp, "virtual");
1111 else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
1112 pp_cxx_identifier (pp, "explicit");
1114 pp_c_function_specifier (pp_c_base (pp), t);
1121 /* decl-specifier-seq:
1122 decl-specifier-seq(opt) decl-specifier
1125 storage-class-specifier
1132 pp_cxx_decl_specifier_seq (cxx_pretty_printer *pp, tree t)
1134 switch (TREE_CODE (t))
1140 pp_cxx_storage_class_specifier (pp, t);
1141 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1145 pp_cxx_identifier (pp, "typedef");
1146 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1150 if (TYPE_PTRMEMFUNC_P (t))
1152 tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t);
1153 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (pfm)));
1154 pp_cxx_whitespace (pp);
1155 pp_cxx_ptr_operator (pp, t);
1160 /* Constructors don't have return types. And conversion functions
1161 do not have a type-specifier in their return types. */
1162 if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t))
1163 pp_cxx_function_specifier (pp, t);
1164 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
1165 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (t)));
1168 pp_c_declaration_specifiers (pp_c_base (pp), t);
1173 /* simple-type-specifier:
1174 ::(opt) nested-name-specifier(opt) type-name
1175 ::(opt) nested-name-specifier(opt) template(opt) template-id
1189 pp_cxx_simple_type_specifier (cxx_pretty_printer *pp, tree t)
1191 switch (TREE_CODE (t))
1196 pp_cxx_qualified_id (pp, t);
1199 case TEMPLATE_TYPE_PARM:
1200 case TEMPLATE_TEMPLATE_PARM:
1201 case TEMPLATE_PARM_INDEX:
1202 pp_cxx_unqualified_id (pp, t);
1206 pp_cxx_identifier (pp, "typename");
1207 pp_cxx_nested_name_specifier (pp, TYPE_CONTEXT (t));
1208 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
1212 pp_c_type_specifier (pp_c_base (pp), t);
1217 /* type-specifier-seq:
1218 type-specifier type-specifier-seq(opt)
1221 simple-type-specifier
1224 elaborated-type-specifier
1228 pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
1230 switch (TREE_CODE (t))
1233 case TEMPLATE_TYPE_PARM:
1234 case TEMPLATE_TEMPLATE_PARM:
1236 case BOUND_TEMPLATE_TEMPLATE_PARM:
1237 pp_cxx_cv_qualifier_seq (pp, t);
1238 pp_cxx_simple_type_specifier (pp, t);
1242 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
1243 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1244 pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t));
1248 pp_cxx_identifier (pp, "decltype");
1249 pp_cxx_left_paren (pp);
1250 pp_cxx_expression (pp, DECLTYPE_TYPE_EXPR (t));
1251 pp_cxx_right_paren (pp);
1255 if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
1256 pp_c_specifier_qualifier_list (pp_c_base (pp), t);
1261 * cv-qualifier-seq(opt)
1263 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1266 pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
1268 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
1270 switch (TREE_CODE (t))
1272 case REFERENCE_TYPE:
1274 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
1275 || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t)))
1276 pp_cxx_ptr_operator (pp, TREE_TYPE (t));
1277 if (TREE_CODE (t) == POINTER_TYPE)
1280 pp_cxx_cv_qualifier_seq (pp, t);
1287 if (TYPE_PTRMEMFUNC_P (t))
1289 pp_cxx_left_paren (pp);
1290 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t));
1295 if (TYPE_PTR_TO_MEMBER_P (t))
1297 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1298 pp_cxx_left_paren (pp);
1299 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t));
1301 pp_cxx_cv_qualifier_seq (pp, t);
1304 /* else fall through. */
1307 pp_unsupported_tree (pp, t);
1313 pp_cxx_implicit_parameter_type (tree mf)
1315 return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf))));
1319 parameter-declaration:
1320 decl-specifier-seq declarator
1321 decl-specifier-seq declarator = assignment-expression
1322 decl-specifier-seq abstract-declarator(opt)
1323 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1326 pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
1328 pp_cxx_decl_specifier_seq (pp, t);
1330 pp_cxx_abstract_declarator (pp, t);
1332 pp_cxx_declarator (pp, t);
1335 /* parameter-declaration-clause:
1336 parameter-declaration-list(opt) ...(opt)
1337 parameter-declaration-list , ...
1339 parameter-declaration-list:
1340 parameter-declaration
1341 parameter-declaration-list , parameter-declaration */
1344 pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
1346 tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t);
1348 TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
1349 const bool abstract = args == NULL
1350 || pp_c_base (pp)->flags & pp_c_flag_abstract;
1353 /* Skip artificial parameter for nonstatic member functions. */
1354 if (TREE_CODE (t) == METHOD_TYPE)
1355 types = TREE_CHAIN (types);
1357 pp_cxx_left_paren (pp);
1358 for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
1361 pp_cxx_separate_with (pp, ',');
1363 pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
1364 if (!abstract && pp_c_base (pp)->flags & pp_cxx_flag_default_argument)
1366 pp_cxx_whitespace (pp);
1368 pp_cxx_whitespace (pp);
1369 pp_cxx_assignment_expression (pp, TREE_PURPOSE (types));
1372 pp_cxx_right_paren (pp);
1375 /* exception-specification:
1376 throw ( type-id-list(opt) )
1380 type-id-list , type-id */
1383 pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
1385 tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
1386 bool need_comma = false;
1388 if (!TYPE_NOTHROW_P (t) && ex_spec == NULL)
1390 pp_cxx_identifier (pp, "throw");
1391 pp_cxx_left_paren (pp);
1392 for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
1394 tree type = TREE_VALUE (ex_spec);
1395 tree argpack = NULL_TREE;
1398 if (ARGUMENT_PACK_P (type))
1400 argpack = ARGUMENT_PACK_ARGS (type);
1401 len = TREE_VEC_LENGTH (argpack);
1404 for (i = 0; i < len; ++i)
1407 type = TREE_VEC_ELT (argpack, i);
1410 pp_cxx_separate_with (pp, ',');
1414 pp_cxx_type_id (pp, type);
1417 pp_cxx_right_paren (pp);
1420 /* direct-declarator:
1422 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1423 exception-specification(opt)
1424 direct-declaration [ constant-expression(opt) ]
1428 pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t)
1430 switch (TREE_CODE (t))
1438 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1440 if ((TREE_CODE (t) == PARM_DECL && FUNCTION_PARAMETER_PACK_P (t))
1441 || template_parameter_pack_p (t))
1442 /* A function parameter pack or non-type template
1444 pp_cxx_identifier (pp, "...");
1446 pp_cxx_id_expression (pp, DECL_NAME (t));
1448 pp_cxx_abstract_declarator (pp, TREE_TYPE (t));
1452 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
1453 pp_cxx_id_expression (pp, t);
1454 pp_cxx_parameter_declaration_clause (pp, t);
1456 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
1458 pp_base (pp)->padding = pp_before;
1459 pp_cxx_cv_qualifier_seq (pp, pp_cxx_implicit_parameter_type (t));
1462 pp_cxx_exception_specification (pp, TREE_TYPE (t));
1467 case TEMPLATE_TYPE_PARM:
1468 case TEMPLATE_PARM_INDEX:
1469 case TEMPLATE_TEMPLATE_PARM:
1473 pp_c_direct_declarator (pp_c_base (pp), t);
1480 ptr-operator declarator */
1483 pp_cxx_declarator (cxx_pretty_printer *pp, tree t)
1485 pp_cxx_direct_declarator (pp, t);
1488 /* ctor-initializer:
1489 : mem-initializer-list
1491 mem-initializer-list:
1493 mem-initializer , mem-initializer-list
1496 mem-initializer-id ( expression-list(opt) )
1499 ::(opt) nested-name-specifier(opt) class-name
1503 pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
1505 t = TREE_OPERAND (t, 0);
1506 pp_cxx_whitespace (pp);
1508 pp_cxx_whitespace (pp);
1509 for (; t; t = TREE_CHAIN (t))
1511 tree purpose = TREE_PURPOSE (t);
1512 bool is_pack = PACK_EXPANSION_P (purpose);
1515 pp_cxx_primary_expression (pp, PACK_EXPANSION_PATTERN (purpose));
1517 pp_cxx_primary_expression (pp, purpose);
1518 pp_cxx_call_argument_list (pp, TREE_VALUE (t));
1520 pp_cxx_identifier (pp, "...");
1522 pp_cxx_separate_with (pp, ',');
1526 /* function-definition:
1527 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1528 decl-specifier-seq(opt) declarator function-try-block */
1531 pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
1533 tree saved_scope = pp->enclosing_scope;
1534 pp_cxx_decl_specifier_seq (pp, t);
1535 pp_cxx_declarator (pp, t);
1536 pp_needs_newline (pp) = true;
1537 pp->enclosing_scope = DECL_CONTEXT (t);
1538 if (DECL_SAVED_TREE (t))
1539 pp_cxx_statement (pp, DECL_SAVED_TREE (t));
1542 pp_cxx_semicolon (pp);
1543 pp_needs_newline (pp) = true;
1546 pp->enclosing_scope = saved_scope;
1549 /* abstract-declarator:
1550 ptr-operator abstract-declarator(opt)
1551 direct-abstract-declarator */
1554 pp_cxx_abstract_declarator (cxx_pretty_printer *pp, tree t)
1556 if (TYPE_PTRMEM_P (t) || TYPE_PTRMEMFUNC_P (t))
1557 pp_cxx_right_paren (pp);
1558 else if (POINTER_TYPE_P (t))
1560 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
1561 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1562 pp_cxx_right_paren (pp);
1565 pp_cxx_direct_abstract_declarator (pp, t);
1568 /* direct-abstract-declarator:
1569 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1570 cv-qualifier-seq(opt) exception-specification(opt)
1571 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1572 ( abstract-declarator ) */
1575 pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
1577 switch (TREE_CODE (t))
1579 case REFERENCE_TYPE:
1580 pp_cxx_abstract_declarator (pp, t);
1584 if (TYPE_PTRMEMFUNC_P (t))
1585 pp_cxx_direct_abstract_declarator (pp, TYPE_PTRMEMFUNC_FN_TYPE (t));
1590 pp_cxx_parameter_declaration_clause (pp, t);
1591 pp_cxx_direct_abstract_declarator (pp, TREE_TYPE (t));
1592 if (TREE_CODE (t) == METHOD_TYPE)
1594 pp_base (pp)->padding = pp_before;
1595 pp_cxx_cv_qualifier_seq
1596 (pp, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))));
1598 pp_cxx_exception_specification (pp, t);
1602 case TEMPLATE_TYPE_PARM:
1603 case TEMPLATE_TEMPLATE_PARM:
1604 case BOUND_TEMPLATE_TEMPLATE_PARM:
1605 case UNBOUND_CLASS_TEMPLATE:
1609 pp_c_direct_abstract_declarator (pp_c_base (pp), t);
1615 type-specifier-seq abstract-declarator(opt) */
1618 pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
1620 pp_flags saved_flags = pp_c_base (pp)->flags;
1621 pp_c_base (pp)->flags |= pp_c_flag_abstract;
1623 switch (TREE_CODE (t))
1630 case BOUND_TEMPLATE_TEMPLATE_PARM:
1631 case UNBOUND_CLASS_TEMPLATE:
1632 case TEMPLATE_TEMPLATE_PARM:
1633 case TEMPLATE_TYPE_PARM:
1634 case TEMPLATE_PARM_INDEX:
1638 case TEMPLATE_ID_EXPR:
1639 pp_cxx_type_specifier_seq (pp, t);
1642 case TYPE_PACK_EXPANSION:
1643 pp_cxx_type_id (pp, PACK_EXPANSION_PATTERN (t));
1644 pp_cxx_identifier (pp, "...");
1648 pp_c_type_id (pp_c_base (pp), t);
1652 pp_c_base (pp)->flags = saved_flags;
1655 /* template-argument-list:
1656 template-argument ...(opt)
1657 template-argument-list, template-argument ...(opt)
1660 assignment-expression
1665 pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
1668 bool need_comma = false;
1672 for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
1674 tree arg = TREE_VEC_ELT (t, i);
1675 tree argpack = NULL_TREE;
1678 if (ARGUMENT_PACK_P (arg))
1680 argpack = ARGUMENT_PACK_ARGS (arg);
1681 len = TREE_VEC_LENGTH (argpack);
1684 for (idx = 0; idx < len; idx++)
1687 arg = TREE_VEC_ELT (argpack, idx);
1690 pp_cxx_separate_with (pp, ',');
1694 if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
1695 && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
1696 pp_cxx_type_id (pp, arg);
1698 pp_cxx_expression (pp, arg);
1705 pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
1707 t = DECL_EXPR_DECL (t);
1708 pp_cxx_type_specifier_seq (pp, t);
1710 pp_cxx_abstract_declarator (pp, t);
1712 pp_cxx_declarator (pp, t);
1718 pp_cxx_statement (cxx_pretty_printer *pp, tree t)
1720 switch (TREE_CODE (t))
1722 case CTOR_INITIALIZER:
1723 pp_cxx_ctor_initializer (pp, t);
1727 pp_cxx_identifier (pp, "using");
1728 pp_cxx_identifier (pp, "namespace");
1729 if (DECL_CONTEXT (t))
1730 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1731 pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t));
1735 pp_cxx_identifier (pp, "using");
1736 pp_cxx_nested_name_specifier (pp, USING_DECL_SCOPE (t));
1737 pp_cxx_unqualified_id (pp, DECL_NAME (t));
1744 try compound-statement handler-seq */
1746 pp_maybe_newline_and_indent (pp, 0);
1747 pp_cxx_identifier (pp, "try");
1748 pp_newline_and_indent (pp, 3);
1749 pp_cxx_statement (pp, TRY_STMTS (t));
1750 pp_newline_and_indent (pp, -3);
1754 pp_cxx_statement (pp, TRY_HANDLERS (t));
1759 handler handler-seq(opt)
1762 catch ( exception-declaration ) compound-statement
1764 exception-declaration:
1765 type-specifier-seq declarator
1766 type-specifier-seq abstract-declarator
1769 pp_cxx_identifier (pp, "catch");
1770 pp_cxx_left_paren (pp);
1771 pp_cxx_exception_declaration (pp, HANDLER_PARMS (t));
1772 pp_cxx_right_paren (pp);
1773 pp_indentation (pp) += 3;
1774 pp_needs_newline (pp) = true;
1775 pp_cxx_statement (pp, HANDLER_BODY (t));
1776 pp_indentation (pp) -= 3;
1777 pp_needs_newline (pp) = true;
1780 /* selection-statement:
1781 if ( expression ) statement
1782 if ( expression ) statement else statement */
1784 pp_cxx_identifier (pp, "if");
1785 pp_cxx_whitespace (pp);
1786 pp_cxx_left_paren (pp);
1787 pp_cxx_expression (pp, IF_COND (t));
1788 pp_cxx_right_paren (pp);
1789 pp_newline_and_indent (pp, 2);
1790 pp_cxx_statement (pp, THEN_CLAUSE (t));
1791 pp_newline_and_indent (pp, -2);
1792 if (ELSE_CLAUSE (t))
1794 tree else_clause = ELSE_CLAUSE (t);
1795 pp_cxx_identifier (pp, "else");
1796 if (TREE_CODE (else_clause) == IF_STMT)
1797 pp_cxx_whitespace (pp);
1799 pp_newline_and_indent (pp, 2);
1800 pp_cxx_statement (pp, else_clause);
1801 if (TREE_CODE (else_clause) != IF_STMT)
1802 pp_newline_and_indent (pp, -2);
1807 pp_cxx_identifier (pp, "switch");
1809 pp_cxx_left_paren (pp);
1810 pp_cxx_expression (pp, SWITCH_STMT_COND (t));
1811 pp_cxx_right_paren (pp);
1812 pp_indentation (pp) += 3;
1813 pp_needs_newline (pp) = true;
1814 pp_cxx_statement (pp, SWITCH_STMT_BODY (t));
1815 pp_newline_and_indent (pp, -3);
1818 /* iteration-statement:
1819 while ( expression ) statement
1820 do statement while ( expression ) ;
1821 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1822 for ( declaration expression(opt) ; expression(opt) ) statement */
1824 pp_cxx_identifier (pp, "while");
1826 pp_cxx_left_paren (pp);
1827 pp_cxx_expression (pp, WHILE_COND (t));
1828 pp_cxx_right_paren (pp);
1829 pp_newline_and_indent (pp, 3);
1830 pp_cxx_statement (pp, WHILE_BODY (t));
1831 pp_indentation (pp) -= 3;
1832 pp_needs_newline (pp) = true;
1836 pp_cxx_identifier (pp, "do");
1837 pp_newline_and_indent (pp, 3);
1838 pp_cxx_statement (pp, DO_BODY (t));
1839 pp_newline_and_indent (pp, -3);
1840 pp_cxx_identifier (pp, "while");
1842 pp_cxx_left_paren (pp);
1843 pp_cxx_expression (pp, DO_COND (t));
1844 pp_cxx_right_paren (pp);
1845 pp_cxx_semicolon (pp);
1846 pp_needs_newline (pp) = true;
1850 pp_cxx_identifier (pp, "for");
1852 pp_cxx_left_paren (pp);
1853 if (FOR_INIT_STMT (t))
1854 pp_cxx_statement (pp, FOR_INIT_STMT (t));
1856 pp_cxx_semicolon (pp);
1857 pp_needs_newline (pp) = false;
1858 pp_cxx_whitespace (pp);
1860 pp_cxx_expression (pp, FOR_COND (t));
1861 pp_cxx_semicolon (pp);
1862 pp_needs_newline (pp) = false;
1863 pp_cxx_whitespace (pp);
1865 pp_cxx_expression (pp, FOR_EXPR (t));
1866 pp_cxx_right_paren (pp);
1867 pp_newline_and_indent (pp, 3);
1868 pp_cxx_statement (pp, FOR_BODY (t));
1869 pp_indentation (pp) -= 3;
1870 pp_needs_newline (pp) = true;
1876 return expression(opt) ; */
1879 pp_identifier (pp, TREE_CODE (t) == BREAK_STMT ? "break" : "continue");
1880 pp_cxx_semicolon (pp);
1881 pp_needs_newline (pp) = true;
1884 /* expression-statement:
1885 expression(opt) ; */
1887 pp_cxx_expression (pp, EXPR_STMT_EXPR (t));
1888 pp_cxx_semicolon (pp);
1889 pp_needs_newline (pp) = true;
1893 pp_cxx_identifier (pp, "try");
1894 pp_newline_and_indent (pp, 2);
1895 pp_cxx_statement (pp, CLEANUP_BODY (t));
1896 pp_newline_and_indent (pp, -2);
1897 pp_cxx_identifier (pp, CLEANUP_EH_ONLY (t) ? "catch" : "finally");
1898 pp_newline_and_indent (pp, 2);
1899 pp_cxx_statement (pp, CLEANUP_EXPR (t));
1900 pp_newline_and_indent (pp, -2);
1904 pp_cxx_declaration (pp, t);
1908 pp_c_statement (pp_c_base (pp), t);
1913 /* original-namespace-definition:
1914 namespace identifier { namespace-body }
1916 As an edge case, we also handle unnamed namespace definition here. */
1919 pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t)
1921 pp_cxx_identifier (pp, "namespace");
1922 if (DECL_CONTEXT (t))
1923 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1925 pp_cxx_unqualified_id (pp, t);
1926 pp_cxx_whitespace (pp);
1927 pp_cxx_left_brace (pp);
1928 /* We do not print the namespace-body. */
1929 pp_cxx_whitespace (pp);
1930 pp_cxx_right_brace (pp);
1936 namespace-alias-definition:
1937 namespace identifier = qualified-namespace-specifier ;
1939 qualified-namespace-specifier:
1940 ::(opt) nested-name-specifier(opt) namespace-name */
1943 pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t)
1945 pp_cxx_identifier (pp, "namespace");
1946 if (DECL_CONTEXT (t))
1947 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1948 pp_cxx_unqualified_id (pp, t);
1949 pp_cxx_whitespace (pp);
1951 pp_cxx_whitespace (pp);
1952 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)))
1953 pp_cxx_nested_name_specifier (pp,
1954 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)));
1955 pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t));
1956 pp_cxx_semicolon (pp);
1959 /* simple-declaration:
1960 decl-specifier-seq(opt) init-declarator-list(opt) */
1963 pp_cxx_simple_declaration (cxx_pretty_printer *pp, tree t)
1965 pp_cxx_decl_specifier_seq (pp, t);
1966 pp_cxx_init_declarator (pp, t);
1967 pp_cxx_semicolon (pp);
1968 pp_needs_newline (pp) = true;
1972 template-parameter-list:
1974 template-parameter-list , template-parameter */
1977 pp_cxx_template_parameter_list (cxx_pretty_printer *pp, tree t)
1979 const int n = TREE_VEC_LENGTH (t);
1981 for (i = 0; i < n; ++i)
1984 pp_cxx_separate_with (pp, ',');
1985 pp_cxx_template_parameter (pp, TREE_VEC_ELT (t, i));
1989 /* template-parameter:
1991 parameter-declaration
1994 class ...(opt) identifier(opt)
1995 class identifier(opt) = type-id
1996 typename identifier(opt)
1997 typename ...(opt) identifier(opt) = type-id
1998 template < template-parameter-list > class ...(opt) identifier(opt)
1999 template < template-parameter-list > class identifier(opt) = template-name */
2002 pp_cxx_template_parameter (cxx_pretty_printer *pp, tree t)
2004 tree parameter = TREE_VALUE (t);
2005 switch (TREE_CODE (parameter))
2008 pp_cxx_identifier (pp, "class");
2009 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t)))
2010 pp_cxx_identifier (pp, "...");
2011 if (DECL_NAME (parameter))
2012 pp_cxx_tree_identifier (pp, DECL_NAME (parameter));
2013 /* FIXME: Chech if we should print also default argument. */
2017 pp_cxx_parameter_declaration (pp, parameter);
2024 pp_unsupported_tree (pp, t);
2029 /* Pretty-print a template parameter in the canonical form
2030 "template-parameter-<level>-<position in parameter list>". */
2033 pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm)
2035 const enum tree_code code = TREE_CODE (parm);
2037 /* Brings type template parameters to the canonical forms. */
2038 if (code == TEMPLATE_TYPE_PARM || code == TEMPLATE_TEMPLATE_PARM
2039 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
2040 parm = TEMPLATE_TYPE_PARM_INDEX (parm);
2042 pp_cxx_begin_template_argument_list (pp);
2043 pp_cxx_identifier (pp, "template-parameter-");
2044 pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm));
2046 pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1);
2047 pp_cxx_end_template_argument_list (pp);
2051 template-declaration:
2052 export(opt) template < template-parameter-list > declaration */
2055 pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t)
2057 tree tmpl = most_general_template (t);
2061 pp_maybe_newline_and_indent (pp, 0);
2062 for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level))
2064 pp_cxx_identifier (pp, "template");
2065 pp_cxx_begin_template_argument_list (pp);
2066 pp_cxx_template_parameter_list (pp, TREE_VALUE (level));
2067 pp_cxx_end_template_argument_list (pp);
2068 pp_newline_and_indent (pp, 3);
2071 if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t))
2072 pp_cxx_function_definition (pp, t);
2074 pp_cxx_simple_declaration (pp, t);
2078 pp_cxx_explicit_specialization (cxx_pretty_printer *pp, tree t)
2080 pp_unsupported_tree (pp, t);
2084 pp_cxx_explicit_instantiation (cxx_pretty_printer *pp, tree t)
2086 pp_unsupported_tree (pp, t);
2093 template-declaration
2094 explicit-instantiation
2095 explicit-specialization
2096 linkage-specification
2097 namespace-definition
2102 namespace-alias-definition
2105 static_assert-declaration */
2107 pp_cxx_declaration (cxx_pretty_printer *pp, tree t)
2109 if (TREE_CODE (t) == STATIC_ASSERT)
2111 pp_cxx_identifier (pp, "static_assert");
2112 pp_cxx_left_paren (pp);
2113 pp_cxx_expression (pp, STATIC_ASSERT_CONDITION (t));
2114 pp_cxx_separate_with (pp, ',');
2115 pp_cxx_expression (pp, STATIC_ASSERT_MESSAGE (t));
2116 pp_cxx_right_paren (pp);
2118 else if (!DECL_LANG_SPECIFIC (t))
2119 pp_cxx_simple_declaration (pp, t);
2120 else if (DECL_USE_TEMPLATE (t))
2121 switch (DECL_USE_TEMPLATE (t))
2124 pp_cxx_template_declaration (pp, t);
2128 pp_cxx_explicit_specialization (pp, t);
2132 pp_cxx_explicit_instantiation (pp, t);
2138 else switch (TREE_CODE (t))
2142 pp_cxx_simple_declaration (pp, t);
2146 if (DECL_SAVED_TREE (t))
2147 pp_cxx_function_definition (pp, t);
2149 pp_cxx_simple_declaration (pp, t);
2152 case NAMESPACE_DECL:
2153 if (DECL_NAMESPACE_ALIAS (t))
2154 pp_cxx_namespace_alias_definition (pp, t);
2156 pp_cxx_original_namespace_definition (pp, t);
2160 pp_unsupported_tree (pp, t);
2166 pp_cxx_typeid_expression (cxx_pretty_printer *pp, tree t)
2168 t = TREE_OPERAND (t, 0);
2169 pp_cxx_identifier (pp, "typeid");
2170 pp_cxx_left_paren (pp);
2172 pp_cxx_type_id (pp, t);
2174 pp_cxx_expression (pp, t);
2175 pp_cxx_right_paren (pp);
2179 pp_cxx_va_arg_expression (cxx_pretty_printer *pp, tree t)
2181 pp_cxx_identifier (pp, "va_arg");
2182 pp_cxx_left_paren (pp);
2183 pp_cxx_assignment_expression (pp, TREE_OPERAND (t, 0));
2184 pp_cxx_separate_with (pp, ',');
2185 pp_cxx_type_id (pp, TREE_TYPE (t));
2186 pp_cxx_right_paren (pp);
2190 pp_cxx_offsetof_expression_1 (cxx_pretty_printer *pp, tree t)
2192 switch (TREE_CODE (t))
2195 if (TREE_CODE (TREE_OPERAND (t, 0)) == STATIC_CAST_EXPR
2196 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
2198 pp_cxx_type_id (pp, TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))));
2199 pp_cxx_separate_with (pp, ',');
2204 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
2206 if (TREE_CODE (TREE_OPERAND (t, 0)) != ARROW_EXPR)
2208 pp_cxx_expression (pp, TREE_OPERAND (t, 1));
2211 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
2213 pp_left_bracket (pp);
2214 pp_cxx_expression (pp, TREE_OPERAND (t, 1));
2215 pp_right_bracket (pp);
2223 pp_cxx_offsetof_expression (cxx_pretty_printer *pp, tree t)
2225 pp_cxx_identifier (pp, "offsetof");
2226 pp_cxx_left_paren (pp);
2227 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
2228 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
2229 pp_cxx_right_paren (pp);
2233 pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t)
2235 cp_trait_kind kind = TRAIT_EXPR_KIND (t);
2239 case CPTK_HAS_NOTHROW_ASSIGN:
2240 pp_cxx_identifier (pp, "__has_nothrow_assign");
2242 case CPTK_HAS_TRIVIAL_ASSIGN:
2243 pp_cxx_identifier (pp, "__has_trivial_assign");
2245 case CPTK_HAS_NOTHROW_CONSTRUCTOR:
2246 pp_cxx_identifier (pp, "__has_nothrow_constructor");
2248 case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
2249 pp_cxx_identifier (pp, "__has_trivial_constructor");
2251 case CPTK_HAS_NOTHROW_COPY:
2252 pp_cxx_identifier (pp, "__has_nothrow_copy");
2254 case CPTK_HAS_TRIVIAL_COPY:
2255 pp_cxx_identifier (pp, "__has_trivial_copy");
2257 case CPTK_HAS_TRIVIAL_DESTRUCTOR:
2258 pp_cxx_identifier (pp, "__has_trivial_destructor");
2260 case CPTK_HAS_VIRTUAL_DESTRUCTOR:
2261 pp_cxx_identifier (pp, "__has_virtual_destructor");
2263 case CPTK_IS_ABSTRACT:
2264 pp_cxx_identifier (pp, "__is_abstract");
2266 case CPTK_IS_BASE_OF:
2267 pp_cxx_identifier (pp, "__is_base_of");
2270 pp_cxx_identifier (pp, "__is_class");
2272 case CPTK_IS_CONVERTIBLE_TO:
2273 pp_cxx_identifier (pp, "__is_convertible_to");
2276 pp_cxx_identifier (pp, "__is_empty");
2279 pp_cxx_identifier (pp, "__is_enum");
2282 pp_cxx_identifier (pp, "__is_pod");
2284 case CPTK_IS_POLYMORPHIC:
2285 pp_cxx_identifier (pp, "__is_polymorphic");
2288 pp_cxx_identifier (pp, "__is_union");
2295 pp_cxx_left_paren (pp);
2296 pp_cxx_type_id (pp, TRAIT_EXPR_TYPE1 (t));
2298 if (kind == CPTK_IS_BASE_OF || kind == CPTK_IS_CONVERTIBLE_TO)
2300 pp_cxx_separate_with (pp, ',');
2301 pp_cxx_type_id (pp, TRAIT_EXPR_TYPE2 (t));
2304 pp_cxx_right_paren (pp);
2307 typedef c_pretty_print_fn pp_fun;
2309 /* Initialization of a C++ pretty-printer object. */
2312 pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
2314 pp_c_pretty_printer_init (pp_c_base (pp));
2315 pp_set_line_maximum_length (pp, 0);
2317 pp->c_base.declaration = (pp_fun) pp_cxx_declaration;
2318 pp->c_base.declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
2319 pp->c_base.function_specifier = (pp_fun) pp_cxx_function_specifier;
2320 pp->c_base.type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
2321 pp->c_base.declarator = (pp_fun) pp_cxx_declarator;
2322 pp->c_base.direct_declarator = (pp_fun) pp_cxx_direct_declarator;
2323 pp->c_base.parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
2324 pp->c_base.type_id = (pp_fun) pp_cxx_type_id;
2325 pp->c_base.abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
2326 pp->c_base.direct_abstract_declarator =
2327 (pp_fun) pp_cxx_direct_abstract_declarator;
2328 pp->c_base.simple_type_specifier = (pp_fun)pp_cxx_simple_type_specifier;
2330 /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
2332 pp->c_base.constant = (pp_fun) pp_cxx_constant;
2333 pp->c_base.id_expression = (pp_fun) pp_cxx_id_expression;
2334 pp->c_base.primary_expression = (pp_fun) pp_cxx_primary_expression;
2335 pp->c_base.postfix_expression = (pp_fun) pp_cxx_postfix_expression;
2336 pp->c_base.unary_expression = (pp_fun) pp_cxx_unary_expression;
2337 pp->c_base.multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
2338 pp->c_base.conditional_expression = (pp_fun) pp_cxx_conditional_expression;
2339 pp->c_base.assignment_expression = (pp_fun) pp_cxx_assignment_expression;
2340 pp->c_base.expression = (pp_fun) pp_cxx_expression;
2341 pp->enclosing_scope = global_namespace;