diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-01-23 11:42:38 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-24 13:07:00 +0100 |
commit | 50c9ea9121629fc415700aa0b343b87247cc2a89 (patch) | |
tree | 188c6ba428ddd1be3c57c0db89eaa2ce14af71d9 /gcc | |
parent | 51c247c4dbe9166669ca0f06127a8f24f0c37aae (diff) | |
download | gcc-50c9ea9121629fc415700aa0b343b87247cc2a89.zip gcc-50c9ea9121629fc415700aa0b343b87247cc2a89.tar.gz gcc-50c9ea9121629fc415700aa0b343b87247cc2a89.tar.bz2 |
gccrs: 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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-ast-builder.cc | 7 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-builder.h | 4 |
2 files changed, 11 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc index 3a3181f..aef0e11 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 9c5c164..90a8787 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, |