| 1 |
/* Implementation of subroutines for the GNU C++ pretty-printer. |
| 2 |
Copyright (C) 2003-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Gabriel Dos Reis <[email protected]> |
| 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 |
| 9 |
Software Foundation; either version 3, or (at your option) any later |
| 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 |
| 18 |
along with GCC; see the file COPYING3. If not see |
| 19 |
<http://www.gnu.org/licenses/>. */ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
#include "system.h" |
| 23 |
#include "coretypes.h" |
| 24 |
#include "cp-tree.h" |
| 25 |
#include "cxx-pretty-print.h" |
| 26 |
#include "tree-pretty-print.h" |
| 27 |
#include "make-unique.h" |
| 28 |
|
| 29 |
static void pp_cxx_unqualified_id (cxx_pretty_printer *, tree); |
| 30 |
static void pp_cxx_nested_name_specifier (cxx_pretty_printer *, tree); |
| 31 |
static void pp_cxx_qualified_id (cxx_pretty_printer *, tree); |
| 32 |
static void pp_cxx_template_argument_list (cxx_pretty_printer *, tree); |
| 33 |
static void pp_cxx_type_specifier_seq (cxx_pretty_printer *, tree); |
| 34 |
static void pp_cxx_ptr_operator (cxx_pretty_printer *, tree); |
| 35 |
static void pp_cxx_parameter_declaration_clause (cxx_pretty_printer *, tree); |
| 36 |
static void pp_cxx_template_parameter (cxx_pretty_printer *, tree); |
| 37 |
static void pp_cxx_cast_expression (cxx_pretty_printer *, tree); |
| 38 |
static void pp_cxx_typeid_expression (cxx_pretty_printer *, tree); |
| 39 |
static void pp_cxx_unary_left_fold_expression (cxx_pretty_printer *, tree); |
| 40 |
static void pp_cxx_unary_right_fold_expression (cxx_pretty_printer *, tree); |
| 41 |
static void pp_cxx_binary_fold_expression (cxx_pretty_printer *, tree); |
| 42 |
static void pp_cxx_concept_definition (cxx_pretty_printer *, tree); |
| 43 |
|
| 44 |
|
| 45 |
static inline void |
| 46 |
pp_cxx_nonconsecutive_character (cxx_pretty_printer *pp, int c) |
| 47 |
{ |
| 48 |
const char *p = pp_last_position_in_text (pp); |
| 49 |
|
| 50 |
if (p != NULL && *p == c) |
| 51 |
pp_cxx_whitespace (pp); |
| 52 |
pp_character (pp, c); |
| 53 |
pp->set_padding (pp_none); |
| 54 |
} |
| 55 |
|
| 56 |
#define pp_cxx_expression_list(PP, T) \ |
| 57 |
pp_c_expression_list (PP, T) |
| 58 |
#define pp_cxx_space_for_pointer_operator(PP, T) \ |
| 59 |
pp_c_space_for_pointer_operator (PP, T) |
| 60 |
#define pp_cxx_init_declarator(PP, T) \ |
| 61 |
pp_c_init_declarator (PP, T) |
| 62 |
#define pp_cxx_call_argument_list(PP, T) \ |
| 63 |
pp_c_call_argument_list (PP, T) |
| 64 |
|
| 65 |
void |
| 66 |
pp_cxx_colon_colon (cxx_pretty_printer *pp) |
| 67 |
{ |
| 68 |
pp_colon_colon (pp); |
| 69 |
pp->set_padding (pp_none); |
| 70 |
} |
| 71 |
|
| 72 |
void |
| 73 |
pp_cxx_begin_template_argument_list (cxx_pretty_printer *pp) |
| 74 |
{ |
| 75 |
pp_cxx_nonconsecutive_character (pp, '<'); |
| 76 |
} |
| 77 |
|
| 78 |
void |
| 79 |
pp_cxx_end_template_argument_list (cxx_pretty_printer *pp) |
| 80 |
{ |
| 81 |
pp_cxx_nonconsecutive_character (pp, '>'); |
| 82 |
} |
| 83 |
|
| 84 |
void |
| 85 |
pp_cxx_separate_with (cxx_pretty_printer *pp, int c) |
| 86 |
{ |
| 87 |
pp_separate_with (pp, c); |
| 88 |
pp->set_padding (pp_none); |
| 89 |
} |
| 90 |
|
| 91 |
/* Expressions. */ |
| 92 |
|
| 93 |
/* conversion-function-id: |
| 94 |
operator conversion-type-id |
| 95 |
|
| 96 |
conversion-type-id: |
| 97 |
type-specifier-seq conversion-declarator(opt) |
| 98 |
|
| 99 |
conversion-declarator: |
| 100 |
ptr-operator conversion-declarator(opt) */ |
| 101 |
|
| 102 |
static inline void |
| 103 |
pp_cxx_conversion_function_id (cxx_pretty_printer *pp, tree t) |
| 104 |
{ |
| 105 |
pp_cxx_ws_string (pp, "operator"); |
| 106 |
pp_cxx_type_specifier_seq (pp, TREE_TYPE (t)); |
| 107 |
} |
| 108 |
|
| 109 |
static inline void |
| 110 |
pp_cxx_template_id (cxx_pretty_printer *pp, tree t) |
| 111 |
{ |
| 112 |
pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0)); |
| 113 |
pp_cxx_begin_template_argument_list (pp); |
| 114 |
pp_cxx_template_argument_list (pp, TREE_OPERAND (t, 1)); |
| 115 |
pp_cxx_end_template_argument_list (pp); |
| 116 |
} |
| 117 |
|
| 118 |
/* Prints the unqualified part of the id-expression T. |
| 119 |
|
| 120 |
unqualified-id: |
| 121 |
identifier |
| 122 |
operator-function-id |
| 123 |
conversion-function-id |
| 124 |
~ class-name |
| 125 |
template-id */ |
| 126 |
|
| 127 |
static void |
| 128 |
pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t) |
| 129 |
{ |
| 130 |
enum tree_code code = TREE_CODE (t); |
| 131 |
switch (code) |
| 132 |
{ |
| 133 |
case RESULT_DECL: |
| 134 |
pp->translate_string ("<return-value>"); |
| 135 |
break; |
| 136 |
|
| 137 |
case OVERLOAD: |
| 138 |
t = OVL_FIRST (t); |
| 139 |
/* FALLTHRU */ |
| 140 |
case VAR_DECL: |
| 141 |
case PARM_DECL: |
| 142 |
case CONST_DECL: |
| 143 |
case TYPE_DECL: |
| 144 |
case FUNCTION_DECL: |
| 145 |
case NAMESPACE_DECL: |
| 146 |
case FIELD_DECL: |
| 147 |
case LABEL_DECL: |
| 148 |
case USING_DECL: |
| 149 |
case TEMPLATE_DECL: |
| 150 |
t = DECL_NAME (t); |
| 151 |
/* FALLTHRU */ |
| 152 |
|
| 153 |
case IDENTIFIER_NODE: |
| 154 |
if (t == NULL) |
| 155 |
pp->translate_string ("<unnamed>"); |
| 156 |
else if (IDENTIFIER_CONV_OP_P (t)) |
| 157 |
pp_cxx_conversion_function_id (pp, t); |
| 158 |
else |
| 159 |
pp_cxx_tree_identifier (pp, t); |
| 160 |
break; |
| 161 |
|
| 162 |
case TEMPLATE_ID_EXPR: |
| 163 |
pp_cxx_template_id (pp, t); |
| 164 |
break; |
| 165 |
|
| 166 |
case BASELINK: |
| 167 |
pp_cxx_unqualified_id (pp, BASELINK_FUNCTIONS (t)); |
| 168 |
break; |
| 169 |
|
| 170 |
case RECORD_TYPE: |
| 171 |
case UNION_TYPE: |
| 172 |
case ENUMERAL_TYPE: |
| 173 |
case TYPENAME_TYPE: |
| 174 |
case UNBOUND_CLASS_TEMPLATE: |
| 175 |
pp_cxx_unqualified_id (pp, TYPE_NAME (t)); |
| 176 |
if (tree ti = TYPE_TEMPLATE_INFO_MAYBE_ALIAS (t)) |
| 177 |
if (PRIMARY_TEMPLATE_P (TI_TEMPLATE (ti))) |
| 178 |
{ |
| 179 |
pp_cxx_begin_template_argument_list (pp); |
| 180 |
tree args = INNERMOST_TEMPLATE_ARGS (TI_ARGS (ti)); |
| 181 |
pp_cxx_template_argument_list (pp, args); |
| 182 |
pp_cxx_end_template_argument_list (pp); |
| 183 |
} |
| 184 |
break; |
| 185 |
|
| 186 |
case BIT_NOT_EXPR: |
| 187 |
pp_cxx_complement (pp); |
| 188 |
pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0)); |
| 189 |
break; |
| 190 |
|
| 191 |
case TEMPLATE_TYPE_PARM: |
| 192 |
case TEMPLATE_TEMPLATE_PARM: |
| 193 |
if (template_placeholder_p (t)) |
| 194 |
{ |
| 195 |
t = TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t)); |
| 196 |
pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t)); |
| 197 |
pp_string (pp, "<...auto...>"); |
| 198 |
} |
| 199 |
else if (TYPE_IDENTIFIER (t)) |
| 200 |
pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t)); |
| 201 |
else |
| 202 |
pp_cxx_canonical_template_parameter (pp, t); |
| 203 |
break; |
| 204 |
|
| 205 |
case TEMPLATE_PARM_INDEX: |
| 206 |
pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t)); |
| 207 |
break; |
| 208 |
|
| 209 |
case BOUND_TEMPLATE_TEMPLATE_PARM: |
| 210 |
pp_cxx_cv_qualifier_seq (pp, t); |
| 211 |
pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t)); |
| 212 |
pp_cxx_begin_template_argument_list (pp); |
| 213 |
pp_cxx_template_argument_list (pp, TYPE_TI_ARGS (t)); |
| 214 |
pp_cxx_end_template_argument_list (pp); |
| 215 |
break; |
| 216 |
|
| 217 |
default: |
| 218 |
pp_unsupported_tree (pp, t); |
| 219 |
break; |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
/* Pretty-print out the token sequence ":: template" in template codes |
| 224 |
where it is needed to "inline declare" the (following) member as |
| 225 |
a template. This situation arises when SCOPE of T is dependent |
| 226 |
on template parameters. */ |
| 227 |
|
| 228 |
static inline void |
| 229 |
pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t) |
| 230 |
{ |
| 231 |
if (TREE_CODE (t) == TEMPLATE_ID_EXPR |
| 232 |
&& TYPE_P (scope) && dependent_type_p (scope)) |
| 233 |
pp_cxx_ws_string (pp, "template"); |
| 234 |
} |
| 235 |
|
| 236 |
/* nested-name-specifier: |
| 237 |
:: |
| 238 |
type-name :: |
| 239 |
namespace-name :: |
| 240 |
computed-type-specifier :: |
| 241 |
nested-name-specifier identifier :: |
| 242 |
nested-name-specifier template(opt) simple-template-id :: */ |
| 243 |
|
| 244 |
static void |
| 245 |
pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t) |
| 246 |
{ |
| 247 |
/* FIXME: When diagnosing references to concepts (especially as types?) |
| 248 |
we end up adding too many '::' to the name. This is partially due |
| 249 |
to the fact that pp->enclosing_namespace is null. */ |
| 250 |
if (t == global_namespace) |
| 251 |
{ |
| 252 |
pp_cxx_colon_colon (pp); |
| 253 |
} |
| 254 |
else if (!SCOPE_FILE_SCOPE_P (t) && t != pp->enclosing_scope) |
| 255 |
{ |
| 256 |
tree scope = get_containing_scope (t); |
| 257 |
pp_cxx_nested_name_specifier (pp, scope); |
| 258 |
pp_cxx_template_keyword_if_needed (pp, scope, t); |
| 259 |
/* This is a computed-type-specifier. */ |
| 260 |
if (TREE_CODE (t) == PACK_INDEX_TYPE || TREE_CODE (t) == DECLTYPE_TYPE) |
| 261 |
pp->type_id (t); |
| 262 |
else |
| 263 |
pp_cxx_unqualified_id (pp, t); |
| 264 |
pp_cxx_colon_colon (pp); |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
/* qualified-id: |
| 269 |
nested-name-specifier template(opt) unqualified-id */ |
| 270 |
|
| 271 |
static void |
| 272 |
pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t) |
| 273 |
{ |
| 274 |
switch (TREE_CODE (t)) |
| 275 |
{ |
| 276 |
/* A pointer-to-member is always qualified. */ |
| 277 |
case PTRMEM_CST: |
| 278 |
pp_cxx_nested_name_specifier (pp, PTRMEM_CST_CLASS (t)); |
| 279 |
pp_cxx_unqualified_id (pp, PTRMEM_CST_MEMBER (t)); |
| 280 |
break; |
| 281 |
|
| 282 |
/* In Standard C++, functions cannot possibly be used as |
| 283 |
nested-name-specifiers. However, there are situations where |
| 284 |
is "makes sense" to output the surrounding function name for the |
| 285 |
purpose of emphasizing on the scope kind. Just printing the |
| 286 |
function name might not be sufficient as it may be overloaded; so, |
| 287 |
we decorate the function with its signature too. |
| 288 |
FIXME: This is probably the wrong pretty-printing for conversion |
| 289 |
functions and some function templates. */ |
| 290 |
case OVERLOAD: |
| 291 |
t = OVL_FIRST (t); |
| 292 |
/* FALLTHRU */ |
| 293 |
case FUNCTION_DECL: |
| 294 |
if (DECL_FUNCTION_MEMBER_P (t)) |
| 295 |
pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t)); |
| 296 |
pp_cxx_unqualified_id |
| 297 |
(pp, DECL_CONSTRUCTOR_P (t) ? DECL_CONTEXT (t) : t); |
| 298 |
pp_cxx_parameter_declaration_clause (pp, TREE_TYPE (t)); |
| 299 |
break; |
| 300 |
|
| 301 |
case OFFSET_REF: |
| 302 |
case SCOPE_REF: |
| 303 |
pp_cxx_nested_name_specifier (pp, TREE_OPERAND (t, 0)); |
| 304 |
pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 1)); |
| 305 |
break; |
| 306 |
|
| 307 |
default: |
| 308 |
{ |
| 309 |
tree scope = get_containing_scope (t); |
| 310 |
if (scope != pp->enclosing_scope) |
| 311 |
{ |
| 312 |
pp_cxx_nested_name_specifier (pp, scope); |
| 313 |
pp_cxx_template_keyword_if_needed (pp, scope, t); |
| 314 |
} |
| 315 |
pp_cxx_unqualified_id (pp, t); |
| 316 |
} |
| 317 |
break; |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
/* Given a value e of ENUMERAL_TYPE: |
| 322 |
Print out the first ENUMERATOR id with value e, if one is found, |
| 323 |
(including nested names but excluding the enum name if unscoped) |
| 324 |
else print out the value as a C-style cast (type-id)value. */ |
| 325 |
|
| 326 |
static void |
| 327 |
pp_cxx_enumeration_constant (cxx_pretty_printer *pp, tree e) |
| 328 |
{ |
| 329 |
tree type = TREE_TYPE (e); |
| 330 |
tree value = NULL_TREE; |
| 331 |
|
| 332 |
/* Find the name of this constant. */ |
| 333 |
if ((pp->flags & pp_c_flag_gnu_v3) == 0) |
| 334 |
for (value = TYPE_VALUES (type); value != NULL_TREE; |
| 335 |
value = TREE_CHAIN (value)) |
| 336 |
if (tree_int_cst_equal (DECL_INITIAL (TREE_VALUE (value)), e)) |
| 337 |
break; |
| 338 |
|
| 339 |
if (value != NULL_TREE) |
| 340 |
{ |
| 341 |
if (!ENUM_IS_SCOPED (type)) |
| 342 |
type = get_containing_scope (type); |
| 343 |
pp_cxx_nested_name_specifier (pp, type); |
| 344 |
pp->id_expression (TREE_PURPOSE (value)); |
| 345 |
} |
| 346 |
else |
| 347 |
{ |
| 348 |
/* Value must have been cast. */ |
| 349 |
pp_c_type_cast (pp, type); |
| 350 |
pp_c_integer_constant (pp, e); |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
void |
| 356 |
cxx_pretty_printer::constant (tree t) |
| 357 |
{ |
| 358 |
switch (TREE_CODE (t)) |
| 359 |
{ |
| 360 |
case STRING_CST: |
| 361 |
{ |
| 362 |
const bool in_parens = PAREN_STRING_LITERAL_P (t); |
| 363 |
if (in_parens) |
| 364 |
pp_cxx_left_paren (this); |
| 365 |
c_pretty_printer::constant (t); |
| 366 |
if (in_parens) |
| 367 |
pp_cxx_right_paren (this); |
| 368 |
} |
| 369 |
break; |
| 370 |
|
| 371 |
case INTEGER_CST: |
| 372 |
if (NULLPTR_TYPE_P (TREE_TYPE (t))) |
| 373 |
{ |
| 374 |
pp_string (this, "nullptr"); |
| 375 |
break; |
| 376 |
} |
| 377 |
else if (TREE_CODE (TREE_TYPE (t)) == ENUMERAL_TYPE) |
| 378 |
{ |
| 379 |
pp_cxx_enumeration_constant (this, t); |
| 380 |
break; |
| 381 |
} |
| 382 |
/* fall through. */ |
| 383 |
|
| 384 |
default: |
| 385 |
c_pretty_printer::constant (t); |
| 386 |
break; |
| 387 |
} |
| 388 |
} |
| 389 |
|
| 390 |
/* id-expression: |
| 391 |
unqualified-id |
| 392 |
qualified-id */ |
| 393 |
|
| 394 |
void |
| 395 |
cxx_pretty_printer::id_expression (tree t) |
| 396 |
{ |
| 397 |
if (TREE_CODE (t) == OVERLOAD) |
| 398 |
t = OVL_FIRST (t); |
| 399 |
if (DECL_P (t) && DECL_CONTEXT (t)) |
| 400 |
pp_cxx_qualified_id (this, t); |
| 401 |
else |
| 402 |
pp_cxx_unqualified_id (this, t); |
| 403 |
} |
| 404 |
|
| 405 |
/* user-defined literal: |
| 406 |
literal ud-suffix */ |
| 407 |
|
| 408 |
void |
| 409 |
pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t) |
| 410 |
{ |
| 411 |
pp->constant (USERDEF_LITERAL_VALUE (t)); |
| 412 |
pp->id_expression (USERDEF_LITERAL_SUFFIX_ID (t)); |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
/* primary-expression: |
| 417 |
literal |
| 418 |
this |
| 419 |
:: identifier |
| 420 |
:: operator-function-id |
| 421 |
:: qualifier-id |
| 422 |
( expression ) |
| 423 |
id-expression |
| 424 |
|
| 425 |
GNU Extensions: |
| 426 |
__builtin_va_arg ( assignment-expression , type-id ) |
| 427 |
__builtin_offsetof ( type-id, offsetof-expression ) |
| 428 |
__builtin_addressof ( expression ) |
| 429 |
|
| 430 |
__builtin_is_virtual_base_of ( type-id , type-id ) |
| 431 |
|
| 432 |
__has_nothrow_assign ( type-id ) |
| 433 |
__has_nothrow_constructor ( type-id ) |
| 434 |
__has_nothrow_copy ( type-id ) |
| 435 |
__has_trivial_assign ( type-id ) |
| 436 |
__has_trivial_constructor ( type-id ) |
| 437 |
__has_trivial_copy ( type-id ) |
| 438 |
__has_unique_object_representations ( type-id ) |
| 439 |
__has_trivial_destructor ( type-id ) |
| 440 |
__has_virtual_destructor ( type-id ) |
| 441 |
__is_abstract ( type-id ) |
| 442 |
__is_base_of ( type-id , type-id ) |
| 443 |
__is_class ( type-id ) |
| 444 |
__is_empty ( type-id ) |
| 445 |
__is_enum ( type-id ) |
| 446 |
__is_literal_type ( type-id ) |
| 447 |
__is_pod ( type-id ) |
| 448 |
__is_polymorphic ( type-id ) |
| 449 |
__is_std_layout ( type-id ) |
| 450 |
__is_trivial ( type-id ) |
| 451 |
__is_union ( type-id ) */ |
| 452 |
|
| 453 |
void |
| 454 |
cxx_pretty_printer::primary_expression (tree t) |
| 455 |
{ |
| 456 |
switch (TREE_CODE (t)) |
| 457 |
{ |
| 458 |
case VOID_CST: |
| 459 |
case INTEGER_CST: |
| 460 |
case REAL_CST: |
| 461 |
case COMPLEX_CST: |
| 462 |
case STRING_CST: |
| 463 |
constant (t); |
| 464 |
break; |
| 465 |
|
| 466 |
case USERDEF_LITERAL: |
| 467 |
pp_cxx_userdef_literal (this, t); |
| 468 |
break; |
| 469 |
|
| 470 |
case BASELINK: |
| 471 |
t = BASELINK_FUNCTIONS (t); |
| 472 |
/* FALLTHRU */ |
| 473 |
case VAR_DECL: |
| 474 |
case PARM_DECL: |
| 475 |
case FIELD_DECL: |
| 476 |
case FUNCTION_DECL: |
| 477 |
case OVERLOAD: |
| 478 |
case CONST_DECL: |
| 479 |
case TEMPLATE_DECL: |
| 480 |
id_expression (t); |
| 481 |
break; |
| 482 |
|
| 483 |
case RESULT_DECL: |
| 484 |
case TEMPLATE_TYPE_PARM: |
| 485 |
case TEMPLATE_TEMPLATE_PARM: |
| 486 |
case TEMPLATE_PARM_INDEX: |
| 487 |
pp_cxx_unqualified_id (this, t); |
| 488 |
break; |
| 489 |
|
| 490 |
case STMT_EXPR: |
| 491 |
pp_cxx_left_paren (this); |
| 492 |
statement (STMT_EXPR_STMT (t)); |
| 493 |
pp_cxx_right_paren (this); |
| 494 |
break; |
| 495 |
|
| 496 |
case TRAIT_EXPR: |
| 497 |
pp_cxx_trait (this, t); |
| 498 |
break; |
| 499 |
|
| 500 |
case VA_ARG_EXPR: |
| 501 |
pp_cxx_va_arg_expression (this, t); |
| 502 |
break; |
| 503 |
|
| 504 |
case OFFSETOF_EXPR: |
| 505 |
pp_cxx_offsetof_expression (this, t); |
| 506 |
break; |
| 507 |
|
| 508 |
case ADDRESSOF_EXPR: |
| 509 |
pp_cxx_addressof_expression (this, t); |
| 510 |
break; |
| 511 |
|
| 512 |
case REQUIRES_EXPR: |
| 513 |
pp_cxx_requires_expr (this, t); |
| 514 |
break; |
| 515 |
|
| 516 |
default: |
| 517 |
c_pretty_printer::primary_expression (t); |
| 518 |
break; |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
/* postfix-expression: |
| 523 |
primary-expression |
| 524 |
postfix-expression [ expression ] |
| 525 |
postfix-expression ( expression-list(opt) ) |
| 526 |
simple-type-specifier ( expression-list(opt) ) |
| 527 |
typename ::(opt) nested-name-specifier identifier ( expression-list(opt) ) |
| 528 |
typename ::(opt) nested-name-specifier template(opt) |
| 529 |
template-id ( expression-list(opt) ) |
| 530 |
postfix-expression . template(opt) ::(opt) id-expression |
| 531 |
postfix-expression -> template(opt) ::(opt) id-expression |
| 532 |
postfix-expression . pseudo-destructor-name |
| 533 |
postfix-expression -> pseudo-destructor-name |
| 534 |
postfix-expression ++ |
| 535 |
postfix-expression -- |
| 536 |
dynamic_cast < type-id > ( expression ) |
| 537 |
static_cast < type-id > ( expression ) |
| 538 |
reinterpret_cast < type-id > ( expression ) |
| 539 |
const_cast < type-id > ( expression ) |
| 540 |
typeid ( expression ) |
| 541 |
typeid ( type-id ) */ |
| 542 |
|
| 543 |
void |
| 544 |
cxx_pretty_printer::postfix_expression (tree t) |
| 545 |
{ |
| 546 |
enum tree_code code = TREE_CODE (t); |
| 547 |
|
| 548 |
switch (code) |
| 549 |
{ |
| 550 |
case AGGR_INIT_EXPR: |
| 551 |
case CALL_EXPR: |
| 552 |
{ |
| 553 |
tree fun = cp_get_callee (t); |
| 554 |
tree saved_scope = enclosing_scope; |
| 555 |
bool skipfirst = false; |
| 556 |
tree arg; |
| 557 |
|
| 558 |
if (TREE_CODE (fun) == ADDR_EXPR) |
| 559 |
fun = TREE_OPERAND (fun, 0); |
| 560 |
|
| 561 |
/* In templates, where there is no way to tell whether a given |
| 562 |
call uses an actual member function. So the parser builds |
| 563 |
FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until |
| 564 |
instantiation time. */ |
| 565 |
if (TREE_CODE (fun) != FUNCTION_DECL) |
| 566 |
; |
| 567 |
else if (DECL_OBJECT_MEMBER_FUNCTION_P (fun)) |
| 568 |
{ |
| 569 |
tree object = (code == AGGR_INIT_EXPR |
| 570 |
? (AGGR_INIT_VIA_CTOR_P (t) |
| 571 |
? AGGR_INIT_EXPR_SLOT (t) |
| 572 |
: AGGR_INIT_EXPR_ARG (t, 0)) |
| 573 |
: CALL_EXPR_ARG (t, 0)); |
| 574 |
|
| 575 |
while (TREE_CODE (object) == NOP_EXPR) |
| 576 |
object = TREE_OPERAND (object, 0); |
| 577 |
|
| 578 |
if (TREE_CODE (object) == ADDR_EXPR) |
| 579 |
object = TREE_OPERAND (object, 0); |
| 580 |
|
| 581 |
if (!TYPE_PTR_P (TREE_TYPE (object))) |
| 582 |
{ |
| 583 |
postfix_expression (object); |
| 584 |
pp_cxx_dot (this); |
| 585 |
} |
| 586 |
else |
| 587 |
{ |
| 588 |
postfix_expression (object); |
| 589 |
pp_cxx_arrow (this); |
| 590 |
} |
| 591 |
skipfirst = true; |
| 592 |
enclosing_scope = strip_pointer_operator (TREE_TYPE (object)); |
| 593 |
} |
| 594 |
|
| 595 |
postfix_expression (fun); |
| 596 |
enclosing_scope = saved_scope; |
| 597 |
pp_cxx_left_paren (this); |
| 598 |
if (code == AGGR_INIT_EXPR) |
| 599 |
{ |
| 600 |
aggr_init_expr_arg_iterator iter; |
| 601 |
FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t) |
| 602 |
{ |
| 603 |
if (skipfirst) |
| 604 |
skipfirst = false; |
| 605 |
else |
| 606 |
{ |
| 607 |
expression (arg); |
| 608 |
if (more_aggr_init_expr_args_p (&iter)) |
| 609 |
pp_cxx_separate_with (this, ','); |
| 610 |
} |
| 611 |
} |
| 612 |
} |
| 613 |
else |
| 614 |
{ |
| 615 |
call_expr_arg_iterator iter; |
| 616 |
FOR_EACH_CALL_EXPR_ARG (arg, iter, t) |
| 617 |
{ |
| 618 |
if (skipfirst) |
| 619 |
skipfirst = false; |
| 620 |
else |
| 621 |
{ |
| 622 |
expression (arg); |
| 623 |
if (more_call_expr_args_p (&iter)) |
| 624 |
pp_cxx_separate_with (this, ','); |
| 625 |
} |
| 626 |
} |
| 627 |
} |
| 628 |
pp_cxx_right_paren (this); |
| 629 |
} |
| 630 |
if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t)) |
| 631 |
{ |
| 632 |
pp_cxx_separate_with (this, ','); |
| 633 |
postfix_expression (AGGR_INIT_EXPR_SLOT (t)); |
| 634 |
} |
| 635 |
break; |
| 636 |
|
| 637 |
case BASELINK: |
| 638 |
case VAR_DECL: |
| 639 |
case PARM_DECL: |
| 640 |
case FIELD_DECL: |
| 641 |
case FUNCTION_DECL: |
| 642 |
case OVERLOAD: |
| 643 |
case CONST_DECL: |
| 644 |
case TEMPLATE_DECL: |
| 645 |
case RESULT_DECL: |
| 646 |
primary_expression (t); |
| 647 |
break; |
| 648 |
|
| 649 |
case DYNAMIC_CAST_EXPR: |
| 650 |
case STATIC_CAST_EXPR: |
| 651 |
case REINTERPRET_CAST_EXPR: |
| 652 |
case CONST_CAST_EXPR: |
| 653 |
if (code == DYNAMIC_CAST_EXPR) |
| 654 |
pp_cxx_ws_string (this, "dynamic_cast"); |
| 655 |
else if (code == STATIC_CAST_EXPR) |
| 656 |
pp_cxx_ws_string (this, "static_cast"); |
| 657 |
else if (code == REINTERPRET_CAST_EXPR) |
| 658 |
pp_cxx_ws_string (this, "reinterpret_cast"); |
| 659 |
else |
| 660 |
pp_cxx_ws_string (this, "const_cast"); |
| 661 |
pp_cxx_begin_template_argument_list (this); |
| 662 |
type_id (TREE_TYPE (t)); |
| 663 |
pp_cxx_end_template_argument_list (this); |
| 664 |
pp_left_paren (this); |
| 665 |
expression (TREE_OPERAND (t, 0)); |
| 666 |
pp_right_paren (this); |
| 667 |
break; |
| 668 |
|
| 669 |
case BIT_CAST_EXPR: |
| 670 |
pp_cxx_ws_string (this, "__builtin_bit_cast"); |
| 671 |
pp_left_paren (this); |
| 672 |
type_id (TREE_TYPE (t)); |
| 673 |
pp_comma (this); |
| 674 |
expression (TREE_OPERAND (t, 0)); |
| 675 |
pp_right_paren (this); |
| 676 |
break; |
| 677 |
|
| 678 |
case EMPTY_CLASS_EXPR: |
| 679 |
type_id (TREE_TYPE (t)); |
| 680 |
pp_left_paren (this); |
| 681 |
pp_right_paren (this); |
| 682 |
break; |
| 683 |
|
| 684 |
case TYPEID_EXPR: |
| 685 |
pp_cxx_typeid_expression (this, t); |
| 686 |
break; |
| 687 |
|
| 688 |
case PSEUDO_DTOR_EXPR: |
| 689 |
postfix_expression (TREE_OPERAND (t, 0)); |
| 690 |
pp_cxx_dot (this); |
| 691 |
if (TREE_OPERAND (t, 1)) |
| 692 |
{ |
| 693 |
pp_cxx_qualified_id (this, TREE_OPERAND (t, 1)); |
| 694 |
pp_cxx_colon_colon (this); |
| 695 |
} |
| 696 |
pp_complement (this); |
| 697 |
pp_cxx_unqualified_id (this, TREE_OPERAND (t, 2)); |
| 698 |
break; |
| 699 |
|
| 700 |
case ARROW_EXPR: |
| 701 |
postfix_expression (TREE_OPERAND (t, 0)); |
| 702 |
pp_cxx_arrow (this); |
| 703 |
break; |
| 704 |
|
| 705 |
default: |
| 706 |
c_pretty_printer::postfix_expression (t); |
| 707 |
break; |
| 708 |
} |
| 709 |
} |
| 710 |
|
| 711 |
/* new-expression: |
| 712 |
::(opt) new new-placement(opt) new-type-id new-initializer(opt) |
| 713 |
::(opt) new new-placement(opt) ( type-id ) new-initializer(opt) |
| 714 |
|
| 715 |
new-placement: |
| 716 |
( expression-list ) |
| 717 |
|
| 718 |
new-type-id: |
| 719 |
type-specifier-seq new-declarator(opt) |
| 720 |
|
| 721 |
new-declarator: |
| 722 |
ptr-operator new-declarator(opt) |
| 723 |
direct-new-declarator |
| 724 |
|
| 725 |
direct-new-declarator |
| 726 |
[ expression ] |
| 727 |
direct-new-declarator [ constant-expression ] |
| 728 |
|
| 729 |
new-initializer: |
| 730 |
( expression-list(opt) ) */ |
| 731 |
|
| 732 |
static void |
| 733 |
pp_cxx_new_expression (cxx_pretty_printer *pp, tree t) |
| 734 |
{ |
| 735 |
enum tree_code code = TREE_CODE (t); |
| 736 |
tree type = TREE_OPERAND (t, 1); |
| 737 |
tree init = TREE_OPERAND (t, 2); |
| 738 |
switch (code) |
| 739 |
{ |
| 740 |
case NEW_EXPR: |
| 741 |
case VEC_NEW_EXPR: |
| 742 |
if (NEW_EXPR_USE_GLOBAL (t)) |
| 743 |
pp_cxx_colon_colon (pp); |
| 744 |
pp_cxx_ws_string (pp, "new"); |
| 745 |
if (TREE_OPERAND (t, 0)) |
| 746 |
{ |
| 747 |
pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0)); |
| 748 |
pp_space (pp); |
| 749 |
} |
| 750 |
if (TREE_CODE (type) == ARRAY_REF) |
| 751 |
type = build_cplus_array_type |
| 752 |
(TREE_OPERAND (type, 0), |
| 753 |
build_index_type (fold_build2_loc (input_location, |
| 754 |
MINUS_EXPR, integer_type_node, |
| 755 |
TREE_OPERAND (type, 1), |
| 756 |
integer_one_node))); |
| 757 |
pp->type_id (type); |
| 758 |
if (init) |
| 759 |
{ |
| 760 |
pp_left_paren (pp); |
| 761 |
if (TREE_CODE (init) == TREE_LIST) |
| 762 |
pp_c_expression_list (pp, init); |
| 763 |
else if (init == void_node) |
| 764 |
; /* OK, empty initializer list. */ |
| 765 |
else |
| 766 |
pp->expression (init); |
| 767 |
pp_right_paren (pp); |
| 768 |
} |
| 769 |
break; |
| 770 |
|
| 771 |
default: |
| 772 |
pp_unsupported_tree (pp, t); |
| 773 |
} |
| 774 |
} |
| 775 |
|
| 776 |
/* delete-expression: |
| 777 |
::(opt) delete cast-expression |
| 778 |
::(opt) delete [ ] cast-expression */ |
| 779 |
|
| 780 |
static void |
| 781 |
pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t) |
| 782 |
{ |
| 783 |
enum tree_code code = TREE_CODE (t); |
| 784 |
switch (code) |
| 785 |
{ |
| 786 |
case DELETE_EXPR: |
| 787 |
case VEC_DELETE_EXPR: |
| 788 |
if (DELETE_EXPR_USE_GLOBAL (t)) |
| 789 |
pp_cxx_colon_colon (pp); |
| 790 |
pp_cxx_ws_string (pp, "delete"); |
| 791 |
pp_space (pp); |
| 792 |
if (code == VEC_DELETE_EXPR |
| 793 |
|| DELETE_EXPR_USE_VEC (t)) |
| 794 |
{ |
| 795 |
pp_left_bracket (pp); |
| 796 |
pp_right_bracket (pp); |
| 797 |
pp_space (pp); |
| 798 |
} |
| 799 |
pp_c_cast_expression (pp, TREE_OPERAND (t, 0)); |
| 800 |
break; |
| 801 |
|
| 802 |
default: |
| 803 |
pp_unsupported_tree (pp, t); |
| 804 |
} |
| 805 |
} |
| 806 |
|
| 807 |
/* unary-expression: |
| 808 |
postfix-expression |
| 809 |
++ cast-expression |
| 810 |
-- cast-expression |
| 811 |
unary-operator cast-expression |
| 812 |
sizeof unary-expression |
| 813 |
sizeof ( type-id ) |
| 814 |
sizeof ... ( identifier ) |
| 815 |
new-expression |
| 816 |
delete-expression |
| 817 |
|
| 818 |
unary-operator: one of |
| 819 |
* & + - ! |
| 820 |
|
| 821 |
GNU extensions: |
| 822 |
__alignof__ unary-expression |
| 823 |
__alignof__ ( type-id ) */ |
| 824 |
|
| 825 |
void |
| 826 |
cxx_pretty_printer::unary_expression (tree t) |
| 827 |
{ |
| 828 |
enum tree_code code = TREE_CODE (t); |
| 829 |
switch (code) |
| 830 |
{ |
| 831 |
case NEW_EXPR: |
| 832 |
case VEC_NEW_EXPR: |
| 833 |
pp_cxx_new_expression (this, t); |
| 834 |
break; |
| 835 |
|
| 836 |
case DELETE_EXPR: |
| 837 |
case VEC_DELETE_EXPR: |
| 838 |
pp_cxx_delete_expression (this, t); |
| 839 |
break; |
| 840 |
|
| 841 |
case SIZEOF_EXPR: |
| 842 |
if (PACK_EXPANSION_P (TREE_OPERAND (t, 0))) |
| 843 |
{ |
| 844 |
pp_cxx_ws_string (this, "sizeof"); |
| 845 |
pp_cxx_ws_string (this, "..."); |
| 846 |
pp_cxx_whitespace (this); |
| 847 |
pp_cxx_left_paren (this); |
| 848 |
if (TYPE_P (TREE_OPERAND (t, 0))) |
| 849 |
type_id (TREE_OPERAND (t, 0)); |
| 850 |
else |
| 851 |
unary_expression (TREE_OPERAND (t, 0)); |
| 852 |
pp_cxx_right_paren (this); |
| 853 |
break; |
| 854 |
} |
| 855 |
/* Fall through */ |
| 856 |
|
| 857 |
case ALIGNOF_EXPR: |
| 858 |
if (code == SIZEOF_EXPR) |
| 859 |
pp_cxx_ws_string (this, "sizeof"); |
| 860 |
else if (ALIGNOF_EXPR_STD_P (t)) |
| 861 |
pp_cxx_ws_string (this, "alignof"); |
| 862 |
else |
| 863 |
pp_cxx_ws_string (this, "__alignof__"); |
| 864 |
pp_cxx_whitespace (this); |
| 865 |
if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t)) |
| 866 |
{ |
| 867 |
pp_cxx_left_paren (this); |
| 868 |
type_id (TREE_TYPE (TREE_OPERAND (t, 0))); |
| 869 |
pp_cxx_right_paren (this); |
| 870 |
} |
| 871 |
else if (TYPE_P (TREE_OPERAND (t, 0))) |
| 872 |
{ |
| 873 |
pp_cxx_left_paren (this); |
| 874 |
type_id (TREE_OPERAND (t, 0)); |
| 875 |
pp_cxx_right_paren (this); |
| 876 |
} |
| 877 |
else |
| 878 |
unary_expression (TREE_OPERAND (t, 0)); |
| 879 |
break; |
| 880 |
|
| 881 |
case AT_ENCODE_EXPR: |
| 882 |
pp_cxx_ws_string (this, "@encode"); |
| 883 |
pp_cxx_whitespace (this); |
| 884 |
pp_cxx_left_paren (this); |
| 885 |
type_id (TREE_OPERAND (t, 0)); |
| 886 |
pp_cxx_right_paren (this); |
| 887 |
break; |
| 888 |
|
| 889 |
case NOEXCEPT_EXPR: |
| 890 |
pp_cxx_ws_string (this, "noexcept"); |
| 891 |
pp_cxx_whitespace (this); |
| 892 |
pp_cxx_left_paren (this); |
| 893 |
expression (TREE_OPERAND (t, 0)); |
| 894 |
pp_cxx_right_paren (this); |
| 895 |
break; |
| 896 |
|
| 897 |
case UNARY_PLUS_EXPR: |
| 898 |
pp_plus (this); |
| 899 |
pp_cxx_cast_expression (this, TREE_OPERAND (t, 0)); |
| 900 |
break; |
| 901 |
|
| 902 |
default: |
| 903 |
c_pretty_printer::unary_expression (t); |
| 904 |
break; |
| 905 |
} |
| 906 |
} |
| 907 |
|
| 908 |
/* cast-expression: |
| 909 |
unary-expression |
| 910 |
( type-id ) cast-expression */ |
| 911 |
|
| 912 |
static void |
| 913 |
pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t) |
| 914 |
{ |
| 915 |
switch (TREE_CODE (t)) |
| 916 |
{ |
| 917 |
case CAST_EXPR: |
| 918 |
case IMPLICIT_CONV_EXPR: |
| 919 |
pp->type_id (TREE_TYPE (t)); |
| 920 |
pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0)); |
| 921 |
break; |
| 922 |
|
| 923 |
default: |
| 924 |
pp_c_cast_expression (pp, t); |
| 925 |
break; |
| 926 |
} |
| 927 |
} |
| 928 |
|
| 929 |
/* pm-expression: |
| 930 |
cast-expression |
| 931 |
pm-expression .* cast-expression |
| 932 |
pm-expression ->* cast-expression */ |
| 933 |
|
| 934 |
static void |
| 935 |
pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t) |
| 936 |
{ |
| 937 |
switch (TREE_CODE (t)) |
| 938 |
{ |
| 939 |
/* Handle unfortunate OFFSET_REF overloading here. */ |
| 940 |
case OFFSET_REF: |
| 941 |
if (TYPE_P (TREE_OPERAND (t, 0))) |
| 942 |
{ |
| 943 |
pp_cxx_qualified_id (pp, t); |
| 944 |
break; |
| 945 |
} |
| 946 |
/* Fall through. */ |
| 947 |
case MEMBER_REF: |
| 948 |
case DOTSTAR_EXPR: |
| 949 |
pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0)); |
| 950 |
if (TREE_CODE (t) == MEMBER_REF) |
| 951 |
pp_cxx_arrow (pp); |
| 952 |
else |
| 953 |
pp_cxx_dot (pp); |
| 954 |
pp_star(pp); |
| 955 |
pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1)); |
| 956 |
break; |
| 957 |
|
| 958 |
|
| 959 |
default: |
| 960 |
pp_cxx_cast_expression (pp, t); |
| 961 |
break; |
| 962 |
} |
| 963 |
} |
| 964 |
|
| 965 |
/* multiplicative-expression: |
| 966 |
pm-expression |
| 967 |
multiplicative-expression * pm-expression |
| 968 |
multiplicative-expression / pm-expression |
| 969 |
multiplicative-expression % pm-expression */ |
| 970 |
|
| 971 |
void |
| 972 |
cxx_pretty_printer::multiplicative_expression (tree e) |
| 973 |
{ |
| 974 |
enum tree_code code = TREE_CODE (e); |
| 975 |
switch (code) |
| 976 |
{ |
| 977 |
case MULT_EXPR: |
| 978 |
case TRUNC_DIV_EXPR: |
| 979 |
case TRUNC_MOD_EXPR: |
| 980 |
case EXACT_DIV_EXPR: |
| 981 |
case RDIV_EXPR: |
| 982 |
multiplicative_expression (TREE_OPERAND (e, 0)); |
| 983 |
pp_space (this); |
| 984 |
if (code == MULT_EXPR) |
| 985 |
pp_star (this); |
| 986 |
else if (code != TRUNC_MOD_EXPR) |
| 987 |
pp_slash (this); |
| 988 |
else |
| 989 |
pp_modulo (this); |
| 990 |
pp_space (this); |
| 991 |
pp_cxx_pm_expression (this, TREE_OPERAND (e, 1)); |
| 992 |
break; |
| 993 |
|
| 994 |
default: |
| 995 |
pp_cxx_pm_expression (this, e); |
| 996 |
break; |
| 997 |
} |
| 998 |
} |
| 999 |
|
| 1000 |
/* conditional-expression: |
| 1001 |
logical-or-expression |
| 1002 |
logical-or-expression ? expression : assignment-expression */ |
| 1003 |
|
| 1004 |
void |
| 1005 |
cxx_pretty_printer::conditional_expression (tree e) |
| 1006 |
{ |
| 1007 |
if (TREE_CODE (e) == COND_EXPR) |
| 1008 |
{ |
| 1009 |
pp_c_logical_or_expression (this, TREE_OPERAND (e, 0)); |
| 1010 |
pp_space (this); |
| 1011 |
pp_question (this); |
| 1012 |
pp_space (this); |
| 1013 |
expression (TREE_OPERAND (e, 1)); |
| 1014 |
pp_space (this); |
| 1015 |
assignment_expression (TREE_OPERAND (e, 2)); |
| 1016 |
} |
| 1017 |
else |
| 1018 |
pp_c_logical_or_expression (this, e); |
| 1019 |
} |
| 1020 |
|
| 1021 |
/* Pretty-print a compound assignment operator token as indicated by T. */ |
| 1022 |
|
| 1023 |
static void |
| 1024 |
pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t) |
| 1025 |
{ |
| 1026 |
const char *op; |
| 1027 |
|
| 1028 |
switch (TREE_CODE (t)) |
| 1029 |
{ |
| 1030 |
case NOP_EXPR: |
| 1031 |
op = "="; |
| 1032 |
break; |
| 1033 |
|
| 1034 |
case PLUS_EXPR: |
| 1035 |
op = "+="; |
| 1036 |
break; |
| 1037 |
|
| 1038 |
case MINUS_EXPR: |
| 1039 |
op = "-="; |
| 1040 |
break; |
| 1041 |
|
| 1042 |
case TRUNC_DIV_EXPR: |
| 1043 |
op = "/="; |
| 1044 |
break; |
| 1045 |
|
| 1046 |
case TRUNC_MOD_EXPR: |
| 1047 |
op = "%="; |
| 1048 |
break; |
| 1049 |
|
| 1050 |
default: |
| 1051 |
op = get_tree_code_name (TREE_CODE (t)); |
| 1052 |
break; |
| 1053 |
} |
| 1054 |
|
| 1055 |
pp_cxx_ws_string (pp, op); |
| 1056 |
} |
| 1057 |
|
| 1058 |
|
| 1059 |
/* assignment-expression: |
| 1060 |
conditional-expression |
| 1061 |
logical-or-expression assignment-operator assignment-expression |
| 1062 |
throw-expression |
| 1063 |
|
| 1064 |
throw-expression: |
| 1065 |
throw assignment-expression(opt) |
| 1066 |
|
| 1067 |
assignment-operator: one of |
| 1068 |
= *= /= %= += -= >>= <<= &= ^= |= */ |
| 1069 |
|
| 1070 |
void |
| 1071 |
cxx_pretty_printer::assignment_expression (tree e) |
| 1072 |
{ |
| 1073 |
switch (TREE_CODE (e)) |
| 1074 |
{ |
| 1075 |
case MODIFY_EXPR: |
| 1076 |
case INIT_EXPR: |
| 1077 |
pp_c_logical_or_expression (this, TREE_OPERAND (e, 0)); |
| 1078 |
pp_space (this); |
| 1079 |
pp_equal (this); |
| 1080 |
pp_space (this); |
| 1081 |
assignment_expression (TREE_OPERAND (e, 1)); |
| 1082 |
break; |
| 1083 |
|
| 1084 |
case THROW_EXPR: |
| 1085 |
pp_cxx_ws_string (this, "throw"); |
| 1086 |
if (TREE_OPERAND (e, 0)) |
| 1087 |
assignment_expression (TREE_OPERAND (e, 0)); |
| 1088 |
break; |
| 1089 |
|
| 1090 |
case MODOP_EXPR: |
| 1091 |
pp_c_logical_or_expression (this, TREE_OPERAND (e, 0)); |
| 1092 |
pp_cxx_assignment_operator (this, TREE_OPERAND (e, 1)); |
| 1093 |
assignment_expression (TREE_OPERAND (e, 2)); |
| 1094 |
break; |
| 1095 |
|
| 1096 |
default: |
| 1097 |
conditional_expression (e); |
| 1098 |
break; |
| 1099 |
} |
| 1100 |
} |
| 1101 |
|
| 1102 |
void |
| 1103 |
cxx_pretty_printer::expression (tree t) |
| 1104 |
{ |
| 1105 |
switch (TREE_CODE (t)) |
| 1106 |
{ |
| 1107 |
case STRING_CST: |
| 1108 |
case VOID_CST: |
| 1109 |
case INTEGER_CST: |
| 1110 |
case REAL_CST: |
| 1111 |
case COMPLEX_CST: |
| 1112 |
constant (t); |
| 1113 |
break; |
| 1114 |
|
| 1115 |
case USERDEF_LITERAL: |
| 1116 |
pp_cxx_userdef_literal (this, t); |
| 1117 |
break; |
| 1118 |
|
| 1119 |
case RESULT_DECL: |
| 1120 |
pp_cxx_unqualified_id (this, t); |
| 1121 |
break; |
| 1122 |
|
| 1123 |
#if 0 |
| 1124 |
case OFFSET_REF: |
| 1125 |
#endif |
| 1126 |
case SCOPE_REF: |
| 1127 |
case PTRMEM_CST: |
| 1128 |
pp_cxx_qualified_id (this, t); |
| 1129 |
break; |
| 1130 |
|
| 1131 |
case OVERLOAD: |
| 1132 |
t = OVL_FIRST (t); |
| 1133 |
/* FALLTHRU */ |
| 1134 |
case VAR_DECL: |
| 1135 |
if (DECL_NTTP_OBJECT_P (t)) |
| 1136 |
{ |
| 1137 |
/* Print the type followed by the CONSTRUCTOR value of the |
| 1138 |
NTTP object. */ |
| 1139 |
simple_type_specifier (cv_unqualified (TREE_TYPE (t))); |
| 1140 |
expression (DECL_INITIAL (t)); |
| 1141 |
break; |
| 1142 |
} |
| 1143 |
/* FALLTHRU */ |
| 1144 |
case PARM_DECL: |
| 1145 |
case FIELD_DECL: |
| 1146 |
case CONST_DECL: |
| 1147 |
case FUNCTION_DECL: |
| 1148 |
case BASELINK: |
| 1149 |
case TEMPLATE_DECL: |
| 1150 |
case TEMPLATE_TYPE_PARM: |
| 1151 |
case TEMPLATE_PARM_INDEX: |
| 1152 |
case TEMPLATE_TEMPLATE_PARM: |
| 1153 |
case STMT_EXPR: |
| 1154 |
case REQUIRES_EXPR: |
| 1155 |
primary_expression (t); |
| 1156 |
break; |
| 1157 |
|
| 1158 |
case CALL_EXPR: |
| 1159 |
case DYNAMIC_CAST_EXPR: |
| 1160 |
case STATIC_CAST_EXPR: |
| 1161 |
case REINTERPRET_CAST_EXPR: |
| 1162 |
case CONST_CAST_EXPR: |
| 1163 |
#if 0 |
| 1164 |
case MEMBER_REF: |
| 1165 |
#endif |
| 1166 |
case EMPTY_CLASS_EXPR: |
| 1167 |
case TYPEID_EXPR: |
| 1168 |
case PSEUDO_DTOR_EXPR: |
| 1169 |
case AGGR_INIT_EXPR: |
| 1170 |
case ARROW_EXPR: |
| 1171 |
postfix_expression (t); |
| 1172 |
break; |
| 1173 |
|
| 1174 |
case NEW_EXPR: |
| 1175 |
case VEC_NEW_EXPR: |
| 1176 |
pp_cxx_new_expression (this, t); |
| 1177 |
break; |
| 1178 |
|
| 1179 |
case DELETE_EXPR: |
| 1180 |
case VEC_DELETE_EXPR: |
| 1181 |
pp_cxx_delete_expression (this, t); |
| 1182 |
break; |
| 1183 |
|
| 1184 |
case SIZEOF_EXPR: |
| 1185 |
case ALIGNOF_EXPR: |
| 1186 |
case NOEXCEPT_EXPR: |
| 1187 |
case UNARY_PLUS_EXPR: |
| 1188 |
unary_expression (t); |
| 1189 |
break; |
| 1190 |
|
| 1191 |
case CAST_EXPR: |
| 1192 |
case IMPLICIT_CONV_EXPR: |
| 1193 |
pp_cxx_cast_expression (this, t); |
| 1194 |
break; |
| 1195 |
|
| 1196 |
case OFFSET_REF: |
| 1197 |
case MEMBER_REF: |
| 1198 |
case DOTSTAR_EXPR: |
| 1199 |
pp_cxx_pm_expression (this, t); |
| 1200 |
break; |
| 1201 |
|
| 1202 |
case MULT_EXPR: |
| 1203 |
case TRUNC_DIV_EXPR: |
| 1204 |
case TRUNC_MOD_EXPR: |
| 1205 |
case EXACT_DIV_EXPR: |
| 1206 |
case RDIV_EXPR: |
| 1207 |
multiplicative_expression (t); |
| 1208 |
break; |
| 1209 |
|
| 1210 |
case COND_EXPR: |
| 1211 |
conditional_expression (t); |
| 1212 |
break; |
| 1213 |
|
| 1214 |
case MODIFY_EXPR: |
| 1215 |
case INIT_EXPR: |
| 1216 |
case THROW_EXPR: |
| 1217 |
case MODOP_EXPR: |
| 1218 |
assignment_expression (t); |
| 1219 |
break; |
| 1220 |
|
| 1221 |
case MUST_NOT_THROW_EXPR: |
| 1222 |
expression (TREE_OPERAND (t, 0)); |
| 1223 |
break; |
| 1224 |
|
| 1225 |
case EXPR_PACK_EXPANSION: |
| 1226 |
expression (PACK_EXPANSION_PATTERN (t)); |
| 1227 |
pp_cxx_ws_string (this, "..."); |
| 1228 |
break; |
| 1229 |
|
| 1230 |
case PACK_INDEX_EXPR: |
| 1231 |
expression (PACK_INDEX_PACK (t)); |
| 1232 |
pp_cxx_left_bracket (this); |
| 1233 |
expression (PACK_INDEX_INDEX (t)); |
| 1234 |
pp_cxx_right_bracket (this); |
| 1235 |
break; |
| 1236 |
|
| 1237 |
case UNARY_LEFT_FOLD_EXPR: |
| 1238 |
pp_cxx_unary_left_fold_expression (this, t); |
| 1239 |
break; |
| 1240 |
|
| 1241 |
case UNARY_RIGHT_FOLD_EXPR: |
| 1242 |
pp_cxx_unary_right_fold_expression (this, t); |
| 1243 |
break; |
| 1244 |
|
| 1245 |
case BINARY_LEFT_FOLD_EXPR: |
| 1246 |
case BINARY_RIGHT_FOLD_EXPR: |
| 1247 |
pp_cxx_binary_fold_expression (this, t); |
| 1248 |
break; |
| 1249 |
|
| 1250 |
case TEMPLATE_ID_EXPR: |
| 1251 |
pp_cxx_template_id (this, t); |
| 1252 |
break; |
| 1253 |
|
| 1254 |
case NONTYPE_ARGUMENT_PACK: |
| 1255 |
{ |
| 1256 |
tree args = ARGUMENT_PACK_ARGS (t); |
| 1257 |
int i, len = TREE_VEC_LENGTH (args); |
| 1258 |
pp_cxx_left_brace (this); |
| 1259 |
for (i = 0; i < len; ++i) |
| 1260 |
{ |
| 1261 |
if (i > 0) |
| 1262 |
pp_cxx_separate_with (this, ','); |
| 1263 |
expression (TREE_VEC_ELT (args, i)); |
| 1264 |
} |
| 1265 |
pp_cxx_right_brace (this); |
| 1266 |
} |
| 1267 |
break; |
| 1268 |
|
| 1269 |
case LAMBDA_EXPR: |
| 1270 |
pp_cxx_ws_string (this, "<lambda>"); |
| 1271 |
break; |
| 1272 |
|
| 1273 |
case TRAIT_EXPR: |
| 1274 |
pp_cxx_trait (this, t); |
| 1275 |
break; |
| 1276 |
|
| 1277 |
case ATOMIC_CONSTR: |
| 1278 |
case CONJ_CONSTR: |
| 1279 |
case DISJ_CONSTR: |
| 1280 |
pp_cxx_constraint (this, t); |
| 1281 |
break; |
| 1282 |
|
| 1283 |
case PAREN_EXPR: |
| 1284 |
pp_cxx_left_paren (this); |
| 1285 |
expression (TREE_OPERAND (t, 0)); |
| 1286 |
pp_cxx_right_paren (this); |
| 1287 |
break; |
| 1288 |
|
| 1289 |
case VIEW_CONVERT_EXPR: |
| 1290 |
if (TREE_CODE (TREE_OPERAND (t, 0)) == TEMPLATE_PARM_INDEX) |
| 1291 |
{ |
| 1292 |
/* Strip const VIEW_CONVERT_EXPR wrappers for class NTTPs. */ |
| 1293 |
expression (TREE_OPERAND (t, 0)); |
| 1294 |
break; |
| 1295 |
} |
| 1296 |
/* FALLTHRU */ |
| 1297 |
default: |
| 1298 |
c_pretty_printer::expression (t); |
| 1299 |
break; |
| 1300 |
} |
| 1301 |
} |
| 1302 |
|
| 1303 |
|
| 1304 |
/* Declarations. */ |
| 1305 |
|
| 1306 |
/* function-specifier: |
| 1307 |
inline |
| 1308 |
virtual |
| 1309 |
explicit */ |
| 1310 |
|
| 1311 |
void |
| 1312 |
cxx_pretty_printer::function_specifier (tree t) |
| 1313 |
{ |
| 1314 |
switch (TREE_CODE (t)) |
| 1315 |
{ |
| 1316 |
case FUNCTION_DECL: |
| 1317 |
if (DECL_VIRTUAL_P (t)) |
| 1318 |
pp_cxx_ws_string (this, "virtual"); |
| 1319 |
else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t)) |
| 1320 |
pp_cxx_ws_string (this, "explicit"); |
| 1321 |
else |
| 1322 |
c_pretty_printer::function_specifier (t); |
| 1323 |
|
| 1324 |
default: |
| 1325 |
break; |
| 1326 |
} |
| 1327 |
} |
| 1328 |
|
| 1329 |
/* decl-specifier-seq: |
| 1330 |
decl-specifier-seq(opt) decl-specifier |
| 1331 |
|
| 1332 |
decl-specifier: |
| 1333 |
storage-class-specifier |
| 1334 |
type-specifier |
| 1335 |
function-specifier |
| 1336 |
friend |
| 1337 |
typedef */ |
| 1338 |
|
| 1339 |
void |
| 1340 |
cxx_pretty_printer::declaration_specifiers (tree t) |
| 1341 |
{ |
| 1342 |
switch (TREE_CODE (t)) |
| 1343 |
{ |
| 1344 |
case VAR_DECL: |
| 1345 |
case PARM_DECL: |
| 1346 |
case CONST_DECL: |
| 1347 |
case FIELD_DECL: |
| 1348 |
storage_class_specifier (t); |
| 1349 |
declaration_specifiers (TREE_TYPE (t)); |
| 1350 |
break; |
| 1351 |
|
| 1352 |
case TYPE_DECL: |
| 1353 |
pp_cxx_ws_string (this, "typedef"); |
| 1354 |
declaration_specifiers (TREE_TYPE (t)); |
| 1355 |
break; |
| 1356 |
|
| 1357 |
case FUNCTION_DECL: |
| 1358 |
/* Constructors don't have return types. And conversion functions |
| 1359 |
do not have a type-specifier in their return types. */ |
| 1360 |
if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t)) |
| 1361 |
function_specifier (t); |
| 1362 |
else if (DECL_IOBJ_MEMBER_FUNCTION_P (t)) |
| 1363 |
declaration_specifiers (TREE_TYPE (TREE_TYPE (t))); |
| 1364 |
else |
| 1365 |
c_pretty_printer::declaration_specifiers (t); |
| 1366 |
break; |
| 1367 |
default: |
| 1368 |
c_pretty_printer::declaration_specifiers (t); |
| 1369 |
break; |
| 1370 |
} |
| 1371 |
} |
| 1372 |
|
| 1373 |
/* simple-type-specifier: |
| 1374 |
::(opt) nested-name-specifier(opt) type-name |
| 1375 |
::(opt) nested-name-specifier(opt) template(opt) template-id |
| 1376 |
decltype-specifier |
| 1377 |
char |
| 1378 |
wchar_t |
| 1379 |
bool |
| 1380 |
short |
| 1381 |
int |
| 1382 |
long |
| 1383 |
signed |
| 1384 |
unsigned |
| 1385 |
float |
| 1386 |
double |
| 1387 |
void */ |
| 1388 |
|
| 1389 |
void |
| 1390 |
cxx_pretty_printer::simple_type_specifier (tree t) |
| 1391 |
{ |
| 1392 |
switch (TREE_CODE (t)) |
| 1393 |
{ |
| 1394 |
case RECORD_TYPE: |
| 1395 |
case UNION_TYPE: |
| 1396 |
case ENUMERAL_TYPE: |
| 1397 |
pp_cxx_qualified_id (this, t); |
| 1398 |
break; |
| 1399 |
|
| 1400 |
case TEMPLATE_TYPE_PARM: |
| 1401 |
case TEMPLATE_TEMPLATE_PARM: |
| 1402 |
case TEMPLATE_PARM_INDEX: |
| 1403 |
case BOUND_TEMPLATE_TEMPLATE_PARM: |
| 1404 |
pp_cxx_unqualified_id (this, t); |
| 1405 |
if (TREE_CODE (t) == TEMPLATE_TYPE_PARM) |
| 1406 |
if (tree c = PLACEHOLDER_TYPE_CONSTRAINTS (t)) |
| 1407 |
pp_cxx_constrained_type_spec (this, c); |
| 1408 |
break; |
| 1409 |
|
| 1410 |
case TYPENAME_TYPE: |
| 1411 |
pp_cxx_ws_string (this, "typename"); |
| 1412 |
pp_cxx_nested_name_specifier (this, TYPE_CONTEXT (t)); |
| 1413 |
pp_cxx_unqualified_id (this, TYPENAME_TYPE_FULLNAME (t)); |
| 1414 |
break; |
| 1415 |
|
| 1416 |
case DECLTYPE_TYPE: |
| 1417 |
pp_cxx_ws_string (this, "decltype"); |
| 1418 |
pp_cxx_left_paren (this); |
| 1419 |
this->expression (DECLTYPE_TYPE_EXPR (t)); |
| 1420 |
pp_cxx_right_paren (this); |
| 1421 |
break; |
| 1422 |
|
| 1423 |
case NULLPTR_TYPE: |
| 1424 |
pp_cxx_ws_string (this, "std::nullptr_t"); |
| 1425 |
break; |
| 1426 |
|
| 1427 |
case TRAIT_TYPE: |
| 1428 |
pp_cxx_trait (this, t); |
| 1429 |
break; |
| 1430 |
|
| 1431 |
default: |
| 1432 |
c_pretty_printer::simple_type_specifier (t); |
| 1433 |
break; |
| 1434 |
} |
| 1435 |
} |
| 1436 |
|
| 1437 |
/* type-specifier-seq: |
| 1438 |
type-specifier type-specifier-seq(opt) |
| 1439 |
|
| 1440 |
type-specifier: |
| 1441 |
simple-type-specifier |
| 1442 |
class-specifier |
| 1443 |
enum-specifier |
| 1444 |
elaborated-type-specifier |
| 1445 |
cv-qualifier */ |
| 1446 |
|
| 1447 |
static void |
| 1448 |
pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t) |
| 1449 |
{ |
| 1450 |
switch (TREE_CODE (t)) |
| 1451 |
{ |
| 1452 |
case TEMPLATE_DECL: |
| 1453 |
case TEMPLATE_TYPE_PARM: |
| 1454 |
case TEMPLATE_TEMPLATE_PARM: |
| 1455 |
case TYPE_DECL: |
| 1456 |
case BOUND_TEMPLATE_TEMPLATE_PARM: |
| 1457 |
case DECLTYPE_TYPE: |
| 1458 |
case NULLPTR_TYPE: |
| 1459 |
pp_cxx_cv_qualifier_seq (pp, t); |
| 1460 |
pp->simple_type_specifier (t); |
| 1461 |
break; |
| 1462 |
|
| 1463 |
case METHOD_TYPE: |
| 1464 |
pp_cxx_type_specifier_seq (pp, TREE_TYPE (t)); |
| 1465 |
pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t)); |
| 1466 |
pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t)); |
| 1467 |
break; |
| 1468 |
|
| 1469 |
case RECORD_TYPE: |
| 1470 |
if (TYPE_PTRMEMFUNC_P (t)) |
| 1471 |
{ |
| 1472 |
tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t); |
| 1473 |
pp->declaration_specifiers (TREE_TYPE (TREE_TYPE (pfm))); |
| 1474 |
pp_cxx_whitespace (pp); |
| 1475 |
pp_cxx_ptr_operator (pp, t); |
| 1476 |
break; |
| 1477 |
} |
| 1478 |
/* fall through */ |
| 1479 |
|
| 1480 |
case OFFSET_TYPE: |
| 1481 |
if (TYPE_PTRDATAMEM_P (t)) |
| 1482 |
{ |
| 1483 |
pp_cxx_type_specifier_seq (pp, TREE_TYPE (t)); |
| 1484 |
pp_cxx_whitespace (pp); |
| 1485 |
pp_cxx_ptr_operator (pp, t); |
| 1486 |
break; |
| 1487 |
} |
| 1488 |
/* fall through */ |
| 1489 |
|
| 1490 |
default: |
| 1491 |
if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t))) |
| 1492 |
pp_c_specifier_qualifier_list (pp, t); |
| 1493 |
} |
| 1494 |
} |
| 1495 |
|
| 1496 |
/* ptr-operator: |
| 1497 |
* cv-qualifier-seq(opt) |
| 1498 |
& |
| 1499 |
::(opt) nested-name-specifier * cv-qualifier-seq(opt) */ |
| 1500 |
|
| 1501 |
static void |
| 1502 |
pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t) |
| 1503 |
{ |
| 1504 |
if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL) |
| 1505 |
t = TREE_TYPE (t); |
| 1506 |
switch (TREE_CODE (t)) |
| 1507 |
{ |
| 1508 |
case REFERENCE_TYPE: |
| 1509 |
case POINTER_TYPE: |
| 1510 |
if (TYPE_PTR_OR_PTRMEM_P (TREE_TYPE (t))) |
| 1511 |
pp_cxx_ptr_operator (pp, TREE_TYPE (t)); |
| 1512 |
pp_c_attributes_display (pp, TYPE_ATTRIBUTES (TREE_TYPE (t))); |
| 1513 |
if (TYPE_PTR_P (t)) |
| 1514 |
{ |
| 1515 |
pp_star (pp); |
| 1516 |
pp_cxx_cv_qualifier_seq (pp, t); |
| 1517 |
} |
| 1518 |
else |
| 1519 |
pp_ampersand (pp); |
| 1520 |
break; |
| 1521 |
|
| 1522 |
case RECORD_TYPE: |
| 1523 |
if (TYPE_PTRMEMFUNC_P (t)) |
| 1524 |
{ |
| 1525 |
pp_cxx_left_paren (pp); |
| 1526 |
pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t)); |
| 1527 |
pp_star (pp); |
| 1528 |
break; |
| 1529 |
} |
| 1530 |
/* FALLTHRU */ |
| 1531 |
case OFFSET_TYPE: |
| 1532 |
if (TYPE_PTRMEM_P (t)) |
| 1533 |
{ |
| 1534 |
if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) |
| 1535 |
pp_cxx_left_paren (pp); |
| 1536 |
pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t)); |
| 1537 |
pp_star (pp); |
| 1538 |
pp_cxx_cv_qualifier_seq (pp, t); |
| 1539 |
break; |
| 1540 |
} |
| 1541 |
/* fall through. */ |
| 1542 |
|
| 1543 |
default: |
| 1544 |
pp_unsupported_tree (pp, t); |
| 1545 |
break; |
| 1546 |
} |
| 1547 |
} |
| 1548 |
|
| 1549 |
static inline tree |
| 1550 |
pp_cxx_implicit_parameter_type (tree mf) |
| 1551 |
{ |
| 1552 |
return class_of_this_parm (TREE_TYPE (mf)); |
| 1553 |
} |
| 1554 |
|
| 1555 |
/* |
| 1556 |
parameter-declaration: |
| 1557 |
decl-specifier-seq declarator |
| 1558 |
decl-specifier-seq declarator = assignment-expression |
| 1559 |
decl-specifier-seq abstract-declarator(opt) |
| 1560 |
decl-specifier-seq abstract-declarator(opt) assignment-expression */ |
| 1561 |
|
| 1562 |
static inline void |
| 1563 |
pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t) |
| 1564 |
{ |
| 1565 |
pp->declaration_specifiers (t); |
| 1566 |
if (TYPE_P (t)) |
| 1567 |
pp->abstract_declarator (t); |
| 1568 |
else |
| 1569 |
pp->declarator (t); |
| 1570 |
} |
| 1571 |
|
| 1572 |
/* parameter-declaration-clause: |
| 1573 |
parameter-declaration-list(opt) ...(opt) |
| 1574 |
parameter-declaration-list , ... |
| 1575 |
|
| 1576 |
parameter-declaration-list: |
| 1577 |
parameter-declaration |
| 1578 |
parameter-declaration-list , parameter-declaration */ |
| 1579 |
|
| 1580 |
static void |
| 1581 |
pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t) |
| 1582 |
{ |
| 1583 |
gcc_assert (FUNC_OR_METHOD_TYPE_P (t) || TREE_CODE (t) == FUNCTION_DECL); |
| 1584 |
tree types, args; |
| 1585 |
if (TYPE_P (t)) |
| 1586 |
{ |
| 1587 |
types = TYPE_ARG_TYPES (t); |
| 1588 |
args = NULL_TREE; |
| 1589 |
} |
| 1590 |
else |
| 1591 |
{ |
| 1592 |
types = FUNCTION_FIRST_USER_PARMTYPE (t); |
| 1593 |
args = FUNCTION_FIRST_USER_PARM (t); |
| 1594 |
} |
| 1595 |
bool abstract = !args || (pp->flags & pp_c_flag_abstract); |
| 1596 |
|
| 1597 |
/* Skip artificial parameter for non-static member functions. */ |
| 1598 |
if (TREE_CODE (t) == METHOD_TYPE) |
| 1599 |
types = TREE_CHAIN (types); |
| 1600 |
|
| 1601 |
bool first = true; |
| 1602 |
pp_cxx_left_paren (pp); |
| 1603 |
for (; types != void_list_node; types = TREE_CHAIN (types)) |
| 1604 |
{ |
| 1605 |
if (!first) |
| 1606 |
pp_cxx_separate_with (pp, ','); |
| 1607 |
first = false; |
| 1608 |
if (!types) |
| 1609 |
{ |
| 1610 |
pp_cxx_ws_string (pp, "..."); |
| 1611 |
break; |
| 1612 |
} |
| 1613 |
pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args); |
| 1614 |
if (!abstract && pp->flags & pp_cxx_flag_default_argument) |
| 1615 |
{ |
| 1616 |
pp_cxx_whitespace (pp); |
| 1617 |
pp_equal (pp); |
| 1618 |
pp_cxx_whitespace (pp); |
| 1619 |
pp->assignment_expression (TREE_PURPOSE (types)); |
| 1620 |
} |
| 1621 |
if (!abstract) |
| 1622 |
args = TREE_CHAIN (args); |
| 1623 |
} |
| 1624 |
pp_cxx_right_paren (pp); |
| 1625 |
} |
| 1626 |
|
| 1627 |
/* exception-specification: |
| 1628 |
throw ( type-id-list(opt) ) |
| 1629 |
|
| 1630 |
type-id-list |
| 1631 |
type-id |
| 1632 |
type-id-list , type-id */ |
| 1633 |
|
| 1634 |
static void |
| 1635 |
pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t) |
| 1636 |
{ |
| 1637 |
tree ex_spec = TYPE_RAISES_EXCEPTIONS (t); |
| 1638 |
bool need_comma = false; |
| 1639 |
|
| 1640 |
if (ex_spec == NULL) |
| 1641 |
return; |
| 1642 |
if (TREE_PURPOSE (ex_spec)) |
| 1643 |
{ |
| 1644 |
pp_cxx_ws_string (pp, "noexcept"); |
| 1645 |
pp_cxx_whitespace (pp); |
| 1646 |
pp_cxx_left_paren (pp); |
| 1647 |
if (DEFERRED_NOEXCEPT_SPEC_P (ex_spec)) |
| 1648 |
pp_cxx_ws_string (pp, "<uninstantiated>"); |
| 1649 |
else |
| 1650 |
pp->expression (TREE_PURPOSE (ex_spec)); |
| 1651 |
pp_cxx_right_paren (pp); |
| 1652 |
return; |
| 1653 |
} |
| 1654 |
pp_cxx_ws_string (pp, "throw"); |
| 1655 |
pp_cxx_left_paren (pp); |
| 1656 |
for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec)) |
| 1657 |
{ |
| 1658 |
tree type = TREE_VALUE (ex_spec); |
| 1659 |
tree argpack = NULL_TREE; |
| 1660 |
int i, len = 1; |
| 1661 |
|
| 1662 |
if (ARGUMENT_PACK_P (type)) |
| 1663 |
{ |
| 1664 |
argpack = ARGUMENT_PACK_ARGS (type); |
| 1665 |
len = TREE_VEC_LENGTH (argpack); |
| 1666 |
} |
| 1667 |
|
| 1668 |
for (i = 0; i < len; ++i) |
| 1669 |
{ |
| 1670 |
if (argpack) |
| 1671 |
type = TREE_VEC_ELT (argpack, i); |
| 1672 |
|
| 1673 |
if (need_comma) |
| 1674 |
pp_cxx_separate_with (pp, ','); |
| 1675 |
else |
| 1676 |
need_comma = true; |
| 1677 |
|
| 1678 |
pp->type_id (type); |
| 1679 |
} |
| 1680 |
} |
| 1681 |
pp_cxx_right_paren (pp); |
| 1682 |
} |
| 1683 |
|
| 1684 |
/* direct-declarator: |
| 1685 |
declarator-id |
| 1686 |
direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt) |
| 1687 |
exception-specification(opt) |
| 1688 |
direct-declaration [ constant-expression(opt) ] |
| 1689 |
( declarator ) */ |
| 1690 |
|
| 1691 |
void |
| 1692 |
cxx_pretty_printer::direct_declarator (tree t) |
| 1693 |
{ |
| 1694 |
switch (TREE_CODE (t)) |
| 1695 |
{ |
| 1696 |
case VAR_DECL: |
| 1697 |
case PARM_DECL: |
| 1698 |
case CONST_DECL: |
| 1699 |
case FIELD_DECL: |
| 1700 |
if (DECL_NAME (t)) |
| 1701 |
{ |
| 1702 |
pp_cxx_space_for_pointer_operator (this, TREE_TYPE (t)); |
| 1703 |
|
| 1704 |
if ((TREE_CODE (t) == PARM_DECL && DECL_PACK_P (t)) |
| 1705 |
|| template_parameter_pack_p (t)) |
| 1706 |
/* A function parameter pack or non-type template |
| 1707 |
parameter pack. */ |
| 1708 |
pp_cxx_ws_string (this, "..."); |
| 1709 |
|
| 1710 |
id_expression (DECL_NAME (t)); |
| 1711 |
} |
| 1712 |
abstract_declarator (TREE_TYPE (t)); |
| 1713 |
break; |
| 1714 |
|
| 1715 |
case FUNCTION_DECL: |
| 1716 |
pp_cxx_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t))); |
| 1717 |
expression (t); |
| 1718 |
pp_cxx_parameter_declaration_clause (this, t); |
| 1719 |
|
| 1720 |
if (DECL_IOBJ_MEMBER_FUNCTION_P (t)) |
| 1721 |
{ |
| 1722 |
set_padding (pp_before); |
| 1723 |
pp_cxx_cv_qualifier_seq (this, pp_cxx_implicit_parameter_type (t)); |
| 1724 |
} |
| 1725 |
|
| 1726 |
pp_cxx_exception_specification (this, TREE_TYPE (t)); |
| 1727 |
break; |
| 1728 |
|
| 1729 |
case TYPENAME_TYPE: |
| 1730 |
case TEMPLATE_DECL: |
| 1731 |
case TEMPLATE_TYPE_PARM: |
| 1732 |
case TEMPLATE_PARM_INDEX: |
| 1733 |
case TEMPLATE_TEMPLATE_PARM: |
| 1734 |
break; |
| 1735 |
|
| 1736 |
default: |
| 1737 |
c_pretty_printer::direct_declarator (t); |
| 1738 |
break; |
| 1739 |
} |
| 1740 |
} |
| 1741 |
|
| 1742 |
/* declarator: |
| 1743 |
direct-declarator |
| 1744 |
ptr-operator declarator */ |
| 1745 |
|
| 1746 |
void |
| 1747 |
cxx_pretty_printer::declarator (tree t) |
| 1748 |
{ |
| 1749 |
direct_declarator (t); |
| 1750 |
|
| 1751 |
// Print a requires clause. |
| 1752 |
if (flag_concepts) |
| 1753 |
if (tree ci = get_constraints (t)) |
| 1754 |
if (tree reqs = CI_DECLARATOR_REQS (ci)) |
| 1755 |
pp_cxx_requires_clause (this, reqs); |
| 1756 |
} |
| 1757 |
|
| 1758 |
/* ctor-initializer: |
| 1759 |
: mem-initializer-list |
| 1760 |
|
| 1761 |
mem-initializer-list: |
| 1762 |
mem-initializer |
| 1763 |
mem-initializer , mem-initializer-list |
| 1764 |
|
| 1765 |
mem-initializer: |
| 1766 |
mem-initializer-id ( expression-list(opt) ) |
| 1767 |
|
| 1768 |
mem-initializer-id: |
| 1769 |
::(opt) nested-name-specifier(opt) class-name |
| 1770 |
identifier */ |
| 1771 |
|
| 1772 |
static void |
| 1773 |
pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t) |
| 1774 |
{ |
| 1775 |
t = TREE_OPERAND (t, 0); |
| 1776 |
pp_cxx_whitespace (pp); |
| 1777 |
pp_colon (pp); |
| 1778 |
pp_cxx_whitespace (pp); |
| 1779 |
for (; t; t = TREE_CHAIN (t)) |
| 1780 |
{ |
| 1781 |
tree purpose = TREE_PURPOSE (t); |
| 1782 |
bool is_pack = PACK_EXPANSION_P (purpose); |
| 1783 |
|
| 1784 |
if (is_pack) |
| 1785 |
pp->primary_expression (PACK_EXPANSION_PATTERN (purpose)); |
| 1786 |
else |
| 1787 |
pp->primary_expression (purpose); |
| 1788 |
pp_cxx_call_argument_list (pp, TREE_VALUE (t)); |
| 1789 |
if (is_pack) |
| 1790 |
pp_cxx_ws_string (pp, "..."); |
| 1791 |
if (TREE_CHAIN (t)) |
| 1792 |
pp_cxx_separate_with (pp, ','); |
| 1793 |
} |
| 1794 |
} |
| 1795 |
|
| 1796 |
/* function-definition: |
| 1797 |
decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body |
| 1798 |
decl-specifier-seq(opt) declarator function-try-block */ |
| 1799 |
|
| 1800 |
static void |
| 1801 |
pp_cxx_function_definition (cxx_pretty_printer *pp, tree t) |
| 1802 |
{ |
| 1803 |
tree saved_scope = pp->enclosing_scope; |
| 1804 |
pp->declaration_specifiers (t); |
| 1805 |
pp->declarator (t); |
| 1806 |
pp_needs_newline (pp) = true; |
| 1807 |
pp->enclosing_scope = DECL_CONTEXT (t); |
| 1808 |
if (DECL_SAVED_TREE (t)) |
| 1809 |
pp->statement (DECL_SAVED_TREE (t)); |
| 1810 |
else |
| 1811 |
pp_cxx_semicolon (pp); |
| 1812 |
pp_newline_and_flush (pp); |
| 1813 |
pp->enclosing_scope = saved_scope; |
| 1814 |
} |
| 1815 |
|
| 1816 |
/* abstract-declarator: |
| 1817 |
ptr-operator abstract-declarator(opt) |
| 1818 |
direct-abstract-declarator */ |
| 1819 |
|
| 1820 |
void |
| 1821 |
cxx_pretty_printer::abstract_declarator (tree t) |
| 1822 |
{ |
| 1823 |
/* pp_cxx_ptr_operator prints '(' for a pointer-to-member function, |
| 1824 |
or a pointer-to-data-member of array type: |
| 1825 |
|
| 1826 |
void (X::*)() |
| 1827 |
int (X::*)[5] |
| 1828 |
|
| 1829 |
but not for a pointer-to-data-member of non-array type: |
| 1830 |
|
| 1831 |
int X::* |
| 1832 |
|
| 1833 |
so be mindful of that. */ |
| 1834 |
if (TYPE_PTRMEMFUNC_P (t) |
| 1835 |
|| (TYPE_PTRDATAMEM_P (t) |
| 1836 |
&& TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)) |
| 1837 |
pp_cxx_right_paren (this); |
| 1838 |
else if (INDIRECT_TYPE_P (t)) |
| 1839 |
{ |
| 1840 |
if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE |
| 1841 |
|| TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE) |
| 1842 |
pp_cxx_right_paren (this); |
| 1843 |
t = TREE_TYPE (t); |
| 1844 |
} |
| 1845 |
direct_abstract_declarator (t); |
| 1846 |
} |
| 1847 |
|
| 1848 |
/* direct-abstract-declarator: |
| 1849 |
direct-abstract-declarator(opt) ( parameter-declaration-clause ) |
| 1850 |
cv-qualifier-seq(opt) exception-specification(opt) |
| 1851 |
direct-abstract-declarator(opt) [ constant-expression(opt) ] |
| 1852 |
( abstract-declarator ) */ |
| 1853 |
|
| 1854 |
void |
| 1855 |
cxx_pretty_printer::direct_abstract_declarator (tree t) |
| 1856 |
{ |
| 1857 |
switch (TREE_CODE (t)) |
| 1858 |
{ |
| 1859 |
case REFERENCE_TYPE: |
| 1860 |
abstract_declarator (t); |
| 1861 |
break; |
| 1862 |
|
| 1863 |
case RECORD_TYPE: |
| 1864 |
if (TYPE_PTRMEMFUNC_P (t)) |
| 1865 |
direct_abstract_declarator (TYPE_PTRMEMFUNC_FN_TYPE (t)); |
| 1866 |
break; |
| 1867 |
|
| 1868 |
case OFFSET_TYPE: |
| 1869 |
if (TYPE_PTRDATAMEM_P (t)) |
| 1870 |
direct_abstract_declarator (TREE_TYPE (t)); |
| 1871 |
break; |
| 1872 |
|
| 1873 |
case METHOD_TYPE: |
| 1874 |
case FUNCTION_TYPE: |
| 1875 |
pp_cxx_parameter_declaration_clause (this, t); |
| 1876 |
direct_abstract_declarator (TREE_TYPE (t)); |
| 1877 |
if (TREE_CODE (t) == METHOD_TYPE) |
| 1878 |
{ |
| 1879 |
set_padding (pp_before); |
| 1880 |
pp_cxx_cv_qualifier_seq (this, class_of_this_parm (t)); |
| 1881 |
} |
| 1882 |
pp_cxx_exception_specification (this, t); |
| 1883 |
break; |
| 1884 |
|
| 1885 |
case TYPENAME_TYPE: |
| 1886 |
case TEMPLATE_TYPE_PARM: |
| 1887 |
case TEMPLATE_TEMPLATE_PARM: |
| 1888 |
case BOUND_TEMPLATE_TEMPLATE_PARM: |
| 1889 |
case UNBOUND_CLASS_TEMPLATE: |
| 1890 |
case DECLTYPE_TYPE: |
| 1891 |
break; |
| 1892 |
|
| 1893 |
default: |
| 1894 |
c_pretty_printer::direct_abstract_declarator (t); |
| 1895 |
break; |
| 1896 |
} |
| 1897 |
} |
| 1898 |
|
| 1899 |
/* type-id: |
| 1900 |
type-specifier-seq abstract-declarator(opt) */ |
| 1901 |
|
| 1902 |
void |
| 1903 |
cxx_pretty_printer::type_id (tree t) |
| 1904 |
{ |
| 1905 |
pp_flags saved_flags = flags; |
| 1906 |
flags |= pp_c_flag_abstract; |
| 1907 |
|
| 1908 |
switch (TREE_CODE (t)) |
| 1909 |
{ |
| 1910 |
case TYPE_DECL: |
| 1911 |
case UNION_TYPE: |
| 1912 |
case RECORD_TYPE: |
| 1913 |
case ENUMERAL_TYPE: |
| 1914 |
case TYPENAME_TYPE: |
| 1915 |
case BOUND_TEMPLATE_TEMPLATE_PARM: |
| 1916 |
case UNBOUND_CLASS_TEMPLATE: |
| 1917 |
case TEMPLATE_TEMPLATE_PARM: |
| 1918 |
case TEMPLATE_TYPE_PARM: |
| 1919 |
case TEMPLATE_PARM_INDEX: |
| 1920 |
case TEMPLATE_DECL: |
| 1921 |
case TYPEOF_TYPE: |
| 1922 |
case TRAIT_TYPE: |
| 1923 |
case DECLTYPE_TYPE: |
| 1924 |
case NULLPTR_TYPE: |
| 1925 |
case TEMPLATE_ID_EXPR: |
| 1926 |
case OFFSET_TYPE: |
| 1927 |
pp_cxx_type_specifier_seq (this, t); |
| 1928 |
if (TYPE_PTRMEM_P (t)) |
| 1929 |
abstract_declarator (t); |
| 1930 |
break; |
| 1931 |
|
| 1932 |
case TYPE_PACK_EXPANSION: |
| 1933 |
type_id (PACK_EXPANSION_PATTERN (t)); |
| 1934 |
pp_cxx_ws_string (this, "..."); |
| 1935 |
break; |
| 1936 |
|
| 1937 |
case PACK_INDEX_TYPE: |
| 1938 |
type_id (PACK_INDEX_PACK (t)); |
| 1939 |
pp_cxx_left_bracket (this); |
| 1940 |
expression (PACK_INDEX_INDEX (t)); |
| 1941 |
pp_cxx_right_bracket (this); |
| 1942 |
break; |
| 1943 |
|
| 1944 |
case TYPE_ARGUMENT_PACK: |
| 1945 |
{ |
| 1946 |
tree args = ARGUMENT_PACK_ARGS (t); |
| 1947 |
int len = TREE_VEC_LENGTH (args); |
| 1948 |
pp_cxx_left_brace (this); |
| 1949 |
for (int i = 0; i < len; ++i) |
| 1950 |
{ |
| 1951 |
if (i > 0) |
| 1952 |
pp_cxx_separate_with (this, ','); |
| 1953 |
type_id (TREE_VEC_ELT (args, i)); |
| 1954 |
} |
| 1955 |
pp_cxx_right_brace (this); |
| 1956 |
} |
| 1957 |
break; |
| 1958 |
|
| 1959 |
default: |
| 1960 |
c_pretty_printer::type_id (t); |
| 1961 |
break; |
| 1962 |
} |
| 1963 |
|
| 1964 |
flags = saved_flags; |
| 1965 |
} |
| 1966 |
|
| 1967 |
/* template-argument-list: |
| 1968 |
template-argument ...(opt) |
| 1969 |
template-argument-list, template-argument ...(opt) |
| 1970 |
|
| 1971 |
template-argument: |
| 1972 |
assignment-expression |
| 1973 |
type-id |
| 1974 |
template-name */ |
| 1975 |
|
| 1976 |
static void |
| 1977 |
pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t) |
| 1978 |
{ |
| 1979 |
int i; |
| 1980 |
bool need_comma = false; |
| 1981 |
|
| 1982 |
if (t == NULL) |
| 1983 |
return; |
| 1984 |
for (i = 0; i < TREE_VEC_LENGTH (t); ++i) |
| 1985 |
{ |
| 1986 |
tree arg = TREE_VEC_ELT (t, i); |
| 1987 |
tree argpack = NULL_TREE; |
| 1988 |
int idx, len = 1; |
| 1989 |
|
| 1990 |
if (ARGUMENT_PACK_P (arg)) |
| 1991 |
{ |
| 1992 |
argpack = ARGUMENT_PACK_ARGS (arg); |
| 1993 |
len = TREE_VEC_LENGTH (argpack); |
| 1994 |
} |
| 1995 |
|
| 1996 |
for (idx = 0; idx < len; idx++) |
| 1997 |
{ |
| 1998 |
if (argpack) |
| 1999 |
arg = TREE_VEC_ELT (argpack, idx); |
| 2000 |
|
| 2001 |
if (need_comma) |
| 2002 |
pp_cxx_separate_with (pp, ','); |
| 2003 |
else |
| 2004 |
need_comma = true; |
| 2005 |
|
| 2006 |
if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL |
| 2007 |
&& TYPE_P (DECL_TEMPLATE_RESULT (arg)))) |
| 2008 |
pp->type_id (arg); |
| 2009 |
else |
| 2010 |
pp->expression (arg); |
| 2011 |
} |
| 2012 |
} |
| 2013 |
} |
| 2014 |
|
| 2015 |
|
| 2016 |
static void |
| 2017 |
pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t) |
| 2018 |
{ |
| 2019 |
t = DECL_EXPR_DECL (t); |
| 2020 |
pp_cxx_type_specifier_seq (pp, t); |
| 2021 |
if (TYPE_P (t)) |
| 2022 |
pp->abstract_declarator (t); |
| 2023 |
else |
| 2024 |
pp->declarator (t); |
| 2025 |
} |
| 2026 |
|
| 2027 |
/* Statements. */ |
| 2028 |
|
| 2029 |
void |
| 2030 |
cxx_pretty_printer::statement (tree t) |
| 2031 |
{ |
| 2032 |
switch (TREE_CODE (t)) |
| 2033 |
{ |
| 2034 |
case CTOR_INITIALIZER: |
| 2035 |
pp_cxx_ctor_initializer (this, t); |
| 2036 |
break; |
| 2037 |
|
| 2038 |
case USING_STMT: |
| 2039 |
pp_cxx_ws_string (this, "using"); |
| 2040 |
pp_cxx_ws_string (this, "namespace"); |
| 2041 |
if (DECL_CONTEXT (t)) |
| 2042 |
pp_cxx_nested_name_specifier (this, DECL_CONTEXT (t)); |
| 2043 |
pp_cxx_qualified_id (this, USING_STMT_NAMESPACE (t)); |
| 2044 |
break; |
| 2045 |
|
| 2046 |
case USING_DECL: |
| 2047 |
pp_cxx_ws_string (this, "using"); |
| 2048 |
pp_cxx_nested_name_specifier (this, USING_DECL_SCOPE (t)); |
| 2049 |
pp_cxx_unqualified_id (this, DECL_NAME (t)); |
| 2050 |
break; |
| 2051 |
|
| 2052 |
case EH_SPEC_BLOCK: |
| 2053 |
break; |
| 2054 |
|
| 2055 |
/* try-block: |
| 2056 |
try compound-statement handler-seq */ |
| 2057 |
case TRY_BLOCK: |
| 2058 |
pp_maybe_newline_and_indent (this, 0); |
| 2059 |
pp_cxx_ws_string (this, "try"); |
| 2060 |
pp_newline_and_indent (this, 3); |
| 2061 |
statement (TRY_STMTS (t)); |
| 2062 |
pp_newline_and_indent (this, -3); |
| 2063 |
if (CLEANUP_P (t)) |
| 2064 |
; |
| 2065 |
else |
| 2066 |
statement (TRY_HANDLERS (t)); |
| 2067 |
break; |
| 2068 |
|
| 2069 |
/* |
| 2070 |
handler-seq: |
| 2071 |
handler handler-seq(opt) |
| 2072 |
|
| 2073 |
handler: |
| 2074 |
catch ( exception-declaration ) compound-statement |
| 2075 |
|
| 2076 |
exception-declaration: |
| 2077 |
type-specifier-seq declarator |
| 2078 |
type-specifier-seq abstract-declarator |
| 2079 |
... */ |
| 2080 |
case HANDLER: |
| 2081 |
pp_cxx_ws_string (this, "catch"); |
| 2082 |
pp_cxx_left_paren (this); |
| 2083 |
pp_cxx_exception_declaration (this, HANDLER_PARMS (t)); |
| 2084 |
pp_cxx_right_paren (this); |
| 2085 |
pp_indentation (this) += 3; |
| 2086 |
pp_needs_newline (this) = true; |
| 2087 |
statement (HANDLER_BODY (t)); |
| 2088 |
pp_indentation (this) -= 3; |
| 2089 |
pp_needs_newline (this) = true; |
| 2090 |
break; |
| 2091 |
|
| 2092 |
/* selection-statement: |
| 2093 |
if ( expression ) statement |
| 2094 |
if ( expression ) statement else statement */ |
| 2095 |
case IF_STMT: |
| 2096 |
pp_cxx_ws_string (this, "if"); |
| 2097 |
pp_cxx_whitespace (this); |
| 2098 |
pp_cxx_left_paren (this); |
| 2099 |
expression (IF_COND (t)); |
| 2100 |
pp_cxx_right_paren (this); |
| 2101 |
pp_newline_and_indent (this, 2); |
| 2102 |
statement (THEN_CLAUSE (t)); |
| 2103 |
pp_newline_and_indent (this, -2); |
| 2104 |
if (ELSE_CLAUSE (t)) |
| 2105 |
{ |
| 2106 |
tree else_clause = ELSE_CLAUSE (t); |
| 2107 |
pp_cxx_ws_string (this, "else"); |
| 2108 |
if (TREE_CODE (else_clause) == IF_STMT) |
| 2109 |
pp_cxx_whitespace (this); |
| 2110 |
else |
| 2111 |
pp_newline_and_indent (this, 2); |
| 2112 |
statement (else_clause); |
| 2113 |
if (TREE_CODE (else_clause) != IF_STMT) |
| 2114 |
pp_newline_and_indent (this, -2); |
| 2115 |
} |
| 2116 |
break; |
| 2117 |
|
| 2118 |
case RANGE_FOR_STMT: |
| 2119 |
pp_cxx_ws_string (this, "for"); |
| 2120 |
pp_space (this); |
| 2121 |
pp_cxx_left_paren (this); |
| 2122 |
if (RANGE_FOR_INIT_STMT (t)) |
| 2123 |
{ |
| 2124 |
statement (RANGE_FOR_INIT_STMT (t)); |
| 2125 |
pp_needs_newline (this) = false; |
| 2126 |
pp_cxx_whitespace (this); |
| 2127 |
} |
| 2128 |
statement (RANGE_FOR_DECL (t)); |
| 2129 |
pp_space (this); |
| 2130 |
pp_needs_newline (this) = false; |
| 2131 |
pp_colon (this); |
| 2132 |
pp_space (this); |
| 2133 |
statement (RANGE_FOR_EXPR (t)); |
| 2134 |
pp_cxx_right_paren (this); |
| 2135 |
pp_newline_and_indent (this, 3); |
| 2136 |
statement (FOR_BODY (t)); |
| 2137 |
pp_indentation (this) -= 3; |
| 2138 |
pp_needs_newline (this) = true; |
| 2139 |
break; |
| 2140 |
|
| 2141 |
/* expression-statement: |
| 2142 |
expression(opt) ; */ |
| 2143 |
case EXPR_STMT: |
| 2144 |
expression (EXPR_STMT_EXPR (t)); |
| 2145 |
pp_cxx_semicolon (this); |
| 2146 |
pp_needs_newline (this) = true; |
| 2147 |
break; |
| 2148 |
|
| 2149 |
case CLEANUP_STMT: |
| 2150 |
pp_cxx_ws_string (this, "try"); |
| 2151 |
pp_newline_and_indent (this, 2); |
| 2152 |
statement (CLEANUP_BODY (t)); |
| 2153 |
pp_newline_and_indent (this, -2); |
| 2154 |
pp_cxx_ws_string (this, CLEANUP_EH_ONLY (t) ? "catch" : "finally"); |
| 2155 |
pp_newline_and_indent (this, 2); |
| 2156 |
statement (CLEANUP_EXPR (t)); |
| 2157 |
pp_newline_and_indent (this, -2); |
| 2158 |
break; |
| 2159 |
|
| 2160 |
case STATIC_ASSERT: |
| 2161 |
declaration (t); |
| 2162 |
break; |
| 2163 |
|
| 2164 |
case OMP_DEPOBJ: |
| 2165 |
pp_cxx_ws_string (this, "#pragma omp depobj"); |
| 2166 |
pp_space (this); |
| 2167 |
pp_cxx_left_paren (this); |
| 2168 |
expression (OMP_DEPOBJ_DEPOBJ (t)); |
| 2169 |
pp_cxx_right_paren (this); |
| 2170 |
if (OMP_DEPOBJ_CLAUSES (t) && OMP_DEPOBJ_CLAUSES (t) != error_mark_node) |
| 2171 |
{ |
| 2172 |
if (TREE_CODE (OMP_DEPOBJ_CLAUSES (t)) == OMP_CLAUSE) |
| 2173 |
dump_omp_clauses (this, OMP_DEPOBJ_CLAUSES (t), |
| 2174 |
pp_indentation (this), TDF_NONE); |
| 2175 |
else |
| 2176 |
switch (tree_to_uhwi (OMP_DEPOBJ_CLAUSES (t))) |
| 2177 |
{ |
| 2178 |
case OMP_CLAUSE_DEPEND_IN: |
| 2179 |
pp_cxx_ws_string (this, " update(in)"); |
| 2180 |
break; |
| 2181 |
case OMP_CLAUSE_DEPEND_INOUT: |
| 2182 |
pp_cxx_ws_string (this, " update(inout)"); |
| 2183 |
break; |
| 2184 |
case OMP_CLAUSE_DEPEND_OUT: |
| 2185 |
pp_cxx_ws_string (this, " update(out)"); |
| 2186 |
break; |
| 2187 |
case OMP_CLAUSE_DEPEND_MUTEXINOUTSET: |
| 2188 |
pp_cxx_ws_string (this, " update(mutexinoutset)"); |
| 2189 |
break; |
| 2190 |
case OMP_CLAUSE_DEPEND_INOUTSET: |
| 2191 |
pp_cxx_ws_string (this, " update(inoutset)"); |
| 2192 |
break; |
| 2193 |
case OMP_CLAUSE_DEPEND_LAST: |
| 2194 |
pp_cxx_ws_string (this, " destroy"); |
| 2195 |
break; |
| 2196 |
default: |
| 2197 |
break; |
| 2198 |
} |
| 2199 |
} |
| 2200 |
pp_needs_newline (this) = true; |
| 2201 |
break; |
| 2202 |
|
| 2203 |
default: |
| 2204 |
c_pretty_printer::statement (t); |
| 2205 |
break; |
| 2206 |
} |
| 2207 |
} |
| 2208 |
|
| 2209 |
/* original-namespace-definition: |
| 2210 |
namespace identifier { namespace-body } |
| 2211 |
|
| 2212 |
As an edge case, we also handle unnamed namespace definition here. */ |
| 2213 |
|
| 2214 |
static void |
| 2215 |
pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t) |
| 2216 |
{ |
| 2217 |
pp_cxx_ws_string (pp, "namespace"); |
| 2218 |
if (DECL_CONTEXT (t)) |
| 2219 |
pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t)); |
| 2220 |
if (DECL_NAME (t)) |
| 2221 |
pp_cxx_unqualified_id (pp, t); |
| 2222 |
pp_cxx_whitespace (pp); |
| 2223 |
pp_cxx_left_brace (pp); |
| 2224 |
/* We do not print the namespace-body. */ |
| 2225 |
pp_cxx_whitespace (pp); |
| 2226 |
pp_cxx_right_brace (pp); |
| 2227 |
} |
| 2228 |
|
| 2229 |
/* namespace-alias: |
| 2230 |
identifier |
| 2231 |
|
| 2232 |
namespace-alias-definition: |
| 2233 |
namespace identifier = qualified-namespace-specifier ; |
| 2234 |
|
| 2235 |
qualified-namespace-specifier: |
| 2236 |
::(opt) nested-name-specifier(opt) namespace-name */ |
| 2237 |
|
| 2238 |
static void |
| 2239 |
pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t) |
| 2240 |
{ |
| 2241 |
pp_cxx_ws_string (pp, "namespace"); |
| 2242 |
if (DECL_CONTEXT (t)) |
| 2243 |
pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t)); |
| 2244 |
pp_cxx_unqualified_id (pp, t); |
| 2245 |
pp_cxx_whitespace (pp); |
| 2246 |
pp_equal (pp); |
| 2247 |
pp_cxx_whitespace (pp); |
| 2248 |
if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t))) |
| 2249 |
pp_cxx_nested_name_specifier (pp, |
| 2250 |
DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t))); |
| 2251 |
pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t)); |
| 2252 |
pp_cxx_semicolon (pp); |
| 2253 |
} |
| 2254 |
|
| 2255 |
/* simple-declaration: |
| 2256 |
decl-specifier-seq(opt) init-declarator-list(opt) */ |
| 2257 |
|
| 2258 |
static void |
| 2259 |
pp_cxx_simple_declaration (cxx_pretty_printer *pp, tree t) |
| 2260 |
{ |
| 2261 |
pp->declaration_specifiers (t); |
| 2262 |
pp_cxx_init_declarator (pp, t); |
| 2263 |
pp_cxx_semicolon (pp); |
| 2264 |
pp_needs_newline (pp) = true; |
| 2265 |
} |
| 2266 |
|
| 2267 |
/* |
| 2268 |
template-parameter-list: |
| 2269 |
template-parameter |
| 2270 |
template-parameter-list , template-parameter */ |
| 2271 |
|
| 2272 |
static inline void |
| 2273 |
pp_cxx_template_parameter_list (cxx_pretty_printer *pp, tree t) |
| 2274 |
{ |
| 2275 |
const int n = TREE_VEC_LENGTH (t); |
| 2276 |
int i; |
| 2277 |
for (i = 0; i < n; ++i) |
| 2278 |
{ |
| 2279 |
if (i) |
| 2280 |
pp_cxx_separate_with (pp, ','); |
| 2281 |
pp_cxx_template_parameter (pp, TREE_VEC_ELT (t, i)); |
| 2282 |
} |
| 2283 |
} |
| 2284 |
|
| 2285 |
/* template-parameter: |
| 2286 |
type-parameter |
| 2287 |
parameter-declaration |
| 2288 |
|
| 2289 |
type-parameter: |
| 2290 |
class ...(opt) identifier(opt) |
| 2291 |
class identifier(opt) = type-id |
| 2292 |
typename identifier(opt) |
| 2293 |
typename ...(opt) identifier(opt) = type-id |
| 2294 |
template < template-parameter-list > class ...(opt) identifier(opt) |
| 2295 |
template < template-parameter-list > class identifier(opt) = template-name */ |
| 2296 |
|
| 2297 |
static void |
| 2298 |
pp_cxx_template_parameter (cxx_pretty_printer *pp, tree t) |
| 2299 |
{ |
| 2300 |
tree parameter = TREE_VALUE (t); |
| 2301 |
switch (TREE_CODE (parameter)) |
| 2302 |
{ |
| 2303 |
case TYPE_DECL: |
| 2304 |
pp_cxx_ws_string (pp, "class"); |
| 2305 |
if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (parameter))) |
| 2306 |
pp_cxx_ws_string (pp, "..."); |
| 2307 |
if (DECL_NAME (parameter)) |
| 2308 |
pp_cxx_tree_identifier (pp, DECL_NAME (parameter)); |
| 2309 |
/* FIXME: Check if we should print also default argument. */ |
| 2310 |
break; |
| 2311 |
|
| 2312 |
case PARM_DECL: |
| 2313 |
pp_cxx_parameter_declaration (pp, parameter); |
| 2314 |
break; |
| 2315 |
|
| 2316 |
case TEMPLATE_DECL: |
| 2317 |
break; |
| 2318 |
|
| 2319 |
default: |
| 2320 |
pp_unsupported_tree (pp, t); |
| 2321 |
break; |
| 2322 |
} |
| 2323 |
} |
| 2324 |
|
| 2325 |
/* Pretty-print a template parameter in the canonical form |
| 2326 |
"template-parameter-<level>-<position in parameter list>". */ |
| 2327 |
|
| 2328 |
void |
| 2329 |
pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm) |
| 2330 |
{ |
| 2331 |
const enum tree_code code = TREE_CODE (parm); |
| 2332 |
|
| 2333 |
/* Brings type template parameters to the canonical forms. */ |
| 2334 |
if (code == TEMPLATE_TYPE_PARM || code == TEMPLATE_TEMPLATE_PARM |
| 2335 |
|| code == BOUND_TEMPLATE_TEMPLATE_PARM) |
| 2336 |
parm = TEMPLATE_TYPE_PARM_INDEX (parm); |
| 2337 |
|
| 2338 |
pp_cxx_begin_template_argument_list (pp); |
| 2339 |
pp->translate_string ("template-parameter-"); |
| 2340 |
pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm)); |
| 2341 |
pp_minus (pp); |
| 2342 |
pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1); |
| 2343 |
pp_cxx_end_template_argument_list (pp); |
| 2344 |
} |
| 2345 |
|
| 2346 |
/* Print a constrained-type-specifier. */ |
| 2347 |
|
| 2348 |
void |
| 2349 |
pp_cxx_constrained_type_spec (cxx_pretty_printer *pp, tree c) |
| 2350 |
{ |
| 2351 |
pp_cxx_whitespace (pp); |
| 2352 |
pp_cxx_left_bracket (pp); |
| 2353 |
pp->translate_string ("requires"); |
| 2354 |
pp_cxx_whitespace (pp); |
| 2355 |
if (c == error_mark_node) |
| 2356 |
{ |
| 2357 |
pp_cxx_ws_string(pp, "<unsatisfied-type-constraint>"); |
| 2358 |
return; |
| 2359 |
} |
| 2360 |
tree t = TREE_OPERAND (c, 0); |
| 2361 |
tree a = TREE_OPERAND (c, 1); |
| 2362 |
pp->id_expression (t); |
| 2363 |
pp_cxx_begin_template_argument_list (pp); |
| 2364 |
pp_cxx_ws_string (pp, "<placeholder>"); |
| 2365 |
pp_cxx_separate_with (pp, ','); |
| 2366 |
tree args = make_tree_vec (TREE_VEC_LENGTH (a) - 1); |
| 2367 |
for (int i = 0; i < TREE_VEC_LENGTH (a) - 1; ++i) |
| 2368 |
TREE_VEC_ELT (args, i) = TREE_VEC_ELT (a, i + 1); |
| 2369 |
pp_cxx_template_argument_list (pp, args); |
| 2370 |
ggc_free (args); |
| 2371 |
pp_cxx_end_template_argument_list (pp); |
| 2372 |
pp_cxx_right_bracket (pp); |
| 2373 |
} |
| 2374 |
|
| 2375 |
/* |
| 2376 |
template-declaration: |
| 2377 |
export(opt) template < template-parameter-list > declaration |
| 2378 |
|
| 2379 |
Concept extensions: |
| 2380 |
|
| 2381 |
template-declaration: |
| 2382 |
export(opt) template < template-parameter-list > |
| 2383 |
requires-clause(opt) declaration */ |
| 2384 |
|
| 2385 |
static void |
| 2386 |
pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t) |
| 2387 |
{ |
| 2388 |
tree tmpl = most_general_template (t); |
| 2389 |
tree level; |
| 2390 |
|
| 2391 |
pp_maybe_newline_and_indent (pp, 0); |
| 2392 |
for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level)) |
| 2393 |
{ |
| 2394 |
pp_cxx_ws_string (pp, "template"); |
| 2395 |
pp_cxx_begin_template_argument_list (pp); |
| 2396 |
pp_cxx_template_parameter_list (pp, TREE_VALUE (level)); |
| 2397 |
pp_cxx_end_template_argument_list (pp); |
| 2398 |
pp_newline_and_indent (pp, 3); |
| 2399 |
} |
| 2400 |
|
| 2401 |
if (flag_concepts) |
| 2402 |
if (tree ci = get_constraints (t)) |
| 2403 |
if (tree reqs = CI_TEMPLATE_REQS (ci)) |
| 2404 |
{ |
| 2405 |
pp_cxx_requires_clause (pp, reqs); |
| 2406 |
pp_newline_and_indent (pp, 6); |
| 2407 |
} |
| 2408 |
|
| 2409 |
if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t)) |
| 2410 |
pp_cxx_function_definition (pp, t); |
| 2411 |
else if (TREE_CODE (t) == CONCEPT_DECL) |
| 2412 |
pp_cxx_concept_definition (pp, t); |
| 2413 |
else |
| 2414 |
pp_cxx_simple_declaration (pp, t); |
| 2415 |
} |
| 2416 |
|
| 2417 |
static void |
| 2418 |
pp_cxx_explicit_specialization (cxx_pretty_printer *pp, tree t) |
| 2419 |
{ |
| 2420 |
pp_unsupported_tree (pp, t); |
| 2421 |
} |
| 2422 |
|
| 2423 |
static void |
| 2424 |
pp_cxx_explicit_instantiation (cxx_pretty_printer *pp, tree t) |
| 2425 |
{ |
| 2426 |
pp_unsupported_tree (pp, t); |
| 2427 |
} |
| 2428 |
|
| 2429 |
static void |
| 2430 |
pp_cxx_concept_definition (cxx_pretty_printer *pp, tree t) |
| 2431 |
{ |
| 2432 |
pp_cxx_unqualified_id (pp, DECL_NAME (t)); |
| 2433 |
pp_cxx_whitespace (pp); |
| 2434 |
pp_cxx_ws_string (pp, "="); |
| 2435 |
pp_cxx_whitespace (pp); |
| 2436 |
pp->expression (DECL_INITIAL (t)); |
| 2437 |
pp_cxx_semicolon (pp); |
| 2438 |
} |
| 2439 |
|
| 2440 |
/* |
| 2441 |
declaration: |
| 2442 |
block-declaration |
| 2443 |
function-definition |
| 2444 |
template-declaration |
| 2445 |
explicit-instantiation |
| 2446 |
explicit-specialization |
| 2447 |
linkage-specification |
| 2448 |
namespace-definition |
| 2449 |
|
| 2450 |
block-declaration: |
| 2451 |
simple-declaration |
| 2452 |
asm-definition |
| 2453 |
namespace-alias-definition |
| 2454 |
using-declaration |
| 2455 |
using-directive |
| 2456 |
static_assert-declaration */ |
| 2457 |
void |
| 2458 |
cxx_pretty_printer::declaration (tree t) |
| 2459 |
{ |
| 2460 |
if (TREE_CODE (t) == STATIC_ASSERT) |
| 2461 |
{ |
| 2462 |
pp_cxx_ws_string (this, "static_assert"); |
| 2463 |
pp_cxx_left_paren (this); |
| 2464 |
expression (STATIC_ASSERT_CONDITION (t)); |
| 2465 |
pp_cxx_separate_with (this, ','); |
| 2466 |
expression (STATIC_ASSERT_MESSAGE (t)); |
| 2467 |
pp_cxx_right_paren (this); |
| 2468 |
} |
| 2469 |
else if (!DECL_LANG_SPECIFIC (t)) |
| 2470 |
pp_cxx_simple_declaration (this, t); |
| 2471 |
else if (DECL_USE_TEMPLATE (t)) |
| 2472 |
switch (DECL_USE_TEMPLATE (t)) |
| 2473 |
{ |
| 2474 |
case 1: |
| 2475 |
pp_cxx_template_declaration (this, t); |
| 2476 |
break; |
| 2477 |
|
| 2478 |
case 2: |
| 2479 |
pp_cxx_explicit_specialization (this, t); |
| 2480 |
break; |
| 2481 |
|
| 2482 |
case 3: |
| 2483 |
pp_cxx_explicit_instantiation (this, t); |
| 2484 |
break; |
| 2485 |
|
| 2486 |
default: |
| 2487 |
break; |
| 2488 |
} |
| 2489 |
else switch (TREE_CODE (t)) |
| 2490 |
{ |
| 2491 |
case FIELD_DECL: |
| 2492 |
case VAR_DECL: |
| 2493 |
case TYPE_DECL: |
| 2494 |
pp_cxx_simple_declaration (this, t); |
| 2495 |
break; |
| 2496 |
|
| 2497 |
case FUNCTION_DECL: |
| 2498 |
if (DECL_SAVED_TREE (t)) |
| 2499 |
pp_cxx_function_definition (this, t); |
| 2500 |
else |
| 2501 |
pp_cxx_simple_declaration (this, t); |
| 2502 |
break; |
| 2503 |
|
| 2504 |
case NAMESPACE_DECL: |
| 2505 |
if (DECL_NAMESPACE_ALIAS (t)) |
| 2506 |
pp_cxx_namespace_alias_definition (this, t); |
| 2507 |
else |
| 2508 |
pp_cxx_original_namespace_definition (this, t); |
| 2509 |
break; |
| 2510 |
|
| 2511 |
default: |
| 2512 |
pp_unsupported_tree (this, t); |
| 2513 |
break; |
| 2514 |
} |
| 2515 |
} |
| 2516 |
|
| 2517 |
static void |
| 2518 |
pp_cxx_typeid_expression (cxx_pretty_printer *pp, tree t) |
| 2519 |
{ |
| 2520 |
t = TREE_OPERAND (t, 0); |
| 2521 |
pp_cxx_ws_string (pp, "typeid"); |
| 2522 |
pp_cxx_left_paren (pp); |
| 2523 |
if (TYPE_P (t)) |
| 2524 |
pp->type_id (t); |
| 2525 |
else |
| 2526 |
pp->expression (t); |
| 2527 |
pp_cxx_right_paren (pp); |
| 2528 |
} |
| 2529 |
|
| 2530 |
void |
| 2531 |
pp_cxx_va_arg_expression (cxx_pretty_printer *pp, tree t) |
| 2532 |
{ |
| 2533 |
pp_cxx_ws_string (pp, "va_arg"); |
| 2534 |
pp_cxx_left_paren (pp); |
| 2535 |
pp->assignment_expression (TREE_OPERAND (t, 0)); |
| 2536 |
pp_cxx_separate_with (pp, ','); |
| 2537 |
pp->type_id (TREE_TYPE (t)); |
| 2538 |
pp_cxx_right_paren (pp); |
| 2539 |
} |
| 2540 |
|
| 2541 |
static bool |
| 2542 |
pp_cxx_offsetof_expression_1 (cxx_pretty_printer *pp, tree t) |
| 2543 |
{ |
| 2544 |
switch (TREE_CODE (t)) |
| 2545 |
{ |
| 2546 |
case ARROW_EXPR: |
| 2547 |
if (TREE_CODE (TREE_OPERAND (t, 0)) == STATIC_CAST_EXPR |
| 2548 |
&& INDIRECT_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0)))) |
| 2549 |
{ |
| 2550 |
pp->type_id (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0)))); |
| 2551 |
pp_cxx_separate_with (pp, ','); |
| 2552 |
return true; |
| 2553 |
} |
| 2554 |
return false; |
| 2555 |
case COMPONENT_REF: |
| 2556 |
if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0))) |
| 2557 |
return false; |
| 2558 |
if (TREE_CODE (TREE_OPERAND (t, 0)) != ARROW_EXPR) |
| 2559 |
pp_cxx_dot (pp); |
| 2560 |
pp->expression (TREE_OPERAND (t, 1)); |
| 2561 |
return true; |
| 2562 |
case ARRAY_REF: |
| 2563 |
if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0))) |
| 2564 |
return false; |
| 2565 |
pp_left_bracket (pp); |
| 2566 |
pp->expression (TREE_OPERAND (t, 1)); |
| 2567 |
pp_right_bracket (pp); |
| 2568 |
return true; |
| 2569 |
default: |
| 2570 |
return false; |
| 2571 |
} |
| 2572 |
} |
| 2573 |
|
| 2574 |
void |
| 2575 |
pp_cxx_offsetof_expression (cxx_pretty_printer *pp, tree t) |
| 2576 |
{ |
| 2577 |
pp_cxx_ws_string (pp, "offsetof"); |
| 2578 |
pp_cxx_left_paren (pp); |
| 2579 |
if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0))) |
| 2580 |
pp->expression (TREE_OPERAND (t, 0)); |
| 2581 |
pp_cxx_right_paren (pp); |
| 2582 |
} |
| 2583 |
|
| 2584 |
void |
| 2585 |
pp_cxx_addressof_expression (cxx_pretty_printer *pp, tree t) |
| 2586 |
{ |
| 2587 |
pp_cxx_ws_string (pp, "__builtin_addressof"); |
| 2588 |
pp_cxx_left_paren (pp); |
| 2589 |
pp->expression (TREE_OPERAND (t, 0)); |
| 2590 |
pp_cxx_right_paren (pp); |
| 2591 |
} |
| 2592 |
|
| 2593 |
static char const* |
| 2594 |
get_fold_operator (tree t) |
| 2595 |
{ |
| 2596 |
ovl_op_info_t *info = OVL_OP_INFO (FOLD_EXPR_MODIFY_P (t), |
| 2597 |
FOLD_EXPR_OP (t)); |
| 2598 |
return info->name; |
| 2599 |
} |
| 2600 |
|
| 2601 |
void |
| 2602 |
pp_cxx_unary_left_fold_expression (cxx_pretty_printer *pp, tree t) |
| 2603 |
{ |
| 2604 |
char const* op = get_fold_operator (t); |
| 2605 |
tree expr = PACK_EXPANSION_PATTERN (FOLD_EXPR_PACK (t)); |
| 2606 |
pp_cxx_left_paren (pp); |
| 2607 |
pp_cxx_ws_string (pp, "..."); |
| 2608 |
pp_cxx_ws_string (pp, op); |
| 2609 |
pp->expression (expr); |
| 2610 |
pp_cxx_right_paren (pp); |
| 2611 |
} |
| 2612 |
|
| 2613 |
void |
| 2614 |
pp_cxx_unary_right_fold_expression (cxx_pretty_printer *pp, tree t) |
| 2615 |
{ |
| 2616 |
char const* op = get_fold_operator (t); |
| 2617 |
tree expr = PACK_EXPANSION_PATTERN (FOLD_EXPR_PACK (t)); |
| 2618 |
pp_cxx_left_paren (pp); |
| 2619 |
pp->expression (expr); |
| 2620 |
pp_space (pp); |
| 2621 |
pp_cxx_ws_string (pp, op); |
| 2622 |
pp_cxx_ws_string (pp, "..."); |
| 2623 |
pp_cxx_right_paren (pp); |
| 2624 |
} |
| 2625 |
|
| 2626 |
void |
| 2627 |
pp_cxx_binary_fold_expression (cxx_pretty_printer *pp, tree t) |
| 2628 |
{ |
| 2629 |
char const* op = get_fold_operator (t); |
| 2630 |
tree t1 = TREE_OPERAND (t, 1); |
| 2631 |
tree t2 = TREE_OPERAND (t, 2); |
| 2632 |
if (t1 == FOLD_EXPR_PACK (t)) |
| 2633 |
t1 = PACK_EXPANSION_PATTERN (t1); |
| 2634 |
else |
| 2635 |
t2 = PACK_EXPANSION_PATTERN (t2); |
| 2636 |
pp_cxx_left_paren (pp); |
| 2637 |
pp->expression (t1); |
| 2638 |
pp_cxx_ws_string (pp, op); |
| 2639 |
pp_cxx_ws_string (pp, "..."); |
| 2640 |
pp_cxx_ws_string (pp, op); |
| 2641 |
pp->expression (t2); |
| 2642 |
pp_cxx_right_paren (pp); |
| 2643 |
} |
| 2644 |
|
| 2645 |
void |
| 2646 |
pp_cxx_trait (cxx_pretty_printer *pp, tree t) |
| 2647 |
{ |
| 2648 |
cp_trait_kind kind; |
| 2649 |
tree type1, type2; |
| 2650 |
if (TREE_CODE (t) == TRAIT_EXPR) |
| 2651 |
{ |
| 2652 |
kind = TRAIT_EXPR_KIND (t); |
| 2653 |
type1 = TRAIT_EXPR_TYPE1 (t); |
| 2654 |
type2 = TRAIT_EXPR_TYPE2 (t); |
| 2655 |
} |
| 2656 |
else |
| 2657 |
{ |
| 2658 |
kind = TRAIT_TYPE_KIND (t); |
| 2659 |
type1 = TRAIT_TYPE_TYPE1 (t); |
| 2660 |
type2 = TRAIT_TYPE_TYPE2 (t); |
| 2661 |
} |
| 2662 |
|
| 2663 |
switch (kind) |
| 2664 |
{ |
| 2665 |
#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ |
| 2666 |
case CPTK_##CODE: \ |
| 2667 |
pp_cxx_ws_string (pp, NAME); \ |
| 2668 |
break; |
| 2669 |
#include "cp-trait.def" |
| 2670 |
#undef DEFTRAIT |
| 2671 |
} |
| 2672 |
|
| 2673 |
if (kind == CPTK_TYPE_PACK_ELEMENT) |
| 2674 |
{ |
| 2675 |
pp_cxx_begin_template_argument_list (pp); |
| 2676 |
pp->expression (type1); |
| 2677 |
} |
| 2678 |
else |
| 2679 |
{ |
| 2680 |
pp_cxx_left_paren (pp); |
| 2681 |
if (TYPE_P (type1)) |
| 2682 |
pp->type_id (type1); |
| 2683 |
else |
| 2684 |
pp->expression (type1); |
| 2685 |
} |
| 2686 |
if (type2) |
| 2687 |
{ |
| 2688 |
if (TREE_CODE (type2) != TREE_VEC) |
| 2689 |
{ |
| 2690 |
pp_cxx_separate_with (pp, ','); |
| 2691 |
pp->type_id (type2); |
| 2692 |
} |
| 2693 |
else |
| 2694 |
for (tree arg : tree_vec_range (type2)) |
| 2695 |
{ |
| 2696 |
pp_cxx_separate_with (pp, ','); |
| 2697 |
pp->type_id (arg); |
| 2698 |
} |
| 2699 |
} |
| 2700 |
if (kind == CPTK_TYPE_PACK_ELEMENT) |
| 2701 |
pp_cxx_end_template_argument_list (pp); |
| 2702 |
else |
| 2703 |
pp_cxx_right_paren (pp); |
| 2704 |
} |
| 2705 |
|
| 2706 |
// requires-clause: |
| 2707 |
// 'requires' logical-or-expression |
| 2708 |
void |
| 2709 |
pp_cxx_requires_clause (cxx_pretty_printer *pp, tree t) |
| 2710 |
{ |
| 2711 |
if (!t) |
| 2712 |
return; |
| 2713 |
pp->set_padding (pp_before); |
| 2714 |
pp_cxx_ws_string (pp, "requires"); |
| 2715 |
pp_space (pp); |
| 2716 |
pp->expression (t); |
| 2717 |
} |
| 2718 |
|
| 2719 |
/* requirement: |
| 2720 |
simple-requirement |
| 2721 |
compound-requirement |
| 2722 |
type-requirement |
| 2723 |
nested-requirement */ |
| 2724 |
static void |
| 2725 |
pp_cxx_requirement (cxx_pretty_printer *pp, tree t) |
| 2726 |
{ |
| 2727 |
switch (TREE_CODE (t)) |
| 2728 |
{ |
| 2729 |
case SIMPLE_REQ: |
| 2730 |
pp_cxx_simple_requirement (pp, t); |
| 2731 |
break; |
| 2732 |
|
| 2733 |
case TYPE_REQ: |
| 2734 |
pp_cxx_type_requirement (pp, t); |
| 2735 |
break; |
| 2736 |
|
| 2737 |
case COMPOUND_REQ: |
| 2738 |
pp_cxx_compound_requirement (pp, t); |
| 2739 |
break; |
| 2740 |
|
| 2741 |
case NESTED_REQ: |
| 2742 |
pp_cxx_nested_requirement (pp, t); |
| 2743 |
break; |
| 2744 |
|
| 2745 |
default: |
| 2746 |
gcc_unreachable (); |
| 2747 |
} |
| 2748 |
} |
| 2749 |
|
| 2750 |
// requirement-list: |
| 2751 |
// requirement |
| 2752 |
// requirement-list ';' requirement[opt] |
| 2753 |
// |
| 2754 |
static void |
| 2755 |
pp_cxx_requirement_list (cxx_pretty_printer *pp, tree t) |
| 2756 |
{ |
| 2757 |
for (; t; t = TREE_CHAIN (t)) |
| 2758 |
pp_cxx_requirement (pp, TREE_VALUE (t)); |
| 2759 |
} |
| 2760 |
|
| 2761 |
// requirement-body: |
| 2762 |
// '{' requirement-list '}' |
| 2763 |
static void |
| 2764 |
pp_cxx_requirement_body (cxx_pretty_printer *pp, tree t) |
| 2765 |
{ |
| 2766 |
pp_cxx_left_brace (pp); |
| 2767 |
pp_cxx_requirement_list (pp, t); |
| 2768 |
pp_cxx_right_brace (pp); |
| 2769 |
} |
| 2770 |
|
| 2771 |
// requires-expression: |
| 2772 |
// 'requires' requirement-parameter-list requirement-body |
| 2773 |
void |
| 2774 |
pp_cxx_requires_expr (cxx_pretty_printer *pp, tree t) |
| 2775 |
{ |
| 2776 |
pp_string (pp, "requires"); |
| 2777 |
if (tree parms = REQUIRES_EXPR_PARMS (t)) |
| 2778 |
{ |
| 2779 |
bool first = true; |
| 2780 |
pp_cxx_left_paren (pp); |
| 2781 |
for (; parms; parms = TREE_CHAIN (parms)) |
| 2782 |
{ |
| 2783 |
if (!first) |
| 2784 |
pp_cxx_separate_with (pp, ',' ); |
| 2785 |
first = false; |
| 2786 |
pp_cxx_parameter_declaration (pp, parms); |
| 2787 |
} |
| 2788 |
pp_cxx_right_paren (pp); |
| 2789 |
pp_cxx_whitespace (pp); |
| 2790 |
} |
| 2791 |
pp_cxx_requirement_body (pp, TREE_OPERAND (t, 1)); |
| 2792 |
} |
| 2793 |
|
| 2794 |
/* simple-requirement: |
| 2795 |
expression ';' */ |
| 2796 |
void |
| 2797 |
pp_cxx_simple_requirement (cxx_pretty_printer *pp, tree t) |
| 2798 |
{ |
| 2799 |
pp->expression (TREE_OPERAND (t, 0)); |
| 2800 |
pp_cxx_semicolon (pp); |
| 2801 |
} |
| 2802 |
|
| 2803 |
/* type-requirement: |
| 2804 |
typename type-name ';' */ |
| 2805 |
void |
| 2806 |
pp_cxx_type_requirement (cxx_pretty_printer *pp, tree t) |
| 2807 |
{ |
| 2808 |
pp->type_id (TREE_OPERAND (t, 0)); |
| 2809 |
pp_cxx_semicolon (pp); |
| 2810 |
} |
| 2811 |
|
| 2812 |
/* compound-requirement: |
| 2813 |
'{' expression '}' 'noexcept' [opt] trailing-return-type [opt] */ |
| 2814 |
void |
| 2815 |
pp_cxx_compound_requirement (cxx_pretty_printer *pp, tree t) |
| 2816 |
{ |
| 2817 |
pp_cxx_left_brace (pp); |
| 2818 |
pp->expression (TREE_OPERAND (t, 0)); |
| 2819 |
pp_cxx_right_brace (pp); |
| 2820 |
|
| 2821 |
if (COMPOUND_REQ_NOEXCEPT_P (t)) |
| 2822 |
pp_cxx_ws_string (pp, "noexcept"); |
| 2823 |
|
| 2824 |
if (tree type = TREE_OPERAND (t, 1)) |
| 2825 |
{ |
| 2826 |
pp_cxx_whitespace (pp); |
| 2827 |
pp_cxx_ws_string (pp, "->"); |
| 2828 |
pp->type_id (type); |
| 2829 |
} |
| 2830 |
pp_cxx_semicolon (pp); |
| 2831 |
} |
| 2832 |
|
| 2833 |
/* nested requirement: |
| 2834 |
'requires' constraint-expression */ |
| 2835 |
void |
| 2836 |
pp_cxx_nested_requirement (cxx_pretty_printer *pp, tree t) |
| 2837 |
{ |
| 2838 |
pp_cxx_ws_string (pp, "requires"); |
| 2839 |
pp->expression (TREE_OPERAND (t, 0)); |
| 2840 |
pp_cxx_semicolon (pp); |
| 2841 |
} |
| 2842 |
|
| 2843 |
/* Output the "[with ...]" clause for a parameter mapping of an atomic |
| 2844 |
constraint. */ |
| 2845 |
|
| 2846 |
void |
| 2847 |
pp_cxx_parameter_mapping (cxx_pretty_printer *pp, tree map) |
| 2848 |
{ |
| 2849 |
pp_cxx_whitespace (pp); |
| 2850 |
pp_cxx_left_bracket (pp); |
| 2851 |
pp->translate_string ("with"); |
| 2852 |
pp_cxx_whitespace (pp); |
| 2853 |
|
| 2854 |
for (tree p = map; p; p = TREE_CHAIN (p)) |
| 2855 |
{ |
| 2856 |
tree parm = TREE_VALUE (p); |
| 2857 |
tree arg = TREE_PURPOSE (p); |
| 2858 |
|
| 2859 |
if (TYPE_P (parm)) |
| 2860 |
pp->type_id (parm); |
| 2861 |
else if (tree name = DECL_NAME (TEMPLATE_PARM_DECL (parm))) |
| 2862 |
pp_cxx_tree_identifier (pp, name); |
| 2863 |
else |
| 2864 |
pp->translate_string ("<unnamed>"); |
| 2865 |
|
| 2866 |
pp_cxx_whitespace (pp); |
| 2867 |
pp_equal (pp); |
| 2868 |
pp_cxx_whitespace (pp); |
| 2869 |
|
| 2870 |
if (TYPE_P (arg) || DECL_TEMPLATE_TEMPLATE_PARM_P (arg)) |
| 2871 |
pp->type_id (arg); |
| 2872 |
else |
| 2873 |
pp->expression (arg); |
| 2874 |
|
| 2875 |
if (TREE_CHAIN (p) != NULL_TREE) |
| 2876 |
pp_cxx_separate_with (pp, ';'); |
| 2877 |
} |
| 2878 |
|
| 2879 |
pp_cxx_right_bracket (pp); |
| 2880 |
} |
| 2881 |
|
| 2882 |
void |
| 2883 |
pp_cxx_atomic_constraint (cxx_pretty_printer *pp, tree t) |
| 2884 |
{ |
| 2885 |
/* Emit the expression. */ |
| 2886 |
pp->expression (ATOMIC_CONSTR_EXPR (t)); |
| 2887 |
|
| 2888 |
/* Emit the parameter mapping. */ |
| 2889 |
tree map = ATOMIC_CONSTR_MAP (t); |
| 2890 |
if (map && map != error_mark_node) |
| 2891 |
pp_cxx_parameter_mapping (pp, map); |
| 2892 |
} |
| 2893 |
|
| 2894 |
void |
| 2895 |
pp_cxx_conjunction (cxx_pretty_printer *pp, tree t) |
| 2896 |
{ |
| 2897 |
pp_cxx_constraint (pp, TREE_OPERAND (t, 0)); |
| 2898 |
pp_string (pp, " /\\ "); |
| 2899 |
pp_cxx_constraint (pp, TREE_OPERAND (t, 1)); |
| 2900 |
} |
| 2901 |
|
| 2902 |
void |
| 2903 |
pp_cxx_disjunction (cxx_pretty_printer *pp, tree t) |
| 2904 |
{ |
| 2905 |
pp_cxx_constraint (pp, TREE_OPERAND (t, 0)); |
| 2906 |
pp_string (pp, " \\/ "); |
| 2907 |
pp_cxx_constraint (pp, TREE_OPERAND (t, 1)); |
| 2908 |
} |
| 2909 |
|
| 2910 |
void |
| 2911 |
pp_cxx_constraint (cxx_pretty_printer *pp, tree t) |
| 2912 |
{ |
| 2913 |
if (t == error_mark_node) |
| 2914 |
return pp->expression (t); |
| 2915 |
|
| 2916 |
switch (TREE_CODE (t)) |
| 2917 |
{ |
| 2918 |
case ATOMIC_CONSTR: |
| 2919 |
pp_cxx_atomic_constraint (pp, t); |
| 2920 |
break; |
| 2921 |
|
| 2922 |
case CONJ_CONSTR: |
| 2923 |
pp_cxx_conjunction (pp, t); |
| 2924 |
break; |
| 2925 |
|
| 2926 |
case DISJ_CONSTR: |
| 2927 |
pp_cxx_disjunction (pp, t); |
| 2928 |
break; |
| 2929 |
|
| 2930 |
case EXPR_PACK_EXPANSION: |
| 2931 |
pp->expression (TREE_OPERAND (t, 0)); |
| 2932 |
break; |
| 2933 |
|
| 2934 |
default: |
| 2935 |
gcc_unreachable (); |
| 2936 |
} |
| 2937 |
} |
| 2938 |
|
| 2939 |
|
| 2940 |
typedef c_pretty_print_fn pp_fun; |
| 2941 |
|
| 2942 |
/* Initialization of a C++ pretty-printer object. */ |
| 2943 |
|
| 2944 |
cxx_pretty_printer::cxx_pretty_printer () |
| 2945 |
: c_pretty_printer (), |
| 2946 |
enclosing_scope (global_namespace) |
| 2947 |
{ |
| 2948 |
type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq; |
| 2949 |
parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause; |
| 2950 |
} |
| 2951 |
|
| 2952 |
/* cxx_pretty_printer's implementation of pretty_printer::clone vfunc. */ |
| 2953 |
|
| 2954 |
std::unique_ptr<pretty_printer> |
| 2955 |
cxx_pretty_printer::clone () const |
| 2956 |
{ |
| 2957 |
return ::make_unique<cxx_pretty_printer> (*this); |
| 2958 |
} |