Skip to content

Commit afbc93e

Browse files
committed
desugar: Cleanup for-loop desugar implementation.
gcc/rust/ChangeLog: * ast/rust-desugar-for-loops.cc: Remove functions implemented in AST::Builder. * ast/rust-desugar-for-loops.h: Likewise.
1 parent e5326d2 commit afbc93e

2 files changed

Lines changed: 4 additions & 21 deletions

File tree

gcc/rust/ast/rust-desugar-for-loops.cc

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,10 @@ namespace AST {
3030

3131
DesugarForLoops::DesugarForLoops () {}
3232

33-
MatchArm
34-
DesugarForLoops::DesugarCtx::make_match_arm (std::unique_ptr<Pattern> &&path)
35-
{
36-
auto patterns = std::vector<std::unique_ptr<Pattern>> ();
37-
patterns.emplace_back (std::move (path));
38-
39-
return MatchArm (std::move (patterns), loc);
40-
}
41-
4233
MatchCase
4334
DesugarForLoops::DesugarCtx::make_break_arm ()
4435
{
45-
auto arm = make_match_arm (std::unique_ptr<Pattern> (new PathInExpression (
36+
auto arm = builder.match_arm (std::unique_ptr<Pattern> (new PathInExpression (
4637
builder.path_in_expression (LangItem::Kind::OPTION_NONE))));
4738

4839
auto break_expr
@@ -65,7 +56,7 @@ DesugarForLoops::DesugarCtx::make_continue_arm ()
6556
builder.path_in_expression (LangItem::Kind::OPTION_SOME),
6657
std::move (pattern_item)));
6758

68-
auto val_arm = make_match_arm (std::move (pattern));
59+
auto val_arm = builder.match_arm (std::move (pattern));
6960

7061
auto next = builder.identifier (DesugarCtx::next_value_id);
7162

@@ -77,12 +68,6 @@ DesugarForLoops::DesugarCtx::make_continue_arm ()
7768
return MatchCase (std::move (val_arm), std::move (assignment));
7869
}
7970

80-
std::unique_ptr<Stmt>
81-
DesugarForLoops::DesugarCtx::statementify (std::unique_ptr<Expr> &&expr)
82-
{
83-
return std::unique_ptr<Stmt> (new ExprStmt (std::move (expr), loc, true));
84-
}
85-
8671
std::unique_ptr<Expr>
8772
DesugarForLoops::desugar (ForLoopExpr &expr)
8873
{
@@ -126,10 +111,10 @@ DesugarForLoops::desugar (ForLoopExpr &expr)
126111

127112
auto loop_stmts = std::vector<std::unique_ptr<Stmt>> ();
128113
loop_stmts.emplace_back (std::move (let_next));
129-
loop_stmts.emplace_back (ctx.statementify (std::move (match_next)));
114+
loop_stmts.emplace_back (ctx.builder.statementify (std::move (match_next)));
130115
loop_stmts.emplace_back (std::move (let_pat));
131116
loop_stmts.emplace_back (
132-
ctx.statementify (expr.get_loop_block ().clone_expr ()));
117+
ctx.builder.statementify (expr.get_loop_block ().clone_expr ()));
133118

134119
// loop {
135120
// <let_next>;

gcc/rust/ast/rust-desugar-for-loops.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ class DesugarForLoops
8383
Builder builder;
8484
location_t loc;
8585

86-
MatchArm make_match_arm (std::unique_ptr<Pattern> &&pattern);
8786
MatchCase make_break_arm ();
8887
MatchCase make_continue_arm ();
89-
std::unique_ptr<Stmt> statementify (std::unique_ptr<Expr> &&expr);
9088

9189
constexpr static const char *continue_pattern_id = "#val";
9290
constexpr static const char *next_value_id = "#__next";

0 commit comments

Comments
 (0)