1 /* Implementation of subroutines for the GNU C++ pretty-printer.
2 Copyright (C) 2003, 2004, 2005 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 2, 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 COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "coretypes.h"
27 #include "cxx-pretty-print.h"
31 static void pp_cxx_unqualified_id (cxx_pretty_printer *, tree);
32 static void pp_cxx_nested_name_specifier (cxx_pretty_printer *, tree);
33 static void pp_cxx_qualified_id (cxx_pretty_printer *, tree);
34 static void pp_cxx_assignment_expression (cxx_pretty_printer *, tree);
35 static void pp_cxx_expression (cxx_pretty_printer *, tree);
36 static void pp_cxx_template_argument_list (cxx_pretty_printer *, tree);
37 static void pp_cxx_type_specifier_seq (cxx_pretty_printer *, tree);
38 static void pp_cxx_ptr_operator (cxx_pretty_printer *, tree);
39 static void pp_cxx_type_id (cxx_pretty_printer *, tree);
40 static void pp_cxx_direct_abstract_declarator (cxx_pretty_printer *, tree);
41 static void pp_cxx_declarator (cxx_pretty_printer *, tree);
42 static void pp_cxx_parameter_declaration_clause (cxx_pretty_printer *, tree);
43 static void pp_cxx_abstract_declarator (cxx_pretty_printer *, tree);
44 static void pp_cxx_statement (cxx_pretty_printer *, tree);
45 static void pp_cxx_template_parameter (cxx_pretty_printer *, tree);
46 static void pp_cxx_cast_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));
194 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
197 case TEMPLATE_TYPE_PARM:
198 case TEMPLATE_TEMPLATE_PARM:
199 if (TYPE_IDENTIFIER (t))
200 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
202 pp_cxx_canonical_template_parameter (pp, t);
205 case TEMPLATE_PARM_INDEX:
206 pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t));
210 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
214 pp_unsupported_tree (pp, t);
219 /* Pretty-print out the token sequence ":: template" in template codes
220 where it is needed to "inline declare" the (following) member as
221 a template. This situation arises when SCOPE of T is dependent
222 on template parameters. */
225 pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
227 if (TREE_CODE (t) == TEMPLATE_ID_EXPR
228 && TYPE_P (scope) && dependent_type_p (scope))
229 pp_cxx_identifier (pp, "template");
232 /* nested-name-specifier:
233 class-or-namespace-name :: nested-name-specifier(opt)
234 class-or-namespace-name :: template nested-name-specifier */
237 pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
239 if (t != NULL && t != pp->enclosing_scope)
241 tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
242 pp_cxx_nested_name_specifier (pp, scope);
243 pp_cxx_template_keyword_if_needed (pp, scope, t);
244 pp_cxx_unqualified_id (pp, t);
245 pp_cxx_colon_colon (pp);
250 nested-name-specifier template(opt) unqualified-id */
253 pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t)
255 switch (TREE_CODE (t))
257 /* A pointer-to-member is always qualified. */
259 pp_cxx_nested_name_specifier (pp, PTRMEM_CST_CLASS (t));
260 pp_cxx_unqualified_id (pp, PTRMEM_CST_MEMBER (t));
263 /* In Standard C++, functions cannot possibly be used as
264 nested-name-specifiers. However, there are situations where
265 is "makes sense" to output the surrounding function name for the
266 purpose of emphasizing on the scope kind. Just printing the
267 function name might not be sufficient as it may be overloaded; so,
268 we decorate the function with its signature too.
269 FIXME: This is probably the wrong pretty-printing for conversion
270 functions and some function templates. */
274 if (DECL_FUNCTION_MEMBER_P (t))
275 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
276 pp_cxx_unqualified_id
277 (pp, DECL_CONSTRUCTOR_P (t) ? DECL_CONTEXT (t) : t);
278 pp_cxx_parameter_declaration_clause (pp, TREE_TYPE (t));
283 pp_cxx_nested_name_specifier (pp, TREE_OPERAND (t, 0));
284 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 1));
289 tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
290 if (scope != pp->enclosing_scope)
292 pp_cxx_nested_name_specifier (pp, scope);
293 pp_cxx_template_keyword_if_needed (pp, scope, t);
295 pp_cxx_unqualified_id (pp, t);
303 pp_cxx_constant (cxx_pretty_printer *pp, tree t)
305 switch (TREE_CODE (t))
309 const bool in_parens = PAREN_STRING_LITERAL_P (t);
311 pp_cxx_left_paren (pp);
312 pp_c_constant (pp_c_base (pp), t);
314 pp_cxx_right_paren (pp);
319 pp_c_constant (pp_c_base (pp), t);
329 pp_cxx_id_expression (cxx_pretty_printer *pp, tree t)
331 if (TREE_CODE (t) == OVERLOAD)
333 if (DECL_P (t) && DECL_CONTEXT (t))
334 pp_cxx_qualified_id (pp, t);
336 pp_cxx_unqualified_id (pp, t);
339 /* primary-expression:
343 :: operator-function-id
349 pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
351 switch (TREE_CODE (t))
356 pp_cxx_constant (pp, t);
360 t = BASELINK_FUNCTIONS (t);
368 pp_cxx_id_expression (pp, t);
372 case TEMPLATE_TYPE_PARM:
373 case TEMPLATE_TEMPLATE_PARM:
374 case TEMPLATE_PARM_INDEX:
375 pp_cxx_unqualified_id (pp, t);
379 pp_cxx_left_paren (pp);
380 pp_cxx_statement (pp, STMT_EXPR_STMT (t));
381 pp_cxx_right_paren (pp);
385 pp_c_primary_expression (pp_c_base (pp), t);
390 /* postfix-expression:
392 postfix-expression [ expression ]
393 postfix-expression ( expression-list(opt) )
394 simple-type-specifier ( expression-list(opt) )
395 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
396 typename ::(opt) nested-name-specifier template(opt)
397 template-id ( expression-list(opt) )
398 postfix-expression . template(opt) ::(opt) id-expression
399 postfix-expression -> template(opt) ::(opt) id-expression
400 postfix-expression . pseudo-destructor-name
401 postfix-expression -> pseudo-destructor-name
402 postfix-expression ++
403 postfix-expression --
404 dynamic_cast < type-id > ( expression )
405 static_cast < type-id > ( expression )
406 reinterpret_cast < type-id > ( expression )
407 const_cast < type-id > ( expression )
408 typeid ( expression )
409 typeif ( type-id ) */
412 pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t)
414 enum tree_code code = TREE_CODE (t);
421 tree fun = (code == AGGR_INIT_EXPR ? AGGR_INIT_EXPR_FN (t)
423 tree saved_scope = pp->enclosing_scope;
424 bool skipfirst = false;
427 if (TREE_CODE (fun) == ADDR_EXPR)
428 fun = TREE_OPERAND (fun, 0);
430 /* In templates, where there is no way to tell whether a given
431 call uses an actual member function. So the parser builds
432 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
433 instantiation time. */
434 if (TREE_CODE (fun) != FUNCTION_DECL)
436 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun))
438 tree object = (code == AGGR_INIT_EXPR
439 ? (AGGR_INIT_VIA_CTOR_P (t)
440 ? AGGR_INIT_EXPR_SLOT (t)
441 : AGGR_INIT_EXPR_ARG (t, 0))
442 : CALL_EXPR_ARG (t, 0));
444 while (TREE_CODE (object) == NOP_EXPR)
445 object = TREE_OPERAND (object, 0);
447 if (TREE_CODE (object) == ADDR_EXPR)
448 object = TREE_OPERAND (object, 0);
450 if (TREE_CODE (TREE_TYPE (object)) != POINTER_TYPE)
452 pp_cxx_postfix_expression (pp, object);
457 pp_cxx_postfix_expression (pp, object);
461 pp->enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
464 pp_cxx_postfix_expression (pp, fun);
465 pp->enclosing_scope = saved_scope;
466 pp_cxx_left_paren (pp);
467 if (code == AGGR_INIT_EXPR)
469 aggr_init_expr_arg_iterator iter;
470 FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t)
476 pp_cxx_expression (pp, arg);
477 if (more_aggr_init_expr_args_p (&iter))
478 pp_cxx_separate_with (pp, ',');
484 call_expr_arg_iterator iter;
485 FOR_EACH_CALL_EXPR_ARG (arg, iter, t)
491 pp_cxx_expression (pp, arg);
492 if (more_call_expr_args_p (&iter))
493 pp_cxx_separate_with (pp, ',');
497 pp_cxx_right_paren (pp);
499 if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
501 pp_cxx_separate_with (pp, ',');
502 pp_cxx_postfix_expression (pp, AGGR_INIT_EXPR_SLOT (t));
515 pp_cxx_primary_expression (pp, t);
518 case DYNAMIC_CAST_EXPR:
519 case STATIC_CAST_EXPR:
520 case REINTERPRET_CAST_EXPR:
521 case CONST_CAST_EXPR:
522 if (code == DYNAMIC_CAST_EXPR)
523 pp_cxx_identifier (pp, "dynamic_cast");
524 else if (code == STATIC_CAST_EXPR)
525 pp_cxx_identifier (pp, "static_cast");
526 else if (code == REINTERPRET_CAST_EXPR)
527 pp_cxx_identifier (pp, "reinterpret_cast");
529 pp_cxx_identifier (pp, "const_cast");
530 pp_cxx_begin_template_argument_list (pp);
531 pp_cxx_type_id (pp, TREE_TYPE (t));
532 pp_cxx_end_template_argument_list (pp);
534 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
538 case EMPTY_CLASS_EXPR:
539 pp_cxx_type_id (pp, TREE_TYPE (t));
545 t = TREE_OPERAND (t, 0);
546 pp_cxx_identifier (pp, "typeid");
549 pp_cxx_type_id (pp, t);
551 pp_cxx_expression (pp, t);
555 case PSEUDO_DTOR_EXPR:
556 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
558 pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1));
559 pp_cxx_colon_colon (pp);
561 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2));
565 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
570 pp_c_postfix_expression (pp_c_base (pp), t);
576 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
577 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
583 type-specifier-seq new-declarator(opt)
586 ptr-operator new-declarator(opt)
587 direct-new-declarator
589 direct-new-declarator
591 direct-new-declarator [ constant-expression ]
594 ( expression-list(opt) ) */
597 pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
599 enum tree_code code = TREE_CODE (t);
604 if (NEW_EXPR_USE_GLOBAL (t))
605 pp_cxx_colon_colon (pp);
606 pp_cxx_identifier (pp, "new");
607 if (TREE_OPERAND (t, 0))
609 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
612 /* FIXME: array-types are built with one more element. */
613 pp_cxx_type_id (pp, TREE_OPERAND (t, 1));
614 if (TREE_OPERAND (t, 2))
617 t = TREE_OPERAND (t, 2);
618 if (TREE_CODE (t) == TREE_LIST)
619 pp_c_expression_list (pp_c_base (pp), t);
620 else if (t == void_zero_node)
621 ; /* OK, empty initializer list. */
623 pp_cxx_expression (pp, t);
629 pp_unsupported_tree (pp, t);
633 /* delete-expression:
634 ::(opt) delete cast-expression
635 ::(opt) delete [ ] cast-expression */
638 pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
640 enum tree_code code = TREE_CODE (t);
644 case VEC_DELETE_EXPR:
645 if (DELETE_EXPR_USE_GLOBAL (t))
646 pp_cxx_colon_colon (pp);
647 pp_cxx_identifier (pp, "delete");
648 if (code == VEC_DELETE_EXPR)
650 pp_left_bracket (pp);
651 pp_right_bracket (pp);
653 pp_c_cast_expression (pp_c_base (pp), TREE_OPERAND (t, 0));
657 pp_unsupported_tree (pp, t);
665 unary-operator cast-expression
666 sizeof unary-expression
668 sizeof ... ( identifier )
672 unary-operator: one of
676 __alignof__ unary-expression
677 __alignof__ ( type-id ) */
680 pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
682 enum tree_code code = TREE_CODE (t);
687 pp_cxx_new_expression (pp, t);
691 case VEC_DELETE_EXPR:
692 pp_cxx_delete_expression (pp, t);
696 if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
698 pp_cxx_identifier (pp, "sizeof");
699 pp_cxx_identifier (pp, "...");
700 pp_cxx_whitespace (pp);
701 pp_cxx_left_paren (pp);
702 if (TYPE_P (TREE_OPERAND (t, 0)))
703 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
705 pp_unary_expression (pp, TREE_OPERAND (t, 0));
706 pp_cxx_right_paren (pp);
712 pp_cxx_identifier (pp, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
713 pp_cxx_whitespace (pp);
714 if (TYPE_P (TREE_OPERAND (t, 0)))
716 pp_cxx_left_paren (pp);
717 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
718 pp_cxx_right_paren (pp);
721 pp_unary_expression (pp, TREE_OPERAND (t, 0));
724 case UNARY_PLUS_EXPR:
726 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0));
730 pp_c_unary_expression (pp_c_base (pp), t);
737 ( type-id ) cast-expression */
740 pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
742 switch (TREE_CODE (t))
745 pp_cxx_type_id (pp, TREE_TYPE (t));
746 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
750 pp_c_cast_expression (pp_c_base (pp), t);
757 pm-expression .* cast-expression
758 pm-expression ->* cast-expression */
761 pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t)
763 switch (TREE_CODE (t))
765 /* Handle unfortunate OFFESET_REF overloading here. */
767 if (TYPE_P (TREE_OPERAND (t, 0)))
769 pp_cxx_qualified_id (pp, t);
772 /* Else fall through. */
775 pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
778 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1));
783 pp_cxx_cast_expression (pp, t);
788 /* multiplicative-expression:
790 multiplicative-expression * pm-expression
791 multiplicative-expression / pm-expression
792 multiplicative-expression % pm-expression */
795 pp_cxx_multiplicative_expression (cxx_pretty_printer *pp, tree e)
797 enum tree_code code = TREE_CODE (e);
803 pp_cxx_multiplicative_expression (pp, TREE_OPERAND (e, 0));
805 if (code == MULT_EXPR)
807 else if (code == TRUNC_DIV_EXPR)
812 pp_cxx_pm_expression (pp, TREE_OPERAND (e, 1));
816 pp_cxx_pm_expression (pp, e);
821 /* conditional-expression:
822 logical-or-expression
823 logical-or-expression ? expression : assignment-expression */
826 pp_cxx_conditional_expression (cxx_pretty_printer *pp, tree e)
828 if (TREE_CODE (e) == COND_EXPR)
830 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
834 pp_cxx_expression (pp, TREE_OPERAND (e, 1));
836 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
839 pp_c_logical_or_expression (pp_c_base (pp), e);
842 /* Pretty-print a compound assignment operator token as indicated by T. */
845 pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t)
849 switch (TREE_CODE (t))
872 op = tree_code_name[TREE_CODE (t)];
876 pp_cxx_identifier (pp, op);
880 /* assignment-expression:
881 conditional-expression
882 logical-or-expression assignment-operator assignment-expression
886 throw assignment-expression(opt)
888 assignment-operator: one of
889 = *= /= %= += -= >>= <<= &= ^= |= */
892 pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e)
894 switch (TREE_CODE (e))
898 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
902 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 1));
906 pp_cxx_identifier (pp, "throw");
907 if (TREE_OPERAND (e, 0))
908 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 0));
912 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
913 pp_cxx_assignment_operator (pp, TREE_OPERAND (e, 1));
914 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
918 pp_cxx_conditional_expression (pp, e);
924 pp_cxx_expression (cxx_pretty_printer *pp, tree t)
926 switch (TREE_CODE (t))
931 pp_cxx_constant (pp, t);
935 pp_cxx_unqualified_id (pp, t);
943 pp_cxx_qualified_id (pp, t);
955 case TEMPLATE_TYPE_PARM:
956 case TEMPLATE_PARM_INDEX:
957 case TEMPLATE_TEMPLATE_PARM:
959 pp_cxx_primary_expression (pp, t);
963 case DYNAMIC_CAST_EXPR:
964 case STATIC_CAST_EXPR:
965 case REINTERPRET_CAST_EXPR:
966 case CONST_CAST_EXPR:
970 case EMPTY_CLASS_EXPR:
972 case PSEUDO_DTOR_EXPR:
975 pp_cxx_postfix_expression (pp, t);
980 pp_cxx_new_expression (pp, t);
984 case VEC_DELETE_EXPR:
985 pp_cxx_delete_expression (pp, t);
990 pp_cxx_unary_expression (pp, t);
994 pp_cxx_cast_expression (pp, t);
1000 pp_cxx_pm_expression (pp, t);
1004 case TRUNC_DIV_EXPR:
1005 case TRUNC_MOD_EXPR:
1006 pp_cxx_multiplicative_expression (pp, t);
1010 pp_cxx_conditional_expression (pp, t);
1017 pp_cxx_assignment_expression (pp, t);
1020 case NON_DEPENDENT_EXPR:
1021 case MUST_NOT_THROW_EXPR:
1022 pp_cxx_expression (pp, t);
1025 case EXPR_PACK_EXPANSION:
1026 pp_cxx_expression (pp, PACK_EXPANSION_PATTERN (t));
1027 pp_cxx_identifier (pp, "...");
1030 case NONTYPE_ARGUMENT_PACK:
1032 tree args = ARGUMENT_PACK_ARGS (t);
1033 int i, len = TREE_VEC_LENGTH (args);
1034 for (i = 0; i < len; ++i)
1037 pp_cxx_separate_with (pp, ',');
1038 pp_cxx_expression (pp, TREE_VEC_ELT (args, i));
1044 pp_c_expression (pp_c_base (pp), t);
1052 /* function-specifier:
1058 pp_cxx_function_specifier (cxx_pretty_printer *pp, tree t)
1060 switch (TREE_CODE (t))
1063 if (DECL_VIRTUAL_P (t))
1064 pp_cxx_identifier (pp, "virtual");
1065 else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
1066 pp_cxx_identifier (pp, "explicit");
1068 pp_c_function_specifier (pp_c_base (pp), t);
1075 /* decl-specifier-seq:
1076 decl-specifier-seq(opt) decl-specifier
1079 storage-class-specifier
1086 pp_cxx_decl_specifier_seq (cxx_pretty_printer *pp, tree t)
1088 switch (TREE_CODE (t))
1094 pp_cxx_storage_class_specifier (pp, t);
1095 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1099 pp_cxx_identifier (pp, "typedef");
1100 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1104 if (TYPE_PTRMEMFUNC_P (t))
1106 tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t);
1107 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (pfm)));
1108 pp_cxx_whitespace (pp);
1109 pp_cxx_ptr_operator (pp, t);
1114 /* Constructors don't have return types. And conversion functions
1115 do not have a type-specifier in their return types. */
1116 if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t))
1117 pp_cxx_function_specifier (pp, t);
1118 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
1119 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (t)));
1122 pp_c_declaration_specifiers (pp_c_base (pp), t);
1127 /* simple-type-specifier:
1128 ::(opt) nested-name-specifier(opt) type-name
1129 ::(opt) nested-name-specifier(opt) template(opt) template-id
1143 pp_cxx_simple_type_specifier (cxx_pretty_printer *pp, tree t)
1145 switch (TREE_CODE (t))
1150 pp_cxx_qualified_id (pp, t);
1153 case TEMPLATE_TYPE_PARM:
1154 case TEMPLATE_TEMPLATE_PARM:
1155 case TEMPLATE_PARM_INDEX:
1156 pp_cxx_unqualified_id (pp, t);
1160 pp_cxx_identifier (pp, "typename");
1161 pp_cxx_nested_name_specifier (pp, TYPE_CONTEXT (t));
1162 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
1166 pp_c_type_specifier (pp_c_base (pp), t);
1171 /* type-specifier-seq:
1172 type-specifier type-specifier-seq(opt)
1175 simple-type-specifier
1178 elaborated-type-specifier
1182 pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
1184 switch (TREE_CODE (t))
1187 case TEMPLATE_TYPE_PARM:
1188 case TEMPLATE_TEMPLATE_PARM:
1190 case BOUND_TEMPLATE_TEMPLATE_PARM:
1191 pp_cxx_cv_qualifier_seq (pp, t);
1192 pp_cxx_simple_type_specifier (pp, t);
1196 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
1197 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1198 pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t));
1202 pp_cxx_identifier (pp, "decltype");
1203 pp_cxx_left_paren (pp);
1204 pp_cxx_expression (pp, DECLTYPE_TYPE_EXPR (t));
1205 pp_cxx_right_paren (pp);
1209 if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
1210 pp_c_specifier_qualifier_list (pp_c_base (pp), t);
1215 * cv-qualifier-seq(opt)
1217 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1220 pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
1222 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
1224 switch (TREE_CODE (t))
1226 case REFERENCE_TYPE:
1228 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
1229 || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t)))
1230 pp_cxx_ptr_operator (pp, TREE_TYPE (t));
1231 if (TREE_CODE (t) == POINTER_TYPE)
1234 pp_cxx_cv_qualifier_seq (pp, t);
1241 if (TYPE_PTRMEMFUNC_P (t))
1243 pp_cxx_left_paren (pp);
1244 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t));
1249 if (TYPE_PTR_TO_MEMBER_P (t))
1251 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1252 pp_cxx_left_paren (pp);
1253 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t));
1255 pp_cxx_cv_qualifier_seq (pp, t);
1258 /* else fall through. */
1261 pp_unsupported_tree (pp, t);
1267 pp_cxx_implicit_parameter_type (tree mf)
1269 return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf))));
1273 parameter-declaration:
1274 decl-specifier-seq declarator
1275 decl-specifier-seq declarator = assignment-expression
1276 decl-specifier-seq abstract-declarator(opt)
1277 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1280 pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
1282 pp_cxx_decl_specifier_seq (pp, t);
1284 pp_cxx_abstract_declarator (pp, t);
1286 pp_cxx_declarator (pp, t);
1289 /* parameter-declaration-clause:
1290 parameter-declaration-list(opt) ...(opt)
1291 parameter-declaration-list , ...
1293 parameter-declaration-list:
1294 parameter-declaration
1295 parameter-declaration-list , parameter-declaration */
1298 pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
1300 tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t);
1302 TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
1303 const bool abstract = args == NULL
1304 || pp_c_base (pp)->flags & pp_c_flag_abstract;
1307 /* Skip artificial parameter for nonstatic member functions. */
1308 if (TREE_CODE (t) == METHOD_TYPE)
1309 types = TREE_CHAIN (types);
1311 pp_cxx_left_paren (pp);
1312 for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
1315 pp_cxx_separate_with (pp, ',');
1317 pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
1318 if (!abstract && pp_c_base (pp)->flags & pp_cxx_flag_default_argument)
1320 pp_cxx_whitespace (pp);
1322 pp_cxx_whitespace (pp);
1323 pp_cxx_assignment_expression (pp, TREE_PURPOSE (types));
1326 pp_cxx_right_paren (pp);
1329 /* exception-specification:
1330 throw ( type-id-list(opt) )
1334 type-id-list , type-id */
1337 pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
1339 tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
1340 bool need_comma = false;
1342 if (!TYPE_NOTHROW_P (t) && ex_spec == NULL)
1344 pp_cxx_identifier (pp, "throw");
1345 pp_cxx_left_paren (pp);
1346 for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
1348 tree type = TREE_VALUE (ex_spec);
1349 tree argpack = NULL_TREE;
1352 if (ARGUMENT_PACK_P (type))
1354 argpack = ARGUMENT_PACK_ARGS (type);
1355 len = TREE_VEC_LENGTH (argpack);
1358 for (i = 0; i < len; ++i)
1361 type = TREE_VEC_ELT (argpack, i);
1364 pp_cxx_separate_with (pp, ',');
1368 pp_cxx_type_id (pp, type);
1371 pp_cxx_right_paren (pp);
1374 /* direct-declarator:
1376 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1377 exception-specification(opt)
1378 direct-declaration [ constant-expression(opt) ]
1382 pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t)
1384 switch (TREE_CODE (t))
1392 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1394 if ((TREE_CODE (t) == PARM_DECL && FUNCTION_PARAMETER_PACK_P (t))
1395 || template_parameter_pack_p (t))
1396 /* A function parameter pack or non-type template
1398 pp_cxx_identifier (pp, "...");
1400 pp_cxx_id_expression (pp, DECL_NAME (t));
1402 pp_cxx_abstract_declarator (pp, TREE_TYPE (t));
1406 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
1407 pp_cxx_id_expression (pp, t);
1408 pp_cxx_parameter_declaration_clause (pp, t);
1410 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
1412 pp_base (pp)->padding = pp_before;
1413 pp_cxx_cv_qualifier_seq (pp, pp_cxx_implicit_parameter_type (t));
1416 pp_cxx_exception_specification (pp, TREE_TYPE (t));
1421 case TEMPLATE_TYPE_PARM:
1422 case TEMPLATE_PARM_INDEX:
1423 case TEMPLATE_TEMPLATE_PARM:
1427 pp_c_direct_declarator (pp_c_base (pp), t);
1434 ptr-operator declarator */
1437 pp_cxx_declarator (cxx_pretty_printer *pp, tree t)
1439 pp_cxx_direct_declarator (pp, t);
1442 /* ctor-initializer:
1443 : mem-initializer-list
1445 mem-initializer-list:
1447 mem-initializer , mem-initializer-list
1450 mem-initializer-id ( expression-list(opt) )
1453 ::(opt) nested-name-specifier(opt) class-name
1457 pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
1459 t = TREE_OPERAND (t, 0);
1460 pp_cxx_whitespace (pp);
1462 pp_cxx_whitespace (pp);
1463 for (; t; t = TREE_CHAIN (t))
1465 tree purpose = TREE_PURPOSE (t);
1466 bool is_pack = PACK_EXPANSION_P (purpose);
1469 pp_cxx_primary_expression (pp, PACK_EXPANSION_PATTERN (purpose));
1471 pp_cxx_primary_expression (pp, purpose);
1472 pp_cxx_call_argument_list (pp, TREE_VALUE (t));
1474 pp_cxx_identifier (pp, "...");
1476 pp_cxx_separate_with (pp, ',');
1480 /* function-definition:
1481 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1482 decl-specifier-seq(opt) declarator function-try-block */
1485 pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
1487 tree saved_scope = pp->enclosing_scope;
1488 pp_cxx_decl_specifier_seq (pp, t);
1489 pp_cxx_declarator (pp, t);
1490 pp_needs_newline (pp) = true;
1491 pp->enclosing_scope = DECL_CONTEXT (t);
1492 if (DECL_SAVED_TREE (t))
1493 pp_cxx_statement (pp, DECL_SAVED_TREE (t));
1496 pp_cxx_semicolon (pp);
1497 pp_needs_newline (pp) = true;
1500 pp->enclosing_scope = saved_scope;
1503 /* abstract-declarator:
1504 ptr-operator abstract-declarator(opt)
1505 direct-abstract-declarator */
1508 pp_cxx_abstract_declarator (cxx_pretty_printer *pp, tree t)
1510 if (TYPE_PTRMEM_P (t) || TYPE_PTRMEMFUNC_P (t))
1511 pp_cxx_right_paren (pp);
1512 else if (POINTER_TYPE_P (t))
1514 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
1515 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1516 pp_cxx_right_paren (pp);
1519 pp_cxx_direct_abstract_declarator (pp, t);
1522 /* direct-abstract-declarator:
1523 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1524 cv-qualifier-seq(opt) exception-specification(opt)
1525 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1526 ( abstract-declarator ) */
1529 pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
1531 switch (TREE_CODE (t))
1533 case REFERENCE_TYPE:
1534 pp_cxx_abstract_declarator (pp, t);
1538 if (TYPE_PTRMEMFUNC_P (t))
1539 pp_cxx_direct_abstract_declarator (pp, TYPE_PTRMEMFUNC_FN_TYPE (t));
1544 pp_cxx_parameter_declaration_clause (pp, t);
1545 pp_cxx_direct_abstract_declarator (pp, TREE_TYPE (t));
1546 if (TREE_CODE (t) == METHOD_TYPE)
1548 pp_base (pp)->padding = pp_before;
1549 pp_cxx_cv_qualifier_seq
1550 (pp, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))));
1552 pp_cxx_exception_specification (pp, t);
1556 case TEMPLATE_TYPE_PARM:
1557 case TEMPLATE_TEMPLATE_PARM:
1558 case BOUND_TEMPLATE_TEMPLATE_PARM:
1559 case UNBOUND_CLASS_TEMPLATE:
1563 pp_c_direct_abstract_declarator (pp_c_base (pp), t);
1569 type-specifier-seq abstract-declarator(opt) */
1572 pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
1574 pp_flags saved_flags = pp_c_base (pp)->flags;
1575 pp_c_base (pp)->flags |= pp_c_flag_abstract;
1577 switch (TREE_CODE (t))
1584 case BOUND_TEMPLATE_TEMPLATE_PARM:
1585 case UNBOUND_CLASS_TEMPLATE:
1586 case TEMPLATE_TEMPLATE_PARM:
1587 case TEMPLATE_TYPE_PARM:
1588 case TEMPLATE_PARM_INDEX:
1592 case TEMPLATE_ID_EXPR:
1593 pp_cxx_type_specifier_seq (pp, t);
1596 case TYPE_PACK_EXPANSION:
1597 pp_cxx_type_id (pp, PACK_EXPANSION_PATTERN (t));
1598 pp_cxx_identifier (pp, "...");
1602 pp_c_type_id (pp_c_base (pp), t);
1606 pp_c_base (pp)->flags = saved_flags;
1609 /* template-argument-list:
1610 template-argument ...(opt)
1611 template-argument-list, template-argument ...(opt)
1614 assignment-expression
1619 pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
1622 bool need_comma = false;
1626 for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
1628 tree arg = TREE_VEC_ELT (t, i);
1629 tree argpack = NULL_TREE;
1632 if (ARGUMENT_PACK_P (arg))
1634 argpack = ARGUMENT_PACK_ARGS (arg);
1635 len = TREE_VEC_LENGTH (argpack);
1638 for (idx = 0; idx < len; idx++)
1641 arg = TREE_VEC_ELT (argpack, idx);
1644 pp_cxx_separate_with (pp, ',');
1648 if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
1649 && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
1650 pp_cxx_type_id (pp, arg);
1652 pp_cxx_expression (pp, arg);
1659 pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
1661 t = DECL_EXPR_DECL (t);
1662 pp_cxx_type_specifier_seq (pp, t);
1664 pp_cxx_abstract_declarator (pp, t);
1666 pp_cxx_declarator (pp, t);
1672 pp_cxx_statement (cxx_pretty_printer *pp, tree t)
1674 switch (TREE_CODE (t))
1676 case CTOR_INITIALIZER:
1677 pp_cxx_ctor_initializer (pp, t);
1681 pp_cxx_identifier (pp, "using");
1682 pp_cxx_identifier (pp, "namespace");
1683 if (DECL_CONTEXT (t))
1684 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1685 pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t));
1689 pp_cxx_identifier (pp, "using");
1690 pp_cxx_nested_name_specifier (pp, USING_DECL_SCOPE (t));
1691 pp_cxx_unqualified_id (pp, DECL_NAME (t));
1698 try compound-statement handler-seq */
1700 pp_maybe_newline_and_indent (pp, 0);
1701 pp_cxx_identifier (pp, "try");
1702 pp_newline_and_indent (pp, 3);
1703 pp_cxx_statement (pp, TRY_STMTS (t));
1704 pp_newline_and_indent (pp, -3);
1708 pp_cxx_statement (pp, TRY_HANDLERS (t));
1713 handler handler-seq(opt)
1716 catch ( exception-declaration ) compound-statement
1718 exception-declaration:
1719 type-specifier-seq declarator
1720 type-specifier-seq abstract-declarator
1723 pp_cxx_identifier (pp, "catch");
1724 pp_cxx_left_paren (pp);
1725 pp_cxx_exception_declaration (pp, HANDLER_PARMS (t));
1726 pp_cxx_right_paren (pp);
1727 pp_indentation (pp) += 3;
1728 pp_needs_newline (pp) = true;
1729 pp_cxx_statement (pp, HANDLER_BODY (t));
1730 pp_indentation (pp) -= 3;
1731 pp_needs_newline (pp) = true;
1734 /* selection-statement:
1735 if ( expression ) statement
1736 if ( expression ) statement else statement */
1738 pp_cxx_identifier (pp, "if");
1739 pp_cxx_whitespace (pp);
1740 pp_cxx_left_paren (pp);
1741 pp_cxx_expression (pp, IF_COND (t));
1742 pp_cxx_right_paren (pp);
1743 pp_newline_and_indent (pp, 2);
1744 pp_cxx_statement (pp, THEN_CLAUSE (t));
1745 pp_newline_and_indent (pp, -2);
1746 if (ELSE_CLAUSE (t))
1748 tree else_clause = ELSE_CLAUSE (t);
1749 pp_cxx_identifier (pp, "else");
1750 if (TREE_CODE (else_clause) == IF_STMT)
1751 pp_cxx_whitespace (pp);
1753 pp_newline_and_indent (pp, 2);
1754 pp_cxx_statement (pp, else_clause);
1755 if (TREE_CODE (else_clause) != IF_STMT)
1756 pp_newline_and_indent (pp, -2);
1761 pp_cxx_identifier (pp, "switch");
1763 pp_cxx_left_paren (pp);
1764 pp_cxx_expression (pp, SWITCH_STMT_COND (t));
1765 pp_cxx_right_paren (pp);
1766 pp_indentation (pp) += 3;
1767 pp_needs_newline (pp) = true;
1768 pp_cxx_statement (pp, SWITCH_STMT_BODY (t));
1769 pp_newline_and_indent (pp, -3);
1772 /* iteration-statement:
1773 while ( expression ) statement
1774 do statement while ( expression ) ;
1775 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1776 for ( declaration expression(opt) ; expression(opt) ) statement */
1778 pp_cxx_identifier (pp, "while");
1780 pp_cxx_left_paren (pp);
1781 pp_cxx_expression (pp, WHILE_COND (t));
1782 pp_cxx_right_paren (pp);
1783 pp_newline_and_indent (pp, 3);
1784 pp_cxx_statement (pp, WHILE_BODY (t));
1785 pp_indentation (pp) -= 3;
1786 pp_needs_newline (pp) = true;
1790 pp_cxx_identifier (pp, "do");
1791 pp_newline_and_indent (pp, 3);
1792 pp_cxx_statement (pp, DO_BODY (t));
1793 pp_newline_and_indent (pp, -3);
1794 pp_cxx_identifier (pp, "while");
1796 pp_cxx_left_paren (pp);
1797 pp_cxx_expression (pp, DO_COND (t));
1798 pp_cxx_right_paren (pp);
1799 pp_cxx_semicolon (pp);
1800 pp_needs_newline (pp) = true;
1804 pp_cxx_identifier (pp, "for");
1806 pp_cxx_left_paren (pp);
1807 if (FOR_INIT_STMT (t))
1808 pp_cxx_statement (pp, FOR_INIT_STMT (t));
1810 pp_cxx_semicolon (pp);
1811 pp_needs_newline (pp) = false;
1812 pp_cxx_whitespace (pp);
1814 pp_cxx_expression (pp, FOR_COND (t));
1815 pp_cxx_semicolon (pp);
1816 pp_needs_newline (pp) = false;
1817 pp_cxx_whitespace (pp);
1819 pp_cxx_expression (pp, FOR_EXPR (t));
1820 pp_cxx_right_paren (pp);
1821 pp_newline_and_indent (pp, 3);
1822 pp_cxx_statement (pp, FOR_BODY (t));
1823 pp_indentation (pp) -= 3;
1824 pp_needs_newline (pp) = true;
1830 return expression(opt) ; */
1833 pp_identifier (pp, TREE_CODE (t) == BREAK_STMT ? "break" : "continue");
1834 pp_cxx_semicolon (pp);
1835 pp_needs_newline (pp) = true;
1838 /* expression-statement:
1839 expression(opt) ; */
1841 pp_cxx_expression (pp, EXPR_STMT_EXPR (t));
1842 pp_cxx_semicolon (pp);
1843 pp_needs_newline (pp) = true;
1847 pp_cxx_identifier (pp, "try");
1848 pp_newline_and_indent (pp, 2);
1849 pp_cxx_statement (pp, CLEANUP_BODY (t));
1850 pp_newline_and_indent (pp, -2);
1851 pp_cxx_identifier (pp, CLEANUP_EH_ONLY (t) ? "catch" : "finally");
1852 pp_newline_and_indent (pp, 2);
1853 pp_cxx_statement (pp, CLEANUP_EXPR (t));
1854 pp_newline_and_indent (pp, -2);
1858 pp_cxx_declaration (pp, t);
1862 pp_c_statement (pp_c_base (pp), t);
1867 /* original-namespace-definition:
1868 namespace identifier { namespace-body }
1870 As an edge case, we also handle unnamed namespace definition here. */
1873 pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t)
1875 pp_cxx_identifier (pp, "namespace");
1876 if (DECL_CONTEXT (t))
1877 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1879 pp_cxx_unqualified_id (pp, t);
1880 pp_cxx_whitespace (pp);
1881 pp_cxx_left_brace (pp);
1882 /* We do not print the namespace-body. */
1883 pp_cxx_whitespace (pp);
1884 pp_cxx_right_brace (pp);
1890 namespace-alias-definition:
1891 namespace identifier = qualified-namespace-specifier ;
1893 qualified-namespace-specifier:
1894 ::(opt) nested-name-specifier(opt) namespace-name */
1897 pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t)
1899 pp_cxx_identifier (pp, "namespace");
1900 if (DECL_CONTEXT (t))
1901 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1902 pp_cxx_unqualified_id (pp, t);
1903 pp_cxx_whitespace (pp);
1905 pp_cxx_whitespace (pp);
1906 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)))
1907 pp_cxx_nested_name_specifier (pp,
1908 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)));
1909 pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t));
1910 pp_cxx_semicolon (pp);
1913 /* simple-declaration:
1914 decl-specifier-seq(opt) init-declarator-list(opt) */
1917 pp_cxx_simple_declaration (cxx_pretty_printer *pp, tree t)
1919 pp_cxx_decl_specifier_seq (pp, t);
1920 pp_cxx_init_declarator (pp, t);
1921 pp_cxx_semicolon (pp);
1922 pp_needs_newline (pp) = true;
1926 template-parameter-list:
1928 template-parameter-list , template-parameter */
1931 pp_cxx_template_parameter_list (cxx_pretty_printer *pp, tree t)
1933 const int n = TREE_VEC_LENGTH (t);
1935 for (i = 0; i < n; ++i)
1938 pp_cxx_separate_with (pp, ',');
1939 pp_cxx_template_parameter (pp, TREE_VEC_ELT (t, i));
1943 /* template-parameter:
1945 parameter-declaration
1948 class ...(opt) identifier(opt)
1949 class identifier(opt) = type-id
1950 typename identifier(opt)
1951 typename ...(opt) identifier(opt) = type-id
1952 template < template-parameter-list > class ...(opt) identifier(opt)
1953 template < template-parameter-list > class identifier(opt) = template-name */
1956 pp_cxx_template_parameter (cxx_pretty_printer *pp, tree t)
1958 tree parameter = TREE_VALUE (t);
1959 switch (TREE_CODE (parameter))
1962 pp_cxx_identifier (pp, "class");
1963 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t)))
1964 pp_cxx_identifier (pp, "...");
1965 if (DECL_NAME (parameter))
1966 pp_cxx_tree_identifier (pp, DECL_NAME (parameter));
1967 /* FIXME: Chech if we should print also default argument. */
1971 pp_cxx_parameter_declaration (pp, parameter);
1978 pp_unsupported_tree (pp, t);
1983 /* Pretty-print a template parameter in the canonical form
1984 "template-parameter-<level>-<position in parameter list>". */
1987 pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm)
1989 const enum tree_code code = TREE_CODE (parm);
1991 /* Brings type template parameters to the canonical forms. */
1992 if (code == TEMPLATE_TYPE_PARM || code == TEMPLATE_TEMPLATE_PARM
1993 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
1994 parm = TEMPLATE_TYPE_PARM_INDEX (parm);
1996 pp_cxx_begin_template_argument_list (pp);
1997 pp_cxx_identifier (pp, "template-parameter-");
1998 pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm));
2000 pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1);
2001 pp_cxx_end_template_argument_list (pp);
2005 template-declaration:
2006 export(opt) template < template-parameter-list > declaration */
2009 pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t)
2011 tree tmpl = most_general_template (t);
2015 pp_maybe_newline_and_indent (pp, 0);
2016 for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level))
2018 pp_cxx_identifier (pp, "template");
2019 pp_cxx_begin_template_argument_list (pp);
2020 pp_cxx_template_parameter_list (pp, TREE_VALUE (level));
2021 pp_cxx_end_template_argument_list (pp);
2022 pp_newline_and_indent (pp, 3);
2025 if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t))
2026 pp_cxx_function_definition (pp, t);
2028 pp_cxx_simple_declaration (pp, t);
2032 pp_cxx_explicit_specialization (cxx_pretty_printer *pp, tree t)
2034 pp_unsupported_tree (pp, t);
2038 pp_cxx_explicit_instantiation (cxx_pretty_printer *pp, tree t)
2040 pp_unsupported_tree (pp, t);
2047 template-declaration
2048 explicit-instantiation
2049 explicit-specialization
2050 linkage-specification
2051 namespace-definition
2056 namespace-alias-definition
2059 static_assert-declaration */
2061 pp_cxx_declaration (cxx_pretty_printer *pp, tree t)
2063 if (TREE_CODE (t) == STATIC_ASSERT)
2065 pp_cxx_identifier (pp, "static_assert");
2066 pp_cxx_left_paren (pp);
2067 pp_cxx_expression (pp, STATIC_ASSERT_CONDITION (t));
2068 pp_cxx_separate_with (pp, ',');
2069 pp_cxx_expression (pp, STATIC_ASSERT_MESSAGE (t));
2070 pp_cxx_right_paren (pp);
2072 else if (!DECL_LANG_SPECIFIC (t))
2073 pp_cxx_simple_declaration (pp, t);
2074 else if (DECL_USE_TEMPLATE (t))
2075 switch (DECL_USE_TEMPLATE (t))
2078 pp_cxx_template_declaration (pp, t);
2082 pp_cxx_explicit_specialization (pp, t);
2086 pp_cxx_explicit_instantiation (pp, t);
2092 else switch (TREE_CODE (t))
2096 pp_cxx_simple_declaration (pp, t);
2100 if (DECL_SAVED_TREE (t))
2101 pp_cxx_function_definition (pp, t);
2103 pp_cxx_simple_declaration (pp, t);
2106 case NAMESPACE_DECL:
2107 if (DECL_NAMESPACE_ALIAS (t))
2108 pp_cxx_namespace_alias_definition (pp, t);
2110 pp_cxx_original_namespace_definition (pp, t);
2114 pp_unsupported_tree (pp, t);
2120 typedef c_pretty_print_fn pp_fun;
2122 /* Initialization of a C++ pretty-printer object. */
2125 pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
2127 pp_c_pretty_printer_init (pp_c_base (pp));
2128 pp_set_line_maximum_length (pp, 0);
2130 pp->c_base.declaration = (pp_fun) pp_cxx_declaration;
2131 pp->c_base.declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
2132 pp->c_base.function_specifier = (pp_fun) pp_cxx_function_specifier;
2133 pp->c_base.type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
2134 pp->c_base.declarator = (pp_fun) pp_cxx_declarator;
2135 pp->c_base.direct_declarator = (pp_fun) pp_cxx_direct_declarator;
2136 pp->c_base.parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
2137 pp->c_base.type_id = (pp_fun) pp_cxx_type_id;
2138 pp->c_base.abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
2139 pp->c_base.direct_abstract_declarator =
2140 (pp_fun) pp_cxx_direct_abstract_declarator;
2141 pp->c_base.simple_type_specifier = (pp_fun)pp_cxx_simple_type_specifier;
2143 /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
2145 pp->c_base.constant = (pp_fun) pp_cxx_constant;
2146 pp->c_base.id_expression = (pp_fun) pp_cxx_id_expression;
2147 pp->c_base.primary_expression = (pp_fun) pp_cxx_primary_expression;
2148 pp->c_base.postfix_expression = (pp_fun) pp_cxx_postfix_expression;
2149 pp->c_base.unary_expression = (pp_fun) pp_cxx_unary_expression;
2150 pp->c_base.multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
2151 pp->c_base.conditional_expression = (pp_fun) pp_cxx_conditional_expression;
2152 pp->c_base.assignment_expression = (pp_fun) pp_cxx_assignment_expression;
2153 pp->c_base.expression = (pp_fun) pp_cxx_expression;
2154 pp->enclosing_scope = global_namespace;