]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: ast: builder: Add Return expression builder
authorArthur Cohen <arthur.cohen@embecosm.com>
Thu, 23 Jan 2025 11:42:38 +0000 (11:42 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 24 Mar 2025 12:07:00 +0000 (13:07 +0100)
gcc/rust/ChangeLog:

* ast/rust-ast-builder.h: Declare it.
* ast/rust-ast-builder.cc (Builder::return_expr): Define it.

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

index 3a3181f3752dc0f4d80fcf5ada7984d612cd9ea1..aef0e110ce073bea65cc8ba3b1199ad6d4fc6d2d 100644 (file)
@@ -276,6 +276,13 @@ Builder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
                                               LoopLabel::error (), loc, loc));
 }
 
+std::unique_ptr<Expr>
+Builder::return_expr (std::unique_ptr<Expr> &&to_return)
+{
+  return std::unique_ptr<Expr> (
+    new ReturnExpr (std::move (to_return), {}, loc));
+}
+
 std::unique_ptr<Stmt>
 Builder::let (std::unique_ptr<Pattern> pattern, std::unique_ptr<Type> type,
              std::unique_ptr<Expr> init) const
index 9c5c1645eb94095592ba94ed05556d20536e50d4..90a878791dfcc97addbe23dc8731e409b5cecad7 100644 (file)
@@ -89,6 +89,10 @@ public:
                               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
+                                    = nullptr);
+
   /* Create a let binding with an optional type and initializer (`let <name> :
    * <type> = <init>`) */
   std::unique_ptr<Stmt> let (std::unique_ptr<Pattern> pattern,