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
665 unary-operator: one of
669 __alignof__ unary-expression
670 __alignof__ ( type-id ) */
673 pp_cxx_unary_expression (cxx_pretty_printer
*pp
, tree t
)
675 enum tree_code code
= TREE_CODE (t
);
680 pp_cxx_new_expression (pp
, t
);
684 case VEC_DELETE_EXPR
:
685 pp_cxx_delete_expression (pp
, t
);
690 pp_cxx_identifier (pp
, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
691 pp_cxx_whitespace (pp
);
692 if (TYPE_P (TREE_OPERAND (t
, 0)))
694 pp_cxx_left_paren (pp
);
695 pp_cxx_type_id (pp
, TREE_OPERAND (t
, 0));
696 pp_cxx_right_paren (pp
);
699 pp_unary_expression (pp
, TREE_OPERAND (t
, 0));
702 case UNARY_PLUS_EXPR
:
704 pp_cxx_cast_expression (pp
, TREE_OPERAND (t
, 0));
708 pp_c_unary_expression (pp_c_base (pp
), t
);
715 ( type-id ) cast-expression */
718 pp_cxx_cast_expression (cxx_pretty_printer
*pp
, tree t
)
720 switch (TREE_CODE (t
))
723 pp_cxx_type_id (pp
, TREE_TYPE (t
));
724 pp_cxx_call_argument_list (pp
, TREE_OPERAND (t
, 0));
728 pp_c_cast_expression (pp_c_base (pp
), t
);
735 pm-expression .* cast-expression
736 pm-expression ->* cast-expression */
739 pp_cxx_pm_expression (cxx_pretty_printer
*pp
, tree t
)
741 switch (TREE_CODE (t
))
743 /* Handle unfortunate OFFESET_REF overloading here. */
745 if (TYPE_P (TREE_OPERAND (t
, 0)))
747 pp_cxx_qualified_id (pp
, t
);
750 /* Else fall through. */
753 pp_cxx_pm_expression (pp
, TREE_OPERAND (t
, 0));
756 pp_cxx_cast_expression (pp
, TREE_OPERAND (t
, 1));
761 pp_cxx_cast_expression (pp
, t
);
766 /* multiplicative-expression:
768 multiplicative-expression * pm-expression
769 multiplicative-expression / pm-expression
770 multiplicative-expression % pm-expression */
773 pp_cxx_multiplicative_expression (cxx_pretty_printer
*pp
, tree e
)
775 enum tree_code code
= TREE_CODE (e
);
781 pp_cxx_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
783 if (code
== MULT_EXPR
)
785 else if (code
== TRUNC_DIV_EXPR
)
790 pp_cxx_pm_expression (pp
, TREE_OPERAND (e
, 1));
794 pp_cxx_pm_expression (pp
, e
);
799 /* conditional-expression:
800 logical-or-expression
801 logical-or-expression ? expression : assignment-expression */
804 pp_cxx_conditional_expression (cxx_pretty_printer
*pp
, tree e
)
806 if (TREE_CODE (e
) == COND_EXPR
)
808 pp_c_logical_or_expression (pp_c_base (pp
), TREE_OPERAND (e
, 0));
812 pp_cxx_expression (pp
, TREE_OPERAND (e
, 1));
814 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 2));
817 pp_c_logical_or_expression (pp_c_base (pp
), e
);
820 /* Pretty-print a compound assignment operator token as indicated by T. */
823 pp_cxx_assignment_operator (cxx_pretty_printer
*pp
, tree t
)
827 switch (TREE_CODE (t
))
850 op
= tree_code_name
[TREE_CODE (t
)];
854 pp_cxx_identifier (pp
, op
);
858 /* assignment-expression:
859 conditional-expression
860 logical-or-expression assignment-operator assignment-expression
864 throw assignment-expression(opt)
866 assignment-operator: one of
867 = *= /= %= += -= >>= <<= &= ^= |= */
870 pp_cxx_assignment_expression (cxx_pretty_printer
*pp
, tree e
)
872 switch (TREE_CODE (e
))
876 pp_c_logical_or_expression (pp_c_base (pp
), TREE_OPERAND (e
, 0));
880 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 1));
884 pp_cxx_identifier (pp
, "throw");
885 if (TREE_OPERAND (e
, 0))
886 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 0));
890 pp_c_logical_or_expression (pp_c_base (pp
), TREE_OPERAND (e
, 0));
891 pp_cxx_assignment_operator (pp
, TREE_OPERAND (e
, 1));
892 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 2));
896 pp_cxx_conditional_expression (pp
, e
);
902 pp_cxx_expression (cxx_pretty_printer
*pp
, tree t
)
904 switch (TREE_CODE (t
))
909 pp_cxx_constant (pp
, t
);
913 pp_cxx_unqualified_id (pp
, t
);
921 pp_cxx_qualified_id (pp
, t
);
933 case TEMPLATE_TYPE_PARM
:
934 case TEMPLATE_PARM_INDEX
:
935 case TEMPLATE_TEMPLATE_PARM
:
937 pp_cxx_primary_expression (pp
, t
);
941 case DYNAMIC_CAST_EXPR
:
942 case STATIC_CAST_EXPR
:
943 case REINTERPRET_CAST_EXPR
:
944 case CONST_CAST_EXPR
:
948 case EMPTY_CLASS_EXPR
:
950 case PSEUDO_DTOR_EXPR
:
953 pp_cxx_postfix_expression (pp
, t
);
958 pp_cxx_new_expression (pp
, t
);
962 case VEC_DELETE_EXPR
:
963 pp_cxx_delete_expression (pp
, t
);
968 pp_cxx_unary_expression (pp
, t
);
972 pp_cxx_cast_expression (pp
, t
);
978 pp_cxx_pm_expression (pp
, t
);
984 pp_cxx_multiplicative_expression (pp
, t
);
988 pp_cxx_conditional_expression (pp
, t
);
995 pp_cxx_assignment_expression (pp
, t
);
998 case NON_DEPENDENT_EXPR
:
999 case MUST_NOT_THROW_EXPR
:
1000 pp_cxx_expression (pp
, t
);
1004 pp_c_expression (pp_c_base (pp
), t
);
1012 /* function-specifier:
1018 pp_cxx_function_specifier (cxx_pretty_printer
*pp
, tree t
)
1020 switch (TREE_CODE (t
))
1023 if (DECL_VIRTUAL_P (t
))
1024 pp_cxx_identifier (pp
, "virtual");
1025 else if (DECL_CONSTRUCTOR_P (t
) && DECL_NONCONVERTING_P (t
))
1026 pp_cxx_identifier (pp
, "explicit");
1028 pp_c_function_specifier (pp_c_base (pp
), t
);
1035 /* decl-specifier-seq:
1036 decl-specifier-seq(opt) decl-specifier
1039 storage-class-specifier
1046 pp_cxx_decl_specifier_seq (cxx_pretty_printer
*pp
, tree t
)
1048 switch (TREE_CODE (t
))
1054 pp_cxx_storage_class_specifier (pp
, t
);
1055 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (t
));
1059 pp_cxx_identifier (pp
, "typedef");
1060 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (t
));
1064 if (TYPE_PTRMEMFUNC_P (t
))
1066 tree pfm
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
1067 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (TREE_TYPE (pfm
)));
1068 pp_cxx_whitespace (pp
);
1069 pp_cxx_ptr_operator (pp
, t
);
1074 /* Constructors don't have return types. And conversion functions
1075 do not have a type-specifier in their return types. */
1076 if (DECL_CONSTRUCTOR_P (t
) || DECL_CONV_FN_P (t
))
1077 pp_cxx_function_specifier (pp
, t
);
1078 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1079 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (TREE_TYPE (t
)));
1082 pp_c_declaration_specifiers (pp_c_base (pp
), t
);
1087 /* simple-type-specifier:
1088 ::(opt) nested-name-specifier(opt) type-name
1089 ::(opt) nested-name-specifier(opt) template(opt) template-id
1103 pp_cxx_simple_type_specifier (cxx_pretty_printer
*pp
, tree t
)
1105 switch (TREE_CODE (t
))
1110 pp_cxx_qualified_id (pp
, t
);
1113 case TEMPLATE_TYPE_PARM
:
1114 case TEMPLATE_TEMPLATE_PARM
:
1115 case TEMPLATE_PARM_INDEX
:
1116 pp_cxx_unqualified_id (pp
, t
);
1120 pp_cxx_identifier (pp
, "typename");
1121 pp_cxx_nested_name_specifier (pp
, TYPE_CONTEXT (t
));
1122 pp_cxx_unqualified_id (pp
, TYPE_NAME (t
));
1126 pp_c_type_specifier (pp_c_base (pp
), t
);
1131 /* type-specifier-seq:
1132 type-specifier type-specifier-seq(opt)
1135 simple-type-specifier
1138 elaborated-type-specifier
1142 pp_cxx_type_specifier_seq (cxx_pretty_printer
*pp
, tree t
)
1144 switch (TREE_CODE (t
))
1147 case TEMPLATE_TYPE_PARM
:
1148 case TEMPLATE_TEMPLATE_PARM
:
1150 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1151 pp_cxx_cv_qualifier_seq (pp
, t
);
1152 pp_cxx_simple_type_specifier (pp
, t
);
1156 pp_cxx_type_specifier_seq (pp
, TREE_TYPE (t
));
1157 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (t
));
1158 pp_cxx_nested_name_specifier (pp
, TYPE_METHOD_BASETYPE (t
));
1162 if (!(TREE_CODE (t
) == FUNCTION_DECL
&& DECL_CONSTRUCTOR_P (t
)))
1163 pp_c_specifier_qualifier_list (pp_c_base (pp
), t
);
1168 * cv-qualifier-seq(opt)
1170 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1173 pp_cxx_ptr_operator (cxx_pretty_printer
*pp
, tree t
)
1175 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
1177 switch (TREE_CODE (t
))
1179 case REFERENCE_TYPE
:
1181 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
1182 || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t
)))
1183 pp_cxx_ptr_operator (pp
, TREE_TYPE (t
));
1184 if (TREE_CODE (t
) == POINTER_TYPE
)
1187 pp_cxx_cv_qualifier_seq (pp
, t
);
1194 if (TYPE_PTRMEMFUNC_P (t
))
1196 pp_cxx_left_paren (pp
);
1197 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEMFUNC_OBJECT_TYPE (t
));
1202 if (TYPE_PTR_TO_MEMBER_P (t
))
1204 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1205 pp_cxx_left_paren (pp
);
1206 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEM_CLASS_TYPE (t
));
1208 pp_cxx_cv_qualifier_seq (pp
, t
);
1211 /* else fall through. */
1214 pp_unsupported_tree (pp
, t
);
1220 pp_cxx_implicit_parameter_type (tree mf
)
1222 return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf
))));
1226 parameter-declaration:
1227 decl-specifier-seq declarator
1228 decl-specifier-seq declarator = assignment-expression
1229 decl-specifier-seq abstract-declarator(opt)
1230 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1233 pp_cxx_parameter_declaration (cxx_pretty_printer
*pp
, tree t
)
1235 pp_cxx_decl_specifier_seq (pp
, t
);
1237 pp_cxx_abstract_declarator (pp
, t
);
1239 pp_cxx_declarator (pp
, t
);
1242 /* parameter-declaration-clause:
1243 parameter-declaration-list(opt) ...(opt)
1244 parameter-declaration-list , ...
1246 parameter-declaration-list:
1247 parameter-declaration
1248 parameter-declaration-list , parameter-declaration */
1251 pp_cxx_parameter_declaration_clause (cxx_pretty_printer
*pp
, tree t
)
1253 tree args
= TYPE_P (t
) ? NULL
: FUNCTION_FIRST_USER_PARM (t
);
1255 TYPE_P (t
) ? TYPE_ARG_TYPES (t
) : FUNCTION_FIRST_USER_PARMTYPE (t
);
1256 const bool abstract
= args
== NULL
1257 || pp_c_base (pp
)->flags
& pp_c_flag_abstract
;
1260 /* Skip artificial parameter for nonstatic member functions. */
1261 if (TREE_CODE (t
) == METHOD_TYPE
)
1262 types
= TREE_CHAIN (types
);
1264 pp_cxx_left_paren (pp
);
1265 for (; args
; args
= TREE_CHAIN (args
), types
= TREE_CHAIN (types
))
1268 pp_cxx_separate_with (pp
, ',');
1270 pp_cxx_parameter_declaration (pp
, abstract
? TREE_VALUE (types
) : args
);
1271 if (!abstract
&& pp_c_base (pp
)->flags
& pp_cxx_flag_default_argument
)
1273 pp_cxx_whitespace (pp
);
1275 pp_cxx_whitespace (pp
);
1276 pp_cxx_assignment_expression (pp
, TREE_PURPOSE (types
));
1279 pp_cxx_right_paren (pp
);
1282 /* exception-specification:
1283 throw ( type-id-list(opt) )
1287 type-id-list , type-id */
1290 pp_cxx_exception_specification (cxx_pretty_printer
*pp
, tree t
)
1292 tree ex_spec
= TYPE_RAISES_EXCEPTIONS (t
);
1294 if (!TYPE_NOTHROW_P (t
) && ex_spec
== NULL
)
1296 pp_cxx_identifier (pp
, "throw");
1297 pp_cxx_left_paren (pp
);
1298 for (; ex_spec
&& TREE_VALUE (ex_spec
); ex_spec
= TREE_CHAIN (ex_spec
))
1300 pp_cxx_type_id (pp
, TREE_VALUE (ex_spec
));
1301 if (TREE_CHAIN (ex_spec
))
1302 pp_cxx_separate_with (pp
, ',');
1304 pp_cxx_right_paren (pp
);
1307 /* direct-declarator:
1309 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1310 exception-specification(opt)
1311 direct-declaration [ constant-expression(opt) ]
1315 pp_cxx_direct_declarator (cxx_pretty_printer
*pp
, tree t
)
1317 switch (TREE_CODE (t
))
1325 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (t
));
1326 pp_cxx_id_expression (pp
, DECL_NAME (t
));
1328 pp_cxx_abstract_declarator (pp
, TREE_TYPE (t
));
1332 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
1333 pp_cxx_id_expression (pp
, t
);
1334 pp_cxx_parameter_declaration_clause (pp
, t
);
1336 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1338 pp_base (pp
)->padding
= pp_before
;
1339 pp_cxx_cv_qualifier_seq (pp
, pp_cxx_implicit_parameter_type (t
));
1342 pp_cxx_exception_specification (pp
, TREE_TYPE (t
));
1347 case TEMPLATE_TYPE_PARM
:
1348 case TEMPLATE_PARM_INDEX
:
1349 case TEMPLATE_TEMPLATE_PARM
:
1353 pp_c_direct_declarator (pp_c_base (pp
), t
);
1360 ptr-operator declarator */
1363 pp_cxx_declarator (cxx_pretty_printer
*pp
, tree t
)
1365 pp_cxx_direct_declarator (pp
, t
);
1368 /* ctor-initializer:
1369 : mem-initializer-list
1371 mem-initializer-list:
1373 mem-initializer , mem-initializer-list
1376 mem-initializer-id ( expression-list(opt) )
1379 ::(opt) nested-name-specifier(opt) class-name
1383 pp_cxx_ctor_initializer (cxx_pretty_printer
*pp
, tree t
)
1385 t
= TREE_OPERAND (t
, 0);
1386 pp_cxx_whitespace (pp
);
1388 pp_cxx_whitespace (pp
);
1389 for (; t
; t
= TREE_CHAIN (t
))
1391 pp_cxx_primary_expression (pp
, TREE_PURPOSE (t
));
1392 pp_cxx_call_argument_list (pp
, TREE_VALUE (t
));
1394 pp_cxx_separate_with (pp
, ',');
1398 /* function-definition:
1399 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1400 decl-specifier-seq(opt) declarator function-try-block */
1403 pp_cxx_function_definition (cxx_pretty_printer
*pp
, tree t
)
1405 tree saved_scope
= pp
->enclosing_scope
;
1406 pp_cxx_decl_specifier_seq (pp
, t
);
1407 pp_cxx_declarator (pp
, t
);
1408 pp_needs_newline (pp
) = true;
1409 pp
->enclosing_scope
= DECL_CONTEXT (t
);
1410 if (DECL_SAVED_TREE (t
))
1411 pp_cxx_statement (pp
, DECL_SAVED_TREE (t
));
1414 pp_cxx_semicolon (pp
);
1415 pp_needs_newline (pp
) = true;
1418 pp
->enclosing_scope
= saved_scope
;
1421 /* abstract-declarator:
1422 ptr-operator abstract-declarator(opt)
1423 direct-abstract-declarator */
1426 pp_cxx_abstract_declarator (cxx_pretty_printer
*pp
, tree t
)
1428 if (TYPE_PTRMEM_P (t
) || TYPE_PTRMEMFUNC_P (t
))
1429 pp_cxx_right_paren (pp
);
1430 else if (POINTER_TYPE_P (t
))
1432 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
1433 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1434 pp_cxx_right_paren (pp
);
1437 pp_cxx_direct_abstract_declarator (pp
, t
);
1440 /* direct-abstract-declarator:
1441 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1442 cv-qualifier-seq(opt) exception-specification(opt)
1443 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1444 ( abstract-declarator ) */
1447 pp_cxx_direct_abstract_declarator (cxx_pretty_printer
*pp
, tree t
)
1449 switch (TREE_CODE (t
))
1451 case REFERENCE_TYPE
:
1452 pp_cxx_abstract_declarator (pp
, t
);
1456 if (TYPE_PTRMEMFUNC_P (t
))
1457 pp_cxx_direct_abstract_declarator (pp
, TYPE_PTRMEMFUNC_FN_TYPE (t
));
1462 pp_cxx_parameter_declaration_clause (pp
, t
);
1463 pp_cxx_direct_abstract_declarator (pp
, TREE_TYPE (t
));
1464 if (TREE_CODE (t
) == METHOD_TYPE
)
1466 pp_base (pp
)->padding
= pp_before
;
1467 pp_cxx_cv_qualifier_seq
1468 (pp
, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))));
1470 pp_cxx_exception_specification (pp
, t
);
1474 case TEMPLATE_TYPE_PARM
:
1475 case TEMPLATE_TEMPLATE_PARM
:
1476 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1477 case UNBOUND_CLASS_TEMPLATE
:
1481 pp_c_direct_abstract_declarator (pp_c_base (pp
), t
);
1487 type-specifier-seq abstract-declarator(opt) */
1490 pp_cxx_type_id (cxx_pretty_printer
*pp
, tree t
)
1492 pp_flags saved_flags
= pp_c_base (pp
)->flags
;
1493 pp_c_base (pp
)->flags
|= pp_c_flag_abstract
;
1495 switch (TREE_CODE (t
))
1502 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1503 case UNBOUND_CLASS_TEMPLATE
:
1504 case TEMPLATE_TEMPLATE_PARM
:
1505 case TEMPLATE_TYPE_PARM
:
1506 case TEMPLATE_PARM_INDEX
:
1509 case TEMPLATE_ID_EXPR
:
1510 pp_cxx_type_specifier_seq (pp
, t
);
1514 pp_c_type_id (pp_c_base (pp
), t
);
1518 pp_c_base (pp
)->flags
= saved_flags
;
1521 /* template-argument-list:
1523 template-argument-list, template-argument
1526 assignment-expression
1531 pp_cxx_template_argument_list (cxx_pretty_printer
*pp
, tree t
)
1536 for (i
= 0; i
< TREE_VEC_LENGTH (t
); ++i
)
1538 tree arg
= TREE_VEC_ELT (t
, i
);
1540 pp_cxx_separate_with (pp
, ',');
1541 if (TYPE_P (arg
) || (TREE_CODE (arg
) == TEMPLATE_DECL
1542 && TYPE_P (DECL_TEMPLATE_RESULT (arg
))))
1543 pp_cxx_type_id (pp
, arg
);
1545 pp_cxx_expression (pp
, arg
);
1551 pp_cxx_exception_declaration (cxx_pretty_printer
*pp
, tree t
)
1553 t
= DECL_EXPR_DECL (t
);
1554 pp_cxx_type_specifier_seq (pp
, t
);
1556 pp_cxx_abstract_declarator (pp
, t
);
1558 pp_cxx_declarator (pp
, t
);
1564 pp_cxx_statement (cxx_pretty_printer
*pp
, tree t
)
1566 switch (TREE_CODE (t
))
1568 case CTOR_INITIALIZER
:
1569 pp_cxx_ctor_initializer (pp
, t
);
1573 pp_cxx_identifier (pp
, "using");
1574 pp_cxx_identifier (pp
, "namespace");
1575 if (DECL_CONTEXT (t
))
1576 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
1577 pp_cxx_qualified_id (pp
, USING_STMT_NAMESPACE (t
));
1581 pp_cxx_identifier (pp
, "using");
1582 pp_cxx_nested_name_specifier (pp
, USING_DECL_SCOPE (t
));
1583 pp_cxx_unqualified_id (pp
, DECL_NAME (t
));
1590 try compound-statement handler-seq */
1592 pp_maybe_newline_and_indent (pp
, 0);
1593 pp_cxx_identifier (pp
, "try");
1594 pp_newline_and_indent (pp
, 3);
1595 pp_cxx_statement (pp
, TRY_STMTS (t
));
1596 pp_newline_and_indent (pp
, -3);
1600 pp_cxx_statement (pp
, TRY_HANDLERS (t
));
1605 handler handler-seq(opt)
1608 catch ( exception-declaration ) compound-statement
1610 exception-declaration:
1611 type-specifier-seq declarator
1612 type-specifier-seq abstract-declarator
1615 pp_cxx_identifier (pp
, "catch");
1616 pp_cxx_left_paren (pp
);
1617 pp_cxx_exception_declaration (pp
, HANDLER_PARMS (t
));
1618 pp_cxx_right_paren (pp
);
1619 pp_indentation (pp
) += 3;
1620 pp_needs_newline (pp
) = true;
1621 pp_cxx_statement (pp
, HANDLER_BODY (t
));
1622 pp_indentation (pp
) -= 3;
1623 pp_needs_newline (pp
) = true;
1626 /* selection-statement:
1627 if ( expression ) statement
1628 if ( expression ) statement else statement */
1630 pp_cxx_identifier (pp
, "if");
1631 pp_cxx_whitespace (pp
);
1632 pp_cxx_left_paren (pp
);
1633 pp_cxx_expression (pp
, IF_COND (t
));
1634 pp_cxx_right_paren (pp
);
1635 pp_newline_and_indent (pp
, 2);
1636 pp_cxx_statement (pp
, THEN_CLAUSE (t
));
1637 pp_newline_and_indent (pp
, -2);
1638 if (ELSE_CLAUSE (t
))
1640 tree else_clause
= ELSE_CLAUSE (t
);
1641 pp_cxx_identifier (pp
, "else");
1642 if (TREE_CODE (else_clause
) == IF_STMT
)
1643 pp_cxx_whitespace (pp
);
1645 pp_newline_and_indent (pp
, 2);
1646 pp_cxx_statement (pp
, else_clause
);
1647 if (TREE_CODE (else_clause
) != IF_STMT
)
1648 pp_newline_and_indent (pp
, -2);
1653 pp_cxx_identifier (pp
, "switch");
1655 pp_cxx_left_paren (pp
);
1656 pp_cxx_expression (pp
, SWITCH_STMT_COND (t
));
1657 pp_cxx_right_paren (pp
);
1658 pp_indentation (pp
) += 3;
1659 pp_needs_newline (pp
) = true;
1660 pp_cxx_statement (pp
, SWITCH_STMT_BODY (t
));
1661 pp_newline_and_indent (pp
, -3);
1664 /* iteration-statement:
1665 while ( expression ) statement
1666 do statement while ( expression ) ;
1667 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1668 for ( declaration expression(opt) ; expression(opt) ) statement */
1670 pp_cxx_identifier (pp
, "while");
1672 pp_cxx_left_paren (pp
);
1673 pp_cxx_expression (pp
, WHILE_COND (t
));
1674 pp_cxx_right_paren (pp
);
1675 pp_newline_and_indent (pp
, 3);
1676 pp_cxx_statement (pp
, WHILE_BODY (t
));
1677 pp_indentation (pp
) -= 3;
1678 pp_needs_newline (pp
) = true;
1682 pp_cxx_identifier (pp
, "do");
1683 pp_newline_and_indent (pp
, 3);
1684 pp_cxx_statement (pp
, DO_BODY (t
));
1685 pp_newline_and_indent (pp
, -3);
1686 pp_cxx_identifier (pp
, "while");
1688 pp_cxx_left_paren (pp
);
1689 pp_cxx_expression (pp
, DO_COND (t
));
1690 pp_cxx_right_paren (pp
);
1691 pp_cxx_semicolon (pp
);
1692 pp_needs_newline (pp
) = true;
1696 pp_cxx_identifier (pp
, "for");
1698 pp_cxx_left_paren (pp
);
1699 if (FOR_INIT_STMT (t
))
1700 pp_cxx_statement (pp
, FOR_INIT_STMT (t
));
1702 pp_cxx_semicolon (pp
);
1703 pp_needs_newline (pp
) = false;
1704 pp_cxx_whitespace (pp
);
1706 pp_cxx_expression (pp
, FOR_COND (t
));
1707 pp_cxx_semicolon (pp
);
1708 pp_needs_newline (pp
) = false;
1709 pp_cxx_whitespace (pp
);
1711 pp_cxx_expression (pp
, FOR_EXPR (t
));
1712 pp_cxx_right_paren (pp
);
1713 pp_newline_and_indent (pp
, 3);
1714 pp_cxx_statement (pp
, FOR_BODY (t
));
1715 pp_indentation (pp
) -= 3;
1716 pp_needs_newline (pp
) = true;
1722 return expression(opt) ; */
1725 pp_identifier (pp
, TREE_CODE (t
) == BREAK_STMT
? "break" : "continue");
1726 pp_cxx_semicolon (pp
);
1727 pp_needs_newline (pp
) = true;
1730 /* expression-statement:
1731 expression(opt) ; */
1733 pp_cxx_expression (pp
, EXPR_STMT_EXPR (t
));
1734 pp_cxx_semicolon (pp
);
1735 pp_needs_newline (pp
) = true;
1739 pp_cxx_identifier (pp
, "try");
1740 pp_newline_and_indent (pp
, 2);
1741 pp_cxx_statement (pp
, CLEANUP_BODY (t
));
1742 pp_newline_and_indent (pp
, -2);
1743 pp_cxx_identifier (pp
, CLEANUP_EH_ONLY (t
) ? "catch" : "finally");
1744 pp_newline_and_indent (pp
, 2);
1745 pp_cxx_statement (pp
, CLEANUP_EXPR (t
));
1746 pp_newline_and_indent (pp
, -2);
1750 pp_cxx_declaration (pp
, t
);
1754 pp_c_statement (pp_c_base (pp
), t
);
1759 /* original-namespace-definition:
1760 namespace identifier { namespace-body }
1762 As an edge case, we also handle unnamed namespace definition here. */
1765 pp_cxx_original_namespace_definition (cxx_pretty_printer
*pp
, tree t
)
1767 pp_cxx_identifier (pp
, "namespace");
1768 if (DECL_CONTEXT (t
))
1769 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
1771 pp_cxx_unqualified_id (pp
, t
);
1772 pp_cxx_whitespace (pp
);
1773 pp_cxx_left_brace (pp
);
1774 /* We do not print the namespace-body. */
1775 pp_cxx_whitespace (pp
);
1776 pp_cxx_right_brace (pp
);
1782 namespace-alias-definition:
1783 namespace identifier = qualified-namespace-specifier ;
1785 qualified-namespace-specifier:
1786 ::(opt) nested-name-specifier(opt) namespace-name */
1789 pp_cxx_namespace_alias_definition (cxx_pretty_printer
*pp
, tree t
)
1791 pp_cxx_identifier (pp
, "namespace");
1792 if (DECL_CONTEXT (t
))
1793 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
1794 pp_cxx_unqualified_id (pp
, t
);
1795 pp_cxx_whitespace (pp
);
1797 pp_cxx_whitespace (pp
);
1798 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t
)))
1799 pp_cxx_nested_name_specifier (pp
,
1800 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t
)));
1801 pp_cxx_qualified_id (pp
, DECL_NAMESPACE_ALIAS (t
));
1802 pp_cxx_semicolon (pp
);
1805 /* simple-declaration:
1806 decl-specifier-seq(opt) init-declarator-list(opt) */
1809 pp_cxx_simple_declaration (cxx_pretty_printer
*pp
, tree t
)
1811 pp_cxx_decl_specifier_seq (pp
, t
);
1812 pp_cxx_init_declarator (pp
, t
);
1813 pp_cxx_semicolon (pp
);
1814 pp_needs_newline (pp
) = true;
1818 template-parameter-list:
1820 template-parameter-list , template-parameter */
1823 pp_cxx_template_parameter_list (cxx_pretty_printer
*pp
, tree t
)
1825 const int n
= TREE_VEC_LENGTH (t
);
1827 for (i
= 0; i
< n
; ++i
)
1830 pp_cxx_separate_with (pp
, ',');
1831 pp_cxx_template_parameter (pp
, TREE_VEC_ELT (t
, i
));
1835 /* template-parameter:
1837 parameter-declaration
1840 class identifier(opt)
1841 class identifier(op) = type-id
1842 typename identifier(opt)
1843 typename identifier(opt) = type-id
1844 template < template-parameter-list > class identifier(opt)
1845 template < template-parameter-list > class identifier(opt) = template-name */
1848 pp_cxx_template_parameter (cxx_pretty_printer
*pp
, tree t
)
1850 tree parameter
= TREE_VALUE (t
);
1851 switch (TREE_CODE (parameter
))
1854 pp_cxx_identifier (pp
, "class");
1855 if (DECL_NAME (parameter
))
1856 pp_cxx_tree_identifier (pp
, DECL_NAME (parameter
));
1857 /* FIXME: Chech if we should print also default argument. */
1861 pp_cxx_parameter_declaration (pp
, parameter
);
1868 pp_unsupported_tree (pp
, t
);
1873 /* Pretty-print a template parameter in the canonical form
1874 "template-parameter-<level>-<position in parameter list>". */
1877 pp_cxx_canonical_template_parameter (cxx_pretty_printer
*pp
, tree parm
)
1879 const enum tree_code code
= TREE_CODE (parm
);
1881 /* Brings type template parameters to the canonical forms. */
1882 if (code
== TEMPLATE_TYPE_PARM
|| code
== TEMPLATE_TEMPLATE_PARM
1883 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
)
1884 parm
= TEMPLATE_TYPE_PARM_INDEX (parm
);
1886 pp_cxx_begin_template_argument_list (pp
);
1887 pp_cxx_identifier (pp
, "template-parameter-");
1888 pp_wide_integer (pp
, TEMPLATE_PARM_LEVEL (parm
));
1890 pp_wide_integer (pp
, TEMPLATE_PARM_IDX (parm
) + 1);
1891 pp_cxx_end_template_argument_list (pp
);
1895 template-declaration:
1896 export(opt) template < template-parameter-list > declaration */
1899 pp_cxx_template_declaration (cxx_pretty_printer
*pp
, tree t
)
1901 tree tmpl
= most_general_template (t
);
1905 pp_maybe_newline_and_indent (pp
, 0);
1906 for (level
= DECL_TEMPLATE_PARMS (tmpl
); level
; level
= TREE_CHAIN (level
))
1908 pp_cxx_identifier (pp
, "template");
1909 pp_cxx_begin_template_argument_list (pp
);
1910 pp_cxx_template_parameter_list (pp
, TREE_VALUE (level
));
1911 pp_cxx_end_template_argument_list (pp
);
1912 pp_newline_and_indent (pp
, 3);
1915 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_SAVED_TREE (t
))
1916 pp_cxx_function_definition (pp
, t
);
1918 pp_cxx_simple_declaration (pp
, t
);
1922 pp_cxx_explicit_specialization (cxx_pretty_printer
*pp
, tree t
)
1924 pp_unsupported_tree (pp
, t
);
1928 pp_cxx_explicit_instantiation (cxx_pretty_printer
*pp
, tree t
)
1930 pp_unsupported_tree (pp
, t
);
1937 template-declaration
1938 explicit-instantiation
1939 explicit-specialization
1940 linkage-specification
1941 namespace-definition
1946 namespace-alias-definition
1949 static_assert-declaration */
1951 pp_cxx_declaration (cxx_pretty_printer
*pp
, tree t
)
1953 if (TREE_CODE (t
) == STATIC_ASSERT
)
1955 pp_cxx_identifier (pp
, "static_assert");
1956 pp_cxx_left_paren (pp
);
1957 pp_cxx_expression (pp
, STATIC_ASSERT_CONDITION (t
));
1958 pp_cxx_separate_with (pp
, ',');
1959 pp_cxx_expression (pp
, STATIC_ASSERT_MESSAGE (t
));
1960 pp_cxx_right_paren (pp
);
1962 else if (!DECL_LANG_SPECIFIC (t
))
1963 pp_cxx_simple_declaration (pp
, t
);
1964 else if (DECL_USE_TEMPLATE (t
))
1965 switch (DECL_USE_TEMPLATE (t
))
1968 pp_cxx_template_declaration (pp
, t
);
1972 pp_cxx_explicit_specialization (pp
, t
);
1976 pp_cxx_explicit_instantiation (pp
, t
);
1982 else switch (TREE_CODE (t
))
1986 pp_cxx_simple_declaration (pp
, t
);
1990 if (DECL_SAVED_TREE (t
))
1991 pp_cxx_function_definition (pp
, t
);
1993 pp_cxx_simple_declaration (pp
, t
);
1996 case NAMESPACE_DECL
:
1997 if (DECL_NAMESPACE_ALIAS (t
))
1998 pp_cxx_namespace_alias_definition (pp
, t
);
2000 pp_cxx_original_namespace_definition (pp
, t
);
2004 pp_unsupported_tree (pp
, t
);
2010 typedef c_pretty_print_fn pp_fun
;
2012 /* Initialization of a C++ pretty-printer object. */
2015 pp_cxx_pretty_printer_init (cxx_pretty_printer
*pp
)
2017 pp_c_pretty_printer_init (pp_c_base (pp
));
2018 pp_set_line_maximum_length (pp
, 0);
2020 pp
->c_base
.declaration
= (pp_fun
) pp_cxx_declaration
;
2021 pp
->c_base
.declaration_specifiers
= (pp_fun
) pp_cxx_decl_specifier_seq
;
2022 pp
->c_base
.function_specifier
= (pp_fun
) pp_cxx_function_specifier
;
2023 pp
->c_base
.type_specifier_seq
= (pp_fun
) pp_cxx_type_specifier_seq
;
2024 pp
->c_base
.declarator
= (pp_fun
) pp_cxx_declarator
;
2025 pp
->c_base
.direct_declarator
= (pp_fun
) pp_cxx_direct_declarator
;
2026 pp
->c_base
.parameter_list
= (pp_fun
) pp_cxx_parameter_declaration_clause
;
2027 pp
->c_base
.type_id
= (pp_fun
) pp_cxx_type_id
;
2028 pp
->c_base
.abstract_declarator
= (pp_fun
) pp_cxx_abstract_declarator
;
2029 pp
->c_base
.direct_abstract_declarator
=
2030 (pp_fun
) pp_cxx_direct_abstract_declarator
;
2031 pp
->c_base
.simple_type_specifier
= (pp_fun
)pp_cxx_simple_type_specifier
;
2033 /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
2035 pp
->c_base
.constant
= (pp_fun
) pp_cxx_constant
;
2036 pp
->c_base
.id_expression
= (pp_fun
) pp_cxx_id_expression
;
2037 pp
->c_base
.primary_expression
= (pp_fun
) pp_cxx_primary_expression
;
2038 pp
->c_base
.postfix_expression
= (pp_fun
) pp_cxx_postfix_expression
;
2039 pp
->c_base
.unary_expression
= (pp_fun
) pp_cxx_unary_expression
;
2040 pp
->c_base
.multiplicative_expression
= (pp_fun
) pp_cxx_multiplicative_expression
;
2041 pp
->c_base
.conditional_expression
= (pp_fun
) pp_cxx_conditional_expression
;
2042 pp
->c_base
.assignment_expression
= (pp_fun
) pp_cxx_assignment_expression
;
2043 pp
->c_base
.expression
= (pp_fun
) pp_cxx_expression
;
2044 pp
->enclosing_scope
= global_namespace
;