https://gcc.gnu.org/g:5ea7f9cf6169cd75cce13fa89a6269f179bad156

commit r16-2854-g5ea7f9cf6169cd75cce13fa89a6269f179bad156
Author: Arthur Cohen <arthur.co...@embecosm.com>
Date:   Fri Apr 18 18:18:06 2025 +0200

    gccrs: builder: Add match_case() function and new block() one
    
    gcc/rust/ChangeLog:
    
            * ast/rust-ast-builder.cc (Builder::block): New function.
            (Builder::match_case): Likewise.
            * ast/rust-ast-builder.h: Declare them.

Diff:
---
 gcc/rust/ast/rust-ast-builder.cc | 13 ++++++++++++-
 gcc/rust/ast/rust-ast-builder.h  |  4 ++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 7e017d53629c..2692684a9bac 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -331,6 +331,12 @@ Builder::block () const
   return block (std::move (stmts));
 }
 
+std::unique_ptr<BlockExpr>
+Builder::block (std::unique_ptr<Expr> &&tail_expr) const
+{
+  return block (tl::nullopt, std::move (tail_expr));
+}
+
 std::unique_ptr<BlockExpr>
 Builder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
                std::unique_ptr<Expr> &&tail_expr) const
@@ -490,9 +496,14 @@ MatchCase
 Builder::match_case (std::unique_ptr<Pattern> &&pattern,
                     std::unique_ptr<Expr> &&expr)
 {
-  return MatchCase (match_arm (std::move (pattern)), std::move (expr));
+  return match_case (match_arm (std::move (pattern)), std::move (expr));
 }
 
+MatchCase
+Builder::match_case (MatchArm &&arm, std::unique_ptr<Expr> &&expr)
+{
+  return MatchCase (std::move (arm), std::move (expr));
+}
 std::unique_ptr<Expr>
 Builder::loop (std::vector<std::unique_ptr<Stmt>> &&stmts)
 {
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index d1b6529599f7..cb922dba6589 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -130,6 +130,9 @@ public:
   /* Create an empty block */
   std::unique_ptr<BlockExpr> block () const;
 
+  /* Create a block with just a tail expression */
+  std::unique_ptr<BlockExpr> block (std::unique_ptr<Expr> &&tail_expr) const;
+
   /* Create an early return expression with an optional expression */
   std::unique_ptr<Expr> return_expr (std::unique_ptr<Expr> &&to_return
                                     = nullptr);
@@ -285,6 +288,7 @@ public:
   MatchArm match_arm (std::unique_ptr<Pattern> &&pattern);
   MatchCase match_case (std::unique_ptr<Pattern> &&pattern,
                        std::unique_ptr<Expr> &&expr);
+  MatchCase match_case (MatchArm &&arm, std::unique_ptr<Expr> &&expr);
 
   /* Create a loop expression */
   std::unique_ptr<Expr> loop (std::vector<std::unique_ptr<Stmt>> &&stmts);

Reply via email to