Skip to content

Commit

Permalink
ast: builder: Add Return expression builder
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* ast/rust-ast-builder.h: Declare it.
	* ast/rust-ast-builder.cc (Builder::return_expr): Define it.
  • Loading branch information
CohenArthur committed Jan 24, 2025
1 parent dd750c9 commit ba18d7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gcc/rust/ast/rust-ast-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,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
Expand Down
4 changes: 4 additions & 0 deletions gcc/rust/ast/rust-ast-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class Builder
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,
Expand Down

0 comments on commit ba18d7b

Please sign in to comment.