[gcc/devel/rust/master] ast: builder: Add Return expression builder
Thomas Schwinge
tschwinge@gcc.gnu.org
Wed Mar 26 14:11:19 GMT 2025
https://gcc.gnu.org/g:4a053730c5c880984be1a7f8b6cfb19b62aa3331
commit 4a053730c5c880984be1a7f8b6cfb19b62aa3331
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Thu Jan 23 11:42:38 2025 +0000
ast: builder: Add Return expression builder
gcc/rust/ChangeLog:
* ast/rust-ast-builder.h: Declare it.
* ast/rust-ast-builder.cc (Builder::return_expr): Define it.
Diff:
---
gcc/rust/ast/rust-ast-builder.cc | 7 +++++++
gcc/rust/ast/rust-ast-builder.h | 4 ++++
2 files changed, 11 insertions(+)
diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 963ba99d05f4..0538998f0170 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -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
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index 5096e83bd9c0..f67546fe8809 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -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,
More information about the Gcc-cvs
mailing list