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);
135 conversion-function-id
140 pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t)
142 enum tree_code code = TREE_CODE (t);
146 pp_cxx_identifier (pp, "<return-value>");
163 case IDENTIFIER_NODE:
165 pp_cxx_identifier (pp, "<unnamed>");
166 else if (IDENTIFIER_TYPENAME_P (t))
167 pp_cxx_conversion_function_id (pp, t);
170 if (is_destructor_name (t))
173 /* FIXME: Why is this necessary? */
175 t = constructor_name (TREE_TYPE (t));
177 pp_cxx_tree_identifier (pp, t);
181 case TEMPLATE_ID_EXPR:
182 pp_cxx_template_id (pp, t);
186 pp_cxx_unqualified_id (pp, BASELINK_FUNCTIONS (t));
192 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
195 case TEMPLATE_TYPE_PARM:
196 case TEMPLATE_TEMPLATE_PARM:
197 if (TYPE_IDENTIFIER (t))
198 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
200 pp_cxx_canonical_template_parameter (pp, t);
203 case TEMPLATE_PARM_INDEX:
204 pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t));
208 pp_unsupported_tree (pp, t);
213 /* Pretty-print out the token sequence ":: template" in template codes
214 where it is needed to "inline declare" the (following) member as
215 a template. This situation arises when SCOPE of T is dependent
216 on template parameters. */
219 pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
221 if (TREE_CODE (t) == TEMPLATE_ID_EXPR
222 && TYPE_P (scope) && dependent_type_p (scope))
223 pp_cxx_identifier (pp, "template");
226 /* nested-name-specifier:
227 class-or-namespace-name :: nested-name-specifier(opt)
228 class-or-namespace-name :: template nested-name-specifier */
231 pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
233 if (t != NULL && t != pp->enclosing_scope)
235 tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
236 pp_cxx_nested_name_specifier (pp, scope);
237 pp_cxx_template_keyword_if_needed (pp, scope, t);
238 pp_cxx_unqualified_id (pp, t);
239 pp_cxx_colon_colon (pp);
244 nested-name-specifier template(opt) unqualified-id */
247 pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t)
249 switch (TREE_CODE (t))
251 /* A pointer-to-member is always qualified. */
253 pp_cxx_nested_name_specifier (pp, PTRMEM_CST_CLASS (t));
254 pp_cxx_unqualified_id (pp, PTRMEM_CST_MEMBER (t));
257 /* In Standard C++, functions cannot possibly be used as
258 nested-name-specifiers. However, there are situations where
259 is "makes sense" to output the surrounding function name for the
260 purpose of emphasizing on the scope kind. Just printing the
261 function name might not be sufficient as it may be overloaded; so,
262 we decorate the function with its signature too.
263 FIXME: This is probably the wrong pretty-printing for conversion
264 functions and some function templates. */
268 if (DECL_FUNCTION_MEMBER_P (t))
269 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
270 pp_cxx_unqualified_id
271 (pp, DECL_CONSTRUCTOR_P (t) ? DECL_CONTEXT (t) : t);
272 pp_cxx_parameter_declaration_clause (pp, TREE_TYPE (t));
277 pp_cxx_nested_name_specifier (pp, TREE_OPERAND (t, 0));
278 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 1));
283 tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
284 if (scope != pp->enclosing_scope)
286 pp_cxx_nested_name_specifier (pp, scope);
287 pp_cxx_template_keyword_if_needed (pp, scope, t);
289 pp_cxx_unqualified_id (pp, t);
297 pp_cxx_constant (cxx_pretty_printer *pp, tree t)
299 switch (TREE_CODE (t))
303 const bool in_parens = PAREN_STRING_LITERAL_P (t);
305 pp_cxx_left_paren (pp);
306 pp_c_constant (pp_c_base (pp), t);
308 pp_cxx_right_paren (pp);
313 pp_c_constant (pp_c_base (pp), t);
323 pp_cxx_id_expression (cxx_pretty_printer *pp, tree t)
325 if (TREE_CODE (t) == OVERLOAD)
327 if (DECL_P (t) && DECL_CONTEXT (t))
328 pp_cxx_qualified_id (pp, t);
330 pp_cxx_unqualified_id (pp, t);
333 /* primary-expression:
337 :: operator-function-id
343 pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
345 switch (TREE_CODE (t))
350 pp_cxx_constant (pp, t);
354 t = BASELINK_FUNCTIONS (t);
362 pp_cxx_id_expression (pp, t);
366 case TEMPLATE_TYPE_PARM:
367 case TEMPLATE_TEMPLATE_PARM:
368 case TEMPLATE_PARM_INDEX:
369 pp_cxx_unqualified_id (pp, t);
373 pp_cxx_left_paren (pp);
374 pp_cxx_statement (pp, STMT_EXPR_STMT (t));
375 pp_cxx_right_paren (pp);
379 pp_c_primary_expression (pp_c_base (pp), t);
384 /* postfix-expression:
386 postfix-expression [ expression ]
387 postfix-expression ( expression-list(opt) )
388 simple-type-specifier ( expression-list(opt) )
389 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
390 typename ::(opt) nested-name-specifier template(opt)
391 template-id ( expression-list(opt) )
392 postfix-expression . template(opt) ::(opt) id-expression
393 postfix-expression -> template(opt) ::(opt) id-expression
394 postfix-expression . pseudo-destructor-name
395 postfix-expression -> pseudo-destructor-name
396 postfix-expression ++
397 postfix-expression --
398 dynamic_cast < type-id > ( expression )
399 static_cast < type-id > ( expression )
400 reinterpret_cast < type-id > ( expression )
401 const_cast < type-id > ( expression )
402 typeid ( expression )
403 typeif ( type-id ) */
406 pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t)
408 enum tree_code code = TREE_CODE (t);
415 tree fun = (code == AGGR_INIT_EXPR ? AGGR_INIT_EXPR_FN (t)
417 tree saved_scope = pp->enclosing_scope;
418 bool skipfirst = false;
421 if (TREE_CODE (fun) == ADDR_EXPR)
422 fun = TREE_OPERAND (fun, 0);
424 /* In templates, where there is no way to tell whether a given
425 call uses an actual member function. So the parser builds
426 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
427 instantiation time. */
428 if (TREE_CODE (fun) != FUNCTION_DECL)
430 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun))
432 tree object = (code == AGGR_INIT_EXPR
433 ? (AGGR_INIT_VIA_CTOR_P (t)
434 ? AGGR_INIT_EXPR_SLOT (t)
435 : AGGR_INIT_EXPR_ARG (t, 0))
436 : CALL_EXPR_ARG (t, 0));
438 while (TREE_CODE (object) == NOP_EXPR)
439 object = TREE_OPERAND (object, 0);
441 if (TREE_CODE (object) == ADDR_EXPR)
442 object = TREE_OPERAND (object, 0);
444 if (TREE_CODE (TREE_TYPE (object)) != POINTER_TYPE)
446 pp_cxx_postfix_expression (pp, object);
451 pp_cxx_postfix_expression (pp, object);
455 pp->enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
458 pp_cxx_postfix_expression (pp, fun);
459 pp->enclosing_scope = saved_scope;
460 pp_cxx_left_paren (pp);
461 if (code == AGGR_INIT_EXPR)
463 aggr_init_expr_arg_iterator iter;
464 FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t)
470 pp_cxx_expression (pp, arg);
471 if (more_aggr_init_expr_args_p (&iter))
472 pp_cxx_separate_with (pp, ',');
478 call_expr_arg_iterator iter;
479 FOR_EACH_CALL_EXPR_ARG (arg, iter, t)
485 pp_cxx_expression (pp, arg);
486 if (more_call_expr_args_p (&iter))
487 pp_cxx_separate_with (pp, ',');
491 pp_cxx_right_paren (pp);
493 if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
495 pp_cxx_separate_with (pp, ',');
496 pp_cxx_postfix_expression (pp, AGGR_INIT_EXPR_SLOT (t));
509 pp_cxx_primary_expression (pp, t);
512 case DYNAMIC_CAST_EXPR:
513 case STATIC_CAST_EXPR:
514 case REINTERPRET_CAST_EXPR:
515 case CONST_CAST_EXPR:
516 if (code == DYNAMIC_CAST_EXPR)
517 pp_cxx_identifier (pp, "dynamic_cast");
518 else if (code == STATIC_CAST_EXPR)
519 pp_cxx_identifier (pp, "static_cast");
520 else if (code == REINTERPRET_CAST_EXPR)
521 pp_cxx_identifier (pp, "reinterpret_cast");
523 pp_cxx_identifier (pp, "const_cast");
524 pp_cxx_begin_template_argument_list (pp);
525 pp_cxx_type_id (pp, TREE_TYPE (t));
526 pp_cxx_end_template_argument_list (pp);
528 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
532 case EMPTY_CLASS_EXPR:
533 pp_cxx_type_id (pp, TREE_TYPE (t));
539 t = TREE_OPERAND (t, 0);
540 pp_cxx_identifier (pp, "typeid");
543 pp_cxx_type_id (pp, t);
545 pp_cxx_expression (pp, t);
549 case PSEUDO_DTOR_EXPR:
550 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
552 pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1));
553 pp_cxx_colon_colon (pp);
555 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2));
559 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
564 pp_c_postfix_expression (pp_c_base (pp), t);
570 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
571 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
577 type-specifier-seq new-declarator(opt)
580 ptr-operator new-declarator(opt)
581 direct-new-declarator
583 direct-new-declarator
585 direct-new-declarator [ constant-expression ]
588 ( expression-list(opt) ) */
591 pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
593 enum tree_code code = TREE_CODE (t);
598 if (NEW_EXPR_USE_GLOBAL (t))
599 pp_cxx_colon_colon (pp);
600 pp_cxx_identifier (pp, "new");
601 if (TREE_OPERAND (t, 0))
603 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
606 /* FIXME: array-types are built with one more element. */
607 pp_cxx_type_id (pp, TREE_OPERAND (t, 1));
608 if (TREE_OPERAND (t, 2))
611 t = TREE_OPERAND (t, 2);
612 if (TREE_CODE (t) == TREE_LIST)
613 pp_c_expression_list (pp_c_base (pp), t);
614 else if (t == void_zero_node)
615 ; /* OK, empty initializer list. */
617 pp_cxx_expression (pp, t);
623 pp_unsupported_tree (pp, t);
627 /* delete-expression:
628 ::(opt) delete cast-expression
629 ::(opt) delete [ ] cast-expression */
632 pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
634 enum tree_code code = TREE_CODE (t);
638 case VEC_DELETE_EXPR:
639 if (DELETE_EXPR_USE_GLOBAL (t))
640 pp_cxx_colon_colon (pp);
641 pp_cxx_identifier (pp, "delete");
642 if (code == VEC_DELETE_EXPR)
644 pp_left_bracket (pp);
645 pp_right_bracket (pp);
647 pp_c_cast_expression (pp_c_base (pp), TREE_OPERAND (t, 0));
651 pp_unsupported_tree (pp, t);
659 unary-operator cast-expression
660 sizeof unary-expression
662 sizeof ... ( identifier )
666 unary-operator: one of
670 __alignof__ unary-expression
671 __alignof__ ( type-id ) */
674 pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
676 enum tree_code code = TREE_CODE (t);
681 pp_cxx_new_expression (pp, t);
685 case VEC_DELETE_EXPR:
686 pp_cxx_delete_expression (pp, t);
690 if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
692 pp_cxx_identifier (pp, "sizeof");
693 pp_cxx_identifier (pp, "...");
694 pp_cxx_whitespace (pp);
695 pp_cxx_left_paren (pp);
696 if (TYPE_P (TREE_OPERAND (t, 0)))
697 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
699 pp_unary_expression (pp, TREE_OPERAND (t, 0));
700 pp_cxx_right_paren (pp);
706 pp_cxx_identifier (pp, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
707 pp_cxx_whitespace (pp);
708 if (TYPE_P (TREE_OPERAND (t, 0)))
710 pp_cxx_left_paren (pp);
711 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
712 pp_cxx_right_paren (pp);
715 pp_unary_expression (pp, TREE_OPERAND (t, 0));
718 case UNARY_PLUS_EXPR:
720 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0));
724 pp_c_unary_expression (pp_c_base (pp), t);
731 ( type-id ) cast-expression */
734 pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
736 switch (TREE_CODE (t))
739 pp_cxx_type_id (pp, TREE_TYPE (t));
740 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
744 pp_c_cast_expression (pp_c_base (pp), t);
751 pm-expression .* cast-expression
752 pm-expression ->* cast-expression */
755 pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t)
757 switch (TREE_CODE (t))
759 /* Handle unfortunate OFFESET_REF overloading here. */
761 if (TYPE_P (TREE_OPERAND (t, 0)))
763 pp_cxx_qualified_id (pp, t);
766 /* Else fall through. */
769 pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
772 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1));
777 pp_cxx_cast_expression (pp, t);
782 /* multiplicative-expression:
784 multiplicative-expression * pm-expression
785 multiplicative-expression / pm-expression
786 multiplicative-expression % pm-expression */
789 pp_cxx_multiplicative_expression (cxx_pretty_printer *pp, tree e)
791 enum tree_code code = TREE_CODE (e);
797 pp_cxx_multiplicative_expression (pp, TREE_OPERAND (e, 0));
799 if (code == MULT_EXPR)
801 else if (code == TRUNC_DIV_EXPR)
806 pp_cxx_pm_expression (pp, TREE_OPERAND (e, 1));
810 pp_cxx_pm_expression (pp, e);
815 /* conditional-expression:
816 logical-or-expression
817 logical-or-expression ? expression : assignment-expression */
820 pp_cxx_conditional_expression (cxx_pretty_printer *pp, tree e)
822 if (TREE_CODE (e) == COND_EXPR)
824 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
828 pp_cxx_expression (pp, TREE_OPERAND (e, 1));
830 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
833 pp_c_logical_or_expression (pp_c_base (pp), e);
836 /* Pretty-print a compound assignment operator token as indicated by T. */
839 pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t)
843 switch (TREE_CODE (t))
866 op = tree_code_name[TREE_CODE (t)];
870 pp_cxx_identifier (pp, op);
874 /* assignment-expression:
875 conditional-expression
876 logical-or-expression assignment-operator assignment-expression
880 throw assignment-expression(opt)
882 assignment-operator: one of
883 = *= /= %= += -= >>= <<= &= ^= |= */
886 pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e)
888 switch (TREE_CODE (e))
892 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
896 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 1));
900 pp_cxx_identifier (pp, "throw");
901 if (TREE_OPERAND (e, 0))
902 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 0));
906 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
907 pp_cxx_assignment_operator (pp, TREE_OPERAND (e, 1));
908 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
912 pp_cxx_conditional_expression (pp, e);
918 pp_cxx_expression (cxx_pretty_printer *pp, tree t)
920 switch (TREE_CODE (t))
925 pp_cxx_constant (pp, t);
929 pp_cxx_unqualified_id (pp, t);
937 pp_cxx_qualified_id (pp, t);
949 case TEMPLATE_TYPE_PARM:
950 case TEMPLATE_PARM_INDEX:
951 case TEMPLATE_TEMPLATE_PARM:
953 pp_cxx_primary_expression (pp, t);
957 case DYNAMIC_CAST_EXPR:
958 case STATIC_CAST_EXPR:
959 case REINTERPRET_CAST_EXPR:
960 case CONST_CAST_EXPR:
964 case EMPTY_CLASS_EXPR:
966 case PSEUDO_DTOR_EXPR:
969 pp_cxx_postfix_expression (pp, t);
974 pp_cxx_new_expression (pp, t);
978 case VEC_DELETE_EXPR:
979 pp_cxx_delete_expression (pp, t);
984 pp_cxx_unary_expression (pp, t);
988 pp_cxx_cast_expression (pp, t);
994 pp_cxx_pm_expression (pp, t);
1000 pp_cxx_multiplicative_expression (pp, t);
1004 pp_cxx_conditional_expression (pp, t);
1011 pp_cxx_assignment_expression (pp, t);
1014 case NON_DEPENDENT_EXPR:
1015 case MUST_NOT_THROW_EXPR:
1016 pp_cxx_expression (pp, t);
1019 case EXPR_PACK_EXPANSION:
1020 pp_cxx_expression (pp, PACK_EXPANSION_PATTERN (t));
1021 pp_cxx_identifier (pp, "...");
1024 case NONTYPE_ARGUMENT_PACK:
1026 tree args = ARGUMENT_PACK_ARGS (t);
1027 int i, len = TREE_VEC_LENGTH (args);
1028 for (i = 0; i < len; ++i)
1031 pp_cxx_separate_with (pp, ',');
1032 pp_cxx_expression (pp, TREE_VEC_ELT (args, i));
1038 pp_c_expression (pp_c_base (pp), t);
1046 /* function-specifier:
1052 pp_cxx_function_specifier (cxx_pretty_printer *pp, tree t)
1054 switch (TREE_CODE (t))
1057 if (DECL_VIRTUAL_P (t))
1058 pp_cxx_identifier (pp, "virtual");
1059 else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
1060 pp_cxx_identifier (pp, "explicit");
1062 pp_c_function_specifier (pp_c_base (pp), t);
1069 /* decl-specifier-seq:
1070 decl-specifier-seq(opt) decl-specifier
1073 storage-class-specifier
1080 pp_cxx_decl_specifier_seq (cxx_pretty_printer *pp, tree t)
1082 switch (TREE_CODE (t))
1088 pp_cxx_storage_class_specifier (pp, t);
1089 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1093 pp_cxx_identifier (pp, "typedef");
1094 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1098 if (TYPE_PTRMEMFUNC_P (t))
1100 tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t);
1101 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (pfm)));
1102 pp_cxx_whitespace (pp);
1103 pp_cxx_ptr_operator (pp, t);
1108 /* Constructors don't have return types. And conversion functions
1109 do not have a type-specifier in their return types. */
1110 if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t))
1111 pp_cxx_function_specifier (pp, t);
1112 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
1113 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (t)));
1116 pp_c_declaration_specifiers (pp_c_base (pp), t);
1121 /* simple-type-specifier:
1122 ::(opt) nested-name-specifier(opt) type-name
1123 ::(opt) nested-name-specifier(opt) template(opt) template-id
1137 pp_cxx_simple_type_specifier (cxx_pretty_printer *pp, tree t)
1139 switch (TREE_CODE (t))
1144 pp_cxx_qualified_id (pp, t);
1147 case TEMPLATE_TYPE_PARM:
1148 case TEMPLATE_TEMPLATE_PARM:
1149 case TEMPLATE_PARM_INDEX:
1150 pp_cxx_unqualified_id (pp, t);
1154 pp_cxx_identifier (pp, "typename");
1155 pp_cxx_nested_name_specifier (pp, TYPE_CONTEXT (t));
1156 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
1160 pp_c_type_specifier (pp_c_base (pp), t);
1165 /* type-specifier-seq:
1166 type-specifier type-specifier-seq(opt)
1169 simple-type-specifier
1172 elaborated-type-specifier
1176 pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
1178 switch (TREE_CODE (t))
1181 case TEMPLATE_TYPE_PARM:
1182 case TEMPLATE_TEMPLATE_PARM:
1184 case BOUND_TEMPLATE_TEMPLATE_PARM:
1185 pp_cxx_cv_qualifier_seq (pp, t);
1186 pp_cxx_simple_type_specifier (pp, t);
1190 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
1191 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1192 pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t));
1196 if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
1197 pp_c_specifier_qualifier_list (pp_c_base (pp), t);
1202 * cv-qualifier-seq(opt)
1204 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1207 pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
1209 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
1211 switch (TREE_CODE (t))
1213 case REFERENCE_TYPE:
1215 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
1216 || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t)))
1217 pp_cxx_ptr_operator (pp, TREE_TYPE (t));
1218 if (TREE_CODE (t) == POINTER_TYPE)
1221 pp_cxx_cv_qualifier_seq (pp, t);
1228 if (TYPE_PTRMEMFUNC_P (t))
1230 pp_cxx_left_paren (pp);
1231 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t));
1236 if (TYPE_PTR_TO_MEMBER_P (t))
1238 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1239 pp_cxx_left_paren (pp);
1240 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t));
1242 pp_cxx_cv_qualifier_seq (pp, t);
1245 /* else fall through. */
1248 pp_unsupported_tree (pp, t);
1254 pp_cxx_implicit_parameter_type (tree mf)
1256 return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf))));
1260 parameter-declaration:
1261 decl-specifier-seq declarator
1262 decl-specifier-seq declarator = assignment-expression
1263 decl-specifier-seq abstract-declarator(opt)
1264 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1267 pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
1269 pp_cxx_decl_specifier_seq (pp, t);
1271 pp_cxx_abstract_declarator (pp, t);
1273 pp_cxx_declarator (pp, t);
1276 /* parameter-declaration-clause:
1277 parameter-declaration-list(opt) ...(opt)
1278 parameter-declaration-list , ...
1280 parameter-declaration-list:
1281 parameter-declaration
1282 parameter-declaration-list , parameter-declaration */
1285 pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
1287 tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t);
1289 TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
1290 const bool abstract = args == NULL
1291 || pp_c_base (pp)->flags & pp_c_flag_abstract;
1294 /* Skip artificial parameter for nonstatic member functions. */
1295 if (TREE_CODE (t) == METHOD_TYPE)
1296 types = TREE_CHAIN (types);
1298 pp_cxx_left_paren (pp);
1299 for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
1302 pp_cxx_separate_with (pp, ',');
1304 pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
1305 if (!abstract && pp_c_base (pp)->flags & pp_cxx_flag_default_argument)
1307 pp_cxx_whitespace (pp);
1309 pp_cxx_whitespace (pp);
1310 pp_cxx_assignment_expression (pp, TREE_PURPOSE (types));
1313 pp_cxx_right_paren (pp);
1316 /* exception-specification:
1317 throw ( type-id-list(opt) )
1321 type-id-list , type-id */
1324 pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
1326 tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
1327 bool need_comma = false;
1329 if (!TYPE_NOTHROW_P (t) && ex_spec == NULL)
1331 pp_cxx_identifier (pp, "throw");
1332 pp_cxx_left_paren (pp);
1333 for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
1335 tree type = TREE_VALUE (ex_spec);
1336 tree argpack = NULL_TREE;
1339 if (ARGUMENT_PACK_P (type))
1341 argpack = ARGUMENT_PACK_ARGS (type);
1342 len = TREE_VEC_LENGTH (argpack);
1345 for (i = 0; i < len; ++i)
1348 type = TREE_VEC_ELT (argpack, i);
1351 pp_cxx_separate_with (pp, ',');
1355 pp_cxx_type_id (pp, type);
1358 pp_cxx_right_paren (pp);
1361 /* direct-declarator:
1363 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1364 exception-specification(opt)
1365 direct-declaration [ constant-expression(opt) ]
1369 pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t)
1371 switch (TREE_CODE (t))
1379 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1381 if ((TREE_CODE (t) == PARM_DECL && FUNCTION_PARAMETER_PACK_P (t))
1382 || template_parameter_pack_p (t))
1383 /* A function parameter pack or non-type template
1385 pp_cxx_identifier (pp, "...");
1387 pp_cxx_id_expression (pp, DECL_NAME (t));
1389 pp_cxx_abstract_declarator (pp, TREE_TYPE (t));
1393 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
1394 pp_cxx_id_expression (pp, t);
1395 pp_cxx_parameter_declaration_clause (pp, t);
1397 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
1399 pp_base (pp)->padding = pp_before;
1400 pp_cxx_cv_qualifier_seq (pp, pp_cxx_implicit_parameter_type (t));
1403 pp_cxx_exception_specification (pp, TREE_TYPE (t));
1408 case TEMPLATE_TYPE_PARM:
1409 case TEMPLATE_PARM_INDEX:
1410 case TEMPLATE_TEMPLATE_PARM:
1414 pp_c_direct_declarator (pp_c_base (pp), t);
1421 ptr-operator declarator */
1424 pp_cxx_declarator (cxx_pretty_printer *pp, tree t)
1426 pp_cxx_direct_declarator (pp, t);
1429 /* ctor-initializer:
1430 : mem-initializer-list
1432 mem-initializer-list:
1434 mem-initializer , mem-initializer-list
1437 mem-initializer-id ( expression-list(opt) )
1440 ::(opt) nested-name-specifier(opt) class-name
1444 pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
1446 t = TREE_OPERAND (t, 0);
1447 pp_cxx_whitespace (pp);
1449 pp_cxx_whitespace (pp);
1450 for (; t; t = TREE_CHAIN (t))
1452 tree purpose = TREE_PURPOSE (t);
1453 bool is_pack = PACK_EXPANSION_P (purpose);
1456 pp_cxx_primary_expression (pp, PACK_EXPANSION_PATTERN (purpose));
1458 pp_cxx_primary_expression (pp, purpose);
1459 pp_cxx_call_argument_list (pp, TREE_VALUE (t));
1461 pp_cxx_identifier (pp, "...");
1463 pp_cxx_separate_with (pp, ',');
1467 /* function-definition:
1468 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1469 decl-specifier-seq(opt) declarator function-try-block */
1472 pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
1474 tree saved_scope = pp->enclosing_scope;
1475 pp_cxx_decl_specifier_seq (pp, t);
1476 pp_cxx_declarator (pp, t);
1477 pp_needs_newline (pp) = true;
1478 pp->enclosing_scope = DECL_CONTEXT (t);
1479 if (DECL_SAVED_TREE (t))
1480 pp_cxx_statement (pp, DECL_SAVED_TREE (t));
1483 pp_cxx_semicolon (pp);
1484 pp_needs_newline (pp) = true;
1487 pp->enclosing_scope = saved_scope;
1490 /* abstract-declarator:
1491 ptr-operator abstract-declarator(opt)
1492 direct-abstract-declarator */
1495 pp_cxx_abstract_declarator (cxx_pretty_printer *pp, tree t)
1497 if (TYPE_PTRMEM_P (t) || TYPE_PTRMEMFUNC_P (t))
1498 pp_cxx_right_paren (pp);
1499 else if (POINTER_TYPE_P (t))
1501 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
1502 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1503 pp_cxx_right_paren (pp);
1506 pp_cxx_direct_abstract_declarator (pp, t);
1509 /* direct-abstract-declarator:
1510 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1511 cv-qualifier-seq(opt) exception-specification(opt)
1512 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1513 ( abstract-declarator ) */
1516 pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
1518 switch (TREE_CODE (t))
1520 case REFERENCE_TYPE:
1521 pp_cxx_abstract_declarator (pp, t);
1525 if (TYPE_PTRMEMFUNC_P (t))
1526 pp_cxx_direct_abstract_declarator (pp, TYPE_PTRMEMFUNC_FN_TYPE (t));
1531 pp_cxx_parameter_declaration_clause (pp, t);
1532 pp_cxx_direct_abstract_declarator (pp, TREE_TYPE (t));
1533 if (TREE_CODE (t) == METHOD_TYPE)
1535 pp_base (pp)->padding = pp_before;
1536 pp_cxx_cv_qualifier_seq
1537 (pp, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))));
1539 pp_cxx_exception_specification (pp, t);
1543 case TEMPLATE_TYPE_PARM:
1544 case TEMPLATE_TEMPLATE_PARM:
1545 case BOUND_TEMPLATE_TEMPLATE_PARM:
1546 case UNBOUND_CLASS_TEMPLATE:
1550 pp_c_direct_abstract_declarator (pp_c_base (pp), t);
1556 type-specifier-seq abstract-declarator(opt) */
1559 pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
1561 pp_flags saved_flags = pp_c_base (pp)->flags;
1562 pp_c_base (pp)->flags |= pp_c_flag_abstract;
1564 switch (TREE_CODE (t))
1571 case BOUND_TEMPLATE_TEMPLATE_PARM:
1572 case UNBOUND_CLASS_TEMPLATE:
1573 case TEMPLATE_TEMPLATE_PARM:
1574 case TEMPLATE_TYPE_PARM:
1575 case TEMPLATE_PARM_INDEX:
1578 case TEMPLATE_ID_EXPR:
1579 pp_cxx_type_specifier_seq (pp, t);
1582 case TYPE_PACK_EXPANSION:
1583 pp_cxx_type_id (pp, PACK_EXPANSION_PATTERN (t));
1584 pp_cxx_identifier (pp, "...");
1588 pp_c_type_id (pp_c_base (pp), t);
1592 pp_c_base (pp)->flags = saved_flags;
1595 /* template-argument-list:
1596 template-argument ...(opt)
1597 template-argument-list, template-argument ...(opt)
1600 assignment-expression
1605 pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
1608 bool need_comma = false;
1612 for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
1614 tree arg = TREE_VEC_ELT (t, i);
1615 tree argpack = NULL_TREE;
1618 if (ARGUMENT_PACK_P (arg))
1620 argpack = ARGUMENT_PACK_ARGS (arg);
1621 len = TREE_VEC_LENGTH (argpack);
1624 for (idx = 0; idx < len; idx++)
1627 arg = TREE_VEC_ELT (argpack, idx);
1630 pp_cxx_separate_with (pp, ',');
1634 if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
1635 && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
1636 pp_cxx_type_id (pp, arg);
1638 pp_cxx_expression (pp, arg);
1645 pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
1647 t = DECL_EXPR_DECL (t);
1648 pp_cxx_type_specifier_seq (pp, t);
1650 pp_cxx_abstract_declarator (pp, t);
1652 pp_cxx_declarator (pp, t);
1658 pp_cxx_statement (cxx_pretty_printer *pp, tree t)
1660 switch (TREE_CODE (t))
1662 case CTOR_INITIALIZER:
1663 pp_cxx_ctor_initializer (pp, t);
1667 pp_cxx_identifier (pp, "using");
1668 pp_cxx_identifier (pp, "namespace");
1669 if (DECL_CONTEXT (t))
1670 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1671 pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t));
1675 pp_cxx_identifier (pp, "using");
1676 pp_cxx_nested_name_specifier (pp, USING_DECL_SCOPE (t));
1677 pp_cxx_unqualified_id (pp, DECL_NAME (t));
1684 try compound-statement handler-seq */
1686 pp_maybe_newline_and_indent (pp, 0);
1687 pp_cxx_identifier (pp, "try");
1688 pp_newline_and_indent (pp, 3);
1689 pp_cxx_statement (pp, TRY_STMTS (t));
1690 pp_newline_and_indent (pp, -3);
1694 pp_cxx_statement (pp, TRY_HANDLERS (t));
1699 handler handler-seq(opt)
1702 catch ( exception-declaration ) compound-statement
1704 exception-declaration:
1705 type-specifier-seq declarator
1706 type-specifier-seq abstract-declarator
1709 pp_cxx_identifier (pp, "catch");
1710 pp_cxx_left_paren (pp);
1711 pp_cxx_exception_declaration (pp, HANDLER_PARMS (t));
1712 pp_cxx_right_paren (pp);
1713 pp_indentation (pp) += 3;
1714 pp_needs_newline (pp) = true;
1715 pp_cxx_statement (pp, HANDLER_BODY (t));
1716 pp_indentation (pp) -= 3;
1717 pp_needs_newline (pp) = true;
1720 /* selection-statement:
1721 if ( expression ) statement
1722 if ( expression ) statement else statement */
1724 pp_cxx_identifier (pp, "if");
1725 pp_cxx_whitespace (pp);
1726 pp_cxx_left_paren (pp);
1727 pp_cxx_expression (pp, IF_COND (t));
1728 pp_cxx_right_paren (pp);
1729 pp_newline_and_indent (pp, 2);
1730 pp_cxx_statement (pp, THEN_CLAUSE (t));
1731 pp_newline_and_indent (pp, -2);
1732 if (ELSE_CLAUSE (t))
1734 tree else_clause = ELSE_CLAUSE (t);
1735 pp_cxx_identifier (pp, "else");
1736 if (TREE_CODE (else_clause) == IF_STMT)
1737 pp_cxx_whitespace (pp);
1739 pp_newline_and_indent (pp, 2);
1740 pp_cxx_statement (pp, else_clause);
1741 if (TREE_CODE (else_clause) != IF_STMT)
1742 pp_newline_and_indent (pp, -2);
1747 pp_cxx_identifier (pp, "switch");
1749 pp_cxx_left_paren (pp);
1750 pp_cxx_expression (pp, SWITCH_STMT_COND (t));
1751 pp_cxx_right_paren (pp);
1752 pp_indentation (pp) += 3;
1753 pp_needs_newline (pp) = true;
1754 pp_cxx_statement (pp, SWITCH_STMT_BODY (t));
1755 pp_newline_and_indent (pp, -3);
1758 /* iteration-statement:
1759 while ( expression ) statement
1760 do statement while ( expression ) ;
1761 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1762 for ( declaration expression(opt) ; expression(opt) ) statement */
1764 pp_cxx_identifier (pp, "while");
1766 pp_cxx_left_paren (pp);
1767 pp_cxx_expression (pp, WHILE_COND (t));
1768 pp_cxx_right_paren (pp);
1769 pp_newline_and_indent (pp, 3);
1770 pp_cxx_statement (pp, WHILE_BODY (t));
1771 pp_indentation (pp) -= 3;
1772 pp_needs_newline (pp) = true;
1776 pp_cxx_identifier (pp, "do");
1777 pp_newline_and_indent (pp, 3);
1778 pp_cxx_statement (pp, DO_BODY (t));
1779 pp_newline_and_indent (pp, -3);
1780 pp_cxx_identifier (pp, "while");
1782 pp_cxx_left_paren (pp);
1783 pp_cxx_expression (pp, DO_COND (t));
1784 pp_cxx_right_paren (pp);
1785 pp_cxx_semicolon (pp);
1786 pp_needs_newline (pp) = true;
1790 pp_cxx_identifier (pp, "for");
1792 pp_cxx_left_paren (pp);
1793 if (FOR_INIT_STMT (t))
1794 pp_cxx_statement (pp, FOR_INIT_STMT (t));
1796 pp_cxx_semicolon (pp);
1797 pp_needs_newline (pp) = false;
1798 pp_cxx_whitespace (pp);
1800 pp_cxx_expression (pp, FOR_COND (t));
1801 pp_cxx_semicolon (pp);
1802 pp_needs_newline (pp) = false;
1803 pp_cxx_whitespace (pp);
1805 pp_cxx_expression (pp, FOR_EXPR (t));
1806 pp_cxx_right_paren (pp);
1807 pp_newline_and_indent (pp, 3);
1808 pp_cxx_statement (pp, FOR_BODY (t));
1809 pp_indentation (pp) -= 3;
1810 pp_needs_newline (pp) = true;
1816 return expression(opt) ; */
1819 pp_identifier (pp, TREE_CODE (t) == BREAK_STMT ? "break" : "continue");
1820 pp_cxx_semicolon (pp);
1821 pp_needs_newline (pp) = true;
1824 /* expression-statement:
1825 expression(opt) ; */
1827 pp_cxx_expression (pp, EXPR_STMT_EXPR (t));
1828 pp_cxx_semicolon (pp);
1829 pp_needs_newline (pp) = true;
1833 pp_cxx_identifier (pp, "try");
1834 pp_newline_and_indent (pp, 2);
1835 pp_cxx_statement (pp, CLEANUP_BODY (t));
1836 pp_newline_and_indent (pp, -2);
1837 pp_cxx_identifier (pp, CLEANUP_EH_ONLY (t) ? "catch" : "finally");
1838 pp_newline_and_indent (pp, 2);
1839 pp_cxx_statement (pp, CLEANUP_EXPR (t));
1840 pp_newline_and_indent (pp, -2);
1844 pp_cxx_declaration (pp, t);
1848 pp_c_statement (pp_c_base (pp), t);
1853 /* original-namespace-definition:
1854 namespace identifier { namespace-body }
1856 As an edge case, we also handle unnamed namespace definition here. */
1859 pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t)
1861 pp_cxx_identifier (pp, "namespace");
1862 if (DECL_CONTEXT (t))
1863 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1865 pp_cxx_unqualified_id (pp, t);
1866 pp_cxx_whitespace (pp);
1867 pp_cxx_left_brace (pp);
1868 /* We do not print the namespace-body. */
1869 pp_cxx_whitespace (pp);
1870 pp_cxx_right_brace (pp);
1876 namespace-alias-definition:
1877 namespace identifier = qualified-namespace-specifier ;
1879 qualified-namespace-specifier:
1880 ::(opt) nested-name-specifier(opt) namespace-name */
1883 pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t)
1885 pp_cxx_identifier (pp, "namespace");
1886 if (DECL_CONTEXT (t))
1887 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1888 pp_cxx_unqualified_id (pp, t);
1889 pp_cxx_whitespace (pp);
1891 pp_cxx_whitespace (pp);
1892 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)))
1893 pp_cxx_nested_name_specifier (pp,
1894 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)));
1895 pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t));
1896 pp_cxx_semicolon (pp);
1899 /* simple-declaration:
1900 decl-specifier-seq(opt) init-declarator-list(opt) */
1903 pp_cxx_simple_declaration (cxx_pretty_printer *pp, tree t)
1905 pp_cxx_decl_specifier_seq (pp, t);
1906 pp_cxx_init_declarator (pp, t);
1907 pp_cxx_semicolon (pp);
1908 pp_needs_newline (pp) = true;
1912 template-parameter-list:
1914 template-parameter-list , template-parameter */
1917 pp_cxx_template_parameter_list (cxx_pretty_printer *pp, tree t)
1919 const int n = TREE_VEC_LENGTH (t);
1921 for (i = 0; i < n; ++i)
1924 pp_cxx_separate_with (pp, ',');
1925 pp_cxx_template_parameter (pp, TREE_VEC_ELT (t, i));
1929 /* template-parameter:
1931 parameter-declaration
1934 class ...(opt) identifier(opt)
1935 class identifier(opt) = type-id
1936 typename identifier(opt)
1937 typename ...(opt) identifier(opt) = type-id
1938 template < template-parameter-list > class ...(opt) identifier(opt)
1939 template < template-parameter-list > class identifier(opt) = template-name */
1942 pp_cxx_template_parameter (cxx_pretty_printer *pp, tree t)
1944 tree parameter = TREE_VALUE (t);
1945 switch (TREE_CODE (parameter))
1948 pp_cxx_identifier (pp, "class");
1949 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t)))
1950 pp_cxx_identifier (pp, "...");
1951 if (DECL_NAME (parameter))
1952 pp_cxx_tree_identifier (pp, DECL_NAME (parameter));
1953 /* FIXME: Chech if we should print also default argument. */
1957 pp_cxx_parameter_declaration (pp, parameter);
1964 pp_unsupported_tree (pp, t);
1969 /* Pretty-print a template parameter in the canonical form
1970 "template-parameter-<level>-<position in parameter list>". */
1973 pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm)
1975 const enum tree_code code = TREE_CODE (parm);
1977 /* Brings type template parameters to the canonical forms. */
1978 if (code == TEMPLATE_TYPE_PARM || code == TEMPLATE_TEMPLATE_PARM
1979 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
1980 parm = TEMPLATE_TYPE_PARM_INDEX (parm);
1982 pp_cxx_begin_template_argument_list (pp);
1983 pp_cxx_identifier (pp, "template-parameter-");
1984 pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm));
1986 pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1);
1987 pp_cxx_end_template_argument_list (pp);
1991 template-declaration:
1992 export(opt) template < template-parameter-list > declaration */
1995 pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t)
1997 tree tmpl = most_general_template (t);
2001 pp_maybe_newline_and_indent (pp, 0);
2002 for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level))
2004 pp_cxx_identifier (pp, "template");
2005 pp_cxx_begin_template_argument_list (pp);
2006 pp_cxx_template_parameter_list (pp, TREE_VALUE (level));
2007 pp_cxx_end_template_argument_list (pp);
2008 pp_newline_and_indent (pp, 3);
2011 if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t))
2012 pp_cxx_function_definition (pp, t);
2014 pp_cxx_simple_declaration (pp, t);
2018 pp_cxx_explicit_specialization (cxx_pretty_printer *pp, tree t)
2020 pp_unsupported_tree (pp, t);
2024 pp_cxx_explicit_instantiation (cxx_pretty_printer *pp, tree t)
2026 pp_unsupported_tree (pp, t);
2033 template-declaration
2034 explicit-instantiation
2035 explicit-specialization
2036 linkage-specification
2037 namespace-definition
2042 namespace-alias-definition
2045 static_assert-declaration */
2047 pp_cxx_declaration (cxx_pretty_printer *pp, tree t)
2049 if (TREE_CODE (t) == STATIC_ASSERT)
2051 pp_cxx_identifier (pp, "static_assert");
2052 pp_cxx_left_paren (pp);
2053 pp_cxx_expression (pp, STATIC_ASSERT_CONDITION (t));
2054 pp_cxx_separate_with (pp, ',');
2055 pp_cxx_expression (pp, STATIC_ASSERT_MESSAGE (t));
2056 pp_cxx_right_paren (pp);
2058 else if (!DECL_LANG_SPECIFIC (t))
2059 pp_cxx_simple_declaration (pp, t);
2060 else if (DECL_USE_TEMPLATE (t))
2061 switch (DECL_USE_TEMPLATE (t))
2064 pp_cxx_template_declaration (pp, t);
2068 pp_cxx_explicit_specialization (pp, t);
2072 pp_cxx_explicit_instantiation (pp, t);
2078 else switch (TREE_CODE (t))
2082 pp_cxx_simple_declaration (pp, t);
2086 if (DECL_SAVED_TREE (t))
2087 pp_cxx_function_definition (pp, t);
2089 pp_cxx_simple_declaration (pp, t);
2092 case NAMESPACE_DECL:
2093 if (DECL_NAMESPACE_ALIAS (t))
2094 pp_cxx_namespace_alias_definition (pp, t);
2096 pp_cxx_original_namespace_definition (pp, t);
2100 pp_unsupported_tree (pp, t);
2106 typedef c_pretty_print_fn pp_fun;
2108 /* Initialization of a C++ pretty-printer object. */
2111 pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
2113 pp_c_pretty_printer_init (pp_c_base (pp));
2114 pp_set_line_maximum_length (pp, 0);
2116 pp->c_base.declaration = (pp_fun) pp_cxx_declaration;
2117 pp->c_base.declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
2118 pp->c_base.function_specifier = (pp_fun) pp_cxx_function_specifier;
2119 pp->c_base.type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
2120 pp->c_base.declarator = (pp_fun) pp_cxx_declarator;
2121 pp->c_base.direct_declarator = (pp_fun) pp_cxx_direct_declarator;
2122 pp->c_base.parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
2123 pp->c_base.type_id = (pp_fun) pp_cxx_type_id;
2124 pp->c_base.abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
2125 pp->c_base.direct_abstract_declarator =
2126 (pp_fun) pp_cxx_direct_abstract_declarator;
2127 pp->c_base.simple_type_specifier = (pp_fun)pp_cxx_simple_type_specifier;
2129 /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
2131 pp->c_base.constant = (pp_fun) pp_cxx_constant;
2132 pp->c_base.id_expression = (pp_fun) pp_cxx_id_expression;
2133 pp->c_base.primary_expression = (pp_fun) pp_cxx_primary_expression;
2134 pp->c_base.postfix_expression = (pp_fun) pp_cxx_postfix_expression;
2135 pp->c_base.unary_expression = (pp_fun) pp_cxx_unary_expression;
2136 pp->c_base.multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
2137 pp->c_base.conditional_expression = (pp_fun) pp_cxx_conditional_expression;
2138 pp->c_base.assignment_expression = (pp_fun) pp_cxx_assignment_expression;
2139 pp->c_base.expression = (pp_fun) pp_cxx_expression;
2140 pp->enclosing_scope = global_namespace;