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