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
);
300 pp_cxx_id_expression (cxx_pretty_printer
*pp
, tree t
)
302 if (TREE_CODE (t
) == OVERLOAD
)
304 if (DECL_P (t
) && DECL_CONTEXT (t
))
305 pp_cxx_qualified_id (pp
, t
);
307 pp_cxx_unqualified_id (pp
, t
);
310 /* primary-expression:
314 :: operator-function-id
320 pp_cxx_primary_expression (cxx_pretty_printer
*pp
, tree t
)
322 switch (TREE_CODE (t
))
327 pp_c_constant (pp_c_base (pp
), t
);
331 t
= BASELINK_FUNCTIONS (t
);
339 pp_cxx_id_expression (pp
, t
);
343 case TEMPLATE_TYPE_PARM
:
344 case TEMPLATE_TEMPLATE_PARM
:
345 case TEMPLATE_PARM_INDEX
:
346 pp_cxx_unqualified_id (pp
, t
);
350 pp_cxx_left_paren (pp
);
351 pp_cxx_statement (pp
, STMT_EXPR_STMT (t
));
352 pp_cxx_right_paren (pp
);
356 pp_c_primary_expression (pp_c_base (pp
), t
);
361 /* postfix-expression:
363 postfix-expression [ expression ]
364 postfix-expression ( expression-list(opt) )
365 simple-type-specifier ( expression-list(opt) )
366 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
367 typename ::(opt) nested-name-specifier template(opt)
368 template-id ( expression-list(opt) )
369 postfix-expression . template(opt) ::(opt) id-expression
370 postfix-expression -> template(opt) ::(opt) id-expression
371 postfix-expression . pseudo-destructor-name
372 postfix-expression -> pseudo-destructor-name
373 postfix-expression ++
374 postfix-expression --
375 dynamic_cast < type-id > ( expression )
376 static_cast < type-id > ( expression )
377 reinterpret_cast < type-id > ( expression )
378 const_cast < type-id > ( expression )
379 typeid ( expression )
380 typeif ( type-id ) */
383 pp_cxx_postfix_expression (cxx_pretty_printer
*pp
, tree t
)
385 enum tree_code code
= TREE_CODE (t
);
392 tree fun
= TREE_OPERAND (t
, 0);
393 tree args
= TREE_OPERAND (t
, 1);
394 tree saved_scope
= pp
->enclosing_scope
;
396 if (TREE_CODE (fun
) == ADDR_EXPR
)
397 fun
= TREE_OPERAND (fun
, 0);
399 /* In templates, where there is no way to tell whether a given
400 call uses an actual member function. So the parser builds
401 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
402 instantiation time. */
403 if (TREE_CODE (fun
) != FUNCTION_DECL
)
405 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun
))
407 tree object
= code
== AGGR_INIT_EXPR
&& AGGR_INIT_VIA_CTOR_P (t
)
408 ? TREE_OPERAND (t
, 2)
411 while (TREE_CODE (object
) == NOP_EXPR
)
412 object
= TREE_OPERAND (object
, 0);
414 if (TREE_CODE (object
) == ADDR_EXPR
)
415 object
= TREE_OPERAND (object
, 0);
417 if (TREE_CODE (TREE_TYPE (object
)) != POINTER_TYPE
)
419 pp_cxx_postfix_expression (pp
, object
);
424 pp_cxx_postfix_expression (pp
, object
);
427 args
= TREE_CHAIN (args
);
428 pp
->enclosing_scope
= strip_pointer_operator (TREE_TYPE (object
));
431 pp_cxx_postfix_expression (pp
, fun
);
432 pp
->enclosing_scope
= saved_scope
;
433 pp_cxx_call_argument_list (pp
, args
);
435 if (code
== AGGR_INIT_EXPR
&& AGGR_INIT_VIA_CTOR_P (t
))
437 pp_cxx_separate_with (pp
, ',');
438 pp_cxx_postfix_expression (pp
, TREE_OPERAND (t
, 2));
451 pp_cxx_primary_expression (pp
, t
);
454 case DYNAMIC_CAST_EXPR
:
455 case STATIC_CAST_EXPR
:
456 case REINTERPRET_CAST_EXPR
:
457 case CONST_CAST_EXPR
:
458 if (code
== DYNAMIC_CAST_EXPR
)
459 pp_cxx_identifier (pp
, "dynamic_cast");
460 else if (code
== STATIC_CAST_EXPR
)
461 pp_cxx_identifier (pp
, "static_cast");
462 else if (code
== REINTERPRET_CAST_EXPR
)
463 pp_cxx_identifier (pp
, "reinterpret_cast");
465 pp_cxx_identifier (pp
, "const_cast");
466 pp_cxx_begin_template_argument_list (pp
);
467 pp_cxx_type_id (pp
, TREE_TYPE (t
));
468 pp_cxx_end_template_argument_list (pp
);
470 pp_cxx_expression (pp
, TREE_OPERAND (t
, 0));
474 case EMPTY_CLASS_EXPR
:
475 pp_cxx_type_id (pp
, TREE_TYPE (t
));
481 t
= TREE_OPERAND (t
, 0);
482 pp_cxx_identifier (pp
, "typeid");
485 pp_cxx_type_id (pp
, t
);
487 pp_cxx_expression (pp
, t
);
491 case PSEUDO_DTOR_EXPR
:
492 pp_cxx_postfix_expression (pp
, TREE_OPERAND (t
, 0));
494 pp_cxx_qualified_id (pp
, TREE_OPERAND (t
, 1));
495 pp_cxx_colon_colon (pp
);
497 pp_cxx_unqualified_id (pp
, TREE_OPERAND (t
, 2));
501 pp_cxx_postfix_expression (pp
, TREE_OPERAND (t
, 0));
506 pp_c_postfix_expression (pp_c_base (pp
), t
);
512 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
513 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
519 type-specifier-seq new-declarator(opt)
522 ptr-operator new-declarator(opt)
523 direct-new-declarator
525 direct-new-declarator
527 direct-new-declarator [ constant-expression ]
530 ( expression-list(opt) ) */
533 pp_cxx_new_expression (cxx_pretty_printer
*pp
, tree t
)
535 enum tree_code code
= TREE_CODE (t
);
540 if (NEW_EXPR_USE_GLOBAL (t
))
541 pp_cxx_colon_colon (pp
);
542 pp_cxx_identifier (pp
, "new");
543 if (TREE_OPERAND (t
, 0))
545 pp_cxx_call_argument_list (pp
, TREE_OPERAND (t
, 0));
548 /* FIXME: array-types are built with one more element. */
549 pp_cxx_type_id (pp
, TREE_OPERAND (t
, 1));
550 if (TREE_OPERAND (t
, 2))
553 t
= TREE_OPERAND (t
, 2);
554 if (TREE_CODE (t
) == TREE_LIST
)
555 pp_c_expression_list (pp_c_base (pp
), t
);
556 else if (t
== void_zero_node
)
557 ; /* OK, empty initializer list. */
559 pp_cxx_expression (pp
, t
);
565 pp_unsupported_tree (pp
, t
);
569 /* delete-expression:
570 ::(opt) delete cast-expression
571 ::(opt) delete [ ] cast-expression */
574 pp_cxx_delete_expression (cxx_pretty_printer
*pp
, tree t
)
576 enum tree_code code
= TREE_CODE (t
);
580 case VEC_DELETE_EXPR
:
581 if (DELETE_EXPR_USE_GLOBAL (t
))
582 pp_cxx_colon_colon (pp
);
583 pp_cxx_identifier (pp
, "delete");
584 if (code
== VEC_DELETE_EXPR
)
586 pp_left_bracket (pp
);
587 pp_right_bracket (pp
);
589 pp_c_cast_expression (pp_c_base (pp
), TREE_OPERAND (t
, 0));
593 pp_unsupported_tree (pp
, t
);
601 unary-operator cast-expression
602 sizeof unary-expression
607 unary-operator: one of
611 __alignof__ unary-expression
612 __alignof__ ( type-id ) */
615 pp_cxx_unary_expression (cxx_pretty_printer
*pp
, tree t
)
617 enum tree_code code
= TREE_CODE (t
);
622 pp_cxx_new_expression (pp
, t
);
626 case VEC_DELETE_EXPR
:
627 pp_cxx_delete_expression (pp
, t
);
632 pp_cxx_identifier (pp
, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
633 pp_cxx_whitespace (pp
);
634 if (TYPE_P (TREE_OPERAND (t
, 0)))
636 pp_cxx_left_paren (pp
);
637 pp_cxx_type_id (pp
, TREE_OPERAND (t
, 0));
638 pp_cxx_right_paren (pp
);
641 pp_unary_expression (pp
, TREE_OPERAND (t
, 0));
644 case UNARY_PLUS_EXPR
:
646 pp_cxx_cast_expression (pp
, TREE_OPERAND (t
, 0));
650 pp_c_unary_expression (pp_c_base (pp
), t
);
657 ( type-id ) cast-expression */
660 pp_cxx_cast_expression (cxx_pretty_printer
*pp
, tree t
)
662 switch (TREE_CODE (t
))
665 pp_cxx_type_id (pp
, TREE_TYPE (t
));
666 pp_cxx_call_argument_list (pp
, TREE_OPERAND (t
, 0));
670 pp_c_cast_expression (pp_c_base (pp
), t
);
677 pm-expression .* cast-expression
678 pm-expression ->* cast-expression */
681 pp_cxx_pm_expression (cxx_pretty_printer
*pp
, tree t
)
683 switch (TREE_CODE (t
))
685 /* Handle unfortunate OFFESET_REF overloading here. */
687 if (TYPE_P (TREE_OPERAND (t
, 0)))
689 pp_cxx_qualified_id (pp
, t
);
692 /* Else fall through. */
695 pp_cxx_pm_expression (pp
, TREE_OPERAND (t
, 0));
698 pp_cxx_cast_expression (pp
, TREE_OPERAND (t
, 1));
703 pp_cxx_cast_expression (pp
, t
);
708 /* multiplicative-expression:
710 multiplicative-expression * pm-expression
711 multiplicative-expression / pm-expression
712 multiplicative-expression % pm-expression */
715 pp_cxx_multiplicative_expression (cxx_pretty_printer
*pp
, tree e
)
717 enum tree_code code
= TREE_CODE (e
);
723 pp_cxx_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
725 if (code
== MULT_EXPR
)
727 else if (code
== TRUNC_DIV_EXPR
)
732 pp_cxx_pm_expression (pp
, TREE_OPERAND (e
, 1));
736 pp_cxx_pm_expression (pp
, e
);
741 /* conditional-expression:
742 logical-or-expression
743 logical-or-expression ? expression : assignment-expression */
746 pp_cxx_conditional_expression (cxx_pretty_printer
*pp
, tree e
)
748 if (TREE_CODE (e
) == COND_EXPR
)
750 pp_c_logical_or_expression (pp_c_base (pp
), TREE_OPERAND (e
, 0));
754 pp_cxx_expression (pp
, TREE_OPERAND (e
, 1));
756 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 2));
759 pp_c_logical_or_expression (pp_c_base (pp
), e
);
762 /* Pretty-print a compound assignment operator token as indicated by T. */
765 pp_cxx_assignment_operator (cxx_pretty_printer
*pp
, tree t
)
769 switch (TREE_CODE (t
))
792 op
= tree_code_name
[TREE_CODE (t
)];
796 pp_cxx_identifier (pp
, op
);
800 /* assignment-expression:
801 conditional-expression
802 logical-or-expression assignment-operator assignment-expression
806 throw assignment-expression(opt)
808 assignment-operator: one of
809 = *= /= %= += -= >>= <<= &= ^= |= */
812 pp_cxx_assignment_expression (cxx_pretty_printer
*pp
, tree e
)
814 switch (TREE_CODE (e
))
818 pp_c_logical_or_expression (pp_c_base (pp
), TREE_OPERAND (e
, 0));
822 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 1));
826 pp_cxx_identifier (pp
, "throw");
827 if (TREE_OPERAND (e
, 0))
828 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 0));
832 pp_c_logical_or_expression (pp_c_base (pp
), TREE_OPERAND (e
, 0));
833 pp_cxx_assignment_operator (pp
, TREE_OPERAND (e
, 1));
834 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 2));
838 pp_cxx_conditional_expression (pp
, e
);
844 pp_cxx_expression (cxx_pretty_printer
*pp
, tree t
)
846 switch (TREE_CODE (t
))
851 pp_c_constant (pp_c_base (pp
), t
);
855 pp_cxx_unqualified_id (pp
, t
);
863 pp_cxx_qualified_id (pp
, t
);
875 case TEMPLATE_TYPE_PARM
:
876 case TEMPLATE_PARM_INDEX
:
877 case TEMPLATE_TEMPLATE_PARM
:
879 pp_cxx_primary_expression (pp
, t
);
883 case DYNAMIC_CAST_EXPR
:
884 case STATIC_CAST_EXPR
:
885 case REINTERPRET_CAST_EXPR
:
886 case CONST_CAST_EXPR
:
890 case EMPTY_CLASS_EXPR
:
892 case PSEUDO_DTOR_EXPR
:
895 pp_cxx_postfix_expression (pp
, t
);
900 pp_cxx_new_expression (pp
, t
);
904 case VEC_DELETE_EXPR
:
905 pp_cxx_delete_expression (pp
, t
);
910 pp_cxx_unary_expression (pp
, t
);
914 pp_cxx_cast_expression (pp
, t
);
920 pp_cxx_pm_expression (pp
, t
);
926 pp_cxx_multiplicative_expression (pp
, t
);
930 pp_cxx_conditional_expression (pp
, t
);
937 pp_cxx_assignment_expression (pp
, t
);
940 case NON_DEPENDENT_EXPR
:
941 case MUST_NOT_THROW_EXPR
:
942 pp_cxx_expression (pp
, t
);
946 pp_c_expression (pp_c_base (pp
), t
);
954 /* function-specifier:
960 pp_cxx_function_specifier (cxx_pretty_printer
*pp
, tree t
)
962 switch (TREE_CODE (t
))
965 if (DECL_VIRTUAL_P (t
))
966 pp_cxx_identifier (pp
, "virtual");
967 else if (DECL_CONSTRUCTOR_P (t
) && DECL_NONCONVERTING_P (t
))
968 pp_cxx_identifier (pp
, "explicit");
970 pp_c_function_specifier (pp_c_base (pp
), t
);
977 /* decl-specifier-seq:
978 decl-specifier-seq(opt) decl-specifier
981 storage-class-specifier
988 pp_cxx_decl_specifier_seq (cxx_pretty_printer
*pp
, tree t
)
990 switch (TREE_CODE (t
))
996 pp_cxx_storage_class_specifier (pp
, t
);
997 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (t
));
1001 pp_cxx_identifier (pp
, "typedef");
1002 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (t
));
1006 if (TYPE_PTRMEMFUNC_P (t
))
1008 tree pfm
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
1009 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (TREE_TYPE (pfm
)));
1010 pp_cxx_whitespace (pp
);
1011 pp_cxx_ptr_operator (pp
, t
);
1016 /* Constructors don't have return types. And conversion functions
1017 do not have a type-specifier in their return types. */
1018 if (DECL_CONSTRUCTOR_P (t
) || DECL_CONV_FN_P (t
))
1019 pp_cxx_function_specifier (pp
, t
);
1020 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1021 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (TREE_TYPE (t
)));
1024 pp_c_declaration_specifiers (pp_c_base (pp
), t
);
1029 /* simple-type-specifier:
1030 ::(opt) nested-name-specifier(opt) type-name
1031 ::(opt) nested-name-specifier(opt) template(opt) template-id
1045 pp_cxx_simple_type_specifier (cxx_pretty_printer
*pp
, tree t
)
1047 switch (TREE_CODE (t
))
1052 pp_cxx_qualified_id (pp
, t
);
1055 case TEMPLATE_TYPE_PARM
:
1056 case TEMPLATE_TEMPLATE_PARM
:
1057 case TEMPLATE_PARM_INDEX
:
1058 pp_cxx_unqualified_id (pp
, t
);
1062 pp_cxx_identifier (pp
, "typename");
1063 pp_cxx_nested_name_specifier (pp
, TYPE_CONTEXT (t
));
1064 pp_cxx_unqualified_id (pp
, TYPE_NAME (t
));
1068 pp_c_type_specifier (pp_c_base (pp
), t
);
1073 /* type-specifier-seq:
1074 type-specifier type-specifier-seq(opt)
1077 simple-type-specifier
1080 elaborated-type-specifier
1084 pp_cxx_type_specifier_seq (cxx_pretty_printer
*pp
, tree t
)
1086 switch (TREE_CODE (t
))
1089 case TEMPLATE_TYPE_PARM
:
1090 case TEMPLATE_TEMPLATE_PARM
:
1092 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1093 pp_cxx_cv_qualifier_seq (pp
, t
);
1094 pp_cxx_simple_type_specifier (pp
, t
);
1098 pp_cxx_type_specifier_seq (pp
, TREE_TYPE (t
));
1099 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (t
));
1100 pp_cxx_nested_name_specifier (pp
, TYPE_METHOD_BASETYPE (t
));
1104 if (!(TREE_CODE (t
) == FUNCTION_DECL
&& DECL_CONSTRUCTOR_P (t
)))
1105 pp_c_specifier_qualifier_list (pp_c_base (pp
), t
);
1110 * cv-qualifier-seq(opt)
1112 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1115 pp_cxx_ptr_operator (cxx_pretty_printer
*pp
, tree t
)
1117 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
1119 switch (TREE_CODE (t
))
1121 case REFERENCE_TYPE
:
1123 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
1124 || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t
)))
1125 pp_cxx_ptr_operator (pp
, TREE_TYPE (t
));
1126 if (TREE_CODE (t
) == POINTER_TYPE
)
1129 pp_cxx_cv_qualifier_seq (pp
, t
);
1136 if (TYPE_PTRMEMFUNC_P (t
))
1138 pp_cxx_left_paren (pp
);
1139 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEMFUNC_OBJECT_TYPE (t
));
1144 if (TYPE_PTR_TO_MEMBER_P (t
))
1146 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1147 pp_cxx_left_paren (pp
);
1148 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEM_CLASS_TYPE (t
));
1150 pp_cxx_cv_qualifier_seq (pp
, t
);
1153 /* else fall through. */
1156 pp_unsupported_tree (pp
, t
);
1162 pp_cxx_implicit_parameter_type (tree mf
)
1164 return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf
))));
1168 parameter-declaration:
1169 decl-specifier-seq declarator
1170 decl-specifier-seq declarator = assignment-expression
1171 decl-specifier-seq abstract-declarator(opt)
1172 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1175 pp_cxx_parameter_declaration (cxx_pretty_printer
*pp
, tree t
)
1177 pp_cxx_decl_specifier_seq (pp
, t
);
1179 pp_cxx_abstract_declarator (pp
, t
);
1181 pp_cxx_declarator (pp
, t
);
1184 /* parameter-declaration-clause:
1185 parameter-declaration-list(opt) ...(opt)
1186 parameter-declaration-list , ...
1188 parameter-declaration-list:
1189 parameter-declaration
1190 parameter-declaration-list , parameter-declaration */
1193 pp_cxx_parameter_declaration_clause (cxx_pretty_printer
*pp
, tree t
)
1195 tree args
= TYPE_P (t
) ? NULL
: FUNCTION_FIRST_USER_PARM (t
);
1197 TYPE_P (t
) ? TYPE_ARG_TYPES (t
) : FUNCTION_FIRST_USER_PARMTYPE (t
);
1198 const bool abstract
= args
== NULL
1199 || pp_c_base (pp
)->flags
& pp_c_flag_abstract
;
1202 /* Skip artificial parameter for nonstatic member functions. */
1203 if (TREE_CODE (t
) == METHOD_TYPE
)
1204 types
= TREE_CHAIN (types
);
1206 pp_cxx_left_paren (pp
);
1207 for (; args
; args
= TREE_CHAIN (args
), types
= TREE_CHAIN (types
))
1210 pp_cxx_separate_with (pp
, ',');
1212 pp_cxx_parameter_declaration (pp
, abstract
? TREE_VALUE (types
) : args
);
1213 if (!abstract
&& pp_c_base (pp
)->flags
& pp_cxx_flag_default_argument
)
1215 pp_cxx_whitespace (pp
);
1217 pp_cxx_whitespace (pp
);
1218 pp_cxx_assignment_expression (pp
, TREE_PURPOSE (types
));
1221 pp_cxx_right_paren (pp
);
1224 /* exception-specification:
1225 throw ( type-id-list(opt) )
1229 type-id-list , type-id */
1232 pp_cxx_exception_specification (cxx_pretty_printer
*pp
, tree t
)
1234 tree ex_spec
= TYPE_RAISES_EXCEPTIONS (t
);
1236 if (!TYPE_NOTHROW_P (t
) && ex_spec
== NULL
)
1238 pp_cxx_identifier (pp
, "throw");
1239 pp_cxx_left_paren (pp
);
1240 for (; ex_spec
&& TREE_VALUE (ex_spec
); ex_spec
= TREE_CHAIN (ex_spec
))
1242 pp_cxx_type_id (pp
, TREE_VALUE (ex_spec
));
1243 if (TREE_CHAIN (ex_spec
))
1244 pp_cxx_separate_with (pp
, ',');
1246 pp_cxx_right_paren (pp
);
1249 /* direct-declarator:
1251 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1252 exception-specification(opt)
1253 direct-declaration [ constant-expression(opt) ]
1257 pp_cxx_direct_declarator (cxx_pretty_printer
*pp
, tree t
)
1259 switch (TREE_CODE (t
))
1267 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (t
));
1268 pp_cxx_id_expression (pp
, DECL_NAME (t
));
1270 pp_cxx_abstract_declarator (pp
, TREE_TYPE (t
));
1274 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
1275 pp_cxx_id_expression (pp
, t
);
1276 pp_cxx_parameter_declaration_clause (pp
, t
);
1278 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1280 pp_base (pp
)->padding
= pp_before
;
1281 pp_cxx_cv_qualifier_seq (pp
, pp_cxx_implicit_parameter_type (t
));
1284 pp_cxx_exception_specification (pp
, TREE_TYPE (t
));
1289 case TEMPLATE_TYPE_PARM
:
1290 case TEMPLATE_PARM_INDEX
:
1291 case TEMPLATE_TEMPLATE_PARM
:
1295 pp_c_direct_declarator (pp_c_base (pp
), t
);
1302 ptr-operator declarator */
1305 pp_cxx_declarator (cxx_pretty_printer
*pp
, tree t
)
1307 pp_cxx_direct_declarator (pp
, t
);
1310 /* ctor-initializer:
1311 : mem-initializer-list
1313 mem-initializer-list:
1315 mem-initializer , mem-initializer-list
1318 mem-initializer-id ( expression-list(opt) )
1321 ::(opt) nested-name-specifier(opt) class-name
1325 pp_cxx_ctor_initializer (cxx_pretty_printer
*pp
, tree t
)
1327 t
= TREE_OPERAND (t
, 0);
1328 pp_cxx_whitespace (pp
);
1330 pp_cxx_whitespace (pp
);
1331 for (; t
; t
= TREE_CHAIN (t
))
1333 pp_cxx_primary_expression (pp
, TREE_PURPOSE (t
));
1334 pp_cxx_call_argument_list (pp
, TREE_VALUE (t
));
1336 pp_cxx_separate_with (pp
, ',');
1340 /* function-definition:
1341 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1342 decl-specifier-seq(opt) declarator function-try-block */
1345 pp_cxx_function_definition (cxx_pretty_printer
*pp
, tree t
)
1347 tree saved_scope
= pp
->enclosing_scope
;
1348 pp_cxx_decl_specifier_seq (pp
, t
);
1349 pp_cxx_declarator (pp
, t
);
1350 pp_needs_newline (pp
) = true;
1351 pp
->enclosing_scope
= DECL_CONTEXT (t
);
1352 if (DECL_SAVED_TREE (t
))
1353 pp_cxx_statement (pp
, DECL_SAVED_TREE (t
));
1356 pp_cxx_semicolon (pp
);
1357 pp_needs_newline (pp
) = true;
1360 pp
->enclosing_scope
= saved_scope
;
1363 /* abstract-declarator:
1364 ptr-operator abstract-declarator(opt)
1365 direct-abstract-declarator */
1368 pp_cxx_abstract_declarator (cxx_pretty_printer
*pp
, tree t
)
1370 if (TYPE_PTRMEM_P (t
) || TYPE_PTRMEMFUNC_P (t
))
1371 pp_cxx_right_paren (pp
);
1372 else if (POINTER_TYPE_P (t
))
1374 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
1375 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1376 pp_cxx_right_paren (pp
);
1379 pp_cxx_direct_abstract_declarator (pp
, t
);
1382 /* direct-abstract-declarator:
1383 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1384 cv-qualifier-seq(opt) exception-specification(opt)
1385 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1386 ( abstract-declarator ) */
1389 pp_cxx_direct_abstract_declarator (cxx_pretty_printer
*pp
, tree t
)
1391 switch (TREE_CODE (t
))
1393 case REFERENCE_TYPE
:
1394 pp_cxx_abstract_declarator (pp
, t
);
1398 if (TYPE_PTRMEMFUNC_P (t
))
1399 pp_cxx_direct_abstract_declarator (pp
, TYPE_PTRMEMFUNC_FN_TYPE (t
));
1404 pp_cxx_parameter_declaration_clause (pp
, t
);
1405 pp_cxx_direct_abstract_declarator (pp
, TREE_TYPE (t
));
1406 if (TREE_CODE (t
) == METHOD_TYPE
)
1408 pp_base (pp
)->padding
= pp_before
;
1409 pp_cxx_cv_qualifier_seq
1410 (pp
, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))));
1412 pp_cxx_exception_specification (pp
, t
);
1416 case TEMPLATE_TYPE_PARM
:
1417 case TEMPLATE_TEMPLATE_PARM
:
1418 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1419 case UNBOUND_CLASS_TEMPLATE
:
1423 pp_c_direct_abstract_declarator (pp_c_base (pp
), t
);
1429 type-specifier-seq abstract-declarator(opt) */
1432 pp_cxx_type_id (cxx_pretty_printer
*pp
, tree t
)
1434 pp_flags saved_flags
= pp_c_base (pp
)->flags
;
1435 pp_c_base (pp
)->flags
|= pp_c_flag_abstract
;
1437 switch (TREE_CODE (t
))
1444 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1445 case UNBOUND_CLASS_TEMPLATE
:
1446 case TEMPLATE_TEMPLATE_PARM
:
1447 case TEMPLATE_TYPE_PARM
:
1448 case TEMPLATE_PARM_INDEX
:
1451 case TEMPLATE_ID_EXPR
:
1452 pp_cxx_type_specifier_seq (pp
, t
);
1456 pp_c_type_id (pp_c_base (pp
), t
);
1460 pp_c_base (pp
)->flags
= saved_flags
;
1463 /* template-argument-list:
1465 template-argument-list, template-argument
1468 assignment-expression
1473 pp_cxx_template_argument_list (cxx_pretty_printer
*pp
, tree t
)
1478 for (i
= 0; i
< TREE_VEC_LENGTH (t
); ++i
)
1480 tree arg
= TREE_VEC_ELT (t
, i
);
1482 pp_cxx_separate_with (pp
, ',');
1483 if (TYPE_P (arg
) || (TREE_CODE (arg
) == TEMPLATE_DECL
1484 && TYPE_P (DECL_TEMPLATE_RESULT (arg
))))
1485 pp_cxx_type_id (pp
, arg
);
1487 pp_cxx_expression (pp
, arg
);
1493 pp_cxx_exception_declaration (cxx_pretty_printer
*pp
, tree t
)
1495 t
= DECL_EXPR_DECL (t
);
1496 pp_cxx_type_specifier_seq (pp
, t
);
1498 pp_cxx_abstract_declarator (pp
, t
);
1500 pp_cxx_declarator (pp
, t
);
1506 pp_cxx_statement (cxx_pretty_printer
*pp
, tree t
)
1508 switch (TREE_CODE (t
))
1510 case CTOR_INITIALIZER
:
1511 pp_cxx_ctor_initializer (pp
, t
);
1515 pp_cxx_identifier (pp
, "using");
1516 pp_cxx_identifier (pp
, "namespace");
1517 pp_cxx_qualified_id (pp
, USING_STMT_NAMESPACE (t
));
1521 pp_cxx_identifier (pp
, "using");
1522 pp_cxx_nested_name_specifier (pp
, USING_DECL_SCOPE (t
));
1523 pp_cxx_unqualified_id (pp
, DECL_NAME (t
));
1530 try compound-statement handler-seq */
1532 pp_maybe_newline_and_indent (pp
, 0);
1533 pp_cxx_identifier (pp
, "try");
1534 pp_newline_and_indent (pp
, 3);
1535 pp_cxx_statement (pp
, TRY_STMTS (t
));
1536 pp_newline_and_indent (pp
, -3);
1540 pp_cxx_statement (pp
, TRY_HANDLERS (t
));
1545 handler handler-seq(opt)
1548 catch ( exception-declaration ) compound-statement
1550 exception-declaration:
1551 type-specifier-seq declarator
1552 type-specifier-seq abstract-declarator
1555 pp_cxx_identifier (pp
, "catch");
1556 pp_cxx_left_paren (pp
);
1557 pp_cxx_exception_declaration (pp
, HANDLER_PARMS (t
));
1558 pp_cxx_right_paren (pp
);
1559 pp_indentation (pp
) += 3;
1560 pp_needs_newline (pp
) = true;
1561 pp_cxx_statement (pp
, HANDLER_BODY (t
));
1562 pp_indentation (pp
) -= 3;
1563 pp_needs_newline (pp
) = true;
1566 /* selection-statement:
1567 if ( expression ) statement
1568 if ( expression ) statement else statement */
1570 pp_cxx_identifier (pp
, "if");
1571 pp_cxx_whitespace (pp
);
1572 pp_cxx_left_paren (pp
);
1573 pp_cxx_expression (pp
, IF_COND (t
));
1574 pp_cxx_right_paren (pp
);
1575 pp_newline_and_indent (pp
, 2);
1576 pp_cxx_statement (pp
, THEN_CLAUSE (t
));
1577 pp_newline_and_indent (pp
, -2);
1578 if (ELSE_CLAUSE (t
))
1580 tree else_clause
= ELSE_CLAUSE (t
);
1581 pp_cxx_identifier (pp
, "else");
1582 if (TREE_CODE (else_clause
) == IF_STMT
)
1583 pp_cxx_whitespace (pp
);
1585 pp_newline_and_indent (pp
, 2);
1586 pp_cxx_statement (pp
, else_clause
);
1587 if (TREE_CODE (else_clause
) != IF_STMT
)
1588 pp_newline_and_indent (pp
, -2);
1593 pp_cxx_identifier (pp
, "switch");
1595 pp_cxx_left_paren (pp
);
1596 pp_cxx_expression (pp
, SWITCH_STMT_COND (t
));
1597 pp_cxx_right_paren (pp
);
1598 pp_indentation (pp
) += 3;
1599 pp_needs_newline (pp
) = true;
1600 pp_cxx_statement (pp
, SWITCH_STMT_BODY (t
));
1601 pp_newline_and_indent (pp
, -3);
1604 /* iteration-statement:
1605 while ( expression ) statement
1606 do statement while ( expression ) ;
1607 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1608 for ( declaration expression(opt) ; expression(opt) ) statement */
1610 pp_cxx_identifier (pp
, "while");
1612 pp_cxx_left_paren (pp
);
1613 pp_cxx_expression (pp
, WHILE_COND (t
));
1614 pp_cxx_right_paren (pp
);
1615 pp_newline_and_indent (pp
, 3);
1616 pp_cxx_statement (pp
, WHILE_BODY (t
));
1617 pp_indentation (pp
) -= 3;
1618 pp_needs_newline (pp
) = true;
1622 pp_cxx_identifier (pp
, "do");
1623 pp_newline_and_indent (pp
, 3);
1624 pp_cxx_statement (pp
, DO_BODY (t
));
1625 pp_newline_and_indent (pp
, -3);
1626 pp_cxx_identifier (pp
, "while");
1628 pp_cxx_left_paren (pp
);
1629 pp_cxx_expression (pp
, DO_COND (t
));
1630 pp_cxx_right_paren (pp
);
1631 pp_cxx_semicolon (pp
);
1632 pp_needs_newline (pp
) = true;
1636 pp_cxx_identifier (pp
, "for");
1638 pp_cxx_left_paren (pp
);
1639 if (FOR_INIT_STMT (t
))
1640 pp_cxx_statement (pp
, FOR_INIT_STMT (t
));
1642 pp_cxx_semicolon (pp
);
1643 pp_needs_newline (pp
) = false;
1644 pp_cxx_whitespace (pp
);
1646 pp_cxx_expression (pp
, FOR_COND (t
));
1647 pp_cxx_semicolon (pp
);
1648 pp_needs_newline (pp
) = false;
1649 pp_cxx_whitespace (pp
);
1651 pp_cxx_expression (pp
, FOR_EXPR (t
));
1652 pp_cxx_right_paren (pp
);
1653 pp_newline_and_indent (pp
, 3);
1654 pp_cxx_statement (pp
, FOR_BODY (t
));
1655 pp_indentation (pp
) -= 3;
1656 pp_needs_newline (pp
) = true;
1662 return expression(opt) ; */
1665 pp_identifier (pp
, TREE_CODE (t
) == BREAK_STMT
? "break" : "continue");
1666 pp_cxx_semicolon (pp
);
1667 pp_needs_newline (pp
) = true;
1670 /* expression-statement:
1671 expression(opt) ; */
1673 pp_cxx_expression (pp
, EXPR_STMT_EXPR (t
));
1674 pp_cxx_semicolon (pp
);
1675 pp_needs_newline (pp
) = true;
1679 pp_cxx_identifier (pp
, "try");
1680 pp_newline_and_indent (pp
, 2);
1681 pp_cxx_statement (pp
, CLEANUP_BODY (t
));
1682 pp_newline_and_indent (pp
, -2);
1683 pp_cxx_identifier (pp
, CLEANUP_EH_ONLY (t
) ? "catch" : "finally");
1684 pp_newline_and_indent (pp
, 2);
1685 pp_cxx_statement (pp
, CLEANUP_EXPR (t
));
1686 pp_newline_and_indent (pp
, -2);
1690 pp_c_statement (pp_c_base (pp
), t
);
1695 /* original-namespace-definition:
1696 namespace identifier { namespace-body }
1698 As an edge case, we also handle unnamed namespace definition here. */
1701 pp_cxx_original_namespace_definition (cxx_pretty_printer
*pp
, tree t
)
1703 pp_cxx_identifier (pp
, "namespace");
1705 pp_cxx_unqualified_id (pp
, t
);
1706 pp_cxx_whitespace (pp
);
1707 pp_cxx_left_brace (pp
);
1708 /* We do not print the namespace-body. */
1709 pp_cxx_whitespace (pp
);
1710 pp_cxx_right_brace (pp
);
1716 namespace-alias-definition:
1717 namespace identifier = qualified-namespace-specifier ;
1719 qualified-namespace-specifier:
1720 ::(opt) nested-name-specifier(opt) namespace-name */
1723 pp_cxx_namespace_alias_definition (cxx_pretty_printer
*pp
, tree t
)
1725 pp_cxx_identifier (pp
, "namespace");
1726 pp_cxx_unqualified_id (pp
, t
);
1727 pp_cxx_whitespace (pp
);
1729 pp_cxx_whitespace (pp
);
1730 pp_cxx_qualified_id (pp
, DECL_NAMESPACE_ALIAS (t
));
1731 pp_cxx_semicolon (pp
);
1734 /* simple-declaration:
1735 decl-specifier-seq(opt) init-declarator-list(opt) */
1738 pp_cxx_simple_declaration (cxx_pretty_printer
*pp
, tree t
)
1740 pp_cxx_decl_specifier_seq (pp
, t
);
1741 pp_cxx_init_declarator (pp
, t
);
1742 pp_cxx_semicolon (pp
);
1743 pp_needs_newline (pp
) = true;
1747 template-parameter-list:
1749 template-parameter-list , template-parameter */
1752 pp_cxx_template_parameter_list (cxx_pretty_printer
*pp
, tree t
)
1754 const int n
= TREE_VEC_LENGTH (t
);
1756 for (i
= 0; i
< n
; ++i
)
1759 pp_cxx_separate_with (pp
, ',');
1760 pp_cxx_template_parameter (pp
, TREE_VEC_ELT (t
, i
));
1764 /* template-parameter:
1766 parameter-declaration
1769 class identifier(opt)
1770 class identifier(op) = type-id
1771 typename identifier(opt)
1772 typename identifier(opt) = type-id
1773 template < template-parameter-list > class identifier(opt)
1774 template < template-parameter-list > class identifier(opt) = template-name
1778 pp_cxx_template_parameter (cxx_pretty_printer
*pp
, tree t
)
1780 tree parameter
= TREE_VALUE (t
);
1781 switch (TREE_CODE (parameter
))
1784 pp_cxx_identifier (pp
, "class");
1785 if (DECL_NAME (parameter
))
1786 pp_cxx_tree_identifier (pp
, DECL_NAME (parameter
));
1787 /* FIXME: Chech if we should print also default argument. */
1791 pp_cxx_parameter_declaration (pp
, parameter
);
1798 pp_unsupported_tree (pp
, t
);
1803 /* Pretty-print a template parameter in the canonical form
1804 "template-parameter-<level>-<position in parameter list>". */
1807 pp_cxx_canonical_template_parameter (cxx_pretty_printer
*pp
, tree parm
)
1809 const enum tree_code code
= TREE_CODE (parm
);
1811 /* Brings type template parameters to the canonical forms. */
1812 if (code
== TEMPLATE_TYPE_PARM
|| code
== TEMPLATE_TEMPLATE_PARM
1813 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
)
1814 parm
= TEMPLATE_TYPE_PARM_INDEX (parm
);
1816 pp_cxx_begin_template_argument_list (pp
);
1817 pp_cxx_identifier (pp
, "template-parameter-");
1818 pp_wide_integer (pp
, TEMPLATE_PARM_LEVEL (parm
));
1820 pp_wide_integer (pp
, TEMPLATE_PARM_IDX (parm
) + 1);
1821 pp_cxx_end_template_argument_list (pp
);
1825 template-declaration:
1826 export(opt) template < template-parameter-list > declaration */
1829 pp_cxx_template_declaration (cxx_pretty_printer
*pp
, tree t
)
1831 tree tmpl
= most_general_template (t
);
1835 pp_maybe_newline_and_indent (pp
, 0);
1836 for (level
= DECL_TEMPLATE_PARMS (tmpl
); level
; level
= TREE_CHAIN (level
))
1838 pp_cxx_identifier (pp
, "template");
1839 pp_cxx_begin_template_argument_list (pp
);
1840 pp_cxx_template_parameter_list (pp
, TREE_VALUE (level
));
1841 pp_cxx_end_template_argument_list (pp
);
1842 pp_newline_and_indent (pp
, 3);
1845 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_SAVED_TREE (t
))
1846 pp_cxx_function_definition (pp
, t
);
1848 pp_cxx_simple_declaration (pp
, t
);
1852 pp_cxx_explicit_specialization (cxx_pretty_printer
*pp
, tree t
)
1854 pp_unsupported_tree (pp
, t
);
1858 pp_cxx_explicit_instantiation (cxx_pretty_printer
*pp
, tree t
)
1860 pp_unsupported_tree (pp
, t
);
1867 template-declaration
1868 explicit-instantiation
1869 explicit-specialization
1870 linkage-specification
1871 namespace-definition
1876 namespace-alias-definition
1880 pp_cxx_declaration (cxx_pretty_printer
*pp
, tree t
)
1882 if (!DECL_LANG_SPECIFIC (t
))
1883 pp_cxx_simple_declaration (pp
, t
);
1884 else if (DECL_USE_TEMPLATE (t
))
1885 switch (DECL_USE_TEMPLATE (t
))
1888 pp_cxx_template_declaration (pp
, t
);
1892 pp_cxx_explicit_specialization (pp
, t
);
1896 pp_cxx_explicit_instantiation (pp
, t
);
1902 else switch (TREE_CODE (t
))
1906 pp_cxx_simple_declaration (pp
, t
);
1910 if (DECL_SAVED_TREE (t
))
1911 pp_cxx_function_definition (pp
, t
);
1913 pp_cxx_simple_declaration (pp
, t
);
1916 case NAMESPACE_DECL
:
1917 if (DECL_NAMESPACE_ALIAS (t
))
1918 pp_cxx_namespace_alias_definition (pp
, t
);
1920 pp_cxx_original_namespace_definition (pp
, t
);
1924 pp_unsupported_tree (pp
, t
);
1930 typedef c_pretty_print_fn pp_fun
;
1932 /* Initialization of a C++ pretty-printer object. */
1935 pp_cxx_pretty_printer_init (cxx_pretty_printer
*pp
)
1937 pp_c_pretty_printer_init (pp_c_base (pp
));
1938 pp_set_line_maximum_length (pp
, 0);
1940 pp
->c_base
.declaration
= (pp_fun
) pp_cxx_declaration
;
1941 pp
->c_base
.declaration_specifiers
= (pp_fun
) pp_cxx_decl_specifier_seq
;
1942 pp
->c_base
.function_specifier
= (pp_fun
) pp_cxx_function_specifier
;
1943 pp
->c_base
.type_specifier_seq
= (pp_fun
) pp_cxx_type_specifier_seq
;
1944 pp
->c_base
.declarator
= (pp_fun
) pp_cxx_declarator
;
1945 pp
->c_base
.direct_declarator
= (pp_fun
) pp_cxx_direct_declarator
;
1946 pp
->c_base
.parameter_list
= (pp_fun
) pp_cxx_parameter_declaration_clause
;
1947 pp
->c_base
.type_id
= (pp_fun
) pp_cxx_type_id
;
1948 pp
->c_base
.abstract_declarator
= (pp_fun
) pp_cxx_abstract_declarator
;
1949 pp
->c_base
.direct_abstract_declarator
=
1950 (pp_fun
) pp_cxx_direct_abstract_declarator
;
1951 pp
->c_base
.simple_type_specifier
= (pp_fun
)pp_cxx_simple_type_specifier
;
1953 /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
1955 pp
->c_base
.id_expression
= (pp_fun
) pp_cxx_id_expression
;
1956 pp
->c_base
.primary_expression
= (pp_fun
) pp_cxx_primary_expression
;
1957 pp
->c_base
.postfix_expression
= (pp_fun
) pp_cxx_postfix_expression
;
1958 pp
->c_base
.unary_expression
= (pp_fun
) pp_cxx_unary_expression
;
1959 pp
->c_base
.multiplicative_expression
= (pp_fun
) pp_cxx_multiplicative_expression
;
1960 pp
->c_base
.conditional_expression
= (pp_fun
) pp_cxx_conditional_expression
;
1961 pp
->c_base
.assignment_expression
= (pp_fun
) pp_cxx_assignment_expression
;
1962 pp
->c_base
.expression
= (pp_fun
) pp_cxx_expression
;
1963 pp
->enclosing_scope
= global_namespace
;