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));
193 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
196 case TEMPLATE_TYPE_PARM:
197 case TEMPLATE_TEMPLATE_PARM:
198 if (TYPE_IDENTIFIER (t))
199 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
201 pp_cxx_canonical_template_parameter (pp, t);
204 case TEMPLATE_PARM_INDEX:
205 pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t));
209 case UNBOUND_CLASS_TEMPLATE:
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))
357 pp_cxx_constant (pp, t);
361 t = BASELINK_FUNCTIONS (t);
369 pp_cxx_id_expression (pp, t);
373 case TEMPLATE_TYPE_PARM:
374 case TEMPLATE_TEMPLATE_PARM:
375 case TEMPLATE_PARM_INDEX:
376 pp_cxx_unqualified_id (pp, t);
380 pp_cxx_left_paren (pp);
381 pp_cxx_statement (pp, STMT_EXPR_STMT (t));
382 pp_cxx_right_paren (pp);
386 pp_c_primary_expression (pp_c_base (pp), t);
391 /* postfix-expression:
393 postfix-expression [ expression ]
394 postfix-expression ( expression-list(opt) )
395 simple-type-specifier ( expression-list(opt) )
396 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
397 typename ::(opt) nested-name-specifier template(opt)
398 template-id ( expression-list(opt) )
399 postfix-expression . template(opt) ::(opt) id-expression
400 postfix-expression -> template(opt) ::(opt) id-expression
401 postfix-expression . pseudo-destructor-name
402 postfix-expression -> pseudo-destructor-name
403 postfix-expression ++
404 postfix-expression --
405 dynamic_cast < type-id > ( expression )
406 static_cast < type-id > ( expression )
407 reinterpret_cast < type-id > ( expression )
408 const_cast < type-id > ( expression )
409 typeid ( expression )
410 typeif ( type-id ) */
413 pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t)
415 enum tree_code code = TREE_CODE (t);
422 tree fun = (code == AGGR_INIT_EXPR ? AGGR_INIT_EXPR_FN (t)
424 tree saved_scope = pp->enclosing_scope;
425 bool skipfirst = false;
428 if (TREE_CODE (fun) == ADDR_EXPR)
429 fun = TREE_OPERAND (fun, 0);
431 /* In templates, where there is no way to tell whether a given
432 call uses an actual member function. So the parser builds
433 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
434 instantiation time. */
435 if (TREE_CODE (fun) != FUNCTION_DECL)
437 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun))
439 tree object = (code == AGGR_INIT_EXPR
440 ? (AGGR_INIT_VIA_CTOR_P (t)
441 ? AGGR_INIT_EXPR_SLOT (t)
442 : AGGR_INIT_EXPR_ARG (t, 0))
443 : CALL_EXPR_ARG (t, 0));
445 while (TREE_CODE (object) == NOP_EXPR)
446 object = TREE_OPERAND (object, 0);
448 if (TREE_CODE (object) == ADDR_EXPR)
449 object = TREE_OPERAND (object, 0);
451 if (TREE_CODE (TREE_TYPE (object)) != POINTER_TYPE)
453 pp_cxx_postfix_expression (pp, object);
458 pp_cxx_postfix_expression (pp, object);
462 pp->enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
465 pp_cxx_postfix_expression (pp, fun);
466 pp->enclosing_scope = saved_scope;
467 pp_cxx_left_paren (pp);
468 if (code == AGGR_INIT_EXPR)
470 aggr_init_expr_arg_iterator iter;
471 FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t)
477 pp_cxx_expression (pp, arg);
478 if (more_aggr_init_expr_args_p (&iter))
479 pp_cxx_separate_with (pp, ',');
485 call_expr_arg_iterator iter;
486 FOR_EACH_CALL_EXPR_ARG (arg, iter, t)
492 pp_cxx_expression (pp, arg);
493 if (more_call_expr_args_p (&iter))
494 pp_cxx_separate_with (pp, ',');
498 pp_cxx_right_paren (pp);
500 if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
502 pp_cxx_separate_with (pp, ',');
503 pp_cxx_postfix_expression (pp, AGGR_INIT_EXPR_SLOT (t));
516 pp_cxx_primary_expression (pp, t);
519 case DYNAMIC_CAST_EXPR:
520 case STATIC_CAST_EXPR:
521 case REINTERPRET_CAST_EXPR:
522 case CONST_CAST_EXPR:
523 if (code == DYNAMIC_CAST_EXPR)
524 pp_cxx_identifier (pp, "dynamic_cast");
525 else if (code == STATIC_CAST_EXPR)
526 pp_cxx_identifier (pp, "static_cast");
527 else if (code == REINTERPRET_CAST_EXPR)
528 pp_cxx_identifier (pp, "reinterpret_cast");
530 pp_cxx_identifier (pp, "const_cast");
531 pp_cxx_begin_template_argument_list (pp);
532 pp_cxx_type_id (pp, TREE_TYPE (t));
533 pp_cxx_end_template_argument_list (pp);
535 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
539 case EMPTY_CLASS_EXPR:
540 pp_cxx_type_id (pp, TREE_TYPE (t));
546 t = TREE_OPERAND (t, 0);
547 pp_cxx_identifier (pp, "typeid");
550 pp_cxx_type_id (pp, t);
552 pp_cxx_expression (pp, t);
556 case PSEUDO_DTOR_EXPR:
557 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
559 pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1));
560 pp_cxx_colon_colon (pp);
562 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2));
566 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
571 pp_c_postfix_expression (pp_c_base (pp), t);
577 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
578 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
584 type-specifier-seq new-declarator(opt)
587 ptr-operator new-declarator(opt)
588 direct-new-declarator
590 direct-new-declarator
592 direct-new-declarator [ constant-expression ]
595 ( expression-list(opt) ) */
598 pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
600 enum tree_code code = TREE_CODE (t);
605 if (NEW_EXPR_USE_GLOBAL (t))
606 pp_cxx_colon_colon (pp);
607 pp_cxx_identifier (pp, "new");
608 if (TREE_OPERAND (t, 0))
610 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
613 /* FIXME: array-types are built with one more element. */
614 pp_cxx_type_id (pp, TREE_OPERAND (t, 1));
615 if (TREE_OPERAND (t, 2))
618 t = TREE_OPERAND (t, 2);
619 if (TREE_CODE (t) == TREE_LIST)
620 pp_c_expression_list (pp_c_base (pp), t);
621 else if (t == void_zero_node)
622 ; /* OK, empty initializer list. */
624 pp_cxx_expression (pp, t);
630 pp_unsupported_tree (pp, t);
634 /* delete-expression:
635 ::(opt) delete cast-expression
636 ::(opt) delete [ ] cast-expression */
639 pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
641 enum tree_code code = TREE_CODE (t);
645 case VEC_DELETE_EXPR:
646 if (DELETE_EXPR_USE_GLOBAL (t))
647 pp_cxx_colon_colon (pp);
648 pp_cxx_identifier (pp, "delete");
649 if (code == VEC_DELETE_EXPR)
651 pp_left_bracket (pp);
652 pp_right_bracket (pp);
654 pp_c_cast_expression (pp_c_base (pp), TREE_OPERAND (t, 0));
658 pp_unsupported_tree (pp, t);
666 unary-operator cast-expression
667 sizeof unary-expression
669 sizeof ... ( identifier )
673 unary-operator: one of
677 __alignof__ unary-expression
678 __alignof__ ( type-id ) */
681 pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
683 enum tree_code code = TREE_CODE (t);
688 pp_cxx_new_expression (pp, t);
692 case VEC_DELETE_EXPR:
693 pp_cxx_delete_expression (pp, t);
697 if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
699 pp_cxx_identifier (pp, "sizeof");
700 pp_cxx_identifier (pp, "...");
701 pp_cxx_whitespace (pp);
702 pp_cxx_left_paren (pp);
703 if (TYPE_P (TREE_OPERAND (t, 0)))
704 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
706 pp_unary_expression (pp, TREE_OPERAND (t, 0));
707 pp_cxx_right_paren (pp);
713 pp_cxx_identifier (pp, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
714 pp_cxx_whitespace (pp);
715 if (TYPE_P (TREE_OPERAND (t, 0)))
717 pp_cxx_left_paren (pp);
718 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
719 pp_cxx_right_paren (pp);
722 pp_unary_expression (pp, TREE_OPERAND (t, 0));
725 case UNARY_PLUS_EXPR:
727 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0));
731 pp_c_unary_expression (pp_c_base (pp), t);
738 ( type-id ) cast-expression */
741 pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
743 switch (TREE_CODE (t))
746 pp_cxx_type_id (pp, TREE_TYPE (t));
747 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
751 pp_c_cast_expression (pp_c_base (pp), t);
758 pm-expression .* cast-expression
759 pm-expression ->* cast-expression */
762 pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t)
764 switch (TREE_CODE (t))
766 /* Handle unfortunate OFFESET_REF overloading here. */
768 if (TYPE_P (TREE_OPERAND (t, 0)))
770 pp_cxx_qualified_id (pp, t);
773 /* Else fall through. */
776 pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
779 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1));
784 pp_cxx_cast_expression (pp, t);
789 /* multiplicative-expression:
791 multiplicative-expression * pm-expression
792 multiplicative-expression / pm-expression
793 multiplicative-expression % pm-expression */
796 pp_cxx_multiplicative_expression (cxx_pretty_printer *pp, tree e)
798 enum tree_code code = TREE_CODE (e);
804 pp_cxx_multiplicative_expression (pp, TREE_OPERAND (e, 0));
806 if (code == MULT_EXPR)
808 else if (code == TRUNC_DIV_EXPR)
813 pp_cxx_pm_expression (pp, TREE_OPERAND (e, 1));
817 pp_cxx_pm_expression (pp, e);
822 /* conditional-expression:
823 logical-or-expression
824 logical-or-expression ? expression : assignment-expression */
827 pp_cxx_conditional_expression (cxx_pretty_printer *pp, tree e)
829 if (TREE_CODE (e) == COND_EXPR)
831 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
835 pp_cxx_expression (pp, TREE_OPERAND (e, 1));
837 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
840 pp_c_logical_or_expression (pp_c_base (pp), e);
843 /* Pretty-print a compound assignment operator token as indicated by T. */
846 pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t)
850 switch (TREE_CODE (t))
873 op = tree_code_name[TREE_CODE (t)];
877 pp_cxx_identifier (pp, op);
881 /* assignment-expression:
882 conditional-expression
883 logical-or-expression assignment-operator assignment-expression
887 throw assignment-expression(opt)
889 assignment-operator: one of
890 = *= /= %= += -= >>= <<= &= ^= |= */
893 pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e)
895 switch (TREE_CODE (e))
899 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
903 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 1));
907 pp_cxx_identifier (pp, "throw");
908 if (TREE_OPERAND (e, 0))
909 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 0));
913 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
914 pp_cxx_assignment_operator (pp, TREE_OPERAND (e, 1));
915 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
919 pp_cxx_conditional_expression (pp, e);
925 pp_cxx_expression (cxx_pretty_printer *pp, tree t)
927 switch (TREE_CODE (t))
933 pp_cxx_constant (pp, t);
937 pp_cxx_unqualified_id (pp, t);
945 pp_cxx_qualified_id (pp, t);
957 case TEMPLATE_TYPE_PARM:
958 case TEMPLATE_PARM_INDEX:
959 case TEMPLATE_TEMPLATE_PARM:
961 pp_cxx_primary_expression (pp, t);
965 case DYNAMIC_CAST_EXPR:
966 case STATIC_CAST_EXPR:
967 case REINTERPRET_CAST_EXPR:
968 case CONST_CAST_EXPR:
972 case EMPTY_CLASS_EXPR:
974 case PSEUDO_DTOR_EXPR:
977 pp_cxx_postfix_expression (pp, t);
982 pp_cxx_new_expression (pp, t);
986 case VEC_DELETE_EXPR:
987 pp_cxx_delete_expression (pp, t);
992 pp_cxx_unary_expression (pp, t);
996 pp_cxx_cast_expression (pp, t);
1002 pp_cxx_pm_expression (pp, t);
1006 case TRUNC_DIV_EXPR:
1007 case TRUNC_MOD_EXPR:
1008 pp_cxx_multiplicative_expression (pp, t);
1012 pp_cxx_conditional_expression (pp, t);
1019 pp_cxx_assignment_expression (pp, t);
1022 case NON_DEPENDENT_EXPR:
1023 case MUST_NOT_THROW_EXPR:
1024 pp_cxx_expression (pp, t);
1027 case EXPR_PACK_EXPANSION:
1028 pp_cxx_expression (pp, PACK_EXPANSION_PATTERN (t));
1029 pp_cxx_identifier (pp, "...");
1032 case NONTYPE_ARGUMENT_PACK:
1034 tree args = ARGUMENT_PACK_ARGS (t);
1035 int i, len = TREE_VEC_LENGTH (args);
1036 for (i = 0; i < len; ++i)
1039 pp_cxx_separate_with (pp, ',');
1040 pp_cxx_expression (pp, TREE_VEC_ELT (args, i));
1046 pp_c_expression (pp_c_base (pp), t);
1054 /* function-specifier:
1060 pp_cxx_function_specifier (cxx_pretty_printer *pp, tree t)
1062 switch (TREE_CODE (t))
1065 if (DECL_VIRTUAL_P (t))
1066 pp_cxx_identifier (pp, "virtual");
1067 else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
1068 pp_cxx_identifier (pp, "explicit");
1070 pp_c_function_specifier (pp_c_base (pp), t);
1077 /* decl-specifier-seq:
1078 decl-specifier-seq(opt) decl-specifier
1081 storage-class-specifier
1088 pp_cxx_decl_specifier_seq (cxx_pretty_printer *pp, tree t)
1090 switch (TREE_CODE (t))
1096 pp_cxx_storage_class_specifier (pp, t);
1097 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1101 pp_cxx_identifier (pp, "typedef");
1102 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1106 if (TYPE_PTRMEMFUNC_P (t))
1108 tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t);
1109 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (pfm)));
1110 pp_cxx_whitespace (pp);
1111 pp_cxx_ptr_operator (pp, t);
1116 /* Constructors don't have return types. And conversion functions
1117 do not have a type-specifier in their return types. */
1118 if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t))
1119 pp_cxx_function_specifier (pp, t);
1120 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
1121 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (t)));
1124 pp_c_declaration_specifiers (pp_c_base (pp), t);
1129 /* simple-type-specifier:
1130 ::(opt) nested-name-specifier(opt) type-name
1131 ::(opt) nested-name-specifier(opt) template(opt) template-id
1145 pp_cxx_simple_type_specifier (cxx_pretty_printer *pp, tree t)
1147 switch (TREE_CODE (t))
1152 pp_cxx_qualified_id (pp, t);
1155 case TEMPLATE_TYPE_PARM:
1156 case TEMPLATE_TEMPLATE_PARM:
1157 case TEMPLATE_PARM_INDEX:
1158 pp_cxx_unqualified_id (pp, t);
1162 pp_cxx_identifier (pp, "typename");
1163 pp_cxx_nested_name_specifier (pp, TYPE_CONTEXT (t));
1164 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
1168 pp_c_type_specifier (pp_c_base (pp), t);
1173 /* type-specifier-seq:
1174 type-specifier type-specifier-seq(opt)
1177 simple-type-specifier
1180 elaborated-type-specifier
1184 pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
1186 switch (TREE_CODE (t))
1189 case TEMPLATE_TYPE_PARM:
1190 case TEMPLATE_TEMPLATE_PARM:
1192 case BOUND_TEMPLATE_TEMPLATE_PARM:
1193 pp_cxx_cv_qualifier_seq (pp, t);
1194 pp_cxx_simple_type_specifier (pp, t);
1198 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
1199 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1200 pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t));
1204 pp_cxx_identifier (pp, "decltype");
1205 pp_cxx_left_paren (pp);
1206 pp_cxx_expression (pp, DECLTYPE_TYPE_EXPR (t));
1207 pp_cxx_right_paren (pp);
1211 if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
1212 pp_c_specifier_qualifier_list (pp_c_base (pp), t);
1217 * cv-qualifier-seq(opt)
1219 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1222 pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
1224 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
1226 switch (TREE_CODE (t))
1228 case REFERENCE_TYPE:
1230 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
1231 || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t)))
1232 pp_cxx_ptr_operator (pp, TREE_TYPE (t));
1233 if (TREE_CODE (t) == POINTER_TYPE)
1236 pp_cxx_cv_qualifier_seq (pp, t);
1243 if (TYPE_PTRMEMFUNC_P (t))
1245 pp_cxx_left_paren (pp);
1246 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t));
1251 if (TYPE_PTR_TO_MEMBER_P (t))
1253 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1254 pp_cxx_left_paren (pp);
1255 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t));
1257 pp_cxx_cv_qualifier_seq (pp, t);
1260 /* else fall through. */
1263 pp_unsupported_tree (pp, t);
1269 pp_cxx_implicit_parameter_type (tree mf)
1271 return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf))));
1275 parameter-declaration:
1276 decl-specifier-seq declarator
1277 decl-specifier-seq declarator = assignment-expression
1278 decl-specifier-seq abstract-declarator(opt)
1279 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1282 pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
1284 pp_cxx_decl_specifier_seq (pp, t);
1286 pp_cxx_abstract_declarator (pp, t);
1288 pp_cxx_declarator (pp, t);
1291 /* parameter-declaration-clause:
1292 parameter-declaration-list(opt) ...(opt)
1293 parameter-declaration-list , ...
1295 parameter-declaration-list:
1296 parameter-declaration
1297 parameter-declaration-list , parameter-declaration */
1300 pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
1302 tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t);
1304 TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
1305 const bool abstract = args == NULL
1306 || pp_c_base (pp)->flags & pp_c_flag_abstract;
1309 /* Skip artificial parameter for nonstatic member functions. */
1310 if (TREE_CODE (t) == METHOD_TYPE)
1311 types = TREE_CHAIN (types);
1313 pp_cxx_left_paren (pp);
1314 for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
1317 pp_cxx_separate_with (pp, ',');
1319 pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
1320 if (!abstract && pp_c_base (pp)->flags & pp_cxx_flag_default_argument)
1322 pp_cxx_whitespace (pp);
1324 pp_cxx_whitespace (pp);
1325 pp_cxx_assignment_expression (pp, TREE_PURPOSE (types));
1328 pp_cxx_right_paren (pp);
1331 /* exception-specification:
1332 throw ( type-id-list(opt) )
1336 type-id-list , type-id */
1339 pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
1341 tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
1342 bool need_comma = false;
1344 if (!TYPE_NOTHROW_P (t) && ex_spec == NULL)
1346 pp_cxx_identifier (pp, "throw");
1347 pp_cxx_left_paren (pp);
1348 for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
1350 tree type = TREE_VALUE (ex_spec);
1351 tree argpack = NULL_TREE;
1354 if (ARGUMENT_PACK_P (type))
1356 argpack = ARGUMENT_PACK_ARGS (type);
1357 len = TREE_VEC_LENGTH (argpack);
1360 for (i = 0; i < len; ++i)
1363 type = TREE_VEC_ELT (argpack, i);
1366 pp_cxx_separate_with (pp, ',');
1370 pp_cxx_type_id (pp, type);
1373 pp_cxx_right_paren (pp);
1376 /* direct-declarator:
1378 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1379 exception-specification(opt)
1380 direct-declaration [ constant-expression(opt) ]
1384 pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t)
1386 switch (TREE_CODE (t))
1394 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1396 if ((TREE_CODE (t) == PARM_DECL && FUNCTION_PARAMETER_PACK_P (t))
1397 || template_parameter_pack_p (t))
1398 /* A function parameter pack or non-type template
1400 pp_cxx_identifier (pp, "...");
1402 pp_cxx_id_expression (pp, DECL_NAME (t));
1404 pp_cxx_abstract_declarator (pp, TREE_TYPE (t));
1408 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
1409 pp_cxx_id_expression (pp, t);
1410 pp_cxx_parameter_declaration_clause (pp, t);
1412 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
1414 pp_base (pp)->padding = pp_before;
1415 pp_cxx_cv_qualifier_seq (pp, pp_cxx_implicit_parameter_type (t));
1418 pp_cxx_exception_specification (pp, TREE_TYPE (t));
1423 case TEMPLATE_TYPE_PARM:
1424 case TEMPLATE_PARM_INDEX:
1425 case TEMPLATE_TEMPLATE_PARM:
1429 pp_c_direct_declarator (pp_c_base (pp), t);
1436 ptr-operator declarator */
1439 pp_cxx_declarator (cxx_pretty_printer *pp, tree t)
1441 pp_cxx_direct_declarator (pp, t);
1444 /* ctor-initializer:
1445 : mem-initializer-list
1447 mem-initializer-list:
1449 mem-initializer , mem-initializer-list
1452 mem-initializer-id ( expression-list(opt) )
1455 ::(opt) nested-name-specifier(opt) class-name
1459 pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
1461 t = TREE_OPERAND (t, 0);
1462 pp_cxx_whitespace (pp);
1464 pp_cxx_whitespace (pp);
1465 for (; t; t = TREE_CHAIN (t))
1467 tree purpose = TREE_PURPOSE (t);
1468 bool is_pack = PACK_EXPANSION_P (purpose);
1471 pp_cxx_primary_expression (pp, PACK_EXPANSION_PATTERN (purpose));
1473 pp_cxx_primary_expression (pp, purpose);
1474 pp_cxx_call_argument_list (pp, TREE_VALUE (t));
1476 pp_cxx_identifier (pp, "...");
1478 pp_cxx_separate_with (pp, ',');
1482 /* function-definition:
1483 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1484 decl-specifier-seq(opt) declarator function-try-block */
1487 pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
1489 tree saved_scope = pp->enclosing_scope;
1490 pp_cxx_decl_specifier_seq (pp, t);
1491 pp_cxx_declarator (pp, t);
1492 pp_needs_newline (pp) = true;
1493 pp->enclosing_scope = DECL_CONTEXT (t);
1494 if (DECL_SAVED_TREE (t))
1495 pp_cxx_statement (pp, DECL_SAVED_TREE (t));
1498 pp_cxx_semicolon (pp);
1499 pp_needs_newline (pp) = true;
1502 pp->enclosing_scope = saved_scope;
1505 /* abstract-declarator:
1506 ptr-operator abstract-declarator(opt)
1507 direct-abstract-declarator */
1510 pp_cxx_abstract_declarator (cxx_pretty_printer *pp, tree t)
1512 if (TYPE_PTRMEM_P (t) || TYPE_PTRMEMFUNC_P (t))
1513 pp_cxx_right_paren (pp);
1514 else if (POINTER_TYPE_P (t))
1516 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
1517 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1518 pp_cxx_right_paren (pp);
1521 pp_cxx_direct_abstract_declarator (pp, t);
1524 /* direct-abstract-declarator:
1525 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1526 cv-qualifier-seq(opt) exception-specification(opt)
1527 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1528 ( abstract-declarator ) */
1531 pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
1533 switch (TREE_CODE (t))
1535 case REFERENCE_TYPE:
1536 pp_cxx_abstract_declarator (pp, t);
1540 if (TYPE_PTRMEMFUNC_P (t))
1541 pp_cxx_direct_abstract_declarator (pp, TYPE_PTRMEMFUNC_FN_TYPE (t));
1546 pp_cxx_parameter_declaration_clause (pp, t);
1547 pp_cxx_direct_abstract_declarator (pp, TREE_TYPE (t));
1548 if (TREE_CODE (t) == METHOD_TYPE)
1550 pp_base (pp)->padding = pp_before;
1551 pp_cxx_cv_qualifier_seq
1552 (pp, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))));
1554 pp_cxx_exception_specification (pp, t);
1558 case TEMPLATE_TYPE_PARM:
1559 case TEMPLATE_TEMPLATE_PARM:
1560 case BOUND_TEMPLATE_TEMPLATE_PARM:
1561 case UNBOUND_CLASS_TEMPLATE:
1565 pp_c_direct_abstract_declarator (pp_c_base (pp), t);
1571 type-specifier-seq abstract-declarator(opt) */
1574 pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
1576 pp_flags saved_flags = pp_c_base (pp)->flags;
1577 pp_c_base (pp)->flags |= pp_c_flag_abstract;
1579 switch (TREE_CODE (t))
1586 case BOUND_TEMPLATE_TEMPLATE_PARM:
1587 case UNBOUND_CLASS_TEMPLATE:
1588 case TEMPLATE_TEMPLATE_PARM:
1589 case TEMPLATE_TYPE_PARM:
1590 case TEMPLATE_PARM_INDEX:
1594 case TEMPLATE_ID_EXPR:
1595 pp_cxx_type_specifier_seq (pp, t);
1598 case TYPE_PACK_EXPANSION:
1599 pp_cxx_type_id (pp, PACK_EXPANSION_PATTERN (t));
1600 pp_cxx_identifier (pp, "...");
1604 pp_c_type_id (pp_c_base (pp), t);
1608 pp_c_base (pp)->flags = saved_flags;
1611 /* template-argument-list:
1612 template-argument ...(opt)
1613 template-argument-list, template-argument ...(opt)
1616 assignment-expression
1621 pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
1624 bool need_comma = false;
1628 for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
1630 tree arg = TREE_VEC_ELT (t, i);
1631 tree argpack = NULL_TREE;
1634 if (ARGUMENT_PACK_P (arg))
1636 argpack = ARGUMENT_PACK_ARGS (arg);
1637 len = TREE_VEC_LENGTH (argpack);
1640 for (idx = 0; idx < len; idx++)
1643 arg = TREE_VEC_ELT (argpack, idx);
1646 pp_cxx_separate_with (pp, ',');
1650 if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
1651 && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
1652 pp_cxx_type_id (pp, arg);
1654 pp_cxx_expression (pp, arg);
1661 pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
1663 t = DECL_EXPR_DECL (t);
1664 pp_cxx_type_specifier_seq (pp, t);
1666 pp_cxx_abstract_declarator (pp, t);
1668 pp_cxx_declarator (pp, t);
1674 pp_cxx_statement (cxx_pretty_printer *pp, tree t)
1676 switch (TREE_CODE (t))
1678 case CTOR_INITIALIZER:
1679 pp_cxx_ctor_initializer (pp, t);
1683 pp_cxx_identifier (pp, "using");
1684 pp_cxx_identifier (pp, "namespace");
1685 if (DECL_CONTEXT (t))
1686 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1687 pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t));
1691 pp_cxx_identifier (pp, "using");
1692 pp_cxx_nested_name_specifier (pp, USING_DECL_SCOPE (t));
1693 pp_cxx_unqualified_id (pp, DECL_NAME (t));
1700 try compound-statement handler-seq */
1702 pp_maybe_newline_and_indent (pp, 0);
1703 pp_cxx_identifier (pp, "try");
1704 pp_newline_and_indent (pp, 3);
1705 pp_cxx_statement (pp, TRY_STMTS (t));
1706 pp_newline_and_indent (pp, -3);
1710 pp_cxx_statement (pp, TRY_HANDLERS (t));
1715 handler handler-seq(opt)
1718 catch ( exception-declaration ) compound-statement
1720 exception-declaration:
1721 type-specifier-seq declarator
1722 type-specifier-seq abstract-declarator
1725 pp_cxx_identifier (pp, "catch");
1726 pp_cxx_left_paren (pp);
1727 pp_cxx_exception_declaration (pp, HANDLER_PARMS (t));
1728 pp_cxx_right_paren (pp);
1729 pp_indentation (pp) += 3;
1730 pp_needs_newline (pp) = true;
1731 pp_cxx_statement (pp, HANDLER_BODY (t));
1732 pp_indentation (pp) -= 3;
1733 pp_needs_newline (pp) = true;
1736 /* selection-statement:
1737 if ( expression ) statement
1738 if ( expression ) statement else statement */
1740 pp_cxx_identifier (pp, "if");
1741 pp_cxx_whitespace (pp);
1742 pp_cxx_left_paren (pp);
1743 pp_cxx_expression (pp, IF_COND (t));
1744 pp_cxx_right_paren (pp);
1745 pp_newline_and_indent (pp, 2);
1746 pp_cxx_statement (pp, THEN_CLAUSE (t));
1747 pp_newline_and_indent (pp, -2);
1748 if (ELSE_CLAUSE (t))
1750 tree else_clause = ELSE_CLAUSE (t);
1751 pp_cxx_identifier (pp, "else");
1752 if (TREE_CODE (else_clause) == IF_STMT)
1753 pp_cxx_whitespace (pp);
1755 pp_newline_and_indent (pp, 2);
1756 pp_cxx_statement (pp, else_clause);
1757 if (TREE_CODE (else_clause) != IF_STMT)
1758 pp_newline_and_indent (pp, -2);
1763 pp_cxx_identifier (pp, "switch");
1765 pp_cxx_left_paren (pp);
1766 pp_cxx_expression (pp, SWITCH_STMT_COND (t));
1767 pp_cxx_right_paren (pp);
1768 pp_indentation (pp) += 3;
1769 pp_needs_newline (pp) = true;
1770 pp_cxx_statement (pp, SWITCH_STMT_BODY (t));
1771 pp_newline_and_indent (pp, -3);
1774 /* iteration-statement:
1775 while ( expression ) statement
1776 do statement while ( expression ) ;
1777 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1778 for ( declaration expression(opt) ; expression(opt) ) statement */
1780 pp_cxx_identifier (pp, "while");
1782 pp_cxx_left_paren (pp);
1783 pp_cxx_expression (pp, WHILE_COND (t));
1784 pp_cxx_right_paren (pp);
1785 pp_newline_and_indent (pp, 3);
1786 pp_cxx_statement (pp, WHILE_BODY (t));
1787 pp_indentation (pp) -= 3;
1788 pp_needs_newline (pp) = true;
1792 pp_cxx_identifier (pp, "do");
1793 pp_newline_and_indent (pp, 3);
1794 pp_cxx_statement (pp, DO_BODY (t));
1795 pp_newline_and_indent (pp, -3);
1796 pp_cxx_identifier (pp, "while");
1798 pp_cxx_left_paren (pp);
1799 pp_cxx_expression (pp, DO_COND (t));
1800 pp_cxx_right_paren (pp);
1801 pp_cxx_semicolon (pp);
1802 pp_needs_newline (pp) = true;
1806 pp_cxx_identifier (pp, "for");
1808 pp_cxx_left_paren (pp);
1809 if (FOR_INIT_STMT (t))
1810 pp_cxx_statement (pp, FOR_INIT_STMT (t));
1812 pp_cxx_semicolon (pp);
1813 pp_needs_newline (pp) = false;
1814 pp_cxx_whitespace (pp);
1816 pp_cxx_expression (pp, FOR_COND (t));
1817 pp_cxx_semicolon (pp);
1818 pp_needs_newline (pp) = false;
1819 pp_cxx_whitespace (pp);
1821 pp_cxx_expression (pp, FOR_EXPR (t));
1822 pp_cxx_right_paren (pp);
1823 pp_newline_and_indent (pp, 3);
1824 pp_cxx_statement (pp, FOR_BODY (t));
1825 pp_indentation (pp) -= 3;
1826 pp_needs_newline (pp) = true;
1832 return expression(opt) ; */
1835 pp_identifier (pp, TREE_CODE (t) == BREAK_STMT ? "break" : "continue");
1836 pp_cxx_semicolon (pp);
1837 pp_needs_newline (pp) = true;
1840 /* expression-statement:
1841 expression(opt) ; */
1843 pp_cxx_expression (pp, EXPR_STMT_EXPR (t));
1844 pp_cxx_semicolon (pp);
1845 pp_needs_newline (pp) = true;
1849 pp_cxx_identifier (pp, "try");
1850 pp_newline_and_indent (pp, 2);
1851 pp_cxx_statement (pp, CLEANUP_BODY (t));
1852 pp_newline_and_indent (pp, -2);
1853 pp_cxx_identifier (pp, CLEANUP_EH_ONLY (t) ? "catch" : "finally");
1854 pp_newline_and_indent (pp, 2);
1855 pp_cxx_statement (pp, CLEANUP_EXPR (t));
1856 pp_newline_and_indent (pp, -2);
1860 pp_cxx_declaration (pp, t);
1864 pp_c_statement (pp_c_base (pp), t);
1869 /* original-namespace-definition:
1870 namespace identifier { namespace-body }
1872 As an edge case, we also handle unnamed namespace definition here. */
1875 pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t)
1877 pp_cxx_identifier (pp, "namespace");
1878 if (DECL_CONTEXT (t))
1879 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1881 pp_cxx_unqualified_id (pp, t);
1882 pp_cxx_whitespace (pp);
1883 pp_cxx_left_brace (pp);
1884 /* We do not print the namespace-body. */
1885 pp_cxx_whitespace (pp);
1886 pp_cxx_right_brace (pp);
1892 namespace-alias-definition:
1893 namespace identifier = qualified-namespace-specifier ;
1895 qualified-namespace-specifier:
1896 ::(opt) nested-name-specifier(opt) namespace-name */
1899 pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t)
1901 pp_cxx_identifier (pp, "namespace");
1902 if (DECL_CONTEXT (t))
1903 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1904 pp_cxx_unqualified_id (pp, t);
1905 pp_cxx_whitespace (pp);
1907 pp_cxx_whitespace (pp);
1908 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)))
1909 pp_cxx_nested_name_specifier (pp,
1910 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)));
1911 pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t));
1912 pp_cxx_semicolon (pp);
1915 /* simple-declaration:
1916 decl-specifier-seq(opt) init-declarator-list(opt) */
1919 pp_cxx_simple_declaration (cxx_pretty_printer *pp, tree t)
1921 pp_cxx_decl_specifier_seq (pp, t);
1922 pp_cxx_init_declarator (pp, t);
1923 pp_cxx_semicolon (pp);
1924 pp_needs_newline (pp) = true;
1928 template-parameter-list:
1930 template-parameter-list , template-parameter */
1933 pp_cxx_template_parameter_list (cxx_pretty_printer *pp, tree t)
1935 const int n = TREE_VEC_LENGTH (t);
1937 for (i = 0; i < n; ++i)
1940 pp_cxx_separate_with (pp, ',');
1941 pp_cxx_template_parameter (pp, TREE_VEC_ELT (t, i));
1945 /* template-parameter:
1947 parameter-declaration
1950 class ...(opt) identifier(opt)
1951 class identifier(opt) = type-id
1952 typename identifier(opt)
1953 typename ...(opt) identifier(opt) = type-id
1954 template < template-parameter-list > class ...(opt) identifier(opt)
1955 template < template-parameter-list > class identifier(opt) = template-name */
1958 pp_cxx_template_parameter (cxx_pretty_printer *pp, tree t)
1960 tree parameter = TREE_VALUE (t);
1961 switch (TREE_CODE (parameter))
1964 pp_cxx_identifier (pp, "class");
1965 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t)))
1966 pp_cxx_identifier (pp, "...");
1967 if (DECL_NAME (parameter))
1968 pp_cxx_tree_identifier (pp, DECL_NAME (parameter));
1969 /* FIXME: Chech if we should print also default argument. */
1973 pp_cxx_parameter_declaration (pp, parameter);
1980 pp_unsupported_tree (pp, t);
1985 /* Pretty-print a template parameter in the canonical form
1986 "template-parameter-<level>-<position in parameter list>". */
1989 pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm)
1991 const enum tree_code code = TREE_CODE (parm);
1993 /* Brings type template parameters to the canonical forms. */
1994 if (code == TEMPLATE_TYPE_PARM || code == TEMPLATE_TEMPLATE_PARM
1995 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
1996 parm = TEMPLATE_TYPE_PARM_INDEX (parm);
1998 pp_cxx_begin_template_argument_list (pp);
1999 pp_cxx_identifier (pp, "template-parameter-");
2000 pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm));
2002 pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1);
2003 pp_cxx_end_template_argument_list (pp);
2007 template-declaration:
2008 export(opt) template < template-parameter-list > declaration */
2011 pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t)
2013 tree tmpl = most_general_template (t);
2017 pp_maybe_newline_and_indent (pp, 0);
2018 for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level))
2020 pp_cxx_identifier (pp, "template");
2021 pp_cxx_begin_template_argument_list (pp);
2022 pp_cxx_template_parameter_list (pp, TREE_VALUE (level));
2023 pp_cxx_end_template_argument_list (pp);
2024 pp_newline_and_indent (pp, 3);
2027 if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t))
2028 pp_cxx_function_definition (pp, t);
2030 pp_cxx_simple_declaration (pp, t);
2034 pp_cxx_explicit_specialization (cxx_pretty_printer *pp, tree t)
2036 pp_unsupported_tree (pp, t);
2040 pp_cxx_explicit_instantiation (cxx_pretty_printer *pp, tree t)
2042 pp_unsupported_tree (pp, t);
2049 template-declaration
2050 explicit-instantiation
2051 explicit-specialization
2052 linkage-specification
2053 namespace-definition
2058 namespace-alias-definition
2061 static_assert-declaration */
2063 pp_cxx_declaration (cxx_pretty_printer *pp, tree t)
2065 if (TREE_CODE (t) == STATIC_ASSERT)
2067 pp_cxx_identifier (pp, "static_assert");
2068 pp_cxx_left_paren (pp);
2069 pp_cxx_expression (pp, STATIC_ASSERT_CONDITION (t));
2070 pp_cxx_separate_with (pp, ',');
2071 pp_cxx_expression (pp, STATIC_ASSERT_MESSAGE (t));
2072 pp_cxx_right_paren (pp);
2074 else if (!DECL_LANG_SPECIFIC (t))
2075 pp_cxx_simple_declaration (pp, t);
2076 else if (DECL_USE_TEMPLATE (t))
2077 switch (DECL_USE_TEMPLATE (t))
2080 pp_cxx_template_declaration (pp, t);
2084 pp_cxx_explicit_specialization (pp, t);
2088 pp_cxx_explicit_instantiation (pp, t);
2094 else switch (TREE_CODE (t))
2098 pp_cxx_simple_declaration (pp, t);
2102 if (DECL_SAVED_TREE (t))
2103 pp_cxx_function_definition (pp, t);
2105 pp_cxx_simple_declaration (pp, t);
2108 case NAMESPACE_DECL:
2109 if (DECL_NAMESPACE_ALIAS (t))
2110 pp_cxx_namespace_alias_definition (pp, t);
2112 pp_cxx_original_namespace_definition (pp, t);
2116 pp_unsupported_tree (pp, t);
2122 typedef c_pretty_print_fn pp_fun;
2124 /* Initialization of a C++ pretty-printer object. */
2127 pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
2129 pp_c_pretty_printer_init (pp_c_base (pp));
2130 pp_set_line_maximum_length (pp, 0);
2132 pp->c_base.declaration = (pp_fun) pp_cxx_declaration;
2133 pp->c_base.declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
2134 pp->c_base.function_specifier = (pp_fun) pp_cxx_function_specifier;
2135 pp->c_base.type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
2136 pp->c_base.declarator = (pp_fun) pp_cxx_declarator;
2137 pp->c_base.direct_declarator = (pp_fun) pp_cxx_direct_declarator;
2138 pp->c_base.parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
2139 pp->c_base.type_id = (pp_fun) pp_cxx_type_id;
2140 pp->c_base.abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
2141 pp->c_base.direct_abstract_declarator =
2142 (pp_fun) pp_cxx_direct_abstract_declarator;
2143 pp->c_base.simple_type_specifier = (pp_fun)pp_cxx_simple_type_specifier;
2145 /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
2147 pp->c_base.constant = (pp_fun) pp_cxx_constant;
2148 pp->c_base.id_expression = (pp_fun) pp_cxx_id_expression;
2149 pp->c_base.primary_expression = (pp_fun) pp_cxx_primary_expression;
2150 pp->c_base.postfix_expression = (pp_fun) pp_cxx_postfix_expression;
2151 pp->c_base.unary_expression = (pp_fun) pp_cxx_unary_expression;
2152 pp->c_base.multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
2153 pp->c_base.conditional_expression = (pp_fun) pp_cxx_conditional_expression;
2154 pp->c_base.assignment_expression = (pp_fun) pp_cxx_assignment_expression;
2155 pp->c_base.expression = (pp_fun) pp_cxx_expression;
2156 pp->enclosing_scope = global_namespace;