tests: Use ProgramBuilder helpers where we can

A general code cleanup

Change-Id: Ib251ca2d4b71f75736bdba8b4255965593a76c31
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48680
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton
2021-04-22 13:50:53 +00:00
committed by Commit Bot service account
parent 261642e4e3
commit 43073d8aa3
61 changed files with 1050 additions and 1371 deletions

View File

@@ -35,7 +35,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignIncompatibleTypes) {
auto* lhs = Expr("a");
auto* rhs = Expr(2.3f);
auto* assign = create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs);
auto* assign = Assign(Source{{12, 34}}, lhs, rhs);
WrapInFunction(var, assign);
ASSERT_FALSE(r()->Resolve());
@@ -57,7 +57,7 @@ TEST_F(ResolverAssignmentValidationTest,
auto* lhs = Expr("a");
auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs);
auto* assign = Assign(Source{{12, 34}}, lhs, rhs);
WrapInFunction(var_a, var_b, assign);
ASSERT_FALSE(r()->Resolve());
@@ -77,10 +77,7 @@ TEST_F(ResolverAssignmentValidationTest,
auto* lhs = Expr("a");
auto* rhs = Expr(2);
auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs),
});
auto* body = Block(Decl(var), Assign(Source{{12, 34}}, lhs, rhs));
WrapInFunction(body);
ASSERT_TRUE(r()->Resolve()) << r()->error();
@@ -97,10 +94,7 @@ TEST_F(ResolverAssignmentValidationTest,
auto* lhs = Expr("a");
auto* rhs = Expr(2.3f);
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs),
});
auto* block = Block(Decl(var), Assign(Source{{12, 34}}, lhs, rhs));
WrapInFunction(block);
ASSERT_FALSE(r()->Resolve());
@@ -123,14 +117,9 @@ TEST_F(ResolverAssignmentValidationTest,
auto* lhs = Expr("a");
auto* rhs = Expr(2.3f);
auto* inner_block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs),
});
auto* inner_block = Block(Decl(var), Assign(Source{{12, 34}}, lhs, rhs));
auto* outer_block = create<ast::BlockStatement>(ast::StatementList{
inner_block,
});
auto* outer_block = Block(inner_block);
WrapInFunction(outer_block);
@@ -149,7 +138,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignToScalar_Fail) {
auto* lhs = Expr(1);
auto* rhs = Expr("my_var");
auto* assign = create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs);
auto* assign = Assign(Source{{12, 34}}, lhs, rhs);
WrapInFunction(Decl(var), assign);
EXPECT_FALSE(r()->Resolve());
@@ -166,8 +155,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignCompatibleTypes_Pass) {
auto* lhs = Expr("a");
auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs);
auto* assign = Assign(Source{Source::Location{12, 34}}, lhs, rhs);
WrapInFunction(Decl(var), assign);
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -184,8 +172,7 @@ TEST_F(ResolverAssignmentValidationTest,
auto* lhs = Expr("a");
auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs);
auto* assign = Assign(Source{Source::Location{12, 34}}, lhs, rhs);
WrapInFunction(Decl(var), assign);
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -202,8 +189,7 @@ TEST_F(ResolverAssignmentValidationTest,
auto* lhs = Expr("a");
auto* rhs = Expr("b");
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs);
auto* assign = Assign(Source{Source::Location{12, 34}}, lhs, rhs);
WrapInFunction(Decl(var_a), Decl(var_b), assign);
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -220,8 +206,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignThroughPointer_Pass) {
auto* lhs = Expr("b");
auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs);
auto* assign = Assign(Source{Source::Location{12, 34}}, lhs, rhs);
WrapInFunction(Decl(var_a), Decl(var_b), assign);
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -237,11 +222,8 @@ TEST_F(ResolverAssignmentValidationTest, AssignToConstant_Fail) {
auto* lhs = Expr("a");
auto* rhs = Expr(2);
auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
rhs),
});
auto* body =
Block(Decl(var), Assign(Source{Source::Location{12, 34}}, lhs, rhs));
WrapInFunction(body);
@@ -267,7 +249,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignFromPointer_Fail) {
auto* lhs = Expr("a");
auto* rhs = Expr("b");
auto* assign = create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs);
auto* assign = Assign(Source{{12, 34}}, lhs, rhs);
WrapInFunction(Decl(var_a), Decl(var_b), assign);
EXPECT_FALSE(r()->Resolve());

View File

