ast: Remove ReturnStatement constructors that don't take a source

set_source() will be removed, so sources will only be specifiable at construction time.

Bug: tint:390
Change-Id: I2b81929e362ccf75145ebc45028dd973a77ae068
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35010
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-12-07 21:09:57 +00:00 committed by Commit Bot service account
parent 321e5a9d7e
commit d0dda258cc
23 changed files with 183 additions and 187 deletions

View File

@ -22,12 +22,8 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::ReturnStatement);
namespace tint { namespace tint {
namespace ast { namespace ast {
ReturnStatement::ReturnStatement() : Base() {}
ReturnStatement::ReturnStatement(const Source& source) : Base(source) {} ReturnStatement::ReturnStatement(const Source& source) : Base(source) {}
ReturnStatement::ReturnStatement(Expression* value) : Base(), value_(value) {}
ReturnStatement::ReturnStatement(const Source& source, Expression* value) ReturnStatement::ReturnStatement(const Source& source, Expression* value)
: Base(source), value_(value) {} : Base(source), value_(value) {}

View File

@ -27,15 +27,10 @@ namespace ast {
/// A return statement /// A return statement
class ReturnStatement : public Castable<ReturnStatement, Statement> { class ReturnStatement : public Castable<ReturnStatement, Statement> {
public: public:
/// Constructor
ReturnStatement();
/// Constructor /// Constructor
/// @param source the source information /// @param source the source information
explicit ReturnStatement(const Source& source); explicit ReturnStatement(const Source& source);
/// Constructor /// Constructor
/// @param value the return value
explicit ReturnStatement(Expression* value);
/// Constructor
/// @param source the return statement source /// @param source the return statement source
/// @param value the return value /// @param value the return value
ReturnStatement(const Source& source, Expression* value); ReturnStatement(const Source& source, Expression* value);

View File

@ -28,7 +28,7 @@ using ReturnStatementTest = TestHelper;
TEST_F(ReturnStatementTest, Creation) { TEST_F(ReturnStatementTest, Creation) {
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>("expr");
ReturnStatement r(expr); ReturnStatement r(Source{}, expr);
EXPECT_EQ(r.value(), expr); EXPECT_EQ(r.value(), expr);
} }
@ -40,41 +40,41 @@ TEST_F(ReturnStatementTest, Creation_WithSource) {
} }
TEST_F(ReturnStatementTest, IsReturn) { TEST_F(ReturnStatementTest, IsReturn) {
ReturnStatement r; ReturnStatement r(Source{});
EXPECT_TRUE(r.Is<ReturnStatement>()); EXPECT_TRUE(r.Is<ReturnStatement>());
} }
TEST_F(ReturnStatementTest, HasValue_WithoutValue) { TEST_F(ReturnStatementTest, HasValue_WithoutValue) {
ReturnStatement r; ReturnStatement r(Source{});
EXPECT_FALSE(r.has_value()); EXPECT_FALSE(r.has_value());
} }
TEST_F(ReturnStatementTest, HasValue_WithValue) { TEST_F(ReturnStatementTest, HasValue_WithValue) {
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>("expr");
ReturnStatement r(expr); ReturnStatement r(Source{}, expr);
EXPECT_TRUE(r.has_value()); EXPECT_TRUE(r.has_value());
} }
TEST_F(ReturnStatementTest, IsValid_WithoutValue) { TEST_F(ReturnStatementTest, IsValid_WithoutValue) {
ReturnStatement r; ReturnStatement r(Source{});
EXPECT_TRUE(r.IsValid()); EXPECT_TRUE(r.IsValid());
} }
TEST_F(ReturnStatementTest, IsValid_WithValue) { TEST_F(ReturnStatementTest, IsValid_WithValue) {
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>("expr");
ReturnStatement r(expr); ReturnStatement r(Source{}, expr);
EXPECT_TRUE(r.IsValid()); EXPECT_TRUE(r.IsValid());
} }
TEST_F(ReturnStatementTest, IsValid_InvalidValue) { TEST_F(ReturnStatementTest, IsValid_InvalidValue) {
auto* expr = create<IdentifierExpression>(""); auto* expr = create<IdentifierExpression>("");
ReturnStatement r(expr); ReturnStatement r(Source{}, expr);
EXPECT_FALSE(r.IsValid()); EXPECT_FALSE(r.IsValid());
} }
TEST_F(ReturnStatementTest, ToStr_WithValue) { TEST_F(ReturnStatementTest, ToStr_WithValue) {
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>("expr");
ReturnStatement r(expr); ReturnStatement r(Source{}, expr);
std::ostringstream out; std::ostringstream out;
r.to_str(out, 2); r.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Return{ EXPECT_EQ(out.str(), R"( Return{
@ -86,7 +86,7 @@ TEST_F(ReturnStatementTest, ToStr_WithValue) {
} }
TEST_F(ReturnStatementTest, ToStr_WithoutValue) { TEST_F(ReturnStatementTest, ToStr_WithoutValue) {
ReturnStatement r; ReturnStatement r(Source{});
std::ostringstream out; std::ostringstream out;
r.to_str(out, 2); r.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Return{} EXPECT_EQ(out.str(), R"( Return{}

View File

@ -82,7 +82,7 @@ class InspectorHelper {
std::string name, std::string name,
ast::FunctionDecorationList decorations = {}) { ast::FunctionDecorationList decorations = {}) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, name, ast::VariableList(), return create<ast::Function>(Source{}, name, ast::VariableList(),
void_type(), body, decorations); void_type(), body, decorations);
} }
@ -101,7 +101,7 @@ class InspectorHelper {
auto* call_expr = auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList()); create<ast::CallExpression>(ident_expr, ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr)); body->append(create<ast::CallStatement>(call_expr));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, caller, ast::VariableList(), return create<ast::Function>(Source{}, caller, ast::VariableList(),
void_type(), body, decorations); void_type(), body, decorations);
} }
@ -141,7 +141,7 @@ class InspectorHelper {
create<ast::IdentifierExpression>(out), create<ast::IdentifierExpression>(out),
create<ast::IdentifierExpression>(in))); create<ast::IdentifierExpression>(in)));
} }
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, name, ast::VariableList(), return create<ast::Function>(Source{}, name, ast::VariableList(),
void_type(), body, decorations); void_type(), body, decorations);
} }
@ -171,7 +171,7 @@ class InspectorHelper {
auto* call_expr = auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList()); create<ast::CallExpression>(ident_expr, ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr)); body->append(create<ast::CallStatement>(call_expr));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, caller, ast::VariableList(), return create<ast::Function>(Source{}, caller, ast::VariableList(),
void_type(), body, decorations); void_type(), body, decorations);
} }
@ -416,7 +416,7 @@ class InspectorHelper {
create<ast::IdentifierExpression>(member_name)))); create<ast::IdentifierExpression>(member_name))));
} }
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, func_name, ast::VariableList(), return create<ast::Function>(Source{}, func_name, ast::VariableList(),
void_type(), body, void_type(), body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -540,7 +540,7 @@ class InspectorHelper {
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("sampler_result"), call_expr)); create<ast::IdentifierExpression>("sampler_result"), call_expr));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, func_name, ast::VariableList(), return create<ast::Function>(Source{}, func_name, ast::VariableList(),
void_type(), body, decorations); void_type(), body, decorations);
@ -582,7 +582,7 @@ class InspectorHelper {
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("sampler_result"), call_expr)); create<ast::IdentifierExpression>("sampler_result"), call_expr));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, func_name, ast::VariableList(), return create<ast::Function>(Source{}, func_name, ast::VariableList(),
void_type(), body, decorations); void_type(), body, decorations);
@ -624,7 +624,7 @@ class InspectorHelper {
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("sampler_result"), call_expr)); create<ast::IdentifierExpression>("sampler_result"), call_expr));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, func_name, ast::VariableList(), return create<ast::Function>(Source{}, func_name, ast::VariableList(),
void_type(), body, decorations); void_type(), body, decorations);
@ -1455,7 +1455,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
AddFuncCall(body, "ub_bar_func"); AddFuncCall(body, "ub_bar_func");
AddFuncCall(body, "ub_baz_func"); AddFuncCall(body, "ub_baz_func");
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::Function* func = create<ast::Function>( ast::Function* func = create<ast::Function>(
Source{}, "ep_func", ast::VariableList(), void_type(), body, Source{}, "ep_func", ast::VariableList(), void_type(), body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -1601,7 +1601,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
AddFuncCall(body, "sb_bar_func"); AddFuncCall(body, "sb_bar_func");
AddFuncCall(body, "sb_baz_func"); AddFuncCall(body, "sb_baz_func");
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::Function* func = create<ast::Function>( ast::Function* func = create<ast::Function>(
Source{}, "ep_func", ast::VariableList(), void_type(), body, Source{}, "ep_func", ast::VariableList(), void_type(), body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -1774,7 +1774,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
AddFuncCall(body, "sb_bar_func"); AddFuncCall(body, "sb_bar_func");
AddFuncCall(body, "sb_baz_func"); AddFuncCall(body, "sb_baz_func");
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::Function* func = create<ast::Function>( ast::Function* func = create<ast::Function>(
Source{}, "ep_func", ast::VariableList(), void_type(), body, Source{}, "ep_func", ast::VariableList(), void_type(), body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{

View File

@ -2374,11 +2374,11 @@ bool FunctionEmitter::EmitNormalTerminator(const BlockInfo& block_info) {
const auto& terminator = *(block_info.basic_block->terminator()); const auto& terminator = *(block_info.basic_block->terminator());
switch (terminator.opcode()) { switch (terminator.opcode()) {
case SpvOpReturn: case SpvOpReturn:
AddStatement(create<ast::ReturnStatement>()); AddStatement(create<ast::ReturnStatement>(Source{}));
return true; return true;
case SpvOpReturnValue: { case SpvOpReturnValue: {
auto value = MakeExpression(terminator.GetSingleWordInOperand(0)); auto value = MakeExpression(terminator.GetSingleWordInOperand(0));
AddStatement(create<ast::ReturnStatement>(value.expr)); AddStatement(create<ast::ReturnStatement>(Source{}, value.expr));
} }
return true; return true;
case SpvOpKill: case SpvOpKill:
@ -2392,11 +2392,11 @@ bool FunctionEmitter::EmitNormalTerminator(const BlockInfo& block_info) {
{ {
const auto* result_type = type_mgr_->GetType(function_.type_id()); const auto* result_type = type_mgr_->GetType(function_.type_id());
if (result_type->AsVoid() != nullptr) { if (result_type->AsVoid() != nullptr) {
AddStatement(create<ast::ReturnStatement>()); AddStatement(create<ast::ReturnStatement>(Source{}));
} else { } else {
auto* ast_type = parser_impl_.ConvertType(function_.type_id()); auto* ast_type = parser_impl_.ConvertType(function_.type_id());
AddStatement(create<ast::ReturnStatement>( AddStatement(create<ast::ReturnStatement>(
parser_impl_.MakeNullValue(ast_type))); Source{}, parser_impl_.MakeNullValue(ast_type)));
} }
} }
return true; return true;

View File

@ -291,7 +291,7 @@ TEST_F(TypeDeterminerTest, Stmt_Return) {
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)); create<ast::SintLiteral>(&i32, 2));
ast::ReturnStatement ret(cond); ast::ReturnStatement ret(Source{}, cond);
EXPECT_TRUE(td()->DetermineResultType(&ret)); EXPECT_TRUE(td()->DetermineResultType(&ret));
ASSERT_NE(cond->result_type(), nullptr); ASSERT_NE(cond->result_type(), nullptr);
@ -300,7 +300,7 @@ TEST_F(TypeDeterminerTest, Stmt_Return) {
TEST_F(TypeDeterminerTest, Stmt_Return_WithoutValue) { TEST_F(TypeDeterminerTest, Stmt_Return_WithoutValue) {
ast::type::I32 i32; ast::type::I32 i32;
ast::ReturnStatement ret; ast::ReturnStatement ret(Source{});
EXPECT_TRUE(td()->DetermineResultType(&ret)); EXPECT_TRUE(td()->DetermineResultType(&ret));
} }
@ -370,14 +370,14 @@ TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) {
ast::VariableList params0; ast::VariableList params0;
auto* main_body = create<ast::BlockStatement>(); auto* main_body = create<ast::BlockStatement>();
main_body->append(create<ast::CallStatement>(call_expr)); main_body->append(create<ast::CallStatement>(call_expr));
main_body->append(create<ast::ReturnStatement>()); main_body->append(create<ast::ReturnStatement>(Source{}));
auto* func_main = auto* func_main =
create<ast::Function>(Source{}, "main", params0, &f32, main_body, create<ast::Function>(Source{}, "main", params0, &f32, main_body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func_main); mod->AddFunction(func_main);
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, "func", params0, &f32, body, auto* func = create<ast::Function>(Source{}, "func", params0, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->AddFunction(func);

View File

@ -124,7 +124,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "func", params, &void_type, body, Source{}, "func", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -193,7 +193,7 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
auto* return_expr = create<ast::ScalarConstructorExpression>( auto* return_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)); create<ast::SintLiteral>(&i32, 2));
body->append(create<ast::ReturnStatement>(return_expr)); body->append(create<ast::ReturnStatement>(Source{}, return_expr));
auto* func = create<ast::Function>(Source{}, "func", params, &i32, body, auto* func = create<ast::Function>(Source{}, "func", params, &i32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -202,7 +202,7 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
auto* return_expr_copy = create<ast::ScalarConstructorExpression>( auto* return_expr_copy = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)); create<ast::SintLiteral>(&i32, 2));
body_copy->append(create<ast::ReturnStatement>(return_expr_copy)); body_copy->append(create<ast::ReturnStatement>(Source{}, return_expr_copy));
auto* func_copy = create<ast::Function>(Source{Source::Location{12, 34}}, auto* func_copy = create<ast::Function>(Source{Source::Location{12, 34}},
"func", params_copy, &i32, body_copy, "func", params_copy, &i32, body_copy,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -226,7 +226,7 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
ast::VariableList params0; ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>(); auto* body0 = create<ast::BlockStatement>();
body0->append(create<ast::CallStatement>(call_expr)); body0->append(create<ast::CallStatement>(call_expr));
body0->append(create<ast::ReturnStatement>()); body0->append(create<ast::ReturnStatement>(Source{}));
auto* func0 = create<ast::Function>(Source{}, "func", params0, &f32, body0, auto* func0 = create<ast::Function>(Source{}, "func", params0, &f32, body0,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod()->AddFunction(func0); mod()->AddFunction(func0);
@ -252,7 +252,7 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
auto* return_expr = create<ast::ScalarConstructorExpression>( auto* return_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)); create<ast::SintLiteral>(&i32, 2));
body0->append(create<ast::ReturnStatement>(return_expr)); body0->append(create<ast::ReturnStatement>(Source{}, return_expr));
auto* func0 = create<ast::Function>(Source{}, "func", params0, &i32, body0, auto* func0 = create<ast::Function>(Source{}, "func", params0, &i32, body0,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod()->AddFunction(func0); mod()->AddFunction(func0);
@ -271,7 +271,7 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
create<ast::SintLiteral>(&i32, 0)); create<ast::SintLiteral>(&i32, 0));
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(return_expr)); body->append(create<ast::ReturnStatement>(Source{}, return_expr));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, "vtx_main", params, &i32, body, Source{Source::Location{12, 34}}, "vtx_main", params, &i32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -294,7 +294,7 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
params.push_back( params.push_back(
create<ast::Variable>(Source{}, "a", ast::StorageClass::kNone, &i32)); create<ast::Variable>(Source{}, "a", ast::StorageClass::kNone, &i32));
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, "vtx_func", params, &void_type, body, Source{Source::Location{12, 34}}, "vtx_func", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -316,7 +316,7 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
ast::type::Void void_type; ast::type::Void void_type;
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, "main", params, &void_type, body, Source{Source::Location{12, 34}}, "main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -338,7 +338,7 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
ast::type::Void void_type; ast::type::Void void_type;
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "vtx_func", params, &void_type, body, Source{}, "vtx_func", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -355,7 +355,7 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
ast::type::Void void_type; ast::type::Void void_type;
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, "vtx_func", params, &void_type, auto* func = create<ast::Function>(Source{}, "vtx_func", params, &void_type,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
mod()->AddFunction(func); mod()->AddFunction(func);

View File

@ -326,7 +326,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs)); Source{Source::Location{12, 34}}, lhs, rhs));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "my_func", params, &void_type, body, Source{}, "my_func", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -634,7 +634,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
auto* body0 = create<ast::BlockStatement>(); auto* body0 = create<ast::BlockStatement>();
body0->append(create<ast::VariableDeclStatement>( body0->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var0)); Source{Source::Location{12, 34}}, var0));
body0->append(create<ast::ReturnStatement>()); body0->append(create<ast::ReturnStatement>(Source{}));
auto* func0 = create<ast::Function>(Source{}, "func0", params0, &void_type, auto* func0 = create<ast::Function>(Source{}, "func0", params0, &void_type,
body0, ast::FunctionDecorationList{}); body0, ast::FunctionDecorationList{});
@ -642,7 +642,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
auto* body1 = create<ast::BlockStatement>(); auto* body1 = create<ast::BlockStatement>();
body1->append(create<ast::VariableDeclStatement>( body1->append(create<ast::VariableDeclStatement>(
Source{Source::Location{13, 34}}, var1)); Source{Source::Location{13, 34}}, var1));
body1->append(create<ast::ReturnStatement>()); body1->append(create<ast::ReturnStatement>(Source{}));
auto* func1 = create<ast::Function>( auto* func1 = create<ast::Function>(
Source{}, "func1", params1, &void_type, body1, Source{}, "func1", params1, &void_type, body1,
ast::FunctionDecorationList{ ast::FunctionDecorationList{

View File

@ -378,14 +378,14 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
ast::type::I32 i32; ast::type::I32 i32;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::ScalarConstructorExpression>( Source{}, create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
auto* else_stmt = create<ast::ElseStatement>(body); auto* else_stmt = create<ast::ElseStatement>(body);
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::ScalarConstructorExpression>( Source{}, create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto* else_if_stmt = create<ast::ElseStatement>( auto* else_if_stmt = create<ast::ElseStatement>(
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
@ -394,8 +394,8 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
body); body);
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::ScalarConstructorExpression>( Source{}, create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
ast::IfStatement expr( ast::IfStatement expr(
@ -436,7 +436,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Return_WithLogical) {
auto* b = create<ast::IdentifierExpression>("b"); auto* b = create<ast::IdentifierExpression>("b");
auto* c = create<ast::IdentifierExpression>("c"); auto* c = create<ast::IdentifierExpression>("c");
ast::ReturnStatement expr(create<ast::BinaryExpression>( ast::ReturnStatement expr(
Source{},
create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr, ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, a, b), c)); create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, a, b), c));

View File

@ -57,7 +57,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = auto* func =
create<ast::Function>(Source{}, "my_func", ast::VariableList{}, create<ast::Function>(Source{}, "my_func", ast::VariableList{},
&void_type, body, ast::FunctionDecorationList{}); &void_type, body, ast::FunctionDecorationList{});
@ -77,7 +77,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = auto* func =
create<ast::Function>(Source{}, "GeometryShader", ast::VariableList{}, create<ast::Function>(Source{}, "GeometryShader", ast::VariableList{},
&void_type, body, ast::FunctionDecorationList{}); &void_type, body, ast::FunctionDecorationList{});
@ -106,7 +106,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, "my_func", params, &void_type, auto* func = create<ast::Function>(Source{}, "my_func", params, &void_type,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -145,7 +145,7 @@ TEST_F(HlslGeneratorImplTest_Function,
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>("foo")));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -203,7 +203,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x")))); create<ast::IdentifierExpression>("x"))));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -257,7 +257,7 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -318,7 +318,7 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -383,7 +383,7 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -444,7 +444,7 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -507,7 +507,7 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(assign); body->append(assign);
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -565,8 +565,8 @@ TEST_F(
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("val"), create<ast::IdentifierExpression>("val"),
create<ast::IdentifierExpression>("param"))); create<ast::IdentifierExpression>("param")));
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("foo"))); Source{}, create<ast::IdentifierExpression>("foo")));
auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32, auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -581,7 +581,7 @@ TEST_F(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>("bar"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"),
expr))); expr)));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, "ep_1", params, &void_type, body, Source{}, "ep_1", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -639,8 +639,8 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::StorageClass::kFunction, &f32)); ast::StorageClass::kFunction, &f32));
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("param"))); Source{}, create<ast::IdentifierExpression>("param")));
auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32, auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -655,7 +655,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>("depth"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"),
expr))); expr)));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, "ep_1", params, &void_type, body, Source{}, "ep_1", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -716,8 +716,8 @@ TEST_F(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x")))); create<ast::IdentifierExpression>("x"))));
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("param"))); Source{}, create<ast::IdentifierExpression>("param")));
auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32, auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -732,7 +732,7 @@ TEST_F(
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>("depth"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"),
expr))); expr)));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, "ep_1", params, &void_type, body, Source{}, "ep_1", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -788,8 +788,8 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::StorageClass::kFunction, &f32)); ast::StorageClass::kFunction, &f32));
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::MemberAccessorExpression>( Source{}, create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x")))); create<ast::IdentifierExpression>("x"))));
auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32, auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32,
@ -808,7 +808,7 @@ TEST_F(HlslGeneratorImplTest_Function,
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -858,8 +858,8 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::StorageClass::kFunction, &f32)); ast::StorageClass::kFunction, &f32));
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::MemberAccessorExpression>( Source{}, create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x")))); create<ast::IdentifierExpression>("x"))));
auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32, auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32,
@ -878,7 +878,7 @@ TEST_F(HlslGeneratorImplTest_Function,
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -926,7 +926,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::FloatLiteral>(&f32, 1.0f)))); create<ast::FloatLiteral>(&f32, 1.0f))));
auto* list = create<ast::BlockStatement>(); auto* list = create<ast::BlockStatement>();
list->append(create<ast::ReturnStatement>()); list->append(create<ast::ReturnStatement>(Source{}));
body->append(create<ast::IfStatement>( body->append(create<ast::IfStatement>(
Source{}, Source{},
@ -937,7 +937,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::SintLiteral>(&i32, 1))), create<ast::SintLiteral>(&i32, 1))),
list, ast::ElseStatementList{})); list, ast::ElseStatementList{}));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, "ep_1", params, &void_type, body, Source{}, "ep_1", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -990,7 +990,7 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "main", params, &void_type, body, Source{}, "main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -1015,7 +1015,7 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "main", params, &void_type, body, Source{}, "main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -1046,7 +1046,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, "my_func", params, &void_type, auto* func = create<ast::Function>(Source{}, "my_func", params, &void_type,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -1117,7 +1117,7 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = auto* func =
create<ast::Function>(Source{}, "a", params, &void_type, body, create<ast::Function>(Source{}, "a", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -1138,7 +1138,7 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = auto* func =
create<ast::Function>(Source{}, "b", params, &void_type, body, create<ast::Function>(Source{}, "b", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{

View File

@ -29,7 +29,7 @@ using HlslGeneratorImplTest_If = TestHelper;
TEST_F(HlslGeneratorImplTest_If, Emit_If) { TEST_F(HlslGeneratorImplTest_If, Emit_If) {
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{}); ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
gen.increment_indent(); gen.increment_indent();
@ -44,11 +44,11 @@ TEST_F(HlslGeneratorImplTest_If, Emit_If) {
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
auto* else_cond = create<ast::IdentifierExpression>("else_cond"); auto* else_cond = create<ast::IdentifierExpression>("else_cond");
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>(Source{}));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::IfStatement i(Source{}, cond, body, ast::IfStatement i(Source{}, cond, body,
{create<ast::ElseStatement>(else_cond, else_body)}); {create<ast::ElseStatement>(else_cond, else_body)});
@ -68,11 +68,11 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>(Source{}));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::IfStatement i(Source{}, cond, body, ast::IfStatement i(Source{}, cond, body,
{create<ast::ElseStatement>(else_body)}); {create<ast::ElseStatement>(else_body)});
@ -92,14 +92,14 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
auto* else_cond = create<ast::IdentifierExpression>("else_cond"); auto* else_cond = create<ast::IdentifierExpression>("else_cond");
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>(Source{}));
auto* else_body_2 = create<ast::BlockStatement>(); auto* else_body_2 = create<ast::BlockStatement>();
else_body_2->append(create<ast::ReturnStatement>()); else_body_2->append(create<ast::ReturnStatement>(Source{}));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::IfStatement i(Source{}, cond, body, ast::IfStatement i(Source{}, cond, body,
{ {

View File

@ -52,7 +52,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
auto* continuing = create<ast::BlockStatement>(); auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::ReturnStatement>()); continuing->append(create<ast::ReturnStatement>(Source{}));
ast::LoopStatement l(body, continuing); ast::LoopStatement l(body, continuing);
gen.increment_indent(); gen.increment_indent();
@ -79,7 +79,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
auto* continuing = create<ast::BlockStatement>(); auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::ReturnStatement>()); continuing->append(create<ast::ReturnStatement>(Source{}));
auto* inner = create<ast::LoopStatement>(body, continuing); auto* inner = create<ast::LoopStatement>(body, continuing);

View File

@ -28,7 +28,7 @@ namespace {
using HlslGeneratorImplTest_Return = TestHelper; using HlslGeneratorImplTest_Return = TestHelper;
TEST_F(HlslGeneratorImplTest_Return, Emit_Return) { TEST_F(HlslGeneratorImplTest_Return, Emit_Return) {
ast::ReturnStatement r; ast::ReturnStatement r(Source{});
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &r)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, &r)) << gen.error();
@ -37,7 +37,7 @@ TEST_F(HlslGeneratorImplTest_Return, Emit_Return) {
TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) { TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) {
auto* expr = create<ast::IdentifierExpression>("expr"); auto* expr = create<ast::IdentifierExpression>("expr");
ast::ReturnStatement r(expr); ast::ReturnStatement r(Source{}, expr);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &r)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, &r)) << gen.error();

View File

@ -60,7 +60,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = auto* func =
create<ast::Function>(Source{}, "my_func", ast::VariableList{}, create<ast::Function>(Source{}, "my_func", ast::VariableList{},
&void_type, body, ast::FunctionDecorationList{}); &void_type, body, ast::FunctionDecorationList{});
@ -82,7 +82,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = auto* func =
create<ast::Function>(Source{}, "main", ast::VariableList{}, &void_type, create<ast::Function>(Source{}, "main", ast::VariableList{}, &void_type,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -113,7 +113,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, "my_func", params, &void_type, auto* func = create<ast::Function>(Source{}, "my_func", params, &void_type,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -153,7 +153,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>("foo")));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
@ -213,7 +213,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x")))); create<ast::IdentifierExpression>("x"))));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
@ -267,7 +267,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
@ -333,7 +333,7 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
@ -404,7 +404,7 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
@ -469,8 +469,8 @@ TEST_F(
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("val"), create<ast::IdentifierExpression>("val"),
create<ast::IdentifierExpression>("param"))); create<ast::IdentifierExpression>("param")));
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("foo"))); Source{}, create<ast::IdentifierExpression>("foo")));
auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32, auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -485,7 +485,7 @@ TEST_F(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>("bar"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"),
expr))); expr)));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, "ep_1", params, &void_type, body, Source{}, "ep_1", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -546,8 +546,8 @@ TEST_F(MslGeneratorImplTest,
ast::StorageClass::kFunction, &f32)); ast::StorageClass::kFunction, &f32));
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("param"))); Source{}, create<ast::IdentifierExpression>("param")));
auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32, auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -562,7 +562,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>("depth"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"),
expr))); expr)));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, "ep_1", params, &void_type, body, Source{}, "ep_1", params, &void_type, body,
@ -627,8 +627,8 @@ TEST_F(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x")))); create<ast::IdentifierExpression>("x"))));
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("param"))); Source{}, create<ast::IdentifierExpression>("param")));
auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32, auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -643,7 +643,7 @@ TEST_F(
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>("depth"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"),
expr))); expr)));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, "ep_1", params, &void_type, body, Source{}, "ep_1", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -697,8 +697,8 @@ TEST_F(MslGeneratorImplTest,
ast::StorageClass::kFunction, &f32)); ast::StorageClass::kFunction, &f32));
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::MemberAccessorExpression>( Source{}, create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x")))); create<ast::IdentifierExpression>("x"))));
auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32, auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32,
@ -717,7 +717,7 @@ TEST_F(MslGeneratorImplTest,
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
@ -781,8 +781,8 @@ TEST_F(MslGeneratorImplTest,
ast::StorageClass::kFunction, &f32)); ast::StorageClass::kFunction, &f32));
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::MemberAccessorExpression>( Source{}, create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("b")))); create<ast::IdentifierExpression>("b"))));
auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32, auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32,
@ -801,7 +801,7 @@ TEST_F(MslGeneratorImplTest,
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
@ -871,8 +871,8 @@ TEST_F(MslGeneratorImplTest,
ast::StorageClass::kFunction, &f32)); ast::StorageClass::kFunction, &f32));
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::MemberAccessorExpression>( Source{}, create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("b")))); create<ast::IdentifierExpression>("b"))));
auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32, auto* sub_func = create<ast::Function>(Source{}, "sub_func", params, &f32,
@ -891,7 +891,7 @@ TEST_F(MslGeneratorImplTest,
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, "frag_main", params, &void_type, body, Source{}, "frag_main", params, &void_type, body,
@ -946,7 +946,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::FloatLiteral>(&f32, 1.0f)))); create<ast::FloatLiteral>(&f32, 1.0f))));
auto* list = create<ast::BlockStatement>(); auto* list = create<ast::BlockStatement>();
list->append(create<ast::ReturnStatement>()); list->append(create<ast::ReturnStatement>(Source{}));
body->append(create<ast::IfStatement>( body->append(create<ast::IfStatement>(
Source{}, Source{},
@ -957,7 +957,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::SintLiteral>(&i32, 1))), create<ast::SintLiteral>(&i32, 1))),
list, ast::ElseStatementList{})); list, ast::ElseStatementList{}));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, "ep_1", params, &void_type, body, Source{}, "ep_1", params, &void_type, body,
@ -1020,7 +1020,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, "my_func", params, &void_type, auto* func = create<ast::Function>(Source{}, "my_func", params, &void_type,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -1095,7 +1095,7 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = auto* func =
create<ast::Function>(Source{}, "a", params, &void_type, body, create<ast::Function>(Source{}, "a", params, &void_type, body,
@ -1117,7 +1117,7 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = auto* func =
create<ast::Function>(Source{}, "b", params, &void_type, body, create<ast::Function>(Source{}, "b", params, &void_type, body,

View File

@ -31,7 +31,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_If) { TEST_F(MslGeneratorImplTest, Emit_If) {
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{}); ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
@ -47,11 +47,11 @@ TEST_F(MslGeneratorImplTest, Emit_If) {
TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) { TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
auto* else_cond = create<ast::IdentifierExpression>("else_cond"); auto* else_cond = create<ast::IdentifierExpression>("else_cond");
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>(Source{}));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::IfStatement i(Source{}, cond, body, ast::IfStatement i(Source{}, cond, body,
{create<ast::ElseStatement>(else_cond, else_body)}); {create<ast::ElseStatement>(else_cond, else_body)});
@ -69,11 +69,11 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
TEST_F(MslGeneratorImplTest, Emit_IfWithElse) { TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>(Source{}));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::IfStatement i(Source{}, cond, body, ast::IfStatement i(Source{}, cond, body,
{create<ast::ElseStatement>(else_body)}); {create<ast::ElseStatement>(else_body)});
@ -93,14 +93,14 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
auto* else_cond = create<ast::IdentifierExpression>("else_cond"); auto* else_cond = create<ast::IdentifierExpression>("else_cond");
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>(Source{}));
auto* else_body_2 = create<ast::BlockStatement>(); auto* else_body_2 = create<ast::BlockStatement>();
else_body_2->append(create<ast::ReturnStatement>()); else_body_2->append(create<ast::ReturnStatement>(Source{}));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::IfStatement i(Source{}, cond, body, ast::IfStatement i(Source{}, cond, body,
{ {

View File

@ -55,7 +55,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
auto* continuing = create<ast::BlockStatement>(); auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::ReturnStatement>()); continuing->append(create<ast::ReturnStatement>(Source{}));
ast::LoopStatement l(body, continuing); ast::LoopStatement l(body, continuing);
@ -83,7 +83,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
auto* continuing = create<ast::BlockStatement>(); auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::ReturnStatement>()); continuing->append(create<ast::ReturnStatement>(Source{}));
auto* inner = create<ast::LoopStatement>(body, continuing); auto* inner = create<ast::LoopStatement>(body, continuing);

View File

@ -30,7 +30,7 @@ namespace {
using MslGeneratorImplTest = TestHelper; using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Return) { TEST_F(MslGeneratorImplTest, Emit_Return) {
ast::ReturnStatement r; ast::ReturnStatement r(Source{});
gen.increment_indent(); gen.increment_indent();
@ -40,7 +40,7 @@ TEST_F(MslGeneratorImplTest, Emit_Return) {
TEST_F(MslGeneratorImplTest, Emit_ReturnWithValue) { TEST_F(MslGeneratorImplTest, Emit_ReturnWithValue) {
auto* expr = create<ast::IdentifierExpression>("expr"); auto* expr = create<ast::IdentifierExpression>("expr");
ast::ReturnStatement r(expr); ast::ReturnStatement r(Source{}, expr);
gen.increment_indent(); gen.increment_indent();

View File

@ -49,7 +49,8 @@ TEST_F(BuilderTest, Expression_Call) {
create<ast::Variable>(Source{}, "b", ast::StorageClass::kFunction, &f32)); create<ast::Variable>(Source{}, "b", ast::StorageClass::kFunction, &f32));
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(create<ast::BinaryExpression>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::BinaryExpression>(
ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("a"), ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("a"),
create<ast::IdentifierExpression>("b")))); create<ast::IdentifierExpression>("b"))));
ast::Function a_func(Source{}, "a_func", func_params, &f32, body, ast::Function a_func(Source{}, "a_func", func_params, &f32, body,
@ -113,7 +114,8 @@ TEST_F(BuilderTest, Statement_Call) {
create<ast::Variable>(Source{}, "b", ast::StorageClass::kFunction, &f32)); create<ast::Variable>(Source{}, "b", ast::StorageClass::kFunction, &f32));
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(create<ast::BinaryExpression>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::BinaryExpression>(
ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("a"), ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("a"),
create<ast::IdentifierExpression>("b")))); create<ast::IdentifierExpression>("b"))));

View File

@ -67,7 +67,7 @@ TEST_F(BuilderTest, Function_Terminator_Return) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::Function func(Source{}, "a_func", {}, &void_type, body, ast::Function func(Source{}, "a_func", {}, &void_type, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -92,8 +92,8 @@ TEST_F(BuilderTest, Function_Terminator_ReturnValue) {
td.RegisterVariableForTesting(var_a); td.RegisterVariableForTesting(var_a);
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("a"))); Source{}, create<ast::IdentifierExpression>("a")));
ASSERT_TRUE(td.DetermineResultType(body)) << td.error(); ASSERT_TRUE(td.DetermineResultType(body)) << td.error();
ast::Function func(Source{}, "a_func", {}, &void_type, body, ast::Function func(Source{}, "a_func", {}, &void_type, body,
@ -153,8 +153,8 @@ TEST_F(BuilderTest, Function_WithParams) {
params.push_back(var_b); params.push_back(var_b);
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::ReturnStatement>(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("a"))); Source{}, create<ast::IdentifierExpression>("a")));
ast::Function func(Source{}, "a_func", params, &f32, body, ast::Function func(Source{}, "a_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -182,7 +182,7 @@ TEST_F(BuilderTest, Function_WithBody) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::Function func(Source{}, "a_func", {}, &void_type, body, ast::Function func(Source{}, "a_func", {}, &void_type, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -282,7 +282,7 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = auto* func =
create<ast::Function>(Source{}, "a", params, &void_type, body, create<ast::Function>(Source{}, "a", params, &void_type, body,
@ -304,7 +304,7 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = auto* func =
create<ast::Function>(Source{}, "b", params, &void_type, body, create<ast::Function>(Source{}, "b", params, &void_type, body,

View File

@ -549,7 +549,7 @@ TEST_F(BuilderTest, If_WithReturn) {
create<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
auto* if_body = create<ast::BlockStatement>(); auto* if_body = create<ast::BlockStatement>();
if_body->append(create<ast::ReturnStatement>()); if_body->append(create<ast::ReturnStatement>(Source{}));
ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{}); ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{});
@ -581,7 +581,7 @@ TEST_F(BuilderTest, If_WithReturnValue) {
create<ast::BoolLiteral>(&bool_type, false)); create<ast::BoolLiteral>(&bool_type, false));
auto* if_body = create<ast::BlockStatement>(); auto* if_body = create<ast::BlockStatement>();
if_body->append(create<ast::ReturnStatement>(cond2)); if_body->append(create<ast::ReturnStatement>(Source{}, cond2));
ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{}); ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{});

View File

@ -35,7 +35,7 @@ namespace {
using BuilderTest = TestHelper; using BuilderTest = TestHelper;
TEST_F(BuilderTest, Return) { TEST_F(BuilderTest, Return) {
ast::ReturnStatement ret; ast::ReturnStatement ret(Source{});
b.push_function(Function{}); b.push_function(Function{});
EXPECT_TRUE(b.GenerateReturnStatement(&ret)); EXPECT_TRUE(b.GenerateReturnStatement(&ret));
@ -59,7 +59,7 @@ TEST_F(BuilderTest, Return_WithValue) {
auto* val = create<ast::TypeConstructorExpression>(&vec, vals); auto* val = create<ast::TypeConstructorExpression>(&vec, vals);
ast::ReturnStatement ret(val); ast::ReturnStatement ret(Source{}, val);
EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error(); EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error();
@ -83,7 +83,8 @@ TEST_F(BuilderTest, Return_WithValue_GeneratesLoad) {
ast::Variable var(Source{}, "param", ast::StorageClass::kFunction, &f32); ast::Variable var(Source{}, "param", ast::StorageClass::kFunction, &f32);
ast::ReturnStatement ret(create<ast::IdentifierExpression>("param")); ast::ReturnStatement ret(Source{},
create<ast::IdentifierExpression>("param"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error(); EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error();

View File

@ -44,7 +44,7 @@ using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Function) { TEST_F(WgslGeneratorImplTest, Emit_Function) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::type::Void void_type; ast::type::Void void_type;
ast::Function func(Source{}, "my_func", {}, &void_type, body, ast::Function func(Source{}, "my_func", {}, &void_type, body,
@ -63,7 +63,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function) {
TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) { TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::type::F32 f32; ast::type::F32 f32;
ast::type::I32 i32; ast::type::I32 i32;
@ -90,7 +90,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) {
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) { TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::type::Void void_type; ast::type::Void void_type;
ast::Function func(Source{}, "my_func", {}, &void_type, body, ast::Function func(Source{}, "my_func", {}, &void_type, body,
@ -112,7 +112,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) {
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) { TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::type::Void void_type; ast::type::Void void_type;
ast::Function func( ast::Function func(
@ -135,7 +135,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) {
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) { TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
ast::type::Void void_type; ast::type::Void void_type;
ast::Function func( ast::Function func(
@ -214,7 +214,7 @@ TEST_F(WgslGeneratorImplTest,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = auto* func =
create<ast::Function>(Source{}, "a", params, &void_type, body, create<ast::Function>(Source{}, "a", params, &void_type, body,
@ -236,7 +236,7 @@ TEST_F(WgslGeneratorImplTest,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = auto* func =
create<ast::Function>(Source{}, "b", params, &void_type, body, create<ast::Function>(Source{}, "b", params, &void_type, body,

View File

@ -29,7 +29,7 @@ namespace {
using WgslGeneratorImplTest = TestHelper; using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Return) { TEST_F(WgslGeneratorImplTest, Emit_Return) {
ast::ReturnStatement r; ast::ReturnStatement r(Source{});
gen.increment_indent(); gen.increment_indent();
@ -39,7 +39,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Return) {
TEST_F(WgslGeneratorImplTest, Emit_ReturnWithValue) { TEST_F(WgslGeneratorImplTest, Emit_ReturnWithValue) {
auto* expr = create<ast::IdentifierExpression>("expr"); auto* expr = create<ast::IdentifierExpression>("expr");
ast::ReturnStatement r(expr); ast::ReturnStatement r(Source{}, expr);
gen.increment_indent(); gen.increment_indent();