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>
diff --git a/src/program_builder.h b/src/program_builder.h
index 400f9cd..7e28578 100644
--- a/src/program_builder.h
+++ b/src/program_builder.h
@@ -1149,12 +1149,16 @@
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