]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/cxx-pretty-print.c
Implement noexcept operator (5.3.7)
[thirdparty/gcc.git] / gcc / cp / cxx-pretty-print.c
CommitLineData
e1a4dd13 1/* Implementation of subroutines for the GNU C++ pretty-printer.
b02cec6e 2 Copyright (C) 2003, 2004, 2005, 2007, 2008,
cf835838 3 2009, 2010 Free Software Foundation, Inc.
e1a4dd13
GDR
4 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
e77f031d 10Software Foundation; either version 3, or (at your option) any later
e1a4dd13
GDR
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
e77f031d
NC
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
e1a4dd13
GDR
21
22#include "config.h"
23#include "system.h"
24#include "coretypes.h"
25#include "tm.h"
b02cec6e 26#include "intl.h"
e1a4dd13 27#include "cp-tree.h"
40013784 28#include "cxx-pretty-print.h"
5d127eeb 29#include "tree-pretty-print.h"
12ea3302 30#include "toplev.h"
4b780675 31
f41c4af3
JM
32/* Translate if being used for diagnostics, but not for dump files or
33 __PRETTY_FUNCTION. */
34#define M_(msgid) (pp_translate_identifiers (pp) ? _(msgid) : (msgid))
35
4b780675 36static void pp_cxx_unqualified_id (cxx_pretty_printer *, tree);
12ea3302 37static void pp_cxx_nested_name_specifier (cxx_pretty_printer *, tree);
4b780675
GDR
38static void pp_cxx_qualified_id (cxx_pretty_printer *, tree);
39static void pp_cxx_assignment_expression (cxx_pretty_printer *, tree);
12ea3302 40static void pp_cxx_expression (cxx_pretty_printer *, tree);
4b780675 41static void pp_cxx_template_argument_list (cxx_pretty_printer *, tree);
12ea3302
GDR
42static void pp_cxx_type_specifier_seq (cxx_pretty_printer *, tree);
43static void pp_cxx_ptr_operator (cxx_pretty_printer *, tree);
44static void pp_cxx_type_id (cxx_pretty_printer *, tree);
45static void pp_cxx_direct_abstract_declarator (cxx_pretty_printer *, tree);
46static void pp_cxx_declarator (cxx_pretty_printer *, tree);
7090f4b3 47static void pp_cxx_parameter_declaration_clause (cxx_pretty_printer *, tree);
12ea3302 48static void pp_cxx_abstract_declarator (cxx_pretty_printer *, tree);
b01150a2 49static void pp_cxx_statement (cxx_pretty_printer *, tree);
12ea3302 50static void pp_cxx_template_parameter (cxx_pretty_printer *, tree);
392e3d51 51static void pp_cxx_cast_expression (cxx_pretty_printer *, tree);
066f956c 52static void pp_cxx_typeid_expression (cxx_pretty_printer *, tree);
e1a4dd13 53\f
4b780675
GDR
54
55static inline void
56pp_cxx_nonconsecutive_character (cxx_pretty_printer *pp, int c)
57{
58 const char *p = pp_last_position_in_text (pp);
59
60 if (p != NULL && *p == c)
12ea3302 61 pp_cxx_whitespace (pp);
4b780675 62 pp_character (pp, c);
12ea3302 63 pp_base (pp)->padding = pp_none;
4b780675
GDR
64}
65
12ea3302
GDR
66#define pp_cxx_storage_class_specifier(PP, T) \
67 pp_c_storage_class_specifier (pp_c_base (PP), T)
68#define pp_cxx_expression_list(PP, T) \
69 pp_c_expression_list (pp_c_base (PP), T)
70#define pp_cxx_space_for_pointer_operator(PP, T) \
71 pp_c_space_for_pointer_operator (pp_c_base (PP), T)
72#define pp_cxx_init_declarator(PP, T) \
73 pp_c_init_declarator (pp_c_base (PP), T)
74#define pp_cxx_call_argument_list(PP, T) \
75 pp_c_call_argument_list (pp_c_base (PP), T)
e1a4dd13 76
41fd3bac 77void
12ea3302 78pp_cxx_colon_colon (cxx_pretty_printer *pp)
e1a4dd13 79{
12ea3302
GDR
80 pp_colon_colon (pp);
81 pp_base (pp)->padding = pp_none;
e1a4dd13
GDR
82}
83
41fd3bac
GDR
84void
85pp_cxx_begin_template_argument_list (cxx_pretty_printer *pp)
86{
87 pp_cxx_nonconsecutive_character (pp, '<');
88}
89
90void
91pp_cxx_end_template_argument_list (cxx_pretty_printer *pp)
92{
93 pp_cxx_nonconsecutive_character (pp, '>');
94}
95
96void
97pp_cxx_separate_with (cxx_pretty_printer *pp, int c)
98{
99 pp_separate_with (pp, c);
100 pp_base (pp)->padding = pp_none;
101}
e1a4dd13 102
04c06002 103/* Expressions. */
e1a4dd13 104
12ea3302
GDR
105static inline bool
106is_destructor_name (tree name)
e1a4dd13 107{
12ea3302
GDR
108 return name == complete_dtor_identifier
109 || name == base_dtor_identifier
110 || name == deleting_dtor_identifier;
e1a4dd13
GDR
111}
112
12ea3302
GDR
113/* conversion-function-id:
114 operator conversion-type-id
4b780675 115
12ea3302
GDR
116 conversion-type-id:
117 type-specifier-seq conversion-declarator(opt)
4b780675 118
12ea3302
GDR
119 conversion-declarator:
120 ptr-operator conversion-declarator(opt) */
b9b44fb9 121
12ea3302
GDR
122static inline void
123pp_cxx_conversion_function_id (cxx_pretty_printer *pp, tree t)
4b780675 124{
b02cec6e 125 pp_cxx_ws_string (pp, "operator");
12ea3302 126 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
4b780675
GDR
127}
128
12ea3302
GDR
129static inline void
130pp_cxx_template_id (cxx_pretty_printer *pp, tree t)
e1a4dd13 131{
12ea3302
GDR
132 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
133 pp_cxx_begin_template_argument_list (pp);
134 pp_cxx_template_argument_list (pp, TREE_OPERAND (t, 1));
135 pp_cxx_end_template_argument_list (pp);
e1a4dd13
GDR
136}
137
5a023baa
GDR
138/* Prints the unqualified part of the id-expression T.
139
140 unqualified-id:
4b780675
GDR
141 identifier
142 operator-function-id
143 conversion-function-id
144 ~ class-name
145 template-id */
b9b44fb9 146
4b780675
GDR
147static void
148pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t)
149{
150 enum tree_code code = TREE_CODE (t);
151 switch (code)
152 {
12ea3302 153 case RESULT_DECL:
f41c4af3 154 pp_cxx_ws_string (pp, M_("<return-value>"));
12ea3302
GDR
155 break;
156
157 case OVERLOAD:
c8094d83 158 t = OVL_CURRENT (t);
4b780675
GDR
159 case VAR_DECL:
160 case PARM_DECL:
161 case CONST_DECL:
162 case TYPE_DECL:
163 case FUNCTION_DECL:
164 case NAMESPACE_DECL:
165 case FIELD_DECL:
166 case LABEL_DECL:
167 case USING_DECL:
12ea3302 168 case TEMPLATE_DECL:
4b780675 169 t = DECL_NAME (t);
c8094d83 170
4b780675 171 case IDENTIFIER_NODE:
12ea3302 172 if (t == NULL)
f41c4af3 173 pp_cxx_ws_string (pp, M_("<unnamed>"));
12ea3302 174 else if (IDENTIFIER_TYPENAME_P (t))
0cbd7506 175 pp_cxx_conversion_function_id (pp, t);
4b780675 176 else
0cbd7506
MS
177 {
178 if (is_destructor_name (t))
179 {
180 pp_complement (pp);
181 /* FIXME: Why is this necessary? */
182 if (TREE_TYPE (t))
183 t = constructor_name (TREE_TYPE (t));
184 }
185 pp_cxx_tree_identifier (pp, t);
186 }
4b780675
GDR
187 break;
188
189 case TEMPLATE_ID_EXPR:
12ea3302
GDR
190 pp_cxx_template_id (pp, t);
191 break;
192
3601f003
KL
193 case BASELINK:
194 pp_cxx_unqualified_id (pp, BASELINK_FUNCTIONS (t));
195 break;
196
12ea3302
GDR
197 case RECORD_TYPE:
198 case UNION_TYPE:
199 case ENUMERAL_TYPE:
c8c00613
PC
200 case TYPENAME_TYPE:
201 case UNBOUND_CLASS_TEMPLATE:
12ea3302 202 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
e1faa105
JM
203 if (CLASS_TYPE_P (t) && CLASSTYPE_USE_TEMPLATE (t))
204 {
205 pp_cxx_begin_template_argument_list (pp);
38a15b40
DS
206 pp_cxx_template_argument_list (pp, INNERMOST_TEMPLATE_ARGS
207 (CLASSTYPE_TI_ARGS (t)));
e1faa105
JM
208 pp_cxx_end_template_argument_list (pp);
209 }
12ea3302
GDR
210 break;
211
6735e374
PC
212 case BIT_NOT_EXPR:
213 pp_cxx_complement (pp);
214 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
215 break;
216
12ea3302 217 case TEMPLATE_TYPE_PARM:
41fd3bac
GDR
218 case TEMPLATE_TEMPLATE_PARM:
219 if (TYPE_IDENTIFIER (t))
0cbd7506 220 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
41fd3bac 221 else
0cbd7506 222 pp_cxx_canonical_template_parameter (pp, t);
41fd3bac
GDR
223 break;
224
12ea3302
GDR
225 case TEMPLATE_PARM_INDEX:
226 pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t));
4b780675
GDR
227 break;
228
c8c00613
PC
229 case BOUND_TEMPLATE_TEMPLATE_PARM:
230 pp_cxx_cv_qualifier_seq (pp, t);
231 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
232 pp_cxx_begin_template_argument_list (pp);
233 pp_cxx_template_argument_list (pp, TYPE_TI_ARGS (t));
234 pp_cxx_end_template_argument_list (pp);
5a023baa
GDR
235 break;
236
4b780675
GDR
237 default:
238 pp_unsupported_tree (pp, t);
12ea3302
GDR
239 break;
240 }
241}
242
b9b44fb9
GDR
243/* Pretty-print out the token sequence ":: template" in template codes
244 where it is needed to "inline declare" the (following) member as
666c27b9 245 a template. This situation arises when SCOPE of T is dependent
b9b44fb9
GDR
246 on template parameters. */
247
12ea3302
GDR
248static inline void
249pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
250{
251 if (TREE_CODE (t) == TEMPLATE_ID_EXPR
252 && TYPE_P (scope) && dependent_type_p (scope))
b02cec6e 253 pp_cxx_ws_string (pp, "template");
12ea3302
GDR
254}
255
256/* nested-name-specifier:
257 class-or-namespace-name :: nested-name-specifier(opt)
258 class-or-namespace-name :: template nested-name-specifier */
b9b44fb9 259
12ea3302
GDR
260static void
261pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
262{
263 if (t != NULL && t != pp->enclosing_scope)
264 {
265 tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
266 pp_cxx_nested_name_specifier (pp, scope);
267 pp_cxx_template_keyword_if_needed (pp, scope, t);
268 pp_cxx_unqualified_id (pp, t);
269 pp_cxx_colon_colon (pp);
4b780675
GDR
270 }
271}
272
273/* qualified-id:
274 nested-name-specifier template(opt) unqualified-id */
b9b44fb9 275
4b780675
GDR
276static void
277pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t)
278{
279 switch (TREE_CODE (t))
280 {
b9b44fb9 281 /* A pointer-to-member is always qualified. */
4b780675 282 case PTRMEM_CST:
12ea3302 283 pp_cxx_nested_name_specifier (pp, PTRMEM_CST_CLASS (t));
4b780675
GDR
284 pp_cxx_unqualified_id (pp, PTRMEM_CST_MEMBER (t));
285 break;
286
b9b44fb9 287 /* In Standard C++, functions cannot possibly be used as
0cbd7506
MS
288 nested-name-specifiers. However, there are situations where
289 is "makes sense" to output the surrounding function name for the
290 purpose of emphasizing on the scope kind. Just printing the
291 function name might not be sufficient as it may be overloaded; so,
292 we decorate the function with its signature too.
293 FIXME: This is probably the wrong pretty-printing for conversion
294 functions and some function templates. */
12ea3302
GDR
295 case OVERLOAD:
296 t = OVL_CURRENT (t);
297 case FUNCTION_DECL:
298 if (DECL_FUNCTION_MEMBER_P (t))
0cbd7506 299 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
12ea3302 300 pp_cxx_unqualified_id
0cbd7506 301 (pp, DECL_CONSTRUCTOR_P (t) ? DECL_CONTEXT (t) : t);
b9b44fb9 302 pp_cxx_parameter_declaration_clause (pp, TREE_TYPE (t));
12ea3302
GDR
303 break;
304
4b780675
GDR
305 case OFFSET_REF:
306 case SCOPE_REF:
12ea3302 307 pp_cxx_nested_name_specifier (pp, TREE_OPERAND (t, 0));
4b780675
GDR
308 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 1));
309 break;
310
311 default:
312 {
0cbd7506
MS
313 tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
314 if (scope != pp->enclosing_scope)
315 {
316 pp_cxx_nested_name_specifier (pp, scope);
317 pp_cxx_template_keyword_if_needed (pp, scope, t);
318 }
319 pp_cxx_unqualified_id (pp, t);
4b780675
GDR
320 }
321 break;
322 }
323}
324
a176426f
GDR
325
326static void
327pp_cxx_constant (cxx_pretty_printer *pp, tree t)
328{
329 switch (TREE_CODE (t))
330 {
331 case STRING_CST:
332 {
3db45ab5
MS
333 const bool in_parens = PAREN_STRING_LITERAL_P (t);
334 if (in_parens)
335 pp_cxx_left_paren (pp);
336 pp_c_constant (pp_c_base (pp), t);
337 if (in_parens)
338 pp_cxx_right_paren (pp);
a176426f
GDR
339 }
340 break;
341
14c2101d 342 case INTEGER_CST:
5116acc6 343 if (NULLPTR_TYPE_P (TREE_TYPE (t)))
14c2101d
JM
344 {
345 pp_string (pp, "nullptr");
346 break;
347 }
348 /* else fall through. */
349
a176426f
GDR
350 default:
351 pp_c_constant (pp_c_base (pp), t);
352 break;
353 }
354}
355
4b780675 356/* id-expression:
cd0be382 357 unqualified-id
4b780675 358 qualified-id */
b9b44fb9 359
4b780675
GDR
360static inline void
361pp_cxx_id_expression (cxx_pretty_printer *pp, tree t)
362{
12ea3302
GDR
363 if (TREE_CODE (t) == OVERLOAD)
364 t = OVL_CURRENT (t);
d04a575f 365 if (DECL_P (t) && DECL_CONTEXT (t))
4b780675
GDR
366 pp_cxx_qualified_id (pp, t);
367 else
368 pp_cxx_unqualified_id (pp, t);
369}
370
371/* primary-expression:
372 literal
373 this
374 :: identifier
375 :: operator-function-id
376 :: qualifier-id
377 ( expression )
e74392f0
PC
378 id-expression
379
380 GNU Extensions:
fdb8f418 381 __builtin_va_arg ( assignment-expression , type-id )
094a5fe2 382 __builtin_offsetof ( type-id, offsetof-expression )
fdb8f418 383
e74392f0
PC
384 __has_nothrow_assign ( type-id )
385 __has_nothrow_constructor ( type-id )
386 __has_nothrow_copy ( type-id )
387 __has_trivial_assign ( type-id )
388 __has_trivial_constructor ( type-id )
389 __has_trivial_copy ( type-id )
390 __has_trivial_destructor ( type-id )
391 __has_virtual_destructor ( type-id )
392 __is_abstract ( type-id )
393 __is_base_of ( type-id , type-id )
394 __is_class ( type-id )
395 __is_convertible_to ( type-id , type-id )
396 __is_empty ( type-id )
397 __is_enum ( type-id )
398 __is_pod ( type-id )
399 __is_polymorphic ( type-id )
400 __is_union ( type-id ) */
b9b44fb9 401
e1a4dd13
GDR
402static void
403pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
404{
4b780675
GDR
405 switch (TREE_CODE (t))
406 {
4b780675
GDR
407 case INTEGER_CST:
408 case REAL_CST:
7368348c 409 case COMPLEX_CST:
a176426f
GDR
410 case STRING_CST:
411 pp_cxx_constant (pp, t);
4b780675
GDR
412 break;
413
12ea3302
GDR
414 case BASELINK:
415 t = BASELINK_FUNCTIONS (t);
416 case VAR_DECL:
417 case PARM_DECL:
418 case FIELD_DECL:
419 case FUNCTION_DECL:
420 case OVERLOAD:
421 case CONST_DECL:
422 case TEMPLATE_DECL:
423 pp_cxx_id_expression (pp, t);
424 break;
425
426 case RESULT_DECL:
427 case TEMPLATE_TYPE_PARM:
41fd3bac 428 case TEMPLATE_TEMPLATE_PARM:
12ea3302
GDR
429 case TEMPLATE_PARM_INDEX:
430 pp_cxx_unqualified_id (pp, t);
431 break;
432
c3e5898b
ILT
433 case STMT_EXPR:
434 pp_cxx_left_paren (pp);
435 pp_cxx_statement (pp, STMT_EXPR_STMT (t));
436 pp_cxx_right_paren (pp);
437 break;
438
e74392f0
PC
439 case TRAIT_EXPR:
440 pp_cxx_trait_expression (pp, t);
441 break;
442
fdb8f418
PC
443 case VA_ARG_EXPR:
444 pp_cxx_va_arg_expression (pp, t);
445 break;
446
094a5fe2
JJ
447 case OFFSETOF_EXPR:
448 pp_cxx_offsetof_expression (pp, t);
449 break;
450
4b780675 451 default:
12ea3302 452 pp_c_primary_expression (pp_c_base (pp), t);
4b780675
GDR
453 break;
454 }
e1a4dd13
GDR
455}
456
4b780675
GDR
457/* postfix-expression:
458 primary-expression
459 postfix-expression [ expression ]
460 postfix-expression ( expression-list(opt) )
461 simple-type-specifier ( expression-list(opt) )
462 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
463 typename ::(opt) nested-name-specifier template(opt)
0cbd7506 464 template-id ( expression-list(opt) )
4b780675
GDR
465 postfix-expression . template(opt) ::(opt) id-expression
466 postfix-expression -> template(opt) ::(opt) id-expression
467 postfix-expression . pseudo-destructor-name
468 postfix-expression -> pseudo-destructor-name
469 postfix-expression ++
470 postfix-expression --
471 dynamic_cast < type-id > ( expression )
472 static_cast < type-id > ( expression )
473 reinterpret_cast < type-id > ( expression )
474 const_cast < type-id > ( expression )
475 typeid ( expression )
39a13be5 476 typeid ( type-id ) */
4b780675 477
e1a4dd13
GDR
478static void
479pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t)
480{
4b780675 481 enum tree_code code = TREE_CODE (t);
c8094d83 482
4b780675
GDR
483 switch (code)
484 {
12ea3302
GDR
485 case AGGR_INIT_EXPR:
486 case CALL_EXPR:
487 {
5039610b
SL
488 tree fun = (code == AGGR_INIT_EXPR ? AGGR_INIT_EXPR_FN (t)
489 : CALL_EXPR_FN (t));
0cbd7506 490 tree saved_scope = pp->enclosing_scope;
5039610b
SL
491 bool skipfirst = false;
492 tree arg;
0cbd7506
MS
493
494 if (TREE_CODE (fun) == ADDR_EXPR)
495 fun = TREE_OPERAND (fun, 0);
496
497 /* In templates, where there is no way to tell whether a given
498 call uses an actual member function. So the parser builds
499 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
500 instantiation time. */
501 if (TREE_CODE (fun) != FUNCTION_DECL)
502 ;
503 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun))
504 {
5039610b
SL
505 tree object = (code == AGGR_INIT_EXPR
506 ? (AGGR_INIT_VIA_CTOR_P (t)
507 ? AGGR_INIT_EXPR_SLOT (t)
508 : AGGR_INIT_EXPR_ARG (t, 0))
509 : CALL_EXPR_ARG (t, 0));
0cbd7506
MS
510
511 while (TREE_CODE (object) == NOP_EXPR)
512 object = TREE_OPERAND (object, 0);
513
514 if (TREE_CODE (object) == ADDR_EXPR)
515 object = TREE_OPERAND (object, 0);
516
517 if (TREE_CODE (TREE_TYPE (object)) != POINTER_TYPE)
518 {
519 pp_cxx_postfix_expression (pp, object);
520 pp_cxx_dot (pp);
521 }
522 else
523 {
524 pp_cxx_postfix_expression (pp, object);
525 pp_cxx_arrow (pp);
526 }
5039610b 527 skipfirst = true;
0cbd7506
MS
528 pp->enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
529 }
530
531 pp_cxx_postfix_expression (pp, fun);
532 pp->enclosing_scope = saved_scope;
5039610b
SL
533 pp_cxx_left_paren (pp);
534 if (code == AGGR_INIT_EXPR)
535 {
536 aggr_init_expr_arg_iterator iter;
537 FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t)
538 {
539 if (skipfirst)
540 skipfirst = false;
541 else
542 {
543 pp_cxx_expression (pp, arg);
544 if (more_aggr_init_expr_args_p (&iter))
545 pp_cxx_separate_with (pp, ',');
546 }
547 }
548 }
549 else
550 {
551 call_expr_arg_iterator iter;
552 FOR_EACH_CALL_EXPR_ARG (arg, iter, t)
553 {
554 if (skipfirst)
555 skipfirst = false;
556 else
557 {
558 pp_cxx_expression (pp, arg);
559 if (more_call_expr_args_p (&iter))
560 pp_cxx_separate_with (pp, ',');
561 }
562 }
563 }
564 pp_cxx_right_paren (pp);
12ea3302
GDR
565 }
566 if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
0cbd7506
MS
567 {
568 pp_cxx_separate_with (pp, ',');
5039610b 569 pp_cxx_postfix_expression (pp, AGGR_INIT_EXPR_SLOT (t));
0cbd7506 570 }
12ea3302
GDR
571 break;
572
573 case BASELINK:
574 case VAR_DECL:
575 case PARM_DECL:
576 case FIELD_DECL:
577 case FUNCTION_DECL:
578 case OVERLOAD:
579 case CONST_DECL:
580 case TEMPLATE_DECL:
581 case RESULT_DECL:
582 pp_cxx_primary_expression (pp, t);
583 break;
584
4b780675
GDR
585 case DYNAMIC_CAST_EXPR:
586 case STATIC_CAST_EXPR:
587 case REINTERPRET_CAST_EXPR:
588 case CONST_CAST_EXPR:
589 if (code == DYNAMIC_CAST_EXPR)
b02cec6e 590 pp_cxx_ws_string (pp, "dynamic_cast");
4b780675 591 else if (code == STATIC_CAST_EXPR)
b02cec6e 592 pp_cxx_ws_string (pp, "static_cast");
4b780675 593 else if (code == REINTERPRET_CAST_EXPR)
b02cec6e 594 pp_cxx_ws_string (pp, "reinterpret_cast");
4b780675 595 else
b02cec6e 596 pp_cxx_ws_string (pp, "const_cast");
4b780675
GDR
597 pp_cxx_begin_template_argument_list (pp);
598 pp_cxx_type_id (pp, TREE_TYPE (t));
599 pp_cxx_end_template_argument_list (pp);
600 pp_left_paren (pp);
12ea3302 601 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
4b780675
GDR
602 pp_right_paren (pp);
603 break;
604
605 case EMPTY_CLASS_EXPR:
606 pp_cxx_type_id (pp, TREE_TYPE (t));
607 pp_left_paren (pp);
608 pp_right_paren (pp);
609 break;
610
611 case TYPEID_EXPR:
2d65b828 612 pp_cxx_typeid_expression (pp, t);
4b780675
GDR
613 break;
614
615 case PSEUDO_DTOR_EXPR:
616 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
12ea3302 617 pp_cxx_dot (pp);
4b780675 618 pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1));
12ea3302 619 pp_cxx_colon_colon (pp);
4b780675
GDR
620 pp_complement (pp);
621 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2));
622 break;
623
03a08664
ILT
624 case ARROW_EXPR:
625 pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
626 pp_cxx_arrow (pp);
627 break;
628
4b780675
GDR
629 default:
630 pp_c_postfix_expression (pp_c_base (pp), t);
631 break;
632 }
e1a4dd13
GDR
633}
634
4b780675
GDR
635/* new-expression:
636 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
637 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
638
639 new-placement:
640 ( expression-list )
641
642 new-type-id:
643 type-specifier-seq new-declarator(opt)
644
645 new-declarator:
646 ptr-operator new-declarator(opt)
647 direct-new-declarator
648
649 direct-new-declarator
650 [ expression ]
651 direct-new-declarator [ constant-expression ]
652
653 new-initializer:
654 ( expression-list(opt) ) */
b9b44fb9 655
e1a4dd13 656static void
4b780675 657pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
e1a4dd13 658{
4b780675 659 enum tree_code code = TREE_CODE (t);
a84a98ca
PC
660 tree type = TREE_OPERAND (t, 1);
661 tree init = TREE_OPERAND (t, 2);
4b780675
GDR
662 switch (code)
663 {
664 case NEW_EXPR:
665 case VEC_NEW_EXPR:
666 if (NEW_EXPR_USE_GLOBAL (t))
0cbd7506 667 pp_cxx_colon_colon (pp);
b02cec6e 668 pp_cxx_ws_string (pp, "new");
4b780675 669 if (TREE_OPERAND (t, 0))
0cbd7506
MS
670 {
671 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
672 pp_space (pp);
673 }
a84a98ca
PC
674 if (TREE_CODE (type) == ARRAY_REF)
675 type = build_cplus_array_type
676 (TREE_OPERAND (type, 0),
db3927fb
AH
677 build_index_type (fold_build2_loc (input_location,
678 MINUS_EXPR, integer_type_node,
a84a98ca
PC
679 TREE_OPERAND (type, 1),
680 integer_one_node)));
681 pp_cxx_type_id (pp, type);
682 if (init)
0cbd7506
MS
683 {
684 pp_left_paren (pp);
a84a98ca
PC
685 if (TREE_CODE (init) == TREE_LIST)
686 pp_c_expression_list (pp_c_base (pp), init);
687 else if (init == void_zero_node)
0cbd7506
MS
688 ; /* OK, empty initializer list. */
689 else
a84a98ca 690 pp_cxx_expression (pp, init);
0cbd7506
MS
691 pp_right_paren (pp);
692 }
4b780675
GDR
693 break;
694
695 default:
696 pp_unsupported_tree (pp, t);
697 }
e1a4dd13
GDR
698}
699
4b780675
GDR
700/* delete-expression:
701 ::(opt) delete cast-expression
702 ::(opt) delete [ ] cast-expression */
b9b44fb9 703
066f956c 704static void
4b780675 705pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
e1a4dd13 706{
4b780675
GDR
707 enum tree_code code = TREE_CODE (t);
708 switch (code)
709 {
710 case DELETE_EXPR:
711 case VEC_DELETE_EXPR:
712 if (DELETE_EXPR_USE_GLOBAL (t))
0cbd7506 713 pp_cxx_colon_colon (pp);
b02cec6e 714 pp_cxx_ws_string (pp, "delete");
62081704
PC
715 pp_space (pp);
716 if (code == VEC_DELETE_EXPR
717 || DELETE_EXPR_USE_VEC (t))
0cbd7506
MS
718 {
719 pp_left_bracket (pp);
720 pp_right_bracket (pp);
62081704 721 pp_space (pp);
0cbd7506 722 }
4b780675 723 pp_c_cast_expression (pp_c_base (pp), TREE_OPERAND (t, 0));
c8094d83
MS
724 break;
725
4b780675
GDR
726 default:
727 pp_unsupported_tree (pp, t);
728 }
e1a4dd13
GDR
729}
730
4b780675
GDR
731/* unary-expression:
732 postfix-expression
733 ++ cast-expression
734 -- cast-expression
735 unary-operator cast-expression
736 sizeof unary-expression
737 sizeof ( type-id )
5d80a306 738 sizeof ... ( identifier )
4b780675
GDR
739 new-expression
740 delete-expression
741
742 unary-operator: one of
743 * & + - !
744
745 GNU extensions:
746 __alignof__ unary-expression
747 __alignof__ ( type-id ) */
b9b44fb9 748
e1a4dd13 749static void
4b780675 750pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
e1a4dd13 751{
4b780675
GDR
752 enum tree_code code = TREE_CODE (t);
753 switch (code)
754 {
755 case NEW_EXPR:
756 case VEC_NEW_EXPR:
757 pp_cxx_new_expression (pp, t);
758 break;
759
760 case DELETE_EXPR:
761 case VEC_DELETE_EXPR:
762 pp_cxx_delete_expression (pp, t);
763 break;
c8094d83 764
03a08664 765 case SIZEOF_EXPR:
5d80a306
DG
766 if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
767 {
b02cec6e
JM
768 pp_cxx_ws_string (pp, "sizeof");
769 pp_cxx_ws_string (pp, "...");
5d80a306
DG
770 pp_cxx_whitespace (pp);
771 pp_cxx_left_paren (pp);
772 if (TYPE_P (TREE_OPERAND (t, 0)))
773 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
774 else
775 pp_unary_expression (pp, TREE_OPERAND (t, 0));
776 pp_cxx_right_paren (pp);
777 break;
778 }
779 /* Fall through */
780
03a08664 781 case ALIGNOF_EXPR:
b02cec6e 782 pp_cxx_ws_string (pp, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
03a08664
ILT
783 pp_cxx_whitespace (pp);
784 if (TYPE_P (TREE_OPERAND (t, 0)))
785 {
786 pp_cxx_left_paren (pp);
787 pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
788 pp_cxx_right_paren (pp);
789 }
790 else
791 pp_unary_expression (pp, TREE_OPERAND (t, 0));
792 break;
793
392e3d51
RS
794 case UNARY_PLUS_EXPR:
795 pp_plus (pp);
796 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0));
797 break;
798
4b780675
GDR
799 default:
800 pp_c_unary_expression (pp_c_base (pp), t);
801 break;
802 }
e1a4dd13
GDR
803}
804
12ea3302
GDR
805/* cast-expression:
806 unary-expression
807 ( type-id ) cast-expression */
b9b44fb9 808
12ea3302
GDR
809static void
810pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
811{
812 switch (TREE_CODE (t))
813 {
814 case CAST_EXPR:
815 pp_cxx_type_id (pp, TREE_TYPE (t));
816 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
817 break;
818
819 default:
820 pp_c_cast_expression (pp_c_base (pp), t);
821 break;
822 }
823}
824
4b780675
GDR
825/* pm-expression:
826 cast-expression
827 pm-expression .* cast-expression
828 pm-expression ->* cast-expression */
b9b44fb9 829
e1a4dd13 830static void
4b780675 831pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t)
e1a4dd13 832{
4b780675
GDR
833 switch (TREE_CODE (t))
834 {
39a13be5 835 /* Handle unfortunate OFFSET_REF overloading here. */
4b780675
GDR
836 case OFFSET_REF:
837 if (TYPE_P (TREE_OPERAND (t, 0)))
0cbd7506
MS
838 {
839 pp_cxx_qualified_id (pp, t);
840 break;
841 }
f4f206f4 842 /* Else fall through. */
4b780675
GDR
843 case MEMBER_REF:
844 case DOTSTAR_EXPR:
845 pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
1e3eacc7
JJ
846 if (TREE_CODE (t) == MEMBER_REF)
847 pp_cxx_arrow (pp);
848 else
849 pp_cxx_dot (pp);
4b780675 850 pp_star(pp);
12ea3302 851 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1));
4b780675
GDR
852 break;
853
854
855 default:
12ea3302 856 pp_cxx_cast_expression (pp, t);
4b780675
GDR
857 break;
858 }
e1a4dd13
GDR
859}
860
4b780675
GDR
861/* multiplicative-expression:
862 pm-expression
863 multiplicative-expression * pm-expression
864 multiplicative-expression / pm-expression
865 multiplicative-expression % pm-expression */
b9b44fb9 866
e1a4dd13 867static void
4b780675 868pp_cxx_multiplicative_expression (cxx_pretty_printer *pp, tree e)
e1a4dd13 869{
4b780675
GDR
870 enum tree_code code = TREE_CODE (e);
871 switch (code)
872 {
873 case MULT_EXPR:
874 case TRUNC_DIV_EXPR:
875 case TRUNC_MOD_EXPR:
876 pp_cxx_multiplicative_expression (pp, TREE_OPERAND (e, 0));
877 pp_space (pp);
878 if (code == MULT_EXPR)
879 pp_star (pp);
880 else if (code == TRUNC_DIV_EXPR)
881 pp_slash (pp);
882 else
883 pp_modulo (pp);
884 pp_space (pp);
885 pp_cxx_pm_expression (pp, TREE_OPERAND (e, 1));
886 break;
887
888 default:
889 pp_cxx_pm_expression (pp, e);
890 break;
891 }
e1a4dd13
GDR
892}
893
4b780675
GDR
894/* conditional-expression:
895 logical-or-expression
896 logical-or-expression ? expression : assignment-expression */
b9b44fb9 897
4b780675
GDR
898static void
899pp_cxx_conditional_expression (cxx_pretty_printer *pp, tree e)
e1a4dd13 900{
4b780675
GDR
901 if (TREE_CODE (e) == COND_EXPR)
902 {
903 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
904 pp_space (pp);
905 pp_question (pp);
906 pp_space (pp);
12ea3302 907 pp_cxx_expression (pp, TREE_OPERAND (e, 1));
4b780675
GDR
908 pp_space (pp);
909 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
910 }
911 else
912 pp_c_logical_or_expression (pp_c_base (pp), e);
913}
914
b9b44fb9
GDR
915/* Pretty-print a compound assignment operator token as indicated by T. */
916
12ea3302
GDR
917static void
918pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t)
919{
920 const char *op;
921
922 switch (TREE_CODE (t))
923 {
924 case NOP_EXPR:
925 op = "=";
926 break;
927
928 case PLUS_EXPR:
929 op = "+=";
930 break;
931
932 case MINUS_EXPR:
933 op = "-=";
934 break;
935
936 case TRUNC_DIV_EXPR:
937 op = "/=";
938 break;
939
940 case TRUNC_MOD_EXPR:
941 op = "%=";
942 break;
943
944 default:
945 op = tree_code_name[TREE_CODE (t)];
946 break;
947 }
948
b02cec6e 949 pp_cxx_ws_string (pp, op);
12ea3302
GDR
950}
951
952
4b780675
GDR
953/* assignment-expression:
954 conditional-expression
955 logical-or-expression assignment-operator assignment-expression
12ea3302
GDR
956 throw-expression
957
958 throw-expression:
959 throw assignment-expression(opt)
4b780675 960
12ea3302 961 assignment-operator: one of
4b780675 962 = *= /= %= += -= >>= <<= &= ^= |= */
b9b44fb9 963
4b780675
GDR
964static void
965pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e)
966{
12ea3302 967 switch (TREE_CODE (e))
4b780675 968 {
12ea3302
GDR
969 case MODIFY_EXPR:
970 case INIT_EXPR:
4b780675
GDR
971 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
972 pp_space (pp);
973 pp_equal (pp);
974 pp_space (pp);
975 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 1));
12ea3302 976 break;
e1a4dd13 977
12ea3302 978 case THROW_EXPR:
b02cec6e 979 pp_cxx_ws_string (pp, "throw");
12ea3302 980 if (TREE_OPERAND (e, 0))
0cbd7506 981 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 0));
12ea3302 982 break;
e1a4dd13 983
12ea3302
GDR
984 case MODOP_EXPR:
985 pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
986 pp_cxx_assignment_operator (pp, TREE_OPERAND (e, 1));
987 pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
988 break;
e1a4dd13 989
12ea3302
GDR
990 default:
991 pp_cxx_conditional_expression (pp, e);
992 break;
993 }
994}
995
996static void
997pp_cxx_expression (cxx_pretty_printer *pp, tree t)
998{
999 switch (TREE_CODE (t))
1000 {
1001 case STRING_CST:
1002 case INTEGER_CST:
1003 case REAL_CST:
7368348c 1004 case COMPLEX_CST:
a176426f 1005 pp_cxx_constant (pp, t);
12ea3302
GDR
1006 break;
1007
1008 case RESULT_DECL:
1009 pp_cxx_unqualified_id (pp, t);
1010 break;
1011
c8094d83 1012#if 0
12ea3302 1013 case OFFSET_REF:
c8094d83 1014#endif
12ea3302
GDR
1015 case SCOPE_REF:
1016 case PTRMEM_CST:
1017 pp_cxx_qualified_id (pp, t);
1018 break;
1019
1020 case OVERLOAD:
1021 t = OVL_CURRENT (t);
1022 case VAR_DECL:
1023 case PARM_DECL:
1024 case FIELD_DECL:
1025 case CONST_DECL:
1026 case FUNCTION_DECL:
1027 case BASELINK:
1028 case TEMPLATE_DECL:
1029 case TEMPLATE_TYPE_PARM:
1030 case TEMPLATE_PARM_INDEX:
41fd3bac 1031 case TEMPLATE_TEMPLATE_PARM:
c3e5898b 1032 case STMT_EXPR:
12ea3302
GDR
1033 pp_cxx_primary_expression (pp, t);
1034 break;
1035
1036 case CALL_EXPR:
1037 case DYNAMIC_CAST_EXPR:
1038 case STATIC_CAST_EXPR:
1039 case REINTERPRET_CAST_EXPR:
1040 case CONST_CAST_EXPR:
c8094d83 1041#if 0
12ea3302 1042 case MEMBER_REF:
c8094d83 1043#endif
12ea3302
GDR
1044 case EMPTY_CLASS_EXPR:
1045 case TYPEID_EXPR:
1046 case PSEUDO_DTOR_EXPR:
1047 case AGGR_INIT_EXPR:
03a08664 1048 case ARROW_EXPR:
12ea3302
GDR
1049 pp_cxx_postfix_expression (pp, t);
1050 break;
1051
1052 case NEW_EXPR:
1053 case VEC_NEW_EXPR:
1054 pp_cxx_new_expression (pp, t);
1055 break;
1056
1057 case DELETE_EXPR:
1058 case VEC_DELETE_EXPR:
1059 pp_cxx_delete_expression (pp, t);
1060 break;
1061
03a08664
ILT
1062 case SIZEOF_EXPR:
1063 case ALIGNOF_EXPR:
1064 pp_cxx_unary_expression (pp, t);
1065 break;
1066
12ea3302
GDR
1067 case CAST_EXPR:
1068 pp_cxx_cast_expression (pp, t);
1069 break;
1070
1071 case OFFSET_REF:
1072 case MEMBER_REF:
1073 case DOTSTAR_EXPR:
1074 pp_cxx_pm_expression (pp, t);
1075 break;
1076
1077 case MULT_EXPR:
1078 case TRUNC_DIV_EXPR:
1079 case TRUNC_MOD_EXPR:
1080 pp_cxx_multiplicative_expression (pp, t);
1081 break;
1082
1083 case COND_EXPR:
1084 pp_cxx_conditional_expression (pp, t);
1085 break;
1086
1087 case MODIFY_EXPR:
1088 case INIT_EXPR:
1089 case THROW_EXPR:
1090 case MODOP_EXPR:
1091 pp_cxx_assignment_expression (pp, t);
1092 break;
1093
b9b44fb9
GDR
1094 case NON_DEPENDENT_EXPR:
1095 case MUST_NOT_THROW_EXPR:
066f956c 1096 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
b9b44fb9
GDR
1097 break;
1098
5d80a306
DG
1099 case EXPR_PACK_EXPANSION:
1100 pp_cxx_expression (pp, PACK_EXPANSION_PATTERN (t));
b02cec6e 1101 pp_cxx_ws_string (pp, "...");
5d80a306
DG
1102 break;
1103
c7f06e13
PC
1104 case TEMPLATE_ID_EXPR:
1105 pp_cxx_template_id (pp, t);
1106 break;
1107
5d80a306
DG
1108 case NONTYPE_ARGUMENT_PACK:
1109 {
1110 tree args = ARGUMENT_PACK_ARGS (t);
1111 int i, len = TREE_VEC_LENGTH (args);
1112 for (i = 0; i < len; ++i)
1113 {
1114 if (i > 0)
1115 pp_cxx_separate_with (pp, ',');
1116 pp_cxx_expression (pp, TREE_VEC_ELT (args, i));
1117 }
1118 }
1119 break;
1120
12ea3302
GDR
1121 default:
1122 pp_c_expression (pp_c_base (pp), t);
c8094d83 1123 break;
12ea3302
GDR
1124 }
1125}
1126
1127
1128/* Declarations. */
1129
1130/* function-specifier:
1131 inline
1132 virtual
1133 explicit */
b9b44fb9 1134
12ea3302
GDR
1135static void
1136pp_cxx_function_specifier (cxx_pretty_printer *pp, tree t)
1137{
1138 switch (TREE_CODE (t))
1139 {
1140 case FUNCTION_DECL:
1141 if (DECL_VIRTUAL_P (t))
b02cec6e 1142 pp_cxx_ws_string (pp, "virtual");
12ea3302 1143 else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
b02cec6e 1144 pp_cxx_ws_string (pp, "explicit");
12ea3302 1145 else
0cbd7506 1146 pp_c_function_specifier (pp_c_base (pp), t);
12ea3302
GDR
1147
1148 default:
1149 break;
1150 }
1151}
1152
1153/* decl-specifier-seq:
1154 decl-specifier-seq(opt) decl-specifier
1155
1156 decl-specifier:
1157 storage-class-specifier
1158 type-specifier
1159 function-specifier
1160 friend
1161 typedef */
b9b44fb9 1162
12ea3302
GDR
1163static void
1164pp_cxx_decl_specifier_seq (cxx_pretty_printer *pp, tree t)
1165{
1166 switch (TREE_CODE (t))
1167 {
1168 case VAR_DECL:
1169 case PARM_DECL:
1170 case CONST_DECL:
1171 case FIELD_DECL:
1172 pp_cxx_storage_class_specifier (pp, t);
1173 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1174 break;
c8094d83 1175
12ea3302 1176 case TYPE_DECL:
b02cec6e 1177 pp_cxx_ws_string (pp, "typedef");
12ea3302
GDR
1178 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
1179 break;
1180
12ea3302
GDR
1181 case FUNCTION_DECL:
1182 /* Constructors don't have return types. And conversion functions
0cbd7506 1183 do not have a type-specifier in their return types. */
12ea3302 1184 if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t))
0cbd7506 1185 pp_cxx_function_specifier (pp, t);
12ea3302 1186 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
0cbd7506 1187 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (t)));
12ea3302 1188 else
0cbd7506 1189 default:
12ea3302
GDR
1190 pp_c_declaration_specifiers (pp_c_base (pp), t);
1191 break;
1192 }
1193}
1194
1195/* simple-type-specifier:
1196 ::(opt) nested-name-specifier(opt) type-name
1197 ::(opt) nested-name-specifier(opt) template(opt) template-id
1198 char
1199 wchar_t
1200 bool
1201 short
1202 int
1203 long
1204 signed
1205 unsigned
1206 float
1207 double
1208 void */
b9b44fb9 1209
12ea3302
GDR
1210static void
1211pp_cxx_simple_type_specifier (cxx_pretty_printer *pp, tree t)
1212{
1213 switch (TREE_CODE (t))
1214 {
1215 case RECORD_TYPE:
1216 case UNION_TYPE:
1217 case ENUMERAL_TYPE:
1218 pp_cxx_qualified_id (pp, t);
1219 break;
1220
1221 case TEMPLATE_TYPE_PARM:
41fd3bac 1222 case TEMPLATE_TEMPLATE_PARM:
12ea3302
GDR
1223 case TEMPLATE_PARM_INDEX:
1224 pp_cxx_unqualified_id (pp, t);
1225 break;
1226
1227 case TYPENAME_TYPE:
b02cec6e 1228 pp_cxx_ws_string (pp, "typename");
12ea3302
GDR
1229 pp_cxx_nested_name_specifier (pp, TYPE_CONTEXT (t));
1230 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
1231 break;
1232
1233 default:
1234 pp_c_type_specifier (pp_c_base (pp), t);
1235 break;
1236 }
1237}
1238
1239/* type-specifier-seq:
1240 type-specifier type-specifier-seq(opt)
1241
1242 type-specifier:
1243 simple-type-specifier
1244 class-specifier
1245 enum-specifier
1246 elaborated-type-specifier
cd0be382 1247 cv-qualifier */
12ea3302
GDR
1248
1249static void
1250pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
1251{
12ea3302
GDR
1252 switch (TREE_CODE (t))
1253 {
1254 case TEMPLATE_DECL:
1255 case TEMPLATE_TYPE_PARM:
41fd3bac 1256 case TEMPLATE_TEMPLATE_PARM:
12ea3302
GDR
1257 case TYPE_DECL:
1258 case BOUND_TEMPLATE_TEMPLATE_PARM:
41fd3bac 1259 pp_cxx_cv_qualifier_seq (pp, t);
12ea3302
GDR
1260 pp_cxx_simple_type_specifier (pp, t);
1261 break;
1262
1263 case METHOD_TYPE:
1264 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
1265 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
1266 pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t));
1267 break;
1268
3ad6a8e1 1269 case DECLTYPE_TYPE:
b02cec6e 1270 pp_cxx_ws_string (pp, "decltype");
3ad6a8e1
DG
1271 pp_cxx_left_paren (pp);
1272 pp_cxx_expression (pp, DECLTYPE_TYPE_EXPR (t));
1273 pp_cxx_right_paren (pp);
1274 break;
1275
5cb6410a
JM
1276 case RECORD_TYPE:
1277 if (TYPE_PTRMEMFUNC_P (t))
1278 {
1279 tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t);
1280 pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (pfm)));
1281 pp_cxx_whitespace (pp);
1282 pp_cxx_ptr_operator (pp, t);
1283 break;
1284 }
1285 /* else fall through */
1286
12ea3302
GDR
1287 default:
1288 if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
0cbd7506 1289 pp_c_specifier_qualifier_list (pp_c_base (pp), t);
12ea3302
GDR
1290 }
1291}
1292
1293/* ptr-operator:
1294 * cv-qualifier-seq(opt)
1295 &
1296 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
1297
1298static void
1299pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
1300{
1301 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
1302 t = TREE_TYPE (t);
1303 switch (TREE_CODE (t))
1304 {
1305 case REFERENCE_TYPE:
1306 case POINTER_TYPE:
1307 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
0cbd7506
MS
1308 || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t)))
1309 pp_cxx_ptr_operator (pp, TREE_TYPE (t));
12ea3302 1310 if (TREE_CODE (t) == POINTER_TYPE)
0cbd7506
MS
1311 {
1312 pp_star (pp);
1313 pp_cxx_cv_qualifier_seq (pp, t);
1314 }
12ea3302 1315 else
0cbd7506 1316 pp_ampersand (pp);
12ea3302
GDR
1317 break;
1318
1319 case RECORD_TYPE:
1320 if (TYPE_PTRMEMFUNC_P (t))
0cbd7506
MS
1321 {
1322 pp_cxx_left_paren (pp);
1323 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t));
1324 pp_star (pp);
1325 break;
1326 }
12ea3302
GDR
1327 case OFFSET_TYPE:
1328 if (TYPE_PTR_TO_MEMBER_P (t))
0cbd7506
MS
1329 {
1330 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1331 pp_cxx_left_paren (pp);
1332 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t));
1333 pp_star (pp);
1334 pp_cxx_cv_qualifier_seq (pp, t);
1335 break;
1336 }
da1d7781 1337 /* else fall through. */
12ea3302
GDR
1338
1339 default:
1340 pp_unsupported_tree (pp, t);
1341 break;
1342 }
1343}
1344
1345static inline tree
1346pp_cxx_implicit_parameter_type (tree mf)
1347{
1348 return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf))));
1349}
1350
1351/*
1352 parameter-declaration:
1353 decl-specifier-seq declarator
1354 decl-specifier-seq declarator = assignment-expression
1355 decl-specifier-seq abstract-declarator(opt)
1356 decl-specifier-seq abstract-declarator(opt) assignment-expression */
b9b44fb9 1357
12ea3302
GDR
1358static inline void
1359pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
1360{
1361 pp_cxx_decl_specifier_seq (pp, t);
1362 if (TYPE_P (t))
1363 pp_cxx_abstract_declarator (pp, t);
1364 else
1365 pp_cxx_declarator (pp, t);
1366}
1367
1368/* parameter-declaration-clause:
1369 parameter-declaration-list(opt) ...(opt)
1370 parameter-declaration-list , ...
1371
1372 parameter-declaration-list:
1373 parameter-declaration
1374 parameter-declaration-list , parameter-declaration */
b9b44fb9 1375
12ea3302
GDR
1376static void
1377pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
1378{
1379 tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t);
c8094d83 1380 tree types =
6615c446 1381 TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
12ea3302
GDR
1382 const bool abstract = args == NULL
1383 || pp_c_base (pp)->flags & pp_c_flag_abstract;
1384 bool first = true;
1385
1386 /* Skip artificial parameter for nonstatic member functions. */
1387 if (TREE_CODE (t) == METHOD_TYPE)
1388 types = TREE_CHAIN (types);
1389
1390 pp_cxx_left_paren (pp);
1391 for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
1392 {
1393 if (!first)
0cbd7506 1394 pp_cxx_separate_with (pp, ',');
12ea3302
GDR
1395 first = false;
1396 pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
1397 if (!abstract && pp_c_base (pp)->flags & pp_cxx_flag_default_argument)
0cbd7506
MS
1398 {
1399 pp_cxx_whitespace (pp);
1400 pp_equal (pp);
1401 pp_cxx_whitespace (pp);
1402 pp_cxx_assignment_expression (pp, TREE_PURPOSE (types));
1403 }
12ea3302
GDR
1404 }
1405 pp_cxx_right_paren (pp);
1406}
1407
1408/* exception-specification:
1409 throw ( type-id-list(opt) )
1410
1411 type-id-list
1412 type-id
1413 type-id-list , type-id */
b9b44fb9 1414
12ea3302
GDR
1415static void
1416pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
1417{
1418 tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
5d80a306 1419 bool need_comma = false;
12ea3302
GDR
1420
1421 if (!TYPE_NOTHROW_P (t) && ex_spec == NULL)
1422 return;
b02cec6e 1423 pp_cxx_ws_string (pp, "throw");
12ea3302
GDR
1424 pp_cxx_left_paren (pp);
1425 for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
1426 {
5d80a306
DG
1427 tree type = TREE_VALUE (ex_spec);
1428 tree argpack = NULL_TREE;
1429 int i, len = 1;
1430
1431 if (ARGUMENT_PACK_P (type))
1432 {
1433 argpack = ARGUMENT_PACK_ARGS (type);
1434 len = TREE_VEC_LENGTH (argpack);
1435 }
1436
1437 for (i = 0; i < len; ++i)
1438 {
1439 if (argpack)
1440 type = TREE_VEC_ELT (argpack, i);
1441
1442 if (need_comma)
1443 pp_cxx_separate_with (pp, ',');
1444 else
1445 need_comma = true;
1446
1447 pp_cxx_type_id (pp, type);
1448 }
12ea3302
GDR
1449 }
1450 pp_cxx_right_paren (pp);
1451}
1452
1453/* direct-declarator:
1454 declarator-id
1455 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
0cbd7506 1456 exception-specification(opt)
12ea3302
GDR
1457 direct-declaration [ constant-expression(opt) ]
1458 ( declarator ) */
b9b44fb9 1459
12ea3302
GDR
1460static void
1461pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t)
1462{
1463 switch (TREE_CODE (t))
1464 {
1465 case VAR_DECL:
1466 case PARM_DECL:
1467 case CONST_DECL:
1468 case FIELD_DECL:
1469 if (DECL_NAME (t))
0cbd7506
MS
1470 {
1471 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
5d80a306
DG
1472
1473 if ((TREE_CODE (t) == PARM_DECL && FUNCTION_PARAMETER_PACK_P (t))
1474 || template_parameter_pack_p (t))
1475 /* A function parameter pack or non-type template
1476 parameter pack. */
b02cec6e 1477 pp_cxx_ws_string (pp, "...");
5d80a306 1478
0cbd7506
MS
1479 pp_cxx_id_expression (pp, DECL_NAME (t));
1480 }
12ea3302
GDR
1481 pp_cxx_abstract_declarator (pp, TREE_TYPE (t));
1482 break;
c8094d83 1483
12ea3302
GDR
1484 case FUNCTION_DECL:
1485 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
1486 pp_cxx_id_expression (pp, t);
1487 pp_cxx_parameter_declaration_clause (pp, t);
c8094d83 1488
12ea3302 1489 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
0cbd7506
MS
1490 {
1491 pp_base (pp)->padding = pp_before;
1492 pp_cxx_cv_qualifier_seq (pp, pp_cxx_implicit_parameter_type (t));
1493 }
12ea3302
GDR
1494
1495 pp_cxx_exception_specification (pp, TREE_TYPE (t));
1496 break;
1497
1498 case TYPENAME_TYPE:
1499 case TEMPLATE_DECL:
1500 case TEMPLATE_TYPE_PARM:
1501 case TEMPLATE_PARM_INDEX:
41fd3bac 1502 case TEMPLATE_TEMPLATE_PARM:
12ea3302
GDR
1503 break;
1504
1505 default:
1506 pp_c_direct_declarator (pp_c_base (pp), t);
1507 break;
1508 }
1509}
1510
1511/* declarator:
1512 direct-declarator
1513 ptr-operator declarator */
b9b44fb9 1514
12ea3302
GDR
1515static void
1516pp_cxx_declarator (cxx_pretty_printer *pp, tree t)
1517{
1518 pp_cxx_direct_declarator (pp, t);
1519}
1520
1521/* ctor-initializer:
1522 : mem-initializer-list
1523
1524 mem-initializer-list:
1525 mem-initializer
1526 mem-initializer , mem-initializer-list
1527
1528 mem-initializer:
1529 mem-initializer-id ( expression-list(opt) )
1530
1531 mem-initializer-id:
1532 ::(opt) nested-name-specifier(opt) class-name
1533 identifier */
b9b44fb9 1534
12ea3302
GDR
1535static void
1536pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
1537{
1538 t = TREE_OPERAND (t, 0);
1539 pp_cxx_whitespace (pp);
1540 pp_colon (pp);
1541 pp_cxx_whitespace (pp);
1542 for (; t; t = TREE_CHAIN (t))
1543 {
5d80a306
DG
1544 tree purpose = TREE_PURPOSE (t);
1545 bool is_pack = PACK_EXPANSION_P (purpose);
1546
1547 if (is_pack)
1548 pp_cxx_primary_expression (pp, PACK_EXPANSION_PATTERN (purpose));
1549 else
1550 pp_cxx_primary_expression (pp, purpose);
12ea3302 1551 pp_cxx_call_argument_list (pp, TREE_VALUE (t));
5d80a306 1552 if (is_pack)
b02cec6e 1553 pp_cxx_ws_string (pp, "...");
12ea3302 1554 if (TREE_CHAIN (t))
0cbd7506 1555 pp_cxx_separate_with (pp, ',');
12ea3302
GDR
1556 }
1557}
1558
1559/* function-definition:
1560 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
1561 decl-specifier-seq(opt) declarator function-try-block */
1562
b01150a2 1563static void
12ea3302
GDR
1564pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
1565{
1566 tree saved_scope = pp->enclosing_scope;
1567 pp_cxx_decl_specifier_seq (pp, t);
1568 pp_cxx_declarator (pp, t);
1569 pp_needs_newline (pp) = true;
1570 pp->enclosing_scope = DECL_CONTEXT (t);
1571 if (DECL_SAVED_TREE (t))
5882f0f3 1572 pp_cxx_statement (pp, DECL_SAVED_TREE (t));
12ea3302
GDR
1573 else
1574 {
1575 pp_cxx_semicolon (pp);
1576 pp_needs_newline (pp) = true;
1577 }
1578 pp_flush (pp);
1579 pp->enclosing_scope = saved_scope;
1580}
1581
1582/* abstract-declarator:
1583 ptr-operator abstract-declarator(opt)
1584 direct-abstract-declarator */
b9b44fb9 1585
12ea3302
GDR
1586static void
1587pp_cxx_abstract_declarator (cxx_pretty_printer *pp, tree t)
1588{
1589 if (TYPE_PTRMEM_P (t) || TYPE_PTRMEMFUNC_P (t))
1590 pp_cxx_right_paren (pp);
1591 else if (POINTER_TYPE_P (t))
1592 {
1593 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
0cbd7506
MS
1594 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1595 pp_cxx_right_paren (pp);
12ea3302
GDR
1596 t = TREE_TYPE (t);
1597 }
1598 pp_cxx_direct_abstract_declarator (pp, t);
1599}
1600
1601/* direct-abstract-declarator:
1602 direct-abstract-declarator(opt) ( parameter-declaration-clause )
0cbd7506 1603 cv-qualifier-seq(opt) exception-specification(opt)
12ea3302
GDR
1604 direct-abstract-declarator(opt) [ constant-expression(opt) ]
1605 ( abstract-declarator ) */
b9b44fb9 1606
12ea3302
GDR
1607static void
1608pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
1609{
1610 switch (TREE_CODE (t))
1611 {
1612 case REFERENCE_TYPE:
1613 pp_cxx_abstract_declarator (pp, t);
1614 break;
1615
1616 case RECORD_TYPE:
1617 if (TYPE_PTRMEMFUNC_P (t))
0cbd7506 1618 pp_cxx_direct_abstract_declarator (pp, TYPE_PTRMEMFUNC_FN_TYPE (t));
12ea3302
GDR
1619 break;
1620
1621 case METHOD_TYPE:
1622 case FUNCTION_TYPE:
1623 pp_cxx_parameter_declaration_clause (pp, t);
1624 pp_cxx_direct_abstract_declarator (pp, TREE_TYPE (t));
1625 if (TREE_CODE (t) == METHOD_TYPE)
0cbd7506
MS
1626 {
1627 pp_base (pp)->padding = pp_before;
1628 pp_cxx_cv_qualifier_seq
1629 (pp, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))));
1630 }
12ea3302
GDR
1631 pp_cxx_exception_specification (pp, t);
1632 break;
1633
1634 case TYPENAME_TYPE:
1635 case TEMPLATE_TYPE_PARM:
1636 case TEMPLATE_TEMPLATE_PARM:
1637 case BOUND_TEMPLATE_TEMPLATE_PARM:
1638 case UNBOUND_CLASS_TEMPLATE:
1639 break;
1640
1641 default:
1642 pp_c_direct_abstract_declarator (pp_c_base (pp), t);
c8094d83 1643 break;
12ea3302
GDR
1644 }
1645}
1646
1647/* type-id:
1648 type-specifier-seq abstract-declarator(opt) */
b9b44fb9 1649
12ea3302
GDR
1650static void
1651pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
1652{
1653 pp_flags saved_flags = pp_c_base (pp)->flags;
1654 pp_c_base (pp)->flags |= pp_c_flag_abstract;
1655
1656 switch (TREE_CODE (t))
1657 {
1658 case TYPE_DECL:
1659 case UNION_TYPE:
1660 case RECORD_TYPE:
1661 case ENUMERAL_TYPE:
1662 case TYPENAME_TYPE:
1663 case BOUND_TEMPLATE_TEMPLATE_PARM:
1664 case UNBOUND_CLASS_TEMPLATE:
1665 case TEMPLATE_TEMPLATE_PARM:
1666 case TEMPLATE_TYPE_PARM:
1667 case TEMPLATE_PARM_INDEX:
1668 case TEMPLATE_DECL:
1669 case TYPEOF_TYPE:
3ad6a8e1 1670 case DECLTYPE_TYPE:
12ea3302 1671 case TEMPLATE_ID_EXPR:
12ea3302 1672 pp_cxx_type_specifier_seq (pp, t);
12ea3302
GDR
1673 break;
1674
5d80a306
DG
1675 case TYPE_PACK_EXPANSION:
1676 pp_cxx_type_id (pp, PACK_EXPANSION_PATTERN (t));
b02cec6e 1677 pp_cxx_ws_string (pp, "...");
5d80a306
DG
1678 break;
1679
12ea3302
GDR
1680 default:
1681 pp_c_type_id (pp_c_base (pp), t);
1682 break;
1683 }
1684
1685 pp_c_base (pp)->flags = saved_flags;
1686}
1687
1688/* template-argument-list:
5d80a306
DG
1689 template-argument ...(opt)
1690 template-argument-list, template-argument ...(opt)
12ea3302
GDR
1691
1692 template-argument:
1693 assignment-expression
1694 type-id
5d80a306 1695 template-name */
b9b44fb9 1696
12ea3302
GDR
1697static void
1698pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
1699{
1700 int i;
5d80a306
DG
1701 bool need_comma = false;
1702
12ea3302
GDR
1703 if (t == NULL)
1704 return;
1705 for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
1706 {
1707 tree arg = TREE_VEC_ELT (t, i);
5d80a306
DG
1708 tree argpack = NULL_TREE;
1709 int idx, len = 1;
1710
1711 if (ARGUMENT_PACK_P (arg))
1712 {
1713 argpack = ARGUMENT_PACK_ARGS (arg);
1714 len = TREE_VEC_LENGTH (argpack);
1715 }
1716
1717 for (idx = 0; idx < len; idx++)
1718 {
1719 if (argpack)
1720 arg = TREE_VEC_ELT (argpack, idx);
1721
1722 if (need_comma)
1723 pp_cxx_separate_with (pp, ',');
1724 else
1725 need_comma = true;
1726
1727 if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
1728 && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
1729 pp_cxx_type_id (pp, arg);
1730 else
1731 pp_cxx_expression (pp, arg);
1732 }
12ea3302
GDR
1733 }
1734}
1735
1736
1737static void
1738pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
1739{
350fae66 1740 t = DECL_EXPR_DECL (t);
12ea3302
GDR
1741 pp_cxx_type_specifier_seq (pp, t);
1742 if (TYPE_P (t))
1743 pp_cxx_abstract_declarator (pp, t);
1744 else
1745 pp_cxx_declarator (pp, t);
1746}
1747
1748/* Statements. */
1749
b01150a2 1750static void
12ea3302
GDR
1751pp_cxx_statement (cxx_pretty_printer *pp, tree t)
1752{
1753 switch (TREE_CODE (t))
1754 {
5882f0f3
RH
1755 case CTOR_INITIALIZER:
1756 pp_cxx_ctor_initializer (pp, t);
1757 break;
1758
12ea3302 1759 case USING_STMT:
b02cec6e
JM
1760 pp_cxx_ws_string (pp, "using");
1761 pp_cxx_ws_string (pp, "namespace");
91b1ca65
MM
1762 if (DECL_CONTEXT (t))
1763 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
12ea3302
GDR
1764 pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t));
1765 break;
1766
1767 case USING_DECL:
b02cec6e 1768 pp_cxx_ws_string (pp, "using");
98ed9dae 1769 pp_cxx_nested_name_specifier (pp, USING_DECL_SCOPE (t));
12ea3302
GDR
1770 pp_cxx_unqualified_id (pp, DECL_NAME (t));
1771 break;
1772
1773 case EH_SPEC_BLOCK:
1774 break;
1775
1776 /* try-block:
0cbd7506 1777 try compound-statement handler-seq */
12ea3302
GDR
1778 case TRY_BLOCK:
1779 pp_maybe_newline_and_indent (pp, 0);
b02cec6e 1780 pp_cxx_ws_string (pp, "try");
12ea3302
GDR
1781 pp_newline_and_indent (pp, 3);
1782 pp_cxx_statement (pp, TRY_STMTS (t));
1783 pp_newline_and_indent (pp, -3);
1784 if (CLEANUP_P (t))
0cbd7506 1785 ;
12ea3302 1786 else
0cbd7506 1787 pp_cxx_statement (pp, TRY_HANDLERS (t));
12ea3302
GDR
1788 break;
1789
1790 /*
0cbd7506
MS
1791 handler-seq:
1792 handler handler-seq(opt)
12ea3302 1793
0cbd7506
MS
1794 handler:
1795 catch ( exception-declaration ) compound-statement
12ea3302 1796
0cbd7506
MS
1797 exception-declaration:
1798 type-specifier-seq declarator
1799 type-specifier-seq abstract-declarator
1800 ... */
12ea3302 1801 case HANDLER:
b02cec6e 1802 pp_cxx_ws_string (pp, "catch");
12ea3302
GDR
1803 pp_cxx_left_paren (pp);
1804 pp_cxx_exception_declaration (pp, HANDLER_PARMS (t));
1805 pp_cxx_right_paren (pp);
1806 pp_indentation (pp) += 3;
1807 pp_needs_newline (pp) = true;
1808 pp_cxx_statement (pp, HANDLER_BODY (t));
1809 pp_indentation (pp) -= 3;
1810 pp_needs_newline (pp) = true;
1811 break;
1812
5a508662 1813 /* selection-statement:
0cbd7506
MS
1814 if ( expression ) statement
1815 if ( expression ) statement else statement */
5a508662 1816 case IF_STMT:
b02cec6e 1817 pp_cxx_ws_string (pp, "if");
5a508662
RH
1818 pp_cxx_whitespace (pp);
1819 pp_cxx_left_paren (pp);
1820 pp_cxx_expression (pp, IF_COND (t));
1821 pp_cxx_right_paren (pp);
1822 pp_newline_and_indent (pp, 2);
1823 pp_cxx_statement (pp, THEN_CLAUSE (t));
1824 pp_newline_and_indent (pp, -2);
1825 if (ELSE_CLAUSE (t))
1826 {
1827 tree else_clause = ELSE_CLAUSE (t);
b02cec6e 1828 pp_cxx_ws_string (pp, "else");
5a508662
RH
1829 if (TREE_CODE (else_clause) == IF_STMT)
1830 pp_cxx_whitespace (pp);
1831 else
1832 pp_newline_and_indent (pp, 2);
1833 pp_cxx_statement (pp, else_clause);
1834 if (TREE_CODE (else_clause) != IF_STMT)
1835 pp_newline_and_indent (pp, -2);
1836 }
1837 break;
1838
fbc315db 1839 case SWITCH_STMT:
b02cec6e 1840 pp_cxx_ws_string (pp, "switch");
fbc315db
ILT
1841 pp_space (pp);
1842 pp_cxx_left_paren (pp);
934790cc 1843 pp_cxx_expression (pp, SWITCH_STMT_COND (t));
fbc315db
ILT
1844 pp_cxx_right_paren (pp);
1845 pp_indentation (pp) += 3;
1846 pp_needs_newline (pp) = true;
c3e5898b 1847 pp_cxx_statement (pp, SWITCH_STMT_BODY (t));
fbc315db
ILT
1848 pp_newline_and_indent (pp, -3);
1849 break;
1850
1851 /* iteration-statement:
0cbd7506
MS
1852 while ( expression ) statement
1853 do statement while ( expression ) ;
1854 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1855 for ( declaration expression(opt) ; expression(opt) ) statement */
fbc315db 1856 case WHILE_STMT:
b02cec6e 1857 pp_cxx_ws_string (pp, "while");
fbc315db
ILT
1858 pp_space (pp);
1859 pp_cxx_left_paren (pp);
934790cc 1860 pp_cxx_expression (pp, WHILE_COND (t));
fbc315db
ILT
1861 pp_cxx_right_paren (pp);
1862 pp_newline_and_indent (pp, 3);
c3e5898b 1863 pp_cxx_statement (pp, WHILE_BODY (t));
fbc315db
ILT
1864 pp_indentation (pp) -= 3;
1865 pp_needs_newline (pp) = true;
1866 break;
1867
1868 case DO_STMT:
b02cec6e 1869 pp_cxx_ws_string (pp, "do");
fbc315db 1870 pp_newline_and_indent (pp, 3);
c3e5898b 1871 pp_cxx_statement (pp, DO_BODY (t));
fbc315db 1872 pp_newline_and_indent (pp, -3);
b02cec6e 1873 pp_cxx_ws_string (pp, "while");
fbc315db
ILT
1874 pp_space (pp);
1875 pp_cxx_left_paren (pp);
934790cc 1876 pp_cxx_expression (pp, DO_COND (t));
fbc315db
ILT
1877 pp_cxx_right_paren (pp);
1878 pp_cxx_semicolon (pp);
1879 pp_needs_newline (pp) = true;
1880 break;
1881
1882 case FOR_STMT:
b02cec6e 1883 pp_cxx_ws_string (pp, "for");
fbc315db
ILT
1884 pp_space (pp);
1885 pp_cxx_left_paren (pp);
1886 if (FOR_INIT_STMT (t))
0cbd7506 1887 pp_cxx_statement (pp, FOR_INIT_STMT (t));
fbc315db 1888 else
0cbd7506 1889 pp_cxx_semicolon (pp);
fbc315db
ILT
1890 pp_needs_newline (pp) = false;
1891 pp_cxx_whitespace (pp);
1892 if (FOR_COND (t))
934790cc 1893 pp_cxx_expression (pp, FOR_COND (t));
fbc315db
ILT
1894 pp_cxx_semicolon (pp);
1895 pp_needs_newline (pp) = false;
1896 pp_cxx_whitespace (pp);
1897 if (FOR_EXPR (t))
934790cc 1898 pp_cxx_expression (pp, FOR_EXPR (t));
fbc315db
ILT
1899 pp_cxx_right_paren (pp);
1900 pp_newline_and_indent (pp, 3);
c3e5898b 1901 pp_cxx_statement (pp, FOR_BODY (t));
fbc315db
ILT
1902 pp_indentation (pp) -= 3;
1903 pp_needs_newline (pp) = true;
1904 break;
1905
1906 /* jump-statement:
0cbd7506
MS
1907 goto identifier;
1908 continue ;
1909 return expression(opt) ; */
fbc315db
ILT
1910 case BREAK_STMT:
1911 case CONTINUE_STMT:
b02cec6e 1912 pp_string (pp, TREE_CODE (t) == BREAK_STMT ? "break" : "continue");
fbc315db
ILT
1913 pp_cxx_semicolon (pp);
1914 pp_needs_newline (pp) = true;
1915 break;
1916
934790cc 1917 /* expression-statement:
0cbd7506 1918 expression(opt) ; */
934790cc
ILT
1919 case EXPR_STMT:
1920 pp_cxx_expression (pp, EXPR_STMT_EXPR (t));
1921 pp_cxx_semicolon (pp);
1922 pp_needs_newline (pp) = true;
1923 break;
1924
5a508662 1925 case CLEANUP_STMT:
b02cec6e 1926 pp_cxx_ws_string (pp, "try");
5a508662
RH
1927 pp_newline_and_indent (pp, 2);
1928 pp_cxx_statement (pp, CLEANUP_BODY (t));
1929 pp_newline_and_indent (pp, -2);
b02cec6e 1930 pp_cxx_ws_string (pp, CLEANUP_EH_ONLY (t) ? "catch" : "finally");
5a508662
RH
1931 pp_newline_and_indent (pp, 2);
1932 pp_cxx_statement (pp, CLEANUP_EXPR (t));
1933 pp_newline_and_indent (pp, -2);
1934 break;
1935
55a3debe
DG
1936 case STATIC_ASSERT:
1937 pp_cxx_declaration (pp, t);
1938 break;
1939
12ea3302
GDR
1940 default:
1941 pp_c_statement (pp_c_base (pp), t);
1942 break;
1943 }
1944}
1945
a2a9e21c
GDR
1946/* original-namespace-definition:
1947 namespace identifier { namespace-body }
1948
1949 As an edge case, we also handle unnamed namespace definition here. */
1950
1951static void
1952pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t)
1953{
b02cec6e 1954 pp_cxx_ws_string (pp, "namespace");
91b1ca65
MM
1955 if (DECL_CONTEXT (t))
1956 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
ed36980c 1957 if (DECL_NAME (t))
a2a9e21c
GDR
1958 pp_cxx_unqualified_id (pp, t);
1959 pp_cxx_whitespace (pp);
1960 pp_cxx_left_brace (pp);
1961 /* We do not print the namespace-body. */
1962 pp_cxx_whitespace (pp);
1963 pp_cxx_right_brace (pp);
1964}
1965
1966/* namespace-alias:
1967 identifier
1968
1969 namespace-alias-definition:
1970 namespace identifier = qualified-namespace-specifier ;
1971
1972 qualified-namespace-specifier:
1973 ::(opt) nested-name-specifier(opt) namespace-name */
1974
1975static void
1976pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t)
1977{
b02cec6e 1978 pp_cxx_ws_string (pp, "namespace");
91b1ca65
MM
1979 if (DECL_CONTEXT (t))
1980 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
a2a9e21c
GDR
1981 pp_cxx_unqualified_id (pp, t);
1982 pp_cxx_whitespace (pp);
1983 pp_equal (pp);
1984 pp_cxx_whitespace (pp);
91b1ca65 1985 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)))
3db45ab5 1986 pp_cxx_nested_name_specifier (pp,
91b1ca65 1987 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)));
a2a9e21c
GDR
1988 pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t));
1989 pp_cxx_semicolon (pp);
1990}
1991
12ea3302
GDR
1992/* simple-declaration:
1993 decl-specifier-seq(opt) init-declarator-list(opt) */
b9b44fb9 1994
12ea3302
GDR
1995static void
1996pp_cxx_simple_declaration (cxx_pretty_printer *pp, tree t)
1997{
1998 pp_cxx_decl_specifier_seq (pp, t);
1999 pp_cxx_init_declarator (pp, t);
2000 pp_cxx_semicolon (pp);
2001 pp_needs_newline (pp) = true;
2002}
2003
2004/*
2005 template-parameter-list:
2006 template-parameter
2007 template-parameter-list , template-parameter */
2008
2009static inline void
2010pp_cxx_template_parameter_list (cxx_pretty_printer *pp, tree t)
2011{
2012 const int n = TREE_VEC_LENGTH (t);
2013 int i;
2014 for (i = 0; i < n; ++i)
2015 {
2016 if (i)
0cbd7506 2017 pp_cxx_separate_with (pp, ',');
12ea3302
GDR
2018 pp_cxx_template_parameter (pp, TREE_VEC_ELT (t, i));
2019 }
2020}
2021
2022/* template-parameter:
2023 type-parameter
2024 parameter-declaration
2025
2026 type-parameter:
5d80a306
DG
2027 class ...(opt) identifier(opt)
2028 class identifier(opt) = type-id
12ea3302 2029 typename identifier(opt)
5d80a306
DG
2030 typename ...(opt) identifier(opt) = type-id
2031 template < template-parameter-list > class ...(opt) identifier(opt)
3db45ab5 2032 template < template-parameter-list > class identifier(opt) = template-name */
b9b44fb9 2033
12ea3302
GDR
2034static void
2035pp_cxx_template_parameter (cxx_pretty_printer *pp, tree t)
2036{
2037 tree parameter = TREE_VALUE (t);
2038 switch (TREE_CODE (parameter))
2039 {
2040 case TYPE_DECL:
b02cec6e 2041 pp_cxx_ws_string (pp, "class");
5d80a306 2042 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t)))
b02cec6e 2043 pp_cxx_ws_string (pp, "...");
12ea3302 2044 if (DECL_NAME (parameter))
0cbd7506 2045 pp_cxx_tree_identifier (pp, DECL_NAME (parameter));
39a13be5 2046 /* FIXME: Check if we should print also default argument. */
12ea3302
GDR
2047 break;
2048
2049 case PARM_DECL:
2050 pp_cxx_parameter_declaration (pp, parameter);
2051 break;
2052
2053 case TEMPLATE_DECL:
2054 break;
2055
2056 default:
2057 pp_unsupported_tree (pp, t);
2058 break;
2059 }
2060}
2061
b2517173
GDR
2062/* Pretty-print a template parameter in the canonical form
2063 "template-parameter-<level>-<position in parameter list>". */
2064
2065void
2066pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm)
2067{
2068 const enum tree_code code = TREE_CODE (parm);
2069
04c06002 2070 /* Brings type template parameters to the canonical forms. */
b2517173
GDR
2071 if (code == TEMPLATE_TYPE_PARM || code == TEMPLATE_TEMPLATE_PARM
2072 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
2073 parm = TEMPLATE_TYPE_PARM_INDEX (parm);
c8094d83 2074
b2517173 2075 pp_cxx_begin_template_argument_list (pp);
f41c4af3 2076 pp_cxx_ws_string (pp, M_("template-parameter-"));
b2517173
GDR
2077 pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm));
2078 pp_minus (pp);
2079 pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1);
2080 pp_cxx_end_template_argument_list (pp);
2081}
2082
12ea3302
GDR
2083/*
2084 template-declaration:
2085 export(opt) template < template-parameter-list > declaration */
b9b44fb9 2086
12ea3302
GDR
2087static void
2088pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t)
2089{
2090 tree tmpl = most_general_template (t);
2091 tree level;
2092 int i = 0;
2093
2094 pp_maybe_newline_and_indent (pp, 0);
2095 for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level))
2096 {
b02cec6e 2097 pp_cxx_ws_string (pp, "template");
12ea3302
GDR
2098 pp_cxx_begin_template_argument_list (pp);
2099 pp_cxx_template_parameter_list (pp, TREE_VALUE (level));
2100 pp_cxx_end_template_argument_list (pp);
2101 pp_newline_and_indent (pp, 3);
2102 i += 3;
2103 }
2104 if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t))
2105 pp_cxx_function_definition (pp, t);
2106 else
2107 pp_cxx_simple_declaration (pp, t);
2108}
2109
2110static void
2111pp_cxx_explicit_specialization (cxx_pretty_printer *pp, tree t)
2112{
2113 pp_unsupported_tree (pp, t);
2114}
2115
2116static void
2117pp_cxx_explicit_instantiation (cxx_pretty_printer *pp, tree t)
2118{
2119 pp_unsupported_tree (pp, t);
2120}
2121
2122/*
2123 declaration:
2124 block-declaration
2125 function-definition
2126 template-declaration
2127 explicit-instantiation
2128 explicit-specialization
2129 linkage-specification
2130 namespace-definition
2131
2132 block-declaration:
2133 simple-declaration
2134 asm-definition
2135 namespace-alias-definition
2136 using-declaration
55a3debe
DG
2137 using-directive
2138 static_assert-declaration */
12ea3302
GDR
2139void
2140pp_cxx_declaration (cxx_pretty_printer *pp, tree t)
2141{
55a3debe
DG
2142 if (TREE_CODE (t) == STATIC_ASSERT)
2143 {
b02cec6e 2144 pp_cxx_ws_string (pp, "static_assert");
55a3debe
DG
2145 pp_cxx_left_paren (pp);
2146 pp_cxx_expression (pp, STATIC_ASSERT_CONDITION (t));
2147 pp_cxx_separate_with (pp, ',');
2148 pp_cxx_expression (pp, STATIC_ASSERT_MESSAGE (t));
2149 pp_cxx_right_paren (pp);
2150 }
2151 else if (!DECL_LANG_SPECIFIC (t))
12ea3302 2152 pp_cxx_simple_declaration (pp, t);
a2a9e21c 2153 else if (DECL_USE_TEMPLATE (t))
12ea3302
GDR
2154 switch (DECL_USE_TEMPLATE (t))
2155 {
a2a9e21c 2156 case 1:
0cbd7506
MS
2157 pp_cxx_template_declaration (pp, t);
2158 break;
c8094d83 2159
12ea3302 2160 case 2:
0cbd7506
MS
2161 pp_cxx_explicit_specialization (pp, t);
2162 break;
12ea3302
GDR
2163
2164 case 3:
0cbd7506
MS
2165 pp_cxx_explicit_instantiation (pp, t);
2166 break;
12ea3302
GDR
2167
2168 default:
0cbd7506 2169 break;
12ea3302 2170 }
12ea3302
GDR
2171 else switch (TREE_CODE (t))
2172 {
2173 case VAR_DECL:
2174 case TYPE_DECL:
2175 pp_cxx_simple_declaration (pp, t);
2176 break;
c8094d83 2177
12ea3302
GDR
2178 case FUNCTION_DECL:
2179 if (DECL_SAVED_TREE (t))
0cbd7506 2180 pp_cxx_function_definition (pp, t);
12ea3302 2181 else
0cbd7506 2182 pp_cxx_simple_declaration (pp, t);
12ea3302
GDR
2183 break;
2184
a2a9e21c
GDR
2185 case NAMESPACE_DECL:
2186 if (DECL_NAMESPACE_ALIAS (t))
0cbd7506 2187 pp_cxx_namespace_alias_definition (pp, t);
a2a9e21c 2188 else
0cbd7506 2189 pp_cxx_original_namespace_definition (pp, t);
a2a9e21c
GDR
2190 break;
2191
12ea3302
GDR
2192 default:
2193 pp_unsupported_tree (pp, t);
2194 break;
2195 }
2196}
2197
066f956c 2198static void
2d65b828
PC
2199pp_cxx_typeid_expression (cxx_pretty_printer *pp, tree t)
2200{
2201 t = TREE_OPERAND (t, 0);
b02cec6e 2202 pp_cxx_ws_string (pp, "typeid");
2d65b828
PC
2203 pp_cxx_left_paren (pp);
2204 if (TYPE_P (t))
2205 pp_cxx_type_id (pp, t);
2206 else
2207 pp_cxx_expression (pp, t);
2208 pp_cxx_right_paren (pp);
2209}
2210
fdb8f418
PC
2211void
2212pp_cxx_va_arg_expression (cxx_pretty_printer *pp, tree t)
2213{
b02cec6e 2214 pp_cxx_ws_string (pp, "va_arg");
fdb8f418
PC
2215 pp_cxx_left_paren (pp);
2216 pp_cxx_assignment_expression (pp, TREE_OPERAND (t, 0));
2217 pp_cxx_separate_with (pp, ',');
2218 pp_cxx_type_id (pp, TREE_TYPE (t));
2219 pp_cxx_right_paren (pp);
2220}
2221
094a5fe2
JJ
2222static bool
2223pp_cxx_offsetof_expression_1 (cxx_pretty_printer *pp, tree t)
2224{
2225 switch (TREE_CODE (t))
2226 {
2227 case ARROW_EXPR:
2228 if (TREE_CODE (TREE_OPERAND (t, 0)) == STATIC_CAST_EXPR
2229 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
2230 {
2231 pp_cxx_type_id (pp, TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))));
2232 pp_cxx_separate_with (pp, ',');
2233 return true;
2234 }
2235 return false;
2236 case COMPONENT_REF:
2237 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
2238 return false;
2239 if (TREE_CODE (TREE_OPERAND (t, 0)) != ARROW_EXPR)
2240 pp_cxx_dot (pp);
2241 pp_cxx_expression (pp, TREE_OPERAND (t, 1));
2242 return true;
2243 case ARRAY_REF:
2244 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
2245 return false;
2246 pp_left_bracket (pp);
2247 pp_cxx_expression (pp, TREE_OPERAND (t, 1));
2248 pp_right_bracket (pp);
2249 return true;
2250 default:
2251 return false;
2252 }
2253}
2254
2255void
2256pp_cxx_offsetof_expression (cxx_pretty_printer *pp, tree t)
2257{
b02cec6e 2258 pp_cxx_ws_string (pp, "offsetof");
094a5fe2
JJ
2259 pp_cxx_left_paren (pp);
2260 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
2261 pp_cxx_expression (pp, TREE_OPERAND (t, 0));
2262 pp_cxx_right_paren (pp);
2263}
2264
e74392f0
PC
2265void
2266pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t)
2267{
2268 cp_trait_kind kind = TRAIT_EXPR_KIND (t);
2269
2270 switch (kind)
2271 {
2272 case CPTK_HAS_NOTHROW_ASSIGN:
b02cec6e 2273 pp_cxx_ws_string (pp, "__has_nothrow_assign");
e74392f0
PC
2274 break;
2275 case CPTK_HAS_TRIVIAL_ASSIGN:
b02cec6e 2276 pp_cxx_ws_string (pp, "__has_trivial_assign");
e74392f0
PC
2277 break;
2278 case CPTK_HAS_NOTHROW_CONSTRUCTOR:
b02cec6e 2279 pp_cxx_ws_string (pp, "__has_nothrow_constructor");
e74392f0
PC
2280 break;
2281 case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
b02cec6e 2282 pp_cxx_ws_string (pp, "__has_trivial_constructor");
e74392f0
PC
2283 break;
2284 case CPTK_HAS_NOTHROW_COPY:
b02cec6e 2285 pp_cxx_ws_string (pp, "__has_nothrow_copy");
e74392f0
PC
2286 break;
2287 case CPTK_HAS_TRIVIAL_COPY:
b02cec6e 2288 pp_cxx_ws_string (pp, "__has_trivial_copy");
e74392f0
PC
2289 break;
2290 case CPTK_HAS_TRIVIAL_DESTRUCTOR:
b02cec6e 2291 pp_cxx_ws_string (pp, "__has_trivial_destructor");
e74392f0
PC
2292 break;
2293 case CPTK_HAS_VIRTUAL_DESTRUCTOR:
b02cec6e 2294 pp_cxx_ws_string (pp, "__has_virtual_destructor");
e74392f0
PC
2295 break;
2296 case CPTK_IS_ABSTRACT:
b02cec6e 2297 pp_cxx_ws_string (pp, "__is_abstract");
e74392f0
PC
2298 break;
2299 case CPTK_IS_BASE_OF:
b02cec6e 2300 pp_cxx_ws_string (pp, "__is_base_of");
e74392f0
PC
2301 break;
2302 case CPTK_IS_CLASS:
b02cec6e 2303 pp_cxx_ws_string (pp, "__is_class");
e74392f0
PC
2304 break;
2305 case CPTK_IS_CONVERTIBLE_TO:
b02cec6e 2306 pp_cxx_ws_string (pp, "__is_convertible_to");
e74392f0
PC
2307 break;
2308 case CPTK_IS_EMPTY:
b02cec6e 2309 pp_cxx_ws_string (pp, "__is_empty");
e74392f0
PC
2310 break;
2311 case CPTK_IS_ENUM:
b02cec6e 2312 pp_cxx_ws_string (pp, "__is_enum");
e74392f0
PC
2313 break;
2314 case CPTK_IS_POD:
b02cec6e 2315 pp_cxx_ws_string (pp, "__is_pod");
e74392f0
PC
2316 break;
2317 case CPTK_IS_POLYMORPHIC:
b02cec6e 2318 pp_cxx_ws_string (pp, "__is_polymorphic");
e74392f0 2319 break;
c32097d8
JM
2320 case CPTK_IS_STD_LAYOUT:
2321 pp_cxx_ws_string (pp, "__is_std_layout");
2322 break;
2323 case CPTK_IS_TRIVIAL:
2324 pp_cxx_ws_string (pp, "__is_trivial");
2325 break;
e74392f0 2326 case CPTK_IS_UNION:
b02cec6e 2327 pp_cxx_ws_string (pp, "__is_union");
e74392f0
PC
2328 break;
2329
2330 default:
2331 gcc_unreachable ();
2332 }
2333
2334 pp_cxx_left_paren (pp);
2335 pp_cxx_type_id (pp, TRAIT_EXPR_TYPE1 (t));
2336
2337 if (kind == CPTK_IS_BASE_OF || kind == CPTK_IS_CONVERTIBLE_TO)
2338 {
2339 pp_cxx_separate_with (pp, ',');
2340 pp_cxx_type_id (pp, TRAIT_EXPR_TYPE2 (t));
2341 }
2342
2343 pp_cxx_right_paren (pp);
2344}
12ea3302
GDR
2345\f
2346typedef c_pretty_print_fn pp_fun;
2347
b9b44fb9
GDR
2348/* Initialization of a C++ pretty-printer object. */
2349
12ea3302
GDR
2350void
2351pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
2352{
2353 pp_c_pretty_printer_init (pp_c_base (pp));
2354 pp_set_line_maximum_length (pp, 0);
e1a4dd13
GDR
2355
2356 pp->c_base.declaration = (pp_fun) pp_cxx_declaration;
12ea3302
GDR
2357 pp->c_base.declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
2358 pp->c_base.function_specifier = (pp_fun) pp_cxx_function_specifier;
2359 pp->c_base.type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
e1a4dd13
GDR
2360 pp->c_base.declarator = (pp_fun) pp_cxx_declarator;
2361 pp->c_base.direct_declarator = (pp_fun) pp_cxx_direct_declarator;
12ea3302 2362 pp->c_base.parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
e1a4dd13 2363 pp->c_base.type_id = (pp_fun) pp_cxx_type_id;
12ea3302
GDR
2364 pp->c_base.abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
2365 pp->c_base.direct_abstract_declarator =
2366 (pp_fun) pp_cxx_direct_abstract_declarator;
2367 pp->c_base.simple_type_specifier = (pp_fun)pp_cxx_simple_type_specifier;
2368
2369 /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
2370
a176426f 2371 pp->c_base.constant = (pp_fun) pp_cxx_constant;
4b780675 2372 pp->c_base.id_expression = (pp_fun) pp_cxx_id_expression;
e1a4dd13
GDR
2373 pp->c_base.primary_expression = (pp_fun) pp_cxx_primary_expression;
2374 pp->c_base.postfix_expression = (pp_fun) pp_cxx_postfix_expression;
2375 pp->c_base.unary_expression = (pp_fun) pp_cxx_unary_expression;
4b780675 2376 pp->c_base.multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
e1a4dd13
GDR
2377 pp->c_base.conditional_expression = (pp_fun) pp_cxx_conditional_expression;
2378 pp->c_base.assignment_expression = (pp_fun) pp_cxx_assignment_expression;
12ea3302
GDR
2379 pp->c_base.expression = (pp_fun) pp_cxx_expression;
2380 pp->enclosing_scope = global_namespace;
e1a4dd13 2381}