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 4860 : ExpressionYeast::go (AST::Crate &crate)
33 : {
34 4860 : current_crate = crate;
35 :
36 4860 : PointerVisitor::visit (crate);
37 4860 : }
38 :
39 : void
40 950 : ExpressionYeast::dispatch_loops (std::unique_ptr<Expr> &loop_expr)
41 : {
42 950 : auto &loop = static_cast<BaseLoopExpr &> (*loop_expr.get ());
43 950 : auto node_source = Builder::get_item_source (current_crate.value ());
44 :
45 950 : switch (loop.get_loop_kind ())
46 : {
47 169 : case BaseLoopExpr::Kind::For:
48 169 : DesugarForLoops::go (loop_expr, node_source);
49 169 : break;
50 47 : case BaseLoopExpr::Kind::WhileLet:
51 47 : DesugarWhileLet::go (loop_expr, node_source);
52 47 : break;
53 : default:
54 : break;
55 : }
56 950 : }
57 :
58 : void
59 701325 : ExpressionYeast::reseat (std::unique_ptr<Expr> &expr)
60 : {
61 701325 : auto node_source = Builder::get_item_source (current_crate.value ());
62 :
63 701325 : switch (expr->get_expr_kind ())
64 : {
65 241 : case Expr::Kind::ErrorPropagation:
66 241 : DesugarQuestionMark::go (expr, node_source);
67 241 : break;
68 31 : case Expr::Kind::Try:
69 31 : DesugarTryBlock::go (expr, node_source);
70 31 : break;
71 950 : case Expr::Kind::Loop:
72 950 : dispatch_loops (expr);
73 950 : break;
74 :
75 : default:
76 : break;
77 : }
78 :
79 701325 : visit (expr);
80 701325 : }
81 :
82 : } // namespace AST
83 : } // namespace Rust
|