| 1 |
/* General AST-related method implementations for Rust frontend. |
| 2 |
Copyright (C) 2009-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GCC. |
| 5 |
|
| 6 |
GCC is free software; you can redistribute it and/or modify it under |
| 7 |
the terms of the GNU General Public License as published by the Free |
| 8 |
Software Foundation; either version 3, or (at your option) any later |
| 9 |
version. |
| 10 |
|
| 11 |
GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 |
for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with GCC; see the file COPYING3. If not see |
| 18 |
<http://www.gnu.org/licenses/>. */ |
| 19 |
|
| 20 |
#include "rust-ast.h" |
| 21 |
#include "optional.h" |
| 22 |
#include "rust-builtin-ast-nodes.h" |
| 23 |
#include "rust-common.h" |
| 24 |
#include "rust-expr.h" |
| 25 |
#include "rust-system.h" |
| 26 |
#include "rust-ast-full.h" |
| 27 |
#include "rust-diagnostics.h" |
| 28 |
#include "rust-ast-visitor.h" |
| 29 |
#include "rust-macro.h" |
| 30 |
#include "rust-session-manager.h" |
| 31 |
#include "rust-lex.h" |
| 32 |
#include "rust-parse.h" |
| 33 |
#include "rust-operators.h" |
| 34 |
#include "rust-dir-owner.h" |
| 35 |
#include "rust-attribute-values.h" |
| 36 |
|
| 37 |
/* Compilation unit used for various AST-related functions that would make |
| 38 |
* the headers too long if they were defined inline and don't receive any |
| 39 |
* benefits from being defined inline because they are virtual. Also used |
| 40 |
* for various other stuff. */ |
| 41 |
|
| 42 |
namespace Rust { |
| 43 |
namespace AST { |
| 44 |
|
| 45 |
SingleASTNode::SingleASTNode (SingleASTNode const &other) |
| 46 |
{ |
| 47 |
kind = other.kind; |
| 48 |
switch (kind) |
| 49 |
{ |
| 50 |
case EXPRESSION: |
| 51 |
expr = other.expr->clone_expr (); |
| 52 |
break; |
| 53 |
|
| 54 |
case ITEM: |
| 55 |
item = other.item->clone_item (); |
| 56 |
break; |
| 57 |
|
| 58 |
case STMT: |
| 59 |
stmt = other.stmt->clone_stmt (); |
| 60 |
break; |
| 61 |
|
| 62 |
case EXTERN: |
| 63 |
external_item = other.external_item->clone_external_item (); |
| 64 |
break; |
| 65 |
|
| 66 |
case ASSOC_ITEM: |
| 67 |
assoc_item = other.assoc_item->clone_associated_item (); |
| 68 |
break; |
| 69 |
|
| 70 |
case TYPE: |
| 71 |
type = other.type->clone_type (); |
| 72 |
break; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
SingleASTNode |
| 77 |
SingleASTNode::operator= (SingleASTNode const &other) |
| 78 |
{ |
| 79 |
kind = other.kind; |
| 80 |
switch (kind) |
| 81 |
{ |
| 82 |
case EXPRESSION: |
| 83 |
expr = other.expr->clone_expr (); |
| 84 |
break; |
| 85 |
|
| 86 |
case ITEM: |
| 87 |
item = other.item->clone_item (); |
| 88 |
break; |
| 89 |
|
| 90 |
case STMT: |
| 91 |
stmt = other.stmt->clone_stmt (); |
| 92 |
break; |
| 93 |
|
| 94 |
case EXTERN: |
| 95 |
external_item = other.external_item->clone_external_item (); |
| 96 |
break; |
| 97 |
|
| 98 |
case ASSOC_ITEM: |
| 99 |
assoc_item = other.assoc_item->clone_associated_item (); |
| 100 |
break; |
| 101 |
|
| 102 |
case TYPE: |
| 103 |
type = other.type->clone_type (); |
| 104 |
break; |
| 105 |
} |
| 106 |
return *this; |
| 107 |
} |
| 108 |
|
| 109 |
void |
| 110 |
SingleASTNode::accept_vis (ASTVisitor &vis) |
| 111 |
{ |
| 112 |
switch (kind) |
| 113 |
{ |
| 114 |
case EXPRESSION: |
| 115 |
expr->accept_vis (vis); |
| 116 |
break; |
| 117 |
|
| 118 |
case ITEM: |
| 119 |
item->accept_vis (vis); |
| 120 |
break; |
| 121 |
|
| 122 |
case STMT: |
| 123 |
stmt->accept_vis (vis); |
| 124 |
break; |
| 125 |
|
| 126 |
case EXTERN: |
| 127 |
external_item->accept_vis (vis); |
| 128 |
break; |
| 129 |
|
| 130 |
case ASSOC_ITEM: |
| 131 |
assoc_item->accept_vis (vis); |
| 132 |
break; |
| 133 |
|
| 134 |
case TYPE: |
| 135 |
type->accept_vis (vis); |
| 136 |
break; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
bool |
| 141 |
SingleASTNode::is_error () |
| 142 |
{ |
| 143 |
switch (kind) |
| 144 |
{ |
| 145 |
case EXPRESSION: |
| 146 |
return expr == nullptr; |
| 147 |
case ITEM: |
| 148 |
return item == nullptr; |
| 149 |
case STMT: |
| 150 |
return stmt == nullptr; |
| 151 |
case EXTERN: |
| 152 |
return external_item == nullptr; |
| 153 |
case ASSOC_ITEM: |
| 154 |
return assoc_item == nullptr; |
| 155 |
case TYPE: |
| 156 |
return type == nullptr; |
| 157 |
} |
| 158 |
|
| 159 |
rust_unreachable (); |
| 160 |
return true; |
| 161 |
} |
| 162 |
|
| 163 |
std::string |
| 164 |
SingleASTNode::as_string () const |
| 165 |
{ |
| 166 |
switch (kind) |
| 167 |
{ |
| 168 |
case EXPRESSION: |
| 169 |
return "Expr: " + expr->as_string (); |
| 170 |
case ITEM: |
| 171 |
return "Item: " + item->as_string (); |
| 172 |
case STMT: |
| 173 |
return "Stmt: " + stmt->as_string (); |
| 174 |
case EXTERN: |
| 175 |
return "External Item: " + external_item->as_string (); |
| 176 |
case ASSOC_ITEM: |
| 177 |
return "Associated Item: " + assoc_item->as_string (); |
| 178 |
case TYPE: |
| 179 |
return "Type: " + type->as_string (); |
| 180 |
} |
| 181 |
|
| 182 |
rust_unreachable (); |
| 183 |
return ""; |
| 184 |
} |
| 185 |
|
| 186 |
std::string |
| 187 |
Crate::as_string () const |
| 188 |
{ |
| 189 |
rust_debug ("beginning crate recursive as-string"); |
| 190 |
|
| 191 |
std::string str ("Crate: "); |
| 192 |
|
| 193 |
// inner attributes |
| 194 |
str += append_attributes (inner_attrs, INNER); |
| 195 |
|
| 196 |
// items |
| 197 |
str += "\n items: "; |
| 198 |
if (items.empty ()) |
| 199 |
{ |
| 200 |
str += "none"; |
| 201 |
} |
| 202 |
else |
| 203 |
{ |
| 204 |
for (const auto &item : items) |
| 205 |
{ |
| 206 |
// DEBUG: null pointer check |
| 207 |
if (item == nullptr) |
| 208 |
{ |
| 209 |
rust_debug ("something really terrible has gone wrong - " |
| 210 |
"null pointer item in crate."); |
| 211 |
return "NULL_POINTER_MARK"; |
| 212 |
} |
| 213 |
|
| 214 |
str += "\n " + item->as_string (); |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
return str + "\n"; |
| 219 |
} |
| 220 |
|
| 221 |
std::string |
| 222 |
Attribute::as_string () const |
| 223 |
{ |
| 224 |
std::string path_str = path.as_string (); |
| 225 |
if (attr_input == nullptr) |
| 226 |
return path_str; |
| 227 |
else |
| 228 |
return path_str + attr_input->as_string (); |
| 229 |
} |
| 230 |
|
| 231 |
bool |
| 232 |
Attribute::is_derive () const |
| 233 |
{ |
| 234 |
return has_attr_input () && get_path () == "derive"; |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Returns a list of traits to derive from within a given attribute. |
| 239 |
* |
| 240 |
* @param attrs The attributes on the item to derive |
| 241 |
*/ |
| 242 |
std::vector<std::reference_wrapper<AST::SimplePath>> |
| 243 |
Attribute::get_traits_to_derive () |
| 244 |
{ |
| 245 |
rust_assert (this->is_derive ()); |
| 246 |
|
| 247 |
this->parse_attr_to_meta_item (); |
| 248 |
std::vector<std::reference_wrapper<AST::SimplePath>> result; |
| 249 |
auto &input = get_attr_input (); |
| 250 |
switch (input.get_attr_input_type ()) |
| 251 |
{ |
| 252 |
case AST::AttrInput::META_ITEM: { |
| 253 |
auto &meta = static_cast<AST::AttrInputMetaItemContainer &> (input); |
| 254 |
for (auto ¤t : meta.get_items ()) |
| 255 |
{ |
| 256 |
// HACK: Find a better way to achieve the downcast. |
| 257 |
switch (current->get_kind ()) |
| 258 |
{ |
| 259 |
case AST::MetaItemInner::Kind::MetaItem: { |
| 260 |
// Let raw pointer go out of scope without freeing, it doesn't |
| 261 |
// own the data anyway |
| 262 |
auto meta_item |
| 263 |
= static_cast<AST::MetaItem *> (current.get ()); |
| 264 |
switch (meta_item->get_item_kind ()) |
| 265 |
{ |
| 266 |
case AST::MetaItem::ItemKind::Path: { |
| 267 |
auto path |
| 268 |
= static_cast<AST::MetaItemPath *> (meta_item); |
| 269 |
result.push_back (path->get_path ()); |
| 270 |
} |
| 271 |
break; |
| 272 |
case AST::MetaItem::ItemKind::Word: { |
| 273 |
auto word = static_cast<AST::MetaWord *> (meta_item); |
| 274 |
// Convert current word to path |
| 275 |
current = std::make_unique<AST::MetaItemPath> ( |
| 276 |
AST::MetaItemPath ( |
| 277 |
AST::SimplePath (word->get_ident ()))); |
| 278 |
auto path |
| 279 |
= static_cast<AST::MetaItemPath *> (current.get ()); |
| 280 |
|
| 281 |
result.push_back (path->get_path ()); |
| 282 |
} |
| 283 |
break; |
| 284 |
case AST::MetaItem::ItemKind::ListPaths: |
| 285 |
case AST::MetaItem::ItemKind::NameValueStr: |
| 286 |
case AST::MetaItem::ItemKind::PathLit: |
| 287 |
case AST::MetaItem::ItemKind::Seq: |
| 288 |
case AST::MetaItem::ItemKind::ListNameValueStr: |
| 289 |
default: |
| 290 |
gcc_unreachable (); |
| 291 |
break; |
| 292 |
} |
| 293 |
} |
| 294 |
break; |
| 295 |
case AST::MetaItemInner::Kind::LitExpr: |
| 296 |
default: |
| 297 |
gcc_unreachable (); |
| 298 |
break; |
| 299 |
} |
| 300 |
} |
| 301 |
} |
| 302 |
break; |
| 303 |
case AST::AttrInput::TOKEN_TREE: |
| 304 |
case AST::AttrInput::LITERAL: |
| 305 |
case AST::AttrInput::MACRO: |
| 306 |
rust_unreachable (); |
| 307 |
break; |
| 308 |
} |
| 309 |
return result; |
| 310 |
} |
| 311 |
|
| 312 |
// Copy constructor must deep copy attr_input as unique pointer |
| 313 |
Attribute::Attribute (Attribute const &other) |
| 314 |
: path (other.path), locus (other.locus), |
| 315 |
inner_attribute (other.inner_attribute) |
| 316 |
{ |
| 317 |
// guard to protect from null pointer dereference |
| 318 |
if (other.attr_input != nullptr) |
| 319 |
attr_input = other.attr_input->clone_attr_input (); |
| 320 |
} |
| 321 |
|
| 322 |
// overload assignment operator to use custom clone method |
| 323 |
Attribute & |
| 324 |
Attribute::operator= (Attribute const &other) |
| 325 |
{ |
| 326 |
path = other.path; |
| 327 |
locus = other.locus; |
| 328 |
inner_attribute = other.inner_attribute; |
| 329 |
// guard to protect from null pointer dereference |
| 330 |
if (other.attr_input != nullptr) |
| 331 |
attr_input = other.attr_input->clone_attr_input (); |
| 332 |
else |
| 333 |
attr_input = nullptr; |
| 334 |
|
| 335 |
return *this; |
| 336 |
} |
| 337 |
|
| 338 |
std::string |
| 339 |
DelimTokenTree::as_string () const |
| 340 |
{ |
| 341 |
std::string start_delim; |
| 342 |
std::string end_delim; |
| 343 |
switch (delim_type) |
| 344 |
{ |
| 345 |
case PARENS: |
| 346 |
start_delim = "("; |
| 347 |
end_delim = ")"; |
| 348 |
break; |
| 349 |
case SQUARE: |
| 350 |
start_delim = "["; |
| 351 |
end_delim = "]"; |
| 352 |
break; |
| 353 |
case CURLY: |
| 354 |
start_delim = "{"; |
| 355 |
end_delim = "}"; |
| 356 |
break; |
| 357 |
default: |
| 358 |
rust_debug ("Invalid delimiter type, " |
| 359 |
"Should be PARENS, SQUARE, or CURLY."); |
| 360 |
return "Invalid delimiter type"; |
| 361 |
} |
| 362 |
std::string str = start_delim; |
| 363 |
if (!token_trees.empty ()) |
| 364 |
{ |
| 365 |
for (const auto &tree : token_trees) |
| 366 |
{ |
| 367 |
// DEBUG: null pointer check |
| 368 |
if (tree == nullptr) |
| 369 |
{ |
| 370 |
rust_debug ( |
| 371 |
"something really terrible has gone wrong - null pointer " |
| 372 |
"token tree in delim token tree."); |
| 373 |
return "NULL_POINTER_MARK"; |
| 374 |
} |
| 375 |
|
| 376 |
str += tree->as_string (); |
| 377 |
} |
| 378 |
} |
| 379 |
str += end_delim; |
| 380 |
|
| 381 |
return str; |
| 382 |
} |
| 383 |
|
| 384 |
std::string |
| 385 |
Token::as_string () const |
| 386 |
{ |
| 387 |
if (tok_ref->has_str ()) |
| 388 |
{ |
| 389 |
std::string str = tok_ref->get_str (); |
| 390 |
|
| 391 |
std::string quote = is_string_lit () ? "\"" : ""; |
| 392 |
return quote + str + quote; |
| 393 |
} |
| 394 |
else |
| 395 |
{ |
| 396 |
return tok_ref->get_token_description (); |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
std::string |
| 401 |
SimplePathSegment::as_string () const |
| 402 |
{ |
| 403 |
return segment_name; |
| 404 |
} |
| 405 |
|
| 406 |
const std::string |
| 407 |
SimplePath::as_string () const |
| 408 |
{ |
| 409 |
std::string path; |
| 410 |
if (opening_scope_resolution) |
| 411 |
path = "::"; |
| 412 |
|
| 413 |
// crappy hack because doing proper for loop would be more code |
| 414 |
bool first_time = true; |
| 415 |
for (const auto &segment : segments) |
| 416 |
{ |
| 417 |
if (first_time) |
| 418 |
{ |
| 419 |
path += segment.as_string (); |
| 420 |
first_time = false; |
| 421 |
} |
| 422 |
else |
| 423 |
{ |
| 424 |
path += "::" + segment.as_string (); |
| 425 |
} |
| 426 |
|
| 427 |
// DEBUG: remove later. Checks for path error. |
| 428 |
if (segment.is_error ()) |
| 429 |
{ |
| 430 |
rust_debug ("segment in path is error - this should've been filtered " |
| 431 |
"out. first segment " |
| 432 |
"was '%s'", |
| 433 |
segments.at (0).as_string ().c_str ()); |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
return path; |
| 438 |
} |
| 439 |
|
| 440 |
std::string |
| 441 |
Visibility::as_string () const |
| 442 |
{ |
| 443 |
switch (vis_type) |
| 444 |
{ |
| 445 |
case PRIV: |
| 446 |
return std::string (""); |
| 447 |
case PUB: |
| 448 |
return std::string ("pub"); |
| 449 |
case PUB_CRATE: |
| 450 |
return std::string ("pub(crate)"); |
| 451 |
case PUB_SELF: |
| 452 |
return std::string ("pub(self)"); |
| 453 |
case PUB_SUPER: |
| 454 |
return std::string ("pub(super)"); |
| 455 |
case PUB_IN_PATH: |
| 456 |
return std::string ("pub(in ") + in_path.as_string () + std::string (")"); |
| 457 |
default: |
| 458 |
rust_unreachable (); |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
// Creates a string that reflects the visibility stored. |
| 463 |
std::string |
| 464 |
VisItem::as_string () const |
| 465 |
{ |
| 466 |
// FIXME: can't do formatting on string to make identation occur. |
| 467 |
std::string str; |
| 468 |
|
| 469 |
if (!outer_attrs.empty ()) |
| 470 |
{ |
| 471 |
for (const auto &attr : outer_attrs) |
| 472 |
str += attr.as_string () + "\n"; |
| 473 |
} |
| 474 |
|
| 475 |
if (has_visibility ()) |
| 476 |
str += visibility.as_string () + " "; |
| 477 |
|
| 478 |
return str; |
| 479 |
} |
| 480 |
|
| 481 |
std::string |
| 482 |
Module::as_string () const |
| 483 |
{ |
| 484 |
std::string str = VisItem::as_string () + "mod " + module_name.as_string (); |
| 485 |
|
| 486 |
// Return early if we're dealing with an unloaded module as their body resides |
| 487 |
// in a different file |
| 488 |
if (kind == ModuleKind::UNLOADED) |
| 489 |
return str + "\n no body (reference to external file)\n"; |
| 490 |
|
| 491 |
// inner attributes |
| 492 |
str += append_attributes (inner_attrs, INNER); |
| 493 |
|
| 494 |
// items |
| 495 |
str += "\n items: "; |
| 496 |
|
| 497 |
// This can still happen if the module is loaded but empty, i.e. `mod foo {}` |
| 498 |
if (items.empty ()) |
| 499 |
{ |
| 500 |
str += "none"; |
| 501 |
} |
| 502 |
else |
| 503 |
{ |
| 504 |
for (const auto &item : items) |
| 505 |
{ |
| 506 |
// DEBUG: null pointer check |
| 507 |
if (item == nullptr) |
| 508 |
{ |
| 509 |
rust_debug ("something really terrible has gone wrong - " |
| 510 |
"null pointer item in crate."); |
| 511 |
return "NULL_POINTER_MARK"; |
| 512 |
} |
| 513 |
|
| 514 |
str += "\n " + item->as_string (); |
| 515 |
} |
| 516 |
} |
| 517 |
|
| 518 |
return str + "\n"; |
| 519 |
} |
| 520 |
|
| 521 |
std::string |
| 522 |
StaticItem::as_string () const |
| 523 |
{ |
| 524 |
std::string str = VisItem::as_string (); |
| 525 |
|
| 526 |
str += indent_spaces (stay) + "static"; |
| 527 |
|
| 528 |
if (has_mut) |
| 529 |
str += " mut"; |
| 530 |
|
| 531 |
str += " " + name.as_string (); |
| 532 |
|
| 533 |
// DEBUG: null pointer check |
| 534 |
if (type == nullptr) |
| 535 |
{ |
| 536 |
rust_debug ("something really terrible has gone wrong - null " |
| 537 |
"pointer type in static item."); |
| 538 |
return "NULL_POINTER_MARK"; |
| 539 |
} |
| 540 |
str += "\n" + indent_spaces (stay) + "Type: " + type->as_string (); |
| 541 |
|
| 542 |
// DEBUG: null pointer check |
| 543 |
if (expr == nullptr) |
| 544 |
{ |
| 545 |
rust_debug ("something really terrible has gone wrong - null " |
| 546 |
"pointer expr in static item."); |
| 547 |
return "NULL_POINTER_MARK"; |
| 548 |
} |
| 549 |
str += "\n" + indent_spaces (stay) + "Expression: " + expr->as_string (); |
| 550 |
|
| 551 |
return str + "\n"; |
| 552 |
} |
| 553 |
|
| 554 |
std::string |
| 555 |
ExternCrate::as_string () const |
| 556 |
{ |
| 557 |
std::string str = VisItem::as_string (); |
| 558 |
|
| 559 |
str += "extern crate " + referenced_crate; |
| 560 |
|
| 561 |
if (has_as_clause ()) |
| 562 |
str += " as " + as_clause_name; |
| 563 |
|
| 564 |
return str; |
| 565 |
} |
| 566 |
|
| 567 |
std::string |
| 568 |
TupleStruct::as_string () const |
| 569 |
{ |
| 570 |
std::string str = VisItem::as_string (); |
| 571 |
|
| 572 |
str += "struct " + struct_name.as_string (); |
| 573 |
|
| 574 |
// generic params |
| 575 |
str += "\n Generic params: "; |
| 576 |
if (generic_params.empty ()) |
| 577 |
{ |
| 578 |
str += "none"; |
| 579 |
} |
| 580 |
else |
| 581 |
{ |
| 582 |
for (const auto ¶m : generic_params) |
| 583 |
{ |
| 584 |
// DEBUG: null pointer check |
| 585 |
if (param == nullptr) |
| 586 |
{ |
| 587 |
rust_debug ( |
| 588 |
"something really terrible has gone wrong - null pointer " |
| 589 |
"generic param in enum."); |
| 590 |
return "NULL_POINTER_MARK"; |
| 591 |
} |
| 592 |
|
| 593 |
str += "\n " + param->as_string (); |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
// tuple fields |
| 598 |
str += "\n Tuple fields: "; |
| 599 |
if (fields.empty ()) |
| 600 |
{ |
| 601 |
str += "none"; |
| 602 |
} |
| 603 |
else |
| 604 |
{ |
| 605 |
for (const auto &field : fields) |
| 606 |
str += "\n " + field.as_string (); |
| 607 |
} |
| 608 |
|
| 609 |
str += "\n Where clause: "; |
| 610 |
if (has_where_clause ()) |
| 611 |
str += where_clause.as_string (); |
| 612 |
else |
| 613 |
str += "none"; |
| 614 |
|
| 615 |
return str; |
| 616 |
} |
| 617 |
|
| 618 |
std::string |
| 619 |
ConstantItem::as_string () const |
| 620 |
{ |
| 621 |
std::string str = VisItem::as_string (); |
| 622 |
|
| 623 |
str += "const " + identifier; |
| 624 |
|
| 625 |
// DEBUG: null pointer check |
| 626 |
if (type == nullptr) |
| 627 |
{ |
| 628 |
rust_debug ("something really terrible has gone wrong - null " |
| 629 |
"pointer type in const item."); |
| 630 |
return "NULL_POINTER_MARK"; |
| 631 |
} |
| 632 |
str += "\n Type: " + type->as_string (); |
| 633 |
|
| 634 |
// DEBUG: null pointer check |
| 635 |
if (const_expr == nullptr) |
| 636 |
{ |
| 637 |
rust_debug ("something really terrible has gone wrong - null " |
| 638 |
"pointer expr in const item."); |
| 639 |
return "NULL_POINTER_MARK"; |
| 640 |
} |
| 641 |
str += "\n Expression: " + const_expr->as_string (); |
| 642 |
|
| 643 |
return str + "\n"; |
| 644 |
} |
| 645 |
|
| 646 |
std::string |
| 647 |
InherentImpl::as_string () const |
| 648 |
{ |
| 649 |
std::string str = VisItem::as_string (); |
| 650 |
|
| 651 |
str += "impl "; |
| 652 |
|
| 653 |
// generic params |
| 654 |
str += "\n Generic params: "; |
| 655 |
if (generic_params.empty ()) |
| 656 |
{ |
| 657 |
str += "none"; |
| 658 |
} |
| 659 |
else |
| 660 |
{ |
| 661 |
for (const auto ¶m : generic_params) |
| 662 |
{ |
| 663 |
// DEBUG: null pointer check |
| 664 |
if (param == nullptr) |
| 665 |
{ |
| 666 |
rust_debug ( |
| 667 |
"something really terrible has gone wrong - null pointer " |
| 668 |
"generic param in inherent impl."); |
| 669 |
return "NULL_POINTER_MARK"; |
| 670 |
} |
| 671 |
|
| 672 |
str += "\n " + param->as_string (); |
| 673 |
} |
| 674 |
} |
| 675 |
|
| 676 |
str += "\n Type: " + trait_type->as_string (); |
| 677 |
|
| 678 |
str += "\n Where clause: "; |
| 679 |
if (has_where_clause ()) |
| 680 |
str += where_clause.as_string (); |
| 681 |
else |
| 682 |
str += "none"; |
| 683 |
|
| 684 |
// inner attributes |
| 685 |
str += append_attributes (inner_attrs, INNER); |
| 686 |
|
| 687 |
// inherent impl items |
| 688 |
str += "\n Inherent impl items: "; |
| 689 |
if (!has_impl_items ()) |
| 690 |
{ |
| 691 |
str += "none"; |
| 692 |
} |
| 693 |
else |
| 694 |
{ |
| 695 |
for (const auto &item : impl_items) |
| 696 |
str += "\n " + item->as_string (); |
| 697 |
} |
| 698 |
|
| 699 |
return str; |
| 700 |
} |
| 701 |
|
| 702 |
std::string |
| 703 |
StructStruct::as_string () const |
| 704 |
{ |
| 705 |
std::string str = VisItem::as_string (); |
| 706 |
|
| 707 |
str += "struct " + struct_name.as_string (); |
| 708 |
|
| 709 |
// generic params |
| 710 |
str += "\n Generic params: "; |
| 711 |
if (generic_params.empty ()) |
| 712 |
{ |
| 713 |
str += "none"; |
| 714 |
} |
| 715 |
else |
| 716 |
{ |
| 717 |
for (const auto ¶m : generic_params) |
| 718 |
{ |
| 719 |
// DEBUG: null pointer check |
| 720 |
if (param == nullptr) |
| 721 |
{ |
| 722 |
rust_debug ( |
| 723 |
"something really terrible has gone wrong - null pointer " |
| 724 |
"generic param in enum."); |
| 725 |
return "NULL_POINTER_MARK"; |
| 726 |
} |
| 727 |
|
| 728 |
str += "\n " + param->as_string (); |
| 729 |
} |
| 730 |
} |
| 731 |
|
| 732 |
str += "\n Where clause: "; |
| 733 |
if (has_where_clause ()) |
| 734 |
str += where_clause.as_string (); |
| 735 |
else |
| 736 |
str += "none"; |
| 737 |
|
| 738 |
// struct fields |
| 739 |
str += "\n Struct fields: "; |
| 740 |
if (is_unit) |
| 741 |
{ |
| 742 |
str += "none (unit)"; |
| 743 |
} |
| 744 |
else if (fields.empty ()) |
| 745 |
{ |
| 746 |
str += "none (non-unit)"; |
| 747 |
} |
| 748 |
else |
| 749 |
{ |
| 750 |
for (const auto &field : fields) |
| 751 |
str += "\n " + field.as_string (); |
| 752 |
} |
| 753 |
|
| 754 |
return str; |
| 755 |
} |
| 756 |
|
| 757 |
std::string |
| 758 |
UseDeclaration::as_string () const |
| 759 |
{ |
| 760 |
std::string str = VisItem::as_string (); |
| 761 |
|
| 762 |
// DEBUG: null pointer check |
| 763 |
if (use_tree == nullptr) |
| 764 |
{ |
| 765 |
rust_debug ( |
| 766 |
"something really terrible has gone wrong - null pointer use tree in " |
| 767 |
"use declaration."); |
| 768 |
return "NULL_POINTER_MARK"; |
| 769 |
} |
| 770 |
|
| 771 |
str += "use " + use_tree->as_string (); |
| 772 |
|
| 773 |
return str; |
| 774 |
} |
| 775 |
|
| 776 |
std::string |
| 777 |
UseTreeGlob::as_string () const |
| 778 |
{ |
| 779 |
switch (glob_type) |
| 780 |
{ |
| 781 |
case NO_PATH: |
| 782 |
return "*"; |
| 783 |
case GLOBAL: |
| 784 |
return "::*"; |
| 785 |
case PATH_PREFIXED: { |
| 786 |
std::string path_str = path.as_string (); |
| 787 |
return path_str + "::*"; |
| 788 |
} |
| 789 |
default: |
| 790 |
// some kind of error |
| 791 |
return "ERROR-PATH"; |
| 792 |
} |
| 793 |
rust_unreachable (); |
| 794 |
} |
| 795 |
|
| 796 |
std::string |
| 797 |
UseTreeList::as_string () const |
| 798 |
{ |
| 799 |
std::string path_str; |
| 800 |
switch (path_type) |
| 801 |
{ |
| 802 |
case NO_PATH: |
| 803 |
path_str = "{"; |
| 804 |
break; |
| 805 |
case GLOBAL: |
| 806 |
path_str = "::{"; |
| 807 |
break; |
| 808 |
case PATH_PREFIXED: { |
| 809 |
path_str = path.as_string () + "::{"; |
| 810 |
break; |
| 811 |
} |
| 812 |
default: |
| 813 |
// some kind of error |
| 814 |
return "ERROR-PATH-LIST"; |
| 815 |
} |
| 816 |
|
| 817 |
if (has_trees ()) |
| 818 |
{ |
| 819 |
auto i = trees.begin (); |
| 820 |
auto e = trees.end (); |
| 821 |
|
| 822 |
// DEBUG: null pointer check |
| 823 |
if (*i == nullptr) |
| 824 |
{ |
| 825 |
rust_debug ("something really terrible has gone wrong - null pointer " |
| 826 |
"tree in use tree list."); |
| 827 |
return "NULL_POINTER_MARK"; |
| 828 |
} |
| 829 |
|
| 830 |
for (; i != e; i++) |
| 831 |
{ |
| 832 |
path_str += (*i)->as_string (); |
| 833 |
if (e != i + 1) |
| 834 |
path_str += ", "; |
| 835 |
} |
| 836 |
} |
| 837 |
else |
| 838 |
{ |
| 839 |
path_str += "none"; |
| 840 |
} |
| 841 |
|
| 842 |
return path_str + "}"; |
| 843 |
} |
| 844 |
|
| 845 |
std::string |
| 846 |
UseTreeRebind::as_string () const |
| 847 |
{ |
| 848 |
std::string path_str = path.as_string (); |
| 849 |
|
| 850 |
switch (bind_type) |
| 851 |
{ |
| 852 |
case NONE: |
| 853 |
// nothing to add, just path |
| 854 |
break; |
| 855 |
case IDENTIFIER: |
| 856 |
path_str += " as " + identifier.as_string (); |
| 857 |
break; |
| 858 |
case WILDCARD: |
| 859 |
path_str += " as _"; |
| 860 |
break; |
| 861 |
default: |
| 862 |
// error |
| 863 |
return "ERROR-PATH-REBIND"; |
| 864 |
} |
| 865 |
|
| 866 |
return path_str; |
| 867 |
} |
| 868 |
|
| 869 |
std::string |
| 870 |
Enum::as_string () const |
| 871 |
{ |
| 872 |
std::string str = VisItem::as_string (); |
| 873 |
str += enum_name.as_string (); |
| 874 |
|
| 875 |
// generic params |
| 876 |
str += "\n Generic params: "; |
| 877 |
if (generic_params.empty ()) |
| 878 |
{ |
| 879 |
str += "none"; |
| 880 |
} |
| 881 |
else |
| 882 |
{ |
| 883 |
for (const auto ¶m : generic_params) |
| 884 |
{ |
| 885 |
// DEBUG: null pointer check |
| 886 |
if (param == nullptr) |
| 887 |
{ |
| 888 |
rust_debug ( |
| 889 |
"something really terrible has gone wrong - null pointer " |
| 890 |
"generic param in enum."); |
| 891 |
return "NULL_POINTER_MARK"; |
| 892 |
} |
| 893 |
|
| 894 |
str += "\n " + param->as_string (); |
| 895 |
} |
| 896 |
} |
| 897 |
|
| 898 |
str += "\n Where clause: "; |
| 899 |
if (has_where_clause ()) |
| 900 |
str += where_clause.as_string (); |
| 901 |
else |
| 902 |
str += "none"; |
| 903 |
|
| 904 |
// items |
| 905 |
str += "\n Items: "; |
| 906 |
if (items.empty ()) |
| 907 |
{ |
| 908 |
str += "none"; |
| 909 |
} |
| 910 |
else |
| 911 |
{ |
| 912 |
for (const auto &item : items) |
| 913 |
{ |
| 914 |
// DEBUG: null pointer check |
| 915 |
if (item == nullptr) |
| 916 |
{ |
| 917 |
rust_debug ( |
| 918 |
"something really terrible has gone wrong - null pointer " |
| 919 |
"enum item in enum."); |
| 920 |
return "NULL_POINTER_MARK"; |
| 921 |
} |
| 922 |
|
| 923 |
str += "\n " + item->as_string (); |
| 924 |
} |
| 925 |
} |
| 926 |
|
| 927 |
return str; |
| 928 |
} |
| 929 |
|
| 930 |
std::string |
| 931 |
Trait::as_string () const |
| 932 |
{ |
| 933 |
std::string str = VisItem::as_string (); |
| 934 |
|
| 935 |
if (has_unsafe) |
| 936 |
str += "unsafe "; |
| 937 |
|
| 938 |
str += "trait " + name.as_string (); |
| 939 |
|
| 940 |
// generic params |
| 941 |
str += "\n Generic params: "; |
| 942 |
if (generic_params.empty ()) |
| 943 |
{ |
| 944 |
str += "none"; |
| 945 |
} |
| 946 |
else |
| 947 |
{ |
| 948 |
for (const auto ¶m : generic_params) |
| 949 |
{ |
| 950 |
// DEBUG: null pointer check |
| 951 |
if (param == nullptr) |
| 952 |
{ |
| 953 |
rust_debug ( |
| 954 |
"something really terrible has gone wrong - null pointer " |
| 955 |
"generic param in trait."); |
| 956 |
return "NULL_POINTER_MARK"; |
| 957 |
} |
| 958 |
|
| 959 |
str += "\n " + param->as_string (); |
| 960 |
} |
| 961 |
} |
| 962 |
|
| 963 |
str += "\n Type param bounds: "; |
| 964 |
if (!has_type_param_bounds ()) |
| 965 |
{ |
| 966 |
str += "none"; |
| 967 |
} |
| 968 |
else |
| 969 |
{ |
| 970 |
for (const auto &bound : type_param_bounds) |
| 971 |
{ |
| 972 |
// DEBUG: null pointer check |
| 973 |
if (bound == nullptr) |
| 974 |
{ |
| 975 |
rust_debug ( |
| 976 |
"something really terrible has gone wrong - null pointer " |
| 977 |
"type param bound in trait."); |
| 978 |
return "NULL_POINTER_MARK"; |
| 979 |
} |
| 980 |
|
| 981 |
str += "\n " + bound->as_string (); |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
str += "\n Where clause: "; |
| 986 |
if (!has_where_clause ()) |
| 987 |
str += "none"; |
| 988 |
else |
| 989 |
str += where_clause.as_string (); |
| 990 |
|
| 991 |
str += "\n Trait items: "; |
| 992 |
if (!has_trait_items ()) |
| 993 |
{ |
| 994 |
str += "none"; |
| 995 |
} |
| 996 |
else |
| 997 |
{ |
| 998 |
for (const auto &item : trait_items) |
| 999 |
{ |
| 1000 |
// DEBUG: null pointer check |
| 1001 |
if (item == nullptr) |
| 1002 |
{ |
| 1003 |
rust_debug ( |
| 1004 |
"something really terrible has gone wrong - null pointer " |
| 1005 |
"trait item in trait."); |
| 1006 |
return "NULL_POINTER_MARK"; |
| 1007 |
} |
| 1008 |
|
| 1009 |
str += "\n " + item->as_string (); |
| 1010 |
} |
| 1011 |
} |
| 1012 |
|
| 1013 |
return str; |
| 1014 |
} |
| 1015 |
|
| 1016 |
std::string |
| 1017 |
Union::as_string () const |
| 1018 |
{ |
| 1019 |
std::string str = VisItem::as_string (); |
| 1020 |
|
| 1021 |
str += "union " + union_name.as_string (); |
| 1022 |
|
| 1023 |
// generic params |
| 1024 |
str += "\n Generic params: "; |
| 1025 |
if (generic_params.empty ()) |
| 1026 |
{ |
| 1027 |
str += "none"; |
| 1028 |
} |
| 1029 |
else |
| 1030 |
{ |
| 1031 |
for (const auto ¶m : generic_params) |
| 1032 |
{ |
| 1033 |
// DEBUG: null pointer check |
| 1034 |
if (param == nullptr) |
| 1035 |
{ |
| 1036 |
rust_debug ( |
| 1037 |
"something really terrible has gone wrong - null pointer " |
| 1038 |
"generic param in union."); |
| 1039 |
return "NULL_POINTER_MARK"; |
| 1040 |
} |
| 1041 |
|
| 1042 |
str += "\n " + param->as_string (); |
| 1043 |
} |
| 1044 |
} |
| 1045 |
|
| 1046 |
str += "\n Where clause: "; |
| 1047 |
if (has_where_clause ()) |
| 1048 |
str += where_clause.as_string (); |
| 1049 |
else |
| 1050 |
str += "none"; |
| 1051 |
|
| 1052 |
// struct fields |
| 1053 |
str += "\n Struct fields (variants): "; |
| 1054 |
if (variants.empty ()) |
| 1055 |
{ |
| 1056 |
str += "none"; |
| 1057 |
} |
| 1058 |
else |
| 1059 |
{ |
| 1060 |
for (const auto &field : variants) |
| 1061 |
str += "\n " + field.as_string (); |
| 1062 |
} |
| 1063 |
|
| 1064 |
return str; |
| 1065 |
} |
| 1066 |
|
| 1067 |
Function::Function (Function const &other) |
| 1068 |
: VisItem (other), ExternalItem (other.get_node_id ()), |
| 1069 |
qualifiers (other.qualifiers), function_name (other.function_name), |
| 1070 |
where_clause (other.where_clause), locus (other.locus), |
| 1071 |
has_default (other.has_default), |
| 1072 |
is_external_function (other.is_external_function) |
| 1073 |
{ |
| 1074 |
// guard to prevent null dereference (always required) |
| 1075 |
if (other.return_type != nullptr) |
| 1076 |
return_type = other.return_type->clone_type (); |
| 1077 |
|
| 1078 |
// guard to prevent null dereference (only required if error state) |
| 1079 |
if (other.has_body ()) |
| 1080 |
function_body = other.function_body.value ()->clone_block_expr (); |
| 1081 |
else |
| 1082 |
function_body = tl::nullopt; |
| 1083 |
|
| 1084 |
generic_params.reserve (other.generic_params.size ()); |
| 1085 |
for (const auto &e : other.generic_params) |
| 1086 |
generic_params.push_back (e->clone_generic_param ()); |
| 1087 |
|
| 1088 |
function_params.reserve (other.function_params.size ()); |
| 1089 |
for (const auto &e : other.function_params) |
| 1090 |
function_params.push_back (e->clone_param ()); |
| 1091 |
} |
| 1092 |
|
| 1093 |
Function & |
| 1094 |
Function::operator= (Function const &other) |
| 1095 |
{ |
| 1096 |
VisItem::operator= (other); |
| 1097 |
function_name = other.function_name; |
| 1098 |
qualifiers = other.qualifiers; |
| 1099 |
where_clause = other.where_clause; |
| 1100 |
// visibility = other.visibility->clone_visibility(); |
| 1101 |
// outer_attrs = other.outer_attrs; |
| 1102 |
locus = other.locus; |
| 1103 |
has_default = other.has_default; |
| 1104 |
is_external_function = other.is_external_function; |
| 1105 |
|
| 1106 |
// guard to prevent null dereference (always required) |
| 1107 |
if (other.return_type != nullptr) |
| 1108 |
return_type = other.return_type->clone_type (); |
| 1109 |
else |
| 1110 |
return_type = nullptr; |
| 1111 |
|
| 1112 |
// guard to prevent null dereference (only required if error state) |
| 1113 |
if (other.has_body ()) |
| 1114 |
function_body = other.function_body.value ()->clone_block_expr (); |
| 1115 |
else |
| 1116 |
function_body = tl::nullopt; |
| 1117 |
|
| 1118 |
generic_params.reserve (other.generic_params.size ()); |
| 1119 |
for (const auto &e : other.generic_params) |
| 1120 |
generic_params.push_back (e->clone_generic_param ()); |
| 1121 |
|
| 1122 |
function_params.reserve (other.function_params.size ()); |
| 1123 |
for (const auto &e : other.function_params) |
| 1124 |
function_params.push_back (e->clone_param ()); |
| 1125 |
|
| 1126 |
return *this; |
| 1127 |
} |
| 1128 |
std::string |
| 1129 |
Function::as_string () const |
| 1130 |
{ |
| 1131 |
std::string str = VisItem::as_string () + "\n"; |
| 1132 |
std::string qstr = qualifiers.as_string (); |
| 1133 |
if ("" != qstr) |
| 1134 |
str += qstr + " "; |
| 1135 |
|
| 1136 |
if (has_return_type ()) |
| 1137 |
{ |
| 1138 |
// DEBUG: null pointer check |
| 1139 |
if (return_type == nullptr) |
| 1140 |
{ |
| 1141 |
rust_debug ( |
| 1142 |
"something really terrible has gone wrong - null pointer return " |
| 1143 |
"type in function."); |
| 1144 |
return "NULL_POINTER_MARK"; |
| 1145 |
} |
| 1146 |
|
| 1147 |
str += return_type->as_string () + " "; |
| 1148 |
} |
| 1149 |
else |
| 1150 |
{ |
| 1151 |
str += "void "; |
| 1152 |
} |
| 1153 |
|
| 1154 |
str += function_name.as_string (); |
| 1155 |
|
| 1156 |
if (has_generics ()) |
| 1157 |
{ |
| 1158 |
str += "<"; |
| 1159 |
|
| 1160 |
auto i = generic_params.begin (); |
| 1161 |
auto e = generic_params.end (); |
| 1162 |
|
| 1163 |
// DEBUG: null pointer check |
| 1164 |
if (i == e) |
| 1165 |
{ |
| 1166 |
rust_debug ("something really terrible has gone wrong - null pointer " |
| 1167 |
"generic param in function item."); |
| 1168 |
return "NULL_POINTER_MARK"; |
| 1169 |
} |
| 1170 |
|
| 1171 |
for (; i != e; i++) |
| 1172 |
{ |
| 1173 |
str += (*i)->as_string (); |
| 1174 |
if (e != i + 1) |
| 1175 |
str += ", "; |
| 1176 |
} |
| 1177 |
str += ">"; |
| 1178 |
} |
| 1179 |
|
| 1180 |
if (has_function_params ()) |
| 1181 |
{ |
| 1182 |
auto i = function_params.begin (); |
| 1183 |
auto e = function_params.end (); |
| 1184 |
str += "("; |
| 1185 |
for (; i != e; i++) |
| 1186 |
{ |
| 1187 |
str += (*i)->as_string (); |
| 1188 |
if (e != i + 1) |
| 1189 |
str += ", "; |
| 1190 |
} |
| 1191 |
str += ")"; |
| 1192 |
} |
| 1193 |
else |
| 1194 |
{ |
| 1195 |
str += "()"; |
| 1196 |
} |
| 1197 |
|
| 1198 |
if (has_where_clause ()) |
| 1199 |
str += " where " + where_clause.as_string (); |
| 1200 |
|
| 1201 |
str += "\n"; |
| 1202 |
|
| 1203 |
if (has_body ()) |
| 1204 |
str += function_body.value ()->as_string () + "\n"; |
| 1205 |
|
| 1206 |
return str; |
| 1207 |
} |
| 1208 |
|
| 1209 |
std::string |
| 1210 |
WhereClause::as_string () const |
| 1211 |
{ |
| 1212 |
// just print where clause items, don't mention "where" or "where clause" |
| 1213 |
std::string str; |
| 1214 |
|
| 1215 |
if (where_clause_items.empty ()) |
| 1216 |
{ |
| 1217 |
str = "none"; |
| 1218 |
} |
| 1219 |
else |
| 1220 |
{ |
| 1221 |
for (const auto &item : where_clause_items) |
| 1222 |
str += "\n " + item->as_string (); |
| 1223 |
} |
| 1224 |
|
| 1225 |
return str; |
| 1226 |
} |
| 1227 |
|
| 1228 |
std::string |
| 1229 |
BlockExpr::as_string () const |
| 1230 |
{ |
| 1231 |
std::string istr = indent_spaces (enter); |
| 1232 |
std::string str = istr + "BlockExpr:\n" + istr; |
| 1233 |
|
| 1234 |
// get outer attributes |
| 1235 |
str += append_attributes (outer_attrs, OUTER); |
| 1236 |
|
| 1237 |
// inner attributes |
| 1238 |
str += append_attributes (inner_attrs, INNER); |
| 1239 |
|
| 1240 |
// statements |
| 1241 |
str += "\n" + indent_spaces (stay) + "statements: "; |
| 1242 |
if (statements.empty ()) |
| 1243 |
{ |
| 1244 |
str += "none"; |
| 1245 |
} |
| 1246 |
else |
| 1247 |
{ |
| 1248 |
for (const auto &stmt : statements) |
| 1249 |
{ |
| 1250 |
// DEBUG: null pointer check |
| 1251 |
if (stmt == nullptr) |
| 1252 |
{ |
| 1253 |
rust_debug ( |
| 1254 |
"something really terrible has gone wrong - null pointer " |
| 1255 |
"stmt in block expr."); |
| 1256 |
return "NULL_POINTER_MARK"; |
| 1257 |
} |
| 1258 |
|
| 1259 |
str += "\n" + indent_spaces (stay) + stmt->as_string (); |
| 1260 |
} |
| 1261 |
} |
| 1262 |
|
| 1263 |
// final expression |
| 1264 |
str += "\n" + indent_spaces (stay) + "final expression: "; |
| 1265 |
if (expr == nullptr) |
| 1266 |
str += "none"; |
| 1267 |
else |
| 1268 |
str += "\n" + expr->as_string (); |
| 1269 |
|
| 1270 |
str += "\n" + indent_spaces (out); |
| 1271 |
return str; |
| 1272 |
} |
| 1273 |
|
| 1274 |
std::string |
| 1275 |
TraitImpl::as_string () const |
| 1276 |
{ |
| 1277 |
std::string str = VisItem::as_string (); |
| 1278 |
|
| 1279 |
if (has_unsafe) |
| 1280 |
str += "unsafe "; |
| 1281 |
|
| 1282 |
str += "impl "; |
| 1283 |
|
| 1284 |
// generic params |
| 1285 |
str += "\n Generic params: "; |
| 1286 |
if (!has_generics ()) |
| 1287 |
{ |
| 1288 |
str += "none"; |
| 1289 |
} |
| 1290 |
else |
| 1291 |
{ |
| 1292 |
for (const auto ¶m : generic_params) |
| 1293 |
str += "\n " + param->as_string (); |
| 1294 |
} |
| 1295 |
|
| 1296 |
str += "\n Has exclam: "; |
| 1297 |
if (has_exclam) |
| 1298 |
str += "true"; |
| 1299 |
else |
| 1300 |
str += "false"; |
| 1301 |
|
| 1302 |
str += "\n TypePath (to trait): " + trait_path.as_string (); |
| 1303 |
|
| 1304 |
str += "\n Type (struct to impl on): " + trait_type->as_string (); |
| 1305 |
|
| 1306 |
str += "\n Where clause: "; |
| 1307 |
if (!has_where_clause ()) |
| 1308 |
str += "none"; |
| 1309 |
else |
| 1310 |
str += where_clause.as_string (); |
| 1311 |
|
| 1312 |
// inner attributes |
| 1313 |
str += append_attributes (inner_attrs, INNER); |
| 1314 |
|
| 1315 |
str += "\n trait impl items: "; |
| 1316 |
if (!has_impl_items ()) |
| 1317 |
{ |
| 1318 |
str += "none"; |
| 1319 |
} |
| 1320 |
else |
| 1321 |
{ |
| 1322 |
for (const auto &item : impl_items) |
| 1323 |
str += "\n " + item->as_string (); |
| 1324 |
} |
| 1325 |
|
| 1326 |
return str; |
| 1327 |
} |
| 1328 |
|
| 1329 |
std::string |
| 1330 |
TypeAlias::as_string () const |
| 1331 |
{ |
| 1332 |
std::string str = VisItem::as_string (); |
| 1333 |
|
| 1334 |
str += " " + new_type_name.as_string (); |
| 1335 |
|
| 1336 |
// generic params |
| 1337 |
str += "\n Generic params: "; |
| 1338 |
if (!has_generics ()) |
| 1339 |
{ |
| 1340 |
str += "none"; |
| 1341 |
} |
| 1342 |
else |
| 1343 |
{ |
| 1344 |
auto i = generic_params.begin (); |
| 1345 |
auto e = generic_params.end (); |
| 1346 |
|
| 1347 |
for (; i != e; i++) |
| 1348 |
{ |
| 1349 |
str += (*i)->as_string (); |
| 1350 |
if (e != i + 1) |
| 1351 |
str += ", "; |
| 1352 |
} |
| 1353 |
} |
| 1354 |
|
| 1355 |
str += "\n Where clause: "; |
| 1356 |
if (!has_where_clause ()) |
| 1357 |
str += "none"; |
| 1358 |
else |
| 1359 |
str += where_clause.as_string (); |
| 1360 |
|
| 1361 |
str += "\n Type: " + existing_type->as_string (); |
| 1362 |
|
| 1363 |
return str; |
| 1364 |
} |
| 1365 |
|
| 1366 |
std::string |
| 1367 |
ExternBlock::as_string () const |
| 1368 |
{ |
| 1369 |
std::string str = VisItem::as_string (); |
| 1370 |
|
| 1371 |
str += "extern "; |
| 1372 |
if (has_abi ()) |
| 1373 |
str += "\"" + abi + "\" "; |
| 1374 |
|
| 1375 |
str += append_attributes (inner_attrs, INNER); |
| 1376 |
|
| 1377 |
str += "\n external items: "; |
| 1378 |
if (!has_extern_items ()) |
| 1379 |
{ |
| 1380 |
str += "none"; |
| 1381 |
} |
| 1382 |
else |
| 1383 |
{ |
| 1384 |
for (const auto &item : extern_items) |
| 1385 |
str += "\n " + item->as_string (); |
| 1386 |
} |
| 1387 |
|
| 1388 |
return str; |
| 1389 |
} |
| 1390 |
|
| 1391 |
std::string |
| 1392 |
MacroRule::as_string () const |
| 1393 |
{ |
| 1394 |
std::string str ("Macro rule: "); |
| 1395 |
|
| 1396 |
str += "\n Matcher: \n "; |
| 1397 |
str += matcher.as_string (); |
| 1398 |
|
| 1399 |
str += "\n Transcriber: \n "; |
| 1400 |
str += transcriber.as_string (); |
| 1401 |
|
| 1402 |
return str; |
| 1403 |
} |
| 1404 |
|
| 1405 |
std::string |
| 1406 |
MacroRulesDefinition::as_string () const |
| 1407 |
{ |
| 1408 |
std::string str; |
| 1409 |
|
| 1410 |
// get outer attrs |
| 1411 |
str += append_attributes (outer_attrs, OUTER); |
| 1412 |
|
| 1413 |
// TODO: deal with macro_2_0 |
| 1414 |
str += "macro_rules!"; |
| 1415 |
|
| 1416 |
str += rule_name.as_string (); |
| 1417 |
|
| 1418 |
str += "\n Macro rules: "; |
| 1419 |
if (rules.empty ()) |
| 1420 |
{ |
| 1421 |
str += "none"; |
| 1422 |
} |
| 1423 |
else |
| 1424 |
{ |
| 1425 |
for (const auto &rule : rules) |
| 1426 |
str += "\n " + rule.as_string (); |
| 1427 |
} |
| 1428 |
|
| 1429 |
str += "\n Delim type: "; |
| 1430 |
switch (delim_type) |
| 1431 |
{ |
| 1432 |
case PARENS: |
| 1433 |
str += "parentheses"; |
| 1434 |
break; |
| 1435 |
case SQUARE: |
| 1436 |
str += "square"; |
| 1437 |
break; |
| 1438 |
case CURLY: |
| 1439 |
str += "curly"; |
| 1440 |
break; |
| 1441 |
default: |
| 1442 |
return "ERROR_MARK_STRING - delim type in macro invocation"; |
| 1443 |
} |
| 1444 |
|
| 1445 |
return str; |
| 1446 |
} |
| 1447 |
|
| 1448 |
std::string |
| 1449 |
MacroInvocation::as_string () const |
| 1450 |
{ |
| 1451 |
std::string str = "MacroInvocation: "; |
| 1452 |
auto is_builtin = kind == InvocKind::Builtin; |
| 1453 |
|
| 1454 |
if (is_builtin) |
| 1455 |
str += "[builtin] "; |
| 1456 |
else |
| 1457 |
str += "[regular] "; |
| 1458 |
|
| 1459 |
str += append_attributes (outer_attrs, OUTER); |
| 1460 |
|
| 1461 |
str += "\n " + invoc_data.as_string (); |
| 1462 |
|
| 1463 |
str += "\n has semicolon: "; |
| 1464 |
str += has_semicolon () ? "true" : "false"; |
| 1465 |
|
| 1466 |
if (is_builtin) |
| 1467 |
{ |
| 1468 |
str += "[PENDING EAGER INVOCATIONS]: "; |
| 1469 |
for (auto &pending : pending_eager_invocs) |
| 1470 |
{ |
| 1471 |
str += pending->as_string (); |
| 1472 |
str += "\n"; |
| 1473 |
} |
| 1474 |
} |
| 1475 |
|
| 1476 |
return str; |
| 1477 |
} |
| 1478 |
|
| 1479 |
std::string |
| 1480 |
MacroInvocData::as_string () const |
| 1481 |
{ |
| 1482 |
return path.as_string () + "!" + token_tree.as_string (); |
| 1483 |
} |
| 1484 |
|
| 1485 |
std::string |
| 1486 |
ExprStmt::as_string () const |
| 1487 |
{ |
| 1488 |
std::string str = indent_spaces (enter) + "ExprStmt: \n"; |
| 1489 |
|
| 1490 |
if (expr == nullptr) |
| 1491 |
{ |
| 1492 |
str += "none (this should not happen and is an error)"; |
| 1493 |
} |
| 1494 |
else |
| 1495 |
{ |
| 1496 |
indent_spaces (enter); |
| 1497 |
str += expr->as_string (); |
| 1498 |
if (semicolon_followed) |
| 1499 |
str += ";"; |
| 1500 |
indent_spaces (out); |
| 1501 |
} |
| 1502 |
|
| 1503 |
indent_spaces (out); |
| 1504 |
return str; |
| 1505 |
} |
| 1506 |
|
| 1507 |
std::string |
| 1508 |
ClosureParam::as_string () const |
| 1509 |
{ |
| 1510 |
std::string str (pattern->as_string ()); |
| 1511 |
|
| 1512 |
if (has_type_given ()) |
| 1513 |
str += " : " + type->as_string (); |
| 1514 |
|
| 1515 |
return str; |
| 1516 |
} |
| 1517 |
|
| 1518 |
std::string |
| 1519 |
ClosureExpr::as_string () const |
| 1520 |
{ |
| 1521 |
std::string str = "ClosureExpr:"; |
| 1522 |
|
| 1523 |
str += append_attributes (outer_attrs, OUTER); |
| 1524 |
|
| 1525 |
str += "\n Has move: "; |
| 1526 |
if (has_move) |
| 1527 |
str += "true"; |
| 1528 |
else |
| 1529 |
str += "false"; |
| 1530 |
|
| 1531 |
str += "\n Params: "; |
| 1532 |
if (params.empty ()) |
| 1533 |
{ |
| 1534 |
str += "none"; |
| 1535 |
} |
| 1536 |
else |
| 1537 |
{ |
| 1538 |
for (const auto ¶m : params) |
| 1539 |
str += "\n " + param.as_string (); |
| 1540 |
} |
| 1541 |
|
| 1542 |
return str; |
| 1543 |
} |
| 1544 |
|
| 1545 |
std::string |
| 1546 |
ClosureExprInnerTyped::as_string () const |
| 1547 |
{ |
| 1548 |
std::string str = ClosureExpr::as_string (); |
| 1549 |
|
| 1550 |
str += "\n Return type: " + return_type->as_string (); |
| 1551 |
|
| 1552 |
str += "\n Body: " + expr->as_string (); |
| 1553 |
|
| 1554 |
return str; |
| 1555 |
} |
| 1556 |
|
| 1557 |
std::string |
| 1558 |
QualifiedPathType::as_string () const |
| 1559 |
{ |
| 1560 |
std::string str ("<"); |
| 1561 |
str += type_to_invoke_on->as_string (); |
| 1562 |
|
| 1563 |
if (has_as_clause ()) |
| 1564 |
str += " as " + trait_path.as_string (); |
| 1565 |
|
| 1566 |
return str + ">"; |
| 1567 |
} |
| 1568 |
|
| 1569 |
std::string |
| 1570 |
BorrowExpr::as_string () const |
| 1571 |
{ |
| 1572 |
/* TODO: find way to incorporate outer attrs - may have to represent in |
| 1573 |
* different style (i.e. something more like BorrowExpr: \n outer attrs) */ |
| 1574 |
|
| 1575 |
std::string str ("&"); |
| 1576 |
|
| 1577 |
if (raw_borrow) |
| 1578 |
{ |
| 1579 |
str += "raw "; |
| 1580 |
str += get_is_mut () ? "const " : "mut "; |
| 1581 |
} |
| 1582 |
else |
| 1583 |
{ |
| 1584 |
if (double_borrow) |
| 1585 |
str += "&"; |
| 1586 |
|
| 1587 |
if (get_is_mut ()) |
| 1588 |
str += "mut "; |
| 1589 |
} |
| 1590 |
str += main_or_left_expr->as_string (); |
| 1591 |
|
| 1592 |
return str; |
| 1593 |
} |
| 1594 |
|
| 1595 |
std::string |
| 1596 |
BoxExpr::as_string () const |
| 1597 |
{ |
| 1598 |
return "box " + expr->as_string (); |
| 1599 |
} |
| 1600 |
|
| 1601 |
void |
| 1602 |
BoxExpr::accept_vis (ASTVisitor &vis) |
| 1603 |
{ |
| 1604 |
vis.visit (*this); |
| 1605 |
} |
| 1606 |
|
| 1607 |
std::string |
| 1608 |
ReturnExpr::as_string () const |
| 1609 |
{ |
| 1610 |
/* TODO: find way to incorporate outer attrs - may have to represent in |
| 1611 |
* different style (i.e. something more like BorrowExpr: \n outer attrs) */ |
| 1612 |
|
| 1613 |
std::string str ("return "); |
| 1614 |
|
| 1615 |
if (has_returned_expr ()) |
| 1616 |
str += return_expr->as_string (); |
| 1617 |
|
| 1618 |
return str; |
| 1619 |
} |
| 1620 |
|
| 1621 |
std::string |
| 1622 |
RangeToExpr::as_string () const |
| 1623 |
{ |
| 1624 |
return ".." + to->as_string (); |
| 1625 |
} |
| 1626 |
|
| 1627 |
std::string |
| 1628 |
ContinueExpr::as_string () const |
| 1629 |
{ |
| 1630 |
// TODO: rewrite format to allow outer attributes |
| 1631 |
std::string str ("continue "); |
| 1632 |
|
| 1633 |
if (has_label ()) |
| 1634 |
str += get_label_unchecked ().as_string (); |
| 1635 |
|
| 1636 |
return str; |
| 1637 |
} |
| 1638 |
|
| 1639 |
std::string |
| 1640 |
NegationExpr::as_string () const |
| 1641 |
{ |
| 1642 |
// TODO: rewrite formula to allow outer attributes |
| 1643 |
std::string str; |
| 1644 |
|
| 1645 |
switch (expr_type) |
| 1646 |
{ |
| 1647 |
case NegationOperator::NEGATE: |
| 1648 |
str = "-"; |
| 1649 |
break; |
| 1650 |
case NegationOperator::NOT: |
| 1651 |
str = "!"; |
| 1652 |
break; |
| 1653 |
default: |
| 1654 |
return "ERROR_MARK_STRING - negation expr"; |
| 1655 |
} |
| 1656 |
|
| 1657 |
str += main_or_left_expr->as_string (); |
| 1658 |
|
| 1659 |
return str; |
| 1660 |
} |
| 1661 |
|
| 1662 |
std::string |
| 1663 |
RangeFromExpr::as_string () const |
| 1664 |
{ |
| 1665 |
return from->as_string () + ".."; |
| 1666 |
} |
| 1667 |
|
| 1668 |
std::string |
| 1669 |
RangeFullExpr::as_string () const |
| 1670 |
{ |
| 1671 |
return ".."; |
| 1672 |
} |
| 1673 |
|
| 1674 |
std::string |
| 1675 |
ArrayIndexExpr::as_string () const |
| 1676 |
{ |
| 1677 |
// TODO: rewrite formula to allow outer attributes |
| 1678 |
return array_expr->as_string () + "[" + index_expr->as_string () + "]"; |
| 1679 |
} |
| 1680 |
|
| 1681 |
std::string |
| 1682 |
AssignmentExpr::as_string () const |
| 1683 |
{ |
| 1684 |
std::string str ("AssignmentExpr: "); |
| 1685 |
|
| 1686 |
if (main_or_left_expr == nullptr || right_expr == nullptr) |
| 1687 |
{ |
| 1688 |
str += "error (either or both expressions are null)"; |
| 1689 |
} |
| 1690 |
else |
| 1691 |
{ |
| 1692 |
// left expr |
| 1693 |
str += "\n left: " + main_or_left_expr->as_string (); |
| 1694 |
|
| 1695 |
// right expr |
| 1696 |
str += "\n right: " + right_expr->as_string (); |
| 1697 |
} |
| 1698 |
|
| 1699 |
return str; |
| 1700 |
} |
| 1701 |
|
| 1702 |
std::string |
| 1703 |
AsyncBlockExpr::as_string () const |
| 1704 |
{ |
| 1705 |
std::string str = "AsyncBlockExpr: "; |
| 1706 |
|
| 1707 |
// get outer attributes |
| 1708 |
// str += "\n " + Expr::as_string (); |
| 1709 |
str += append_attributes (outer_attrs, OUTER); |
| 1710 |
|
| 1711 |
str += "\n Has move: "; |
| 1712 |
str += has_move ? "true" : "false"; |
| 1713 |
|
| 1714 |
return str + "\n" + block_expr->as_string (); |
| 1715 |
} |
| 1716 |
|
| 1717 |
std::string |
| 1718 |
ComparisonExpr::as_string () const |
| 1719 |
{ |
| 1720 |
// TODO: rewrite to better reflect non-literal expressions |
| 1721 |
std::string str (main_or_left_expr->as_string ()); |
| 1722 |
|
| 1723 |
switch (expr_type) |
| 1724 |
{ |
| 1725 |
case ComparisonOperator::EQUAL: |
| 1726 |
str += " == "; |
| 1727 |
break; |
| 1728 |
case ComparisonOperator::NOT_EQUAL: |
| 1729 |
str += " != "; |
| 1730 |
break; |
| 1731 |
case ComparisonOperator::GREATER_THAN: |
| 1732 |
str += " > "; |
| 1733 |
break; |
| 1734 |
case ComparisonOperator::LESS_THAN: |
| 1735 |
str += " < "; |
| 1736 |
break; |
| 1737 |
case ComparisonOperator::GREATER_OR_EQUAL: |
| 1738 |
str += " >= "; |
| 1739 |
break; |
| 1740 |
case ComparisonOperator::LESS_OR_EQUAL: |
| 1741 |
str += " <= "; |
| 1742 |
break; |
| 1743 |
default: |
| 1744 |
return "ERROR_MARK_STRING - comparison expr"; |
| 1745 |
} |
| 1746 |
|
| 1747 |
str += right_expr->as_string (); |
| 1748 |
|
| 1749 |
return str; |
| 1750 |
} |
| 1751 |
|
| 1752 |
std::string |
| 1753 |
MethodCallExpr::as_string () const |
| 1754 |
{ |
| 1755 |
std::string str = "MethodCallExpr: "; |
| 1756 |
|
| 1757 |
str += append_attributes (outer_attrs, OUTER); |
| 1758 |
|
| 1759 |
str += "\n Object (receiver) expr: \n"; |
| 1760 |
str += receiver->as_string (); |
| 1761 |
|
| 1762 |
str += "\n Method path segment: \n"; |
| 1763 |
str += method_name.as_string (); |
| 1764 |
|
| 1765 |
str += "\n Call params:"; |
| 1766 |
if (params.empty ()) |
| 1767 |
{ |
| 1768 |
str += "none"; |
| 1769 |
} |
| 1770 |
else |
| 1771 |
{ |
| 1772 |
for (const auto ¶m : params) |
| 1773 |
{ |
| 1774 |
if (param == nullptr) |
| 1775 |
return "ERROR_MARK_STRING - method call expr param is null"; |
| 1776 |
|
| 1777 |
str += "\n " + param->as_string (); |
| 1778 |
} |
| 1779 |
} |
| 1780 |
|
| 1781 |
return str; |
| 1782 |
} |
| 1783 |
|
| 1784 |
std::string |
| 1785 |
TupleIndexExpr::as_string () const |
| 1786 |
{ |
| 1787 |
// TODO: rewrite dump to better reflect non-literal exprs |
| 1788 |
return tuple_expr->as_string () + "." + std::to_string (tuple_index); |
| 1789 |
} |
| 1790 |
|
| 1791 |
std::string |
| 1792 |
DereferenceExpr::as_string () const |
| 1793 |
{ |
| 1794 |
// TODO: rewrite dump to better reflect non-literal exprs |
| 1795 |
return "*" + main_or_left_expr->as_string (); |
| 1796 |
} |
| 1797 |
|
| 1798 |
std::string |
| 1799 |
FieldAccessExpr::as_string () const |
| 1800 |
{ |
| 1801 |
// TODO: rewrite dump to better reflect non-literal exprs |
| 1802 |
return receiver->as_string () + "." + field.as_string (); |
| 1803 |
} |
| 1804 |
|
| 1805 |
std::string |
| 1806 |
LazyBooleanExpr::as_string () const |
| 1807 |
{ |
| 1808 |
// TODO: rewrite dump to better reflect non-literal exprs |
| 1809 |
std::string str (main_or_left_expr->as_string ()); |
| 1810 |
|
| 1811 |
switch (expr_type) |
| 1812 |
{ |
| 1813 |
case LazyBooleanOperator::LOGICAL_OR: |
| 1814 |
str += " || "; |
| 1815 |
break; |
| 1816 |
case LazyBooleanOperator::LOGICAL_AND: |
| 1817 |
str += " && "; |
| 1818 |
break; |
| 1819 |
default: |
| 1820 |
return "ERROR_MARK_STRING - lazy boolean expr out of bounds"; |
| 1821 |
} |
| 1822 |
|
| 1823 |
str += right_expr->as_string (); |
| 1824 |
|
| 1825 |
return str; |
| 1826 |
} |
| 1827 |
|
| 1828 |
std::string |
| 1829 |
RangeFromToExpr::as_string () const |
| 1830 |
{ |
| 1831 |
// TODO: rewrite dump to better reflect non-literal exprs |
| 1832 |
return from->as_string () + ".." + to->as_string (); |
| 1833 |
} |
| 1834 |
|
| 1835 |
std::string |
| 1836 |
RangeToInclExpr::as_string () const |
| 1837 |
{ |
| 1838 |
// TODO: rewrite dump to better reflect non-literal exprs |
| 1839 |
return "..=" + to->as_string (); |
| 1840 |
} |
| 1841 |
|
| 1842 |
std::string |
| 1843 |
UnsafeBlockExpr::as_string () const |
| 1844 |
{ |
| 1845 |
std::string str = "UnsafeBlockExpr:" + indent_spaces (enter); |
| 1846 |
|
| 1847 |
// get outer attributes |
| 1848 |
str += append_attributes (outer_attrs, OUTER); |
| 1849 |
|
| 1850 |
str += indent_spaces (stay) + expr->as_string () + "\n" + indent_spaces (out); |
| 1851 |
|
| 1852 |
return str; |
| 1853 |
} |
| 1854 |
|
| 1855 |
std::string |
| 1856 |
ClosureExprInner::as_string () const |
| 1857 |
{ |
| 1858 |
std::string str = ClosureExpr::as_string (); |
| 1859 |
|
| 1860 |
str += "\n Expression: " + closure_inner->as_string (); |
| 1861 |
|
| 1862 |
return str; |
| 1863 |
} |
| 1864 |
|
| 1865 |
std::string |
| 1866 |
IfExpr::as_string () const |
| 1867 |
{ |
| 1868 |
std::string str = "IfExpr: "; |
| 1869 |
|
| 1870 |
str += append_attributes (outer_attrs, OUTER); |
| 1871 |
|
| 1872 |
str += "\n Condition expr: " + condition->as_string (); |
| 1873 |
|
| 1874 |
str += "\n If block expr: " + if_block->as_string (); |
| 1875 |
|
| 1876 |
return str; |
| 1877 |
} |
| 1878 |
|
| 1879 |
std::string |
| 1880 |
IfExprConseqElse::as_string () const |
| 1881 |
{ |
| 1882 |
std::string str = IfExpr::as_string (); |
| 1883 |
|
| 1884 |
str += "\n Else expr: " + else_block->as_string (); |
| 1885 |
|
| 1886 |
return str; |
| 1887 |
} |
| 1888 |
|
| 1889 |
std::string |
| 1890 |
IfLetExpr::as_string () const |
| 1891 |
{ |
| 1892 |
std::string str = "IfLetExpr: "; |
| 1893 |
|
| 1894 |
str += append_attributes (outer_attrs, OUTER); |
| 1895 |
|
| 1896 |
str += "\n Condition match arm patterns: "; |
| 1897 |
if (match_arm_patterns.empty ()) |
| 1898 |
{ |
| 1899 |
str += "none"; |
| 1900 |
} |
| 1901 |
else |
| 1902 |
{ |
| 1903 |
for (const auto &pattern : match_arm_patterns) |
| 1904 |
str += "\n " + pattern->as_string (); |
| 1905 |
} |
| 1906 |
|
| 1907 |
str += "\n Scrutinee expr: " + value->as_string (); |
| 1908 |
|
| 1909 |
str += "\n If let block expr: " + if_block->as_string (); |
| 1910 |
|
| 1911 |
return str; |
| 1912 |
} |
| 1913 |
|
| 1914 |
std::string |
| 1915 |
IfLetExprConseqElse::as_string () const |
| 1916 |
{ |
| 1917 |
std::string str = IfLetExpr::as_string (); |
| 1918 |
|
| 1919 |
str += "\n Else expr: " + else_block->as_string (); |
| 1920 |
|
| 1921 |
return str; |
| 1922 |
} |
| 1923 |
|
| 1924 |
std::string |
| 1925 |
RangeFromToInclExpr::as_string () const |
| 1926 |
{ |
| 1927 |
// TODO: rewrite to allow dumps with non-literal exprs |
| 1928 |
return from->as_string () + "..=" + to->as_string (); |
| 1929 |
} |
| 1930 |
|
| 1931 |
std::string |
| 1932 |
ErrorPropagationExpr::as_string () const |
| 1933 |
{ |
| 1934 |
// TODO: rewrite to allow dumps with non-literal exprs |
| 1935 |
return main_or_left_expr->as_string () + "?"; |
| 1936 |
} |
| 1937 |
|
| 1938 |
std::string |
| 1939 |
CompoundAssignmentExpr::as_string () const |
| 1940 |
{ |
| 1941 |
std::string operator_str; |
| 1942 |
operator_str.reserve (1); |
| 1943 |
|
| 1944 |
// get operator string |
| 1945 |
switch (expr_type) |
| 1946 |
{ |
| 1947 |
case CompoundAssignmentOperator::ADD: |
| 1948 |
operator_str = "+"; |
| 1949 |
break; |
| 1950 |
case CompoundAssignmentOperator::SUBTRACT: |
| 1951 |
operator_str = "-"; |
| 1952 |
break; |
| 1953 |
case CompoundAssignmentOperator::MULTIPLY: |
| 1954 |
operator_str = "*"; |
| 1955 |
break; |
| 1956 |
case CompoundAssignmentOperator::DIVIDE: |
| 1957 |
operator_str = "/"; |
| 1958 |
break; |
| 1959 |
case CompoundAssignmentOperator::MODULUS: |
| 1960 |
operator_str = "%"; |
| 1961 |
break; |
| 1962 |
case CompoundAssignmentOperator::BITWISE_AND: |
| 1963 |
operator_str = "&"; |
| 1964 |
break; |
| 1965 |
case CompoundAssignmentOperator::BITWISE_OR: |
| 1966 |
operator_str = "|"; |
| 1967 |
break; |
| 1968 |
case CompoundAssignmentOperator::BITWISE_XOR: |
| 1969 |
operator_str = "^"; |
| 1970 |
break; |
| 1971 |
case CompoundAssignmentOperator::LEFT_SHIFT: |
| 1972 |
operator_str = "<<"; |
| 1973 |
break; |
| 1974 |
case CompoundAssignmentOperator::RIGHT_SHIFT: |
| 1975 |
operator_str = ">>"; |
| 1976 |
break; |
| 1977 |
default: |
| 1978 |
operator_str = "invalid operator. wtf"; |
| 1979 |
break; |
| 1980 |
} |
| 1981 |
|
| 1982 |
operator_str += "="; |
| 1983 |
|
| 1984 |
std::string str ("CompoundAssignmentExpr: "); |
| 1985 |
if (main_or_left_expr == nullptr || right_expr == nullptr) |
| 1986 |
{ |
| 1987 |
str += "error. this is probably a parsing failure."; |
| 1988 |
} |
| 1989 |
else |
| 1990 |
{ |
| 1991 |
str += "\n left: " + main_or_left_expr->as_string (); |
| 1992 |
str += "\n right: " + right_expr->as_string (); |
| 1993 |
str += "\n operator: " + operator_str; |
| 1994 |
} |
| 1995 |
|
| 1996 |
return str; |
| 1997 |
} |
| 1998 |
|
| 1999 |
std::string |
| 2000 |
ArithmeticOrLogicalExpr::as_string () const |
| 2001 |
{ |
| 2002 |
std::string operator_str; |
| 2003 |
operator_str.reserve (1); |
| 2004 |
|
| 2005 |
// get operator string |
| 2006 |
switch (expr_type) |
| 2007 |
{ |
| 2008 |
case ArithmeticOrLogicalOperator::ADD: |
| 2009 |
operator_str = "+"; |
| 2010 |
break; |
| 2011 |
case ArithmeticOrLogicalOperator::SUBTRACT: |
| 2012 |
operator_str = "-"; |
| 2013 |
break; |
| 2014 |
case ArithmeticOrLogicalOperator::MULTIPLY: |
| 2015 |
operator_str = "*"; |
| 2016 |
break; |
| 2017 |
case ArithmeticOrLogicalOperator::DIVIDE: |
| 2018 |
operator_str = "/"; |
| 2019 |
break; |
| 2020 |
case ArithmeticOrLogicalOperator::MODULUS: |
| 2021 |
operator_str = "%"; |
| 2022 |
break; |
| 2023 |
case ArithmeticOrLogicalOperator::BITWISE_AND: |
| 2024 |
operator_str = "&"; |
| 2025 |
break; |
| 2026 |
case ArithmeticOrLogicalOperator::BITWISE_OR: |
| 2027 |
operator_str = "|"; |
| 2028 |
break; |
| 2029 |
case ArithmeticOrLogicalOperator::BITWISE_XOR: |
| 2030 |
operator_str = "^"; |
| 2031 |
break; |
| 2032 |
case ArithmeticOrLogicalOperator::LEFT_SHIFT: |
| 2033 |
operator_str = "<<"; |
| 2034 |
break; |
| 2035 |
case ArithmeticOrLogicalOperator::RIGHT_SHIFT: |
| 2036 |
operator_str = ">>"; |
| 2037 |
break; |
| 2038 |
default: |
| 2039 |
operator_str = "invalid operator. wtf"; |
| 2040 |
break; |
| 2041 |
} |
| 2042 |
|
| 2043 |
std::string str ("ArithmeticOrLogicalExpr: "); |
| 2044 |
if (main_or_left_expr == nullptr || right_expr == nullptr) |
| 2045 |
{ |
| 2046 |
str += "error. this is probably a parsing failure."; |
| 2047 |
} |
| 2048 |
else |
| 2049 |
{ |
| 2050 |
str += main_or_left_expr->as_string () + " "; |
| 2051 |
str += operator_str + " "; |
| 2052 |
str += right_expr->as_string (); |
| 2053 |
} |
| 2054 |
|
| 2055 |
return str; |
| 2056 |
} |
| 2057 |
|
| 2058 |
std::string |
| 2059 |
CallExpr::as_string () const |
| 2060 |
{ |
| 2061 |
std::string str = "CallExpr: "; |
| 2062 |
|
| 2063 |
str += append_attributes (outer_attrs, OUTER); |
| 2064 |
|
| 2065 |
str += "\n Function expr: "; |
| 2066 |
str += function->as_string (); |
| 2067 |
|
| 2068 |
str += "\n Call params:"; |
| 2069 |
if (!has_params ()) |
| 2070 |
{ |
| 2071 |
str += "none"; |
| 2072 |
} |
| 2073 |
else |
| 2074 |
{ |
| 2075 |
for (const auto ¶m : params) |
| 2076 |
{ |
| 2077 |
if (param == nullptr) |
| 2078 |
return "ERROR_MARK_STRING - call expr param is null"; |
| 2079 |
|
| 2080 |
str += "\n " + param->as_string (); |
| 2081 |
} |
| 2082 |
} |
| 2083 |
|
| 2084 |
return str; |
| 2085 |
} |
| 2086 |
|
| 2087 |
std::string |
| 2088 |
WhileLoopExpr::as_string () const |
| 2089 |
{ |
| 2090 |
std::string str = "WhileLoopExpr: "; |
| 2091 |
|
| 2092 |
str += append_attributes (outer_attrs, OUTER); |
| 2093 |
|
| 2094 |
str += "\n Label: "; |
| 2095 |
if (!has_loop_label ()) |
| 2096 |
str += "none"; |
| 2097 |
else |
| 2098 |
str += get_loop_label ().as_string (); |
| 2099 |
|
| 2100 |
str += "\n Conditional expr: " + condition->as_string (); |
| 2101 |
|
| 2102 |
str += "\n Loop block: " + loop_block->as_string (); |
| 2103 |
|
| 2104 |
return str; |
| 2105 |
} |
| 2106 |
|
| 2107 |
std::string |
| 2108 |
WhileLetLoopExpr::as_string () const |
| 2109 |
{ |
| 2110 |
std::string str = "WhileLetLoopExpr: "; |
| 2111 |
|
| 2112 |
str += append_attributes (outer_attrs, OUTER); |
| 2113 |
|
| 2114 |
str += "\n Label: "; |
| 2115 |
if (!has_loop_label ()) |
| 2116 |
str += "none"; |
| 2117 |
else |
| 2118 |
str += get_loop_label ().as_string (); |
| 2119 |
|
| 2120 |
str += "\n Match arm patterns: "; |
| 2121 |
if (match_arm_patterns.empty ()) |
| 2122 |
{ |
| 2123 |
str += "none"; |
| 2124 |
} |
| 2125 |
else |
| 2126 |
{ |
| 2127 |
for (const auto &pattern : match_arm_patterns) |
| 2128 |
str += "\n " + pattern->as_string (); |
| 2129 |
} |
| 2130 |
|
| 2131 |
str += "\n Scrutinee expr: " + scrutinee->as_string (); |
| 2132 |
|
| 2133 |
str += "\n Loop block: " + loop_block->as_string (); |
| 2134 |
|
| 2135 |
return str; |
| 2136 |
} |
| 2137 |
|
| 2138 |
std::string |
| 2139 |
LoopExpr::as_string () const |
| 2140 |
{ |
| 2141 |
std::string str = "LoopExpr: (infinite loop)"; |
| 2142 |
|
| 2143 |
str += append_attributes (outer_attrs, OUTER); |
| 2144 |
|
| 2145 |
str += "\n Label: "; |
| 2146 |
if (!has_loop_label ()) |
| 2147 |
str += "none"; |
| 2148 |
else |
| 2149 |
str += get_loop_label ().as_string (); |
| 2150 |
|
| 2151 |
str += "\n Loop block: " + loop_block->as_string (); |
| 2152 |
|
| 2153 |
return str; |
| 2154 |
} |
| 2155 |
|
| 2156 |
std::string |
| 2157 |
ArrayExpr::as_string () const |
| 2158 |
{ |
| 2159 |
std::string str = "ArrayExpr:"; |
| 2160 |
|
| 2161 |
str += append_attributes (outer_attrs, OUTER); |
| 2162 |
|
| 2163 |
// inner attributes |
| 2164 |
str += append_attributes (inner_attrs, INNER); |
| 2165 |
|
| 2166 |
str += "\n Array elems: "; |
| 2167 |
str += internal_elements->as_string (); |
| 2168 |
|
| 2169 |
return str; |
| 2170 |
} |
| 2171 |
|
| 2172 |
std::string |
| 2173 |
AwaitExpr::as_string () const |
| 2174 |
{ |
| 2175 |
// TODO: rewrite dump to allow non-literal exprs |
| 2176 |
return awaited_expr->as_string () + ".await"; |
| 2177 |
} |
| 2178 |
|
| 2179 |
std::string |
| 2180 |
BreakExpr::as_string () const |
| 2181 |
{ |
| 2182 |
// TODO: rewrite dump to allow outer attrs, non-literal exprs |
| 2183 |
std::string str ("break "); |
| 2184 |
|
| 2185 |
if (has_label ()) |
| 2186 |
str += get_label_unchecked ().as_string () + " "; |
| 2187 |
|
| 2188 |
if (has_break_expr ()) |
| 2189 |
str += break_expr->as_string (); |
| 2190 |
|
| 2191 |
return str; |
| 2192 |
} |
| 2193 |
|
| 2194 |
std::string |
| 2195 |
LoopLabel::as_string () const |
| 2196 |
{ |
| 2197 |
return label.as_string () + ": (label) "; |
| 2198 |
} |
| 2199 |
|
| 2200 |
std::string |
| 2201 |
MatchArm::as_string () const |
| 2202 |
{ |
| 2203 |
// outer attributes |
| 2204 |
std::string str = append_attributes (outer_attrs, OUTER); |
| 2205 |
|
| 2206 |
str += "\nPatterns: "; |
| 2207 |
if (match_arm_patterns.empty ()) |
| 2208 |
{ |
| 2209 |
str += "none"; |
| 2210 |
} |
| 2211 |
else |
| 2212 |
{ |
| 2213 |
for (const auto &pattern : match_arm_patterns) |
| 2214 |
str += "\n " + pattern->as_string (); |
| 2215 |
} |
| 2216 |
|
| 2217 |
str += "\nGuard expr: "; |
| 2218 |
if (!has_match_arm_guard ()) |
| 2219 |
str += "none"; |
| 2220 |
else |
| 2221 |
str += guard_expr->as_string (); |
| 2222 |
|
| 2223 |
return str; |
| 2224 |
} |
| 2225 |
|
| 2226 |
std::string |
| 2227 |
MatchCase::as_string () const |
| 2228 |
{ |
| 2229 |
std::string str ("MatchCase: (match arm) "); |
| 2230 |
|
| 2231 |
str += "\n Match arm matcher: \n" + arm.as_string (); |
| 2232 |
str += "\n Expr: " + expr->as_string (); |
| 2233 |
|
| 2234 |
return str; |
| 2235 |
} |
| 2236 |
|
| 2237 |
std::string |
| 2238 |
MatchExpr::as_string () const |
| 2239 |
{ |
| 2240 |
std::string str ("MatchExpr:"); |
| 2241 |
|
| 2242 |
str += append_attributes (outer_attrs, OUTER); |
| 2243 |
|
| 2244 |
str += "\n Scrutinee expr: " + branch_value->as_string (); |
| 2245 |
|
| 2246 |
// inner attributes |
| 2247 |
str += append_attributes (inner_attrs, INNER); |
| 2248 |
|
| 2249 |
// match arms |
| 2250 |
str += "\n Match arms: "; |
| 2251 |
if (match_arms.empty ()) |
| 2252 |
{ |
| 2253 |
str += "none"; |
| 2254 |
} |
| 2255 |
else |
| 2256 |
{ |
| 2257 |
for (const auto &arm : match_arms) |
| 2258 |
str += "\n " + arm.as_string (); |
| 2259 |
} |
| 2260 |
|
| 2261 |
return str; |
| 2262 |
} |
| 2263 |
|
| 2264 |
std::string |
| 2265 |
TupleExpr::as_string () const |
| 2266 |
{ |
| 2267 |
std::string str ("TupleExpr:"); |
| 2268 |
|
| 2269 |
str += append_attributes (outer_attrs, OUTER); |
| 2270 |
|
| 2271 |
// inner attributes |
| 2272 |
str += append_attributes (inner_attrs, INNER); |
| 2273 |
|
| 2274 |
str += "\n Tuple elements: "; |
| 2275 |
if (tuple_elems.empty ()) |
| 2276 |
{ |
| 2277 |
str += "none"; |
| 2278 |
} |
| 2279 |
else |
| 2280 |
{ |
| 2281 |
for (const auto &elem : tuple_elems) |
| 2282 |
str += "\n " + elem->as_string (); |
| 2283 |
} |
| 2284 |
|
| 2285 |
return str; |
| 2286 |
} |
| 2287 |
|
| 2288 |
std::string |
| 2289 |
FunctionParam::as_string () const |
| 2290 |
{ |
| 2291 |
// TODO: rewrite dump to allow non-literal types |
| 2292 |
return param_name->as_string () + " : " + type->as_string (); |
| 2293 |
} |
| 2294 |
|
| 2295 |
void |
| 2296 |
FunctionParam::accept_vis (ASTVisitor &vis) |
| 2297 |
{ |
| 2298 |
vis.visit (*this); |
| 2299 |
} |
| 2300 |
|
| 2301 |
void |
| 2302 |
SelfParam::accept_vis (ASTVisitor &vis) |
| 2303 |
{ |
| 2304 |
vis.visit (*this); |
| 2305 |
} |
| 2306 |
|
| 2307 |
void |
| 2308 |
VariadicParam::accept_vis (ASTVisitor &vis) |
| 2309 |
{ |
| 2310 |
vis.visit (*this); |
| 2311 |
} |
| 2312 |
|
| 2313 |
std::string |
| 2314 |
VariadicParam::as_string () const |
| 2315 |
{ |
| 2316 |
if (has_pattern ()) |
| 2317 |
return get_pattern ().as_string () + " : ..."; |
| 2318 |
else |
| 2319 |
return "..."; |
| 2320 |
} |
| 2321 |
|
| 2322 |
std::string |
| 2323 |
FunctionQualifiers::as_string () const |
| 2324 |
{ |
| 2325 |
std::string str; |
| 2326 |
|
| 2327 |
if (is_async ()) |
| 2328 |
str += "async "; |
| 2329 |
if (is_const ()) |
| 2330 |
str += "const "; |
| 2331 |
if (is_unsafe ()) |
| 2332 |
str += "unsafe "; |
| 2333 |
|
| 2334 |
if (has_extern) |
| 2335 |
{ |
| 2336 |
str += "extern"; |
| 2337 |
if (extern_abi != "") |
| 2338 |
str += " \"" + extern_abi + "\""; |
| 2339 |
} |
| 2340 |
|
| 2341 |
return str; |
| 2342 |
} |
| 2343 |
|
| 2344 |
std::string |
| 2345 |
TraitBound::as_string () const |
| 2346 |
{ |
| 2347 |
std::string str ("TraitBound:"); |
| 2348 |
|
| 2349 |
str += "\n Has opening question mark: "; |
| 2350 |
if (opening_question_mark) |
| 2351 |
str += "true"; |
| 2352 |
else |
| 2353 |
str += "false"; |
| 2354 |
|
| 2355 |
str += "\n For lifetimes: "; |
| 2356 |
if (!has_for_lifetimes ()) |
| 2357 |
{ |
| 2358 |
str += "none"; |
| 2359 |
} |
| 2360 |
else |
| 2361 |
{ |
| 2362 |
for (const auto &lifetime : for_lifetimes) |
| 2363 |
str += "\n " + lifetime.as_string (); |
| 2364 |
} |
| 2365 |
|
| 2366 |
str += "\n Type path: " + type_path.as_string (); |
| 2367 |
|
| 2368 |
return str; |
| 2369 |
} |
| 2370 |
|
| 2371 |
std::string |
| 2372 |
MacroMatcher::as_string () const |
| 2373 |
{ |
| 2374 |
std::string str ("Macro matcher: "); |
| 2375 |
|
| 2376 |
str += "\n Delim type: "; |
| 2377 |
|
| 2378 |
switch (delim_type) |
| 2379 |
{ |
| 2380 |
case PARENS: |
| 2381 |
str += "parentheses"; |
| 2382 |
break; |
| 2383 |
case SQUARE: |
| 2384 |
str += "square"; |
| 2385 |
break; |
| 2386 |
case CURLY: |
| 2387 |
str += "curly"; |
| 2388 |
break; |
| 2389 |
default: |
| 2390 |
return "ERROR_MARK_STRING - macro matcher delim"; |
| 2391 |
} |
| 2392 |
|
| 2393 |
str += "\n Matches: "; |
| 2394 |
|
| 2395 |
if (matches.empty ()) |
| 2396 |
{ |
| 2397 |
str += "none"; |
| 2398 |
} |
| 2399 |
else |
| 2400 |
{ |
| 2401 |
for (const auto &match : matches) |
| 2402 |
str += "\n " + match->as_string (); |
| 2403 |
} |
| 2404 |
|
| 2405 |
return str; |
| 2406 |
} |
| 2407 |
|
| 2408 |
std::string |
| 2409 |
LifetimeParam::as_string () const |
| 2410 |
{ |
| 2411 |
std::string str ("LifetimeParam: "); |
| 2412 |
|
| 2413 |
str += "\n Outer attribute:"; |
| 2414 |
if (!has_outer_attribute ()) |
| 2415 |
str += "none"; |
| 2416 |
for (auto &attr : outer_attrs) |
| 2417 |
str += " " + attr.as_string (); |
| 2418 |
|
| 2419 |
str += "\n Lifetime: " + lifetime.as_string (); |
| 2420 |
|
| 2421 |
str += "\n Lifetime bounds: "; |
| 2422 |
if (!has_lifetime_bounds ()) |
| 2423 |
{ |
| 2424 |
str += "none"; |
| 2425 |
} |
| 2426 |
else |
| 2427 |
{ |
| 2428 |
for (const auto &bound : lifetime_bounds) |
| 2429 |
str += "\n " + bound.as_string (); |
| 2430 |
} |
| 2431 |
|
| 2432 |
return str; |
| 2433 |
} |
| 2434 |
|
| 2435 |
std::string |
| 2436 |
MacroMatchFragment::as_string () const |
| 2437 |
{ |
| 2438 |
return "$" + ident.as_string () + ": " + frag_spec.as_string (); |
| 2439 |
} |
| 2440 |
|
| 2441 |
std::string |
| 2442 |
MacroMatchRepetition::as_string () const |
| 2443 |
{ |
| 2444 |
std::string str ("Macro match repetition: "); |
| 2445 |
|
| 2446 |
str += "\n Matches: "; |
| 2447 |
if (matches.empty ()) |
| 2448 |
{ |
| 2449 |
str += "none"; |
| 2450 |
} |
| 2451 |
else |
| 2452 |
{ |
| 2453 |
for (const auto &match : matches) |
| 2454 |
str += "\n " + match->as_string (); |
| 2455 |
} |
| 2456 |
|
| 2457 |
str += "\n Sep: "; |
| 2458 |
if (!has_sep ()) |
| 2459 |
str += "none"; |
| 2460 |
else |
| 2461 |
str += sep->as_string (); |
| 2462 |
|
| 2463 |
str += "\n Op: "; |
| 2464 |
switch (op) |
| 2465 |
{ |
| 2466 |
case ANY: |
| 2467 |
str += "*"; |
| 2468 |
break; |
| 2469 |
case ONE_OR_MORE: |
| 2470 |
str += "+"; |
| 2471 |
break; |
| 2472 |
case ZERO_OR_ONE: |
| 2473 |
str += "?"; |
| 2474 |
break; |
| 2475 |
case NONE: |
| 2476 |
str += "no op? shouldn't be allowed"; |
| 2477 |
break; |
| 2478 |
default: |
| 2479 |
return "ERROR_MARK_STRING - unknown op in macro match repetition"; |
| 2480 |
} |
| 2481 |
|
| 2482 |
return str; |
| 2483 |
} |
| 2484 |
|
| 2485 |
std::string |
| 2486 |
Lifetime::as_string () const |
| 2487 |
{ |
| 2488 |
switch (lifetime_type) |
| 2489 |
{ |
| 2490 |
case NAMED: |
| 2491 |
return "'" + lifetime_name; |
| 2492 |
case STATIC: |
| 2493 |
return "'static"; |
| 2494 |
case WILDCARD: |
| 2495 |
return "'_"; |
| 2496 |
default: |
| 2497 |
return "ERROR-MARK-STRING: lifetime type failure"; |
| 2498 |
} |
| 2499 |
} |
| 2500 |
|
| 2501 |
std::string |
| 2502 |
TypeParam::as_string () const |
| 2503 |
{ |
| 2504 |
std::string str ("TypeParam: "); |
| 2505 |
|
| 2506 |
str += "\n Outer attribute:"; |
| 2507 |
if (!has_outer_attribute ()) |
| 2508 |
str += "none"; |
| 2509 |
for (auto &attr : outer_attrs) |
| 2510 |
str += " " + attr.as_string (); |
| 2511 |
|
| 2512 |
str += "\n Identifier: " + type_representation.as_string (); |
| 2513 |
|
| 2514 |
str += "\n Type param bounds: "; |
| 2515 |
if (!has_type_param_bounds ()) |
| 2516 |
{ |
| 2517 |
str += "none"; |
| 2518 |
} |
| 2519 |
else |
| 2520 |
{ |
| 2521 |
for (const auto &bound : type_param_bounds) |
| 2522 |
str += "\n " + bound->as_string (); |
| 2523 |
} |
| 2524 |
|
| 2525 |
str += "\n Type: "; |
| 2526 |
if (!has_type ()) |
| 2527 |
str += "none"; |
| 2528 |
else |
| 2529 |
str += type->as_string (); |
| 2530 |
|
| 2531 |
return str; |
| 2532 |
} |
| 2533 |
|
| 2534 |
std::string |
| 2535 |
ForLoopExpr::as_string () const |
| 2536 |
{ |
| 2537 |
std::string str = "ForLoopExpr: "; |
| 2538 |
|
| 2539 |
str += append_attributes (outer_attrs, OUTER); |
| 2540 |
|
| 2541 |
str += "\n Label: "; |
| 2542 |
if (!has_loop_label ()) |
| 2543 |
str += "none"; |
| 2544 |
else |
| 2545 |
str += get_loop_label ().as_string (); |
| 2546 |
|
| 2547 |
str += "\n Pattern: " + pattern->as_string (); |
| 2548 |
|
| 2549 |
str += "\n Iterator expr: " + iterator_expr->as_string (); |
| 2550 |
|
| 2551 |
str += "\n Loop block: " + loop_block->as_string (); |
| 2552 |
|
| 2553 |
return str; |
| 2554 |
} |
| 2555 |
|
| 2556 |
std::string |
| 2557 |
LetStmt::as_string () const |
| 2558 |
{ |
| 2559 |
// TODO: rewrite to work with non-linearisable types and exprs |
| 2560 |
std::string str = append_attributes (outer_attrs, OUTER); |
| 2561 |
|
| 2562 |
str += "\n" + indent_spaces (stay) + "let " + variables_pattern->as_string (); |
| 2563 |
|
| 2564 |
if (has_type ()) |
| 2565 |
str += " : " + type->as_string (); |
| 2566 |
|
| 2567 |
if (has_init_expr ()) |
| 2568 |
str += " = " + init_expr->as_string (); |
| 2569 |
|
| 2570 |
return str; |
| 2571 |
} |
| 2572 |
|
| 2573 |
std::string |
| 2574 |
InferredType::as_string () const |
| 2575 |
{ |
| 2576 |
return "_ (inferred)"; |
| 2577 |
} |
| 2578 |
|
| 2579 |
std::string |
| 2580 |
TypeCastExpr::as_string () const |
| 2581 |
{ |
| 2582 |
// TODO: rewrite to work with non-linearisable exprs and types |
| 2583 |
return main_or_left_expr->as_string () + " as " |
| 2584 |
+ type_to_convert_to->as_string (); |
| 2585 |
} |
| 2586 |
|
| 2587 |
std::string |
| 2588 |
ImplTraitType::as_string () const |
| 2589 |
{ |
| 2590 |
std::string str ("ImplTraitType: \n TypeParamBounds: "); |
| 2591 |
|
| 2592 |
if (type_param_bounds.empty ()) |
| 2593 |
{ |
| 2594 |
str += "none"; |
| 2595 |
} |
| 2596 |
else |
| 2597 |
{ |
| 2598 |
for (const auto &bound : type_param_bounds) |
| 2599 |
str += "\n " + bound->as_string (); |
| 2600 |
} |
| 2601 |
|
| 2602 |
return str; |
| 2603 |
} |
| 2604 |
|
| 2605 |
std::string |
| 2606 |
ReferenceType::as_string () const |
| 2607 |
{ |
| 2608 |
// TODO: rewrite to work with non-linearisable types |
| 2609 |
std::string str ("&"); |
| 2610 |
|
| 2611 |
if (has_lifetime ()) |
| 2612 |
str += get_lifetime ().as_string () + " "; |
| 2613 |
|
| 2614 |
if (has_mut) |
| 2615 |
str += "mut "; |
| 2616 |
|
| 2617 |
str += type->as_string (); |
| 2618 |
|
| 2619 |
return str; |
| 2620 |
} |
| 2621 |
|
| 2622 |
std::string |
| 2623 |
RawPointerType::as_string () const |
| 2624 |
{ |
| 2625 |
// TODO: rewrite to work with non-linearisable types |
| 2626 |
std::string str ("*"); |
| 2627 |
|
| 2628 |
switch (pointer_type) |
| 2629 |
{ |
| 2630 |
case MUT: |
| 2631 |
str += "mut "; |
| 2632 |
break; |
| 2633 |
case CONST: |
| 2634 |
str += "const "; |
| 2635 |
break; |
| 2636 |
default: |
| 2637 |
return "ERROR_MARK_STRING - unknown pointer type in raw pointer type"; |
| 2638 |
} |
| 2639 |
|
| 2640 |
str += type->as_string (); |
| 2641 |
|
| 2642 |
return str; |
| 2643 |
} |
| 2644 |
|
| 2645 |
std::string |
| 2646 |
TraitObjectType::as_string () const |
| 2647 |
{ |
| 2648 |
std::string str ("TraitObjectType: \n Has dyn dispatch: "); |
| 2649 |
|
| 2650 |
if (has_dyn) |
| 2651 |
str += "true"; |
| 2652 |
else |
| 2653 |
str += "false"; |
| 2654 |
|
| 2655 |
str += "\n TypeParamBounds: "; |
| 2656 |
if (type_param_bounds.empty ()) |
| 2657 |
{ |
| 2658 |
str += "none"; |
| 2659 |
} |
| 2660 |
else |
| 2661 |
{ |
| 2662 |
for (const auto &bound : type_param_bounds) |
| 2663 |
str += "\n " + bound->as_string (); |
| 2664 |
} |
| 2665 |
|
| 2666 |
return str; |
| 2667 |
} |
| 2668 |
|
| 2669 |
std::string |
| 2670 |
BareFunctionType::as_string () const |
| 2671 |
{ |
| 2672 |
std::string str ("BareFunctionType: \n For lifetimes: "); |
| 2673 |
|
| 2674 |
if (!has_for_lifetimes ()) |
| 2675 |
{ |
| 2676 |
str += "none"; |
| 2677 |
} |
| 2678 |
else |
| 2679 |
{ |
| 2680 |
for (const auto &for_lifetime : for_lifetimes) |
| 2681 |
str += "\n " + for_lifetime.as_string (); |
| 2682 |
} |
| 2683 |
|
| 2684 |
str += "\n Qualifiers: " + function_qualifiers.as_string (); |
| 2685 |
|
| 2686 |
str += "\n Params: "; |
| 2687 |
if (params.empty ()) |
| 2688 |
{ |
| 2689 |
str += "none"; |
| 2690 |
} |
| 2691 |
else |
| 2692 |
{ |
| 2693 |
for (const auto ¶m : params) |
| 2694 |
str += "\n " + param.as_string (); |
| 2695 |
} |
| 2696 |
|
| 2697 |
str += "\n Is variadic: "; |
| 2698 |
if (_is_variadic) |
| 2699 |
str += "true"; |
| 2700 |
else |
| 2701 |
str += "false"; |
| 2702 |
|
| 2703 |
str += "\n Return type: "; |
| 2704 |
if (!has_return_type ()) |
| 2705 |
str += "none (void)"; |
| 2706 |
else |
| 2707 |
str += return_type->as_string (); |
| 2708 |
|
| 2709 |
return str; |
| 2710 |
} |
| 2711 |
|
| 2712 |
std::string |
| 2713 |
ImplTraitTypeOneBound::as_string () const |
| 2714 |
{ |
| 2715 |
std::string str ("ImplTraitTypeOneBound: \n TraitBound: "); |
| 2716 |
|
| 2717 |
return str + trait_bound.as_string (); |
| 2718 |
} |
| 2719 |
|
| 2720 |
std::string |
| 2721 |
TraitObjectTypeOneBound::as_string () const |
| 2722 |
{ |
| 2723 |
std::string str ("TraitObjectTypeOneBound: \n Has dyn dispatch: "); |
| 2724 |
|
| 2725 |
if (has_dyn) |
| 2726 |
str += "true"; |
| 2727 |
else |
| 2728 |
str += "false"; |
| 2729 |
|
| 2730 |
str += "\n TraitBound: " + trait_bound.as_string (); |
| 2731 |
|
| 2732 |
return str; |
| 2733 |
} |
| 2734 |
|
| 2735 |
std::string |
| 2736 |
ArrayType::as_string () const |
| 2737 |
{ |
| 2738 |
// TODO: rewrite to work with non-linearisable types and exprs |
| 2739 |
return "[" + elem_type->as_string () + "; " + size->as_string () + "]"; |
| 2740 |
} |
| 2741 |
|
| 2742 |
std::string |
| 2743 |
SliceType::as_string () const |
| 2744 |
{ |
| 2745 |
// TODO: rewrite to work with non-linearisable types |
| 2746 |
return "[" + elem_type->as_string () + "]"; |
| 2747 |
} |
| 2748 |
|
| 2749 |
std::string |
| 2750 |
TupleType::as_string () const |
| 2751 |
{ |
| 2752 |
// TODO: rewrite to work with non-linearisable types |
| 2753 |
std::string str ("("); |
| 2754 |
|
| 2755 |
if (!is_unit_type ()) |
| 2756 |
{ |
| 2757 |
auto i = elems.begin (); |
| 2758 |
auto e = elems.end (); |
| 2759 |
|
| 2760 |
for (; i != e; i++) |
| 2761 |
{ |
| 2762 |
str += (*i)->as_string (); |
| 2763 |
if (e != i + 1) |
| 2764 |
str += ", "; |
| 2765 |
} |
| 2766 |
} |
| 2767 |
|
| 2768 |
str += ")"; |
| 2769 |
|
| 2770 |
return str; |
| 2771 |
} |
| 2772 |
|
| 2773 |
std::string |
| 2774 |
StructExpr::as_string () const |
| 2775 |
{ |
| 2776 |
std::string str = append_attributes (outer_attrs, OUTER); |
| 2777 |
indent_spaces (enter); |
| 2778 |
str += "\n" + indent_spaces (stay) + "StructExpr:"; |
| 2779 |
indent_spaces (enter); |
| 2780 |
str += "\n" + indent_spaces (stay) + "PathInExpr:\n"; |
| 2781 |
str += indent_spaces (stay) + struct_name.as_string (); |
| 2782 |
indent_spaces (out); |
| 2783 |
indent_spaces (out); |
| 2784 |
return str; |
| 2785 |
} |
| 2786 |
|
| 2787 |
std::string |
| 2788 |
StructExprStruct::as_string () const |
| 2789 |
{ |
| 2790 |
// TODO: doesn't this require data from StructExpr? |
| 2791 |
std::string str ("StructExprStruct (or subclass): "); |
| 2792 |
|
| 2793 |
str += "\n Path: " + get_struct_name ().as_string (); |
| 2794 |
|
| 2795 |
// inner attributes |
| 2796 |
str += append_attributes (inner_attrs, INNER); |
| 2797 |
|
| 2798 |
return str; |
| 2799 |
} |
| 2800 |
|
| 2801 |
std::string |
| 2802 |
StructBase::as_string () const |
| 2803 |
{ |
| 2804 |
if (base_struct != nullptr) |
| 2805 |
return base_struct->as_string (); |
| 2806 |
else |
| 2807 |
return "ERROR_MARK_STRING - invalid struct base had as string applied"; |
| 2808 |
} |
| 2809 |
|
| 2810 |
std::string |
| 2811 |
StructExprFieldWithVal::as_string () const |
| 2812 |
{ |
| 2813 |
// used to get value string |
| 2814 |
return value->as_string (); |
| 2815 |
} |
| 2816 |
|
| 2817 |
std::string |
| 2818 |
StructExprFieldIdentifierValue::as_string () const |
| 2819 |
{ |
| 2820 |
// TODO: rewrite to work with non-linearisable exprs |
| 2821 |
return field_name.as_string () + " : " + StructExprFieldWithVal::as_string (); |
| 2822 |
} |
| 2823 |
|
| 2824 |
std::string |
| 2825 |
StructExprFieldIndexValue::as_string () const |
| 2826 |
{ |
| 2827 |
// TODO: rewrite to work with non-linearisable exprs |
| 2828 |
return std::to_string (index) + " : " + StructExprFieldWithVal::as_string (); |
| 2829 |
} |
| 2830 |
|
| 2831 |
std::string |
| 2832 |
StructExprStructFields::as_string () const |
| 2833 |
{ |
| 2834 |
std::string str = StructExprStruct::as_string (); |
| 2835 |
|
| 2836 |
str += "\n Fields: "; |
| 2837 |
if (fields.empty ()) |
| 2838 |
{ |
| 2839 |
str += "none"; |
| 2840 |
} |
| 2841 |
else |
| 2842 |
{ |
| 2843 |
for (const auto &field : fields) |
| 2844 |
str += "\n " + field->as_string (); |
| 2845 |
} |
| 2846 |
|
| 2847 |
str += "\n Struct base: "; |
| 2848 |
if (!has_struct_base ()) |
| 2849 |
str += "none"; |
| 2850 |
else |
| 2851 |
str += struct_base.as_string (); |
| 2852 |
|
| 2853 |
return str; |
| 2854 |
} |
| 2855 |
|
| 2856 |
std::string |
| 2857 |
EnumItem::as_string () const |
| 2858 |
{ |
| 2859 |
std::string str = VisItem::as_string (); |
| 2860 |
str += variant_name.as_string (); |
| 2861 |
|
| 2862 |
return str; |
| 2863 |
} |
| 2864 |
|
| 2865 |
std::string |
| 2866 |
EnumItemTuple::as_string () const |
| 2867 |
{ |
| 2868 |
std::string str = EnumItem::as_string (); |
| 2869 |
|
| 2870 |
// add tuple opening parens |
| 2871 |
str += "("; |
| 2872 |
|
| 2873 |
// tuple fields |
| 2874 |
if (has_tuple_fields ()) |
| 2875 |
{ |
| 2876 |
auto i = tuple_fields.begin (); |
| 2877 |
auto e = tuple_fields.end (); |
| 2878 |
|
| 2879 |
for (; i != e; i++) |
| 2880 |
{ |
| 2881 |
str += (*i).as_string (); |
| 2882 |
if (e != i + 1) |
| 2883 |
str += ", "; |
| 2884 |
} |
| 2885 |
} |
| 2886 |
|
| 2887 |
// add tuple closing parens |
| 2888 |
str += ")"; |
| 2889 |
|
| 2890 |
return str; |
| 2891 |
} |
| 2892 |
|
| 2893 |
std::string |
| 2894 |
TupleField::as_string () const |
| 2895 |
{ |
| 2896 |
// TODO: rewrite to work with non-linearisable exprs |
| 2897 |
|
| 2898 |
// outer attributes |
| 2899 |
std::string str = append_attributes (outer_attrs, OUTER); |
| 2900 |
|
| 2901 |
if (has_visibility ()) |
| 2902 |
str += "\n" + visibility.as_string (); |
| 2903 |
|
| 2904 |
str += " " + field_type->as_string (); |
| 2905 |
|
| 2906 |
return str; |
| 2907 |
} |
| 2908 |
|
| 2909 |
std::string |
| 2910 |
EnumItemStruct::as_string () const |
| 2911 |
{ |
| 2912 |
std::string str = EnumItem::as_string (); |
| 2913 |
|
| 2914 |
// add struct opening parens |
| 2915 |
str += "{"; |
| 2916 |
|
| 2917 |
// tuple fields |
| 2918 |
if (has_struct_fields ()) |
| 2919 |
{ |
| 2920 |
auto i = struct_fields.begin (); |
| 2921 |
auto e = struct_fields.end (); |
| 2922 |
|
| 2923 |
for (; i != e; i++) |
| 2924 |
{ |
| 2925 |
str += (*i).as_string (); |
| 2926 |
if (e != i + 1) |
| 2927 |
str += ", "; |
| 2928 |
} |
| 2929 |
} |
| 2930 |
|
| 2931 |
// add struct closing parens |
| 2932 |
str += "}"; |
| 2933 |
|
| 2934 |
return str; |
| 2935 |
} |
| 2936 |
|
| 2937 |
std::string |
| 2938 |
StructField::as_string () const |
| 2939 |
{ |
| 2940 |
// TODO: rewrite to work with non-linearisable exprs |
| 2941 |
// outer attributes |
| 2942 |
std::string str = append_attributes (outer_attrs, OUTER); |
| 2943 |
|
| 2944 |
if (has_visibility ()) |
| 2945 |
str += "\n" + visibility.as_string (); |
| 2946 |
|
| 2947 |
str += " " + field_name.as_string () + " : " + field_type->as_string (); |
| 2948 |
|
| 2949 |
return str; |
| 2950 |
} |
| 2951 |
|
| 2952 |
std::string |
| 2953 |
EnumItemDiscriminant::as_string () const |
| 2954 |
{ |
| 2955 |
// TODO: rewrite to work with non-linearisable exprs |
| 2956 |
std::string str = EnumItem::as_string (); |
| 2957 |
|
| 2958 |
// add equal and expression |
| 2959 |
str += " = " + expression->as_string (); |
| 2960 |
|
| 2961 |
return str; |
| 2962 |
} |
| 2963 |
|
| 2964 |
std::string |
| 2965 |
ExternalTypeItem::as_string () const |
| 2966 |
{ |
| 2967 |
auto str = append_attributes (outer_attrs, OUTER); |
| 2968 |
|
| 2969 |
str += "type " + item_name.as_string () + ";"; |
| 2970 |
|
| 2971 |
return str; |
| 2972 |
} |
| 2973 |
|
| 2974 |
std::string |
| 2975 |
ExternalStaticItem::as_string () const |
| 2976 |
{ |
| 2977 |
// outer attributes |
| 2978 |
std::string str = append_attributes (outer_attrs, OUTER); |
| 2979 |
|
| 2980 |
// start visibility on new line and with a space |
| 2981 |
str += "\n" + visibility.as_string () + " "; |
| 2982 |
|
| 2983 |
str += "static "; |
| 2984 |
|
| 2985 |
if (has_mut) |
| 2986 |
str += "mut "; |
| 2987 |
|
| 2988 |
// add name |
| 2989 |
str += item_name.as_string (); |
| 2990 |
|
| 2991 |
// add type on new line |
| 2992 |
str += "\n Type: " + item_type->as_string (); |
| 2993 |
|
| 2994 |
return str; |
| 2995 |
} |
| 2996 |
|
| 2997 |
std::string |
| 2998 |
TraitItemConst::as_string () const |
| 2999 |
{ |
| 3000 |
// TODO: rewrite to work with non-linearisable exprs |
| 3001 |
std::string str = append_attributes (outer_attrs, OUTER); |
| 3002 |
|
| 3003 |
str += "\nconst " + name.as_string () + " : " + type->as_string (); |
| 3004 |
|
| 3005 |
if (has_expression ()) |
| 3006 |
str += " = " + expr->as_string (); |
| 3007 |
|
| 3008 |
return str; |
| 3009 |
} |
| 3010 |
|
| 3011 |
std::string |
| 3012 |
TraitItemType::as_string () const |
| 3013 |
{ |
| 3014 |
std::string str = append_attributes (outer_attrs, OUTER); |
| 3015 |
|
| 3016 |
str += "\ntype " + name.as_string (); |
| 3017 |
|
| 3018 |
str += "\n Type param bounds: "; |
| 3019 |
if (!has_type_param_bounds ()) |
| 3020 |
{ |
| 3021 |
str += "none"; |
| 3022 |
} |
| 3023 |
else |
| 3024 |
{ |
| 3025 |
for (const auto &bound : type_param_bounds) |
| 3026 |
{ |
| 3027 |
// DEBUG: null pointer check |
| 3028 |
if (bound == nullptr) |
| 3029 |
{ |
| 3030 |
rust_debug ( |
| 3031 |
"something really terrible has gone wrong - null pointer " |
| 3032 |
"type param bound in trait item type."); |
| 3033 |
return "NULL_POINTER_MARK"; |
| 3034 |
} |
| 3035 |
|
| 3036 |
str += "\n " + bound->as_string (); |
| 3037 |
} |
| 3038 |
} |
| 3039 |
|
| 3040 |
return str; |
| 3041 |
} |
| 3042 |
|
| 3043 |
std::string |
| 3044 |
SelfParam::as_string () const |
| 3045 |
{ |
| 3046 |
// TODO: rewrite to allow non-linearisable types |
| 3047 |
if (is_error ()) |
| 3048 |
{ |
| 3049 |
return "error"; |
| 3050 |
} |
| 3051 |
else |
| 3052 |
{ |
| 3053 |
if (has_type ()) |
| 3054 |
{ |
| 3055 |
// type (i.e. not ref, no lifetime) |
| 3056 |
std::string str; |
| 3057 |
|
| 3058 |
if (is_mut) |
| 3059 |
str += "mut "; |
| 3060 |
|
| 3061 |
str += "self : "; |
| 3062 |
|
| 3063 |
str += type->as_string (); |
| 3064 |
|
| 3065 |
return str; |
| 3066 |
} |
| 3067 |
else if (has_lifetime ()) |
| 3068 |
{ |
| 3069 |
// ref and lifetime |
| 3070 |
std::string str = "&" + get_lifetime ().as_string () + " "; |
| 3071 |
|
| 3072 |
if (is_mut) |
| 3073 |
str += "mut "; |
| 3074 |
|
| 3075 |
str += "self"; |
| 3076 |
|
| 3077 |
return str; |
| 3078 |
} |
| 3079 |
else if (has_ref) |
| 3080 |
{ |
| 3081 |
// ref with no lifetime |
| 3082 |
std::string str = "&"; |
| 3083 |
|
| 3084 |
if (is_mut) |
| 3085 |
str += " mut "; |
| 3086 |
|
| 3087 |
str += "self"; |
| 3088 |
|
| 3089 |
return str; |
| 3090 |
} |
| 3091 |
else |
| 3092 |
{ |
| 3093 |
// no ref, no type |
| 3094 |
std::string str; |
| 3095 |
|
| 3096 |
if (is_mut) |
| 3097 |
str += "mut "; |
| 3098 |
|
| 3099 |
str += "self"; |
| 3100 |
|
| 3101 |
return str; |
| 3102 |
} |
| 3103 |
} |
| 3104 |
} |
| 3105 |
|
| 3106 |
std::string |
| 3107 |
ArrayElemsCopied::as_string () const |
| 3108 |
{ |
| 3109 |
// TODO: rewrite to allow non-linearisable exprs |
| 3110 |
return elem_to_copy->as_string () + "; " + num_copies->as_string (); |
| 3111 |
} |
| 3112 |
|
| 3113 |
std::string |
| 3114 |
LifetimeWhereClauseItem::as_string () const |
| 3115 |
{ |
| 3116 |
std::string str ("Lifetime: "); |
| 3117 |
|
| 3118 |
str += lifetime.as_string (); |
| 3119 |
|
| 3120 |
str += "\nLifetime bounds: "; |
| 3121 |
|
| 3122 |
for (const auto &bound : lifetime_bounds) |
| 3123 |
str += "\n " + bound.as_string (); |
| 3124 |
|
| 3125 |
return str; |
| 3126 |
} |
| 3127 |
|
| 3128 |
std::string |
| 3129 |
TypeBoundWhereClauseItem::as_string () const |
| 3130 |
{ |
| 3131 |
std::string str ("For lifetimes: "); |
| 3132 |
|
| 3133 |
if (!has_for_lifetimes ()) |
| 3134 |
{ |
| 3135 |
str += "none"; |
| 3136 |
} |
| 3137 |
else |
| 3138 |
{ |
| 3139 |
for (const auto &for_lifetime : for_lifetimes) |
| 3140 |
str += "\n " + for_lifetime.as_string (); |
| 3141 |
} |
| 3142 |
|
| 3143 |
str += "\nType: " + bound_type->as_string (); |
| 3144 |
|
| 3145 |
str += "\nType param bounds bounds: "; |
| 3146 |
|
| 3147 |
for (const auto &bound : type_param_bounds) |
| 3148 |
{ |
| 3149 |
// debug null pointer check |
| 3150 |
if (bound == nullptr) |
| 3151 |
return "NULL_POINTER_MARK - type param bounds"; |
| 3152 |
|
| 3153 |
str += "\n " + bound->as_string (); |
| 3154 |
} |
| 3155 |
|
| 3156 |
return str; |
| 3157 |
} |
| 3158 |
|
| 3159 |
std::string |
| 3160 |
ArrayElemsValues::as_string () const |
| 3161 |
{ |
| 3162 |
std::string str; |
| 3163 |
|
| 3164 |
for (const auto &expr : values) |
| 3165 |
{ |
| 3166 |
// DEBUG: null pointer check |
| 3167 |
if (expr == nullptr) |
| 3168 |
{ |
| 3169 |
rust_debug ("something really terrible has gone wrong - null pointer " |
| 3170 |
"expr in array elems values."); |
| 3171 |
return "NULL_POINTER_MARK"; |
| 3172 |
} |
| 3173 |
|
| 3174 |
str += "\n " + expr->as_string (); |
| 3175 |
} |
| 3176 |
|
| 3177 |
return str; |
| 3178 |
} |
| 3179 |
|
| 3180 |
std::string |
| 3181 |
MaybeNamedParam::as_string () const |
| 3182 |
{ |
| 3183 |
// TODO: rewrite to allow using non-linearisable types in dump |
| 3184 |
std::string str; |
| 3185 |
|
| 3186 |
switch (param_kind) |
| 3187 |
{ |
| 3188 |
case UNNAMED: |
| 3189 |
break; |
| 3190 |
case IDENTIFIER: |
| 3191 |
str = name.as_string () + " : "; |
| 3192 |
break; |
| 3193 |
case WILDCARD: |
| 3194 |
str = "_ : "; |
| 3195 |
break; |
| 3196 |
default: |
| 3197 |
return "ERROR_MARK_STRING - maybe named param unrecognised param kind"; |
| 3198 |
} |
| 3199 |
|
| 3200 |
str += param_type->as_string (); |
| 3201 |
|
| 3202 |
return str; |
| 3203 |
} |
| 3204 |
|
| 3205 |
MetaItemInner::~MetaItemInner () = default; |
| 3206 |
|
| 3207 |
std::unique_ptr<MetaNameValueStr> |
| 3208 |
MetaItemInner::to_meta_name_value_str () const |
| 3209 |
{ |
| 3210 |
if (is_key_value_pair ()) |
| 3211 |
{ |
| 3212 |
auto converted_item = static_cast<const MetaNameValueStr *> (this); |
| 3213 |
return converted_item->to_meta_name_value_str (); |
| 3214 |
} |
| 3215 |
// TODO actually parse foo = bar |
| 3216 |
return nullptr; |
| 3217 |
} |
| 3218 |
|
| 3219 |
std::string |
| 3220 |
MetaItemSeq::as_string () const |
| 3221 |
{ |
| 3222 |
std::string path_str = path.as_string () + "("; |
| 3223 |
|
| 3224 |
auto i = seq.begin (); |
| 3225 |
auto e = seq.end (); |
| 3226 |
|
| 3227 |
for (; i != e; i++) |
| 3228 |
{ |
| 3229 |
path_str += (*i)->as_string (); |
| 3230 |
if (e != i + 1) |
| 3231 |
path_str += ", "; |
| 3232 |
} |
| 3233 |
|
| 3234 |
return path_str + ")"; |
| 3235 |
} |
| 3236 |
|
| 3237 |
std::string |
| 3238 |
MetaListPaths::as_string () const |
| 3239 |
{ |
| 3240 |
std::string str = ident.as_string () + "("; |
| 3241 |
|
| 3242 |
auto i = paths.begin (); |
| 3243 |
auto e = paths.end (); |
| 3244 |
|
| 3245 |
for (; i != e; i++) |
| 3246 |
{ |
| 3247 |
str += (*i).as_string (); |
| 3248 |
if (e != i + 1) |
| 3249 |
str += ", "; |
| 3250 |
} |
| 3251 |
|
| 3252 |
return str + ")"; |
| 3253 |
} |
| 3254 |
|
| 3255 |
std::string |
| 3256 |
MetaListNameValueStr::as_string () const |
| 3257 |
{ |
| 3258 |
std::string str = ident.as_string () + "("; |
| 3259 |
|
| 3260 |
auto i = strs.begin (); |
| 3261 |
auto e = strs.end (); |
| 3262 |
|
| 3263 |
for (; i != e; i++) |
| 3264 |
{ |
| 3265 |
str += (*i).as_string (); |
| 3266 |
if (e != i + 1) |
| 3267 |
str += ", "; |
| 3268 |
} |
| 3269 |
|
| 3270 |
return str + ")"; |
| 3271 |
} |
| 3272 |
|
| 3273 |
std::string |
| 3274 |
AttrInputMetaItemContainer::as_string () const |
| 3275 |
{ |
| 3276 |
std::string str = "("; |
| 3277 |
|
| 3278 |
auto i = items.begin (); |
| 3279 |
auto e = items.end (); |
| 3280 |
|
| 3281 |
for (; i != e; i++) |
| 3282 |
{ |
| 3283 |
str += (*i)->as_string (); |
| 3284 |
if (e != i + 1) |
| 3285 |
str += ", "; |
| 3286 |
} |
| 3287 |
|
| 3288 |
return str + ")"; |
| 3289 |
} |
| 3290 |
|
| 3291 |
std::string |
| 3292 |
AttrInputMacro::as_string () const |
| 3293 |
{ |
| 3294 |
return " = " + macro->as_string (); |
| 3295 |
} |
| 3296 |
|
| 3297 |
/* Override that calls the function recursively on all items contained within |
| 3298 |
* the module. */ |
| 3299 |
void |
| 3300 |
Module::add_crate_name (std::vector<std::string> &names) const |
| 3301 |
{ |
| 3302 |
/* TODO: test whether module has been 'cfg'-ed out to determine whether to |
| 3303 |
* exclude it from search */ |
| 3304 |
|
| 3305 |
for (const auto &item : items) |
| 3306 |
item->add_crate_name (names); |
| 3307 |
} |
| 3308 |
|
| 3309 |
static bool |
| 3310 |
file_exists (const std::string path) |
| 3311 |
{ |
| 3312 |
// Simply check if the file exists |
| 3313 |
// FIXME: This does not work on Windows |
| 3314 |
return access (path.c_str (), F_OK) != -1; |
| 3315 |
} |
| 3316 |
|
| 3317 |
static std::string |
| 3318 |
filename_from_path_attribute (std::vector<Attribute> &outer_attrs) |
| 3319 |
{ |
| 3320 |
// An out-of-line module cannot have inner attributes. Additionally, the |
| 3321 |
// default name is specified as `""` so that the caller can detect the case |
| 3322 |
// of "no path given" and use the default path logic (`name.rs` or |
| 3323 |
// `name/mod.rs`). |
| 3324 |
return extract_module_path ({}, outer_attrs, ""); |
| 3325 |
} |
| 3326 |
|
| 3327 |
void |
| 3328 |
Module::process_file_path () |
| 3329 |
{ |
| 3330 |
rust_assert (kind == Module::ModuleKind::UNLOADED); |
| 3331 |
rust_assert (module_file.empty ()); |
| 3332 |
|
| 3333 |
// This corresponds to the path of the file 'including' the module. So the |
| 3334 |
// file that contains the 'mod <file>;' directive |
| 3335 |
std::string including_fpath (outer_filename); |
| 3336 |
|
| 3337 |
std::string expected_file_path = module_name.as_string () + ".rs"; |
| 3338 |
std::string expected_dir_path = "mod.rs"; |
| 3339 |
|
| 3340 |
auto dir_slash_pos = including_fpath.rfind (file_separator); |
| 3341 |
std::string current_directory_name; |
| 3342 |
std::string including_fname; |
| 3343 |
|
| 3344 |
// If we haven't found a file_separator, then we may have to look for files in |
| 3345 |
// the current directory ('.') |
| 3346 |
if (dir_slash_pos == std::string::npos) |
| 3347 |
{ |
| 3348 |
including_fname = std::move (including_fpath); |
| 3349 |
including_fpath = std::string (".") + file_separator + including_fname; |
| 3350 |
dir_slash_pos = 1; |
| 3351 |
} |
| 3352 |
else |
| 3353 |
{ |
| 3354 |
including_fname = including_fpath.substr (dir_slash_pos + 1); |
| 3355 |
} |
| 3356 |
|
| 3357 |
current_directory_name |
| 3358 |
= including_fpath.substr (0, dir_slash_pos) + file_separator; |
| 3359 |
|
| 3360 |
auto path_string = filename_from_path_attribute (get_outer_attrs ()); |
| 3361 |
|
| 3362 |
std::string including_subdir; |
| 3363 |
if (path_string.empty () && module_scope.empty () |
| 3364 |
&& get_file_subdir (including_fname, including_subdir)) |
| 3365 |
current_directory_name += including_subdir + file_separator; |
| 3366 |
|
| 3367 |
// Handle inline module declarations adding path components. |
| 3368 |
for (auto const &name : module_scope) |
| 3369 |
{ |
| 3370 |
current_directory_name.append (name); |
| 3371 |
current_directory_name.append (file_separator); |
| 3372 |
} |
| 3373 |
|
| 3374 |
if (!path_string.empty ()) |
| 3375 |
{ |
| 3376 |
module_file = current_directory_name + path_string; |
| 3377 |
return; |
| 3378 |
} |
| 3379 |
|
| 3380 |
// FIXME: We also have to search for |
| 3381 |
// <directory>/<including_fname>/<module_name>.rs In rustc, this is done via |
| 3382 |
// the concept of `DirOwnernship`, which is based on whether or not the |
| 3383 |
// current file is titled `mod.rs`. |
| 3384 |
|
| 3385 |
// First, we search for <directory>/<module_name>.rs |
| 3386 |
std::string file_mod_path = current_directory_name + expected_file_path; |
| 3387 |
bool file_mod_found = file_exists (file_mod_path); |
| 3388 |
|
| 3389 |
// Then, search for <directory>/<module_name>/mod.rs |
| 3390 |
std::string dir_mod_path = current_directory_name + module_name.as_string () |
| 3391 |
+ file_separator + expected_dir_path; |
| 3392 |
bool dir_mod_found = file_exists (dir_mod_path); |
| 3393 |
|
| 3394 |
bool multiple_candidates_found = file_mod_found && dir_mod_found; |
| 3395 |
bool no_candidates_found = !file_mod_found && !dir_mod_found; |
| 3396 |
|
| 3397 |
if (multiple_candidates_found) |
| 3398 |
rust_error_at (locus, |
| 3399 |
"two candidates found for module %s: %s.rs and %s%smod.rs", |
| 3400 |
module_name.as_string ().c_str (), |
| 3401 |
module_name.as_string ().c_str (), |
| 3402 |
module_name.as_string ().c_str (), file_separator); |
| 3403 |
|
| 3404 |
if (no_candidates_found) |
| 3405 |
rust_error_at (locus, "no candidate found for module %s", |
| 3406 |
module_name.as_string ().c_str ()); |
| 3407 |
|
| 3408 |
if (no_candidates_found || multiple_candidates_found) |
| 3409 |
return; |
| 3410 |
|
| 3411 |
module_file = std::move (file_mod_found ? file_mod_path : dir_mod_path); |
| 3412 |
} |
| 3413 |
|
| 3414 |
void |
| 3415 |
Module::load_items () |
| 3416 |
{ |
| 3417 |
process_file_path (); |
| 3418 |
|
| 3419 |
// We will already have errored out appropriately in the process_file_path () |
| 3420 |
// method |
| 3421 |
if (module_file.empty ()) |
| 3422 |
return; |
| 3423 |
|
| 3424 |
RAIIFile file_wrap (module_file.c_str ()); |
| 3425 |
Linemap *linemap = Session::get_instance ().linemap; |
| 3426 |
if (!file_wrap.ok ()) |
| 3427 |
{ |
| 3428 |
rust_error_at (get_locus (), "cannot open module file %s: %m", |
| 3429 |
module_file.c_str ()); |
| 3430 |
return; |
| 3431 |
} |
| 3432 |
|
| 3433 |
rust_debug ("Attempting to parse file %s", module_file.c_str ()); |
| 3434 |
|
| 3435 |
Lexer lex (module_file.c_str (), std::move (file_wrap), linemap); |
| 3436 |
Parser<Lexer> parser (lex); |
| 3437 |
|
| 3438 |
// we need to parse any possible inner attributes for this module |
| 3439 |
inner_attrs = parser.parse_inner_attributes (); |
| 3440 |
auto parsed_items = parser.parse_items (); |
| 3441 |
for (const auto &error : parser.get_errors ()) |
| 3442 |
error.emit (); |
| 3443 |
|
| 3444 |
items = std::move (parsed_items); |
| 3445 |
kind = ModuleKind::LOADED; |
| 3446 |
} |
| 3447 |
|
| 3448 |
void |
| 3449 |
Attribute::parse_attr_to_meta_item () |
| 3450 |
{ |
| 3451 |
// only parse if has attribute input and not already parsed |
| 3452 |
if (!has_attr_input () || is_parsed_to_meta_item ()) |
| 3453 |
return; |
| 3454 |
|
| 3455 |
auto res = attr_input->parse_to_meta_item (); |
| 3456 |
std::unique_ptr<AttrInput> converted_input (res); |
| 3457 |
|
| 3458 |
if (converted_input != nullptr) |
| 3459 |
attr_input = std::move (converted_input); |
| 3460 |
} |
| 3461 |
|
| 3462 |
AttrInputMetaItemContainer * |
| 3463 |
DelimTokenTree::parse_to_meta_item () const |
| 3464 |
{ |
| 3465 |
// must have token trees |
| 3466 |
if (token_trees.empty ()) |
| 3467 |
return nullptr; |
| 3468 |
|
| 3469 |
/* assume top-level delim token tree in attribute - convert all nested ones |
| 3470 |
* to token stream */ |
| 3471 |
std::vector<std::unique_ptr<Token>> token_stream = to_token_stream (); |
| 3472 |
|
| 3473 |
AttributeParser parser (std::move (token_stream)); |
| 3474 |
std::vector<std::unique_ptr<MetaItemInner>> meta_items ( |
| 3475 |
parser.parse_meta_item_seq ()); |
| 3476 |
|
| 3477 |
return new AttrInputMetaItemContainer (std::move (meta_items)); |
| 3478 |
} |
| 3479 |
|
| 3480 |
std::unique_ptr<MetaItemInner> |
| 3481 |
AttributeParser::parse_meta_item_inner () |
| 3482 |
{ |
| 3483 |
// if first tok not identifier, not a "special" case one |
| 3484 |
if (peek_token ()->get_id () != IDENTIFIER) |
| 3485 |
{ |
| 3486 |
switch (peek_token ()->get_id ()) |
| 3487 |
{ |
| 3488 |
case CHAR_LITERAL: |
| 3489 |
case STRING_LITERAL: |
| 3490 |
case BYTE_CHAR_LITERAL: |
| 3491 |
case BYTE_STRING_LITERAL: |
| 3492 |
case RAW_STRING_LITERAL: |
| 3493 |
case INT_LITERAL: |
| 3494 |
case FLOAT_LITERAL: |
| 3495 |
case TRUE_LITERAL: |
| 3496 |
case FALSE_LITERAL: |
| 3497 |
return parse_meta_item_lit (); |
| 3498 |
|
| 3499 |
case SUPER: |
| 3500 |
case SELF: |
| 3501 |
case CRATE: |
| 3502 |
case DOLLAR_SIGN: |
| 3503 |
case SCOPE_RESOLUTION: |
| 3504 |
return parse_path_meta_item (); |
| 3505 |
|
| 3506 |
default: |
| 3507 |
rust_error_at (peek_token ()->get_locus (), |
| 3508 |
"unrecognised token '%s' in meta item", |
| 3509 |
get_token_description (peek_token ()->get_id ())); |
| 3510 |
return nullptr; |
| 3511 |
} |
| 3512 |
} |
| 3513 |
|
| 3514 |
// else, check for path |
| 3515 |
if (peek_token (1)->get_id () == SCOPE_RESOLUTION) |
| 3516 |
{ |
| 3517 |
// path |
| 3518 |
return parse_path_meta_item (); |
| 3519 |
} |
| 3520 |
|
| 3521 |
auto ident = peek_token ()->as_string (); |
| 3522 |
auto ident_locus = peek_token ()->get_locus (); |
| 3523 |
|
| 3524 |
if (is_end_meta_item_tok (peek_token (1)->get_id ())) |
| 3525 |
{ |
| 3526 |
// meta word syntax |
| 3527 |
skip_token (); |
| 3528 |
return std::unique_ptr<MetaWord> (new MetaWord (ident, ident_locus)); |
| 3529 |
} |
| 3530 |
|
| 3531 |
if (peek_token (1)->get_id () == EQUAL) |
| 3532 |
{ |
| 3533 |
// maybe meta name value str syntax - check next 2 tokens |
| 3534 |
if (peek_token (2)->get_id () == STRING_LITERAL |
| 3535 |
&& is_end_meta_item_tok (peek_token (3)->get_id ())) |
| 3536 |
{ |
| 3537 |
// meta name value str syntax |
| 3538 |
auto &value_tok = peek_token (2); |
| 3539 |
auto value = value_tok->as_string (); |
| 3540 |
auto locus = value_tok->get_locus (); |
| 3541 |
|
| 3542 |
skip_token (2); |
| 3543 |
|
| 3544 |
// remove the quotes from the string value |
| 3545 |
std::string raw_value = unquote_string (std::move (value)); |
| 3546 |
|
| 3547 |
return std::unique_ptr<MetaNameValueStr> ( |
| 3548 |
new MetaNameValueStr (ident, ident_locus, std::move (raw_value), |
| 3549 |
locus)); |
| 3550 |
} |
| 3551 |
else |
| 3552 |
{ |
| 3553 |
// just interpret as path-based meta item |
| 3554 |
return parse_path_meta_item (); |
| 3555 |
} |
| 3556 |
} |
| 3557 |
|
| 3558 |
if (peek_token (1)->get_id () != LEFT_PAREN) |
| 3559 |
{ |
| 3560 |
rust_error_at (peek_token (1)->get_locus (), |
| 3561 |
"unexpected token '%s' after identifier in attribute", |
| 3562 |
get_token_description (peek_token (1)->get_id ())); |
| 3563 |
return nullptr; |
| 3564 |
} |
| 3565 |
|
| 3566 |
// is it one of those special cases like not? |
| 3567 |
if (peek_token ()->get_id () == IDENTIFIER) |
| 3568 |
{ |
| 3569 |
return parse_path_meta_item (); |
| 3570 |
} |
| 3571 |
|
| 3572 |
auto meta_items = parse_meta_item_seq (); |
| 3573 |
|
| 3574 |
// pass for meta name value str |
| 3575 |
std::vector<MetaNameValueStr> meta_name_value_str_items; |
| 3576 |
for (const auto &item : meta_items) |
| 3577 |
{ |
| 3578 |
std::unique_ptr<MetaNameValueStr> converted_item |
| 3579 |
= item->to_meta_name_value_str (); |
| 3580 |
if (converted_item == nullptr) |
| 3581 |
{ |
| 3582 |
meta_name_value_str_items.clear (); |
| 3583 |
break; |
| 3584 |
} |
| 3585 |
meta_name_value_str_items.push_back (std::move (*converted_item)); |
| 3586 |
} |
| 3587 |
// if valid, return this |
| 3588 |
if (!meta_name_value_str_items.empty ()) |
| 3589 |
{ |
| 3590 |
return std::unique_ptr<MetaListNameValueStr> ( |
| 3591 |
new MetaListNameValueStr (ident, ident_locus, |
| 3592 |
std::move (meta_name_value_str_items))); |
| 3593 |
} |
| 3594 |
|
| 3595 |
// // pass for meta list idents |
| 3596 |
// std::vector<Identifier> ident_items; |
| 3597 |
// for (const auto &item : meta_items) |
| 3598 |
// { |
| 3599 |
// std::unique_ptr<Identifier> converted_ident (item->to_ident_item ()); |
| 3600 |
// if (converted_ident == nullptr) |
| 3601 |
// { |
| 3602 |
// ident_items.clear (); |
| 3603 |
// break; |
| 3604 |
// } |
| 3605 |
// ident_items.push_back (std::move (*converted_ident)); |
| 3606 |
// } |
| 3607 |
// // if valid return this |
| 3608 |
// if (!ident_items.empty ()) |
| 3609 |
// { |
| 3610 |
// return std::unique_ptr<MetaListIdents> ( |
| 3611 |
// new MetaListIdents (std::move (ident), std::move (ident_items))); |
| 3612 |
// } |
| 3613 |
// // as currently no meta list ident, currently no path. may change in future |
| 3614 |
|
| 3615 |
// pass for meta list paths |
| 3616 |
std::vector<SimplePath> path_items; |
| 3617 |
for (const auto &item : meta_items) |
| 3618 |
{ |
| 3619 |
SimplePath converted_path (item->to_path_item ()); |
| 3620 |
if (converted_path.is_empty ()) |
| 3621 |
{ |
| 3622 |
path_items.clear (); |
| 3623 |
break; |
| 3624 |
} |
| 3625 |
path_items.push_back (std::move (converted_path)); |
| 3626 |
} |
| 3627 |
if (!path_items.empty ()) |
| 3628 |
{ |
| 3629 |
return std::unique_ptr<MetaListPaths> ( |
| 3630 |
new MetaListPaths (ident, ident_locus, std::move (path_items))); |
| 3631 |
} |
| 3632 |
|
| 3633 |
rust_error_at (UNKNOWN_LOCATION, "failed to parse any meta item inner"); |
| 3634 |
return nullptr; |
| 3635 |
} |
| 3636 |
|
| 3637 |
bool |
| 3638 |
AttributeParser::is_end_meta_item_tok (TokenId id) const |
| 3639 |
{ |
| 3640 |
return id == COMMA || id == RIGHT_PAREN; |
| 3641 |
} |
| 3642 |
|
| 3643 |
std::unique_ptr<MetaItem> |
| 3644 |
AttributeParser::parse_path_meta_item () |
| 3645 |
{ |
| 3646 |
SimplePath path = parse_simple_path (); |
| 3647 |
if (path.is_empty ()) |
| 3648 |
{ |
| 3649 |
rust_error_at (peek_token ()->get_locus (), |
| 3650 |
"failed to parse simple path in attribute"); |
| 3651 |
return nullptr; |
| 3652 |
} |
| 3653 |
|
| 3654 |
switch (peek_token ()->get_id ()) |
| 3655 |
{ |
| 3656 |
case LEFT_PAREN: { |
| 3657 |
std::vector<std::unique_ptr<MetaItemInner>> meta_items |
| 3658 |
= parse_meta_item_seq (); |
| 3659 |
|
| 3660 |
return std::unique_ptr<MetaItemSeq> ( |
| 3661 |
new MetaItemSeq (std::move (path), std::move (meta_items))); |
| 3662 |
} |
| 3663 |
case EQUAL: { |
| 3664 |
skip_token (); |
| 3665 |
|
| 3666 |
location_t locus = peek_token ()->get_locus (); |
| 3667 |
Literal lit = parse_literal (); |
| 3668 |
if (lit.is_error ()) |
| 3669 |
{ |
| 3670 |
rust_error_at (peek_token ()->get_locus (), |
| 3671 |
"failed to parse literal in attribute"); |
| 3672 |
return nullptr; |
| 3673 |
} |
| 3674 |
LiteralExpr expr (std::move (lit), {}, locus); |
| 3675 |
// stream_pos++; |
| 3676 |
/* shouldn't be required anymore due to parsing literal actually |
| 3677 |
* skipping the token */ |
| 3678 |
return std::unique_ptr<MetaItemPathLit> ( |
| 3679 |
new MetaItemPathLit (std::move (path), std::move (expr))); |
| 3680 |
} |
| 3681 |
case COMMA: |
| 3682 |
// just simple path |
| 3683 |
return std::unique_ptr<MetaItemPath> ( |
| 3684 |
new MetaItemPath (std::move (path))); |
| 3685 |
default: |
| 3686 |
rust_error_at (peek_token ()->get_locus (), |
| 3687 |
"unrecognised token '%s' in meta item", |
| 3688 |
get_token_description (peek_token ()->get_id ())); |
| 3689 |
return nullptr; |
| 3690 |
} |
| 3691 |
} |
| 3692 |
|
| 3693 |
/* Parses a parenthesised sequence of meta item inners. Parentheses are |
| 3694 |
* required here. */ |
| 3695 |
std::vector<std::unique_ptr<MetaItemInner>> |
| 3696 |
AttributeParser::parse_meta_item_seq () |
| 3697 |
{ |
| 3698 |
int vec_length = token_stream.size (); |
| 3699 |
std::vector<std::unique_ptr<MetaItemInner>> meta_items; |
| 3700 |
|
| 3701 |
if (peek_token ()->get_id () != LEFT_PAREN) |
| 3702 |
{ |
| 3703 |
rust_error_at (peek_token ()->get_locus (), |
| 3704 |
"missing left paren in delim token tree"); |
| 3705 |
return {}; |
| 3706 |
} |
| 3707 |
skip_token (); |
| 3708 |
|
| 3709 |
while (stream_pos < vec_length && peek_token ()->get_id () != RIGHT_PAREN) |
| 3710 |
{ |
| 3711 |
std::unique_ptr<MetaItemInner> inner = parse_meta_item_inner (); |
| 3712 |
if (inner == nullptr) |
| 3713 |
{ |
| 3714 |
rust_error_at (peek_token ()->get_locus (), |
| 3715 |
"failed to parse inner meta item in attribute"); |
| 3716 |
return {}; |
| 3717 |
} |
| 3718 |
meta_items.push_back (std::move (inner)); |
| 3719 |
|
| 3720 |
if (peek_token ()->get_id () != COMMA) |
| 3721 |
break; |
| 3722 |
|
| 3723 |
skip_token (); |
| 3724 |
} |
| 3725 |
|
| 3726 |
if (peek_token ()->get_id () != RIGHT_PAREN) |
| 3727 |
{ |
| 3728 |
rust_error_at (peek_token ()->get_locus (), |
| 3729 |
"missing right paren in delim token tree"); |
| 3730 |
return {}; |
| 3731 |
} |
| 3732 |
skip_token (); |
| 3733 |
|
| 3734 |
return meta_items; |
| 3735 |
} |
| 3736 |
|
| 3737 |
/* Collects any nested token trees into a flat token stream, suitable for |
| 3738 |
* parsing. */ |
| 3739 |
std::vector<std::unique_ptr<Token>> |
| 3740 |
DelimTokenTree::to_token_stream () const |
| 3741 |
{ |
| 3742 |
std::vector<std::unique_ptr<Token>> tokens; |
| 3743 |
for (const auto &tree : token_trees) |
| 3744 |
{ |
| 3745 |
std::vector<std::unique_ptr<Token>> stream = tree->to_token_stream (); |
| 3746 |
|
| 3747 |
tokens.insert (tokens.end (), std::make_move_iterator (stream.begin ()), |
| 3748 |
std::make_move_iterator (stream.end ())); |
| 3749 |
} |
| 3750 |
|
| 3751 |
tokens.shrink_to_fit (); |
| 3752 |
return tokens; |
| 3753 |
} |
| 3754 |
|
| 3755 |
Literal |
| 3756 |
AttributeParser::parse_literal () |
| 3757 |
{ |
| 3758 |
const std::unique_ptr<Token> &tok = peek_token (); |
| 3759 |
switch (tok->get_id ()) |
| 3760 |
{ |
| 3761 |
case CHAR_LITERAL: |
| 3762 |
skip_token (); |
| 3763 |
return Literal (tok->as_string (), Literal::CHAR, tok->get_type_hint ()); |
| 3764 |
case STRING_LITERAL: |
| 3765 |
skip_token (); |
| 3766 |
return Literal (tok->as_string (), Literal::STRING, |
| 3767 |
tok->get_type_hint ()); |
| 3768 |
case BYTE_CHAR_LITERAL: |
| 3769 |
skip_token (); |
| 3770 |
return Literal (tok->as_string (), Literal::BYTE, tok->get_type_hint ()); |
| 3771 |
case BYTE_STRING_LITERAL: |
| 3772 |
skip_token (); |
| 3773 |
return Literal (tok->as_string (), Literal::BYTE_STRING, |
| 3774 |
tok->get_type_hint ()); |
| 3775 |
case RAW_STRING_LITERAL: |
| 3776 |
skip_token (); |
| 3777 |
return Literal (tok->as_string (), Literal::RAW_STRING, |
| 3778 |
tok->get_type_hint ()); |
| 3779 |
case INT_LITERAL: |
| 3780 |
skip_token (); |
| 3781 |
return Literal (tok->as_string (), Literal::INT, tok->get_type_hint ()); |
| 3782 |
case FLOAT_LITERAL: |
| 3783 |
skip_token (); |
| 3784 |
return Literal (tok->as_string (), Literal::FLOAT, tok->get_type_hint ()); |
| 3785 |
case TRUE_LITERAL: |
| 3786 |
skip_token (); |
| 3787 |
return Literal ("true", Literal::BOOL, tok->get_type_hint ()); |
| 3788 |
case FALSE_LITERAL: |
| 3789 |
skip_token (); |
| 3790 |
return Literal ("false", Literal::BOOL, tok->get_type_hint ()); |
| 3791 |
default: |
| 3792 |
rust_error_at (tok->get_locus (), "expected literal - found '%s'", |
| 3793 |
get_token_description (tok->get_id ())); |
| 3794 |
return Literal::create_error (); |
| 3795 |
} |
| 3796 |
} |
| 3797 |
|
| 3798 |
SimplePath |
| 3799 |
AttributeParser::parse_simple_path () |
| 3800 |
{ |
| 3801 |
bool has_opening_scope_res = false; |
| 3802 |
if (peek_token ()->get_id () == SCOPE_RESOLUTION) |
| 3803 |
{ |
| 3804 |
has_opening_scope_res = true; |
| 3805 |
skip_token (); |
| 3806 |
} |
| 3807 |
|
| 3808 |
std::vector<SimplePathSegment> segments; |
| 3809 |
|
| 3810 |
SimplePathSegment segment = parse_simple_path_segment (); |
| 3811 |
if (segment.is_error ()) |
| 3812 |
{ |
| 3813 |
rust_error_at ( |
| 3814 |
peek_token ()->get_locus (), |
| 3815 |
"failed to parse simple path segment in attribute simple path"); |
| 3816 |
return SimplePath::create_empty (); |
| 3817 |
} |
| 3818 |
segments.push_back (std::move (segment)); |
| 3819 |
|
| 3820 |
while (peek_token ()->get_id () == SCOPE_RESOLUTION) |
| 3821 |
{ |
| 3822 |
skip_token (); |
| 3823 |
|
| 3824 |
SimplePathSegment segment = parse_simple_path_segment (); |
| 3825 |
if (segment.is_error ()) |
| 3826 |
{ |
| 3827 |
rust_error_at ( |
| 3828 |
peek_token ()->get_locus (), |
| 3829 |
"failed to parse simple path segment in attribute simple path"); |
| 3830 |
return SimplePath::create_empty (); |
| 3831 |
} |
| 3832 |
segments.push_back (std::move (segment)); |
| 3833 |
} |
| 3834 |
segments.shrink_to_fit (); |
| 3835 |
|
| 3836 |
return SimplePath (std::move (segments), has_opening_scope_res); |
| 3837 |
} |
| 3838 |
|
| 3839 |
SimplePathSegment |
| 3840 |
AttributeParser::parse_simple_path_segment () |
| 3841 |
{ |
| 3842 |
const std::unique_ptr<Token> &tok = peek_token (); |
| 3843 |
switch (tok->get_id ()) |
| 3844 |
{ |
| 3845 |
case IDENTIFIER: |
| 3846 |
skip_token (); |
| 3847 |
return SimplePathSegment (tok->as_string (), tok->get_locus ()); |
| 3848 |
case SUPER: |
| 3849 |
skip_token (); |
| 3850 |
return SimplePathSegment ("super", tok->get_locus ()); |
| 3851 |
case SELF: |
| 3852 |
skip_token (); |
| 3853 |
return SimplePathSegment ("self", tok->get_locus ()); |
| 3854 |
case CRATE: |
| 3855 |
skip_token (); |
| 3856 |
return SimplePathSegment ("crate", tok->get_locus ()); |
| 3857 |
case DOLLAR_SIGN: |
| 3858 |
if (peek_token (1)->get_id () == CRATE) |
| 3859 |
{ |
| 3860 |
skip_token (1); |
| 3861 |
return SimplePathSegment ("$crate", tok->get_locus ()); |
| 3862 |
} |
| 3863 |
gcc_fallthrough (); |
| 3864 |
default: |
| 3865 |
rust_error_at (tok->get_locus (), |
| 3866 |
"unexpected token '%s' in simple path segment", |
| 3867 |
get_token_description (tok->get_id ())); |
| 3868 |
return SimplePathSegment::create_error (); |
| 3869 |
} |
| 3870 |
} |
| 3871 |
|
| 3872 |
std::unique_ptr<MetaItemLitExpr> |
| 3873 |
AttributeParser::parse_meta_item_lit () |
| 3874 |
{ |
| 3875 |
location_t locus = peek_token ()->get_locus (); |
| 3876 |
LiteralExpr lit_expr (parse_literal (), {}, locus); |
| 3877 |
return std::unique_ptr<MetaItemLitExpr> ( |
| 3878 |
new MetaItemLitExpr (std::move (lit_expr))); |
| 3879 |
} |
| 3880 |
|
| 3881 |
bool |
| 3882 |
AttrInputMetaItemContainer::check_cfg_predicate (const Session &session) const |
| 3883 |
{ |
| 3884 |
if (items.empty ()) |
| 3885 |
return false; |
| 3886 |
|
| 3887 |
for (const auto &inner_item : items) |
| 3888 |
{ |
| 3889 |
if (!inner_item->check_cfg_predicate (session)) |
| 3890 |
return false; |
| 3891 |
} |
| 3892 |
|
| 3893 |
return true; |
| 3894 |
} |
| 3895 |
|
| 3896 |
bool |
| 3897 |
MetaItemLitExpr::check_cfg_predicate (const Session &) const |
| 3898 |
{ |
| 3899 |
/* as far as I can tell, a literal expr can never be a valid cfg body, so |
| 3900 |
* false */ |
| 3901 |
return false; |
| 3902 |
} |
| 3903 |
|
| 3904 |
bool |
| 3905 |
MetaListNameValueStr::check_cfg_predicate (const Session &session) const |
| 3906 |
{ |
| 3907 |
if (ident.as_string () == "all") |
| 3908 |
{ |
| 3909 |
for (const auto &str : strs) |
| 3910 |
{ |
| 3911 |
if (!str.check_cfg_predicate (session)) |
| 3912 |
return false; |
| 3913 |
} |
| 3914 |
return true; |
| 3915 |
} |
| 3916 |
else if (ident.as_string () == "any") |
| 3917 |
{ |
| 3918 |
for (const auto &str : strs) |
| 3919 |
{ |
| 3920 |
if (str.check_cfg_predicate (session)) |
| 3921 |
return true; |
| 3922 |
} |
| 3923 |
return false; |
| 3924 |
} |
| 3925 |
else if (ident.as_string () == "not") |
| 3926 |
{ |
| 3927 |
if (strs.size () != 1) |
| 3928 |
{ |
| 3929 |
/* HACK: convert vector platform-dependent size_type to string to |
| 3930 |
* use in printf */ |
| 3931 |
rust_error_at (UNKNOWN_LOCATION, |
| 3932 |
"cfg predicate could not be checked for " |
| 3933 |
"MetaListNameValueStr with ident of " |
| 3934 |
"'not' because there are '%s' elements, not '1'", |
| 3935 |
std::to_string (strs.size ()).c_str ()); |
| 3936 |
return false; |
| 3937 |
} |
| 3938 |
|
| 3939 |
return !strs[0].check_cfg_predicate (session); |
| 3940 |
} |
| 3941 |
else |
| 3942 |
{ |
| 3943 |
rust_error_at (UNKNOWN_LOCATION, |
| 3944 |
"cfg predicate could not be checked for " |
| 3945 |
"MetaListNameValueStr with ident of " |
| 3946 |
"'%s' - ident must be 'all' or 'any'", |
| 3947 |
ident.as_string ().c_str ()); |
| 3948 |
return false; |
| 3949 |
} |
| 3950 |
} |
| 3951 |
|
| 3952 |
bool |
| 3953 |
MetaListPaths::check_cfg_predicate (const Session &session) const |
| 3954 |
{ |
| 3955 |
if (ident.as_string () == "all") |
| 3956 |
{ |
| 3957 |
for (const auto &path : paths) |
| 3958 |
{ |
| 3959 |
if (!check_path_exists_in_cfg (session, path)) |
| 3960 |
return false; |
| 3961 |
} |
| 3962 |
return true; |
| 3963 |
} |
| 3964 |
else if (ident.as_string () == "any") |
| 3965 |
{ |
| 3966 |
for (const auto &path : paths) |
| 3967 |
{ |
| 3968 |
if (check_path_exists_in_cfg (session, path)) |
| 3969 |
return true; |
| 3970 |
} |
| 3971 |
return false; |
| 3972 |
} |
| 3973 |
else if (ident.as_string () == "not") |
| 3974 |
{ |
| 3975 |
if (paths.size () != 1) |
| 3976 |
{ |
| 3977 |
// HACK: convert vector platform-dependent size_type to string to |
| 3978 |
// use in printf |
| 3979 |
rust_error_at (UNKNOWN_LOCATION, |
| 3980 |
"cfg predicate could not be checked for MetaListPaths " |
| 3981 |
"with ident of 'not' " |
| 3982 |
"because there are '%s' elements, not '1'", |
| 3983 |
std::to_string (paths.size ()).c_str ()); |
| 3984 |
return false; |
| 3985 |
} |
| 3986 |
|
| 3987 |
return !check_path_exists_in_cfg (session, paths[0]); |
| 3988 |
} |
| 3989 |
else |
| 3990 |
{ |
| 3991 |
rust_error_at (UNKNOWN_LOCATION, |
| 3992 |
"cfg predicate could not be checked for " |
| 3993 |
"MetaListNameValueStr with ident of " |
| 3994 |
"'%s' - ident must be 'all' or 'any'", |
| 3995 |
ident.as_string ().c_str ()); |
| 3996 |
return false; |
| 3997 |
} |
| 3998 |
} |
| 3999 |
|
| 4000 |
bool |
| 4001 |
MetaListPaths::check_path_exists_in_cfg (const Session &session, |
| 4002 |
const SimplePath &path) const |
| 4003 |
{ |
| 4004 |
return session.options.target_data.has_key (path.as_string ()); |
| 4005 |
} |
| 4006 |
|
| 4007 |
bool |
| 4008 |
MetaItemSeq::check_cfg_predicate (const Session &session) const |
| 4009 |
{ |
| 4010 |
if (path.as_string () == "all") |
| 4011 |
{ |
| 4012 |
for (const auto &item : seq) |
| 4013 |
{ |
| 4014 |
if (!item->check_cfg_predicate (session)) |
| 4015 |
return false; |
| 4016 |
} |
| 4017 |
return true; |
| 4018 |
} |
| 4019 |
else if (path.as_string () == "any") |
| 4020 |
{ |
| 4021 |
for (const auto &item : seq) |
| 4022 |
{ |
| 4023 |
if (item->check_cfg_predicate (session)) |
| 4024 |
return true; |
| 4025 |
} |
| 4026 |
return false; |
| 4027 |
} |
| 4028 |
else if (path.as_string () == "not") |
| 4029 |
{ |
| 4030 |
if (seq.size () != 1) |
| 4031 |
{ |
| 4032 |
/* HACK: convert vector platform-dependent size_type to string to |
| 4033 |
* use in printf */ |
| 4034 |
rust_error_at (UNKNOWN_LOCATION, |
| 4035 |
"cfg predicate could not be checked for MetaItemSeq " |
| 4036 |
"with ident of 'not' " |
| 4037 |
"because there are '%s' elements, not '1'", |
| 4038 |
std::to_string (seq.size ()).c_str ()); |
| 4039 |
return false; |
| 4040 |
} |
| 4041 |
|
| 4042 |
return !seq[0]->check_cfg_predicate (session); |
| 4043 |
} |
| 4044 |
else |
| 4045 |
{ |
| 4046 |
rust_error_at ( |
| 4047 |
UNKNOWN_LOCATION, |
| 4048 |
"cfg predicate could not be checked for MetaItemSeq with path of " |
| 4049 |
"'%s' - path must be 'all' or 'any'", |
| 4050 |
path.as_string ().c_str ()); |
| 4051 |
return false; |
| 4052 |
} |
| 4053 |
} |
| 4054 |
|
| 4055 |
bool |
| 4056 |
MetaWord::check_cfg_predicate (const Session &session) const |
| 4057 |
{ |
| 4058 |
return session.options.target_data.has_key (ident.as_string ()); |
| 4059 |
} |
| 4060 |
|
| 4061 |
bool |
| 4062 |
MetaItemPath::check_cfg_predicate (const Session &session) const |
| 4063 |
{ |
| 4064 |
/* Strictly speaking, this should always be false, but maybe do check |
| 4065 |
* relating to SimplePath being identifier. Currently, it would return true |
| 4066 |
* if path as identifier existed, and if the path in string form existed |
| 4067 |
* (though this shouldn't occur). */ |
| 4068 |
return session.options.target_data.has_key (path.as_string ()); |
| 4069 |
} |
| 4070 |
|
| 4071 |
bool |
| 4072 |
MetaNameValueStr::check_cfg_predicate (const Session &session) const |
| 4073 |
{ |
| 4074 |
// DEBUG |
| 4075 |
rust_debug ( |
| 4076 |
"checked key-value pair for cfg: '%s', '%s' - is%s in target data", |
| 4077 |
ident.as_string ().c_str (), str.c_str (), |
| 4078 |
session.options.target_data.has_key_value_pair (ident.as_string (), str) |
| 4079 |
? "" |
| 4080 |
: " not"); |
| 4081 |
|
| 4082 |
return session.options.target_data.has_key_value_pair (ident.as_string (), |
| 4083 |
str); |
| 4084 |
} |
| 4085 |
|
| 4086 |
bool |
| 4087 |
MetaItemPathLit::check_cfg_predicate (const Session &session) const |
| 4088 |
{ |
| 4089 |
return session.options.target_data.has_key_value_pair (path.as_string (), |
| 4090 |
lit.as_string ()); |
| 4091 |
} |
| 4092 |
|
| 4093 |
std::vector<std::unique_ptr<Token>> |
| 4094 |
Token::to_token_stream () const |
| 4095 |
{ |
| 4096 |
/* initialisation list doesn't work as it needs copy constructor, so have to |
| 4097 |
* do this */ |
| 4098 |
std::vector<std::unique_ptr<Token>> dummy_vector; |
| 4099 |
dummy_vector.reserve (1); |
| 4100 |
dummy_vector.push_back (std::unique_ptr<Token> (clone_token_impl ())); |
| 4101 |
return dummy_vector; |
| 4102 |
} |
| 4103 |
|
| 4104 |
Attribute |
| 4105 |
MetaNameValueStr::to_attribute () const |
| 4106 |
{ |
| 4107 |
LiteralExpr lit_expr (str, Literal::LitType::STRING, |
| 4108 |
PrimitiveCoreType::CORETYPE_UNKNOWN, {}, str_locus); |
| 4109 |
// FIXME: What location do we put here? Is the literal above supposed to have |
| 4110 |
// an empty location as well? |
| 4111 |
// Should MetaNameValueStr keep a location? |
| 4112 |
return Attribute (SimplePath::from_str (ident.as_string (), ident_locus), |
| 4113 |
std::unique_ptr<AttrInputLiteral> ( |
| 4114 |
new AttrInputLiteral (std::move (lit_expr)))); |
| 4115 |
} |
| 4116 |
|
| 4117 |
Attribute |
| 4118 |
MetaItemPath::to_attribute () const |
| 4119 |
{ |
| 4120 |
return Attribute (path, nullptr); |
| 4121 |
} |
| 4122 |
|
| 4123 |
Attribute |
| 4124 |
MetaItemSeq::to_attribute () const |
| 4125 |
{ |
| 4126 |
std::vector<std::unique_ptr<MetaItemInner>> new_seq; |
| 4127 |
new_seq.reserve (seq.size ()); |
| 4128 |
for (const auto &e : seq) |
| 4129 |
new_seq.push_back (e->clone_meta_item_inner ()); |
| 4130 |
|
| 4131 |
std::unique_ptr<AttrInputMetaItemContainer> new_seq_container ( |
| 4132 |
new AttrInputMetaItemContainer (std::move (new_seq))); |
| 4133 |
return Attribute (path, std::move (new_seq_container)); |
| 4134 |
} |
| 4135 |
|
| 4136 |
Attribute |
| 4137 |
MetaWord::to_attribute () const |
| 4138 |
{ |
| 4139 |
return Attribute (SimplePath::from_str (ident.as_string (), ident_locus), |
| 4140 |
nullptr); |
| 4141 |
} |
| 4142 |
|
| 4143 |
Attribute |
| 4144 |
MetaListPaths::to_attribute () const |
| 4145 |
{ |
| 4146 |
/* probably one of the most annoying conversions - have to lose specificity by |
| 4147 |
* turning it into just AttrInputMetaItemContainer (i.e. paths-only nature is |
| 4148 |
* no longer known). If conversions back are required, might have to do a |
| 4149 |
* "check all are paths" pass or something. */ |
| 4150 |
|
| 4151 |
std::vector<std::unique_ptr<MetaItemInner>> new_seq; |
| 4152 |
new_seq.reserve (paths.size ()); |
| 4153 |
for (const auto &e : paths) |
| 4154 |
new_seq.push_back (std::unique_ptr<MetaItemPath> (new MetaItemPath (e))); |
| 4155 |
|
| 4156 |
std::unique_ptr<AttrInputMetaItemContainer> new_seq_container ( |
| 4157 |
new AttrInputMetaItemContainer (std::move (new_seq))); |
| 4158 |
return Attribute (SimplePath::from_str (ident.as_string (), ident_locus), |
| 4159 |
std::move (new_seq_container)); |
| 4160 |
} |
| 4161 |
|
| 4162 |
Attribute |
| 4163 |
MetaListNameValueStr::to_attribute () const |
| 4164 |
{ |
| 4165 |
std::vector<std::unique_ptr<MetaItemInner>> new_seq; |
| 4166 |
new_seq.reserve (strs.size ()); |
| 4167 |
for (const auto &e : strs) |
| 4168 |
new_seq.push_back ( |
| 4169 |
std::unique_ptr<MetaNameValueStr> (new MetaNameValueStr (e))); |
| 4170 |
|
| 4171 |
std::unique_ptr<AttrInputMetaItemContainer> new_seq_container ( |
| 4172 |
new AttrInputMetaItemContainer (std::move (new_seq))); |
| 4173 |
return Attribute (SimplePath::from_str (ident.as_string (), ident_locus), |
| 4174 |
std::move (new_seq_container)); |
| 4175 |
} |
| 4176 |
|
| 4177 |
Attribute |
| 4178 |
MetaItemPathLit::to_attribute () const |
| 4179 |
{ |
| 4180 |
return Attribute (path, std::unique_ptr<AttrInputLiteral> ( |
| 4181 |
new AttrInputLiteral (lit))); |
| 4182 |
} |
| 4183 |
|
| 4184 |
std::vector<Attribute> |
| 4185 |
AttrInputMetaItemContainer::separate_cfg_attrs () const |
| 4186 |
{ |
| 4187 |
rust_assert (!items.empty ()); |
| 4188 |
|
| 4189 |
if (items.size () == 1) |
| 4190 |
return {}; |
| 4191 |
|
| 4192 |
std::vector<Attribute> attrs; |
| 4193 |
attrs.reserve (items.size () - 1); |
| 4194 |
|
| 4195 |
for (auto it = items.begin () + 1; it != items.end (); ++it) |
| 4196 |
{ |
| 4197 |
Attribute attr = (*it)->to_attribute (); |
| 4198 |
if (attr.is_empty ()) |
| 4199 |
{ |
| 4200 |
/* TODO should this be an error that causes us to chuck out |
| 4201 |
* everything? */ |
| 4202 |
continue; |
| 4203 |
} |
| 4204 |
attrs.push_back (std::move (attr)); |
| 4205 |
} |
| 4206 |
|
| 4207 |
attrs.shrink_to_fit (); |
| 4208 |
return attrs; |
| 4209 |
} |
| 4210 |
|
| 4211 |
bool |
| 4212 |
Attribute::check_cfg_predicate (const Session &session) const |
| 4213 |
{ |
| 4214 |
/* assume that cfg predicate actually can exist, i.e. attribute has cfg or |
| 4215 |
* cfg_attr path */ |
| 4216 |
if (!has_attr_input () |
| 4217 |
|| (path.as_string () != Values::Attributes::CFG |
| 4218 |
&& path.as_string () != Values::Attributes::CFG_ATTR)) |
| 4219 |
{ |
| 4220 |
// DEBUG message |
| 4221 |
rust_debug ( |
| 4222 |
"tried to check cfg predicate on attr that either has no input " |
| 4223 |
"or invalid path. attr: '%s'", |
| 4224 |
as_string ().c_str ()); |
| 4225 |
|
| 4226 |
return false; |
| 4227 |
} |
| 4228 |
|
| 4229 |
// assume that it has already been parsed |
| 4230 |
if (!is_parsed_to_meta_item ()) |
| 4231 |
return false; |
| 4232 |
|
| 4233 |
auto &meta_item = static_cast<AttrInputMetaItemContainer &> (*attr_input); |
| 4234 |
return meta_item.get_items ().front ()->check_cfg_predicate (session); |
| 4235 |
} |
| 4236 |
|
| 4237 |
std::vector<Attribute> |
| 4238 |
Attribute::separate_cfg_attrs () const |
| 4239 |
{ |
| 4240 |
if (!has_attr_input () || path.as_string () != Values::Attributes::CFG_ATTR) |
| 4241 |
return {}; |
| 4242 |
|
| 4243 |
// assume that it has already been parsed |
| 4244 |
if (!is_parsed_to_meta_item ()) |
| 4245 |
return {}; |
| 4246 |
|
| 4247 |
return attr_input->separate_cfg_attrs (); |
| 4248 |
} |
| 4249 |
|
| 4250 |
bool |
| 4251 |
Attribute::is_parsed_to_meta_item () const |
| 4252 |
{ |
| 4253 |
return has_attr_input () && attr_input->is_meta_item (); |
| 4254 |
} |
| 4255 |
|
| 4256 |
void |
| 4257 |
BlockExpr::normalize_tail_expr () |
| 4258 |
{ |
| 4259 |
if (!expr) |
| 4260 |
{ |
| 4261 |
// HACK: try to turn the last statement into a tail expression |
| 4262 |
if (!statements.empty () && statements.back ()->is_expr ()) |
| 4263 |
{ |
| 4264 |
// Watch out: This reference become invalid when the vector is |
| 4265 |
// modified. |
| 4266 |
auto &stmt = static_cast<ExprStmt &> (*statements.back ()); |
| 4267 |
|
| 4268 |
if (!stmt.is_semicolon_followed ()) |
| 4269 |
{ |
| 4270 |
expr = stmt.take_expr (); |
| 4271 |
statements.pop_back (); |
| 4272 |
} |
| 4273 |
} |
| 4274 |
} |
| 4275 |
} |
| 4276 |
|
| 4277 |
// needed here because "rust-expr.h" doesn't include "rust-macro.h" |
| 4278 |
AttrInputMacro::AttrInputMacro (const AttrInputMacro &oth) |
| 4279 |
: macro (oth.macro->clone_macro_invocation_impl ()) |
| 4280 |
{} |
| 4281 |
|
| 4282 |
void |
| 4283 |
AttrInputMacro::operator= (const AttrInputMacro &oth) |
| 4284 |
{ |
| 4285 |
macro = std::unique_ptr<MacroInvocation> ( |
| 4286 |
oth.macro->clone_macro_invocation_impl ()); |
| 4287 |
} |
| 4288 |
|
| 4289 |
/* Visitor implementations - these are short but inlining can't happen anyway |
| 4290 |
* due to virtual functions and I didn't want to make the ast header includes |
| 4291 |
* any longer than they already are. */ |
| 4292 |
|
| 4293 |
void |
| 4294 |
Token::accept_vis (ASTVisitor &vis) |
| 4295 |
{ |
| 4296 |
vis.visit (*this); |
| 4297 |
} |
| 4298 |
|
| 4299 |
void |
| 4300 |
DelimTokenTree::accept_vis (ASTVisitor &vis) |
| 4301 |
{ |
| 4302 |
vis.visit (*this); |
| 4303 |
} |
| 4304 |
|
| 4305 |
void |
| 4306 |
IdentifierExpr::accept_vis (ASTVisitor &vis) |
| 4307 |
{ |
| 4308 |
vis.visit (*this); |
| 4309 |
} |
| 4310 |
|
| 4311 |
void |
| 4312 |
Lifetime::accept_vis (ASTVisitor &vis) |
| 4313 |
{ |
| 4314 |
vis.visit (*this); |
| 4315 |
} |
| 4316 |
|
| 4317 |
void |
| 4318 |
LifetimeParam::accept_vis (ASTVisitor &vis) |
| 4319 |
{ |
| 4320 |
vis.visit (*this); |
| 4321 |
} |
| 4322 |
|
| 4323 |
void |
| 4324 |
LiteralExpr::accept_vis (ASTVisitor &vis) |
| 4325 |
{ |
| 4326 |
vis.visit (*this); |
| 4327 |
} |
| 4328 |
|
| 4329 |
void |
| 4330 |
AttrInputLiteral::accept_vis (ASTVisitor &vis) |
| 4331 |
{ |
| 4332 |
vis.visit (*this); |
| 4333 |
} |
| 4334 |
|
| 4335 |
void |
| 4336 |
AttrInputMacro::accept_vis (ASTVisitor &vis) |
| 4337 |
{ |
| 4338 |
vis.visit (*this); |
| 4339 |
} |
| 4340 |
|
| 4341 |
void |
| 4342 |
MetaItemLitExpr::accept_vis (ASTVisitor &vis) |
| 4343 |
{ |
| 4344 |
vis.visit (*this); |
| 4345 |
} |
| 4346 |
|
| 4347 |
void |
| 4348 |
MetaItemPathLit::accept_vis (ASTVisitor &vis) |
| 4349 |
{ |
| 4350 |
vis.visit (*this); |
| 4351 |
} |
| 4352 |
|
| 4353 |
void |
| 4354 |
BorrowExpr::accept_vis (ASTVisitor &vis) |
| 4355 |
{ |
| 4356 |
vis.visit (*this); |
| 4357 |
} |
| 4358 |
|
| 4359 |
void |
| 4360 |
DereferenceExpr::accept_vis (ASTVisitor &vis) |
| 4361 |
{ |
| 4362 |
vis.visit (*this); |
| 4363 |
} |
| 4364 |
|
| 4365 |
void |
| 4366 |
ErrorPropagationExpr::accept_vis (ASTVisitor &vis) |
| 4367 |
{ |
| 4368 |
vis.visit (*this); |
| 4369 |
} |
| 4370 |
|
| 4371 |
void |
| 4372 |
NegationExpr::accept_vis (ASTVisitor &vis) |
| 4373 |
{ |
| 4374 |
vis.visit (*this); |
| 4375 |
} |
| 4376 |
|
| 4377 |
void |
| 4378 |
ArithmeticOrLogicalExpr::accept_vis (ASTVisitor &vis) |
| 4379 |
{ |
| 4380 |
vis.visit (*this); |
| 4381 |
} |
| 4382 |
|
| 4383 |
void |
| 4384 |
ComparisonExpr::accept_vis (ASTVisitor &vis) |
| 4385 |
{ |
| 4386 |
vis.visit (*this); |
| 4387 |
} |
| 4388 |
|
| 4389 |
void |
| 4390 |
LazyBooleanExpr::accept_vis (ASTVisitor &vis) |
| 4391 |
{ |
| 4392 |
vis.visit (*this); |
| 4393 |
} |
| 4394 |
|
| 4395 |
void |
| 4396 |
TypeCastExpr::accept_vis (ASTVisitor &vis) |
| 4397 |
{ |
| 4398 |
vis.visit (*this); |
| 4399 |
} |
| 4400 |
|
| 4401 |
void |
| 4402 |
AssignmentExpr::accept_vis (ASTVisitor &vis) |
| 4403 |
{ |
| 4404 |
vis.visit (*this); |
| 4405 |
} |
| 4406 |
|
| 4407 |
void |
| 4408 |
CompoundAssignmentExpr::accept_vis (ASTVisitor &vis) |
| 4409 |
{ |
| 4410 |
vis.visit (*this); |
| 4411 |
} |
| 4412 |
|
| 4413 |
void |
| 4414 |
ArrayElemsValues::accept_vis (ASTVisitor &vis) |
| 4415 |
{ |
| 4416 |
vis.visit (*this); |
| 4417 |
} |
| 4418 |
|
| 4419 |
void |
| 4420 |
ArrayElemsCopied::accept_vis (ASTVisitor &vis) |
| 4421 |
{ |
| 4422 |
vis.visit (*this); |
| 4423 |
} |
| 4424 |
|
| 4425 |
void |
| 4426 |
ArrayExpr::accept_vis (ASTVisitor &vis) |
| 4427 |
{ |
| 4428 |
vis.visit (*this); |
| 4429 |
} |
| 4430 |
|
| 4431 |
void |
| 4432 |
ArrayIndexExpr::accept_vis (ASTVisitor &vis) |
| 4433 |
{ |
| 4434 |
vis.visit (*this); |
| 4435 |
} |
| 4436 |
|
| 4437 |
void |
| 4438 |
TupleExpr::accept_vis (ASTVisitor &vis) |
| 4439 |
{ |
| 4440 |
vis.visit (*this); |
| 4441 |
} |
| 4442 |
|
| 4443 |
void |
| 4444 |
TupleIndexExpr::accept_vis (ASTVisitor &vis) |
| 4445 |
{ |
| 4446 |
vis.visit (*this); |
| 4447 |
} |
| 4448 |
|
| 4449 |
void |
| 4450 |
StructExprStruct::accept_vis (ASTVisitor &vis) |
| 4451 |
{ |
| 4452 |
vis.visit (*this); |
| 4453 |
} |
| 4454 |
|
| 4455 |
void |
| 4456 |
StructExprFieldIdentifier::accept_vis (ASTVisitor &vis) |
| 4457 |
{ |
| 4458 |
vis.visit (*this); |
| 4459 |
} |
| 4460 |
|
| 4461 |
void |
| 4462 |
StructExprFieldIdentifierValue::accept_vis (ASTVisitor &vis) |
| 4463 |
{ |
| 4464 |
vis.visit (*this); |
| 4465 |
} |
| 4466 |
|
| 4467 |
void |
| 4468 |
StructExprFieldIndexValue::accept_vis (ASTVisitor &vis) |
| 4469 |
{ |
| 4470 |
vis.visit (*this); |
| 4471 |
} |
| 4472 |
|
| 4473 |
void |
| 4474 |
StructExprStructFields::accept_vis (ASTVisitor &vis) |
| 4475 |
{ |
| 4476 |
vis.visit (*this); |
| 4477 |
} |
| 4478 |
|
| 4479 |
void |
| 4480 |
StructExprStructBase::accept_vis (ASTVisitor &vis) |
| 4481 |
{ |
| 4482 |
vis.visit (*this); |
| 4483 |
} |
| 4484 |
|
| 4485 |
void |
| 4486 |
CallExpr::accept_vis (ASTVisitor &vis) |
| 4487 |
{ |
| 4488 |
vis.visit (*this); |
| 4489 |
} |
| 4490 |
|
| 4491 |
void |
| 4492 |
MethodCallExpr::accept_vis (ASTVisitor &vis) |
| 4493 |
{ |
| 4494 |
vis.visit (*this); |
| 4495 |
} |
| 4496 |
|
| 4497 |
void |
| 4498 |
FieldAccessExpr::accept_vis (ASTVisitor &vis) |
| 4499 |
{ |
| 4500 |
vis.visit (*this); |
| 4501 |
} |
| 4502 |
|
| 4503 |
void |
| 4504 |
ClosureExprInner::accept_vis (ASTVisitor &vis) |
| 4505 |
{ |
| 4506 |
vis.visit (*this); |
| 4507 |
} |
| 4508 |
|
| 4509 |
void |
| 4510 |
BlockExpr::accept_vis (ASTVisitor &vis) |
| 4511 |
{ |
| 4512 |
vis.visit (*this); |
| 4513 |
} |
| 4514 |
|
| 4515 |
void |
| 4516 |
ClosureExprInnerTyped::accept_vis (ASTVisitor &vis) |
| 4517 |
{ |
| 4518 |
vis.visit (*this); |
| 4519 |
} |
| 4520 |
|
| 4521 |
void |
| 4522 |
ContinueExpr::accept_vis (ASTVisitor &vis) |
| 4523 |
{ |
| 4524 |
vis.visit (*this); |
| 4525 |
} |
| 4526 |
|
| 4527 |
void |
| 4528 |
BreakExpr::accept_vis (ASTVisitor &vis) |
| 4529 |
{ |
| 4530 |
vis.visit (*this); |
| 4531 |
} |
| 4532 |
|
| 4533 |
void |
| 4534 |
RangeFromToExpr::accept_vis (ASTVisitor &vis) |
| 4535 |
{ |
| 4536 |
vis.visit (*this); |
| 4537 |
} |
| 4538 |
|
| 4539 |
void |
| 4540 |
RangeFromExpr::accept_vis (ASTVisitor &vis) |
| 4541 |
{ |
| 4542 |
vis.visit (*this); |
| 4543 |
} |
| 4544 |
|
| 4545 |
void |
| 4546 |
RangeToExpr::accept_vis (ASTVisitor &vis) |
| 4547 |
{ |
| 4548 |
vis.visit (*this); |
| 4549 |
} |
| 4550 |
|
| 4551 |
void |
| 4552 |
RangeFullExpr::accept_vis (ASTVisitor &vis) |
| 4553 |
{ |
| 4554 |
vis.visit (*this); |
| 4555 |
} |
| 4556 |
|
| 4557 |
void |
| 4558 |
RangeFromToInclExpr::accept_vis (ASTVisitor &vis) |
| 4559 |
{ |
| 4560 |
vis.visit (*this); |
| 4561 |
} |
| 4562 |
|
| 4563 |
void |
| 4564 |
RangeToInclExpr::accept_vis (ASTVisitor &vis) |
| 4565 |
{ |
| 4566 |
vis.visit (*this); |
| 4567 |
} |
| 4568 |
|
| 4569 |
void |
| 4570 |
ReturnExpr::accept_vis (ASTVisitor &vis) |
| 4571 |
{ |
| 4572 |
vis.visit (*this); |
| 4573 |
} |
| 4574 |
|
| 4575 |
void |
| 4576 |
UnsafeBlockExpr::accept_vis (ASTVisitor &vis) |
| 4577 |
{ |
| 4578 |
vis.visit (*this); |
| 4579 |
} |
| 4580 |
|
| 4581 |
void |
| 4582 |
LoopExpr::accept_vis (ASTVisitor &vis) |
| 4583 |
{ |
| 4584 |
vis.visit (*this); |
| 4585 |
} |
| 4586 |
|
| 4587 |
void |
| 4588 |
WhileLoopExpr::accept_vis (ASTVisitor &vis) |
| 4589 |
{ |
| 4590 |
vis.visit (*this); |
| 4591 |
} |
| 4592 |
|
| 4593 |
void |
| 4594 |
WhileLetLoopExpr::accept_vis (ASTVisitor &vis) |
| 4595 |
{ |
| 4596 |
vis.visit (*this); |
| 4597 |
} |
| 4598 |
|
| 4599 |
void |
| 4600 |
ForLoopExpr::accept_vis (ASTVisitor &vis) |
| 4601 |
{ |
| 4602 |
vis.visit (*this); |
| 4603 |
} |
| 4604 |
|
| 4605 |
void |
| 4606 |
IfExpr::accept_vis (ASTVisitor &vis) |
| 4607 |
{ |
| 4608 |
vis.visit (*this); |
| 4609 |
} |
| 4610 |
|
| 4611 |
void |
| 4612 |
IfExprConseqElse::accept_vis (ASTVisitor &vis) |
| 4613 |
{ |
| 4614 |
vis.visit (*this); |
| 4615 |
} |
| 4616 |
|
| 4617 |
void |
| 4618 |
IfLetExpr::accept_vis (ASTVisitor &vis) |
| 4619 |
{ |
| 4620 |
vis.visit (*this); |
| 4621 |
} |
| 4622 |
|
| 4623 |
void |
| 4624 |
IfLetExprConseqElse::accept_vis (ASTVisitor &vis) |
| 4625 |
{ |
| 4626 |
vis.visit (*this); |
| 4627 |
} |
| 4628 |
|
| 4629 |
void |
| 4630 |
MatchExpr::accept_vis (ASTVisitor &vis) |
| 4631 |
{ |
| 4632 |
vis.visit (*this); |
| 4633 |
} |
| 4634 |
|
| 4635 |
void |
| 4636 |
AwaitExpr::accept_vis (ASTVisitor &vis) |
| 4637 |
{ |
| 4638 |
vis.visit (*this); |
| 4639 |
} |
| 4640 |
|
| 4641 |
void |
| 4642 |
AsyncBlockExpr::accept_vis (ASTVisitor &vis) |
| 4643 |
{ |
| 4644 |
vis.visit (*this); |
| 4645 |
} |
| 4646 |
|
| 4647 |
void |
| 4648 |
InlineAsm::accept_vis (ASTVisitor &vis) |
| 4649 |
{ |
| 4650 |
vis.visit (*this); |
| 4651 |
} |
| 4652 |
|
| 4653 |
void |
| 4654 |
TypeParam::accept_vis (ASTVisitor &vis) |
| 4655 |
{ |
| 4656 |
vis.visit (*this); |
| 4657 |
} |
| 4658 |
|
| 4659 |
void |
| 4660 |
LifetimeWhereClauseItem::accept_vis (ASTVisitor &vis) |
| 4661 |
{ |
| 4662 |
vis.visit (*this); |
| 4663 |
} |
| 4664 |
|
| 4665 |
void |
| 4666 |
TypeBoundWhereClauseItem::accept_vis (ASTVisitor &vis) |
| 4667 |
{ |
| 4668 |
vis.visit (*this); |
| 4669 |
} |
| 4670 |
|
| 4671 |
void |
| 4672 |
Module::accept_vis (ASTVisitor &vis) |
| 4673 |
{ |
| 4674 |
vis.visit (*this); |
| 4675 |
} |
| 4676 |
|
| 4677 |
void |
| 4678 |
ExternCrate::accept_vis (ASTVisitor &vis) |
| 4679 |
{ |
| 4680 |
vis.visit (*this); |
| 4681 |
} |
| 4682 |
|
| 4683 |
void |
| 4684 |
UseTreeGlob::accept_vis (ASTVisitor &vis) |
| 4685 |
{ |
| 4686 |
vis.visit (*this); |
| 4687 |
} |
| 4688 |
|
| 4689 |
void |
| 4690 |
UseTreeList::accept_vis (ASTVisitor &vis) |
| 4691 |
{ |
| 4692 |
vis.visit (*this); |
| 4693 |
} |
| 4694 |
|
| 4695 |
void |
| 4696 |
UseTreeRebind::accept_vis (ASTVisitor &vis) |
| 4697 |
{ |
| 4698 |
vis.visit (*this); |
| 4699 |
} |
| 4700 |
|
| 4701 |
void |
| 4702 |
UseDeclaration::accept_vis (ASTVisitor &vis) |
| 4703 |
{ |
| 4704 |
vis.visit (*this); |
| 4705 |
} |
| 4706 |
|
| 4707 |
void |
| 4708 |
Function::accept_vis (ASTVisitor &vis) |
| 4709 |
{ |
| 4710 |
vis.visit (*this); |
| 4711 |
} |
| 4712 |
|
| 4713 |
void |
| 4714 |
TypeAlias::accept_vis (ASTVisitor &vis) |
| 4715 |
{ |
| 4716 |
vis.visit (*this); |
| 4717 |
} |
| 4718 |
|
| 4719 |
void |
| 4720 |
StructStruct::accept_vis (ASTVisitor &vis) |
| 4721 |
{ |
| 4722 |
vis.visit (*this); |
| 4723 |
} |
| 4724 |
|
| 4725 |
void |
| 4726 |
TupleStruct::accept_vis (ASTVisitor &vis) |
| 4727 |
{ |
| 4728 |
vis.visit (*this); |
| 4729 |
} |
| 4730 |
|
| 4731 |
void |
| 4732 |
EnumItem::accept_vis (ASTVisitor &vis) |
| 4733 |
{ |
| 4734 |
vis.visit (*this); |
| 4735 |
} |
| 4736 |
|
| 4737 |
void |
| 4738 |
EnumItemTuple::accept_vis (ASTVisitor &vis) |
| 4739 |
{ |
| 4740 |
vis.visit (*this); |
| 4741 |
} |
| 4742 |
|
| 4743 |
void |
| 4744 |
EnumItemStruct::accept_vis (ASTVisitor &vis) |
| 4745 |
{ |
| 4746 |
vis.visit (*this); |
| 4747 |
} |
| 4748 |
|
| 4749 |
void |
| 4750 |
EnumItemDiscriminant::accept_vis (ASTVisitor &vis) |
| 4751 |
{ |
| 4752 |
vis.visit (*this); |
| 4753 |
} |
| 4754 |
|
| 4755 |
void |
| 4756 |
Enum::accept_vis (ASTVisitor &vis) |
| 4757 |
{ |
| 4758 |
vis.visit (*this); |
| 4759 |
} |
| 4760 |
|
| 4761 |
void |
| 4762 |
Union::accept_vis (ASTVisitor &vis) |
| 4763 |
{ |
| 4764 |
vis.visit (*this); |
| 4765 |
} |
| 4766 |
|
| 4767 |
void |
| 4768 |
ConstantItem::accept_vis (ASTVisitor &vis) |
| 4769 |
{ |
| 4770 |
vis.visit (*this); |
| 4771 |
} |
| 4772 |
|
| 4773 |
void |
| 4774 |
StaticItem::accept_vis (ASTVisitor &vis) |
| 4775 |
{ |
| 4776 |
vis.visit (*this); |
| 4777 |
} |
| 4778 |
|
| 4779 |
void |
| 4780 |
TraitItemConst::accept_vis (ASTVisitor &vis) |
| 4781 |
{ |
| 4782 |
vis.visit (*this); |
| 4783 |
} |
| 4784 |
|
| 4785 |
void |
| 4786 |
TraitItemType::accept_vis (ASTVisitor &vis) |
| 4787 |
{ |
| 4788 |
vis.visit (*this); |
| 4789 |
} |
| 4790 |
|
| 4791 |
void |
| 4792 |
Trait::accept_vis (ASTVisitor &vis) |
| 4793 |
{ |
| 4794 |
vis.visit (*this); |
| 4795 |
} |
| 4796 |
|
| 4797 |
void |
| 4798 |
InherentImpl::accept_vis (ASTVisitor &vis) |
| 4799 |
{ |
| 4800 |
vis.visit (*this); |
| 4801 |
} |
| 4802 |
|
| 4803 |
void |
| 4804 |
TraitImpl::accept_vis (ASTVisitor &vis) |
| 4805 |
{ |
| 4806 |
vis.visit (*this); |
| 4807 |
} |
| 4808 |
|
| 4809 |
void |
| 4810 |
ExternalTypeItem::accept_vis (ASTVisitor &vis) |
| 4811 |
{ |
| 4812 |
vis.visit (*this); |
| 4813 |
} |
| 4814 |
|
| 4815 |
void |
| 4816 |
ExternalStaticItem::accept_vis (ASTVisitor &vis) |
| 4817 |
{ |
| 4818 |
vis.visit (*this); |
| 4819 |
} |
| 4820 |
|
| 4821 |
void |
| 4822 |
ExternBlock::accept_vis (ASTVisitor &vis) |
| 4823 |
{ |
| 4824 |
vis.visit (*this); |
| 4825 |
} |
| 4826 |
|
| 4827 |
void |
| 4828 |
MacroMatchFragment::accept_vis (ASTVisitor &vis) |
| 4829 |
{ |
| 4830 |
vis.visit (*this); |
| 4831 |
} |
| 4832 |
|
| 4833 |
void |
| 4834 |
MacroMatchRepetition::accept_vis (ASTVisitor &vis) |
| 4835 |
{ |
| 4836 |
vis.visit (*this); |
| 4837 |
} |
| 4838 |
|
| 4839 |
void |
| 4840 |
MacroMatcher::accept_vis (ASTVisitor &vis) |
| 4841 |
{ |
| 4842 |
vis.visit (*this); |
| 4843 |
} |
| 4844 |
|
| 4845 |
void |
| 4846 |
MacroRulesDefinition::accept_vis (ASTVisitor &vis) |
| 4847 |
{ |
| 4848 |
vis.visit (*this); |
| 4849 |
} |
| 4850 |
|
| 4851 |
void |
| 4852 |
MacroInvocation::accept_vis (ASTVisitor &vis) |
| 4853 |
{ |
| 4854 |
vis.visit (*this); |
| 4855 |
} |
| 4856 |
|
| 4857 |
void |
| 4858 |
EmptyStmt::accept_vis (ASTVisitor &vis) |
| 4859 |
{ |
| 4860 |
vis.visit (*this); |
| 4861 |
} |
| 4862 |
|
| 4863 |
void |
| 4864 |
LetStmt::accept_vis (ASTVisitor &vis) |
| 4865 |
{ |
| 4866 |
vis.visit (*this); |
| 4867 |
} |
| 4868 |
|
| 4869 |
void |
| 4870 |
ExprStmt::accept_vis (ASTVisitor &vis) |
| 4871 |
{ |
| 4872 |
vis.visit (*this); |
| 4873 |
} |
| 4874 |
|
| 4875 |
void |
| 4876 |
TraitBound::accept_vis (ASTVisitor &vis) |
| 4877 |
{ |
| 4878 |
vis.visit (*this); |
| 4879 |
} |
| 4880 |
|
| 4881 |
void |
| 4882 |
ImplTraitType::accept_vis (ASTVisitor &vis) |
| 4883 |
{ |
| 4884 |
vis.visit (*this); |
| 4885 |
} |
| 4886 |
|
| 4887 |
void |
| 4888 |
TraitObjectType::accept_vis (ASTVisitor &vis) |
| 4889 |
{ |
| 4890 |
vis.visit (*this); |
| 4891 |
} |
| 4892 |
|
| 4893 |
void |
| 4894 |
ParenthesisedType::accept_vis (ASTVisitor &vis) |
| 4895 |
{ |
| 4896 |
vis.visit (*this); |
| 4897 |
} |
| 4898 |
|
| 4899 |
void |
| 4900 |
ImplTraitTypeOneBound::accept_vis (ASTVisitor &vis) |
| 4901 |
{ |
| 4902 |
vis.visit (*this); |
| 4903 |
} |
| 4904 |
|
| 4905 |
void |
| 4906 |
TraitObjectTypeOneBound::accept_vis (ASTVisitor &vis) |
| 4907 |
{ |
| 4908 |
vis.visit (*this); |
| 4909 |
} |
| 4910 |
|
| 4911 |
void |
| 4912 |
TupleType::accept_vis (ASTVisitor &vis) |
| 4913 |
{ |
| 4914 |
vis.visit (*this); |
| 4915 |
} |
| 4916 |
|
| 4917 |
void |
| 4918 |
NeverType::accept_vis (ASTVisitor &vis) |
| 4919 |
{ |
| 4920 |
vis.visit (*this); |
| 4921 |
} |
| 4922 |
|
| 4923 |
void |
| 4924 |
RawPointerType::accept_vis (ASTVisitor &vis) |
| 4925 |
{ |
| 4926 |
vis.visit (*this); |
| 4927 |
} |
| 4928 |
|
| 4929 |
void |
| 4930 |
ReferenceType::accept_vis (ASTVisitor &vis) |
| 4931 |
{ |
| 4932 |
vis.visit (*this); |
| 4933 |
} |
| 4934 |
|
| 4935 |
void |
| 4936 |
ArrayType::accept_vis (ASTVisitor &vis) |
| 4937 |
{ |
| 4938 |
vis.visit (*this); |
| 4939 |
} |
| 4940 |
|
| 4941 |
void |
| 4942 |
SliceType::accept_vis (ASTVisitor &vis) |
| 4943 |
{ |
| 4944 |
vis.visit (*this); |
| 4945 |
} |
| 4946 |
|
| 4947 |
void |
| 4948 |
InferredType::accept_vis (ASTVisitor &vis) |
| 4949 |
{ |
| 4950 |
vis.visit (*this); |
| 4951 |
} |
| 4952 |
|
| 4953 |
void |
| 4954 |
BareFunctionType::accept_vis (ASTVisitor &vis) |
| 4955 |
{ |
| 4956 |
vis.visit (*this); |
| 4957 |
} |
| 4958 |
|
| 4959 |
void |
| 4960 |
MetaItemSeq::accept_vis (ASTVisitor &vis) |
| 4961 |
{ |
| 4962 |
vis.visit (*this); |
| 4963 |
} |
| 4964 |
|
| 4965 |
void |
| 4966 |
MetaItemPath::accept_vis (ASTVisitor &vis) |
| 4967 |
{ |
| 4968 |
vis.visit (*this); |
| 4969 |
} |
| 4970 |
|
| 4971 |
void |
| 4972 |
MetaListPaths::accept_vis (ASTVisitor &vis) |
| 4973 |
{ |
| 4974 |
vis.visit (*this); |
| 4975 |
} |
| 4976 |
|
| 4977 |
void |
| 4978 |
MetaNameValueStr::accept_vis (ASTVisitor &vis) |
| 4979 |
{ |
| 4980 |
vis.visit (*this); |
| 4981 |
} |
| 4982 |
|
| 4983 |
void |
| 4984 |
MetaListNameValueStr::accept_vis (ASTVisitor &vis) |
| 4985 |
{ |
| 4986 |
vis.visit (*this); |
| 4987 |
} |
| 4988 |
|
| 4989 |
void |
| 4990 |
AttrInputMetaItemContainer::accept_vis (ASTVisitor &vis) |
| 4991 |
{ |
| 4992 |
vis.visit (*this); |
| 4993 |
} |
| 4994 |
|
| 4995 |
void |
| 4996 |
MetaWord::accept_vis (ASTVisitor &vis) |
| 4997 |
{ |
| 4998 |
vis.visit (*this); |
| 4999 |
} |
| 5000 |
|
| 5001 |
void |
| 5002 |
FormatArgs::accept_vis (ASTVisitor &vis) |
| 5003 |
{ |
| 5004 |
vis.visit (*this); |
| 5005 |
} |
| 5006 |
|
| 5007 |
std::string |
| 5008 |
FormatArgs::as_string () const |
| 5009 |
{ |
| 5010 |
// FIXME(Arthur): Improve |
| 5011 |
return "FormatArgs"; |
| 5012 |
} |
| 5013 |
|
| 5014 |
location_t |
| 5015 |
FormatArgs::get_locus () const |
| 5016 |
{ |
| 5017 |
return loc; |
| 5018 |
} |
| 5019 |
|
| 5020 |
bool |
| 5021 |
FormatArgs::is_expr_without_block () const |
| 5022 |
{ |
| 5023 |
return false; |
| 5024 |
} |
| 5025 |
|
| 5026 |
void |
| 5027 |
FormatArgs::mark_for_strip () |
| 5028 |
{ |
| 5029 |
marked_for_strip = true; |
| 5030 |
} |
| 5031 |
|
| 5032 |
bool |
| 5033 |
FormatArgs::is_marked_for_strip () const |
| 5034 |
{ |
| 5035 |
return marked_for_strip; |
| 5036 |
} |
| 5037 |
|
| 5038 |
std::vector<Attribute> & |
| 5039 |
FormatArgs::get_outer_attrs () |
| 5040 |
{ |
| 5041 |
rust_unreachable (); |
| 5042 |
} |
| 5043 |
|
| 5044 |
void FormatArgs::set_outer_attrs (std::vector<Attribute>) |
| 5045 |
{ |
| 5046 |
rust_unreachable (); |
| 5047 |
} |
| 5048 |
|
| 5049 |
Expr * |
| 5050 |
FormatArgs::clone_expr_impl () const |
| 5051 |
{ |
| 5052 |
std::cerr << "[ARTHUR] cloning FormatArgs! " << std::endl; |
| 5053 |
|
| 5054 |
return new FormatArgs (*this); |
| 5055 |
} |
| 5056 |
|
| 5057 |
} // namespace AST |
| 5058 |
|
| 5059 |
std::ostream & |
| 5060 |
operator<< (std::ostream &os, Identifier const &i) |
| 5061 |
{ |
| 5062 |
return os << i.as_string (); |
| 5063 |
} |
| 5064 |
|
| 5065 |
} // namespace Rust |