aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2025-01-30 14:56:37 +0100
committerCohenArthur <arthur.cohen@embecosm.com>2025-02-20 09:37:09 +0000
commitf85babd713a141b850eed3b595725ef8d63f3aeb (patch)
tree585c3f72773f9a626827b5d488b968ae7e6cc82e /gcc
parente3cebdda0d57e28098dbcc11b45aef85f9c152ae (diff)
downloadgcc-f85babd713a141b850eed3b595725ef8d63f3aeb.zip
gcc-f85babd713a141b850eed3b595725ef8d63f3aeb.tar.gz
gcc-f85babd713a141b850eed3b595725ef8d63f3aeb.tar.bz2
ast-builder: Improve function generation.
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::block): Change return type. (Builder::loop): Use new APIs. * ast/rust-ast-builder.h: Change return type of block functions.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast-builder.cc22
-rw-r--r--gcc/rust/ast/rust-ast-builder.h12
2 files changed, 17 insertions, 17 deletions
diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index e06b81c..88acb7a 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -279,23 +279,25 @@ Builder::path_in_expression (LangItem::Kind lang_item) const
return PathInExpression (lang_item, {}, loc);
}
-std::unique_ptr<Expr>
-Builder::block (std::unique_ptr<Stmt> &&stmt,
+std::unique_ptr<BlockExpr>
+Builder::block (tl::optional<std::unique_ptr<Stmt>> &&stmt,
std::unique_ptr<Expr> &&tail_expr) const
{
auto stmts = std::vector<std::unique_ptr<Stmt>> ();
- stmts.emplace_back (std::move (stmt));
+
+ if (stmt)
+ stmts.emplace_back (std::move (*stmt));
return block (std::move (stmts), std::move (tail_expr));
}
-std::unique_ptr<Expr>
+std::unique_ptr<BlockExpr>
Builder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
std::unique_ptr<Expr> &&tail_expr) const
{
- return std::unique_ptr<Expr> (new BlockExpr (std::move (stmts),
- std::move (tail_expr), {}, {},
- LoopLabel::error (), loc, loc));
+ return std::unique_ptr<BlockExpr> (
+ new BlockExpr (std::move (stmts), std::move (tail_expr), {}, {},
+ LoopLabel::error (), loc, loc));
}
std::unique_ptr<Expr>
@@ -421,11 +423,9 @@ Builder::match_case (std::unique_ptr<Pattern> &&pattern,
std::unique_ptr<Expr>
Builder::loop (std::vector<std::unique_ptr<Stmt>> &&stmts)
{
- auto block = std::unique_ptr<BlockExpr> (
- new BlockExpr (std::move (stmts), nullptr, {}, {}, LoopLabel::error (), loc,
- loc));
+ auto block_expr = block (std::move (stmts), nullptr);
- return std::unique_ptr<Expr> (new LoopExpr (std::move (block), loc));
+ return std::unique_ptr<Expr> (new LoopExpr (std::move (block_expr), loc));
}
std::unique_ptr<TypeParamBound>
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index 6e4dfb8..3436244 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -82,12 +82,12 @@ public:
std::unique_ptr<Expr> deref (std::unique_ptr<Expr> &&of) const;
/* Create a block with an optional tail expression */
- std::unique_ptr<Expr> block (std::vector<std::unique_ptr<Stmt>> &&stmts,
- std::unique_ptr<Expr> &&tail_expr
- = nullptr) const;
- std::unique_ptr<Expr> block (std::unique_ptr<Stmt> &&stmt,
- std::unique_ptr<Expr> &&tail_expr
- = nullptr) const;
+ std::unique_ptr<BlockExpr> block (std::vector<std::unique_ptr<Stmt>> &&stmts,
+ std::unique_ptr<Expr> &&tail_expr
+ = nullptr) const;
+ std::unique_ptr<BlockExpr> block (tl::optional<std::unique_ptr<Stmt>> &&stmt,
+ std::unique_ptr<Expr> &&tail_expr
+ = nullptr) const;
/* Create an early return expression with an optional expression */
std::unique_ptr<Expr> return_expr (std::unique_ptr<Expr> &&to_return