@@ -31,15 +31,13 @@ TEST_F(ResolverControlBlockValidationTest,
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.14f));
ast::CaseStatementList body;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
auto* block_default = Block();
body.push_back(
create<ast::CaseStatement>(ast::CaseSelectorList{}, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr(Source{Source::Location{12, 34}}, "a"),
body),
});
auto* block =
Block(Decl(var), create<ast::SwitchStatement>(
Expr(Source{Source::Location{12, 34}}, "a"), body));
WrapInFunction(block);
@@ -60,14 +58,11 @@ TEST_F(ResolverControlBlockValidationTest, SwitchWithoutDefault_Fail) {
csl.push_back(Literal(1));
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(
csl, create<ast::BlockStatement>(ast::StatementList{})));
body.push_back(create<ast::CaseStatement>(csl, Block()));
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Source{Source::Location{12, 34}}, Expr("a"),
body),
});
auto* block =
Block(Decl(var), create<ast::SwitchStatement>(
Source{Source::Location{12, 34}}, Expr("a"), body));
WrapInFunction(block);
@@ -87,24 +82,22 @@ TEST_F(ResolverControlBlockValidationTest, SwitchWithTwoDefault_Fail) {
ast::CaseStatementList switch_body;
ast::CaseSelectorList default_csl_1;
auto* block_default_1 = create<ast::BlockStatement>(ast::StatementList{});
auto* block_default_1 = Block();
switch_body.push_back(
create<ast::CaseStatement>(default_csl_1, block_default_1));
ast::CaseSelectorList csl_case_1;
csl_case_1.push_back(Literal(1));
auto* block_case_1 = create<ast::BlockStatement>(ast::StatementList{});
auto* block_case_1 = Block();
switch_body.push_back(create<ast::CaseStatement>(csl_case_1, block_case_1));
ast::CaseSelectorList default_csl_2;
auto* block_default_2 = create<ast::BlockStatement>(ast::StatementList{});
auto* block_default_2 = Block();
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, default_csl_2, block_default_2));
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
auto* block =
Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
WrapInFunction(block);
@@ -128,17 +121,14 @@ TEST_F(ResolverControlBlockValidationTest,
ast::CaseSelectorList csl;
csl.push_back(create<ast::UintLiteral>(ty.u32(), 1));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, csl,
create<ast::BlockStatement>(ast::StatementList{})));
Source{Source::Location{12, 34}}, csl, Block()));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
auto* block_default = Block();
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
auto* block =
Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
WrapInFunction(block);
EXPECT_FALSE(r()->Resolve());
@@ -160,17 +150,14 @@ TEST_F(ResolverControlBlockValidationTest,
ast::CaseSelectorList csl;
csl.push_back(Literal(-1));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, csl,
create<ast::BlockStatement>(ast::StatementList{})));
Source{Source::Location{12, 34}}, csl, Block()));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
auto* block_default = Block();
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
auto* block =
Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
WrapInFunction(block);
EXPECT_FALSE(r()->Resolve());
@@ -192,24 +179,20 @@ TEST_F(ResolverControlBlockValidationTest,
ast::CaseStatementList switch_body;
ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::UintLiteral>(ty.u32(), 0));
switch_body.push_back(create<ast::CaseStatement>(
csl_1, create<ast::BlockStatement>(ast::StatementList{})));
switch_body.push_back(create<ast::CaseStatement>(csl_1, Block()));
ast::CaseSelectorList csl_2;
csl_2.push_back(create<ast::UintLiteral>(ty.u32(), 2));
csl_2.push_back(create<ast::UintLiteral>(ty.u32(), 2));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, csl_2,
create<ast::BlockStatement>(ast::StatementList{})));
Source{Source::Location{12, 34}}, csl_2, Block()));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
auto* block_default = Block();
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
auto* block =
Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
WrapInFunction(block);
EXPECT_FALSE(r()->Resolve());
@@ -231,8 +214,7 @@ TEST_F(ResolverControlBlockValidationTest,
ast::CaseStatementList switch_body;
ast::CaseSelectorList csl_1;
csl_1.push_back(Literal(10));
switch_body.push_back(create<ast::CaseStatement>(
csl_1, create<ast::BlockStatement>(ast::StatementList{})));
switch_body.push_back(create<ast::CaseStatement>(csl_1, Block()));
ast::CaseSelectorList csl_2;
csl_2.push_back(Literal(0));
@@ -240,17 +222,14 @@ TEST_F(ResolverControlBlockValidationTest,
csl_2.push_back(Literal(2));
csl_2.push_back(Literal(10));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, csl_2,
create<ast::BlockStatement>(ast::StatementList{})));
Source{Source::Location{12, 34}}, csl_2, Block()));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
auto* block_default = Block();
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
auto* block =
Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
WrapInFunction(block);
EXPECT_FALSE(r()->Resolve());
@@ -269,18 +248,12 @@ TEST_F(ResolverControlBlockValidationTest,
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(
ast::StatementList{
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}),
});
auto* block_default = Block(
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}));
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), body),
});
auto* block = Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), body));
WrapInFunction(block);
EXPECT_FALSE(r()->Resolve());
@@ -299,19 +272,16 @@ TEST_F(ResolverControlBlockValidationTest, SwitchCase_Pass) {
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
auto* block_default = Block();
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
default_csl, block_default));
ast::CaseSelectorList case_csl;
case_csl.push_back(Literal(5));
auto* block_case = create<ast::BlockStatement>(ast::StatementList{});
auto* block_case = Block();
body.push_back(create<ast::CaseStatement>(case_csl, block_case));
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), body),
});
auto* block = Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), body));
WrapInFunction(block);
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -328,15 +298,12 @@ TEST_F(ResolverControlBlockValidationTest, SwitchCaseAlias_Pass) {
auto* var = Var("a", my_int, ast::StorageClass::kNone, Expr(2u));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
auto* block_default = Block();
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
default_csl, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), body),
});
auto* block = Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), body));
AST().AddConstructedType(my_int);
WrapInFunction(block);

View File

