ProgramBuilder: Tweak Return() signature

Instead of directly fowarding to ReturnStatement, pass the parameter through `Expr()`.
Also add a no-arg overload.

This means we can write `Return(1);`, `Return("a")`, `Return()`

Change-Id: I8f5df630f540f9cecdf82d24e2810a0844e025e8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48046
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-04-17 05:32:01 +00:00 committed by Commit Bot service account
parent a0cf62f415
commit 49668bbe17

View File

@ -1149,12 +1149,16 @@ class ProgramBuilder {
return func;
}
/// Creates an ast::ReturnStatement with the input args
/// @param args arguments to construct a return statement with
/// Creates an ast::ReturnStatement with no return value
/// @returns the return statement pointer
template <typename... Args>
ast::ReturnStatement* Return(Args&&... args) {
return create<ast::ReturnStatement>(std::forward<Args>(args)...);
ast::ReturnStatement* Return() { return create<ast::ReturnStatement>(); }
/// Creates an ast::ReturnStatement with the given return value
/// @param val the return value
/// @returns the return statement pointer
template <typename EXPR>
ast::ReturnStatement* Return(EXPR&& val) {
return create<ast::ReturnStatement>(Expr(std::forward<EXPR>(val)));
}
/// Creates a ast::Struct and type::Struct, registering the type::Struct with