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