Line data Source code
1 : // Copyright (C) 2025-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-expression-yeast.h"
20 : #include "rust-ast-builder.h"
21 : #include "rust-ast-visitor.h"
22 : #include "rust-desugar-question-mark.h"
23 : #include "rust-desugar-try-block.h"
24 : #include "rust-desugar-for-loops.h"
25 : #include "rust-desugar-while-let.h"
26 : #include "rust-expr.h"
27 :
28 : namespace Rust {
29 : namespace AST {
30 :
31 : void
32 4747 : ExpressionYeast::go (AST::Crate &crate)
33 : {
34 4747 : current_crate = crate;
35 :
36 4747 : PointerVisitor::visit (crate);
37 4747 : }
38 :
39 : void
40 614 : ExpressionYeast::dispatch_loops (std::unique_ptr<Expr> &loop_expr)
41 : {
42 614 : auto &loop = static_cast<BaseLoopExpr &> (*loop_expr.get ());
43 614 : auto node_source = Builder::get_item_source (current_crate.value ());
44 :
45 614 : switch (loop.get_loop_kind ())
46 : {
47 119 : case BaseLoopExpr::Kind::For:
48 119 : DesugarForLoops::go (loop_expr, node_source);
49 119 : break;
50 26 : case BaseLoopExpr::Kind::WhileLet:
51 26 : DesugarWhileLet::go (loop_expr, node_source);
52 26 : break;
53 : default:
54 : break;
55 : }
56 614 : }
57 :
58 : void
59 670942 : ExpressionYeast::reseat (std::unique_ptr<Expr> &expr)
60 : {
61 670942 : auto node_source = Builder::get_item_source (current_crate.value ());
62 :
63 670942 : switch (expr->get_expr_kind ())
64 : {
65 194 : case Expr::Kind::ErrorPropagation:
66 194 : DesugarQuestionMark::go (expr, node_source);
67 194 : break;
68 31 : case Expr::Kind::Try:
69 31 : DesugarTryBlock::go (expr, node_source);
70 31 : break;
71 614 : case Expr::Kind::Loop:
72 614 : dispatch_loops (expr);
73 614 : break;
74 :
75 : default:
76 : break;
77 : }
78 :
79 670942 : visit (expr);
80 670942 : }
81 :
82 : } // namespace AST
83 : } // namespace Rust
|