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
= TREE_OPERAND (t
, 0);
416 tree args
= TREE_OPERAND (t
, 1);
417 tree saved_scope
= pp
->enclosing_scope
;
419 if (TREE_CODE (fun
) == ADDR_EXPR
)
420 fun
= TREE_OPERAND (fun
, 0);
422 /* In templates, where there is no way to tell whether a given
423 call uses an actual member function. So the parser builds
424 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
425 instantiation time. */
426 if (TREE_CODE (fun
) != FUNCTION_DECL
)
428 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun
))
430 tree object
= code
== AGGR_INIT_EXPR
&& AGGR_INIT_VIA_CTOR_P (t
)
431 ? TREE_OPERAND (t
, 2)
434 while (TREE_CODE (object
) == NOP_EXPR
)
435 object
= TREE_OPERAND (object
, 0);
437 if (TREE_CODE (object
) == ADDR_EXPR
)
438 object
= TREE_OPERAND (object
, 0);
440 if (TREE_CODE (TREE_TYPE (object
)) != POINTER_TYPE
)
442 pp_cxx_postfix_expression (pp
, object
);
447 pp_cxx_postfix_expression (pp
, object
);
450 args
= TREE_CHAIN (args
);
451 pp
->enclosing_scope
= strip_pointer_operator (TREE_TYPE (object
));
454 pp_cxx_postfix_expression (pp
, fun
);
455 pp
->enclosing_scope
= saved_scope
;
456 pp_cxx_call_argument_list (pp
, args
);
458 if (code
== AGGR_INIT_EXPR
&& AGGR_INIT_VIA_CTOR_P (t
))
460 pp_cxx_separate_with (pp
, ',');
461 pp_cxx_postfix_expression (pp
, TREE_OPERAND (t
, 2));
474 pp_cxx_primary_expression (pp
, t
);
477 case DYNAMIC_CAST_EXPR
:
478 case STATIC_CAST_EXPR
:
479 case REINTERPRET_CAST_EXPR
:
480 case CONST_CAST_EXPR
:
481 if (code
== DYNAMIC_CAST_EXPR
)
482 pp_cxx_identifier (pp
, "dynamic_cast");
483 else if (code
== STATIC_CAST_EXPR
)
484 pp_cxx_identifier (pp
, "static_cast");
485 else if (code
== REINTERPRET_CAST_EXPR
)
486 pp_cxx_identifier (pp
, "reinterpret_cast");
488 pp_cxx_identifier (pp
, "const_cast");
489 pp_cxx_begin_template_argument_list (pp
);
490 pp_cxx_type_id (pp
, TREE_TYPE (t
));
491 pp_cxx_end_template_argument_list (pp
);
493 pp_cxx_expression (pp
, TREE_OPERAND (t
, 0));
497 case EMPTY_CLASS_EXPR
:
498 pp_cxx_type_id (pp
, TREE_TYPE (t
));
504 t
= TREE_OPERAND (t
, 0);
505 pp_cxx_identifier (pp
, "typeid");
508 pp_cxx_type_id (pp
, t
);
510 pp_cxx_expression (pp
, t
);
514 case PSEUDO_DTOR_EXPR
:
515 pp_cxx_postfix_expression (pp
, TREE_OPERAND (t
, 0));
517 pp_cxx_qualified_id (pp
, TREE_OPERAND (t
, 1));
518 pp_cxx_colon_colon (pp
);
520 pp_cxx_unqualified_id (pp
, TREE_OPERAND (t
, 2));
524 pp_cxx_postfix_expression (pp
, TREE_OPERAND (t
, 0));
529 pp_c_postfix_expression (pp_c_base (pp
), t
);
535 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
536 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
542 type-specifier-seq new-declarator(opt)
545 ptr-operator new-declarator(opt)
546 direct-new-declarator
548 direct-new-declarator
550 direct-new-declarator [ constant-expression ]
553 ( expression-list(opt) ) */
556 pp_cxx_new_expression (cxx_pretty_printer
*pp
, tree t
)
558 enum tree_code code
= TREE_CODE (t
);
563 if (NEW_EXPR_USE_GLOBAL (t
))
564 pp_cxx_colon_colon (pp
);
565 pp_cxx_identifier (pp
, "new");
566 if (TREE_OPERAND (t
, 0))
568 pp_cxx_call_argument_list (pp
, TREE_OPERAND (t
, 0));
571 /* FIXME: array-types are built with one more element. */
572 pp_cxx_type_id (pp
, TREE_OPERAND (t
, 1));
573 if (TREE_OPERAND (t
, 2))
576 t
= TREE_OPERAND (t
, 2);
577 if (TREE_CODE (t
) == TREE_LIST
)
578 pp_c_expression_list (pp_c_base (pp
), t
);
579 else if (t
== void_zero_node
)
580 ; /* OK, empty initializer list. */
582 pp_cxx_expression (pp
, t
);
588 pp_unsupported_tree (pp
, t
);
592 /* delete-expression:
593 ::(opt) delete cast-expression
594 ::(opt) delete [ ] cast-expression */
597 pp_cxx_delete_expression (cxx_pretty_printer
*pp
, tree t
)
599 enum tree_code code
= TREE_CODE (t
);
603 case VEC_DELETE_EXPR
:
604 if (DELETE_EXPR_USE_GLOBAL (t
))
605 pp_cxx_colon_colon (pp
);
606 pp_cxx_identifier (pp
, "delete");
607 if (code
== VEC_DELETE_EXPR
)
609 pp_left_bracket (pp
);
610 pp_right_bracket (pp
);
612 pp_c_cast_expression (pp_c_base (pp
), TREE_OPERAND (t
, 0));
616 pp_unsupported_tree (pp
, t
);
624 unary-operator cast-expression
625 sizeof unary-expression
630 unary-operator: one of
634 __alignof__ unary-expression
635 __alignof__ ( type-id ) */
638 pp_cxx_unary_expression (cxx_pretty_printer
*pp
, tree t
)
640 enum tree_code code
= TREE_CODE (t
);
645 pp_cxx_new_expression (pp
, t
);
649 case VEC_DELETE_EXPR
:
650 pp_cxx_delete_expression (pp
, t
);
655 pp_cxx_identifier (pp
, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
656 pp_cxx_whitespace (pp
);
657 if (TYPE_P (TREE_OPERAND (t
, 0)))
659 pp_cxx_left_paren (pp
);
660 pp_cxx_type_id (pp
, TREE_OPERAND (t
, 0));
661 pp_cxx_right_paren (pp
);
664 pp_unary_expression (pp
, TREE_OPERAND (t
, 0));
667 case UNARY_PLUS_EXPR
:
669 pp_cxx_cast_expression (pp
, TREE_OPERAND (t
, 0));
673 pp_c_unary_expression (pp_c_base (pp
), t
);
680 ( type-id ) cast-expression */
683 pp_cxx_cast_expression (cxx_pretty_printer
*pp
, tree t
)
685 switch (TREE_CODE (t
))
688 pp_cxx_type_id (pp
, TREE_TYPE (t
));
689 pp_cxx_call_argument_list (pp
, TREE_OPERAND (t
, 0));
693 pp_c_cast_expression (pp_c_base (pp
), t
);
700 pm-expression .* cast-expression
701 pm-expression ->* cast-expression */
704 pp_cxx_pm_expression (cxx_pretty_printer
*pp
, tree t
)
706 switch (TREE_CODE (t
))
708 /* Handle unfortunate OFFESET_REF overloading here. */
710 if (TYPE_P (TREE_OPERAND (t
, 0)))
712 pp_cxx_qualified_id (pp
, t
);
715 /* Else fall through. */
718 pp_cxx_pm_expression (pp
, TREE_OPERAND (t
, 0));
721 pp_cxx_cast_expression (pp
, TREE_OPERAND (t
, 1));
726 pp_cxx_cast_expression (pp
, t
);
731 /* multiplicative-expression:
733 multiplicative-expression * pm-expression
734 multiplicative-expression / pm-expression
735 multiplicative-expression % pm-expression */
738 pp_cxx_multiplicative_expression (cxx_pretty_printer
*pp
, tree e
)
740 enum tree_code code
= TREE_CODE (e
);
746 pp_cxx_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
748 if (code
== MULT_EXPR
)
750 else if (code
== TRUNC_DIV_EXPR
)
755 pp_cxx_pm_expression (pp
, TREE_OPERAND (e
, 1));
759 pp_cxx_pm_expression (pp
, e
);
764 /* conditional-expression:
765 logical-or-expression
766 logical-or-expression ? expression : assignment-expression */
769 pp_cxx_conditional_expression (cxx_pretty_printer
*pp
, tree e
)
771 if (TREE_CODE (e
) == COND_EXPR
)
773 pp_c_logical_or_expression (pp_c_base (pp
), TREE_OPERAND (e
, 0));
777 pp_cxx_expression (pp
, TREE_OPERAND (e
, 1));
779 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 2));
782 pp_c_logical_or_expression (pp_c_base (pp
), e
);
785 /* Pretty-print a compound assignment operator token as indicated by T. */
788 pp_cxx_assignment_operator (cxx_pretty_printer
*pp
, tree t
)
792 switch (TREE_CODE (t
))
815 op
= tree_code_name
[TREE_CODE (t
)];
819 pp_cxx_identifier (pp
, op
);
823 /* assignment-expression:
824 conditional-expression
825 logical-or-expression assignment-operator assignment-expression
829 throw assignment-expression(opt)
831 assignment-operator: one of
832 = *= /= %= += -= >>= <<= &= ^= |= */
835 pp_cxx_assignment_expression (cxx_pretty_printer
*pp
, tree e
)
837 switch (TREE_CODE (e
))
841 pp_c_logical_or_expression (pp_c_base (pp
), TREE_OPERAND (e
, 0));
845 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 1));
849 pp_cxx_identifier (pp
, "throw");
850 if (TREE_OPERAND (e
, 0))
851 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 0));
855 pp_c_logical_or_expression (pp_c_base (pp
), TREE_OPERAND (e
, 0));
856 pp_cxx_assignment_operator (pp
, TREE_OPERAND (e
, 1));
857 pp_cxx_assignment_expression (pp
, TREE_OPERAND (e
, 2));
861 pp_cxx_conditional_expression (pp
, e
);
867 pp_cxx_expression (cxx_pretty_printer
*pp
, tree t
)
869 switch (TREE_CODE (t
))
874 pp_cxx_constant (pp
, t
);
878 pp_cxx_unqualified_id (pp
, t
);
886 pp_cxx_qualified_id (pp
, t
);
898 case TEMPLATE_TYPE_PARM
:
899 case TEMPLATE_PARM_INDEX
:
900 case TEMPLATE_TEMPLATE_PARM
:
902 pp_cxx_primary_expression (pp
, t
);
906 case DYNAMIC_CAST_EXPR
:
907 case STATIC_CAST_EXPR
:
908 case REINTERPRET_CAST_EXPR
:
909 case CONST_CAST_EXPR
:
913 case EMPTY_CLASS_EXPR
:
915 case PSEUDO_DTOR_EXPR
:
918 pp_cxx_postfix_expression (pp
, t
);
923 pp_cxx_new_expression (pp
, t
);
927 case VEC_DELETE_EXPR
:
928 pp_cxx_delete_expression (pp
, t
);
933 pp_cxx_unary_expression (pp
, t
);
937 pp_cxx_cast_expression (pp
, t
);
943 pp_cxx_pm_expression (pp
, t
);
949 pp_cxx_multiplicative_expression (pp
, t
);
953 pp_cxx_conditional_expression (pp
, t
);
960 pp_cxx_assignment_expression (pp
, t
);
963 case NON_DEPENDENT_EXPR
:
964 case MUST_NOT_THROW_EXPR
:
965 pp_cxx_expression (pp
, t
);
969 pp_c_expression (pp_c_base (pp
), t
);
977 /* function-specifier:
983 pp_cxx_function_specifier (cxx_pretty_printer
*pp
, tree t
)
985 switch (TREE_CODE (t
))
988 if (DECL_VIRTUAL_P (t
))
989 pp_cxx_identifier (pp
, "virtual");
990 else if (DECL_CONSTRUCTOR_P (t
) && DECL_NONCONVERTING_P (t
))
991 pp_cxx_identifier (pp
, "explicit");
993 pp_c_function_specifier (pp_c_base (pp
), t
);
1000 /* decl-specifier-seq:
1001 decl-specifier-seq(opt) decl-specifier
1004 storage-class-specifier
1011 pp_cxx_decl_specifier_seq (cxx_pretty_printer
*pp
, tree t
)
1013 switch (TREE_CODE (t
))
1019 pp_cxx_storage_class_specifier (pp
, t
);
1020 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (t
));
1024 pp_cxx_identifier (pp
, "typedef");
1025 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (t
));
1029 if (TYPE_PTRMEMFUNC_P (t
))
1031 tree pfm
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
1032 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (TREE_TYPE (pfm
)));
1033 pp_cxx_whitespace (pp
);
1034 pp_cxx_ptr_operator (pp
, t
);
1039 /* Constructors don't have return types. And conversion functions
1040 do not have a type-specifier in their return types. */
1041 if (DECL_CONSTRUCTOR_P (t
) || DECL_CONV_FN_P (t
))
1042 pp_cxx_function_specifier (pp
, t
);
1043 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1044 pp_cxx_decl_specifier_seq (pp
, TREE_TYPE (TREE_TYPE (t
)));
1047 pp_c_declaration_specifiers (pp_c_base (pp
), t
);
1052 /* simple-type-specifier:
1053 ::(opt) nested-name-specifier(opt) type-name
1054 ::(opt) nested-name-specifier(opt) template(opt) template-id
1068 pp_cxx_simple_type_specifier (cxx_pretty_printer
*pp
, tree t
)
1070 switch (TREE_CODE (t
))
1075 pp_cxx_qualified_id (pp
, t
);
1078 case TEMPLATE_TYPE_PARM
:
1079 case TEMPLATE_TEMPLATE_PARM
:
1080 case TEMPLATE_PARM_INDEX
:
1081 pp_cxx_unqualified_id (pp
, t
);
1085 pp_cxx_identifier (pp
, "typename");
1086 pp_cxx_nested_name_specifier (pp
, TYPE_CONTEXT (t
));
1087 pp_cxx_unqualified_id (pp
, TYPE_NAME (t
));
1091 pp_c_type_specifier (pp_c_base (pp
), t
);
1096 /* type-specifier-seq:
1097 type-specifier type-specifier-seq(opt)
1100 simple-type-specifier
1103 elaborated-type-specifier
1107 pp_cxx_type_specifier_seq (cxx_pretty_printer
*pp
, tree t
)
1109 switch (TREE_CODE (t
))
1112 case TEMPLATE_TYPE_PARM
:
1113 case TEMPLATE_TEMPLATE_PARM
:
1115 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1116 pp_cxx_cv_qualifier_seq (pp
, t
);
1117 pp_cxx_simple_type_specifier (pp
, t
);
1121 pp_cxx_type_specifier_seq (pp
, TREE_TYPE (t
));
1122 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (t
));
1123 pp_cxx_nested_name_specifier (pp
, TYPE_METHOD_BASETYPE (t
));
1127 if (!(TREE_CODE (t
) == FUNCTION_DECL
&& DECL_CONSTRUCTOR_P (t
)))
1128 pp_c_specifier_qualifier_list (pp_c_base (pp
), t
);
1133 * cv-qualifier-seq(opt)
1135 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1138 pp_cxx_ptr_operator (cxx_pretty_printer
*pp
, tree t
)
1140 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
1142 switch (TREE_CODE (t
))
1144 case REFERENCE_TYPE
:
1146 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
1147 || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t
)))
1148 pp_cxx_ptr_operator (pp
, TREE_TYPE (t
));
1149 if (TREE_CODE (t
) == POINTER_TYPE
)
1152 pp_cxx_cv_qualifier_seq (pp
, t
);
1159 if (TYPE_PTRMEMFUNC_P (t
))
1161 pp_cxx_left_paren (pp
);
1162 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEMFUNC_OBJECT_TYPE (t
));
1167 if (TYPE_PTR_TO_MEMBER_P (t
))
1169 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1170 pp_cxx_left_paren (pp
);
1171 pp_cxx_nested_name_specifier (pp
, TYPE_PTRMEM_CLASS_TYPE (t
));
1173 pp_cxx_cv_qualifier_seq (pp
, t
);
1176 /* else fall through. */
1179 pp_unsupported_tree (pp
, t
);
1185 pp_cxx_implicit_parameter_type (tree mf
)
1187 return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf
))));
1191 parameter-declaration:
1192 decl-specifier-seq declarator
1193 decl-specifier-seq declarator = assignment-expression
1194 decl-specifier-seq abstract-declarator(opt)
1195 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1198 pp_cxx_parameter_declaration (cxx_pretty_printer
*pp
, tree t
)
1200 pp_cxx_decl_specifier_seq (pp
, t
);
1202 pp_cxx_abstract_declarator (pp
, t
);
1204 pp_cxx_declarator (pp
, t
);
1207 /* parameter-declaration-clause:
1208 parameter-declaration-list(opt) ...(opt)
1209 parameter-declaration-list , ...
1211 parameter-declaration-list:
1212 parameter-declaration
1213 parameter-declaration-list , parameter-declaration */
1216 pp_cxx_parameter_declaration_clause (cxx_pretty_printer
*pp
, tree t
)
1218 tree args
= TYPE_P (t
) ? NULL
: FUNCTION_FIRST_USER_PARM (t
);
1220 TYPE_P (t
) ? TYPE_ARG_TYPES (t
) : FUNCTION_FIRST_USER_PARMTYPE (t
);
1221 const bool abstract
= args
== NULL
1222 || pp_c_base (pp
)->flags
& pp_c_flag_abstract
;
1225 /* Skip artificial parameter for nonstatic member functions. */
1226 if (TREE_CODE (t
) == METHOD_TYPE
)
1227 types
= TREE_CHAIN (types
);
1229 pp_cxx_left_paren (pp
);
1230 for (; args
; args
= TREE_CHAIN (args
), types
= TREE_CHAIN (types
))
1233 pp_cxx_separate_with (pp
, ',');
1235 pp_cxx_parameter_declaration (pp
, abstract
? TREE_VALUE (types
) : args
);
1236 if (!abstract
&& pp_c_base (pp
)->flags
& pp_cxx_flag_default_argument
)
1238 pp_cxx_whitespace (pp
);
1240 pp_cxx_whitespace (pp
);
1241 pp_cxx_assignment_expression (pp
, TREE_PURPOSE (types
));
1244 pp_cxx_right_paren (pp
);
1247 /* exception-specification:
1248 throw ( type-id-list(opt) )
1252 type-id-list , type-id */
1255 pp_cxx_exception_specification (cxx_pretty_printer
*pp
, tree t
)
1257 tree ex_spec
= TYPE_RAISES_EXCEPTIONS (t
);
1259 if (!TYPE_NOTHROW_P (t
) && ex_spec
== NULL
)
1261 pp_cxx_identifier (pp
, "throw");
1262 pp_cxx_left_paren (pp
);
1263 for (; ex_spec
&& TREE_VALUE (ex_spec
); ex_spec
= TREE_CHAIN (ex_spec
))
1265 pp_cxx_type_id (pp
, TREE_VALUE (ex_spec
));
1266 if (TREE_CHAIN (ex_spec
))
1267 pp_cxx_separate_with (pp
, ',');
1269 pp_cxx_right_paren (pp
);
1272 /* direct-declarator:
1274 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1275 exception-specification(opt)
1276 direct-declaration [ constant-expression(opt) ]
1280 pp_cxx_direct_declarator (cxx_pretty_printer
*pp
, tree t
)
1282 switch (TREE_CODE (t
))
1290 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (t
));
1291 pp_cxx_id_expression (pp
, DECL_NAME (t
));
1293 pp_cxx_abstract_declarator (pp
, TREE_TYPE (t
));
1297 pp_cxx_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
1298 pp_cxx_id_expression (pp
, t
);
1299 pp_cxx_parameter_declaration_clause (pp
, t
);
1301 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t
))
1303 pp_base (pp
)->padding
= pp_before
;
1304 pp_cxx_cv_qualifier_seq (pp
, pp_cxx_implicit_parameter_type (t
));
1307 pp_cxx_exception_specification (pp
, TREE_TYPE (t
));
1312 case TEMPLATE_TYPE_PARM
:
1313 case TEMPLATE_PARM_INDEX
:
1314 case TEMPLATE_TEMPLATE_PARM
:
1318 pp_c_direct_declarator (pp_c_base (pp
), t
);
1325 ptr-operator declarator */
1328 pp_cxx_declarator (cxx_pretty_printer
*pp
, tree t
)
1330 pp_cxx_direct_declarator (pp
, t
);
1333 /* ctor-initializer:
1334 : mem-initializer-list
1336 mem-initializer-list:
1338 mem-initializer , mem-initializer-list
1341 mem-initializer-id ( expression-list(opt) )
1344 ::(opt) nested-name-specifier(opt) class-name
1348 pp_cxx_ctor_initializer (cxx_pretty_printer
*pp
, tree t
)
1350 t
= TREE_OPERAND (t
, 0);
1351 pp_cxx_whitespace (pp
);
1353 pp_cxx_whitespace (pp
);
1354 for (; t
; t
= TREE_CHAIN (t
))
1356 pp_cxx_primary_expression (pp
, TREE_PURPOSE (t
));
1357 pp_cxx_call_argument_list (pp
, TREE_VALUE (t
));
1359 pp_cxx_separate_with (pp
, ',');
1363 /* function-definition:
1364 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1365 decl-specifier-seq(opt) declarator function-try-block */
1368 pp_cxx_function_definition (cxx_pretty_printer
*pp
, tree t
)
1370 tree saved_scope
= pp
->enclosing_scope
;
1371 pp_cxx_decl_specifier_seq (pp
, t
);
1372 pp_cxx_declarator (pp
, t
);
1373 pp_needs_newline (pp
) = true;
1374 pp
->enclosing_scope
= DECL_CONTEXT (t
);
1375 if (DECL_SAVED_TREE (t
))
1376 pp_cxx_statement (pp
, DECL_SAVED_TREE (t
));
1379 pp_cxx_semicolon (pp
);
1380 pp_needs_newline (pp
) = true;
1383 pp
->enclosing_scope
= saved_scope
;
1386 /* abstract-declarator:
1387 ptr-operator abstract-declarator(opt)
1388 direct-abstract-declarator */
1391 pp_cxx_abstract_declarator (cxx_pretty_printer
*pp
, tree t
)
1393 if (TYPE_PTRMEM_P (t
) || TYPE_PTRMEMFUNC_P (t
))
1394 pp_cxx_right_paren (pp
);
1395 else if (POINTER_TYPE_P (t
))
1397 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
1398 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1399 pp_cxx_right_paren (pp
);
1402 pp_cxx_direct_abstract_declarator (pp
, t
);
1405 /* direct-abstract-declarator:
1406 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1407 cv-qualifier-seq(opt) exception-specification(opt)
1408 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1409 ( abstract-declarator ) */
1412 pp_cxx_direct_abstract_declarator (cxx_pretty_printer
*pp
, tree t
)
1414 switch (TREE_CODE (t
))
1416 case REFERENCE_TYPE
:
1417 pp_cxx_abstract_declarator (pp
, t
);
1421 if (TYPE_PTRMEMFUNC_P (t
))
1422 pp_cxx_direct_abstract_declarator (pp
, TYPE_PTRMEMFUNC_FN_TYPE (t
));
1427 pp_cxx_parameter_declaration_clause (pp
, t
);
1428 pp_cxx_direct_abstract_declarator (pp
, TREE_TYPE (t
));
1429 if (TREE_CODE (t
) == METHOD_TYPE
)
1431 pp_base (pp
)->padding
= pp_before
;
1432 pp_cxx_cv_qualifier_seq
1433 (pp
, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))));
1435 pp_cxx_exception_specification (pp
, t
);
1439 case TEMPLATE_TYPE_PARM
:
1440 case TEMPLATE_TEMPLATE_PARM
:
1441 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1442 case UNBOUND_CLASS_TEMPLATE
:
1446 pp_c_direct_abstract_declarator (pp_c_base (pp
), t
);
1452 type-specifier-seq abstract-declarator(opt) */
1455 pp_cxx_type_id (cxx_pretty_printer
*pp
, tree t
)
1457 pp_flags saved_flags
= pp_c_base (pp
)->flags
;
1458 pp_c_base (pp
)->flags
|= pp_c_flag_abstract
;
1460 switch (TREE_CODE (t
))
1467 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1468 case UNBOUND_CLASS_TEMPLATE
:
1469 case TEMPLATE_TEMPLATE_PARM
:
1470 case TEMPLATE_TYPE_PARM
:
1471 case TEMPLATE_PARM_INDEX
:
1474 case TEMPLATE_ID_EXPR
:
1475 pp_cxx_type_specifier_seq (pp
, t
);
1479 pp_c_type_id (pp_c_base (pp
), t
);
1483 pp_c_base (pp
)->flags
= saved_flags
;
1486 /* template-argument-list:
1488 template-argument-list, template-argument
1491 assignment-expression
1496 pp_cxx_template_argument_list (cxx_pretty_printer
*pp
, tree t
)
1501 for (i
= 0; i
< TREE_VEC_LENGTH (t
); ++i
)
1503 tree arg
= TREE_VEC_ELT (t
, i
);
1505 pp_cxx_separate_with (pp
, ',');
1506 if (TYPE_P (arg
) || (TREE_CODE (arg
) == TEMPLATE_DECL
1507 && TYPE_P (DECL_TEMPLATE_RESULT (arg
))))
1508 pp_cxx_type_id (pp
, arg
);
1510 pp_cxx_expression (pp
, arg
);
1516 pp_cxx_exception_declaration (cxx_pretty_printer
*pp
, tree t
)
1518 t
= DECL_EXPR_DECL (t
);
1519 pp_cxx_type_specifier_seq (pp
, t
);
1521 pp_cxx_abstract_declarator (pp
, t
);
1523 pp_cxx_declarator (pp
, t
);
1529 pp_cxx_statement (cxx_pretty_printer
*pp
, tree t
)
1531 switch (TREE_CODE (t
))
1533 case CTOR_INITIALIZER
:
1534 pp_cxx_ctor_initializer (pp
, t
);
1538 pp_cxx_identifier (pp
, "using");
1539 pp_cxx_identifier (pp
, "namespace");
1540 if (DECL_CONTEXT (t
))
1541 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
1542 pp_cxx_qualified_id (pp
, USING_STMT_NAMESPACE (t
));
1546 pp_cxx_identifier (pp
, "using");
1547 pp_cxx_nested_name_specifier (pp
, USING_DECL_SCOPE (t
));
1548 pp_cxx_unqualified_id (pp
, DECL_NAME (t
));
1555 try compound-statement handler-seq */
1557 pp_maybe_newline_and_indent (pp
, 0);
1558 pp_cxx_identifier (pp
, "try");
1559 pp_newline_and_indent (pp
, 3);
1560 pp_cxx_statement (pp
, TRY_STMTS (t
));
1561 pp_newline_and_indent (pp
, -3);
1565 pp_cxx_statement (pp
, TRY_HANDLERS (t
));
1570 handler handler-seq(opt)
1573 catch ( exception-declaration ) compound-statement
1575 exception-declaration:
1576 type-specifier-seq declarator
1577 type-specifier-seq abstract-declarator
1580 pp_cxx_identifier (pp
, "catch");
1581 pp_cxx_left_paren (pp
);
1582 pp_cxx_exception_declaration (pp
, HANDLER_PARMS (t
));
1583 pp_cxx_right_paren (pp
);
1584 pp_indentation (pp
) += 3;
1585 pp_needs_newline (pp
) = true;
1586 pp_cxx_statement (pp
, HANDLER_BODY (t
));
1587 pp_indentation (pp
) -= 3;
1588 pp_needs_newline (pp
) = true;
1591 /* selection-statement:
1592 if ( expression ) statement
1593 if ( expression ) statement else statement */
1595 pp_cxx_identifier (pp
, "if");
1596 pp_cxx_whitespace (pp
);
1597 pp_cxx_left_paren (pp
);
1598 pp_cxx_expression (pp
, IF_COND (t
));
1599 pp_cxx_right_paren (pp
);
1600 pp_newline_and_indent (pp
, 2);
1601 pp_cxx_statement (pp
, THEN_CLAUSE (t
));
1602 pp_newline_and_indent (pp
, -2);
1603 if (ELSE_CLAUSE (t
))
1605 tree else_clause
= ELSE_CLAUSE (t
);
1606 pp_cxx_identifier (pp
, "else");
1607 if (TREE_CODE (else_clause
) == IF_STMT
)
1608 pp_cxx_whitespace (pp
);
1610 pp_newline_and_indent (pp
, 2);
1611 pp_cxx_statement (pp
, else_clause
);
1612 if (TREE_CODE (else_clause
) != IF_STMT
)
1613 pp_newline_and_indent (pp
, -2);
1618 pp_cxx_identifier (pp
, "switch");
1620 pp_cxx_left_paren (pp
);
1621 pp_cxx_expression (pp
, SWITCH_STMT_COND (t
));
1622 pp_cxx_right_paren (pp
);
1623 pp_indentation (pp
) += 3;
1624 pp_needs_newline (pp
) = true;
1625 pp_cxx_statement (pp
, SWITCH_STMT_BODY (t
));
1626 pp_newline_and_indent (pp
, -3);
1629 /* iteration-statement:
1630 while ( expression ) statement
1631 do statement while ( expression ) ;
1632 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1633 for ( declaration expression(opt) ; expression(opt) ) statement */
1635 pp_cxx_identifier (pp
, "while");
1637 pp_cxx_left_paren (pp
);
1638 pp_cxx_expression (pp
, WHILE_COND (t
));
1639 pp_cxx_right_paren (pp
);
1640 pp_newline_and_indent (pp
, 3);
1641 pp_cxx_statement (pp
, WHILE_BODY (t
));
1642 pp_indentation (pp
) -= 3;
1643 pp_needs_newline (pp
) = true;
1647 pp_cxx_identifier (pp
, "do");
1648 pp_newline_and_indent (pp
, 3);
1649 pp_cxx_statement (pp
, DO_BODY (t
));
1650 pp_newline_and_indent (pp
, -3);
1651 pp_cxx_identifier (pp
, "while");
1653 pp_cxx_left_paren (pp
);
1654 pp_cxx_expression (pp
, DO_COND (t
));
1655 pp_cxx_right_paren (pp
);
1656 pp_cxx_semicolon (pp
);
1657 pp_needs_newline (pp
) = true;
1661 pp_cxx_identifier (pp
, "for");
1663 pp_cxx_left_paren (pp
);
1664 if (FOR_INIT_STMT (t
))
1665 pp_cxx_statement (pp
, FOR_INIT_STMT (t
));
1667 pp_cxx_semicolon (pp
);
1668 pp_needs_newline (pp
) = false;
1669 pp_cxx_whitespace (pp
);
1671 pp_cxx_expression (pp
, FOR_COND (t
));
1672 pp_cxx_semicolon (pp
);
1673 pp_needs_newline (pp
) = false;
1674 pp_cxx_whitespace (pp
);
1676 pp_cxx_expression (pp
, FOR_EXPR (t
));
1677 pp_cxx_right_paren (pp
);
1678 pp_newline_and_indent (pp
, 3);
1679 pp_cxx_statement (pp
, FOR_BODY (t
));
1680 pp_indentation (pp
) -= 3;
1681 pp_needs_newline (pp
) = true;
1687 return expression(opt) ; */
1690 pp_identifier (pp
, TREE_CODE (t
) == BREAK_STMT
? "break" : "continue");
1691 pp_cxx_semicolon (pp
);
1692 pp_needs_newline (pp
) = true;
1695 /* expression-statement:
1696 expression(opt) ; */
1698 pp_cxx_expression (pp
, EXPR_STMT_EXPR (t
));
1699 pp_cxx_semicolon (pp
);
1700 pp_needs_newline (pp
) = true;
1704 pp_cxx_identifier (pp
, "try");
1705 pp_newline_and_indent (pp
, 2);
1706 pp_cxx_statement (pp
, CLEANUP_BODY (t
));
1707 pp_newline_and_indent (pp
, -2);
1708 pp_cxx_identifier (pp
, CLEANUP_EH_ONLY (t
) ? "catch" : "finally");
1709 pp_newline_and_indent (pp
, 2);
1710 pp_cxx_statement (pp
, CLEANUP_EXPR (t
));
1711 pp_newline_and_indent (pp
, -2);
1715 pp_cxx_declaration (pp
, t
);
1719 pp_c_statement (pp_c_base (pp
), t
);
1724 /* original-namespace-definition:
1725 namespace identifier { namespace-body }
1727 As an edge case, we also handle unnamed namespace definition here. */
1730 pp_cxx_original_namespace_definition (cxx_pretty_printer
*pp
, tree t
)
1732 pp_cxx_identifier (pp
, "namespace");
1733 if (DECL_CONTEXT (t
))
1734 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
1736 pp_cxx_unqualified_id (pp
, t
);
1737 pp_cxx_whitespace (pp
);
1738 pp_cxx_left_brace (pp
);
1739 /* We do not print the namespace-body. */
1740 pp_cxx_whitespace (pp
);
1741 pp_cxx_right_brace (pp
);
1747 namespace-alias-definition:
1748 namespace identifier = qualified-namespace-specifier ;
1750 qualified-namespace-specifier:
1751 ::(opt) nested-name-specifier(opt) namespace-name */
1754 pp_cxx_namespace_alias_definition (cxx_pretty_printer
*pp
, tree t
)
1756 pp_cxx_identifier (pp
, "namespace");
1757 if (DECL_CONTEXT (t
))
1758 pp_cxx_nested_name_specifier (pp
, DECL_CONTEXT (t
));
1759 pp_cxx_unqualified_id (pp
, t
);
1760 pp_cxx_whitespace (pp
);
1762 pp_cxx_whitespace (pp
);
1763 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t
)))
1764 pp_cxx_nested_name_specifier (pp
,
1765 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t
)));
1766 pp_cxx_qualified_id (pp
, DECL_NAMESPACE_ALIAS (t
));
1767 pp_cxx_semicolon (pp
);
1770 /* simple-declaration:
1771 decl-specifier-seq(opt) init-declarator-list(opt) */
1774 pp_cxx_simple_declaration (cxx_pretty_printer
*pp
, tree t
)
1776 pp_cxx_decl_specifier_seq (pp
, t
);
1777 pp_cxx_init_declarator (pp
, t
);
1778 pp_cxx_semicolon (pp
);
1779 pp_needs_newline (pp
) = true;
1783 template-parameter-list:
1785 template-parameter-list , template-parameter */
1788 pp_cxx_template_parameter_list (cxx_pretty_printer
*pp
, tree t
)
1790 const int n
= TREE_VEC_LENGTH (t
);
1792 for (i
= 0; i
< n
; ++i
)
1795 pp_cxx_separate_with (pp
, ',');
1796 pp_cxx_template_parameter (pp
, TREE_VEC_ELT (t
, i
));
1800 /* template-parameter:
1802 parameter-declaration
1805 class identifier(opt)
1806 class identifier(op) = type-id
1807 typename identifier(opt)
1808 typename identifier(opt) = type-id
1809 template < template-parameter-list > class identifier(opt)
1810 template < template-parameter-list > class identifier(opt) = template-name */
1813 pp_cxx_template_parameter (cxx_pretty_printer
*pp
, tree t
)
1815 tree parameter
= TREE_VALUE (t
);
1816 switch (TREE_CODE (parameter
))
1819 pp_cxx_identifier (pp
, "class");
1820 if (DECL_NAME (parameter
))
1821 pp_cxx_tree_identifier (pp
, DECL_NAME (parameter
));
1822 /* FIXME: Chech if we should print also default argument. */
1826 pp_cxx_parameter_declaration (pp
, parameter
);
1833 pp_unsupported_tree (pp
, t
);
1838 /* Pretty-print a template parameter in the canonical form
1839 "template-parameter-<level>-<position in parameter list>". */
1842 pp_cxx_canonical_template_parameter (cxx_pretty_printer
*pp
, tree parm
)
1844 const enum tree_code code
= TREE_CODE (parm
);
1846 /* Brings type template parameters to the canonical forms. */
1847 if (code
== TEMPLATE_TYPE_PARM
|| code
== TEMPLATE_TEMPLATE_PARM
1848 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
)
1849 parm
= TEMPLATE_TYPE_PARM_INDEX (parm
);
1851 pp_cxx_begin_template_argument_list (pp
);
1852 pp_cxx_identifier (pp
, "template-parameter-");
1853 pp_wide_integer (pp
, TEMPLATE_PARM_LEVEL (parm
));
1855 pp_wide_integer (pp
, TEMPLATE_PARM_IDX (parm
) + 1);
1856 pp_cxx_end_template_argument_list (pp
);
1860 template-declaration:
1861 export(opt) template < template-parameter-list > declaration */
1864 pp_cxx_template_declaration (cxx_pretty_printer
*pp
, tree t
)
1866 tree tmpl
= most_general_template (t
);
1870 pp_maybe_newline_and_indent (pp
, 0);
1871 for (level
= DECL_TEMPLATE_PARMS (tmpl
); level
; level
= TREE_CHAIN (level
))
1873 pp_cxx_identifier (pp
, "template");
1874 pp_cxx_begin_template_argument_list (pp
);
1875 pp_cxx_template_parameter_list (pp
, TREE_VALUE (level
));
1876 pp_cxx_end_template_argument_list (pp
);
1877 pp_newline_and_indent (pp
, 3);
1880 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_SAVED_TREE (t
))
1881 pp_cxx_function_definition (pp
, t
);
1883 pp_cxx_simple_declaration (pp
, t
);
1887 pp_cxx_explicit_specialization (cxx_pretty_printer
*pp
, tree t
)
1889 pp_unsupported_tree (pp
, t
);
1893 pp_cxx_explicit_instantiation (cxx_pretty_printer
*pp
, tree t
)
1895 pp_unsupported_tree (pp
, t
);
1902 template-declaration
1903 explicit-instantiation
1904 explicit-specialization
1905 linkage-specification
1906 namespace-definition
1911 namespace-alias-definition
1914 static_assert-declaration */
1916 pp_cxx_declaration (cxx_pretty_printer
*pp
, tree t
)
1918 if (TREE_CODE (t
) == STATIC_ASSERT
)
1920 pp_cxx_identifier (pp
, "static_assert");
1921 pp_cxx_left_paren (pp
);
1922 pp_cxx_expression (pp
, STATIC_ASSERT_CONDITION (t
));
1923 pp_cxx_separate_with (pp
, ',');
1924 pp_cxx_expression (pp
, STATIC_ASSERT_MESSAGE (t
));
1925 pp_cxx_right_paren (pp
);
1927 else if (!DECL_LANG_SPECIFIC (t
))
1928 pp_cxx_simple_declaration (pp
, t
);
1929 else if (DECL_USE_TEMPLATE (t
))
1930 switch (DECL_USE_TEMPLATE (t
))
1933 pp_cxx_template_declaration (pp
, t
);
1937 pp_cxx_explicit_specialization (pp
, t
);
1941 pp_cxx_explicit_instantiation (pp
, t
);
1947 else switch (TREE_CODE (t
))
1951 pp_cxx_simple_declaration (pp
, t
);
1955 if (DECL_SAVED_TREE (t
))
1956 pp_cxx_function_definition (pp
, t
);
1958 pp_cxx_simple_declaration (pp
, t
);
1961 case NAMESPACE_DECL
:
1962 if (DECL_NAMESPACE_ALIAS (t
))
1963 pp_cxx_namespace_alias_definition (pp
, t
);
1965 pp_cxx_original_namespace_definition (pp
, t
);
1969 pp_unsupported_tree (pp
, t
);
1975 typedef c_pretty_print_fn pp_fun
;
1977 /* Initialization of a C++ pretty-printer object. */
1980 pp_cxx_pretty_printer_init (cxx_pretty_printer
*pp
)
1982 pp_c_pretty_printer_init (pp_c_base (pp
));
1983 pp_set_line_maximum_length (pp
, 0);
1985 pp
->c_base
.declaration
= (pp_fun
) pp_cxx_declaration
;
1986 pp
->c_base
.declaration_specifiers
= (pp_fun
) pp_cxx_decl_specifier_seq
;
1987 pp
->c_base
.function_specifier
= (pp_fun
) pp_cxx_function_specifier
;
1988 pp
->c_base
.type_specifier_seq
= (pp_fun
) pp_cxx_type_specifier_seq
;
1989 pp
->c_base
.declarator
= (pp_fun
) pp_cxx_declarator
;
1990 pp
->c_base
.direct_declarator
= (pp_fun
) pp_cxx_direct_declarator
;
1991 pp
->c_base
.parameter_list
= (pp_fun
) pp_cxx_parameter_declaration_clause
;
1992 pp
->c_base
.type_id
= (pp_fun
) pp_cxx_type_id
;
1993 pp
->c_base
.abstract_declarator
= (pp_fun
) pp_cxx_abstract_declarator
;
1994 pp
->c_base
.direct_abstract_declarator
=
1995 (pp_fun
) pp_cxx_direct_abstract_declarator
;
1996 pp
->c_base
.simple_type_specifier
= (pp_fun
)pp_cxx_simple_type_specifier
;
1998 /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
2000 pp
->c_base
.constant
= (pp_fun
) pp_cxx_constant
;
2001 pp
->c_base
.id_expression
= (pp_fun
) pp_cxx_id_expression
;
2002 pp
->c_base
.primary_expression
= (pp_fun
) pp_cxx_primary_expression
;
2003 pp
->c_base
.postfix_expression
= (pp_fun
) pp_cxx_postfix_expression
;
2004 pp
->c_base
.unary_expression
= (pp_fun
) pp_cxx_unary_expression
;
2005 pp
->c_base
.multiplicative_expression
= (pp_fun
) pp_cxx_multiplicative_expression
;
2006 pp
->c_base
.conditional_expression
= (pp_fun
) pp_cxx_conditional_expression
;
2007 pp
->c_base
.assignment_expression
= (pp_fun
) pp_cxx_assignment_expression
;
2008 pp
->c_base
.expression
= (pp_fun
) pp_cxx_expression
;
2009 pp
->enclosing_scope
= global_namespace
;