]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: builder: Add match_case() function and new block() one
authorArthur Cohen <arthur.cohen@embecosm.com>
Fri, 18 Apr 2025 16:18:06 +0000 (18:18 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:47 +0000 (16:36 +0200)
gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::block): New function.
(Builder::match_case): Likewise.
* ast/rust-ast-builder.h: Declare them.

gcc/rust/ast/rust-ast-builder.cc
gcc/rust/ast/rust-ast-builder.h

index 7e017d53629cf5e38fcde1df358fd5604308ec47..2692684a9bac3618550b7576b7bd1805ef3cce51 100644 (file)
@@ -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)
 {
index d1b6529599f72fd50e02a051af118693634a5cb9..cb922dba6589f55ec6c678ce5703b167dbc2ffdf 100644 (file)
@@ -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);