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