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);
301 pp_cxx_constant (cxx_pretty_printer *pp, tree t)
303 switch (TREE_CODE (t))
307 const bool in_parens = PAREN_STRING_LITERAL_P (t);
309 pp_cxx_left_paren (pp);
310 pp_c_constant (pp_c_base (pp), t);
312 pp_cxx_right_paren (pp);
317 pp_c_constant (pp_c_base (pp), t);
327 pp_cxx_id_expression (cxx_pretty_printer *pp, tree t)
329 if (TREE_CODE (t) == OVERLOAD)
331 if (DECL_P (t) && DECL_CONTEXT (t))
332 pp_cxx_qualified_id (pp, t);
334 pp_cxx_unqualified_id (pp, t);
337 /* primary-expression:
341 :: operator-function-id
347 pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
349 switch (TREE_CODE (t))
354 pp_cxx_constant (pp, t);
358 t = BASELINK_FUNCTIONS (t);
366 pp_cxx_id_expression (pp, t);
370 case TEMPLATE_TYPE_PARM:
371 case TEMPLATE_TEMPLATE_PARM:
372 case TEMPLATE_PARM_INDEX:
373 pp_cxx_unqualified_id (pp, t);
377 pp_cxx_left_paren (pp);
378 pp_cxx_statement (pp, STMT_EXPR_STMT (t));
379 pp_cxx_right_paren (pp);
383 pp_c_primary_expression (pp_c_base (pp), t);
388 /* postfix-expression:
390 postfix-expression [ expression ]
391 postfix-expression ( expression-list(opt) )
392 simple-type-specifier ( expression-list(opt) )
393 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
394 typename ::(opt) nested-name-specifier template(opt)
395 template-id ( expression-list(opt) )
396 postfix-expression . template(opt) ::(opt) id-expression
397 postfix-expression -> template(opt) ::(opt) id-expression
398 postfix-expression . pseudo-destructor-name
399 postfix-expression -> pseudo-destructor-name
400 postfix-expression ++
401 postfix-expression --
402 dynamic_cast < type-id > ( expression )
403 static_cast < type-id > ( expression )
404 reinterpret_cast < type-id > ( expression )
405 const_cast < type-id > ( expression )
406 typeid ( expression )
407 typeif ( type-id ) */
410 pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t)
412 enum tree_code code = TREE_CODE (t);
419 tree fun = TREE_OPERAND (t, 0);
420 tree args = TREE_OPERAND (t, 1);
421 tree saved_scope = pp->enclosing_scope;
423 if (TREE_CODE (fun) == ADDR_EXPR)
424 fun = TREE_OPERAND (fun, 0);
426 /* In templates, where there is no way to tell whether a given
427 call uses an actual member function. So the parser builds
428 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
429 instantiation time. */
430 if (TREE_CODE (fun) != FUNCTION_DECL)
432 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun))
434 tree object = code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t)
435 ? TREE_OPERAND (t, 2)
438 while (TREE_CODE (object) == NOP_EXPR)
439 object = TREE_OPERAND (object, 0);
441 if (TREE_CODE (object) == ADDR_EXPR)
442 object = TREE_OPERAND (object, 0);
444 if (TREE_CODE (TREE_TYPE (object)) != POINTER_TYPE)
446 pp_cxx_postfix_expression (pp, object);
451 pp_cxx_postfix_expression (pp, object);
454 args = TREE_CHAIN (args);
455 pp->enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
458 pp_cxx_postfix_expression (pp, fun);
459 pp->enclosing_scope = saved_scope;
460 pp_cxx_call_argument_list (pp, args);
462 if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
464 pp_cxx_separate_with (pp, ',');
465 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 2));
478 pp_cxx_primary_expression (pp, t);
481 case DYNAMIC_CAST_EXPR:
482 case STATIC_CAST_EXPR:
483 case REINTERPRET_CAST_EXPR:
484 case CONST_CAST_EXPR:
485 if (code == DYNAMIC_CAST_EXPR)
486 pp_cxx_identifier (pp, "dynamic_cast");
487 else if (code == STATIC_CAST_EXPR)
488 pp_cxx_identifier (pp, "static_cast");
489 else if (code == REINTERPRET_CAST_EXPR)
490 pp_cxx_identifier (pp, "reinterpret_cast");
492 pp_cxx_identifier (pp, "const_cast");
493 pp_cxx_begin_template_argument_list (pp);
494 pp_cxx_type_id (pp, TREE_TYPE (t));
495 pp_cxx_end_template_argument_list (pp);
497 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
501 case EMPTY_CLASS_EXPR:
502 pp_cxx_type_id (pp, TREE_TYPE (t));
508 t = TREE_OPERAND (t, 0);
509 pp_cxx_identifier (pp, "typeid");
512 pp_cxx_type_id (pp, t);
514 pp_cxx_expression (pp, t);
518 case PSEUDO_DTOR_EXPR:
519 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
521 pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1));
522 pp_cxx_colon_colon (pp);
524 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2));
528 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
533 pp_c_postfix_expression (pp_c_base (pp), t);
539 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
540 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
546 type-specifier-seq new-declarator(opt)
549 ptr-operator new-declarator(opt)
550 direct-new-declarator
552 direct-new-declarator
554 direct-new-declarator [ constant-expression ]
557 ( expression-list(opt) ) */
560 pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
562 enum tree_code code = TREE_CODE (t);
567 if (NEW_EXPR_USE_GLOBAL (t))
568 pp_cxx_colon_colon (pp);
569 pp_cxx_identifier (pp, "new");
570 if (TREE_OPERAND (t, 0))
572 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
575 /* FIXME: array-types are built with one more element. */
576 pp_cxx_type_id (pp, TREE_OPERAND (t, 1));
577 if (TREE_OPERAND (t, 2))
580 t = TREE_OPERAND (t, 2);
581 if (TREE_CODE (t) == TREE_LIST)
582 pp_c_expression_list (pp_c_base (pp), t);
583 else if (t == void_zero_node)
584 ; /* OK, empty initializer list. */
586 pp_cxx_expression (pp, t);
592 pp_unsupported_tree (pp, t);
596 /* delete-expression:
597 ::(opt) delete cast-expression
598 ::(opt) delete [ ] cast-expression */
601 pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
603 enum tree_code code = TREE_CODE (t);
607 case VEC_DELETE_EXPR:
608 if (DELETE_EXPR_USE_GLOBAL (t))
609 pp_cxx_colon_colon (pp);
610 pp_cxx_identifier (pp, "delete");
611 if (code == VEC_DELETE_EXPR)
613 pp_left_bracket (pp);
614 pp_right_bracket (pp);
616 pp_c_cast_expression (pp_c_base (pp), TREE_OPERAND (t, 0));
620 pp_unsupported_tree (pp, t);
628 unary-operator cast-expression
629 sizeof unary-expression
634 unary-operator: one of
638 __alignof__ unary-expression
639 __alignof__ ( type-id ) */
642 pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
644 enum tree_code code = TREE_CODE (t);
649 pp_cxx_new_expression (pp, t);
653 case VEC_DELETE_EXPR:
654 pp_cxx_delete_expression (pp, t);
659 pp_cxx_identifier (pp, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
660 pp_cxx_whitespace (pp);
661 if (TYPE_P (TREE_OPERAND (t, 0)))
663 pp_cxx_left_paren (pp);
664 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
665 pp_cxx_right_paren (pp);
668 pp_unary_expression (pp, TREE_OPERAND (t, 0));
671 case UNARY_PLUS_EXPR:
673 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0));
677 pp_c_unary_expression (pp_c_base (pp), t);
684 ( type-id ) cast-expression */
687 pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
689 switch (TREE_CODE (t))
692 pp_cxx_type_id (pp, TREE_TYPE (t));
693 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
697 pp_c_cast_expression (pp_c_base (pp), t);
704 pm-expression .* cast-expression
705 pm-expression ->* cast-expression */
708 pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t)
710 switch (TREE_CODE (t))
712 /* Handle unfortunate OFFESET_REF overloading here. */
714 if (TYPE_P (TREE_OPERAND (t, 0)))
716 pp_cxx_qualified_id (pp, t);
719 /* Else fall through. */
722 pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
725 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1));
730 pp_cxx_cast_expression (pp, t);
735 /* multiplicative-expression:
737 multiplicative-expression * pm-expression
738 multiplicative-expression / pm-expression
739 multiplicative-expression % pm-expression */
742 pp_cxx_multiplicative_expression (cxx_pretty_printer *pp, tree e)
744 enum tree_code code = TREE_CODE (e);
750 pp_cxx_multiplicative_expression (pp, TREE_OPERAND (e, 0));
752 if (code == MULT_EXPR)
754 else if (code == TRUNC_DIV_EXPR)
759 pp_cxx_pm_expression (pp, TREE_OPERAND (e, 1));
763 pp_cxx_pm_expression (pp, e);
768 /* conditional-expression:
769 logical-or-expression
770 logical-or-expression ? expression : assignment-expression */
773 pp_cxx_conditional_expression (cxx_pretty_printer *pp, tree e)
775 if (TREE_CODE (e) == COND_EXPR)
777 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
781 pp_cxx_expression (pp, TREE_OPERAND (e, 1));
783 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
786 pp_c_logical_or_expression (pp_c_base (pp), e);
789 /* Pretty-print a compound assignment operator token as indicated by T. */
792 pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t)
796 switch (TREE_CODE (t))
819 op = tree_code_name[TREE_CODE (t)];
823 pp_cxx_identifier (pp, op);
827 /* assignment-expression:
828 conditional-expression
829 logical-or-expression assignment-operator assignment-expression
833 throw assignment-expression(opt)
835 assignment-operator: one of
836 = *= /= %= += -= >>= <<= &= ^= |= */
839 pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e)
841 switch (TREE_CODE (e))
845 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
849 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 1));
853 pp_cxx_identifier (pp, "throw");
854 if (TREE_OPERAND (e, 0))
855 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 0));
859 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
860 pp_cxx_assignment_operator (pp, TREE_OPERAND (e, 1));
861 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
865 pp_cxx_conditional_expression (pp, e);
871 pp_cxx_expression (cxx_pretty_printer *pp, tree t)
873 switch (TREE_CODE (t))
878 pp_cxx_constant (pp, t);
882 pp_cxx_unqualified_id (pp, t);
890 pp_cxx_qualified_id (pp, t);
902 case TEMPLATE_TYPE_PARM:
903 case TEMPLATE_PARM_INDEX:
904 case TEMPLATE_TEMPLATE_PARM:
906 pp_cxx_primary_expression (pp, t);
910 case DYNAMIC_CAST_EXPR:
911 case STATIC_CAST_EXPR:
912 case REINTERPRET_CAST_EXPR:
913 case CONST_CAST_EXPR:
917 case EMPTY_CLASS_EXPR:
919 case PSEUDO_DTOR_EXPR:
922 pp_cxx_postfix_expression (pp, t);
927 pp_cxx_new_expression (pp, t);
931 case VEC_DELETE_EXPR:
932 pp_cxx_delete_expression (pp, t);
937 pp_cxx_unary_expression (pp, t);
941 pp_cxx_cast_expression (pp, t);
947 pp_cxx_pm_expression (pp, t);
953 pp_cxx_multiplicative_expression (pp, t);
957 pp_cxx_conditional_expression (pp, t);
964 pp_cxx_assignment_expression (pp, t);
967 case NON_DEPENDENT_EXPR:
968 case MUST_NOT_THROW_EXPR:
969 pp_cxx_expression (pp, t);
973 pp_c_expression (pp_c_base (pp), t);
981 /* function-specifier:
987 pp_cxx_function_specifier (cxx_pretty_printer *pp, tree t)
989 switch (TREE_CODE (t))
992 if (DECL_VIRTUAL_P (t))
993 pp_cxx_identifier (pp, "virtual");
994 else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
995 pp_cxx_identifier (pp, "explicit");
997 pp_c_function_specifier (pp_c_base (pp), t);
1004 /* decl-specifier-seq:
1005 decl-specifier-seq(opt) decl-specifier
1008 storage-class-specifier
1015 pp_cxx_decl_specifier_seq (cxx_pretty_printer *pp, tree t)
1017 switch (TREE_CODE (t))
1023 pp_cxx_storage_class_specifier (pp, t);
1024 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1028 pp_cxx_identifier (pp, "typedef");
1029 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1033 if (TYPE_PTRMEMFUNC_P (t))
1035 tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t);
1036 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (pfm)));
1037 pp_cxx_whitespace (pp);
1038 pp_cxx_ptr_operator (pp, t);
1043 /* Constructors don't have return types. And conversion functions
1044 do not have a type-specifier in their return types. */
1045 if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t))
1046 pp_cxx_function_specifier (pp, t);
1047 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
1048 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (t)));
1051 pp_c_declaration_specifiers (pp_c_base (pp), t);
1056 /* simple-type-specifier:
1057 ::(opt) nested-name-specifier(opt) type-name
1058 ::(opt) nested-name-specifier(opt) template(opt) template-id
1072 pp_cxx_simple_type_specifier (cxx_pretty_printer *pp, tree t)
1074 switch (TREE_CODE (t))
1079 pp_cxx_qualified_id (pp, t);
1082 case TEMPLATE_TYPE_PARM:
1083 case TEMPLATE_TEMPLATE_PARM:
1084 case TEMPLATE_PARM_INDEX:
1085 pp_cxx_unqualified_id (pp, t);
1089 pp_cxx_identifier (pp, "typename");
1090 pp_cxx_nested_name_specifier (pp, TYPE_CONTEXT (t));
1091 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
1095 pp_c_type_specifier (pp_c_base (pp), t);
1100 /* type-specifier-seq:
1101 type-specifier type-specifier-seq(opt)
1104 simple-type-specifier
1107 elaborated-type-specifier
1111 pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
1113 switch (TREE_CODE (t))
1116 case TEMPLATE_TYPE_PARM:
1117 case TEMPLATE_TEMPLATE_PARM:
1119 case BOUND_TEMPLATE_TEMPLATE_PARM:
1120 pp_cxx_cv_qualifier_seq (pp, t);
1121 pp_cxx_simple_type_specifier (pp, t);
1125 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
1126 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1127 pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t));
1131 if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
1132 pp_c_specifier_qualifier_list (pp_c_base (pp), t);
1137 * cv-qualifier-seq(opt)
1139 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1142 pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
1144 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
1146 switch (TREE_CODE (t))
1148 case REFERENCE_TYPE:
1150 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
1151 || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t)))
1152 pp_cxx_ptr_operator (pp, TREE_TYPE (t));
1153 if (TREE_CODE (t) == POINTER_TYPE)
1156 pp_cxx_cv_qualifier_seq (pp, t);
1163 if (TYPE_PTRMEMFUNC_P (t))
1165 pp_cxx_left_paren (pp);
1166 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t));
1171 if (TYPE_PTR_TO_MEMBER_P (t))
1173 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1174 pp_cxx_left_paren (pp);
1175 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t));
1177 pp_cxx_cv_qualifier_seq (pp, t);
1180 /* else fall through. */
1183 pp_unsupported_tree (pp, t);
1189 pp_cxx_implicit_parameter_type (tree mf)
1191 return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf))));
1195 parameter-declaration:
1196 decl-specifier-seq declarator
1197 decl-specifier-seq declarator = assignment-expression
1198 decl-specifier-seq abstract-declarator(opt)
1199 decl-specifier-seq abstract-declarator(opt) assignment-expression */
1202 pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
1204 pp_cxx_decl_specifier_seq (pp, t);
1206 pp_cxx_abstract_declarator (pp, t);
1208 pp_cxx_declarator (pp, t);
1211 /* parameter-declaration-clause:
1212 parameter-declaration-list(opt) ...(opt)
1213 parameter-declaration-list , ...
1215 parameter-declaration-list:
1216 parameter-declaration
1217 parameter-declaration-list , parameter-declaration */
1220 pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
1222 tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t);
1224 TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
1225 const bool abstract = args == NULL
1226 || pp_c_base (pp)->flags & pp_c_flag_abstract;
1229 /* Skip artificial parameter for nonstatic member functions. */
1230 if (TREE_CODE (t) == METHOD_TYPE)
1231 types = TREE_CHAIN (types);
1233 pp_cxx_left_paren (pp);
1234 for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
1237 pp_cxx_separate_with (pp, ',');
1239 pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
1240 if (!abstract && pp_c_base (pp)->flags & pp_cxx_flag_default_argument)
1242 pp_cxx_whitespace (pp);
1244 pp_cxx_whitespace (pp);
1245 pp_cxx_assignment_expression (pp, TREE_PURPOSE (types));
1248 pp_cxx_right_paren (pp);
1251 /* exception-specification:
1252 throw ( type-id-list(opt) )
1256 type-id-list , type-id */
1259 pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
1261 tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
1263 if (!TYPE_NOTHROW_P (t) && ex_spec == NULL)
1265 pp_cxx_identifier (pp, "throw");
1266 pp_cxx_left_paren (pp);
1267 for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
1269 pp_cxx_type_id (pp, TREE_VALUE (ex_spec));
1270 if (TREE_CHAIN (ex_spec))
1271 pp_cxx_separate_with (pp, ',');
1273 pp_cxx_right_paren (pp);
1276 /* direct-declarator:
1278 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
1279 exception-specification(opt)
1280 direct-declaration [ constant-expression(opt) ]
1284 pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t)
1286 switch (TREE_CODE (t))
1294 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1295 pp_cxx_id_expression (pp, DECL_NAME (t));
1297 pp_cxx_abstract_declarator (pp, TREE_TYPE (t));
1301 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
1302 pp_cxx_id_expression (pp, t);
1303 pp_cxx_parameter_declaration_clause (pp, t);
1305 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
1307 pp_base (pp)->padding = pp_before;
1308 pp_cxx_cv_qualifier_seq (pp, pp_cxx_implicit_parameter_type (t));
1311 pp_cxx_exception_specification (pp, TREE_TYPE (t));
1316 case TEMPLATE_TYPE_PARM:
1317 case TEMPLATE_PARM_INDEX:
1318 case TEMPLATE_TEMPLATE_PARM:
1322 pp_c_direct_declarator (pp_c_base (pp), t);
1329 ptr-operator declarator */
1332 pp_cxx_declarator (cxx_pretty_printer *pp, tree t)
1334 pp_cxx_direct_declarator (pp, t);
1337 /* ctor-initializer:
1338 : mem-initializer-list
1340 mem-initializer-list:
1342 mem-initializer , mem-initializer-list
1345 mem-initializer-id ( expression-list(opt) )
1348 ::(opt) nested-name-specifier(opt) class-name
1352 pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
1354 t = TREE_OPERAND (t, 0);
1355 pp_cxx_whitespace (pp);
1357 pp_cxx_whitespace (pp);
1358 for (; t; t = TREE_CHAIN (t))
1360 pp_cxx_primary_expression (pp, TREE_PURPOSE (t));
1361 pp_cxx_call_argument_list (pp, TREE_VALUE (t));
1363 pp_cxx_separate_with (pp, ',');
1367 /* function-definition:
1368 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1369 decl-specifier-seq(opt) declarator function-try-block */
1372 pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
1374 tree saved_scope = pp->enclosing_scope;
1375 pp_cxx_decl_specifier_seq (pp, t);
1376 pp_cxx_declarator (pp, t);
1377 pp_needs_newline (pp) = true;
1378 pp->enclosing_scope = DECL_CONTEXT (t);
1379 if (DECL_SAVED_TREE (t))
1380 pp_cxx_statement (pp, DECL_SAVED_TREE (t));
1383 pp_cxx_semicolon (pp);
1384 pp_needs_newline (pp) = true;
1387 pp->enclosing_scope = saved_scope;
1390 /* abstract-declarator:
1391 ptr-operator abstract-declarator(opt)
1392 direct-abstract-declarator */
1395 pp_cxx_abstract_declarator (cxx_pretty_printer *pp, tree t)
1397 if (TYPE_PTRMEM_P (t) || TYPE_PTRMEMFUNC_P (t))
1398 pp_cxx_right_paren (pp);
1399 else if (POINTER_TYPE_P (t))
1401 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
1402 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1403 pp_cxx_right_paren (pp);
1406 pp_cxx_direct_abstract_declarator (pp, t);
1409 /* direct-abstract-declarator:
1410 direct-abstract-declarator(opt) ( parameter-declaration-clause )
1411 cv-qualifier-seq(opt) exception-specification(opt)
1412 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1413 ( abstract-declarator ) */
1416 pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
1418 switch (TREE_CODE (t))
1420 case REFERENCE_TYPE:
1421 pp_cxx_abstract_declarator (pp, t);
1425 if (TYPE_PTRMEMFUNC_P (t))
1426 pp_cxx_direct_abstract_declarator (pp, TYPE_PTRMEMFUNC_FN_TYPE (t));
1431 pp_cxx_parameter_declaration_clause (pp, t);
1432 pp_cxx_direct_abstract_declarator (pp, TREE_TYPE (t));
1433 if (TREE_CODE (t) == METHOD_TYPE)
1435 pp_base (pp)->padding = pp_before;
1436 pp_cxx_cv_qualifier_seq
1437 (pp, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))));
1439 pp_cxx_exception_specification (pp, t);
1443 case TEMPLATE_TYPE_PARM:
1444 case TEMPLATE_TEMPLATE_PARM:
1445 case BOUND_TEMPLATE_TEMPLATE_PARM:
1446 case UNBOUND_CLASS_TEMPLATE:
1450 pp_c_direct_abstract_declarator (pp_c_base (pp), t);
1456 type-specifier-seq abstract-declarator(opt) */
1459 pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
1461 pp_flags saved_flags = pp_c_base (pp)->flags;
1462 pp_c_base (pp)->flags |= pp_c_flag_abstract;
1464 switch (TREE_CODE (t))
1471 case BOUND_TEMPLATE_TEMPLATE_PARM:
1472 case UNBOUND_CLASS_TEMPLATE:
1473 case TEMPLATE_TEMPLATE_PARM:
1474 case TEMPLATE_TYPE_PARM:
1475 case TEMPLATE_PARM_INDEX:
1478 case TEMPLATE_ID_EXPR:
1479 pp_cxx_type_specifier_seq (pp, t);
1483 pp_c_type_id (pp_c_base (pp), t);
1487 pp_c_base (pp)->flags = saved_flags;
1490 /* template-argument-list:
1492 template-argument-list, template-argument
1495 assignment-expression
1500 pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
1505 for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
1507 tree arg = TREE_VEC_ELT (t, i);
1509 pp_cxx_separate_with (pp, ',');
1510 if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
1511 && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
1512 pp_cxx_type_id (pp, arg);
1514 pp_cxx_expression (pp, arg);
1520 pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
1522 t = DECL_EXPR_DECL (t);
1523 pp_cxx_type_specifier_seq (pp, t);
1525 pp_cxx_abstract_declarator (pp, t);
1527 pp_cxx_declarator (pp, t);
1533 pp_cxx_statement (cxx_pretty_printer *pp, tree t)
1535 switch (TREE_CODE (t))
1537 case CTOR_INITIALIZER:
1538 pp_cxx_ctor_initializer (pp, t);
1542 pp_cxx_identifier (pp, "using");
1543 pp_cxx_identifier (pp, "namespace");
1544 if (DECL_CONTEXT (t))
1545 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
1546 pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t));
1550 pp_cxx_identifier (pp, "using");
1551 pp_cxx_nested_name_specifier (pp, USING_DECL_SCOPE (t));
1552 pp_cxx_unqualified_id (pp, DECL_NAME (t));
1559 try compound-statement handler-seq */
1561 pp_maybe_newline_and_indent (pp, 0);
1562 pp_cxx_identifier (pp, "try");
1563 pp_newline_and_indent (pp, 3);
1564 pp_cxx_statement (pp, TRY_STMTS (t));
1565 pp_newline_and_indent (pp, -3);
1569 pp_cxx_statement (pp, TRY_HANDLERS (t));
1574 handler handler-seq(opt)
1577 catch ( exception-declaration ) compound-statement
1579 exception-declaration:
1580 type-specifier-seq declarator
1581 type-specifier-seq abstract-declarator
1584 pp_cxx_identifier (pp, "catch");
1585 pp_cxx_left_paren (pp);
1586 pp_cxx_exception_declaration (pp, HANDLER_PARMS (t));
1587 pp_cxx_right_paren (pp);
1588 pp_indentation (pp) += 3;
1589 pp_needs_newline (pp) = true;
1590 pp_cxx_statement (pp, HANDLER_BODY (t));
1591 pp_indentation (pp) -= 3;
1592 pp_needs_newline (pp) = true;
1595 /* selection-statement:
1596 if ( expression ) statement
1597 if ( expression ) statement else statement */
1599 pp_cxx_identifier (pp, "if");
1600 pp_cxx_whitespace (pp);
1601 pp_cxx_left_paren (pp);
1602 pp_cxx_expression (pp, IF_COND (t));
1603 pp_cxx_right_paren (pp);
1604 pp_newline_and_indent (pp, 2);
1605 pp_cxx_statement (pp, THEN_CLAUSE (t));
1606 pp_newline_and_indent (pp, -2);
1607 if (ELSE_CLAUSE (t))
1609 tree else_clause = ELSE_CLAUSE (t);
1610 pp_cxx_identifier (pp, "else");
1611 if (TREE_CODE (else_clause) == IF_STMT)
1612 pp_cxx_whitespace (pp);
1614 pp_newline_and_indent (pp, 2);
1615 pp_cxx_statement (pp, else_clause);
1616 if (TREE_CODE (else_clause) != IF_STMT)
1617 pp_newline_and_indent (pp, -2);
1622 pp_cxx_identifier (pp, "switch");
1624 pp_cxx_left_paren (pp);
1625 pp_cxx_expression (pp, SWITCH_STMT_COND (t));
1626 pp_cxx_right_paren (pp);
1627 pp_indentation (pp) += 3;
1628 pp_needs_newline (pp) = true;
1629 pp_cxx_statement (pp, SWITCH_STMT_BODY (t));
1630 pp_newline_and_indent (pp, -3);
1633 /* iteration-statement:
1634 while ( expression ) statement
1635 do statement while ( expression ) ;
1636 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1637 for ( declaration expression(opt) ; expression(opt) ) statement */
1639 pp_cxx_identifier (pp, "while");
1641 pp_cxx_left_paren (pp);
1642 pp_cxx_expression (pp, WHILE_COND (t));
1643 pp_cxx_right_paren (pp);
1644 pp_newline_and_indent (pp, 3);
1645 pp_cxx_statement (pp, WHILE_BODY (t));
1646 pp_indentation (pp) -= 3;
1647 pp_needs_newline (pp) = true;
1651 pp_cxx_identifier (pp, "do");
1652 pp_newline_and_indent (pp, 3);
1653 pp_cxx_statement (pp, DO_BODY (t));
1654 pp_newline_and_indent (pp, -3);
1655 pp_cxx_identifier (pp, "while");
1657 pp_cxx_left_paren (pp);
1658 pp_cxx_expression (pp, DO_COND (t));
1659 pp_cxx_right_paren (pp);
1660 pp_cxx_semicolon (pp);
1661 pp_needs_newline (pp) = true;
1665 pp_cxx_identifier (pp, "for");
1667 pp_cxx_left_paren (pp);
1668 if (FOR_INIT_STMT (t))
1669 pp_cxx_statement (pp, FOR_INIT_STMT (t));
1671 pp_cxx_semicolon (pp);
1672 pp_needs_newline (pp) = false;
1673 pp_cxx_whitespace (pp);
1675 pp_cxx_expression (pp, FOR_COND (t));
1676 pp_cxx_semicolon (pp);
1677 pp_needs_newline (pp) = false;
1678 pp_cxx_whitespace (pp);
1680 pp_cxx_expression (pp, FOR_EXPR (t));
1681 pp_cxx_right_paren (pp);
1682 pp_newline_and_indent (pp, 3);
1683 pp_cxx_statement (pp, FOR_BODY (t));
1684 pp_indentation (pp) -= 3;
1685 pp_needs_newline (pp) = true;
1691 return expression(opt) ; */
1694 pp_identifier (pp, TREE_CODE (t) == BREAK_STMT ? "break" : "continue");
1695 pp_cxx_semicolon (pp);
1696 pp_needs_newline (pp) = true;
1699 /* expression-statement:
1700 expression(opt) ; */
1702 pp_cxx_expression (pp, EXPR_STMT_EXPR (t));
1703 pp_cxx_semicolon (pp);
1704 pp_needs_newline (pp) = true;
1708 pp_cxx_identifier (pp, "try");
1709 pp_newline_and_indent (pp, 2);
1710 pp_cxx_statement (pp, CLEANUP_BODY (t));
1711 pp_newline_and_indent (pp, -2);
1712 pp_cxx_identifier (pp, CLEANUP_EH_ONLY (t) ? "catch" : "finally");
1713 pp_newline_and_indent (pp, 2);
1714 pp_cxx_statement (pp, CLEANUP_EXPR (t));
1715 pp_newline_and_indent (pp, -2);
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
1915 pp_cxx_declaration (cxx_pretty_printer *pp, tree t)
1917 if (!DECL_LANG_SPECIFIC (t))
1918 pp_cxx_simple_declaration (pp, t);
1919 else if (DECL_USE_TEMPLATE (t))
1920 switch (DECL_USE_TEMPLATE (t))
1923 pp_cxx_template_declaration (pp, t);
1927 pp_cxx_explicit_specialization (pp, t);
1931 pp_cxx_explicit_instantiation (pp, t);
1937 else switch (TREE_CODE (t))
1941 pp_cxx_simple_declaration (pp, t);
1945 if (DECL_SAVED_TREE (t))
1946 pp_cxx_function_definition (pp, t);
1948 pp_cxx_simple_declaration (pp, t);
1951 case NAMESPACE_DECL:
1952 if (DECL_NAMESPACE_ALIAS (t))
1953 pp_cxx_namespace_alias_definition (pp, t);
1955 pp_cxx_original_namespace_definition (pp, t);
1959 pp_unsupported_tree (pp, t);
1965 typedef c_pretty_print_fn pp_fun;
1967 /* Initialization of a C++ pretty-printer object. */
1970 pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
1972 pp_c_pretty_printer_init (pp_c_base (pp));
1973 pp_set_line_maximum_length (pp, 0);
1975 pp->c_base.declaration = (pp_fun) pp_cxx_declaration;
1976 pp->c_base.declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
1977 pp->c_base.function_specifier = (pp_fun) pp_cxx_function_specifier;
1978 pp->c_base.type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
1979 pp->c_base.declarator = (pp_fun) pp_cxx_declarator;
1980 pp->c_base.direct_declarator = (pp_fun) pp_cxx_direct_declarator;
1981 pp->c_base.parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
1982 pp->c_base.type_id = (pp_fun) pp_cxx_type_id;
1983 pp->c_base.abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
1984 pp->c_base.direct_abstract_declarator =
1985 (pp_fun) pp_cxx_direct_abstract_declarator;
1986 pp->c_base.simple_type_specifier = (pp_fun)pp_cxx_simple_type_specifier;
1988 /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
1990 pp->c_base.constant = (pp_fun) pp_cxx_constant;
1991 pp->c_base.id_expression = (pp_fun) pp_cxx_id_expression;
1992 pp->c_base.primary_expression = (pp_fun) pp_cxx_primary_expression;
1993 pp->c_base.postfix_expression = (pp_fun) pp_cxx_postfix_expression;
1994 pp->c_base.unary_expression = (pp_fun) pp_cxx_unary_expression;
1995 pp->c_base.multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
1996 pp->c_base.conditional_expression = (pp_fun) pp_cxx_conditional_expression;
1997 pp->c_base.assignment_expression = (pp_fun) pp_cxx_assignment_expression;
1998 pp->c_base.expression = (pp_fun) pp_cxx_expression;
1999 pp->enclosing_scope = global_namespace;