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
));
207 case UNBOUND_CLASS_TEMPLATE
:
208 pp_cxx_unqualified_id (pp
, TYPE_NAME (t
));
212 pp_unsupported_tree (pp
, t
);
217 /* Pretty-print out the token sequence ":: template" in template codes
218 where it is needed to "inline declare" the (following) member as
219 a template. This situation arises when SCOPE of T is dependent
220 on template parameters. */
223 pp_cxx_template_keyword_if_needed (cxx_pretty_printer
*pp
, tree scope
, tree t
)
225 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
226 && TYPE_P (scope
) && dependent_type_p (scope
))
227 pp_cxx_identifier (pp
, "template");
230 /* nested-name-specifier:
231 class-or-namespace-name :: nested-name-specifier(opt)
232 class-or-namespace-name :: template nested-name-specifier */
235 pp_cxx_nested_name_specifier (cxx_pretty_printer
*pp
, tree t
)
237 if (t
!= NULL
&& t
!= pp
->enclosing_scope
)
239 tree scope
= TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
);
240 pp_cxx_nested_name_specifier (pp
, scope
);
241 pp_cxx_template_keyword_if_needed (pp
, scope
, t
);
242 pp_cxx_unqualified_id (pp
, t
);
243 pp_cxx_colon_colon (pp
);
248 nested-name-specifier template(opt) unqualified-id */
251 pp_cxx_qualified_id (cxx_pretty_printer
*pp
, tree t
)
253 switch (TREE_CODE (t
))
255 /* A pointer-to-member is always qualified. */
257 pp_cxx_nested_name_specifier (pp
, PTRMEM_CST_CLASS (t
));
258 pp_cxx_unqualified_id (pp
, PTRMEM_CST_MEMBER (t
));
261 /* In Standard C++, functions cannot possibly be used as
262 nested-name-specifiers. However, there are situations where
263 is "makes sense" to output the surrounding function name for the
264 purpose of emphasizing on the scope kind. Just printing the
265 function name might not be sufficient as it may be overloaded; so,
266 we decorate the function with its signature too.
267 FIXME: This is probably the wrong pretty-printing for conversion
268 functions and some function templates. */
272 if (DECL_FUNCTION_MEMBER_P (t
))
273 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
274 pp_cxx_unqualified_id
275 (pp
, DECL_CONSTRUCTOR_P (t
) ? DECL_CONTEXT (t
) : t
);
276 pp_cxx_parameter_declaration_clause (pp
, TREE_TYPE (t
));
281 pp_cxx_nested_name_specifier (pp
, TREE_OPERAND (t
, 0));
282 pp_cxx_unqualified_id (pp
, TREE_OPERAND (t
, 1));
287 tree scope
= TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
);
288 if (scope
!= pp
->enclosing_scope
)
290 pp_cxx_nested_name_specifier (pp
, scope
);
291 pp_cxx_template_keyword_if_needed (pp
, scope
, t
);
293 pp_cxx_unqualified_id (pp
, t
);
304 pp_cxx_id_expression (cxx_pretty_printer
*pp
, tree t
)
306 if (TREE_CODE (t
) == OVERLOAD
)
308 if (DECL_P (t
) && DECL_CONTEXT (t
))
309 pp_cxx_qualified_id (pp
, t
);
311 pp_cxx_unqualified_id (pp
, t
);
314 /* primary-expression:
318 :: operator-function-id
324 pp_cxx_primary_expression (cxx_pretty_printer
*pp
, tree t
)
326 switch (TREE_CODE (t
))
331 pp_c_constant (pp_c_base (pp
), t
);
335 t
= BASELINK_FUNCTIONS (t
);
343 pp_cxx_id_expression (pp
, t
);
347 case TEMPLATE_TYPE_PARM
:
348 case TEMPLATE_TEMPLATE_PARM
:
349 case TEMPLATE_PARM_INDEX
:
350 pp_cxx_unqualified_id (pp
, t
);
354 pp_cxx_left_paren (pp
);
355 pp_cxx_statement (pp
, STMT_EXPR_STMT (t
));
356 pp_cxx_right_paren (pp
);
360 pp_c_primary_expression (pp_c_base (pp
), t
);
365 /* postfix-expression:
367 postfix-expression [ expression ]
368 postfix-expression ( expression-list(opt) )
369 simple-type-specifier ( expression-list(opt) )
370 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
371 typename ::(opt) nested-name-specifier template(opt)
372 template-id ( expression-list(opt) )
373 postfix-expression . template(opt) ::(opt) id-expression
374 postfix-expression -> template(opt) ::(opt) id-expression
375 postfix-expression . pseudo-destructor-name
376 postfix-expression -> pseudo-destructor-name
377 postfix-expression ++
378 postfix-expression --
379 dynamic_cast < type-id > ( expression )
380 static_cast < type-id > ( expression )
381 reinterpret_cast < type-id > ( expression )
382 const_cast < type-id > ( expression )
383 typeid ( expression )
384 typeif ( type-id ) */
387 pp_cxx_postfix_expression (cxx_pretty_printer
*pp
, tree t
)
389 enum tree_code code
= TREE_CODE (t
);
396 tree fun
= TREE_OPERAND (t
, 0);
397 tree args
= TREE_OPERAND (t
, 1);
398 tree saved_scope
= pp
->enclosing_scope
;
400 if (TREE_CODE (fun
) == ADDR_EXPR
)
401 fun
= TREE_OPERAND (fun
, 0);
403 /* In templates, where there is no way to tell whether a given
404 call uses an actual member function. So the parser builds
405 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
406 instantiation time. */
407 if (TREE_CODE (fun
) != FUNCTION_DECL
)
409 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun
))
411 tree object
= code
== AGGR_INIT_EXPR
&& AGGR_INIT_VIA_CTOR_P (t
)
412 ? TREE_OPERAND (t
, 2)
415 while (TREE_CODE (object
) == NOP_EXPR
)
416 object
= TREE_OPERAND (object
, 0);
418 if (TREE_CODE (object
) == ADDR_EXPR
)
419 object
= TREE_OPERAND (object
, 0);
421 if (TREE_CODE (TREE_TYPE (object
)) != POINTER_TYPE
)
423 pp_cxx_postfix_expression (pp
, object
);
428 pp_cxx_postfix_expression (pp
, object
);
431 args
= TREE_CHAIN (args
);
432 pp
->enclosing_scope
= strip_pointer_operator (TREE_TYPE (object
));
435 pp_cxx_postfix_expression (pp
, fun
);
436 pp
->enclosing_scope
= saved_scope
;
437 pp_cxx_call_argument_list (pp
, args
);
439 if (code
== AGGR_INIT_EXPR
&& AGGR_INIT_VIA_CTOR_P (t
))
441 pp_cxx_separate_with (pp
, ',');
442 pp_cxx_postfix_expression (pp
, TREE_OPERAND (t
, 2));
455 pp_cxx_primary_expression (pp
, t
);
458 case DYNAMIC_CAST_EXPR
:
459 case STATIC_CAST_EXPR
:
460 case REINTERPRET_CAST_EXPR
:
461 case CONST_CAST_EXPR
:
462 if (code
== DYNAMIC_CAST_EXPR
)
463 pp_cxx_identifier (pp
, "dynamic_cast");
464 else if (code
== STATIC_CAST_EXPR
)
465 pp_cxx_identifier (pp
, "static_cast");
466 else if (code
== REINTERPRET_CAST_EXPR
)
467 pp_cxx_identifier (pp
, "reinterpret_cast");
469 pp_cxx_identifier (pp
, "const_cast");
470 pp_cxx_begin_template_argument_list (pp
);
471 pp_cxx_type_id (pp
, TREE_TYPE (t
));
472 pp_cxx_end_template_argument_list (pp
);
474 pp_cxx_expression (pp
, TREE_OPERAND (t
, 0));
478 case EMPTY_CLASS_EXPR
:
479 pp_cxx_type_id (pp
, TREE_TYPE (t
));
485 t
= TREE_OPERAND (t
, 0);
486 pp_cxx_identifier (pp
, "typeid");
489 pp_cxx_type_id (pp
, t
);
491 pp_cxx_expression (pp
, t
);
495 case PSEUDO_DTOR_EXPR
:
496 pp_cxx_postfix_expression (pp
, TREE_OPERAND (t
, 0));
498 pp_cxx_qualified_id (pp
, TREE_OPERAND (t
, 1));
499 pp_cxx_colon_colon (pp
);
501 pp_cxx_unqualified_id (pp
, TREE_OPERAND (t
, 2));
505 pp_cxx_postfix_expression (pp
, TREE_OPERAND (t
, 0));
510 pp_c_postfix_expression (pp_c_base (pp
), t
);
516 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
517 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
523 type-specifier-seq new-declarator(opt)
526 ptr-operator new-declarator(opt)
527 direct-new-declarator
529 direct-new-declarator
531 direct-new-declarator [ constant-expression ]
534 ( expression-list(opt) ) */
537 pp_cxx_new_expression (cxx_pretty_printer
*pp
, tree t
)
539 enum tree_code code
= TREE_CODE (t
);
544 if (NEW_EXPR_USE_GLOBAL (t
))
545 pp_cxx_colon_colon (pp
);
546 pp_cxx_identifier (pp
, "new");
547 if (TREE_OPERAND (t
, 0))
549 pp_cxx_call_argument_list (pp
, TREE_OPERAND (t
, 0));
552 /* FIXME: array-types are built with one more element. */
553 pp_cxx_type_id (pp
, TREE_OPERAND (t
, 1));
554 if (TREE_OPERAND (t
, 2))
557 t
= TREE_OPERAND (t
, 2);
558 if (TREE_CODE (t
) == TREE_LIST
)
559 pp_c_expression_list (pp_c_base (pp
), t
);
560 else if (t
== void_zero_node
)
561 ; /* OK, empty initializer list. */
563 pp_cxx_expression (pp
, t
);
569 pp_unsupported_tree (pp
, t
);
573 /* delete-expression:
574 ::(opt) delete cast-expression
575 ::(opt) delete [ ] cast-expression */
578 pp_cxx_delete_expression (cxx_pretty_printer
*pp
, tree t
)
580 enum tree_code code
= TREE_CODE (t
);
584 case VEC_DELETE_EXPR
:
585 if (DELETE_EXPR_USE_GLOBAL (t
))
586 pp_cxx_colon_colon (pp
);
587 pp_cxx_identifier (pp
, "delete");
588 if (code
== VEC_DELETE_EXPR
)
590 pp_left_bracket (pp
);
591 pp_right_bracket (pp
);
593 pp_c_cast_expression (pp_c_base (pp
), TREE_OPERAND (t
, 0));
597 pp_unsupported_tree (pp
, t
);
605 unary-operator cast-expression
606 sizeof unary-expression
611 unary-operator: one of
615 __alignof__ unary-expression
616 __alignof__ ( type-id ) */
619 pp_cxx_unary_expression (cxx_pretty_printer
*pp
, tree t
)
621 enum tree_code code
= TREE_CODE (t
);
626 pp_cxx_new_expression (pp
, t
);
630 case VEC_DELETE_EXPR
:
631 pp_cxx_delete_expression (pp
, t
);
636 pp_cxx_identifier (pp
, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
637 pp_cxx_whitespace (pp
);
638 if (TYPE_P (TREE_OPERAND (t
, 0)))
640 pp_cxx_left_paren (pp
);
641 pp_cxx_type_id (pp
, TREE_OPERAND (t
, 0));
642 pp_cxx_right_paren (pp
);
645 pp_unary_expression (pp
, TREE_OPERAND (t
, 0));
648 case UNARY_PLUS_EXPR
:
650 pp_cxx_cast_expression (pp
, TREE_OPERAND (t
, 0));
654 pp_c_unary_expression (pp_c_base (pp
), t
);
661 ( type-id ) cast-expression */
664 pp_cxx_cast_expression (cxx_pretty_printer
*pp
, tree t
)
666 switch (TREE_CODE (t
))
669 pp_cxx_type_id (pp
, TREE_TYPE (t
));
670 pp_cxx_call_argument_list (pp
, TREE_OPERAND (t
, 0));
674 pp_c_cast_expression (pp_c_base (pp
), t
);
681 pm-expression .* cast-expression
682 pm-expression ->* cast-expression */
685 pp_cxx_pm_expression (cxx_pretty_printer
*pp
, tree t
)
687 switch (TREE_CODE (t
))
689 /* Handle unfortunate OFFESET_REF overloading here. */
691 if (TYPE_P (TREE_OPERAND (t
, 0)))
693 pp_cxx_qualified_id (pp
, t
);
696 /* Else fall through. */
699 pp_cxx_pm_expression (pp
, TREE_OPERAND (t
, 0));
702 pp_cxx_cast_expression (pp
, TREE_OPERAND (t
, 1));
707 pp_cxx_cast_expression (pp
, t
);
712 /* multiplicative-expression:
714 multiplicative-expression * pm-expression
715 multiplicative-expression / pm-expression
716 multiplicative-expression % pm-expression */
719 pp_cxx_multiplicative_expression (cxx_pretty_printer
*pp
, tree e
)
721 enum tree_code code
= TREE_CODE (e
);
727 pp_cxx_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
729 if (code
== MULT_EXPR
)
731 else if (code
== TRUNC_DIV_EXPR
)
736 pp_cxx_pm_expression (pp
, TREE_OPERAND (e
, 1));
740 pp_cxx_pm_expression (pp
, e
);
745 /* conditional-expression:
746 logical-or-expression
747 logical-or-expression ? expression : assignment-expression */
750 pp_cxx_conditional_expression (cxx_pretty_printer
*pp
, tree e
)
752 if (TREE_CODE (e
) == COND_EXPR
)
754 pp_c_logical_or_expression (pp_c_base (pp
), TREE_OPERAND (e
, 0));
758 pp_cxx_expression (pp
, TREE_OPERAND (e
, 1));
760 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 2));
763 pp_c_logical_or_expression (pp_c_base (pp
), e
);
766 /* Pretty-print a compound assignment operator token as indicated by T. */
769 pp_cxx_assignment_operator (cxx_pretty_printer
*pp
, tree t
)
773 switch (TREE_CODE (t
))
796 op
= tree_code_name
[TREE_CODE (t
)];
800 pp_cxx_identifier (pp
, op
);
804 /* assignment-expression:
805 conditional-expression
806 logical-or-expression assignment-operator assignment-expression
810 throw assignment-expression(opt)
812 assignment-operator: one of
813 = *= /= %= += -= >>= <<= &= ^= |= */
816 pp_cxx_assignment_expression (cxx_pretty_printer
*pp
, tree e
)
818 switch (TREE_CODE (e
))
822 pp_c_logical_or_expression (pp_c_base (pp
), TREE_OPERAND (e
, 0));
826 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 1));
830 pp_cxx_identifier (pp
, "throw");
831 if (TREE_OPERAND (e
, 0))
832 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 0));
836 pp_c_logical_or_expression (pp_c_base (pp
), TREE_OPERAND (e
, 0));
837 pp_cxx_assignment_operator (pp
, TREE_OPERAND (e
, 1));
838 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 2));
842 pp_cxx_conditional_expression (pp
, e
);
848 pp_cxx_expression (cxx_pretty_printer
*pp
, tree t
)
850 switch (TREE_CODE (t
))
855 pp_c_constant (pp_c_base (pp
), t
);
859 pp_cxx_unqualified_id (pp
, t
);
867 pp_cxx_qualified_id (pp
, t
);
879 case TEMPLATE_TYPE_PARM
:
880 case TEMPLATE_PARM_INDEX
:
881 case TEMPLATE_TEMPLATE_PARM
:
883 pp_cxx_primary_expression (pp
, t
);
887 case DYNAMIC_CAST_EXPR
:
888 case STATIC_CAST_EXPR
:
889 case REINTERPRET_CAST_EXPR
:
890 case CONST_CAST_EXPR
:
894 case EMPTY_CLASS_EXPR
:
896 case PSEUDO_DTOR_EXPR
:
899 pp_cxx_postfix_expression (pp
, t
);
904 pp_cxx_new_expression (pp
, t
);
908 case VEC_DELETE_EXPR
:
909 pp_cxx_delete_expression (pp
, t
);
914 pp_cxx_unary_expression (pp
, t
);
918 pp_cxx_cast_expression (pp
, t
);
924 pp_cxx_pm_expression (pp
, t
);
930 pp_cxx_multiplicative_expression (pp
, t
);
934 pp_cxx_conditional_expression (pp
, t
);
941 pp_cxx_assignment_expression (pp
, t
);
944 case NON_DEPENDENT_EXPR
:
945 case MUST_NOT_THROW_EXPR
:
946 pp_cxx_expression (pp
, t
);
950 pp_c_expression (pp_c_base (pp
), t
);
958 /* function-specifier:
964 pp_cxx_function_specifier (cxx_pretty_printer
*pp
, tree t
)
966 switch (TREE_CODE (t
))
969 if (DECL_VIRTUAL_P (t
))
970 pp_cxx_identifier (pp
, "virtual");
971 else if (DECL_CONSTRUCTOR_P (t
) && DECL_NONCONVERTING_P (t
))
972 pp_cxx_identifier (pp
, "explicit");
974 pp_c_function_specifier (pp_c_base (pp
), t
);
981 /* decl-specifier-seq:
982 decl-specifier-seq(opt) decl-specifier
985 storage-class-specifier
992 pp_cxx_decl_specifier_seq (cxx_pretty_printer
*pp
, tree t
)
994 switch (TREE_CODE (t
))
1000 pp_cxx_storage_class_specifier (pp
, t
);
1001 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (t
));
1005 pp_cxx_identifier (pp
, "typedef");
1006 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (t
));
1010 if (TYPE_PTRMEMFUNC_P (t
))
1012 tree pfm
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
1013 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (TREE_TYPE (pfm
)));
1014 pp_cxx_whitespace (pp
);
1015 pp_cxx_ptr_operator (pp
, t
);
1020 /* Constructors don't have return types. And conversion functions
1021 do not have a type-specifier in their return types. */
1022 if (DECL_CONSTRUCTOR_P (t
) || DECL_CONV_FN_P (t
))
1023 pp_cxx_function_specifier (pp
, t
);
1024 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1025 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (TREE_TYPE (t
)));
1028 pp_c_declaration_specifiers (pp_c_base (pp
), t
);
1033 /* simple-type-specifier:
1034 ::(opt) nested-name-specifier(opt) type-name
1035 ::(opt) nested-name-specifier(opt) template(opt) template-id
1049 pp_cxx_simple_type_specifier (cxx_pretty_printer
*pp
, tree t
)
1051 switch (TREE_CODE (t
))
1056 pp_cxx_qualified_id (pp
, t
);
1059 case TEMPLATE_TYPE_PARM
:
1060 case TEMPLATE_TEMPLATE_PARM
:
1061 case TEMPLATE_PARM_INDEX
:
1062 pp_cxx_unqualified_id (pp
, t
);
1066 pp_cxx_identifier (pp
, "typename");
1067 pp_cxx_nested_name_specifier (pp
, TYPE_CONTEXT (t
));
1068 pp_cxx_unqualified_id (pp
, TYPE_NAME (t
));
1072 pp_c_type_specifier (pp_c_base (pp
), t
);
1077 /* type-specifier-seq:
1078 type-specifier type-specifier-seq(opt)
1081 simple-type-specifier
1084 elaborated-type-specifier
1088 pp_cxx_type_specifier_seq (cxx_pretty_printer
*pp
, tree t
)
1090 switch (TREE_CODE (t
))
1093 case TEMPLATE_TYPE_PARM
:
1094 case TEMPLATE_TEMPLATE_PARM
:
1096 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1097 pp_cxx_cv_qualifier_seq (pp
, t
);
1098 pp_cxx_simple_type_specifier (pp
, t
);
1102 pp_cxx_type_specifier_seq (pp
, TREE_TYPE (t
));
1103 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (t
));
1104 pp_cxx_nested_name_specifier (pp
, TYPE_METHOD_BASETYPE (t
));
1108 if (!(TREE_CODE (t
) == FUNCTION_DECL
&& DECL_CONSTRUCTOR_P (t
)))
1109 pp_c_specifier_qualifier_list (pp_c_base (pp
), t
);
1114 * cv-qualifier-seq(opt)
1116 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1119 pp_cxx_ptr_operator (cxx_pretty_printer
*pp
, tree t
)
1121 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
1123 switch (TREE_CODE (t
))
1125 case REFERENCE_TYPE
:
1127 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
1128 || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t
)))
1129 pp_cxx_ptr_operator (pp
, TREE_TYPE (t
));
1130 if (TREE_CODE (t
) == POINTER_TYPE
)
1133 pp_cxx_cv_qualifier_seq (pp
, t
);
1140 if (TYPE_PTRMEMFUNC_P (t
))
1142 pp_cxx_left_paren (pp
);
1143 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEMFUNC_OBJECT_TYPE (t
));
1148 if (TYPE_PTR_TO_MEMBER_P (t
))
1150 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1151 pp_cxx_left_paren (pp
);
1152 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEM_CLASS_TYPE (t
));
1154 pp_cxx_cv_qualifier_seq (pp
, t
);
1157 /* else fall through. */
1160 pp_unsupported_tree (pp
, t
);
1166 pp_cxx_implicit_parameter_type (tree mf
)
1168 return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf
))));
1172 parameter-declaration:
1173 decl-specifier-seq declarator
1174 decl-specifier-seq declarator = assignment-expression
1175 decl-specifier-seq abstract-declarator(opt)
1176 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1179 pp_cxx_parameter_declaration (cxx_pretty_printer
*pp
, tree t
)
1181 pp_cxx_decl_specifier_seq (pp
, t
);
1183 pp_cxx_abstract_declarator (pp
, t
);
1185 pp_cxx_declarator (pp
, t
);
1188 /* parameter-declaration-clause:
1189 parameter-declaration-list(opt) ...(opt)
1190 parameter-declaration-list , ...
1192 parameter-declaration-list:
1193 parameter-declaration
1194 parameter-declaration-list , parameter-declaration */
1197 pp_cxx_parameter_declaration_clause (cxx_pretty_printer
*pp
, tree t
)
1199 tree args
= TYPE_P (t
) ? NULL
: FUNCTION_FIRST_USER_PARM (t
);
1201 TYPE_P (t
) ? TYPE_ARG_TYPES (t
) : FUNCTION_FIRST_USER_PARMTYPE (t
);
1202 const bool abstract
= args
== NULL
1203 || pp_c_base (pp
)->flags
& pp_c_flag_abstract
;
1206 /* Skip artificial parameter for nonstatic member functions. */
1207 if (TREE_CODE (t
) == METHOD_TYPE
)
1208 types
= TREE_CHAIN (types
);
1210 pp_cxx_left_paren (pp
);
1211 for (; args
; args
= TREE_CHAIN (args
), types
= TREE_CHAIN (types
))
1214 pp_cxx_separate_with (pp
, ',');
1216 pp_cxx_parameter_declaration (pp
, abstract
? TREE_VALUE (types
) : args
);
1217 if (!abstract
&& pp_c_base (pp
)->flags
& pp_cxx_flag_default_argument
)
1219 pp_cxx_whitespace (pp
);
1221 pp_cxx_whitespace (pp
);
1222 pp_cxx_assignment_expression (pp
, TREE_PURPOSE (types
));
1225 pp_cxx_right_paren (pp
);
1228 /* exception-specification:
1229 throw ( type-id-list(opt) )
1233 type-id-list , type-id */
1236 pp_cxx_exception_specification (cxx_pretty_printer
*pp
, tree t
)
1238 tree ex_spec
= TYPE_RAISES_EXCEPTIONS (t
);
1240 if (!TYPE_NOTHROW_P (t
) && ex_spec
== NULL
)
1242 pp_cxx_identifier (pp
, "throw");
1243 pp_cxx_left_paren (pp
);
1244 for (; ex_spec
&& TREE_VALUE (ex_spec
); ex_spec
= TREE_CHAIN (ex_spec
))
1246 pp_cxx_type_id (pp
, TREE_VALUE (ex_spec
));
1247 if (TREE_CHAIN (ex_spec
))
1248 pp_cxx_separate_with (pp
, ',');
1250 pp_cxx_right_paren (pp
);
1253 /* direct-declarator:
1255 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1256 exception-specification(opt)
1257 direct-declaration [ constant-expression(opt) ]
1261 pp_cxx_direct_declarator (cxx_pretty_printer
*pp
, tree t
)
1263 switch (TREE_CODE (t
))
1271 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (t
));
1272 pp_cxx_id_expression (pp
, DECL_NAME (t
));
1274 pp_cxx_abstract_declarator (pp
, TREE_TYPE (t
));
1278 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
1279 pp_cxx_id_expression (pp
, t
);
1280 pp_cxx_parameter_declaration_clause (pp
, t
);
1282 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1284 pp_base (pp
)->padding
= pp_before
;
1285 pp_cxx_cv_qualifier_seq (pp
, pp_cxx_implicit_parameter_type (t
));
1288 pp_cxx_exception_specification (pp
, TREE_TYPE (t
));
1293 case TEMPLATE_TYPE_PARM
:
1294 case TEMPLATE_PARM_INDEX
:
1295 case TEMPLATE_TEMPLATE_PARM
:
1299 pp_c_direct_declarator (pp_c_base (pp
), t
);
1306 ptr-operator declarator */
1309 pp_cxx_declarator (cxx_pretty_printer
*pp
, tree t
)
1311 pp_cxx_direct_declarator (pp
, t
);
1314 /* ctor-initializer:
1315 : mem-initializer-list
1317 mem-initializer-list:
1319 mem-initializer , mem-initializer-list
1322 mem-initializer-id ( expression-list(opt) )
1325 ::(opt) nested-name-specifier(opt) class-name
1329 pp_cxx_ctor_initializer (cxx_pretty_printer
*pp
, tree t
)
1331 t
= TREE_OPERAND (t
, 0);
1332 pp_cxx_whitespace (pp
);
1334 pp_cxx_whitespace (pp
);
1335 for (; t
; t
= TREE_CHAIN (t
))
1337 pp_cxx_primary_expression (pp
, TREE_PURPOSE (t
));
1338 pp_cxx_call_argument_list (pp
, TREE_VALUE (t
));
1340 pp_cxx_separate_with (pp
, ',');
1344 /* function-definition:
1345 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1346 decl-specifier-seq(opt) declarator function-try-block */
1349 pp_cxx_function_definition (cxx_pretty_printer
*pp
, tree t
)
1351 tree saved_scope
= pp
->enclosing_scope
;
1352 pp_cxx_decl_specifier_seq (pp
, t
);
1353 pp_cxx_declarator (pp
, t
);
1354 pp_needs_newline (pp
) = true;
1355 pp
->enclosing_scope
= DECL_CONTEXT (t
);
1356 if (DECL_SAVED_TREE (t
))
1357 pp_cxx_statement (pp
, DECL_SAVED_TREE (t
));
1360 pp_cxx_semicolon (pp
);
1361 pp_needs_newline (pp
) = true;
1364 pp
->enclosing_scope
= saved_scope
;
1367 /* abstract-declarator:
1368 ptr-operator abstract-declarator(opt)
1369 direct-abstract-declarator */
1372 pp_cxx_abstract_declarator (cxx_pretty_printer
*pp
, tree t
)
1374 if (TYPE_PTRMEM_P (t
) || TYPE_PTRMEMFUNC_P (t
))
1375 pp_cxx_right_paren (pp
);
1376 else if (POINTER_TYPE_P (t
))
1378 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
1379 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1380 pp_cxx_right_paren (pp
);
1383 pp_cxx_direct_abstract_declarator (pp
, t
);
1386 /* direct-abstract-declarator:
1387 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1388 cv-qualifier-seq(opt) exception-specification(opt)
1389 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1390 ( abstract-declarator ) */
1393 pp_cxx_direct_abstract_declarator (cxx_pretty_printer
*pp
, tree t
)
1395 switch (TREE_CODE (t
))
1397 case REFERENCE_TYPE
:
1398 pp_cxx_abstract_declarator (pp
, t
);
1402 if (TYPE_PTRMEMFUNC_P (t
))
1403 pp_cxx_direct_abstract_declarator (pp
, TYPE_PTRMEMFUNC_FN_TYPE (t
));
1408 pp_cxx_parameter_declaration_clause (pp
, t
);
1409 pp_cxx_direct_abstract_declarator (pp
, TREE_TYPE (t
));
1410 if (TREE_CODE (t
) == METHOD_TYPE
)
1412 pp_base (pp
)->padding
= pp_before
;
1413 pp_cxx_cv_qualifier_seq
1414 (pp
, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))));
1416 pp_cxx_exception_specification (pp
, t
);
1420 case TEMPLATE_TYPE_PARM
:
1421 case TEMPLATE_TEMPLATE_PARM
:
1422 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1423 case UNBOUND_CLASS_TEMPLATE
:
1427 pp_c_direct_abstract_declarator (pp_c_base (pp
), t
);
1433 type-specifier-seq abstract-declarator(opt) */
1436 pp_cxx_type_id (cxx_pretty_printer
*pp
, tree t
)
1438 pp_flags saved_flags
= pp_c_base (pp
)->flags
;
1439 pp_c_base (pp
)->flags
|= pp_c_flag_abstract
;
1441 switch (TREE_CODE (t
))
1448 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1449 case UNBOUND_CLASS_TEMPLATE
:
1450 case TEMPLATE_TEMPLATE_PARM
:
1451 case TEMPLATE_TYPE_PARM
:
1452 case TEMPLATE_PARM_INDEX
:
1455 case TEMPLATE_ID_EXPR
:
1456 pp_cxx_type_specifier_seq (pp
, t
);
1460 pp_c_type_id (pp_c_base (pp
), t
);
1464 pp_c_base (pp
)->flags
= saved_flags
;
1467 /* template-argument-list:
1469 template-argument-list, template-argument
1472 assignment-expression
1477 pp_cxx_template_argument_list (cxx_pretty_printer
*pp
, tree t
)
1482 for (i
= 0; i
< TREE_VEC_LENGTH (t
); ++i
)
1484 tree arg
= TREE_VEC_ELT (t
, i
);
1486 pp_cxx_separate_with (pp
, ',');
1487 if (TYPE_P (arg
) || (TREE_CODE (arg
) == TEMPLATE_DECL
1488 && TYPE_P (DECL_TEMPLATE_RESULT (arg
))))
1489 pp_cxx_type_id (pp
, arg
);
1491 pp_cxx_expression (pp
, arg
);
1497 pp_cxx_exception_declaration (cxx_pretty_printer
*pp
, tree t
)
1499 t
= DECL_EXPR_DECL (t
);
1500 pp_cxx_type_specifier_seq (pp
, t
);
1502 pp_cxx_abstract_declarator (pp
, t
);
1504 pp_cxx_declarator (pp
, t
);
1510 pp_cxx_statement (cxx_pretty_printer
*pp
, tree t
)
1512 switch (TREE_CODE (t
))
1514 case CTOR_INITIALIZER
:
1515 pp_cxx_ctor_initializer (pp
, t
);
1519 pp_cxx_identifier (pp
, "using");
1520 pp_cxx_identifier (pp
, "namespace");
1521 if (DECL_CONTEXT (t
))
1522 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
1523 pp_cxx_qualified_id (pp
, USING_STMT_NAMESPACE (t
));
1527 pp_cxx_identifier (pp
, "using");
1528 pp_cxx_nested_name_specifier (pp
, USING_DECL_SCOPE (t
));
1529 pp_cxx_unqualified_id (pp
, DECL_NAME (t
));
1536 try compound-statement handler-seq */
1538 pp_maybe_newline_and_indent (pp
, 0);
1539 pp_cxx_identifier (pp
, "try");
1540 pp_newline_and_indent (pp
, 3);
1541 pp_cxx_statement (pp
, TRY_STMTS (t
));
1542 pp_newline_and_indent (pp
, -3);
1546 pp_cxx_statement (pp
, TRY_HANDLERS (t
));
1551 handler handler-seq(opt)
1554 catch ( exception-declaration ) compound-statement
1556 exception-declaration:
1557 type-specifier-seq declarator
1558 type-specifier-seq abstract-declarator
1561 pp_cxx_identifier (pp
, "catch");
1562 pp_cxx_left_paren (pp
);
1563 pp_cxx_exception_declaration (pp
, HANDLER_PARMS (t
));
1564 pp_cxx_right_paren (pp
);
1565 pp_indentation (pp
) += 3;
1566 pp_needs_newline (pp
) = true;
1567 pp_cxx_statement (pp
, HANDLER_BODY (t
));
1568 pp_indentation (pp
) -= 3;
1569 pp_needs_newline (pp
) = true;
1572 /* selection-statement:
1573 if ( expression ) statement
1574 if ( expression ) statement else statement */
1576 pp_cxx_identifier (pp
, "if");
1577 pp_cxx_whitespace (pp
);
1578 pp_cxx_left_paren (pp
);
1579 pp_cxx_expression (pp
, IF_COND (t
));
1580 pp_cxx_right_paren (pp
);
1581 pp_newline_and_indent (pp
, 2);
1582 pp_cxx_statement (pp
, THEN_CLAUSE (t
));
1583 pp_newline_and_indent (pp
, -2);
1584 if (ELSE_CLAUSE (t
))
1586 tree else_clause
= ELSE_CLAUSE (t
);
1587 pp_cxx_identifier (pp
, "else");
1588 if (TREE_CODE (else_clause
) == IF_STMT
)
1589 pp_cxx_whitespace (pp
);
1591 pp_newline_and_indent (pp
, 2);
1592 pp_cxx_statement (pp
, else_clause
);
1593 if (TREE_CODE (else_clause
) != IF_STMT
)
1594 pp_newline_and_indent (pp
, -2);
1599 pp_cxx_identifier (pp
, "switch");
1601 pp_cxx_left_paren (pp
);
1602 pp_cxx_expression (pp
, SWITCH_STMT_COND (t
));
1603 pp_cxx_right_paren (pp
);
1604 pp_indentation (pp
) += 3;
1605 pp_needs_newline (pp
) = true;
1606 pp_cxx_statement (pp
, SWITCH_STMT_BODY (t
));
1607 pp_newline_and_indent (pp
, -3);
1610 /* iteration-statement:
1611 while ( expression ) statement
1612 do statement while ( expression ) ;
1613 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1614 for ( declaration expression(opt) ; expression(opt) ) statement */
1616 pp_cxx_identifier (pp
, "while");
1618 pp_cxx_left_paren (pp
);
1619 pp_cxx_expression (pp
, WHILE_COND (t
));
1620 pp_cxx_right_paren (pp
);
1621 pp_newline_and_indent (pp
, 3);
1622 pp_cxx_statement (pp
, WHILE_BODY (t
));
1623 pp_indentation (pp
) -= 3;
1624 pp_needs_newline (pp
) = true;
1628 pp_cxx_identifier (pp
, "do");
1629 pp_newline_and_indent (pp
, 3);
1630 pp_cxx_statement (pp
, DO_BODY (t
));
1631 pp_newline_and_indent (pp
, -3);
1632 pp_cxx_identifier (pp
, "while");
1634 pp_cxx_left_paren (pp
);
1635 pp_cxx_expression (pp
, DO_COND (t
));
1636 pp_cxx_right_paren (pp
);
1637 pp_cxx_semicolon (pp
);
1638 pp_needs_newline (pp
) = true;
1642 pp_cxx_identifier (pp
, "for");
1644 pp_cxx_left_paren (pp
);
1645 if (FOR_INIT_STMT (t
))
1646 pp_cxx_statement (pp
, FOR_INIT_STMT (t
));
1648 pp_cxx_semicolon (pp
);
1649 pp_needs_newline (pp
) = false;
1650 pp_cxx_whitespace (pp
);
1652 pp_cxx_expression (pp
, FOR_COND (t
));
1653 pp_cxx_semicolon (pp
);
1654 pp_needs_newline (pp
) = false;
1655 pp_cxx_whitespace (pp
);
1657 pp_cxx_expression (pp
, FOR_EXPR (t
));
1658 pp_cxx_right_paren (pp
);
1659 pp_newline_and_indent (pp
, 3);
1660 pp_cxx_statement (pp
, FOR_BODY (t
));
1661 pp_indentation (pp
) -= 3;
1662 pp_needs_newline (pp
) = true;
1668 return expression(opt) ; */
1671 pp_identifier (pp
, TREE_CODE (t
) == BREAK_STMT
? "break" : "continue");
1672 pp_cxx_semicolon (pp
);
1673 pp_needs_newline (pp
) = true;
1676 /* expression-statement:
1677 expression(opt) ; */
1679 pp_cxx_expression (pp
, EXPR_STMT_EXPR (t
));
1680 pp_cxx_semicolon (pp
);
1681 pp_needs_newline (pp
) = true;
1685 pp_cxx_identifier (pp
, "try");
1686 pp_newline_and_indent (pp
, 2);
1687 pp_cxx_statement (pp
, CLEANUP_BODY (t
));
1688 pp_newline_and_indent (pp
, -2);
1689 pp_cxx_identifier (pp
, CLEANUP_EH_ONLY (t
) ? "catch" : "finally");
1690 pp_newline_and_indent (pp
, 2);
1691 pp_cxx_statement (pp
, CLEANUP_EXPR (t
));
1692 pp_newline_and_indent (pp
, -2);
1696 pp_c_statement (pp_c_base (pp
), t
);
1701 /* original-namespace-definition:
1702 namespace identifier { namespace-body }
1704 As an edge case, we also handle unnamed namespace definition here. */
1707 pp_cxx_original_namespace_definition (cxx_pretty_printer
*pp
, tree t
)
1709 pp_cxx_identifier (pp
, "namespace");
1710 if (DECL_CONTEXT (t
))
1711 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
1713 pp_cxx_unqualified_id (pp
, t
);
1714 pp_cxx_whitespace (pp
);
1715 pp_cxx_left_brace (pp
);
1716 /* We do not print the namespace-body. */
1717 pp_cxx_whitespace (pp
);
1718 pp_cxx_right_brace (pp
);
1724 namespace-alias-definition:
1725 namespace identifier = qualified-namespace-specifier ;
1727 qualified-namespace-specifier:
1728 ::(opt) nested-name-specifier(opt) namespace-name */
1731 pp_cxx_namespace_alias_definition (cxx_pretty_printer
*pp
, tree t
)
1733 pp_cxx_identifier (pp
, "namespace");
1734 if (DECL_CONTEXT (t
))
1735 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
1736 pp_cxx_unqualified_id (pp
, t
);
1737 pp_cxx_whitespace (pp
);
1739 pp_cxx_whitespace (pp
);
1740 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t
)))
1741 pp_cxx_nested_name_specifier (pp
,
1742 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t
)));
1743 pp_cxx_qualified_id (pp
, DECL_NAMESPACE_ALIAS (t
));
1744 pp_cxx_semicolon (pp
);
1747 /* simple-declaration:
1748 decl-specifier-seq(opt) init-declarator-list(opt) */
1751 pp_cxx_simple_declaration (cxx_pretty_printer
*pp
, tree t
)
1753 pp_cxx_decl_specifier_seq (pp
, t
);
1754 pp_cxx_init_declarator (pp
, t
);
1755 pp_cxx_semicolon (pp
);
1756 pp_needs_newline (pp
) = true;
1760 template-parameter-list:
1762 template-parameter-list , template-parameter */
1765 pp_cxx_template_parameter_list (cxx_pretty_printer
*pp
, tree t
)
1767 const int n
= TREE_VEC_LENGTH (t
);
1769 for (i
= 0; i
< n
; ++i
)
1772 pp_cxx_separate_with (pp
, ',');
1773 pp_cxx_template_parameter (pp
, TREE_VEC_ELT (t
, i
));
1777 /* template-parameter:
1779 parameter-declaration
1782 class identifier(opt)
1783 class identifier(op) = type-id
1784 typename identifier(opt)
1785 typename identifier(opt) = type-id
1786 template < template-parameter-list > class identifier(opt)
1787 template < template-parameter-list > class identifier(opt) = template-name
1791 pp_cxx_template_parameter (cxx_pretty_printer
*pp
, tree t
)
1793 tree parameter
= TREE_VALUE (t
);
1794 switch (TREE_CODE (parameter
))
1797 pp_cxx_identifier (pp
, "class");
1798 if (DECL_NAME (parameter
))
1799 pp_cxx_tree_identifier (pp
, DECL_NAME (parameter
));
1800 /* FIXME: Chech if we should print also default argument. */
1804 pp_cxx_parameter_declaration (pp
, parameter
);
1811 pp_unsupported_tree (pp
, t
);
1816 /* Pretty-print a template parameter in the canonical form
1817 "template-parameter-<level>-<position in parameter list>". */
1820 pp_cxx_canonical_template_parameter (cxx_pretty_printer
*pp
, tree parm
)
1822 const enum tree_code code
= TREE_CODE (parm
);
1824 /* Brings type template parameters to the canonical forms. */
1825 if (code
== TEMPLATE_TYPE_PARM
|| code
== TEMPLATE_TEMPLATE_PARM
1826 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
)
1827 parm
= TEMPLATE_TYPE_PARM_INDEX (parm
);
1829 pp_cxx_begin_template_argument_list (pp
);
1830 pp_cxx_identifier (pp
, "template-parameter-");
1831 pp_wide_integer (pp
, TEMPLATE_PARM_LEVEL (parm
));
1833 pp_wide_integer (pp
, TEMPLATE_PARM_IDX (parm
) + 1);
1834 pp_cxx_end_template_argument_list (pp
);
1838 template-declaration:
1839 export(opt) template < template-parameter-list > declaration */
1842 pp_cxx_template_declaration (cxx_pretty_printer
*pp
, tree t
)
1844 tree tmpl
= most_general_template (t
);
1848 pp_maybe_newline_and_indent (pp
, 0);
1849 for (level
= DECL_TEMPLATE_PARMS (tmpl
); level
; level
= TREE_CHAIN (level
))
1851 pp_cxx_identifier (pp
, "template");
1852 pp_cxx_begin_template_argument_list (pp
);
1853 pp_cxx_template_parameter_list (pp
, TREE_VALUE (level
));
1854 pp_cxx_end_template_argument_list (pp
);
1855 pp_newline_and_indent (pp
, 3);
1858 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_SAVED_TREE (t
))
1859 pp_cxx_function_definition (pp
, t
);
1861 pp_cxx_simple_declaration (pp
, t
);
1865 pp_cxx_explicit_specialization (cxx_pretty_printer
*pp
, tree t
)
1867 pp_unsupported_tree (pp
, t
);
1871 pp_cxx_explicit_instantiation (cxx_pretty_printer
*pp
, tree t
)
1873 pp_unsupported_tree (pp
, t
);
1880 template-declaration
1881 explicit-instantiation
1882 explicit-specialization
1883 linkage-specification
1884 namespace-definition
1889 namespace-alias-definition
1893 pp_cxx_declaration (cxx_pretty_printer
*pp
, tree t
)
1895 if (!DECL_LANG_SPECIFIC (t
))
1896 pp_cxx_simple_declaration (pp
, t
);
1897 else if (DECL_USE_TEMPLATE (t
))
1898 switch (DECL_USE_TEMPLATE (t
))
1901 pp_cxx_template_declaration (pp
, t
);
1905 pp_cxx_explicit_specialization (pp
, t
);
1909 pp_cxx_explicit_instantiation (pp
, t
);
1915 else switch (TREE_CODE (t
))
1919 pp_cxx_simple_declaration (pp
, t
);
1923 if (DECL_SAVED_TREE (t
))
1924 pp_cxx_function_definition (pp
, t
);
1926 pp_cxx_simple_declaration (pp
, t
);
1929 case NAMESPACE_DECL
:
1930 if (DECL_NAMESPACE_ALIAS (t
))
1931 pp_cxx_namespace_alias_definition (pp
, t
);
1933 pp_cxx_original_namespace_definition (pp
, t
);
1937 pp_unsupported_tree (pp
, t
);
1943 typedef c_pretty_print_fn pp_fun
;
1945 /* Initialization of a C++ pretty-printer object. */
1948 pp_cxx_pretty_printer_init (cxx_pretty_printer
*pp
)
1950 pp_c_pretty_printer_init (pp_c_base (pp
));
1951 pp_set_line_maximum_length (pp
, 0);
1953 pp
->c_base
.declaration
= (pp_fun
) pp_cxx_declaration
;
1954 pp
->c_base
.declaration_specifiers
= (pp_fun
) pp_cxx_decl_specifier_seq
;
1955 pp
->c_base
.function_specifier
= (pp_fun
) pp_cxx_function_specifier
;
1956 pp
->c_base
.type_specifier_seq
= (pp_fun
) pp_cxx_type_specifier_seq
;
1957 pp
->c_base
.declarator
= (pp_fun
) pp_cxx_declarator
;
1958 pp
->c_base
.direct_declarator
= (pp_fun
) pp_cxx_direct_declarator
;
1959 pp
->c_base
.parameter_list
= (pp_fun
) pp_cxx_parameter_declaration_clause
;
1960 pp
->c_base
.type_id
= (pp_fun
) pp_cxx_type_id
;
1961 pp
->c_base
.abstract_declarator
= (pp_fun
) pp_cxx_abstract_declarator
;
1962 pp
->c_base
.direct_abstract_declarator
=
1963 (pp_fun
) pp_cxx_direct_abstract_declarator
;
1964 pp
->c_base
.simple_type_specifier
= (pp_fun
)pp_cxx_simple_type_specifier
;
1966 /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
1968 pp
->c_base
.id_expression
= (pp_fun
) pp_cxx_id_expression
;
1969 pp
->c_base
.primary_expression
= (pp_fun
) pp_cxx_primary_expression
;
1970 pp
->c_base
.postfix_expression
= (pp_fun
) pp_cxx_postfix_expression
;
1971 pp
->c_base
.unary_expression
= (pp_fun
) pp_cxx_unary_expression
;
1972 pp
->c_base
.multiplicative_expression
= (pp_fun
) pp_cxx_multiplicative_expression
;
1973 pp
->c_base
.conditional_expression
= (pp_fun
) pp_cxx_conditional_expression
;
1974 pp
->c_base
.assignment_expression
= (pp_fun
) pp_cxx_assignment_expression
;
1975 pp
->c_base
.expression
= (pp_fun
) pp_cxx_expression
;
1976 pp
->enclosing_scope
= global_namespace
;