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>
diff --git a/src/tint/ast/if_statement_test.cc b/src/tint/ast/if_statement_test.cc
index 57d0b86..9115cb7 100644
--- a/src/tint/ast/if_statement_test.cc
+++ b/src/tint/ast/if_statement_test.cc
@@ -58,7 +58,7 @@
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 @@
{
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");
}
diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h
index 0b26ede..5c3feee 100644
--- a/src/tint/program_builder.h
+++ b/src/tint/program_builder.h
@@ -2080,6 +2080,17 @@
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 @@
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 @@
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
diff --git a/src/tint/resolver/compound_statement_test.cc b/src/tint/resolver/compound_statement_test.cc
index e3aec74..1358b38 100644
--- a/src/tint/resolver/compound_statement_test.cc
+++ b/src/tint/resolver/compound_statement_test.cc
@@ -224,7 +224,7 @@
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();
diff --git a/src/tint/resolver/dependency_graph_test.cc b/src/tint/resolver/dependency_graph_test.cc
index a02d08c..3a11a8d 100644
--- a/src/tint/resolver/dependency_graph_test.cc
+++ b/src/tint/resolver/dependency_graph_test.cc
@@ -1147,9 +1147,9 @@
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 @@
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), //
diff --git a/src/tint/resolver/resolver_behavior_test.cc b/src/tint/resolver/resolver_behavior_test.cc
index 4bcd4ff..03729c5 100644
--- a/src/tint/resolver/resolver_behavior_test.cc
+++ b/src/tint/resolver/resolver_behavior_test.cc
@@ -332,7 +332,7 @@
}
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_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, 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();
diff --git a/src/tint/resolver/resolver_test.cc b/src/tint/resolver/resolver_test.cc
index 439d929..7c06fab 100644
--- a/src/tint/resolver/resolver_test.cc
+++ b/src/tint/resolver/resolver_test.cc
@@ -168,7 +168,7 @@
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();
diff --git a/src/tint/resolver/validation_test.cc b/src/tint/resolver/validation_test.cc
index 94349d8..0e7cfff 100644
--- a/src/tint/resolver/validation_test.cc
+++ b/src/tint/resolver/validation_test.cc
@@ -124,7 +124,7 @@
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_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_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_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_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 @@
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));
diff --git a/src/tint/transform/multiplanar_external_texture.cc b/src/tint/transform/multiplanar_external_texture.cc
index 93af4ca..671c6c1 100644
--- a/src/tint/transform/multiplanar_external_texture.cc
+++ b/src/tint/transform/multiplanar_external_texture.cc
@@ -329,13 +329,13 @@
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"))),
diff --git a/src/tint/transform/utils/hoist_to_decl_before.cc b/src/tint/transform/utils/hoist_to_decl_before.cc
index 9917412..450a2e8 100644
--- a/src/tint/transform/utils/hoist_to_decl_before.cc
+++ b/src/tint/transform/utils/hoist_to_decl_before.cc
@@ -123,7 +123,7 @@
// 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.
diff --git a/src/tint/transform/utils/hoist_to_decl_before_test.cc b/src/tint/transform/utils/hoist_to_decl_before_test.cc
index bce27df..e675fac 100644
--- a/src/tint/transform/utils/hoist_to_decl_before_test.cc
+++ b/src/tint/transform/utils/hoist_to_decl_before_test.cc
@@ -184,9 +184,9 @@
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 @@
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 @@
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));
diff --git a/src/tint/writer/glsl/generator_impl_binary_test.cc b/src/tint/writer/glsl/generator_impl_binary_test.cc
index 46dd842..a389184 100644
--- a/src/tint/writer/glsl/generator_impl_binary_test.cc
+++ b/src/tint/writer/glsl/generator_impl_binary_test.cc
@@ -343,8 +343,8 @@
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();
diff --git a/src/tint/writer/glsl/generator_impl_continue_test.cc b/src/tint/writer/glsl/generator_impl_continue_test.cc
index 4f77281..331ce79 100644
--- a/src/tint/writer/glsl/generator_impl_continue_test.cc
+++ b/src/tint/writer/glsl/generator_impl_continue_test.cc
@@ -20,8 +20,7 @@
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();
diff --git a/src/tint/writer/glsl/generator_impl_if_test.cc b/src/tint/writer/glsl/generator_impl_if_test.cc
index a5fcbc5..4b0b7bb 100644
--- a/src/tint/writer/glsl/generator_impl_if_test.cc
+++ b/src/tint/writer/glsl/generator_impl_if_test.cc
@@ -46,7 +46,7 @@
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 @@
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 @@
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();
diff --git a/src/tint/writer/hlsl/generator_impl_binary_test.cc b/src/tint/writer/hlsl/generator_impl_binary_test.cc
index 230c72a..6299e84 100644
--- a/src/tint/writer/hlsl/generator_impl_binary_test.cc
+++ b/src/tint/writer/hlsl/generator_impl_binary_test.cc
@@ -333,8 +333,8 @@
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();
diff --git a/src/tint/writer/hlsl/generator_impl_if_test.cc b/src/tint/writer/hlsl/generator_impl_if_test.cc
index c3b2721..1668d71 100644
--- a/src/tint/writer/hlsl/generator_impl_if_test.cc
+++ b/src/tint/writer/hlsl/generator_impl_if_test.cc
@@ -46,7 +46,7 @@
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 @@
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 @@
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();
diff --git a/src/tint/writer/msl/generator_impl_if_test.cc b/src/tint/writer/msl/generator_impl_if_test.cc
index 1af0bed..5138dce 100644
--- a/src/tint/writer/msl/generator_impl_if_test.cc
+++ b/src/tint/writer/msl/generator_impl_if_test.cc
@@ -38,7 +38,7 @@
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_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_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();
diff --git a/src/tint/writer/spirv/builder_if_test.cc b/src/tint/writer/spirv/builder_if_test.cc
index 26b58ae..17a2f50 100644
--- a/src/tint/writer/spirv/builder_if_test.cc
+++ b/src/tint/writer/spirv/builder_if_test.cc
@@ -106,7 +106,7 @@
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 @@
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 @@
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 @@
// }
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 @@
// }
// }
- 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 @@
// }
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 @@
{
If(true, //
Block(Return(true)), //
- Block(Return(true))),
+ Else(Block(Return(true)))),
});
spirv::Builder& b = Build();
@@ -589,7 +589,7 @@
// 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 @@
// }
// }
- 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();
diff --git a/src/tint/writer/spirv/builder_loop_test.cc b/src/tint/writer/spirv/builder_loop_test.cc
index ebce678..5532f6a 100644
--- a/src/tint/writer/spirv/builder_loop_test.cc
+++ b/src/tint/writer/spirv/builder_loop_test.cc
@@ -268,7 +268,7 @@
// 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 @@
// }
// }
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 @@
// }
// }
- 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);
diff --git a/src/tint/writer/wgsl/generator_impl_if_test.cc b/src/tint/writer/wgsl/generator_impl_if_test.cc
index bf85df6..18c0ffd 100644
--- a/src/tint/writer/wgsl/generator_impl_if_test.cc
+++ b/src/tint/writer/wgsl/generator_impl_if_test.cc
@@ -47,7 +47,7 @@
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 @@
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 @@
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();