-
Notifications
You must be signed in to change notification settings - Fork 165
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
base: master
Are you sure you want to change the base?
Conversation
02c1983
to
ba18d7b
Compare
gcc/rust/ChangeLog: * ast/rust-ast-builder.h: Declare it. * ast/rust-ast-builder.cc (Builder::return_expr): Define it.
return std::unique_ptr<Expr> ( | ||
new ReturnExpr (std::move (to_return), {}, loc)); |
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:
../../gcc/rust/ast/rust-ast-builder.cc:220:39: error: no matching function for call to ‘make_unique<Rust::AST::ReturnExpr>(std::remove_reference<std::unique_ptr<Rust::AST::Expr>&>::type, <brace-enclosed initializer list>, location_t&)’
220 | return std::make_unique<ReturnExpr> (std::move (to_return), {}, loc);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
but maybe I'm missing something
std::unique_ptr<Expr> return_expr (std::unique_ptr<Expr> &&to_return | ||
= nullptr); |
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.
std::unique_ptr<Expr> &&
I wish it was an optional instead, this would draw a clear line and we would be able to easily catch rogue null pointers.
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.
I think we'd need to change the AST for this then, because the ReturnExpr
class only keeps a unique_ptr. So the builder's code would look like this:
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
Add new methods for building
return <x>;
expressions/statements in our AST.