@@ -62,21 +62,19 @@ static ast::Decoration* createDecoration(const Source& source,
case DecorationKind::kBinding:
return builder.create<ast::BindingDecoration>(source, 1);
case DecorationKind::kBuiltin:
return builder.create<ast::BuiltinDecoration>(source,
ast::Builtin::kPosition);
return builder.Builtin(source, ast::Builtin::kPosition);
case DecorationKind::kConstantId:
return builder.create<ast::ConstantIdDecoration>(source, 0u);
case DecorationKind::kGroup:
return builder.create<ast::GroupDecoration>(source, 1u);
case DecorationKind::kLocation:
return builder.create<ast::LocationDecoration>(source, 1);
return builder.Location(source, 1);
case DecorationKind::kOffset:
return builder.create<ast::StructMemberOffsetDecoration>(source, 4u);
case DecorationKind::kSize:
return builder.create<ast::StructMemberSizeDecoration>(source, 4u);
case DecorationKind::kStage:
return builder.create<ast::StageDecoration>(source,
ast::PipelineStage::kCompute);
return builder.Stage(source, ast::PipelineStage::kCompute);
case DecorationKind::kStride:
return builder.create<ast::StrideDecoration>(source, 4u);
case DecorationKind::kStructBlock:
@@ -91,10 +89,8 @@ using FunctionReturnTypeDecorationTest = TestWithParams;
TEST_P(FunctionReturnTypeDecorationTest, IsValid) {
auto& params = GetParam();
Func("main", ast::VariableList{}, ty.f32(),
ast::StatementList{create<ast::ReturnStatement>(Expr(1.f))},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute)},
Func("main", ast::VariableList{}, ty.f32(), ast::StatementList{Return(1.f)},
ast::DecorationList{Stage(ast::PipelineStage::kCompute)},
ast::DecorationList{createDecoration({}, *this, params.kind)});
if (params.should_pass) {
@@ -126,15 +122,16 @@ using ArrayDecorationTest = TestWithParams;
TEST_P(ArrayDecorationTest, IsValid) {
auto& params = GetParam();
ast::StructMemberList members{Member(
"a", create<sem::ArrayType>(ty.f32(), 0,
ast::DecorationList{createDecoration(
Source{{12, 34}}, *this, params.kind)}))};
auto* s = create<ast::Struct>(
Sym("mystruct"), members,
ast::DecorationList{create<ast::StructBlockDecoration>()});
auto* s_ty = ty.struct_(s);
AST().AddConstructedType(s_ty);
auto* arr = create<sem::ArrayType>(
ty.f32(), 0,
ast::DecorationList{
createDecoration(Source{{12, 34}}, *this, params.kind),
});
Structure("mystruct",
{
Member("a", arr),
},
{create<ast::StructBlockDecoration>()});
WrapInFunction();
@@ -167,11 +164,8 @@ using StructDecorationTest = TestWithParams;
TEST_P(StructDecorationTest, IsValid) {
auto& params = GetParam();
auto* s = create<ast::Struct>(Sym("mystruct"), ast::StructMemberList{},
ast::DecorationList{createDecoration(
Source{{12, 34}}, *this, params.kind)});
auto* s_ty = ty.struct_(s);
AST().AddConstructedType(s_ty);
Structure("mystruct", {},
{createDecoration(Source{{12, 34}}, *this, params.kind)});
WrapInFunction();
@@ -208,10 +202,8 @@ TEST_P(StructMemberDecorationTest, IsValid) {
Member("a", ty.i32(),
ast::DecorationList{
createDecoration(Source{{12, 34}}, *this, params.kind)})};
auto* s =
create<ast::Struct>(Sym("mystruct"), members, ast::DecorationList{});
auto* s_ty = ty.struct_(s);
AST().AddConstructedType(s_ty);
Structure("mystruct", members);
WrapInFunction();
@@ -281,7 +273,7 @@ TEST_P(FunctionDecorationTest, IsValid) {
Func("foo", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
Stage(ast::PipelineStage::kCompute),
createDecoration(Source{{12, 34}}, *this, params.kind)});
if (params.should_pass) {

View File

@@ -31,7 +31,7 @@ class ResolverEntryPointValidationTest : public resolver::TestHelper,
TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Location) {
// [[stage(vertex)]]
// fn main() -> [[location(0)]] f32 { return 1.0; }
Func(Source{{12, 34}}, "main", {}, ty.f32(), {Return(Expr(1.0f))},
Func(Source{{12, 34}}, "main", {}, ty.f32(), {Return(1.0f)},
{Stage(ast::PipelineStage::kFragment)}, {Location(0)});
EXPECT_TRUE(r()->Resolve()) << r()->error();

View File

@@ -30,13 +30,13 @@ TEST_F(ResolverFunctionValidationTest, FunctionNamesMustBeUnique_fail) {
// fn func -> i32 { return 2; }
Func("func", ast::VariableList{}, ty.i32(),
ast::StatementList{
create<ast::ReturnStatement>(Expr(2)),
Return(2),
},
ast::DecorationList{});
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
ast::StatementList{
create<ast::ReturnStatement>(Expr(2)),
Return(2),
},
ast::DecorationList{});
@@ -53,7 +53,7 @@ TEST_F(ResolverFunctionValidationTest,
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
Decl(var),
});
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -66,7 +66,7 @@ TEST_F(ResolverFunctionValidationTest, FunctionEndWithoutReturnStatement_Fail) {
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
Decl(var),
},
ast::DecorationList{});
@@ -105,7 +105,7 @@ TEST_F(ResolverFunctionValidationTest,
Func("func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
Return(),
});
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -116,8 +116,7 @@ TEST_F(ResolverFunctionValidationTest,
// fn func { return 2; }
Func("func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
Expr(2)),
Return(Source{Source::Location{12, 34}}, Expr(2)),
},
ast::DecorationList{});
@@ -132,8 +131,7 @@ TEST_F(ResolverFunctionValidationTest,
// fn func -> f32 { return 2.0; }
Func("func", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
Expr(2.f)),
Return(Source{Source::Location{12, 34}}, Expr(2.f)),
},
ast::DecorationList{});
@@ -145,8 +143,7 @@ TEST_F(ResolverFunctionValidationTest,
// fn func -> f32 { return 2; }
Func("func", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
Expr(2)),
Return(Source{Source::Location{12, 34}}, Expr(2)),
},
ast::DecorationList{});
@@ -163,8 +160,7 @@ TEST_F(ResolverFunctionValidationTest,
auto* myf32 = ty.alias("myf32", ty.f32());
Func("func", ast::VariableList{}, myf32,
ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
Expr(2.f)),
Return(Source{Source::Location{12, 34}}, Expr(2.f)),
},
ast::DecorationList{});
@@ -178,8 +174,7 @@ TEST_F(ResolverFunctionValidationTest,
auto* myf32 = ty.alias("myf32", ty.f32());
Func("func", ast::VariableList{}, myf32,
ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
Expr(2u)),
Return(Source{Source::Location{12, 34}}, Expr(2u)),
},
ast::DecorationList{});
@@ -196,11 +191,11 @@ TEST_F(ResolverFunctionValidationTest, PipelineStage_MustBeUnique_Fail) {
Func(Source{Source::Location{12, 34}}, "main", ast::VariableList{},
ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
Return(),
},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
Stage(ast::PipelineStage::kVertex),
Stage(ast::PipelineStage::kFragment),
});
EXPECT_FALSE(r()->Resolve());
@@ -212,7 +207,7 @@ TEST_F(ResolverFunctionValidationTest, PipelineStage_MustBeUnique_Fail) {
TEST_F(ResolverFunctionValidationTest, NoPipelineEntryPoints) {
Func("vtx_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
Return(),
},
ast::DecorationList{});

View File

@@ -59,7 +59,7 @@ TEST_F(ResolverTest, Stmt_Assign) {
auto* lhs = Expr("v");
auto* rhs = Expr(2.3f);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
auto* assign = Assign(lhs, rhs);
WrapInFunction(v, assign);
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -78,7 +78,7 @@ TEST_F(ResolverTest, Stmt_Case) {
auto* lhs = Expr("v");
auto* rhs = Expr(2.3f);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
auto* assign = Assign(lhs, rhs);
auto* block = Block(assign);
ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(ty.i32(), 3));
@@ -101,7 +101,7 @@ TEST_F(ResolverTest, Stmt_Block) {
auto* lhs = Expr("v");
auto* rhs = Expr(2.3f);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
auto* assign = Assign(lhs, rhs);
auto* block = Block(assign);
WrapInFunction(v, block);
@@ -123,7 +123,7 @@ TEST_F(ResolverTest, Stmt_If) {
auto* else_lhs = Expr("v");
auto* else_rhs = Expr(2.3f);
auto* else_body = Block(create<ast::AssignmentStatement>(else_lhs, else_rhs));
auto* else_body = Block(Assign(else_lhs, else_rhs));
auto* else_cond = Expr(3);
auto* else_stmt = create<ast::ElseStatement>(else_cond, else_body);
@@ -131,7 +131,7 @@ TEST_F(ResolverTest, Stmt_If) {
auto* lhs = Expr("v");
auto* rhs = Expr(2.3f);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
auto* assign = Assign(lhs, rhs);
auto* body = Block(assign);
auto* cond = Expr(true);
auto* stmt =
@@ -165,14 +165,12 @@ TEST_F(ResolverTest, Stmt_Loop) {
auto* body_lhs = Expr("v");
auto* body_rhs = Expr(2.3f);
auto* body = Block(create<ast::AssignmentStatement>(body_lhs, body_rhs));
auto* body = Block(Assign(body_lhs, body_rhs));
auto* continuing_lhs = Expr("v");
auto* continuing_rhs = Expr(2.3f);
auto* continuing = create<ast::BlockStatement>(ast::StatementList{
create<ast::AssignmentStatement>(continuing_lhs, continuing_rhs),
});
auto* stmt = create<ast::LoopStatement>(body, continuing);
auto* continuing = Block(Assign(continuing_lhs, continuing_rhs));
auto* stmt = Loop(body, continuing);
WrapInFunction(v, stmt);
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -194,7 +192,7 @@ TEST_F(ResolverTest, Stmt_Loop) {
TEST_F(ResolverTest, Stmt_Return) {
auto* cond = Expr(2);
auto* ret = create<ast::ReturnStatement>(cond);
auto* ret = Return(cond);
Func("test", {}, ty.i32(), {ret}, {});
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -204,7 +202,7 @@ TEST_F(ResolverTest, Stmt_Return) {
}
TEST_F(ResolverTest, Stmt_Return_WithoutValue) {
auto* ret = create<ast::ReturnStatement>();
auto* ret = Return();
WrapInFunction(ret);
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -233,7 +231,7 @@ TEST_F(ResolverTest, Stmt_Switch) {
TEST_F(ResolverTest, Stmt_Call) {
ast::VariableList params;
Func("my_func", params, ty.f32(), ast::StatementList{Return(Expr(0.0f))},
Func("my_func", params, ty.f32(), ast::StatementList{Return(0.0f)},
ast::DecorationList{});
auto* expr = Call("my_func");
@@ -252,7 +250,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl) {
auto* var = Var("my_var", ty.i32(), ast::StorageClass::kNone, Expr(2));
auto* init = var->constructor();
auto* decl = create<ast::VariableDeclStatement>(var);
auto* decl = Decl(var);
WrapInFunction(decl);
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -266,7 +264,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_Alias) {
auto* var = Var("my_var", my_int, ast::StorageClass::kNone, Expr(2));
auto* init = var->constructor();
auto* decl = create<ast::VariableDeclStatement>(var);
auto* decl = Decl(var);
WrapInFunction(decl);
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -301,25 +299,24 @@ TEST_F(ResolverTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) {
// Declare i32 "foo" inside a block
auto* foo_i32 = Var("foo", ty.i32(), ast::StorageClass::kNone, Expr(2));
auto* foo_i32_init = foo_i32->constructor();
auto* foo_i32_decl = create<ast::VariableDeclStatement>(foo_i32);
auto* foo_i32_decl = Decl(foo_i32);
// Reference "foo" inside the block
auto* bar_i32 = Var("bar", ty.i32(), ast::StorageClass::kNone, Expr("foo"));
auto* bar_i32_init = bar_i32->constructor();
auto* bar_i32_decl = create<ast::VariableDeclStatement>(bar_i32);
auto* bar_i32_decl = Decl(bar_i32);
auto* inner = create<ast::BlockStatement>(
ast::StatementList{foo_i32_decl, bar_i32_decl});
auto* inner = Block(foo_i32_decl, bar_i32_decl);
// Declare f32 "foo" at function scope
auto* foo_f32 = Var("foo", ty.f32(), ast::StorageClass::kNone, Expr(2.f));
auto* foo_f32_init = foo_f32->constructor();
auto* foo_f32_decl = create<ast::VariableDeclStatement>(foo_f32);
auto* foo_f32_decl = Decl(foo_f32);
// Reference "foo" at function scope
auto* bar_f32 = Var("bar", ty.f32(), ast::StorageClass::kNone, Expr("foo"));
auto* bar_f32_init = bar_f32->constructor();
auto* bar_f32_decl = create<ast::VariableDeclStatement>(bar_f32);
auto* bar_f32_decl = Decl(bar_f32);
Func("func", params, ty.void_(),
ast::StatementList{inner, foo_f32_decl, bar_f32_decl},
@@ -360,7 +357,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) {
// Declare i32 "foo" inside a function
auto* fn_i32 = Var("foo", ty.i32(), ast::StorageClass::kFunction, Expr(2));
auto* fn_i32_init = fn_i32->constructor();
auto* fn_i32_decl = create<ast::VariableDeclStatement>(fn_i32);
auto* fn_i32_decl = Decl(fn_i32);
Func("func_i32", params, ty.void_(), ast::StatementList{fn_i32_decl},
ast::DecorationList{});
@@ -373,7 +370,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) {
auto* fn_f32 =
Var("bar", ty.f32(), ast::StorageClass::kFunction, Expr("foo"));
auto* fn_f32_init = fn_f32->constructor();
auto* fn_f32_decl = create<ast::VariableDeclStatement>(fn_f32);
auto* fn_f32_decl = Decl(fn_f32);
Func("func_f32", params, ty.void_(), ast::StatementList{fn_f32_decl},
ast::DecorationList{});
@@ -498,7 +495,7 @@ TEST_F(ResolverTest, Expr_Bitcast) {
TEST_F(ResolverTest, Expr_Call) {
ast::VariableList params;
Func("my_func", params, ty.f32(), ast::StatementList{Return(Expr(0.0f))},
Func("my_func", params, ty.f32(), ast::StatementList{Return(0.0f)},
ast::DecorationList{});
auto* call = Call("my_func");
@@ -512,7 +509,7 @@ TEST_F(ResolverTest, Expr_Call) {
TEST_F(ResolverTest, Expr_Call_InBinaryOp) {
ast::VariableList params;
Func("func", params, ty.f32(), ast::StatementList{Return(Expr(0.0f))},
Func("func", params, ty.f32(), ast::StatementList{Return(0.0f)},
ast::DecorationList{});
auto* expr = Add(Call("func"), Call("func"));
@@ -646,7 +643,7 @@ TEST_F(ResolverTest, Expr_Identifier_FunctionVariable_Const) {
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
Decl(var),
decl,
},
ast::DecorationList{});
@@ -664,13 +661,13 @@ TEST_F(ResolverTest, Expr_Identifier_FunctionVariable_Const) {
TEST_F(ResolverTest, Expr_Identifier_FunctionVariable) {
auto* my_var_a = Expr("my_var");
auto* my_var_b = Expr("my_var");
auto* assign = create<ast::AssignmentStatement>(my_var_a, my_var_b);
auto* assign = Assign(my_var_a, my_var_b);
auto* var = Var("my_var", ty.f32(), ast::StorageClass::kNone);
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
Decl(var),
assign,
},
ast::DecorationList{});
@@ -695,13 +692,12 @@ TEST_F(ResolverTest, Expr_Identifier_FunctionVariable) {
TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {
auto* my_var_a = Expr("my_var");
auto* my_var_b = Expr("my_var");
auto* assign = create<ast::AssignmentStatement>(my_var_a, my_var_b);
auto* assign = Assign(my_var_a, my_var_b);
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(
Var("my_var", ty.pointer<f32>(ast::StorageClass::kFunction),
ast::StorageClass::kNone)),
Decl(Var("my_var", ty.pointer<f32>(ast::StorageClass::kFunction),
ast::StorageClass::kNone)),
assign,
},
ast::DecorationList{});
@@ -720,7 +716,7 @@ TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {
TEST_F(ResolverTest, Expr_Call_Function) {
Func("my_func", ast::VariableList{}, ty.f32(),
ast::StatementList{Return(Expr(0.0f))}, ast::DecorationList{});
ast::StatementList{Return(0.0f)}, ast::DecorationList{});
auto* call = Call("my_func");
WrapInFunction(call);
@@ -775,15 +771,14 @@ TEST_F(ResolverTest, Function_RegisterInputOutputVariables) {
auto* wg_var = Global("wg_var", ty.f32(), ast::StorageClass::kWorkgroup);
auto* priv_var = Global("priv_var", ty.f32(), ast::StorageClass::kPrivate);
auto* func = Func(
"my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("out_var"), Expr("in_var")),
create<ast::AssignmentStatement>(Expr("wg_var"), Expr("wg_var")),
create<ast::AssignmentStatement>(Expr("sb_var"), Expr("sb_var")),
create<ast::AssignmentStatement>(Expr("priv_var"), Expr("priv_var")),
},
ast::DecorationList{});
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
Assign("out_var", "in_var"),
Assign("wg_var", "wg_var"),
Assign("sb_var", "sb_var"),
Assign("priv_var", "priv_var"),
},
ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -811,22 +806,19 @@ TEST_F(ResolverTest, Function_RegisterInputOutputVariables_SubFunction) {
auto* wg_var = Global("wg_var", ty.f32(), ast::StorageClass::kWorkgroup);
auto* priv_var = Global("priv_var", ty.f32(), ast::StorageClass::kPrivate);
Func("my_func", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("out_var"), Expr("in_var")),
create<ast::AssignmentStatement>(Expr("wg_var"), Expr("wg_var")),
create<ast::AssignmentStatement>(Expr("sb_var"), Expr("sb_var")),
create<ast::AssignmentStatement>(Expr("priv_var"), Expr("priv_var")),
Return(Expr(0.0f))},
ast::DecorationList{});
auto* func2 = Func(
"func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("out_var"), Call("my_func")),
},
Func(
"my_func", ast::VariableList{}, ty.f32(),
ast::StatementList{Assign("out_var", "in_var"),
Assign("wg_var", "wg_var"), Assign("sb_var", "sb_var"),
Assign("priv_var", "priv_var"), Return(0.0f)},
ast::DecorationList{});
auto* func2 = Func("func", ast::VariableList{}, ty.void_(),
ast::StatementList{
Assign("out_var", Call("my_func")),
},
ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()) << r()->error();
auto* func2_sem = Sem().Get(func2);
@@ -846,13 +838,12 @@ TEST_F(ResolverTest, Function_NotRegisterFunctionVariable) {
auto* var = Var("in_var", ty.f32(), ast::StorageClass::kFunction);
Global("var", ty.f32(), ast::StorageClass::kFunction);
auto* func =
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::AssignmentStatement>(Expr("var"), Expr(1.f)),
},
ast::DecorationList{});
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
Decl(var),
Assign("var", 1.f),
},
ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -865,13 +856,12 @@ TEST_F(ResolverTest, Function_NotRegisterFunctionVariable) {
TEST_F(ResolverTest, Function_ReturnStatements) {
auto* var = Var("foo", ty.f32(), ast::StorageClass::kFunction);
auto* ret_1 = create<ast::ReturnStatement>(Expr(1.f));
auto* ret_foo = create<ast::ReturnStatement>(Expr("foo"));
auto* ret_1 = Return(1.f);
auto* ret_foo = Return("foo");
auto* func = Func("my_func", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
If(Expr(true), Block(ret_1)),
Decl(var),
If(true, Block(ret_1)),
ret_foo,
},
ast::DecorationList{});
@@ -888,13 +878,8 @@ TEST_F(ResolverTest, Function_ReturnStatements) {
}
TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {
auto* strct = create<ast::Struct>(
Sym("S"),
ast::StructMemberList{Member("first_member", ty.i32()),
Member("second_member", ty.f32())},
ast::DecorationList{});
auto* st = ty.struct_(strct);
auto* st = Structure("S", {Member("first_member", ty.i32()),
Member("second_member", ty.f32())});
Global("my_struct", st, ast::StorageClass::kInput);
auto* mem = MemberAccessor("my_struct", "second_member");
@@ -918,13 +903,8 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {
}
TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) {
auto* strct = create<ast::Struct>(
Sym("alias"),
ast::StructMemberList{Member("first_member", ty.i32()),
Member("second_member", ty.f32())},
ast::DecorationList{});
auto* st = ty.struct_(strct);
auto* st = Structure("alias", {Member("first_member", ty.i32()),
Member("second_member", ty.f32())});
auto* alias = ty.alias("alias", st);
Global("my_struct", alias, ast::StorageClass::kInput);
@@ -1001,17 +981,11 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
// }
//
auto* strctB = create<ast::Struct>(
Sym("B"), ast::StructMemberList{Member("foo", ty.vec4<f32>())},
ast::DecorationList{});
auto* stB = ty.struct_(strctB);
auto* stB = Structure("B", {Member("foo", ty.vec4<f32>())});
sem::Vector vecB(stB, 3);
auto* strctA =
create<ast::Struct>(Sym("A"), ast::StructMemberList{Member("mem", &vecB)},
ast::DecorationList{});
auto* stA = ty.struct_(strctA);
auto* stA = Structure("A", {Member("mem", &vecB)});
Global("c", stA, ast::StorageClass::kInput);
auto* mem = MemberAccessor(
@@ -1029,13 +1003,8 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
}
TEST_F(ResolverTest, Expr_MemberAccessor_InBinaryOp) {
auto* strct = create<ast::Struct>(
Sym("S"),
ast::StructMemberList{Member("first_member", ty.f32()),
Member("second_member", ty.f32())},
ast::DecorationList{});
auto* st = ty.struct_(strct);
auto* st = Structure("S", {Member("first_member", ty.f32()),
Member("second_member", ty.f32())});
Global("my_struct", st, ast::StorageClass::kInput);
auto* expr = Add(MemberAccessor("my_struct", "first_member"),
@@ -1470,7 +1439,7 @@ INSTANTIATE_TEST_SUITE_P(ResolverTest,
TEST_F(ResolverTest, StorageClass_SetsIfMissing) {
auto* var = Var("var", ty.i32(), ast::StorageClass::kNone);
auto* stmt = create<ast::VariableDeclStatement>(var);
auto* stmt = Decl(var);
Func("func", ast::VariableList{}, ty.void_(), ast::StatementList{stmt},
ast::DecorationList{});
@@ -1481,7 +1450,7 @@ TEST_F(ResolverTest, StorageClass_SetsIfMissing) {
TEST_F(ResolverTest, StorageClass_DoesNotSetOnConst) {
auto* var = Const("var", ty.i32());
auto* stmt = create<ast::VariableDeclStatement>(var);
auto* stmt = Decl(var);
Func("func", ast::VariableList{}, ty.void_(), ast::StatementList{stmt},
ast::DecorationList{});
@@ -1510,39 +1479,34 @@ TEST_F(ResolverTest, Function_EntryPoints_StageDecoration) {
Global("call_c", ty.f32(), ast::StorageClass::kPrivate);
ast::VariableList params;
auto* func_b =
Func("b", params, ty.f32(), ast::StatementList{Return(Expr(0.0f))},
auto* func_b = Func("b", params, ty.f32(), ast::StatementList{Return(0.0f)},
ast::DecorationList{});
auto* func_c =
Func("c", params, ty.f32(),
ast::StatementList{Assign("second", Call("b")), Return(0.0f)},
ast::DecorationList{});
auto* func_c = Func("c", params, ty.f32(),
ast::StatementList{create<ast::AssignmentStatement>(
Expr("second"), Call("b")),
Return(Expr(0.0f))},
ast::DecorationList{});
auto* func_a = Func("a", params, ty.f32(),
ast::StatementList{create<ast::AssignmentStatement>(
Expr("first"), Call("c")),
Return(Expr(0.0f))},
ast::DecorationList{});
auto* func_a =
Func("a", params, ty.f32(),
ast::StatementList{Assign("first", Call("c")), Return(0.0f)},
ast::DecorationList{});
auto* ep_1 =
Func("ep_1", params, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("call_a"), Call("a")),
create<ast::AssignmentStatement>(Expr("call_b"), Call("b")),
},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
auto* ep_1 = Func("ep_1", params, ty.void_(),
ast::StatementList{
Assign("call_a", Call("a")),
Assign("call_b", Call("b")),
},
ast::DecorationList{
Stage(ast::PipelineStage::kCompute),
});
auto* ep_2 =
Func("ep_2", params, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("call_c"), Call("c")),
},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
auto* ep_2 = Func("ep_2", params, ty.void_(),
ast::StatementList{
Assign("call_c", Call("c")),
},
ast::DecorationList{
Stage(ast::PipelineStage::kCompute),
});
ASSERT_TRUE(r()->Resolve()) << r()->error();
@@ -1620,7 +1584,7 @@ TEST_F(ResolverTest, Function_EntryPoints_LinearTime) {
create<ast::CallStatement>(Call(fn_b(0))),
},
{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
Stage(ast::PipelineStage::kCompute),
});
ASSERT_TRUE(r()->Resolve()) << r()->error();

View File

@@ -28,8 +28,7 @@ namespace {
using ResolverPipelineStageUseTest = ResolverTest;
TEST_F(ResolverPipelineStageUseTest, UnusedStruct) {
auto* s = Structure(
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
ASSERT_TRUE(r()->Resolve()) << r()->error();
@@ -39,8 +38,7 @@ TEST_F(ResolverPipelineStageUseTest, UnusedStruct) {
}
TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointParam) {
auto* s = Structure(
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
Func("foo", {Param("param", s)}, ty.void_(), {}, {});
@@ -52,8 +50,7 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointParam) {
}
TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointReturnType) {
auto* s = Structure(
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
Func("foo", {}, s, {Return(Construct(s, Expr(0.f)))}, {});
@@ -96,11 +93,10 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsVertexShaderReturnType) {
}
TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderParam) {
auto* s = Structure(
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
Func("main", {Param("param", s)}, ty.void_(), {},
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
{Stage(ast::PipelineStage::kFragment)});
ASSERT_TRUE(r()->Resolve()) << r()->error();
@@ -111,11 +107,10 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderParam) {
}
TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderReturnType) {
auto* s = Structure(
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
Func("main", {}, s, {Return(Construct(s, Expr(0.f)))},
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
{Stage(ast::PipelineStage::kFragment)});
ASSERT_TRUE(r()->Resolve()) << r()->error();
@@ -126,12 +121,12 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderReturnType) {
}
TEST_F(ResolverPipelineStageUseTest, StructUsedAsComputeShaderParam) {
auto* s = Structure("S", {Member("a", ty.u32(),
{create<ast::BuiltinDecoration>(
ast::Builtin::kLocalInvocationIndex)})});
auto* s = Structure(
"S",
{Member("a", ty.u32(), {Builtin(ast::Builtin::kLocalInvocationIndex)})});
Func("main", {Param("param", s)}, ty.void_(), {},
{create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
{Stage(ast::PipelineStage::kCompute)});
ASSERT_TRUE(r()->Resolve()) << r()->error();
@@ -162,12 +157,11 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedMultipleStages) {
}
TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderParamViaAlias) {
auto* s = Structure(
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
auto* s_alias = ty.alias("S_alias", s);
Func("main", {Param("param", s_alias)}, ty.void_(), {},
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
{Stage(ast::PipelineStage::kFragment)});
ASSERT_TRUE(r()->Resolve()) << r()->error();
@@ -178,12 +172,11 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderParamViaAlias) {
}
TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderReturnTypeViaAlias) {
auto* s = Structure(
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
auto* s_alias = ty.alias("S_alias", s);
Func("main", {}, s_alias, {Return(Construct(s_alias, Expr(0.f)))},
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
{Stage(ast::PipelineStage::kFragment)});
ASSERT_TRUE(r()->Resolve()) << r()->error();

View File

@@ -38,11 +38,8 @@ TEST_F(ResolverTypeValidationTest, VariableDeclNoConstructor_Pass) {
auto* lhs = Expr("a");
auto* rhs = Expr(2);
auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
rhs),
});
auto* body =
Block(Decl(var), Assign(Source{Source::Location{12, 34}}, lhs, rhs));
WrapInFunction(body);
@@ -133,7 +130,7 @@ TEST_F(ResolverTypeValidationTest,
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(Source{{12, 34}}, var),
Decl(Source{{12, 34}}, var),
},
ast::DecorationList{});
@@ -152,8 +149,8 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifier_Fail) {
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::VariableDeclStatement>(Source{{12, 34}}, var_a_float),
Decl(var),
Decl(Source{{12, 34}}, var_a_float),
},
ast::DecorationList{});
@@ -169,16 +166,13 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifierInnerScope_Pass) {
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
auto* cond = Expr(true);
auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
});
auto* body = Block(Decl(var));
auto* var_a_float = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.1f));
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
create<ast::VariableDeclStatement>(Source{{12, 34}}, var_a_float),
});
auto* outer_body =
Block(create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
Decl(Source{{12, 34}}, var_a_float));
WrapInFunction(outer_body);
@@ -198,14 +192,11 @@ TEST_F(ResolverTypeValidationTest,
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
auto* cond = Expr(true);
auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(Source{{12, 34}}, var),
});
auto* body = Block(Decl(Source{{12, 34}}, var));
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var_a_float),
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
});
auto* outer_body =
Block(Decl(var_a_float),
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}));
WrapInFunction(outer_body);
@@ -219,15 +210,10 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifierInnerScopeBlock_Pass) {
// var a : f32;
// }
auto* var_inner = Var("a", ty.f32(), ast::StorageClass::kNone);
auto* inner = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(Source{{12, 34}}, var_inner),
});
auto* inner = Block(Decl(Source{{12, 34}}, var_inner));
auto* var_outer = Var("a", ty.f32(), ast::StorageClass::kNone);
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
inner,
create<ast::VariableDeclStatement>(var_outer),
});
auto* outer_body = Block(inner, Decl(var_outer));
WrapInFunction(outer_body);
@@ -240,15 +226,10 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifierInnerScopeBlock_Fail) {
// { var a : f32; }
// }
auto* var_inner = Var("a", ty.f32(), ast::StorageClass::kNone);
auto* inner = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(Source{{12, 34}}, var_inner),
});
auto* inner = Block(Decl(Source{{12, 34}}, var_inner));
auto* var_outer = Var("a", ty.f32(), ast::StorageClass::kNone);
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var_outer),
inner,
});
auto* outer_body = Block(Decl(var_outer), inner);
WrapInFunction(outer_body);
@@ -266,15 +247,15 @@ TEST_F(ResolverTypeValidationTest,
Func("func0", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(Source{{12, 34}}, var0),
create<ast::ReturnStatement>(),
Decl(Source{{12, 34}}, var0),
Return(),
},
ast::DecorationList{});
Func("func1", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(Source{{13, 34}}, var1),
create<ast::ReturnStatement>(),
Decl(Source{{13, 34}}, var1),
Return(),
});
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -289,10 +270,10 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayInFunction_Fail) {
Func("func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
Decl(var),
},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
Stage(ast::PipelineStage::kVertex),
});
EXPECT_FALSE(r()->Resolve());
@@ -309,16 +290,12 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsLast_Pass) {
// rt: array<f32>;
// };
ast::DecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>());
auto* st =
create<ast::Struct>(Sym("Foo"),
ast::StructMemberList{Member("vf", ty.f32()),
Member("rt", ty.array<f32>())},
decos);
auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type);
Structure("Foo",
{
Member("vf", ty.f32()),
Member("rt", ty.array<f32>()),
},
{create<ast::StructBlockDecoration>()});
WrapInFunction();
@@ -331,15 +308,10 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsLastNoBlock_Fail) {
// rt: array<f32>;
// };
ast::DecorationList decos;
auto* st = create<ast::Struct>(
Sym("Foo"),
ast::StructMemberList{Member("vf", ty.f32()),
Member(Source{{12, 34}}, "rt", ty.array<f32>())},
decos);
auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type);
Structure("Foo", {
Member("vf", ty.f32()),
Member(Source{{12, 34}}, "rt", ty.array<f32>()),
});
WrapInFunction();
@@ -356,16 +328,12 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsNotLast_Fail) {
// vf: f32;
// };
ast::DecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>());
auto* rt = Member(Source{{12, 34}}, "rt", ty.array<f32>());
auto* st = create<ast::Struct>(
Sym("Foo"), ast::StructMemberList{rt, Member("vf", ty.f32())}, decos);
auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type);
Structure("Foo",
{
Member(Source{{12, 34}}, "rt", ty.array<f32>()),
Member("vf", ty.f32()),
},
{create<ast::StructBlockDecoration>()});
WrapInFunction();
@@ -405,16 +373,16 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayAsParameter_Fail) {
Func("func", ast::VariableList{param}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
Return(),
},
ast::DecorationList{});
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
Return(),
},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
Stage(ast::PipelineStage::kVertex),
});
EXPECT_FALSE(r()->Resolve()) << r()->error();
@@ -434,16 +402,12 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsNotLast_Fail) {
auto* alias = ty.alias("RTArr", ty.array<u32>());
ast::DecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>());
auto* st = create<ast::Struct>(
Sym("s"),
ast::StructMemberList{Member(Source{{12, 34}}, "b", alias),
Member("a", ty.u32())},
decos);
auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type);
Structure("s",
{
Member(Source{{12, 34}}, "b", alias),
Member("a", ty.u32()),
},
{create<ast::StructBlockDecoration>()});
WrapInFunction();
@@ -464,14 +428,12 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsLast_Pass) {
auto* alias = ty.alias("RTArr", ty.array<u32>());
ast::DecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>());
auto* st = create<ast::Struct>(
Sym("s"),
ast::StructMemberList{Member("a", ty.u32()), Member("b", alias)}, decos);
auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type);
Structure("s",
{
Member("a", ty.u32()),
Member("b", alias),
},
{create<ast::StructBlockDecoration>()});
WrapInFunction();

