Line data Source code
1 : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
5 : // GCC is free software; you can redistribute it and/or modify it under
6 : // the terms of the GNU General Public License as published by the Free
7 : // Software Foundation; either version 3, or (at your option) any later
8 : // version.
9 :
10 : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : // for more details.
14 :
15 : // You should have received a copy of the GNU General Public License
16 : // along with GCC; see the file COPYING3. If not see
17 : // <http://www.gnu.org/licenses/>.
18 :
19 : #include "rust-hir-dump.h"
20 : #include "rust-abi.h"
21 : #include "rust-hir-item.h"
22 : #include "rust-hir-path.h"
23 : #include "rust-hir-type.h"
24 : #include "rust-hir.h"
25 : #include "rust-attribute-values.h"
26 : #include "tree/rust-hir-expr.h"
27 : #include "rust-system.h"
28 :
29 : namespace Rust {
30 : namespace HIR {
31 :
32 : // Dump Format for HIR
33 : //
34 : // SomeHIRNode [
35 : // field: ...
36 : // field: ...
37 : // field: ...
38 : // ]
39 : //
40 : // When a field is a collection of other HIR objects:
41 : // field {
42 : // SomeHIRNode [ ... ]
43 : // SomeOtherHIRNode [ ... ]
44 : // }
45 : //
46 : // If a field is an empty collection:
47 : // field: empty
48 : //
49 : // If a field is optional and is currently not holding anything:
50 : // field: none
51 :
52 : std::string Dump::delims[2][2] = {
53 : {std::string ("{"), std::string ("}")},
54 : {std::string ("["), std::string ("]")},
55 : };
56 :
57 : static std::string
58 0 : BoundPolarityString (BoundPolarity polarity)
59 : {
60 0 : switch (polarity)
61 : {
62 0 : case RegularBound:
63 0 : return "regular";
64 0 : case NegativeBound:
65 0 : return "negative";
66 0 : case AntiBound:
67 0 : return "anti";
68 : }
69 0 : return "unknown";
70 : }
71 :
72 : /**
73 : * Static member used to dump HIR from the debugger to stderr.
74 : *
75 : * @param v The HIR node to dump
76 : */
77 : void
78 0 : Dump::debug (FullVisitable &v)
79 : {
80 0 : Dump dump (std::cerr);
81 0 : v.accept_vis (dump);
82 0 : }
83 :
84 : void
85 0 : Dump::go (HIR::Crate &e)
86 : {
87 0 : begin ("Crate");
88 0 : do_inner_attrs (e);
89 0 : do_mappings (e.get_mappings ());
90 :
91 0 : visit_collection ("items", e.get_items ());
92 0 : end ("Crate");
93 0 : }
94 :
95 0 : Dump::Dump (std::ostream &stream) : beg_of_line (false), stream (stream) {}
96 :
97 : /**
98 : * Writes TEXT with a final newline if ENDLINE is true.
99 : * If TEXT is starting the current line, its first line is indented.
100 : * If TEXT is multiline, all followning lines are also indented.
101 : *
102 : * @param text Text to emit
103 : * @param endline If true, newline is emitted after text
104 : */
105 : void
106 0 : Dump::put (std::string text, bool endline)
107 : {
108 0 : if (beg_of_line)
109 : {
110 0 : stream << indentation;
111 0 : beg_of_line = false;
112 : }
113 :
114 : // keep multiline string indented
115 0 : std::string::size_type pos = 0;
116 0 : std::string::size_type prev = 0;
117 0 : auto first = true;
118 0 : while ((pos = text.find ('\n', prev)) != std::string::npos)
119 : {
120 0 : if (!first)
121 0 : stream << std::endl << indentation;
122 0 : first = false;
123 :
124 0 : stream << text.substr (prev, pos - prev);
125 0 : prev = pos + 1;
126 : }
127 :
128 0 : if (first)
129 0 : stream << text;
130 :
131 0 : if (endline)
132 : {
133 0 : stream << std::endl;
134 0 : beg_of_line = endline;
135 : }
136 0 : }
137 :
138 : /**
139 : * Called when starting to emit info for an HIR node.
140 : * Emits NAME and an opening delimiter denoted by D.
141 : *
142 : * @param name Name of HIR node
143 : * @param d Delimiter
144 : */
145 : void
146 0 : Dump::begin (std::string name, enum delim d)
147 : {
148 0 : if (!beg_of_line)
149 0 : put ("");
150 0 : put (name + " " + delims[d][0], true);
151 0 : indentation.increment ();
152 0 : }
153 :
154 : /**
155 : * Called when ending the dump info for an HIR node. Emits a C++-style
156 : * comment with NAME and a closing delimiter denoted by D.
157 : *
158 : * @param name Name of HIR node
159 : * @param d Delimiter
160 : */
161 : void
162 0 : Dump::end (std::string name, enum delim d)
163 : {
164 0 : indentation.decrement ();
165 0 : if (!beg_of_line)
166 0 : stream << std::endl;
167 0 : put (delims[d][1] + " // " + name);
168 0 : }
169 :
170 : /**
171 : * Called when starting to emit info for a field within an HIR node.
172 : * Emits NAME and an opening curly brace
173 : *
174 : * @param name HIR field name
175 : */
176 : void
177 0 : Dump::begin_field (std::string name)
178 : {
179 0 : begin (name, CURLY);
180 0 : }
181 :
182 : /**
183 : * Called when ending the dump info for a field within an HIR node.
184 : * Emits a C++-style comment with NAME and a closing curly brace
185 : *
186 : * @param name HIR field name
187 : */
188 : void
189 0 : Dump::end_field (std::string name)
190 : {
191 0 : end (name, CURLY);
192 0 : }
193 :
194 : /**
195 : * Emits a single field/value pair denoted by NAME and TEXT.
196 : *
197 : * @param name Field name
198 : * @param text Field value
199 : */
200 : void
201 0 : Dump::put_field (std::string name, std::string text)
202 : {
203 0 : put (name + ": ", false);
204 0 : indentation.increment ();
205 0 : put (text);
206 0 : indentation.decrement ();
207 0 : }
208 :
209 : /**
210 : * Recursively visits an HIR field NAME with value possibly pointed to by
211 : * PTR, if PTR is not null. If PTR is null, simply emits FIELD_NAME/NULL pair.
212 : *
213 : * @param name Field name
214 : * @param ptr Pointer to field's value
215 : */
216 : template <class T>
217 : void
218 0 : Dump::visit_field (std::string name, std::unique_ptr<T> &ptr)
219 : {
220 0 : if (ptr)
221 0 : visit_field (name, *ptr);
222 : else
223 0 : put_field (name, "NULL");
224 0 : }
225 :
226 : /**
227 : * Recursively visits an HIR field NAME with value V.
228 : *
229 : * @param name Field name
230 : * @param v Field value
231 : */
232 : void
233 0 : Dump::visit_field (std::string name, FullVisitable &v)
234 : {
235 0 : put (name + ": ", false);
236 0 : indentation.increment ();
237 0 : v.accept_vis (*this);
238 0 : indentation.decrement ();
239 0 : }
240 :
241 : /**
242 : * Recursively visits a collection VEC of HIR node for field NAME.
243 : * If VEC is empty, simply emits the NAME/empty pair.
244 : *
245 : * @param name Field name
246 : * @param vec Field value as a vector
247 : */
248 : template <class T>
249 : void
250 0 : Dump::visit_collection (std::string name, std::vector<std::unique_ptr<T>> &vec)
251 : {
252 0 : if (vec.empty ())
253 : {
254 0 : put_field (name, "empty");
255 0 : return;
256 : }
257 :
258 0 : begin_field (name);
259 0 : for (const auto &elt : vec)
260 0 : elt->accept_vis (*this);
261 0 : end_field (name);
262 : }
263 :
264 : /**
265 : * Recursively visits a collection VEC of HIR node for field NAME.
266 : * If VEC is empty, simply emits the NAME/empty pair.
267 : *
268 : * @param name Field name
269 : * @param vec Field value as a vector
270 : */
271 : template <class T>
272 : void
273 0 : Dump::visit_collection (std::string name, std::vector<T> &vec)
274 : {
275 0 : if (vec.empty ())
276 : {
277 0 : put_field (name, "empty");
278 0 : return;
279 : }
280 :
281 0 : begin_field (name);
282 0 : for (auto &elt : vec)
283 0 : elt.accept_vis (*this);
284 0 : end_field (name);
285 : }
286 :
287 : void
288 0 : Dump::do_traititem (TraitItem &e)
289 : {
290 0 : do_mappings (e.get_mappings ());
291 0 : auto oa = e.get_outer_attrs ();
292 0 : do_outer_attrs (oa);
293 0 : }
294 :
295 : void
296 0 : Dump::do_vis_item (VisItem &e)
297 : {
298 0 : do_item (e);
299 0 : std::string str = "none";
300 0 : if (e.has_visibility ())
301 0 : str = e.get_visibility ().to_string ();
302 0 : put_field ("visibility", str);
303 0 : }
304 :
305 : void
306 0 : Dump::do_functionparam (FunctionParam &e)
307 : {
308 0 : begin ("FunctionParam");
309 0 : do_mappings (e.get_mappings ());
310 0 : visit_field ("param_name", e.get_param_name ());
311 0 : visit_field ("type", e.get_type ());
312 0 : end ("FunctionParam");
313 0 : }
314 :
315 : void
316 0 : Dump::do_pathpattern (PathPattern &e)
317 : {
318 0 : if (e.get_path_kind () == PathPattern::Kind::LangItem)
319 : {
320 0 : put_field ("segments", "#[lang = \""
321 0 : + LangItem::ToString (e.get_lang_item ())
322 0 : + "\"]");
323 0 : return;
324 : }
325 :
326 0 : std::string str = "";
327 :
328 0 : for (const auto &segment : e.get_segments ())
329 0 : str += segment.to_string () + ", ";
330 :
331 0 : put_field ("segments", str);
332 0 : }
333 :
334 : void
335 0 : Dump::do_structexprstruct (StructExprStruct &e)
336 : {
337 0 : do_expr (e);
338 :
339 : // StructExpr
340 0 : visit_field ("struct_name", e.get_struct_name ());
341 :
342 : // StructExprStruct
343 0 : do_mappings (e.get_mappings ());
344 0 : do_inner_attrs (e);
345 0 : }
346 :
347 : void
348 0 : Dump::do_ifexpr (IfExpr &e)
349 : {
350 0 : do_expr (e);
351 0 : visit_field ("condition", e.get_if_condition ());
352 0 : visit_field ("if_block", e.get_if_block ());
353 0 : }
354 :
355 : void
356 0 : Dump::do_expr (Expr &e)
357 : {
358 0 : do_mappings (e.get_mappings ());
359 0 : auto oa = e.get_outer_attrs ();
360 0 : do_outer_attrs (oa);
361 0 : }
362 :
363 : void
364 0 : Dump::do_matcharm (MatchArm &e)
365 : {
366 0 : begin ("MatchArm");
367 : // FIXME Can't remember how to handle that. Let's see later.
368 : // do_outer_attrs(e);
369 0 : visit_field ("match_arm_pattern", e.get_pattern ());
370 0 : if (e.has_match_arm_guard ())
371 0 : visit_field ("guard_expr", e.get_guard_expr ());
372 0 : end ("MatchArm");
373 0 : }
374 :
375 : void
376 0 : Dump::do_matchcase (HIR::MatchCase &e)
377 : {
378 0 : begin ("MatchCase");
379 :
380 0 : begin_field ("arm");
381 0 : do_matcharm (e.get_arm ());
382 0 : end_field ("arm");
383 :
384 0 : visit_field ("expr", e.get_expr ());
385 :
386 0 : end ("MatchCase");
387 0 : }
388 :
389 : void
390 0 : Dump::do_pathexpr (PathExpr &e)
391 : {
392 0 : do_expr (e);
393 0 : }
394 :
395 : void
396 0 : Dump::do_typepathsegment (TypePathSegment &e)
397 : {
398 0 : do_mappings (e.get_mappings ());
399 0 : if (e.is_lang_item ())
400 0 : put_field ("ident_segment", LangItem::PrettyString (e.get_lang_item ()));
401 : else
402 0 : put_field ("ident_segment", e.get_ident_segment ().to_string ());
403 0 : }
404 :
405 : void
406 0 : Dump::do_typepathfunction (TypePathFunction &e)
407 : {
408 0 : visit_collection ("params", e.get_params ());
409 0 : if (e.has_return_type ())
410 0 : visit_field ("return_type", e.get_return_type ());
411 0 : }
412 :
413 : void
414 0 : Dump::do_qualifiedpathtype (QualifiedPathType &e)
415 : {
416 0 : do_mappings (e.get_mappings ());
417 0 : if (e.has_type ())
418 0 : visit_field ("type", e.get_type ());
419 : else
420 0 : put_field ("type", "none");
421 :
422 0 : if (e.has_trait ())
423 0 : visit_field ("trait", e.get_trait ());
424 0 : }
425 :
426 : void
427 0 : Dump::do_operatorexpr (OperatorExpr &e)
428 : {
429 0 : visit_field ("main_or_left_expr", e.get_expr ());
430 0 : }
431 :
432 : void
433 0 : Dump::do_mappings (const Analysis::NodeMapping &mappings)
434 : {
435 0 : put ("mapping: ", false);
436 0 : put (mappings.as_string ());
437 0 : }
438 :
439 : void
440 0 : Dump::do_inner_attrs (WithInnerAttrs &e)
441 : {
442 0 : auto attrs = e.get_inner_attrs ();
443 :
444 0 : if (attrs.empty ())
445 : {
446 0 : put_field ("inner_attrs", "empty");
447 0 : return;
448 : }
449 :
450 0 : begin_field ("inner_attrs");
451 0 : for (auto &elt : attrs)
452 0 : visit (elt);
453 0 : end_field ("inner_attrs");
454 0 : }
455 :
456 : void
457 0 : Dump::do_outer_attrs (std::vector<AST::Attribute> &attrs)
458 : {
459 0 : if (attrs.empty ())
460 0 : put_field ("outer_attributes", "empty");
461 : else
462 : {
463 0 : begin_field ("outer_attributes");
464 0 : for (const auto &attr : attrs)
465 0 : put (attr.as_string ());
466 0 : end_field ("outer_attributes");
467 : }
468 0 : }
469 :
470 : void
471 0 : Dump::do_baseloopexpr (BaseLoopExpr &e)
472 : {
473 0 : do_expr (e);
474 :
475 0 : if (!e.has_loop_label ())
476 0 : put_field ("label", "none");
477 : else
478 0 : put_field ("label", e.get_loop_label ().to_string ());
479 :
480 0 : visit_field ("loop_block", e.get_loop_block ());
481 0 : }
482 :
483 : void
484 0 : Dump::do_struct (Struct &e)
485 : {
486 0 : do_vis_item (e);
487 0 : put_field ("struct_name", e.get_identifier ().as_string ());
488 0 : visit_collection ("generic_params", e.get_generic_params ());
489 :
490 0 : if (!e.has_where_clause ())
491 0 : put_field ("where_clause", "none");
492 : else
493 0 : put_field ("where clause", e.get_where_clause ().to_string ());
494 0 : }
495 :
496 : void
497 0 : Dump::do_enumitem (EnumItem &e)
498 : {
499 0 : do_item (e);
500 :
501 0 : put_field ("variant_name", e.get_identifier ().as_string ());
502 :
503 0 : std::string str;
504 0 : switch (e.get_enum_item_kind ())
505 : {
506 0 : case EnumItem::EnumItemKind::Named:
507 0 : str = "[Named variant]";
508 0 : break;
509 0 : case EnumItem::EnumItemKind::Tuple:
510 0 : str = "[Tuple variant]";
511 0 : break;
512 0 : case EnumItem::EnumItemKind::Struct:
513 0 : str = "[Struct variant]";
514 0 : break;
515 0 : case EnumItem::EnumItemKind::Discriminant:
516 0 : str = "[Discriminant variant]";
517 0 : break;
518 : }
519 0 : put_field ("item_kind", str);
520 0 : }
521 :
522 : void
523 0 : Dump::do_traitfunctiondecl (TraitFunctionDecl &e)
524 : {
525 0 : begin ("TraitFunctionDecl");
526 0 : put_field ("qualifiers", e.get_qualifiers ().to_string ());
527 0 : put_field ("function_name", e.get_function_name ().as_string ());
528 0 : visit_collection ("generic_params", e.get_generic_params ());
529 :
530 0 : if (!e.get_function_params ().empty ())
531 : {
532 0 : begin_field ("function_params");
533 0 : for (auto &item : e.get_function_params ())
534 0 : do_functionparam (item);
535 0 : end_field ("function_params");
536 : }
537 : else
538 0 : put_field ("function_params", "empty");
539 :
540 0 : if (e.has_return_type ())
541 0 : visit_field ("return_type", e.get_return_type ());
542 : else
543 0 : put_field ("return_type", "none");
544 :
545 0 : if (e.has_where_clause ())
546 0 : put_field ("where_clause", e.get_where_clause ().to_string ());
547 : else
548 0 : put_field ("where_clause", "none");
549 :
550 0 : if (e.is_method ())
551 0 : put_field ("self", e.get_self_unchecked ().to_string ());
552 :
553 0 : end ("TraitFunctionDecl");
554 0 : }
555 :
556 : void
557 0 : Dump::do_externalitem (ExternalItem &e)
558 : {
559 0 : do_mappings (e.get_mappings ());
560 :
561 0 : auto oa = e.get_outer_attrs ();
562 0 : do_outer_attrs (oa);
563 :
564 0 : std::string str = "none";
565 0 : if (e.has_visibility ())
566 0 : str = e.get_visibility ().to_string ();
567 0 : put_field ("visibility", str);
568 0 : put_field ("item_name", e.get_item_name ().as_string ());
569 0 : }
570 :
571 : void
572 0 : Dump::do_namefunctionparam (NamedFunctionParam &e)
573 : {
574 0 : begin ("NamedFunctionParam");
575 0 : do_mappings (e.get_mappings ());
576 0 : put_field ("name", e.get_param_name ().as_string ());
577 0 : visit_field ("type", e.get_type ());
578 0 : end ("NamedFunctionParam");
579 0 : }
580 :
581 : void
582 0 : Dump::do_stmt (Stmt &e)
583 : {
584 0 : do_mappings (e.get_mappings ());
585 0 : }
586 :
587 : void
588 0 : Dump::do_type (Type &e)
589 : {
590 0 : do_mappings (e.get_mappings ());
591 0 : }
592 :
593 : void
594 0 : Dump::do_item (Item &e)
595 : {
596 0 : do_stmt (e);
597 0 : auto oa = e.get_outer_attrs ();
598 0 : do_outer_attrs (oa);
599 0 : }
600 :
601 : void
602 0 : Dump::do_tuplefield (TupleField &e)
603 : {
604 0 : do_mappings (e.get_mappings ());
605 0 : auto oa = e.get_outer_attrs ();
606 0 : do_outer_attrs (oa);
607 :
608 0 : std::string str = "none";
609 0 : if (e.has_visibility ())
610 0 : str = e.get_visibility ().to_string ();
611 0 : put_field ("visibility", str);
612 :
613 0 : visit_field ("field_type", e.get_field_type ());
614 0 : }
615 :
616 : void
617 0 : Dump::do_structfield (StructField &e)
618 : {
619 0 : do_mappings (e.get_mappings ());
620 0 : auto oa = e.get_outer_attrs ();
621 0 : do_outer_attrs (oa);
622 :
623 0 : std::string str = "none";
624 0 : if (e.has_visibility ())
625 0 : str = e.get_visibility ().to_string ();
626 0 : put_field ("visibility", str);
627 0 : put_field ("field_name", e.get_field_name ().as_string ());
628 0 : visit_field ("field_type", e.get_field_type ());
629 0 : }
630 :
631 : void
632 0 : Dump::do_genericargs (GenericArgs &e)
633 : {
634 0 : visit_collection ("lifetime_args", e.get_lifetime_args ());
635 0 : visit_collection ("type_args", e.get_type_args ());
636 :
637 0 : if (e.get_const_args ().empty ())
638 : {
639 0 : put_field ("binding_args", "empty");
640 : }
641 : else
642 : {
643 0 : begin_field ("const_args");
644 0 : for (auto &arg : e.get_const_args ())
645 : {
646 0 : begin ("ConstGenericArg");
647 0 : visit_field ("expression", arg.get_expression ());
648 0 : end ("ConstGenericArg");
649 : }
650 0 : end_field ("const_args");
651 : }
652 :
653 0 : if (e.get_binding_args ().empty ())
654 : {
655 0 : put_field ("binding_args", "empty");
656 : }
657 : else
658 : {
659 0 : begin_field ("binding_args");
660 0 : for (auto &arg : e.get_binding_args ())
661 : {
662 0 : begin ("GenericArgsBinding");
663 0 : put_field ("identfier", arg.get_identifier ().as_string ());
664 0 : visit_field ("type", arg.get_type ());
665 0 : end ("GenericArgsBinding");
666 : }
667 0 : end_field ("binding_args");
668 : }
669 0 : }
670 :
671 : void
672 0 : Dump::do_maybenamedparam (MaybeNamedParam &e)
673 : {
674 0 : visit_field ("param_type", e.get_type ());
675 0 : put_field ("param_kind", enum_to_str (e.get_param_kind ()));
676 0 : put_field ("name", e.get_name ().as_string ());
677 0 : }
678 :
679 : // All visit methods
680 :
681 : void
682 0 : Dump::visit (AST::Attribute &attribute)
683 : {
684 : // Special, no begin/end as this is called by do_inner_attrs.
685 0 : put_field (Values::Attributes::PATH, attribute.get_path ().as_string ());
686 :
687 0 : std::string str = "none";
688 0 : if (attribute.has_attr_input ())
689 0 : str = attribute.get_attr_input ().as_string ();
690 0 : put_field ("attr_input", str);
691 0 : }
692 :
693 : void
694 0 : Dump::visit (Lifetime &e)
695 : {
696 0 : do_mappings (e.get_mappings ());
697 :
698 0 : std::string type;
699 0 : std::string name = e.get_name ();
700 0 : switch (e.get_lifetime_type ())
701 : {
702 0 : case AST::Lifetime::LifetimeType::NAMED:
703 0 : type = "[NAMED]";
704 0 : break;
705 0 : case AST::Lifetime::LifetimeType::STATIC:
706 0 : type = "[STATIC]";
707 0 : name += " (not applicable for type)";
708 0 : break;
709 0 : case AST::Lifetime::LifetimeType::WILDCARD:
710 0 : type = "[WILDCARD]";
711 0 : name += " (not applicable for type)";
712 0 : break;
713 0 : default:
714 0 : rust_assert (false);
715 : break;
716 : }
717 0 : put_field ("lifetime_type", type);
718 0 : put_field ("lifetime_name", name);
719 0 : }
720 :
721 : void
722 0 : Dump::visit (LifetimeParam &lifetimeparam)
723 : {
724 0 : begin ("Lifetimeparam");
725 0 : put (lifetimeparam.to_debug_string ());
726 0 : end ("Lifetimeparam");
727 0 : }
728 :
729 : void
730 0 : Dump::visit (PathInExpression &e)
731 : {
732 0 : begin ("PathInExpression");
733 0 : do_pathpattern (e);
734 0 : do_pathexpr (e);
735 :
736 0 : put_field ("has_opening_scope_resolution",
737 0 : std::to_string (e.opening_scope_resolution ()));
738 0 : end ("PathInExpression");
739 0 : }
740 :
741 : void
742 0 : Dump::visit (TypePathSegment &e)
743 : {
744 0 : begin ("TypePathSegment");
745 0 : do_typepathsegment (e);
746 0 : end ("TypePathSegment");
747 0 : }
748 :
749 : void
750 0 : Dump::visit (TypePathSegmentGeneric &e)
751 : {
752 0 : begin ("TypePathSegmentGeneric");
753 0 : do_typepathsegment (e);
754 :
755 0 : if (e.has_generic_args ())
756 : {
757 0 : begin_field ("generic_args");
758 0 : begin ("GenericArgs");
759 0 : do_genericargs (e.get_generic_args ());
760 0 : end ("GenericArgs");
761 0 : end_field ("generic_args");
762 : }
763 : else
764 : {
765 0 : put_field ("generic_args", "empty");
766 : }
767 :
768 0 : end ("TypePathSegmentGeneric");
769 0 : }
770 :
771 : void
772 0 : Dump::visit (TypePathSegmentFunction &e)
773 : {
774 0 : begin ("TypePathSegmentFunction");
775 0 : do_typepathsegment (e);
776 :
777 0 : begin ("function_path");
778 0 : do_typepathfunction (e.get_function_path ());
779 0 : end ("function_path");
780 :
781 0 : end ("TypePathSegmentFunction");
782 0 : }
783 :
784 : void
785 0 : Dump::visit (TypePath &e)
786 : {
787 0 : begin ("TypePath");
788 0 : put_field ("has_opening_scope_resolution",
789 0 : std::to_string (e.has_opening_scope_resolution_op ()));
790 :
791 0 : visit_collection ("segments", e.get_segments ());
792 :
793 0 : end ("TypePath");
794 0 : }
795 :
796 : void
797 0 : Dump::visit (QualifiedPathInExpression &e)
798 : {
799 0 : begin ("QualifiedPathInExpression");
800 0 : do_pathpattern (e);
801 0 : do_expr (e);
802 :
803 0 : begin_field ("path_type");
804 :
805 0 : begin ("QualifiedPathType");
806 0 : do_qualifiedpathtype (e.get_path_type ());
807 0 : end ("QualifiedPathType");
808 :
809 0 : end_field ("path_type");
810 :
811 0 : end ("QualifiedPathInExpression");
812 0 : }
813 :
814 : void
815 0 : Dump::visit (QualifiedPathInType &e)
816 : {
817 0 : begin ("QualifiedPathInType");
818 :
819 0 : begin_field ("path_type");
820 0 : do_qualifiedpathtype (e.get_path_type ());
821 0 : end_field ("path_type");
822 :
823 0 : begin_field ("associated_segment");
824 0 : do_typepathsegment (e.get_associated_segment ());
825 0 : end_field ("associated_segment");
826 :
827 0 : visit_collection ("segments", e.get_segments ());
828 :
829 0 : end ("QualifiedPathInType");
830 0 : }
831 :
832 : void
833 0 : Dump::visit (LiteralExpr &e)
834 : {
835 0 : begin ("LiteralExpr");
836 0 : do_expr (e);
837 0 : put_field ("literal", e.get_literal ().as_string ());
838 0 : end ("LiteralExpr");
839 0 : }
840 :
841 : void
842 0 : Dump::visit (BorrowExpr &e)
843 : {
844 0 : begin ("BorrowExpr");
845 0 : do_operatorexpr (e);
846 :
847 0 : put_field ("mut", enum_to_str (e.get_mut ()));
848 :
849 0 : end ("BorrowExpr");
850 0 : }
851 :
852 : void
853 0 : Dump::visit (DereferenceExpr &e)
854 : {
855 0 : begin ("DereferenceExpr");
856 0 : do_operatorexpr (e);
857 0 : end ("DereferenceExpr");
858 0 : }
859 :
860 : void
861 0 : Dump::visit (ErrorPropagationExpr &e)
862 : {
863 0 : begin ("ErrorPropagationExpr");
864 0 : do_operatorexpr (e);
865 0 : end ("ErrorPropagationExpr");
866 0 : }
867 :
868 : void
869 0 : Dump::visit (NegationExpr &e)
870 : {
871 0 : begin ("NegationExpr");
872 0 : do_operatorexpr (e);
873 0 : std::string str;
874 0 : switch (e.get_expr_type ())
875 : {
876 0 : case NegationOperator::NEGATE:
877 0 : str = "[NEGATE]";
878 0 : break;
879 0 : case NegationOperator::NOT:
880 0 : str = "[NOT]";
881 0 : break;
882 0 : default:
883 0 : rust_assert (false);
884 : }
885 0 : put_field ("expr_type", str);
886 :
887 0 : end ("NegationExpr");
888 0 : }
889 :
890 : void
891 0 : Dump::visit (ArithmeticOrLogicalExpr &e)
892 : {
893 0 : begin ("ArithmeticOrLogicalExpr");
894 0 : std::string str;
895 :
896 : // which operator
897 0 : switch (e.get_expr_type ())
898 : {
899 0 : case ArithmeticOrLogicalOperator::ADD:
900 0 : str = "[ADD]";
901 0 : break;
902 0 : case ArithmeticOrLogicalOperator::SUBTRACT:
903 0 : str = "SUBTRACT";
904 0 : break;
905 0 : case ArithmeticOrLogicalOperator::MULTIPLY:
906 0 : str = "MULTIPLY";
907 0 : break;
908 0 : case ArithmeticOrLogicalOperator::DIVIDE:
909 0 : str = "DIVIDE";
910 0 : break;
911 0 : case ArithmeticOrLogicalOperator::MODULUS:
912 0 : str = "MODULUS";
913 0 : break;
914 0 : case ArithmeticOrLogicalOperator::BITWISE_AND:
915 0 : str = "BITWISE";
916 0 : break;
917 0 : case ArithmeticOrLogicalOperator::BITWISE_OR:
918 0 : str = "BITWISE";
919 0 : break;
920 0 : case ArithmeticOrLogicalOperator::BITWISE_XOR:
921 0 : str = "BITWISE";
922 0 : break;
923 0 : case ArithmeticOrLogicalOperator::LEFT_SHIFT:
924 0 : str = "<LEFT";
925 0 : break;
926 0 : case ArithmeticOrLogicalOperator::RIGHT_SHIFT:
927 0 : str = ">RIGHT";
928 0 : break;
929 0 : default:
930 0 : rust_unreachable ();
931 0 : break;
932 : }
933 0 : put_field ("expr_type", str);
934 0 : do_operatorexpr (e);
935 0 : visit_field ("right_expr", e.get_rhs ());
936 :
937 0 : end ("ArithmeticOrLogicalExpr");
938 0 : }
939 :
940 : void
941 0 : Dump::visit (ComparisonExpr &e)
942 : {
943 0 : begin ("ComparisonExpr");
944 0 : std::string str;
945 0 : switch (e.get_expr_type ())
946 : {
947 0 : case ComparisonOperator::EQUAL:
948 0 : str = "EQUAL";
949 0 : break;
950 0 : case ComparisonOperator::NOT_EQUAL:
951 0 : str = "NOT_EQUAL";
952 0 : break;
953 0 : case ComparisonOperator::GREATER_THAN:
954 0 : str = "GREATER_THAN";
955 0 : break;
956 0 : case ComparisonOperator::LESS_THAN:
957 0 : str = "LESS_THAN";
958 0 : break;
959 0 : case ComparisonOperator::GREATER_OR_EQUAL:
960 0 : str = "GREATER_OR_EQUAL";
961 0 : break;
962 0 : case ComparisonOperator::LESS_OR_EQUAL:
963 0 : str = "LESS_OR_EQUAL";
964 0 : break;
965 0 : default:
966 0 : rust_assert (false);
967 : }
968 0 : put_field ("expr_type", str);
969 0 : do_operatorexpr (e);
970 0 : visit_field ("right_expr", e.get_rhs ());
971 0 : end ("ComparisonExpr");
972 0 : }
973 :
974 : void
975 0 : Dump::visit (LazyBooleanExpr &e)
976 : {
977 0 : begin ("LazyBooleanExpr");
978 :
979 0 : std::string str;
980 0 : switch (e.get_expr_type ())
981 : {
982 0 : case LazyBooleanOperator::LOGICAL_OR:
983 0 : str = "LOGICAL_OR";
984 0 : break;
985 0 : case LazyBooleanOperator::LOGICAL_AND:
986 0 : str = "LOGICAL_AND";
987 0 : break;
988 0 : default:
989 0 : rust_assert (false);
990 : }
991 :
992 0 : do_operatorexpr (e);
993 0 : visit_field ("right_expr", e.get_rhs ());
994 0 : end ("LazyBooleanExpr");
995 0 : }
996 :
997 : void
998 0 : Dump::visit (TypeCastExpr &e)
999 : {
1000 0 : begin ("TypeCastExpr");
1001 0 : do_operatorexpr (e);
1002 0 : visit_field ("type_to_convert_to", e.get_type_to_convert_to ());
1003 0 : end ("TypeCastExpr");
1004 0 : }
1005 :
1006 : void
1007 0 : Dump::visit (AssignmentExpr &e)
1008 : {
1009 0 : begin ("AssignmentExpr");
1010 0 : do_operatorexpr (e);
1011 0 : visit_field ("right_expr", e.get_rhs ());
1012 0 : end ("AssignmentExpr");
1013 0 : }
1014 :
1015 : void
1016 0 : Dump::visit (CompoundAssignmentExpr &e)
1017 : {
1018 0 : begin ("CompoundAssignmentExpr");
1019 :
1020 0 : do_operatorexpr (e);
1021 0 : visit_field ("right_expr", e.get_rhs ());
1022 :
1023 0 : std::string str;
1024 :
1025 : // get operator string
1026 0 : switch (e.get_expr_type ())
1027 : {
1028 0 : case ArithmeticOrLogicalOperator::ADD:
1029 0 : str = "ADD";
1030 0 : break;
1031 0 : case ArithmeticOrLogicalOperator::SUBTRACT:
1032 0 : str = "SUBTRACT";
1033 0 : break;
1034 0 : case ArithmeticOrLogicalOperator::MULTIPLY:
1035 0 : str = "MULTIPLY";
1036 0 : break;
1037 0 : case ArithmeticOrLogicalOperator::DIVIDE:
1038 0 : str = "DIVIDE";
1039 0 : break;
1040 0 : case ArithmeticOrLogicalOperator::MODULUS:
1041 0 : str = "MODULUS";
1042 0 : break;
1043 0 : case ArithmeticOrLogicalOperator::BITWISE_AND:
1044 0 : str = "BITWISE_AND";
1045 0 : break;
1046 0 : case ArithmeticOrLogicalOperator::BITWISE_OR:
1047 0 : str = "BITWISE_OR";
1048 0 : break;
1049 0 : case ArithmeticOrLogicalOperator::BITWISE_XOR:
1050 0 : str = "BITWISE_XOR";
1051 0 : break;
1052 0 : case ArithmeticOrLogicalOperator::LEFT_SHIFT:
1053 0 : str = "LEFT_SHIFT";
1054 0 : break;
1055 0 : case ArithmeticOrLogicalOperator::RIGHT_SHIFT:
1056 0 : str = "RIGHT_SHIFT";
1057 0 : break;
1058 0 : default:
1059 0 : gcc_unreachable ();
1060 0 : break;
1061 : }
1062 0 : put_field ("expr_type", str);
1063 0 : end ("CompoundAssignmentExpr");
1064 0 : }
1065 :
1066 : void
1067 0 : Dump::visit (GroupedExpr &e)
1068 : {
1069 0 : begin ("GroupedExpr");
1070 0 : do_expr (e);
1071 0 : do_inner_attrs (e);
1072 :
1073 0 : visit_field ("expr_in_parens", e.get_expr_in_parens ());
1074 :
1075 0 : end ("GroupedExpr");
1076 0 : }
1077 :
1078 : void
1079 0 : Dump::visit (ArrayElemsValues &e)
1080 : {
1081 0 : begin ("ArrayElemsValues");
1082 0 : do_mappings (e.get_mappings ());
1083 :
1084 0 : visit_collection ("values", e.get_values ());
1085 0 : end ("ArrayElemsValues");
1086 0 : }
1087 :
1088 : void
1089 0 : Dump::visit (ArrayElemsCopied &e)
1090 : {
1091 0 : begin ("ArrayElemsCopied");
1092 0 : do_mappings (e.get_mappings ());
1093 :
1094 0 : visit_field ("copied_elem", e.get_elem_to_copy ());
1095 0 : visit_field ("num_copies", e.get_num_copies_expr ());
1096 :
1097 0 : end ("ArrayElemsCopied");
1098 0 : }
1099 :
1100 : void
1101 0 : Dump::visit (ArrayExpr &e)
1102 : {
1103 0 : begin ("ArrayExpr");
1104 0 : do_expr (e);
1105 0 : do_inner_attrs (e);
1106 :
1107 0 : visit_field ("internal_elements", e.get_internal_elements ());
1108 :
1109 0 : end ("ArrayExpr");
1110 0 : }
1111 :
1112 : void
1113 0 : Dump::visit (ArrayIndexExpr &e)
1114 : {
1115 0 : begin ("ArrayIndexExpr");
1116 0 : do_expr (e);
1117 :
1118 0 : visit_field ("array_expr", e.get_array_expr ());
1119 0 : visit_field ("index_expr", e.get_index_expr ());
1120 0 : end ("ArrayIndexExpr");
1121 0 : }
1122 :
1123 : void
1124 0 : Dump::visit (TupleExpr &e)
1125 : {
1126 0 : begin ("TupleExpr");
1127 0 : do_expr (e);
1128 0 : do_inner_attrs (e);
1129 :
1130 0 : visit_collection ("tuple_elems", e.get_tuple_elems ());
1131 :
1132 0 : end ("TupleExpr");
1133 0 : }
1134 :
1135 : void
1136 0 : Dump::visit (TupleIndexExpr &e)
1137 : {
1138 0 : begin ("TupleIndexExpr");
1139 0 : do_expr (e);
1140 0 : visit_field ("tuple_expr", e.get_tuple_expr ());
1141 0 : put_field ("tuple_index", std::to_string (e.get_tuple_index ()));
1142 0 : end ("TupleIndexExpr");
1143 0 : }
1144 :
1145 : void
1146 0 : Dump::visit (StructExprStruct &e)
1147 : {
1148 0 : begin ("StructExprStruct");
1149 0 : do_structexprstruct (e);
1150 0 : end ("StructExprStruct");
1151 0 : }
1152 :
1153 : void
1154 0 : Dump::visit (StructExprFieldIdentifier &e)
1155 : {
1156 0 : begin ("StructExprFieldIdentifier");
1157 0 : do_mappings (e.get_mappings ());
1158 :
1159 0 : put_field ("field_name", e.get_field_name ().as_string ());
1160 0 : end ("StructExprFieldIdentifier");
1161 0 : }
1162 :
1163 : void
1164 0 : Dump::visit (StructExprFieldIdentifierValue &e)
1165 : {
1166 0 : begin ("StructExprFieldIdentifierValue");
1167 0 : do_mappings (e.get_mappings ());
1168 :
1169 0 : visit_field ("value", e.get_value ());
1170 0 : end ("StructExprFieldIdentifierValue");
1171 0 : }
1172 :
1173 : void
1174 0 : Dump::visit (StructExprFieldIndexValue &e)
1175 : {
1176 0 : begin ("StructExprFieldIndexValue");
1177 0 : do_mappings (e.get_mappings ());
1178 :
1179 0 : put_field ("index", std::to_string (e.get_tuple_index ()));
1180 0 : visit_field ("value", e.get_value ());
1181 0 : end ("StructExprFieldIndexValue");
1182 0 : }
1183 :
1184 : void
1185 0 : Dump::visit (StructExprStructFields &e)
1186 : {
1187 0 : begin ("StructExprStructFields");
1188 0 : do_structexprstruct (e);
1189 :
1190 0 : visit_collection ("fields", e.get_fields ());
1191 :
1192 0 : if (!e.has_struct_base ())
1193 0 : put_field ("struct_base", "none");
1194 : else
1195 0 : put_field ("struct_base", e.get_struct_base ().to_string ());
1196 :
1197 0 : end ("StructExprStructFields");
1198 0 : }
1199 :
1200 : void
1201 0 : Dump::visit (StructExprStructBase &e)
1202 : {
1203 0 : begin ("StructExprStructBase");
1204 0 : do_structexprstruct (e);
1205 :
1206 0 : put_field ("struct_base", e.get_struct_base ().to_string ());
1207 :
1208 0 : end ("StructExprStructBase");
1209 0 : }
1210 :
1211 : void
1212 0 : Dump::visit (CallExpr &e)
1213 : {
1214 0 : begin ("CallExpr");
1215 0 : do_expr (e);
1216 0 : visit_field ("function", e.get_fnexpr ());
1217 :
1218 0 : visit_collection ("params", e.get_arguments ());
1219 :
1220 0 : end ("CallExpr");
1221 0 : }
1222 :
1223 : void
1224 0 : Dump::visit (MethodCallExpr &e)
1225 : {
1226 0 : begin ("MethodCallExpr");
1227 0 : do_expr (e);
1228 :
1229 0 : visit_field ("receiver", e.get_receiver ());
1230 0 : put_field ("method_name", e.get_method_name ().to_string ());
1231 0 : visit_collection ("params", e.get_arguments ());
1232 :
1233 0 : end ("MethodCallExpr");
1234 0 : }
1235 :
1236 : void
1237 0 : Dump::visit (FieldAccessExpr &e)
1238 : {
1239 0 : begin ("FieldAccessExpr");
1240 0 : do_expr (e);
1241 0 : visit_field ("receiver", e.get_receiver_expr ());
1242 0 : put_field ("field", e.get_field_name ().as_string ());
1243 0 : end ("FieldAccessExpr");
1244 0 : }
1245 :
1246 : void
1247 0 : Dump::visit (ClosureExpr &e)
1248 : {
1249 0 : begin ("ClosureExpr");
1250 0 : do_expr (e);
1251 :
1252 0 : if (!e.has_params ())
1253 : {
1254 0 : put_field ("params", "none");
1255 : }
1256 : else
1257 : {
1258 0 : begin_field ("params");
1259 0 : for (auto ¶m : e.get_params ())
1260 : {
1261 0 : begin ("ClosureParam");
1262 0 : auto oa = param.get_outer_attrs ();
1263 0 : do_outer_attrs (oa);
1264 0 : visit_field ("pattern", param.get_pattern ());
1265 :
1266 0 : if (param.has_type_given ())
1267 0 : visit_field ("type", param.get_type ());
1268 :
1269 0 : end ("ClosureParam");
1270 0 : }
1271 0 : end_field ("params");
1272 : }
1273 :
1274 0 : if (e.has_return_type ())
1275 0 : visit_field ("return_type", e.get_return_type ());
1276 :
1277 0 : visit_field ("expr", e.get_expr ());
1278 0 : end ("ClosureExpr");
1279 0 : }
1280 :
1281 : void
1282 0 : Dump::visit (BlockExpr &e)
1283 : {
1284 0 : begin ("BlockExpr");
1285 0 : do_expr (e);
1286 0 : do_inner_attrs (e);
1287 0 : put_field ("tail_reachable", std::to_string (e.is_tail_reachable ()));
1288 :
1289 0 : if (e.has_label ())
1290 0 : put_field ("label", e.get_label ().to_string ());
1291 :
1292 0 : visit_collection ("statements", e.get_statements ());
1293 :
1294 0 : if (e.has_final_expr ())
1295 0 : visit_field ("expr", e.get_final_expr ());
1296 :
1297 0 : end ("BlockExpr");
1298 0 : }
1299 :
1300 : void
1301 0 : Dump::visit (AnonConst &e)
1302 : {
1303 0 : begin ("AnonConst");
1304 0 : do_expr (e);
1305 :
1306 0 : if (e.is_deferred ())
1307 0 : put_field ("inner", "_");
1308 : else
1309 0 : visit_field ("inner", e.get_inner_expr ());
1310 :
1311 0 : end ("AnonConst");
1312 0 : }
1313 :
1314 : void
1315 0 : Dump::visit (ConstBlock &e)
1316 : {
1317 0 : begin ("ConstBlock");
1318 0 : do_expr (e);
1319 :
1320 0 : visit_field ("inner", e.get_const_expr ());
1321 :
1322 0 : end ("ConstBlock");
1323 0 : }
1324 :
1325 : void
1326 0 : Dump::visit (ContinueExpr &e)
1327 : {
1328 0 : begin ("ContinueExpr");
1329 :
1330 0 : if (e.has_label ())
1331 0 : put_field ("label", e.get_label ().to_string ());
1332 : else
1333 0 : put_field ("label", "none");
1334 :
1335 0 : end ("ContinueExpr");
1336 0 : }
1337 :
1338 : void
1339 0 : Dump::visit (BreakExpr &e)
1340 : {
1341 0 : begin ("BreakExpr");
1342 0 : std::string str ("break ");
1343 :
1344 0 : if (e.has_label ())
1345 0 : put_field ("label", e.get_label ().to_string ());
1346 : else
1347 0 : put_field ("label", "none");
1348 :
1349 0 : if (e.has_break_expr ())
1350 0 : visit_field ("break_expr ", e.get_expr ());
1351 : else
1352 0 : put_field ("break_expr", "none");
1353 :
1354 0 : end ("BreakExpr");
1355 0 : }
1356 :
1357 : void
1358 0 : Dump::visit (RangeFromToExpr &e)
1359 : {
1360 0 : begin ("RangeFromToExpr");
1361 :
1362 0 : visit_field ("from", e.get_from_expr ());
1363 0 : visit_field ("to", e.get_to_expr ());
1364 :
1365 0 : end ("RangeFromToExpr");
1366 0 : }
1367 :
1368 : void
1369 0 : Dump::visit (RangeFromExpr &e)
1370 : {
1371 0 : begin ("RangeFromExpr");
1372 :
1373 0 : visit_field ("from", e.get_from_expr ());
1374 :
1375 0 : end ("RangeFromExpr");
1376 0 : }
1377 :
1378 : void
1379 0 : Dump::visit (RangeToExpr &e)
1380 : {
1381 0 : begin ("RangeToExpr");
1382 :
1383 0 : visit_field ("to", e.get_to_expr ());
1384 :
1385 0 : end ("RangeToExpr");
1386 0 : }
1387 :
1388 : void
1389 0 : Dump::visit (RangeFullExpr &e)
1390 : {
1391 0 : begin ("RangeFullExpr");
1392 0 : end ("RangeFullExpr");
1393 0 : }
1394 :
1395 : void
1396 0 : Dump::visit (RangeToInclExpr &e)
1397 : {
1398 0 : begin ("RangeToInclExpr");
1399 :
1400 0 : visit_field ("to", e.get_to_expr ());
1401 :
1402 0 : end ("RangeToInclExpr");
1403 0 : }
1404 :
1405 : void
1406 0 : Dump::visit (BoxExpr &e)
1407 : {
1408 0 : begin ("BoxExpr");
1409 0 : do_mappings (e.get_mappings ());
1410 :
1411 0 : visit_field ("box_expr", e.get_expr ());
1412 :
1413 0 : end ("BoxExpr");
1414 0 : }
1415 :
1416 : void
1417 0 : Dump::visit (ReturnExpr &e)
1418 : {
1419 0 : begin ("ReturnExpr");
1420 0 : do_mappings (e.get_mappings ());
1421 :
1422 0 : if (e.has_return_expr ())
1423 0 : visit_field ("return_expr", e.get_expr ());
1424 :
1425 0 : end ("ReturnExpr");
1426 0 : }
1427 :
1428 : void
1429 0 : Dump::visit (UnsafeBlockExpr &e)
1430 : {
1431 0 : begin ("UnsafeBlockExpr");
1432 0 : auto oa = e.get_outer_attrs ();
1433 0 : do_outer_attrs (oa);
1434 :
1435 0 : visit_field ("block_expr", e.get_block_expr ());
1436 :
1437 0 : end ("UnsafeBlockExpr");
1438 0 : }
1439 :
1440 : void
1441 0 : Dump::visit (LoopExpr &e)
1442 : {
1443 0 : begin ("LoopExpr");
1444 0 : do_baseloopexpr (e);
1445 0 : end ("LoopExpr");
1446 0 : }
1447 :
1448 : void
1449 0 : Dump::visit (WhileLoopExpr &e)
1450 : {
1451 0 : begin ("WhileLoopExpr");
1452 0 : do_baseloopexpr (e);
1453 :
1454 0 : visit_field ("condition", e.get_predicate_expr ());
1455 :
1456 0 : end ("WhileLoopExpr");
1457 0 : }
1458 :
1459 : void
1460 0 : Dump::visit (WhileLetLoopExpr &e)
1461 : {
1462 0 : begin ("WhileLetLoopExpr");
1463 0 : do_baseloopexpr (e);
1464 :
1465 0 : visit_field ("match_arm_patterns", e.get_pattern ());
1466 :
1467 0 : visit_field ("condition", e.get_cond ());
1468 :
1469 0 : end ("WhileLetLoopExpr");
1470 0 : }
1471 :
1472 : void
1473 0 : Dump::visit (IfExpr &e)
1474 : {
1475 0 : begin ("IfExpr");
1476 0 : do_ifexpr (e);
1477 0 : end ("IfExpr");
1478 0 : }
1479 :
1480 : void
1481 0 : Dump::visit (IfExprConseqElse &e)
1482 : {
1483 0 : begin ("IfExprConseqElse");
1484 0 : do_ifexpr (e);
1485 0 : visit_field ("else_block", e.get_else_block ());
1486 :
1487 0 : end ("IfExprConseqElse");
1488 0 : }
1489 :
1490 : void
1491 0 : Dump::visit (MatchExpr &e)
1492 : {
1493 0 : begin ("MatchExpr");
1494 0 : do_inner_attrs (e);
1495 0 : do_expr (e);
1496 :
1497 0 : visit_field ("branch_value", e.get_scrutinee_expr ());
1498 :
1499 0 : if (!e.has_match_arms ())
1500 : {
1501 0 : put_field ("match_arms", "empty");
1502 : }
1503 : else
1504 : {
1505 0 : begin_field ("match_arms");
1506 0 : for (auto &arm : e.get_match_cases ())
1507 0 : do_matchcase (arm);
1508 0 : end_field ("match_arms");
1509 : }
1510 0 : end ("MatchExpr");
1511 0 : }
1512 :
1513 : void
1514 0 : Dump::visit (AwaitExpr &e)
1515 : {
1516 0 : begin ("AwaitExpr");
1517 0 : do_expr (e);
1518 0 : visit_field ("awaited_expr", e.get_awaited_expr ());
1519 0 : end ("AwaitExpr");
1520 0 : }
1521 :
1522 : void
1523 0 : Dump::visit (AsyncBlockExpr &e)
1524 : {
1525 0 : begin ("AsyncBlockExpr");
1526 0 : do_expr (e);
1527 :
1528 0 : put_field ("has move", std::to_string (e.get_has_move ()));
1529 0 : visit_field ("block_expr", e.get_block_expr ());
1530 :
1531 0 : end ("AsyncBlockExpr");
1532 0 : }
1533 :
1534 : void
1535 0 : Dump::visit (InlineAsm &e)
1536 : {
1537 0 : begin ("InlineAsm");
1538 0 : do_expr (e);
1539 0 : for (auto &temp : e.get_template_ ())
1540 : {
1541 0 : put_field ("template", temp.string);
1542 0 : }
1543 :
1544 0 : for (auto &temp_str : e.get_template_strs ())
1545 : {
1546 0 : put_field ("template_str", temp_str.symbol);
1547 0 : }
1548 :
1549 0 : for (auto &operand : e.get_operands ())
1550 : {
1551 0 : switch (operand.get_register_type ())
1552 : {
1553 0 : case HIR::InlineAsmOperand::RegisterType::In:
1554 0 : {
1555 0 : const auto &in = operand.get_in ();
1556 0 : visit_field ("in expr", *in.expr);
1557 0 : break;
1558 : }
1559 0 : case HIR::InlineAsmOperand::RegisterType::Out:
1560 0 : {
1561 0 : const auto &out = operand.get_out ();
1562 0 : visit_field ("out expr", *out.expr);
1563 0 : break;
1564 : }
1565 0 : case HIR::InlineAsmOperand::RegisterType::InOut:
1566 0 : {
1567 0 : const auto &inout = operand.get_in_out ();
1568 0 : visit_field ("inout expr", *inout.expr);
1569 0 : break;
1570 : }
1571 0 : case HIR::InlineAsmOperand::RegisterType::SplitInOut:
1572 0 : {
1573 0 : const auto &inout = operand.get_split_in_out ();
1574 0 : begin ("Split in out");
1575 0 : visit_field ("in expr", *inout.in_expr);
1576 0 : visit_field ("out expr", *inout.out_expr);
1577 0 : end ("Split in out");
1578 :
1579 0 : break;
1580 : }
1581 0 : case HIR::InlineAsmOperand::RegisterType::Const:
1582 0 : {
1583 0 : auto &cnst = operand.get_const ();
1584 0 : visit_field ("const expr", cnst.anon_const.get_inner_expr ());
1585 0 : break;
1586 : }
1587 0 : case HIR::InlineAsmOperand::RegisterType::Sym:
1588 0 : {
1589 0 : auto &sym = operand.get_sym ();
1590 0 : visit_field ("sym expr", *sym.expr);
1591 0 : break;
1592 : }
1593 0 : case HIR::InlineAsmOperand::RegisterType::Label:
1594 0 : {
1595 0 : auto &label = operand.get_label ();
1596 0 : put_field ("label name", label.label_name);
1597 0 : do_expr (*label.expr);
1598 0 : break;
1599 : }
1600 : }
1601 : }
1602 0 : end ("InlineAsm");
1603 0 : }
1604 :
1605 : void
1606 0 : Dump::visit (LlvmInlineAsm &e)
1607 0 : {}
1608 :
1609 : void
1610 0 : Dump::visit (OffsetOf &e)
1611 : {
1612 0 : begin ("OffsetOf");
1613 :
1614 0 : put_field ("type", e.get_type ().to_debug_string ());
1615 0 : put_field ("field", e.get_field ());
1616 :
1617 0 : end ("OffsetOf");
1618 0 : }
1619 :
1620 : void
1621 0 : Dump::visit (TypeParam &e)
1622 : {
1623 0 : begin ("TypeParam");
1624 0 : auto &outer_attrs = e.get_outer_attrs ();
1625 0 : do_outer_attrs (outer_attrs);
1626 :
1627 0 : put_field ("type_representation", e.get_type_representation ().as_string ());
1628 :
1629 0 : visit_collection ("type_param_bounds", e.get_type_param_bounds ());
1630 :
1631 0 : if (e.has_type ())
1632 0 : visit_field ("type", e.get_type ());
1633 :
1634 0 : end ("TypeParam");
1635 0 : }
1636 :
1637 : void
1638 0 : Dump::visit (ConstGenericParam &e)
1639 : {
1640 0 : begin ("ConstGenericParam");
1641 0 : do_mappings (e.get_mappings ());
1642 0 : put_field ("name", e.get_name ());
1643 0 : visit_field ("type", e.get_type ());
1644 0 : visit_field ("default_expression", e.get_default_expression ());
1645 0 : end ("ConstGenericParam");
1646 0 : }
1647 :
1648 : void
1649 0 : Dump::visit (LifetimeWhereClauseItem &e)
1650 : {
1651 0 : begin ("LifetimeWhereClauseItem");
1652 0 : do_mappings (e.get_mappings ());
1653 :
1654 0 : visit_field ("lifetime", e.get_lifetime ());
1655 0 : visit_collection ("lifetime_bounds", e.get_lifetime_bounds ());
1656 :
1657 0 : end ("LifetimeWhereClauseItem");
1658 0 : }
1659 :
1660 : void
1661 0 : Dump::visit (TypeBoundWhereClauseItem &e)
1662 : {
1663 0 : begin ("TypeBoundWhereClauseItem");
1664 0 : do_mappings (e.get_mappings ());
1665 :
1666 0 : visit_collection ("for_lifetime", e.get_for_lifetimes ());
1667 :
1668 0 : visit_field ("bound_type", e.get_bound_type ());
1669 0 : visit_collection ("type_param_bound", e.get_type_param_bounds ());
1670 0 : end ("TypeBoundWhereClauseItem");
1671 0 : }
1672 :
1673 : void
1674 0 : Dump::visit (Module &e)
1675 : {
1676 0 : begin ("Module");
1677 0 : do_inner_attrs (e);
1678 0 : put_field ("module_name", e.get_module_name ().as_string ());
1679 0 : visit_collection ("items", e.get_items ());
1680 :
1681 0 : end ("Module");
1682 0 : }
1683 :
1684 : void
1685 0 : Dump::visit (ExternCrate &e)
1686 : {
1687 0 : begin ("ExternCrate");
1688 0 : do_vis_item (e);
1689 0 : put_field ("referenced_crate", e.get_referenced_crate ());
1690 0 : put_field ("as_clause_name", e.get_as_clause_name ());
1691 :
1692 0 : end ("ExternCrate");
1693 0 : }
1694 :
1695 : void
1696 0 : Dump::visit (UseTreeGlob &e)
1697 : {
1698 0 : begin ("UseTreeGlob");
1699 :
1700 0 : std::string glob, path = "not applicable";
1701 0 : switch (e.get_glob_type ())
1702 : {
1703 0 : case UseTreeGlob::PathType::NO_PATH:
1704 0 : glob = "*";
1705 0 : break;
1706 0 : case UseTreeGlob::PathType::GLOBAL:
1707 0 : glob = "::*";
1708 0 : break;
1709 0 : case UseTreeGlob::PathType::PATH_PREFIXED:
1710 0 : {
1711 0 : path = e.get_path ().as_string ();
1712 0 : glob = "::*";
1713 0 : break;
1714 : }
1715 0 : default:
1716 0 : gcc_unreachable ();
1717 : }
1718 0 : put_field ("glob", glob);
1719 0 : put_field ("path", path);
1720 :
1721 0 : end ("UseTreeGlob");
1722 0 : }
1723 :
1724 : void
1725 0 : Dump::visit (UseTreeList &e)
1726 : {
1727 0 : begin ("UseTreeList");
1728 :
1729 0 : std::string path_type, path = "not applicable";
1730 0 : switch (e.get_path_type ())
1731 : {
1732 0 : case UseTreeList::PathType::NO_PATH:
1733 0 : path_type = "*";
1734 0 : break;
1735 0 : case UseTreeList::PathType::GLOBAL:
1736 0 : path_type = "::*";
1737 0 : break;
1738 0 : case UseTreeList::PathType::PATH_PREFIXED:
1739 0 : {
1740 0 : path = e.get_path ().as_string ();
1741 0 : path_type = "::*";
1742 0 : break;
1743 : }
1744 0 : default:
1745 0 : gcc_unreachable ();
1746 : }
1747 0 : put_field ("path_type", path_type);
1748 0 : put_field ("path", path);
1749 :
1750 0 : visit_collection ("trees", e.get_trees ());
1751 :
1752 0 : end ("UseTreeList");
1753 0 : }
1754 :
1755 : void
1756 0 : Dump::visit (UseTreeRebind &e)
1757 : {
1758 0 : begin ("UseTreeRebind");
1759 0 : put_field ("path", e.get_path ().as_string ());
1760 0 : put_field ("identifier", e.get_identifier ().as_string ());
1761 0 : put_field ("bind_type", enum_to_str (e.get_bind_type ()));
1762 0 : end ("UseTreeRebind");
1763 0 : }
1764 :
1765 : void
1766 0 : Dump::visit (UseDeclaration &e)
1767 : {
1768 0 : begin ("UseDeclaration");
1769 0 : do_vis_item (e);
1770 :
1771 0 : visit_field ("use_tree", e.get_use_tree ());
1772 :
1773 0 : end ("UseDeclaration");
1774 0 : }
1775 :
1776 : void
1777 0 : Dump::visit (Function &e)
1778 : {
1779 0 : begin ("Function");
1780 0 : do_vis_item (e);
1781 :
1782 0 : put_field ("function_qualifiers", e.get_qualifiers ().to_string ());
1783 :
1784 0 : visit_collection ("generic_params", e.get_generic_params ());
1785 :
1786 0 : put_field ("function_name", e.get_function_name ().as_string ());
1787 :
1788 0 : if (e.has_function_params ())
1789 : {
1790 0 : begin_field ("function_params");
1791 0 : for (auto &item : e.get_function_params ())
1792 0 : do_functionparam (item);
1793 0 : end_field ("function_params");
1794 : }
1795 : else
1796 : {
1797 0 : put_field ("function_params", "empty");
1798 : }
1799 :
1800 0 : if (e.has_function_return_type ())
1801 0 : visit_field ("return_type", e.get_return_type ());
1802 :
1803 0 : if (!e.has_where_clause ())
1804 0 : put_field ("where_clause", "none");
1805 : else
1806 0 : put_field ("where clause", e.get_where_clause ().to_string ());
1807 :
1808 0 : visit_field ("function_body", e.get_definition ());
1809 0 : if (e.is_method ())
1810 0 : put_field ("self", e.get_self_param_unchecked ().to_string ());
1811 :
1812 0 : end ("Function");
1813 0 : }
1814 :
1815 : void
1816 0 : Dump::visit (TypeAlias &e)
1817 : {
1818 0 : begin ("TypeAlias");
1819 :
1820 0 : do_vis_item (e);
1821 :
1822 0 : put_field ("new_type_name", e.get_new_type_name ().as_string ());
1823 :
1824 0 : visit_collection ("generic_params", e.get_generic_params ());
1825 :
1826 0 : if (!e.has_where_clause ())
1827 0 : put_field ("where_clause", "none");
1828 : else
1829 0 : put_field ("where clause", e.get_where_clause ().to_string ());
1830 :
1831 0 : put_field ("type", e.get_type_aliased ().to_debug_string ());
1832 :
1833 0 : end ("TypeAlias");
1834 0 : }
1835 :
1836 : void
1837 0 : Dump::visit (StructStruct &e)
1838 : {
1839 0 : begin ("StructStruct");
1840 0 : do_struct (e);
1841 :
1842 0 : put_field ("is_unit", std::to_string (e.is_unit_struct ()));
1843 :
1844 0 : if (e.get_fields ().empty ())
1845 0 : put_field ("fields", "empty");
1846 : else
1847 : {
1848 0 : begin_field ("fields");
1849 0 : for (auto &field : e.get_fields ())
1850 : {
1851 0 : begin ("StructField");
1852 0 : do_structfield (field);
1853 0 : end ("StructField");
1854 : }
1855 0 : end_field ("fields");
1856 : }
1857 :
1858 0 : end ("StructStruct");
1859 0 : }
1860 :
1861 : void
1862 0 : Dump::visit (TupleStruct &e)
1863 : {
1864 0 : begin ("TupleStruct");
1865 0 : do_struct (e);
1866 :
1867 0 : if (e.get_fields ().empty ())
1868 0 : put_field ("fields", "empty");
1869 : else
1870 : {
1871 0 : begin_field ("fields");
1872 0 : for (auto &field : e.get_fields ())
1873 : {
1874 0 : begin ("TupleField");
1875 0 : do_tuplefield (field);
1876 0 : end ("TupleField");
1877 : }
1878 0 : end_field ("fields");
1879 : }
1880 :
1881 0 : end ("TupleStruct");
1882 0 : }
1883 :
1884 : void
1885 0 : Dump::visit (EnumItem &e)
1886 : {
1887 0 : begin ("EnumItem");
1888 0 : do_enumitem (e);
1889 0 : end ("EnumItem");
1890 0 : }
1891 :
1892 : void
1893 0 : Dump::visit (EnumItemTuple &e)
1894 : {
1895 0 : begin ("EnumItemTuple");
1896 0 : do_enumitem (e);
1897 :
1898 0 : if (e.has_tuple_fields ())
1899 : {
1900 0 : begin_field ("tuple_fields");
1901 0 : for (auto field : e.get_tuple_fields ())
1902 0 : do_tuplefield (field);
1903 0 : end_field ("tuple_fields");
1904 : }
1905 : else
1906 0 : put_field ("tuple_fields", "empty");
1907 :
1908 0 : end ("EnumItemTuple");
1909 0 : }
1910 :
1911 : void
1912 0 : Dump::visit (EnumItemStruct &e)
1913 : {
1914 0 : begin ("EnumItemStruct");
1915 0 : do_enumitem (e);
1916 :
1917 0 : if (e.has_struct_fields ())
1918 : {
1919 0 : begin_field ("struct_fields");
1920 0 : for (auto field : e.get_struct_fields ())
1921 0 : do_structfield (field);
1922 0 : end_field ("struct_fields");
1923 : }
1924 : else
1925 : {
1926 0 : put_field ("struct_fields", "empty");
1927 : }
1928 0 : end ("EnumItemStruct");
1929 0 : }
1930 :
1931 : void
1932 0 : Dump::visit (EnumItemDiscriminant &e)
1933 : {
1934 0 : begin ("EnumItemDiscriminant");
1935 :
1936 0 : do_enumitem (e);
1937 :
1938 0 : visit_field ("discriminant", e.get_discriminant_expression ());
1939 :
1940 0 : end ("EnumItemDiscriminant");
1941 0 : }
1942 :
1943 : void
1944 0 : Dump::visit (Enum &e)
1945 : {
1946 0 : begin ("Enum");
1947 0 : do_vis_item (e);
1948 :
1949 0 : put_field ("enum_name", e.get_identifier ().as_string ());
1950 :
1951 0 : visit_collection ("generic_params", e.get_generic_params ());
1952 :
1953 0 : std::string str = "none";
1954 0 : if (e.has_where_clause ())
1955 0 : str = e.get_where_clause ().to_string ();
1956 0 : put_field ("where clause", str);
1957 :
1958 0 : visit_collection ("items", e.get_variants ());
1959 :
1960 0 : end ("Enum");
1961 0 : }
1962 :
1963 : void
1964 0 : Dump::visit (Union &e)
1965 : {
1966 0 : begin ("Union");
1967 0 : do_vis_item (e);
1968 :
1969 0 : visit_collection ("generic_params", e.get_generic_params ());
1970 :
1971 0 : std::string str;
1972 0 : if (e.has_where_clause ())
1973 0 : str = e.get_where_clause ().to_string ();
1974 : else
1975 0 : str = "none";
1976 0 : put_field ("where clause", str);
1977 :
1978 0 : if (e.get_variants ().empty ())
1979 : {
1980 0 : put_field ("variants", "empty");
1981 : }
1982 : else
1983 : {
1984 0 : begin_field ("variants");
1985 0 : for (auto &elt : e.get_variants ())
1986 : {
1987 0 : begin ("StructField");
1988 0 : auto oa = e.get_outer_attrs ();
1989 0 : do_outer_attrs (oa);
1990 :
1991 0 : std::string str = "none";
1992 0 : if (elt.has_visibility ())
1993 0 : str = elt.get_visibility ().to_string ();
1994 0 : put_field ("visibility", str);
1995 0 : put_field ("field_name", elt.get_field_name ().as_string ());
1996 0 : visit_field ("field_type", elt.get_field_type ());
1997 0 : end ("StructField");
1998 0 : }
1999 0 : end_field ("variants");
2000 : }
2001 0 : end ("Union");
2002 0 : }
2003 :
2004 : void
2005 0 : Dump::visit (ConstantItem &e)
2006 : {
2007 0 : begin ("ConstantItem");
2008 0 : do_vis_item (e);
2009 0 : put_field ("identifier", e.get_identifier ().as_string ());
2010 0 : visit_field ("type", e.get_type ());
2011 0 : if (e.has_expr ())
2012 0 : visit_field ("const_expr", e.get_expr ());
2013 0 : end ("ConstantItem");
2014 0 : }
2015 :
2016 : void
2017 0 : Dump::visit (StaticItem &e)
2018 : {
2019 0 : begin ("StaticItem");
2020 0 : do_vis_item (e);
2021 0 : put_field ("mut", std::to_string (e.is_mut ()));
2022 0 : put_field ("name", e.get_identifier ().as_string ());
2023 0 : visit_field ("type", e.get_type ());
2024 0 : visit_field ("expr", e.get_expr ());
2025 0 : end ("StaticItem");
2026 0 : }
2027 :
2028 : void
2029 0 : Dump::visit (TraitItemFunc &e)
2030 : {
2031 0 : begin ("TraitItemFunc");
2032 0 : do_traititem (e);
2033 :
2034 0 : do_traitfunctiondecl (e.get_decl ());
2035 :
2036 0 : if (e.has_definition ())
2037 0 : visit_field ("block_expr", e.get_block_expr ());
2038 :
2039 0 : end ("TraitItemFunc");
2040 0 : }
2041 :
2042 : void
2043 0 : Dump::visit (TraitItemConst &e)
2044 : {
2045 0 : begin ("TraitItemConst");
2046 0 : do_traititem (e);
2047 :
2048 0 : put_field ("name", e.get_name ().as_string ());
2049 0 : visit_field ("type", e.get_type ());
2050 0 : if (e.has_expr ())
2051 0 : visit_field ("expr", e.get_expr ());
2052 :
2053 0 : end ("TraitItemConst");
2054 0 : }
2055 :
2056 : void
2057 0 : Dump::visit (TraitItemType &e)
2058 : {
2059 0 : begin ("TraitItemType");
2060 0 : do_traititem (e);
2061 :
2062 0 : put_field ("name", e.get_name ().as_string ());
2063 0 : visit_collection ("type_param_bounds", e.get_type_param_bounds ());
2064 0 : end ("TraitItemType");
2065 0 : }
2066 :
2067 : void
2068 0 : Dump::visit (Trait &e)
2069 : {
2070 0 : begin ("Trait");
2071 0 : do_vis_item (e);
2072 0 : put_field ("unsafety", std::to_string (e.is_unsafe ()));
2073 0 : put_field ("name", e.get_name ().as_string ());
2074 :
2075 0 : visit_collection ("generic_params", e.get_generic_params ());
2076 :
2077 0 : visit_collection ("type_param_bounds", e.get_type_param_bounds ());
2078 :
2079 0 : std::string str;
2080 0 : if (e.has_where_clause ())
2081 0 : str = e.get_where_clause ().to_string ();
2082 : else
2083 0 : str = "none";
2084 0 : put_field ("where clause", str);
2085 :
2086 0 : visit_collection ("trait_items", e.get_trait_items ());
2087 :
2088 0 : end ("Trait");
2089 0 : }
2090 :
2091 : void
2092 0 : Dump::visit (ImplBlock &e)
2093 : {
2094 0 : begin ("ImplBlock");
2095 0 : do_vis_item (e);
2096 :
2097 0 : visit_collection ("generic_params", e.get_generic_params ());
2098 :
2099 0 : visit_field ("impl_type", e.get_type ());
2100 :
2101 0 : std::string str;
2102 0 : if (e.has_where_clause ())
2103 0 : str = e.get_where_clause ().to_string ();
2104 : else
2105 0 : str = "none";
2106 0 : put_field ("where clause", str);
2107 :
2108 0 : do_inner_attrs (e);
2109 :
2110 0 : visit_collection ("impl_items", e.get_impl_items ());
2111 :
2112 0 : end ("ImplBlock");
2113 0 : }
2114 :
2115 : void
2116 0 : Dump::visit (ExternalStaticItem &e)
2117 : {
2118 0 : begin ("ExternalStaticItem");
2119 :
2120 : // FIXME do_vis_item... but not a VisItem... But could be?
2121 0 : auto oa = e.get_outer_attrs ();
2122 0 : do_outer_attrs (oa);
2123 :
2124 0 : std::string str = "none";
2125 0 : if (e.has_visibility ())
2126 0 : str = e.get_visibility ().to_string ();
2127 0 : put_field ("visibility", str);
2128 : //
2129 :
2130 0 : put_field ("mut", std::to_string (e.is_mut ()));
2131 0 : put_field ("name", e.get_item_name ().as_string ());
2132 0 : visit_field ("type", e.get_item_type ());
2133 :
2134 0 : end ("ExternalStaticItem");
2135 0 : }
2136 :
2137 : void
2138 0 : Dump::visit (ExternalFunctionItem &e)
2139 : {
2140 0 : begin ("ExternalFunctionItem");
2141 0 : do_externalitem (e);
2142 :
2143 0 : visit_collection ("generic_params", e.get_generic_params ());
2144 :
2145 0 : std::string str = "none";
2146 0 : if (!e.get_function_params ().empty ())
2147 0 : for (auto ¶m : e.get_function_params ())
2148 0 : do_namefunctionparam (param);
2149 : else
2150 0 : put_field ("function_params", "none");
2151 :
2152 0 : put_field ("has_variadics", std::to_string (e.is_variadic ()));
2153 :
2154 0 : if (e.has_return_type ())
2155 0 : visit_field ("return_type", e.get_return_type ());
2156 :
2157 0 : end ("ExternalFunctionItem");
2158 0 : }
2159 :
2160 : void
2161 0 : Dump::visit (ExternalTypeItem &e)
2162 : {
2163 0 : begin ("ExternalTypeItem");
2164 :
2165 0 : do_externalitem (e);
2166 :
2167 0 : end ("ExternalTypeItem");
2168 0 : }
2169 :
2170 : void
2171 0 : Dump::visit (ExternBlock &e)
2172 : {
2173 0 : begin ("ExternBlock");
2174 0 : do_vis_item (e);
2175 0 : do_inner_attrs (e);
2176 :
2177 0 : put_field ("abi", get_string_from_abi (e.get_abi ()));
2178 :
2179 0 : visit_collection ("extern_items", e.get_extern_items ());
2180 :
2181 0 : end ("ExternBlock");
2182 0 : }
2183 :
2184 : void
2185 0 : Dump::visit (LiteralPattern &e)
2186 : {
2187 0 : begin ("LiteralPattern");
2188 0 : put_field ("lit", e.get_literal ().as_string ());
2189 0 : do_mappings (e.get_mappings ());
2190 0 : end ("LiteralPattern");
2191 0 : }
2192 :
2193 : void
2194 0 : Dump::visit (IdentifierPattern &e)
2195 : {
2196 0 : begin ("IdentifierPattern");
2197 0 : put_field ("variable_ident", e.get_identifier ().as_string ());
2198 0 : put_field ("is_ref", std::to_string (e.get_is_ref ()));
2199 0 : put_field ("mut", std::to_string (e.is_mut ()));
2200 :
2201 0 : if (e.has_subpattern ())
2202 0 : visit_field ("subpattern", e.get_subpattern ());
2203 : else
2204 0 : put_field ("subpattern", "none");
2205 :
2206 0 : end ("IdentifierPattern");
2207 0 : }
2208 : void
2209 0 : Dump::visit (WildcardPattern &e)
2210 : {
2211 0 : begin ("WildcardPattern");
2212 0 : do_mappings (e.get_mappings ());
2213 0 : end ("WildcardPattern");
2214 0 : }
2215 :
2216 : void
2217 0 : Dump::visit (RangePatternBoundLiteral &e)
2218 : {
2219 0 : begin ("RangePatternBoundLiteral");
2220 0 : put_field ("literal", e.get_literal ().as_string ());
2221 0 : put_field ("has_minus", std::to_string (e.get_has_minus ()));
2222 0 : end ("RangePatternBoundLiteral");
2223 0 : }
2224 :
2225 : void
2226 0 : Dump::visit (RangePatternBoundPath &e)
2227 : {
2228 0 : begin ("RangePatternBoundPath");
2229 0 : put_field ("path", e.get_path ().to_string ());
2230 0 : end ("RangePatternBoundPath");
2231 0 : }
2232 :
2233 : void
2234 0 : Dump::visit (RangePatternBoundQualPath &e)
2235 : {
2236 0 : begin ("RangePatternBoundQualPath");
2237 0 : visit_field ("path", e.get_qualified_path ());
2238 0 : end ("RangePatternBoundQualPath");
2239 0 : }
2240 :
2241 : void
2242 0 : Dump::visit (RangePattern &e)
2243 : {
2244 0 : begin ("RangePattern");
2245 0 : do_mappings (e.get_mappings ());
2246 0 : put_field ("lower", e.get_lower_bound ().to_string ());
2247 0 : put_field ("upper", e.get_upper_bound ().to_string ());
2248 0 : put_field ("has_ellipsis_syntax",
2249 0 : std::to_string (e.get_has_ellipsis_syntax ()));
2250 0 : end ("RangePattern");
2251 0 : }
2252 :
2253 : void
2254 0 : Dump::visit (ReferencePattern &e)
2255 : {
2256 0 : begin ("ReferencePattern");
2257 0 : do_mappings (e.get_mappings ());
2258 0 : put_field ("mut", std::to_string (e.is_mut ()));
2259 0 : put_field ("pattern", e.get_referenced_pattern ().to_debug_string ());
2260 0 : end ("ReferencePattern");
2261 0 : }
2262 :
2263 : void
2264 0 : Dump::visit (StructPatternFieldTuplePat &e)
2265 : {
2266 0 : begin ("StructPatternFieldTuplePat");
2267 0 : do_mappings (e.get_mappings ());
2268 0 : auto oa = e.get_outer_attrs ();
2269 0 : do_outer_attrs (oa);
2270 0 : put_field ("index", std::to_string (e.get_index ()));
2271 0 : put_field ("tuple_pattern", e.get_tuple_pattern ().to_string ());
2272 0 : end ("StructPatternFieldTuplePat");
2273 0 : }
2274 :
2275 : void
2276 0 : Dump::visit (StructPatternFieldIdentPat &e)
2277 : {
2278 0 : begin ("StructPatternFieldIdentPat");
2279 0 : auto oa = e.get_outer_attrs ();
2280 0 : do_outer_attrs (oa);
2281 0 : put_field ("ident", e.get_identifier ().as_string ());
2282 0 : visit_field ("ident_pattern", e.get_pattern ());
2283 0 : end ("StructPatternFieldIdentPat");
2284 0 : }
2285 :
2286 : void
2287 0 : Dump::visit (StructPatternFieldIdent &e)
2288 : {
2289 0 : begin ("StructPatternFieldIdent");
2290 0 : auto oa = e.get_outer_attrs ();
2291 0 : do_outer_attrs (oa);
2292 :
2293 0 : put_field ("has_ref", std::to_string (e.get_has_ref ()));
2294 0 : put_field ("mut", std::to_string (e.is_mut ()));
2295 0 : put_field ("ident", e.get_identifier ().as_string ());
2296 0 : end ("StructPatternFieldIdent");
2297 0 : }
2298 :
2299 : void
2300 0 : Dump::visit (StructPattern &e)
2301 : {
2302 0 : begin ("StructPattern");
2303 :
2304 0 : visit_field ("path", e.get_path ());
2305 0 : put_field ("elems", e.get_struct_pattern_elems ().to_string ());
2306 :
2307 0 : end ("StructPattern");
2308 0 : }
2309 :
2310 : void
2311 0 : Dump::visit (TupleStructItemsNoRest &e)
2312 : {
2313 0 : begin ("TupleStructItemsNoRest");
2314 0 : visit_collection ("patterns", e.get_patterns ());
2315 0 : end ("TupleStructItemsNoRest");
2316 0 : }
2317 :
2318 : void
2319 0 : Dump::visit (TupleStructItemsHasRest &e)
2320 : {
2321 0 : begin ("TupleStructItemsHasRest");
2322 0 : visit_collection ("lower_patterns", e.get_lower_patterns ());
2323 0 : visit_collection ("upper_patterns", e.get_upper_patterns ());
2324 0 : end ("TupleStructItemsHasRest");
2325 0 : }
2326 :
2327 : void
2328 0 : Dump::visit (TupleStructPattern &e)
2329 : {
2330 0 : begin ("TupleStructPattern");
2331 0 : do_mappings (e.get_mappings ());
2332 :
2333 0 : put_field ("path", e.get_path ().to_string ());
2334 :
2335 0 : visit_field ("items", e.get_items ());
2336 :
2337 0 : end ("TupleStructPattern");
2338 0 : }
2339 :
2340 : void
2341 0 : Dump::visit (TuplePatternItemsNoRest &e)
2342 : {
2343 0 : begin ("TuplePatternItemsNoRest");
2344 0 : visit_collection ("patterns", e.get_patterns ());
2345 0 : end ("TuplePatternItemsNoRest");
2346 0 : }
2347 :
2348 : void
2349 0 : Dump::visit (TuplePatternItemsHasRest &e)
2350 : {
2351 0 : begin ("TuplePatternItemsHasRest");
2352 0 : visit_collection ("lower_patterns", e.get_lower_patterns ());
2353 0 : visit_collection ("upper_patterns", e.get_upper_patterns ());
2354 0 : end ("TuplePatternItemsHasRest");
2355 0 : }
2356 :
2357 : void
2358 0 : Dump::visit (TuplePattern &e)
2359 : {
2360 0 : begin ("TuplePattern");
2361 0 : do_mappings (e.get_mappings ());
2362 0 : visit_field ("items", e.get_items ());
2363 0 : end ("TuplePattern");
2364 0 : }
2365 :
2366 : void
2367 0 : Dump::visit (SlicePatternItemsNoRest &e)
2368 : {
2369 0 : begin ("SlicePatternItemsNoRest");
2370 0 : visit_collection ("patterns", e.get_patterns ());
2371 0 : end ("SlicePatternItemsNoRest");
2372 0 : }
2373 :
2374 : void
2375 0 : Dump::visit (SlicePatternItemsHasRest &e)
2376 : {
2377 0 : begin ("SlicePatternItemsHasRest");
2378 0 : visit_collection ("lower_patterns", e.get_lower_patterns ());
2379 0 : if (e.has_rest_bind ())
2380 0 : visit_field ("rest_bind", e.get_rest_bind ());
2381 0 : visit_collection ("upper_patterns", e.get_upper_patterns ());
2382 0 : end ("SlicePatternItemsHasRest");
2383 0 : }
2384 :
2385 : void
2386 0 : Dump::visit (SlicePattern &e)
2387 : {
2388 0 : begin ("SlicePattern");
2389 0 : do_mappings (e.get_mappings ());
2390 0 : visit_field ("items", e.get_items ());
2391 0 : end ("SlicePattern");
2392 0 : }
2393 :
2394 : void
2395 0 : Dump::visit (AltPattern &e)
2396 : {
2397 0 : begin ("AltPattern");
2398 0 : do_mappings (e.get_mappings ());
2399 0 : visit_collection ("alts", e.get_alts ());
2400 0 : end ("AltPattern");
2401 0 : }
2402 :
2403 : void
2404 0 : Dump::visit (EmptyStmt &e)
2405 : {
2406 0 : begin ("EmptyStmt");
2407 0 : do_stmt (e);
2408 0 : end ("EmptyStmt");
2409 0 : }
2410 :
2411 : void
2412 0 : Dump::visit (LetStmt &e)
2413 : {
2414 0 : begin ("LetStmt");
2415 0 : do_stmt (e);
2416 0 : auto oa = e.get_outer_attrs ();
2417 0 : do_outer_attrs (oa);
2418 :
2419 0 : visit_field ("variable_pattern", e.get_pattern ());
2420 :
2421 0 : if (e.has_type ())
2422 0 : visit_field ("type", e.get_type ());
2423 0 : if (e.has_init_expr ())
2424 0 : visit_field ("init_expr", e.get_init_expr ());
2425 :
2426 0 : end ("LetStmt");
2427 0 : }
2428 :
2429 : void
2430 0 : Dump::visit (ExprStmt &e)
2431 : {
2432 0 : begin ("ExprStmt");
2433 0 : do_stmt (e);
2434 0 : put_field ("must_be_unit", std::to_string (e.is_unit_check_needed ()));
2435 0 : visit_field ("expr", e.get_expr ());
2436 0 : end ("ExprStmt");
2437 0 : }
2438 :
2439 : void
2440 0 : Dump::visit (TraitBound &e)
2441 : {
2442 0 : begin ("TraitBound");
2443 0 : do_mappings (e.get_mappings ());
2444 0 : put_field ("in_parens", std::to_string (e.get_in_parens ()));
2445 0 : put_field ("polarity", BoundPolarityString (e.get_polarity ()));
2446 :
2447 0 : visit_collection ("for_lifetime", e.get_for_lifetimes ());
2448 0 : visit_field ("type_path", e.get_path ());
2449 :
2450 0 : end ("TraitBound");
2451 0 : }
2452 :
2453 : void
2454 0 : Dump::visit (ImplTraitType &e)
2455 : {
2456 0 : begin ("ImplTraitType");
2457 0 : do_type (e);
2458 :
2459 0 : visit_collection ("type_param_bounds", e.get_type_param_bounds ());
2460 :
2461 0 : end ("ImplTraitType");
2462 0 : }
2463 :
2464 : void
2465 0 : Dump::visit (TraitObjectType &e)
2466 : {
2467 0 : begin ("TraitObjectType");
2468 0 : do_type (e);
2469 :
2470 0 : put_field ("has_dyn", std::to_string (e.get_has_dyn ()));
2471 :
2472 0 : visit_collection ("type_param_bounds", e.get_type_param_bounds ());
2473 :
2474 0 : end ("TraitObjectType");
2475 0 : }
2476 :
2477 : void
2478 0 : Dump::visit (ParenthesisedType &e)
2479 : {
2480 0 : begin ("ParenthesisedType");
2481 0 : do_type (e);
2482 0 : put_field ("type_in_parens", e.get_type_in_parens ().to_debug_string ());
2483 0 : end ("ParenthesisedType");
2484 0 : }
2485 :
2486 : void
2487 0 : Dump::visit (TupleType &e)
2488 : {
2489 0 : begin ("TupleType");
2490 0 : do_type (e);
2491 0 : visit_collection ("elems", e.get_elems ());
2492 0 : end ("TupleType");
2493 0 : }
2494 :
2495 : void
2496 0 : Dump::visit (NeverType &e)
2497 : {
2498 0 : begin ("NeverType");
2499 0 : do_type (e);
2500 0 : end ("NeverType");
2501 0 : }
2502 :
2503 : void
2504 0 : Dump::visit (RawPointerType &e)
2505 : {
2506 0 : begin ("RawPointerType");
2507 0 : do_type (e);
2508 0 : put_field ("mut", Rust::enum_to_str (e.get_mut ()));
2509 0 : put_field ("type", e.get_type ().to_debug_string ());
2510 0 : end ("RawPointerType");
2511 0 : }
2512 :
2513 : void
2514 0 : Dump::visit (ReferenceType &e)
2515 : {
2516 0 : begin ("ReferenceType");
2517 0 : do_type (e);
2518 0 : put_field ("lifetime", e.get_lifetime ().to_string ());
2519 0 : put_field ("mut", enum_to_str (e.get_mut ()));
2520 0 : put_field ("type", e.get_base_type ().to_debug_string ());
2521 0 : end ("ReferenceType");
2522 0 : }
2523 :
2524 : void
2525 0 : Dump::visit (ArrayType &e)
2526 : {
2527 0 : begin ("ArrayType");
2528 0 : do_type (e);
2529 0 : visit_field ("type", e.get_element_type ());
2530 0 : visit_field ("size", e.get_size_expr ());
2531 0 : end ("ArrayType");
2532 0 : }
2533 :
2534 : void
2535 0 : Dump::visit (SliceType &e)
2536 : {
2537 0 : begin ("SliceType");
2538 0 : do_type (e);
2539 0 : visit_field ("elem_type", e.get_element_type ());
2540 0 : end ("SliceType");
2541 0 : }
2542 :
2543 : void
2544 0 : Dump::visit (InferredType &e)
2545 : {
2546 0 : begin ("InferredType");
2547 0 : do_type (e);
2548 0 : end ("InferredType");
2549 0 : }
2550 :
2551 : void
2552 0 : Dump::visit (BareFunctionType &e)
2553 : {
2554 0 : begin ("BareFunctionType");
2555 0 : do_type (e);
2556 :
2557 0 : visit_collection ("for_lifetimes", e.get_for_lifetimes ());
2558 :
2559 0 : put_field ("function_qualifiers", e.get_function_qualifiers ().to_string ());
2560 :
2561 0 : if (e.get_function_params ().empty ())
2562 : {
2563 0 : put_field ("params", "none");
2564 : }
2565 : else
2566 : {
2567 0 : begin_field ("params");
2568 0 : for (auto ¶m : e.get_function_params ())
2569 : {
2570 0 : begin ("MaybeNamedParam");
2571 0 : do_maybenamedparam (param);
2572 0 : end ("MaybeNamedParam");
2573 : }
2574 0 : end_field ("params");
2575 : }
2576 :
2577 0 : if (e.has_return_type ())
2578 0 : visit_field ("return_type", e.get_return_type ());
2579 :
2580 0 : put_field ("is_variadic", std::to_string (e.get_is_variadic ()));
2581 0 : end ("BareFunctionType");
2582 0 : }
2583 :
2584 : } // namespace HIR
2585 : } // namespace Rust
2586 :
2587 : // In the global namespace to make it easier to call from debugger
2588 : void
2589 0 : debug (Rust::HIR::FullVisitable &v)
2590 : {
2591 0 : Rust::HIR::Dump::debug (v);
2592 0 : }
|