From 49668bbe177009abfe5b3224770c88dddf30b436 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Sat, 17 Apr 2021 05:32:01 +0000 Subject: [PATCH] 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 Reviewed-by: James Price --- src/program_builder.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/program_builder.h b/src/program_builder.h index 400f9cdee7..7e2857892b 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -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 - ast::ReturnStatement* Return(Args&&... args) { - return create(std::forward(args)...); + ast::ReturnStatement* Return() { return create(); } + + /// Creates an ast::ReturnStatement with the given return value + /// @param val the return value + /// @returns the return statement pointer + template + ast::ReturnStatement* Return(EXPR&& val) { + return create(Expr(std::forward(val))); } /// Creates a ast::Struct and type::Struct, registering the type::Struct with