View File

@@ -95,13 +95,13 @@ TEST_F(ResolverValidationTest, Stmt_Call_undeclared) {
Func("main", params0, ty.f32(),
ast::StatementList{
create<ast::CallStatement>(call_expr),
create<ast::ReturnStatement>(),
Return(),
},
ast::DecorationList{});
Func("func", params0, ty.f32(),
ast::StatementList{
create<ast::ReturnStatement>(),
Return(),
},
ast::DecorationList{});
@@ -123,7 +123,7 @@ TEST_F(ResolverValidationTest, Stmt_Call_recursive) {
create<ast::CallStatement>(call_expr),
},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
Stage(ast::PipelineStage::kVertex),
});
EXPECT_FALSE(r()->Resolve());
@@ -153,8 +153,7 @@ TEST_F(ResolverValidationTest,
auto* var =
Var("my_var", ty.i32(), ast::StorageClass::kNone, Expr(unsigned_value));
auto* decl =
create<ast::VariableDeclStatement>(Source{{{3, 3}, {3, 22}}}, var);
auto* decl = Decl(Source{{{3, 3}, {3, 22}}}, var);
WrapInFunction(decl);
EXPECT_FALSE(r()->Resolve());
@@ -170,8 +169,7 @@ TEST_F(ResolverValidationTest,
auto* var =
Var("my_var", my_int, ast::StorageClass::kNone, Expr(unsigned_value));
auto* decl =
create<ast::VariableDeclStatement>(Source{{{3, 3}, {3, 22}}}, var);
auto* decl = Decl(Source{{{3, 3}, {3, 22}}}, var);
WrapInFunction(decl);
EXPECT_FALSE(r()->Resolve());
@@ -216,7 +214,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariable_Fail) {
auto* lhs = Expr(Source{{12, 34}}, "b");
auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
auto* assign = Assign(lhs, rhs);
WrapInFunction(assign);
EXPECT_FALSE(r()->Resolve());
@@ -232,9 +230,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableInBlockStatement_Fail) {
auto* lhs = Expr(Source{{12, 34}}, "b");
auto* rhs = Expr(2);
auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::AssignmentStatement>(lhs, rhs),
});
auto* body = Block(Assign(lhs, rhs));
WrapInFunction(body);
EXPECT_FALSE(r()->Resolve());
@@ -253,10 +249,9 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableGlobalVariableAfter_Fail) {
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(lhs, rhs),
Assign(lhs, rhs),
},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
ast::DecorationList{Stage(ast::PipelineStage::kVertex)});
Global("global_var", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f));
@@ -277,9 +272,8 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableGlobalVariable_Pass) {
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}},
Expr("global_var"), Expr(3.14f)),
create<ast::ReturnStatement>(),
Assign(Expr(Source{Source::Location{12, 34}}, "global_var"), 3.14f),
Return(),
});
EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -293,18 +287,15 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableInnerScope_Fail) {
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
auto* cond = Expr(true);
auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
});
auto* body = Block(Decl(var));
SetSource(Source{Source::Location{12, 34}});
auto* lhs = Expr(Source{{12, 34}}, "a");
auto* rhs = Expr(3.14f);
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
create<ast::AssignmentStatement>(lhs, rhs),
});
auto* outer_body =
Block(create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
Assign(lhs, rhs));
WrapInFunction(outer_body);
@@ -324,14 +315,11 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableOuterScope_Pass) {
auto* rhs = Expr(3.14f);
auto* cond = Expr(true);
auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::AssignmentStatement>(lhs, rhs),
});
auto* body = Block(Assign(lhs, rhs));
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
});
auto* outer_body =
Block(Decl(var),
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}));
WrapInFunction(outer_body);
@@ -344,20 +332,13 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableDifferentScope_Fail) {
// { a = 3.14; }
// }
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
auto* first_body = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
});
auto* first_body = Block(Decl(var));
auto* lhs = Expr(Source{{12, 34}}, "a");
auto* rhs = Expr(3.14f);
auto* second_body = create<ast::BlockStatement>(ast::StatementList{
create<ast::AssignmentStatement>(lhs, rhs),
});
auto* second_body = Block(Assign(lhs, rhs));
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
first_body,
second_body,
});
auto* outer_body = Block(first_body, second_body);
WrapInFunction(outer_body);
@@ -369,7 +350,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableDifferentScope_Fail) {
TEST_F(ResolverValidationTest, StorageClass_NonFunctionClassError) {
auto* var = Var("var", ty.i32(), ast::StorageClass::kWorkgroup);
auto* stmt = create<ast::VariableDeclStatement>(var);
auto* stmt = Decl(var);
Func("func", ast::VariableList{}, ty.void_(), ast::StatementList{stmt},
ast::DecorationList{});
@@ -436,7 +417,7 @@ TEST_F(ResolverValidationTest,
auto error_loc = Source{Source::Location{12, 34}};
auto* body = Block(create<ast::ContinueStatement>(),
Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
auto* continuing = Block(Assign(Expr(error_loc, "z"), Expr(2)));
auto* continuing = Block(Assign(Expr(error_loc, "z"), 2));
auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt);
@@ -462,7 +443,7 @@ TEST_F(ResolverValidationTest,
auto* body = Block(create<ast::ContinueStatement>(),
Decl(Var("z", ty.i32(), ast::StorageClass::kNone)),
create<ast::ContinueStatement>());
auto* continuing = Block(Assign(Expr(error_loc, "z"), Expr(2)));
auto* continuing = Block(Assign(Expr(error_loc, "z"), 2));
auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt);
@@ -487,7 +468,7 @@ TEST_F(ResolverValidationTest,
auto error_loc = Source{Source::Location{12, 34}};
auto* body = Block(If(Expr(true), Block(create<ast::ContinueStatement>())),
Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
auto* continuing = Block(Assign(Expr(error_loc, "z"), Expr(2)));
auto* continuing = Block(Assign(Expr(error_loc, "z"), 2));
auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt);
@@ -517,7 +498,7 @@ TEST_F(
Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
auto* continuing =
Block(If(Expr(true), Block(Assign(Expr(error_loc, "z"), Expr(2)))));
Block(If(Expr(true), Block(Assign(Expr(error_loc, "z"), 2))));
auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt);
@@ -545,7 +526,7 @@ TEST_F(ResolverValidationTest,
auto* body = Block(If(Expr(true), Block(create<ast::ContinueStatement>())),
Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
auto* continuing = Block(Loop(Block(Assign(Expr(error_loc, "z"), Expr(2)))));
auto* continuing = Block(Loop(Block(Assign(Expr(error_loc, "z"), 2))));
auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt);
@@ -571,7 +552,7 @@ TEST_F(ResolverValidationTest,
auto* inner_loop = Loop(Block(create<ast::ContinueStatement>()));
auto* body =
Block(inner_loop, Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
auto* continuing = Block(Assign(Expr("z"), Expr(2)));
auto* continuing = Block(Assign("z", 2));
auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt);
@@ -596,7 +577,7 @@ TEST_F(ResolverValidationTest,
auto* inner_loop = Loop(Block(create<ast::ContinueStatement>()));
auto* body =
Block(inner_loop, Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
auto* continuing = Block(If(Expr(true), Block(Assign(Expr("z"), Expr(2)))));
auto* continuing = Block(If(Expr(true), Block(Assign("z", 2))));
auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt);
@@ -621,7 +602,7 @@ TEST_F(ResolverValidationTest,
auto* inner_loop = Loop(Block(create<ast::ContinueStatement>()));
auto* body =
Block(inner_loop, Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
auto* continuing = Block(Loop(Block(Assign(Expr("z"), Expr(2)))));
auto* continuing = Block(Loop(Block(Assign("z", 2))));
auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt);
@@ -641,7 +622,7 @@ TEST_F(ResolverTest, Stmt_Loop_ContinueInLoopBodyAfterDecl_UsageInContinuing) {
auto error_loc = Source{Source::Location{12, 34}};
auto* body = Block(Decl(Var("z", ty.i32(), ast::StorageClass::kNone)),
create<ast::ContinueStatement>());
auto* continuing = Block(Assign(Expr(error_loc, "z"), Expr(2)));
auto* continuing = Block(Assign(Expr(error_loc, "z"), 2));
auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt);