tint: Add ProgramBuilder::Else() helper
This aids readability when building chains of if-else statements. Change-Id: I77ed5a16421bd52302db61f2776d55971838e122 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88366 Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
41e4d9a34c
commit
8aff0ed684
|
@ -58,7 +58,7 @@ TEST_F(IfStatementTest, Assert_InvalidElse) {
|
|||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.If(b.Expr(true), b.Block(), b.CallStmt(b.Call("foo")));
|
||||
b.If(b.Expr(true), b.Block(), b.Else(b.CallStmt(b.Call("foo"))));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ TEST_F(IfStatementTest, Assert_DifferentProgramID_ElseStatement) {
|
|||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.If(b1.Expr(true), b1.Block(), b2.If(b2.Expr("ident"), b2.Block()));
|
||||
b1.If(b1.Expr(true), b1.Block(), b2.Else(b2.If(b2.Expr("ident"), b2.Block())));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
|
|
@ -2080,6 +2080,17 @@ class ProgramBuilder {
|
|||
ast::StatementList{std::forward<STATEMENTS>(statements)...});
|
||||
}
|
||||
|
||||
/// A wrapper type for the Else statement used to create If statements.
|
||||
struct ElseStmt {
|
||||
/// Default constructor - no else statement.
|
||||
ElseStmt() : stmt(nullptr) {}
|
||||
/// Constructor
|
||||
/// @param s The else statement
|
||||
explicit ElseStmt(const ast::Statement* s) : stmt(s) {}
|
||||
/// The else statement, or nullptr.
|
||||
const ast::Statement* stmt;
|
||||
};
|
||||
|
||||
/// Creates a ast::IfStatement with input condition, body, and optional
|
||||
/// else statement
|
||||
/// @param source the source information for the if statement
|
||||
|
@ -2091,9 +2102,9 @@ class ProgramBuilder {
|
|||
const ast::IfStatement* If(const Source& source,
|
||||
CONDITION&& condition,
|
||||
const ast::BlockStatement* body,
|
||||
const ast::Statement* else_stmt = nullptr) {
|
||||
const ElseStmt else_stmt = ElseStmt()) {
|
||||
return create<ast::IfStatement>(source, Expr(std::forward<CONDITION>(condition)), body,
|
||||
else_stmt);
|
||||
else_stmt.stmt);
|
||||
}
|
||||
|
||||
/// Creates a ast::IfStatement with input condition, body, and optional
|
||||
|
@ -2105,10 +2116,16 @@ class ProgramBuilder {
|
|||
template <typename CONDITION>
|
||||
const ast::IfStatement* If(CONDITION&& condition,
|
||||
const ast::BlockStatement* body,
|
||||
const ast::Statement* else_stmt = nullptr) {
|
||||
return create<ast::IfStatement>(Expr(std::forward<CONDITION>(condition)), body, else_stmt);
|
||||
const ElseStmt else_stmt = ElseStmt()) {
|
||||
return create<ast::IfStatement>(Expr(std::forward<CONDITION>(condition)), body,
|
||||
else_stmt.stmt);
|
||||
}
|
||||
|
||||
/// Creates an Else object.
|
||||
/// @param stmt else statement
|
||||
/// @returns the Else object
|
||||
ElseStmt Else(const ast::Statement* stmt) { return ElseStmt(stmt); }
|
||||
|
||||
/// Creates a ast::AssignmentStatement with input lhs and rhs expressions
|
||||
/// @param source the source information
|
||||
/// @param lhs the left hand side expression initializer
|
||||
|
|
|
@ -224,7 +224,7 @@ TEST_F(ResolverCompoundStatementTest, If) {
|
|||
auto* cond_b = Expr(true);
|
||||
auto* stmt_b = Ignore(1);
|
||||
auto* stmt_c = Ignore(1);
|
||||
auto* if_stmt = If(cond_a, Block(stmt_a), If(cond_b, Block(stmt_b), Block(stmt_c)));
|
||||
auto* if_stmt = If(cond_a, Block(stmt_a), Else(If(cond_b, Block(stmt_b), Else(Block(stmt_c)))));
|
||||
WrapInFunction(if_stmt);
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
|
|
@ -1147,9 +1147,9 @@ TEST_P(ResolverDependencyShadowTest, Test) {
|
|||
helper.Add(inner_kind, symbol, Source{{56, 78}});
|
||||
auto* inner_var = helper.nested_statements.size()
|
||||
? helper.nested_statements[0]->As<ast::VariableDeclStatement>()->variable
|
||||
: helper.statements.size()
|
||||
? helper.statements[0]->As<ast::VariableDeclStatement>()->variable
|
||||
: helper.parameters[0];
|
||||
: helper.statements.size()
|
||||
? helper.statements[0]->As<ast::VariableDeclStatement>()->variable
|
||||
: helper.parameters[0];
|
||||
helper.Build();
|
||||
|
||||
EXPECT_EQ(Build().shadows[inner_var], outer);
|
||||
|
@ -1218,8 +1218,8 @@ TEST_F(ResolverDependencyGraphTraversalTest, SymbolsReached) {
|
|||
Assign(V, V)), //
|
||||
If(V, //
|
||||
Block(Assign(V, V)), //
|
||||
If(V, //
|
||||
Block(Assign(V, V)))), //
|
||||
Else(If(V, //
|
||||
Block(Assign(V, V))))), //
|
||||
Ignore(Bitcast(T, V)), //
|
||||
For(Decl(Var(Sym(), T, V)), //
|
||||
Equal(V, V), //
|
||||
|
|
|
@ -332,7 +332,7 @@ TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenDiscard) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock_ElseDiscard) {
|
||||
auto* stmt = If(true, Block(), Block(Discard()));
|
||||
auto* stmt = If(true, Block(), Else(Block(Discard())));
|
||||
WrapInFunction(stmt);
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -342,7 +342,7 @@ TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock_ElseDiscard) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenDiscard_ElseDiscard) {
|
||||
auto* stmt = If(true, Block(Discard()), Block(Discard()));
|
||||
auto* stmt = If(true, Block(Discard()), Else(Block(Discard())));
|
||||
WrapInFunction(stmt);
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -363,7 +363,7 @@ TEST_F(ResolverBehaviorTest, StmtIfCallFuncMayDiscard_ThenEmptyBlock) {
|
|||
|
||||
TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock_ElseCallFuncMayDiscard) {
|
||||
auto* stmt = If(true, Block(), //
|
||||
If(Equal(Call("DiscardOrNext"), 1), Block()));
|
||||
Else(If(Equal(Call("DiscardOrNext"), 1), Block())));
|
||||
WrapInFunction(stmt);
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
|
|
@ -168,7 +168,7 @@ TEST_F(ResolverTest, Stmt_If) {
|
|||
auto* assign = Assign(lhs, rhs);
|
||||
auto* body = Block(assign);
|
||||
auto* cond = Expr(true);
|
||||
auto* stmt = If(cond, body, else_stmt);
|
||||
auto* stmt = If(cond, body, Else(else_stmt));
|
||||
WrapInFunction(v, stmt);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
|
|
@ -124,7 +124,7 @@ TEST_F(ResolverValidationTest, Stmt_If_NonBool) {
|
|||
TEST_F(ResolverValidationTest, Stmt_ElseIf_NonBool) {
|
||||
// else if (1.23f) {}
|
||||
|
||||
WrapInFunction(If(Expr(true), Block(), If(Expr(Source{{12, 34}}, 1.23f), Block())));
|
||||
WrapInFunction(If(Expr(true), Block(), Else(If(Expr(Source{{12, 34}}, 1.23f), Block()))));
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
||||
|
@ -1007,12 +1007,12 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfTrueInContinuing) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInIfElseInContinuing) {
|
||||
auto* cont = Block( // continuing {
|
||||
If(true, Block(), // if(true) {
|
||||
Block( // } else {
|
||||
Break(Source{{12, 34}})))); // break;
|
||||
// }
|
||||
// }
|
||||
auto* cont = Block( // continuing {
|
||||
If(true, Block(), // if(true) {
|
||||
Else(Block( // } else {
|
||||
Break(Source{{12, 34}}))))); // break;
|
||||
// }
|
||||
// }
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
@ -1065,13 +1065,13 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfTrueMultipleStmtsInContinuing) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInIfElseMultipleStmtsInContinuing) {
|
||||
auto* cont = Block( // continuing {
|
||||
If(true, Block(), // if(true) {
|
||||
Block(Source{{56, 78}}, // } else {
|
||||
Assign(Phony(), 1), // _ = 1;
|
||||
Break(Source{{12, 34}})))); // break;
|
||||
// }
|
||||
// }
|
||||
auto* cont = Block( // continuing {
|
||||
If(true, Block(), // if(true) {
|
||||
Else(Block(Source{{56, 78}}, // } else {
|
||||
Assign(Phony(), 1), // _ = 1;
|
||||
Break(Source{{12, 34}}))))); // break;
|
||||
// }
|
||||
// }
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
|
@ -1082,12 +1082,12 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfElseMultipleStmtsInContinuing) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInIfElseIfInContinuing) {
|
||||
auto* cont = Block( // continuing {
|
||||
If(true, Block(), // if(true) {
|
||||
If(Source{{56, 78}}, Expr(true), // } else if (true) {
|
||||
Block(Break(Source{{12, 34}}))))); // break;
|
||||
// }
|
||||
// }
|
||||
auto* cont = Block( // continuing {
|
||||
If(true, Block(), // if(true) {
|
||||
Else(If(Source{{56, 78}}, Expr(true), // } else if (true) {
|
||||
Block(Break(Source{{12, 34}})))))); // break;
|
||||
// }
|
||||
// }
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
|
@ -1098,13 +1098,13 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfElseIfInContinuing) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInIfNonEmptyElseInContinuing) {
|
||||
auto* cont = Block( // continuing {
|
||||
If(true, // if(true) {
|
||||
Block(Break(Source{{12, 34}})), // break;
|
||||
Block(Source{{56, 78}}, // } else {
|
||||
Assign(Phony(), 1)))); // _ = 1;
|
||||
// }
|
||||
// }
|
||||
auto* cont = Block( // continuing {
|
||||
If(true, // if(true) {
|
||||
Block(Break(Source{{12, 34}})), // break;
|
||||
Else(Block(Source{{56, 78}}, // } else {
|
||||
Assign(Phony(), 1))))); // _ = 1;
|
||||
// }
|
||||
// }
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
|
@ -1118,8 +1118,8 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfElseNonEmptyTrueInContinuing) {
|
|||
auto* cont = Block( // continuing {
|
||||
If(true, // if(true) {
|
||||
Block(Source{{56, 78}}, Assign(Phony(), 1)), // _ = 1;
|
||||
Block( // } else {
|
||||
Break(Source{{12, 34}})))); // break;
|
||||
Else(Block( // } else {
|
||||
Break(Source{{12, 34}}))))); // break;
|
||||
// }
|
||||
// }
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
|
|
|
@ -329,13 +329,13 @@ struct MultiplanarExternalTexture::State {
|
|||
b.Block(
|
||||
// color = textureLoad(plane0, coord, 0).rgb;
|
||||
b.Assign("color", b.MemberAccessor(single_plane_call, "rgb"))),
|
||||
b.Block(
|
||||
b.Else(b.Block(
|
||||
// color = vec4<f32>(plane_0_call.r, plane_1_call.rg, 1.0) *
|
||||
// params.yuvToRgbConversionMatrix;
|
||||
b.Assign("color",
|
||||
b.Mul(b.vec4<f32>(b.MemberAccessor(plane_0_call, "r"),
|
||||
b.MemberAccessor(plane_1_call, "rg"), 1.0f),
|
||||
b.MemberAccessor("params", "yuvToRgbConversionMatrix"))))),
|
||||
b.MemberAccessor("params", "yuvToRgbConversionMatrix")))))),
|
||||
// color = gammaConversion(color, gammaDecodeParams);
|
||||
b.Assign("color", b.Call("gammaCorrection", "color",
|
||||
b.MemberAccessor("params", "gammaDecodeParams"))),
|
||||
|
|
|
@ -123,7 +123,7 @@ class HoistToDeclBefore::State {
|
|||
// Move the 'else-if' into the new `else` block as a plain 'if'.
|
||||
auto* cond = ctx.Clone(else_if->condition);
|
||||
auto* body = ctx.Clone(else_if->body);
|
||||
auto* new_if = b.If(cond, body, ctx.Clone(else_if->else_statement));
|
||||
auto* new_if = b.If(cond, body, b.Else(ctx.Clone(else_if->else_statement)));
|
||||
body_stmts.emplace_back(new_if);
|
||||
|
||||
// Replace the 'else-if' with the new 'else' block.
|
||||
|
|
|
@ -184,9 +184,9 @@ TEST_F(HoistToDeclBeforeTest, ElseIf) {
|
|||
ProgramBuilder b;
|
||||
auto* var = b.Decl(b.Var("a", b.ty.bool_()));
|
||||
auto* expr = b.Expr("a");
|
||||
auto* s = b.If(b.Expr(true), b.Block(), //
|
||||
b.If(expr, b.Block(), //
|
||||
b.Block()));
|
||||
auto* s = b.If(b.Expr(true), b.Block(), //
|
||||
b.Else(b.If(expr, b.Block(), //
|
||||
b.Else(b.Block()))));
|
||||
b.Func("f", {}, b.ty.void_(), {var, s});
|
||||
|
||||
Program original(std::move(b));
|
||||
|
@ -378,9 +378,9 @@ TEST_F(HoistToDeclBeforeTest, Prepare_ElseIf) {
|
|||
ProgramBuilder b;
|
||||
auto* var = b.Decl(b.Var("a", b.ty.bool_()));
|
||||
auto* expr = b.Expr("a");
|
||||
auto* s = b.If(b.Expr(true), b.Block(), //
|
||||
b.If(expr, b.Block(), //
|
||||
b.Block()));
|
||||
auto* s = b.If(b.Expr(true), b.Block(), //
|
||||
b.Else(b.If(expr, b.Block(), //
|
||||
b.Else(b.Block()))));
|
||||
b.Func("f", {}, b.ty.void_(), {var, s});
|
||||
|
||||
Program original(std::move(b));
|
||||
|
@ -552,9 +552,9 @@ TEST_F(HoistToDeclBeforeTest, InsertBefore_ElseIf) {
|
|||
ProgramBuilder b;
|
||||
b.Func("foo", {}, b.ty.void_(), {});
|
||||
auto* var = b.Decl(b.Var("a", b.ty.bool_()));
|
||||
auto* elseif = b.If(b.Expr("a"), b.Block(), b.Block());
|
||||
auto* elseif = b.If(b.Expr("a"), b.Block(), b.Else(b.Block()));
|
||||
auto* s = b.If(b.Expr(true), b.Block(), //
|
||||
elseif);
|
||||
b.Else(elseif));
|
||||
b.Func("f", {}, b.ty.void_(), {var, s});
|
||||
|
||||
Program original(std::move(b));
|
||||
|
|
|
@ -343,8 +343,8 @@ TEST_F(GlslGeneratorImplTest_Binary, If_WithLogical) {
|
|||
auto* expr =
|
||||
If(create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr("a"), Expr("b")),
|
||||
Block(Return(1)),
|
||||
If(create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr("b"), Expr("c")),
|
||||
Block(Return(2)), Block(Return(3))));
|
||||
Else(If(create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr("b"), Expr("c")),
|
||||
Block(Return(2)), Else(Block(Return(3))))));
|
||||
Func("func", {}, ty.i32(), {WrapInStatement(expr)});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -20,8 +20,7 @@ namespace {
|
|||
using GlslGeneratorImplTest_Continue = TestHelper;
|
||||
|
||||
TEST_F(GlslGeneratorImplTest_Continue, Emit_Continue) {
|
||||
auto* loop = Loop(Block(If(false, Block(Break())), //
|
||||
Continue()));
|
||||
auto* loop = Loop(Block(If(false, Block(Break())), Continue()));
|
||||
WrapInFunction(loop);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -46,7 +46,7 @@ TEST_F(GlslGeneratorImplTest_If, Emit_IfWithElseIf) {
|
|||
|
||||
auto* cond = Expr("cond");
|
||||
auto* body = Block(Return());
|
||||
auto* i = If(cond, body, If(else_cond, else_body));
|
||||
auto* i = If(cond, body, Else(If(else_cond, else_body)));
|
||||
WrapInFunction(i);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -71,7 +71,7 @@ TEST_F(GlslGeneratorImplTest_If, Emit_IfWithElse) {
|
|||
|
||||
auto* cond = Expr("cond");
|
||||
auto* body = Block(Return());
|
||||
auto* i = If(cond, body, else_body);
|
||||
auto* i = If(cond, body, Else(else_body));
|
||||
WrapInFunction(i);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -99,7 +99,7 @@ TEST_F(GlslGeneratorImplTest_If, Emit_IfWithMultiple) {
|
|||
|
||||
auto* cond = Expr("cond");
|
||||
auto* body = Block(Return());
|
||||
auto* i = If(cond, body, If(else_cond, else_body, else_body_2));
|
||||
auto* i = If(cond, body, Else(If(else_cond, else_body, Else(else_body_2))));
|
||||
WrapInFunction(i);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -333,8 +333,8 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
|
|||
auto* expr =
|
||||
If(create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr("a"), Expr("b")),
|
||||
Block(Return(1)),
|
||||
If(create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr("b"), Expr("c")),
|
||||
Block(Return(2)), Block(Return(3))));
|
||||
Else(If(create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr("b"), Expr("c")),
|
||||
Block(Return(2)), Else(Block(Return(3))))));
|
||||
Func("func", {}, ty.i32(), {WrapInStatement(expr)});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -46,7 +46,7 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
|
|||
|
||||
auto* cond = Expr("cond");
|
||||
auto* body = Block(Return());
|
||||
auto* i = If(cond, body, If(else_cond, else_body));
|
||||
auto* i = If(cond, body, Else(If(else_cond, else_body)));
|
||||
WrapInFunction(i);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -71,7 +71,7 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
|
|||
|
||||
auto* cond = Expr("cond");
|
||||
auto* body = Block(Return());
|
||||
auto* i = If(cond, body, else_body);
|
||||
auto* i = If(cond, body, Else(else_body));
|
||||
WrapInFunction(i);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -99,7 +99,7 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
|
|||
|
||||
auto* cond = Expr("cond");
|
||||
auto* body = Block(Return());
|
||||
auto* i = If(cond, body, If(else_cond, else_body, else_body_2));
|
||||
auto* i = If(cond, body, Else(If(else_cond, else_body, Else(else_body_2))));
|
||||
WrapInFunction(i);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -38,7 +38,7 @@ TEST_F(MslGeneratorImplTest, Emit_If) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
|
||||
auto* cond = Var("cond", ty.bool_());
|
||||
auto* else_cond = Var("else_cond", ty.bool_());
|
||||
auto* i = If(cond, Block(Return()), If(else_cond, Block(Return())));
|
||||
auto* i = If(cond, Block(Return()), Else(If(else_cond, Block(Return()))));
|
||||
WrapInFunction(cond, else_cond, i);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -58,7 +58,7 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
|
|||
|
||||
TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
|
||||
auto* cond = Var("cond", ty.bool_());
|
||||
auto* i = If(cond, Block(Return()), Block(Return()));
|
||||
auto* i = If(cond, Block(Return()), Else(Block(Return())));
|
||||
WrapInFunction(cond, i);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -77,7 +77,8 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
|
||||
auto* cond = Var("cond", ty.bool_());
|
||||
auto* else_cond = Var("else_cond", ty.bool_());
|
||||
auto* i = If(cond, Block(Return()), If(else_cond, Block(Return()), Block(Return())));
|
||||
auto* i =
|
||||
If(cond, Block(Return()), Else(If(else_cond, Block(Return()), Else(Block(Return())))));
|
||||
WrapInFunction(cond, else_cond, i);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -106,7 +106,7 @@ TEST_F(BuilderTest, If_WithElse) {
|
|||
auto* body = Block(Assign("v", 2));
|
||||
auto* else_body = Block(Assign("v", 3));
|
||||
|
||||
auto* expr = If(true, body, else_body);
|
||||
auto* expr = If(true, body, Else(else_body));
|
||||
WrapInFunction(expr);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -148,7 +148,7 @@ TEST_F(BuilderTest, If_WithElseIf) {
|
|||
auto* body = Block(Assign("v", 2));
|
||||
auto* else_body = Block(Assign("v", 3));
|
||||
|
||||
auto* expr = If(true, body, If(true, else_body));
|
||||
auto* expr = If(true, body, Else(If(true, else_body)));
|
||||
WrapInFunction(expr);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -201,10 +201,10 @@ TEST_F(BuilderTest, If_WithMultiple) {
|
|||
auto* elseif_2_body = Block(Assign("v", 4));
|
||||
auto* else_body = Block(Assign("v", 5));
|
||||
|
||||
auto* expr = If(true, body, //
|
||||
If(true, elseif_1_body, //
|
||||
If(false, elseif_2_body, //
|
||||
else_body)));
|
||||
auto* expr = If(true, body, //
|
||||
Else(If(true, elseif_1_body, //
|
||||
Else(If(false, elseif_2_body, //
|
||||
Else(else_body))))));
|
||||
WrapInFunction(expr);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -305,7 +305,7 @@ TEST_F(BuilderTest, If_WithElseBreak) {
|
|||
// }
|
||||
auto* else_body = Block(Break());
|
||||
|
||||
auto* if_stmt = If(true, Block(), else_body);
|
||||
auto* if_stmt = If(true, Block(), Else(else_body));
|
||||
|
||||
auto* loop_body = Block(if_stmt);
|
||||
|
||||
|
@ -349,7 +349,7 @@ TEST_F(BuilderTest, If_WithContinueAndBreak) {
|
|||
// }
|
||||
// }
|
||||
|
||||
auto* if_stmt = If(true, Block(Continue()), Block(Break()));
|
||||
auto* if_stmt = If(true, Block(Continue()), Else(Block(Break())));
|
||||
|
||||
auto* expr = Loop(Block(if_stmt), Block());
|
||||
WrapInFunction(expr);
|
||||
|
@ -392,7 +392,7 @@ TEST_F(BuilderTest, If_WithElseContinue) {
|
|||
// }
|
||||
auto* else_body = Block(create<ast::ContinueStatement>());
|
||||
|
||||
auto* if_stmt = If(true, Block(), else_body);
|
||||
auto* if_stmt = If(true, Block(), Else(else_body));
|
||||
|
||||
auto* loop_body = Block(if_stmt, Break());
|
||||
|
||||
|
@ -493,7 +493,7 @@ TEST_F(BuilderTest, IfElse_BothReturn) {
|
|||
{
|
||||
If(true, //
|
||||
Block(Return(true)), //
|
||||
Block(Return(true))),
|
||||
Else(Block(Return(true)))),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -589,7 +589,7 @@ TEST_F(BuilderTest, If_ElseIf_WithReturn) {
|
|||
// return;
|
||||
// }
|
||||
|
||||
auto* if_stmt = If(false, Block(), If(true, Block(Return())));
|
||||
auto* if_stmt = If(false, Block(), Else(If(true, Block(Return()))));
|
||||
auto* fn = Func("f", {}, ty.void_(), {if_stmt});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -627,7 +627,7 @@ TEST_F(BuilderTest, Loop_If_ElseIf_WithBreak) {
|
|||
// }
|
||||
// }
|
||||
|
||||
auto* if_stmt = If(false, Block(), If(true, Block(Break())));
|
||||
auto* if_stmt = If(false, Block(), Else(If(true, Block(Break()))));
|
||||
auto* fn = Func("f", {}, ty.void_(), {Loop(Block(if_stmt))});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
|
|
@ -268,7 +268,7 @@ TEST_F(BuilderTest, Loop_WithContinuing_BreakUnless) {
|
|||
// if (true) {} else { break; }
|
||||
// }
|
||||
// }
|
||||
auto* if_stmt = If(Expr(true), Block(), Block(Break()));
|
||||
auto* if_stmt = If(Expr(true), Block(), Else(Block(Break())));
|
||||
auto* continuing = Block(if_stmt);
|
||||
auto* loop = Loop(Block(), continuing);
|
||||
WrapInFunction(loop);
|
||||
|
@ -341,7 +341,7 @@ TEST_F(BuilderTest, Loop_WithContinuing_BreakUnless_ConditionIsVar) {
|
|||
// }
|
||||
// }
|
||||
auto* cond_var = Decl(Var("cond", nullptr, Expr(true)));
|
||||
auto* if_stmt = If(Expr("cond"), Block(), Block(Break()));
|
||||
auto* if_stmt = If(Expr("cond"), Block(), Else(Block(Break())));
|
||||
auto* continuing = Block(cond_var, if_stmt);
|
||||
auto* loop = Loop(Block(), continuing);
|
||||
WrapInFunction(loop);
|
||||
|
@ -437,11 +437,11 @@ TEST_F(BuilderTest, Loop_WithContinuing_BreakUnless_Nested) {
|
|||
// }
|
||||
// }
|
||||
|
||||
auto* inner_if_stmt = If(Expr(true), Block(), Block(Break()));
|
||||
auto* inner_if_stmt = If(Expr(true), Block(), Else(Block(Break())));
|
||||
auto* inner_continuing = Block(inner_if_stmt);
|
||||
auto* inner_loop = Loop(Block(), inner_continuing);
|
||||
|
||||
auto* outer_if_stmt = If(Expr(true), Block(), Block(Break()));
|
||||
auto* outer_if_stmt = If(Expr(true), Block(), Else(Block(Break())));
|
||||
auto* outer_continuing = Block(inner_loop, outer_if_stmt);
|
||||
auto* outer_loop = Loop(Block(), outer_continuing);
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithElseIf) {
|
|||
|
||||
auto* cond = Expr("cond");
|
||||
auto* body = Block(Return());
|
||||
auto* i = If(cond, body, If(else_cond, else_body));
|
||||
auto* i = If(cond, body, Else(If(else_cond, else_body)));
|
||||
WrapInFunction(i);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -70,7 +70,7 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithElse) {
|
|||
|
||||
auto* cond = Expr("cond");
|
||||
auto* body = Block(Return());
|
||||
auto* i = If(cond, body, else_body);
|
||||
auto* i = If(cond, body, Else(else_body));
|
||||
WrapInFunction(i);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -98,7 +98,7 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithMultiple) {
|
|||
|
||||
auto* cond = Expr("cond");
|
||||
auto* body = Block(Return());
|
||||
auto* i = If(cond, body, If(else_cond, else_body, else_body_2));
|
||||
auto* i = If(cond, body, Else(If(else_cond, else_body, Else(else_body_2))));
|
||||
WrapInFunction(i);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
Loading…
Reference in New Issue