-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ast: builder: Add Return expression builder #3386
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
Comment on lines
+89
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'd need to change the AST for this then, because the std::unique_ptr<Expr>
Builder::return_expr (tl::optional<std::unique_ptr<Expr>> &&to_return)
{
if (to_return)
return std::unique_ptr<Expr> (
new ReturnExpr (std::move (*to_return), {}, loc));
return std::unique_ptr<Expr> (new ReturnExpr (nullptr, {}, loc));
} which is quite heavy |
||
|
||
/* Create a let binding with an optional type and initializer (`let <name> : | ||
* <type> = <init>`) */ | ||
std::unique_ptr<Stmt> let (std::unique_ptr<Pattern> pattern, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we use
make_unique here
? I believe we can even get rid of our implementation since baseline cpp version has been bumped to cpp14.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried using it and it complains about not finding a matching constructor:
but maybe I'm missing something