diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-01-23 11:42:38 +0000 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2025-02-02 18:31:22 +0000 |
commit | 4a053730c5c880984be1a7f8b6cfb19b62aa3331 (patch) | |
tree | 1fdc15785cdce84d06fa8a6e86c5271275f3479d /gcc | |
parent | df1a65d6d275e097f73bb0c6652061e4dca240ab (diff) | |
download | gcc-4a053730c5c880984be1a7f8b6cfb19b62aa3331.zip gcc-4a053730c5c880984be1a7f8b6cfb19b62aa3331.tar.gz gcc-4a053730c5c880984be1a7f8b6cfb19b62aa3331.tar.bz2 |
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 963ba99..0538998 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 5096e83..f67546f 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, |