ast: Remove IfStatement::set_else_statements()

Move it to the constructor.

Bug: tint:390
Change-Id: Ib4ac1a1c83aa59963472ac7c14c9e0cbcf2734e6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35007
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-12-07 20:11:24 +00:00 committed by Commit Bot service account
parent 4d6635858e
commit 9838768599
19 changed files with 210 additions and 220 deletions

View File

@ -88,7 +88,8 @@ TEST_F(BlockStatementTest, IsValid_NullBodyStatement) {
TEST_F(BlockStatementTest, IsValid_InvalidBodyStatement) { TEST_F(BlockStatementTest, IsValid_InvalidBodyStatement) {
BlockStatement b; BlockStatement b;
b.append(create<IfStatement>(nullptr, create<BlockStatement>())); b.append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
ElseStatementList{}));
EXPECT_FALSE(b.IsValid()); EXPECT_FALSE(b.IsValid());
} }

View File

@ -124,7 +124,8 @@ TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) {
b.push_back(create<SintLiteral>(&i32, 2)); b.push_back(create<SintLiteral>(&i32, 2));
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<IfStatement>(nullptr, create<BlockStatement>())); body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
ElseStatementList{}));
CaseStatement c({b}, body); CaseStatement c({b}, body);
EXPECT_FALSE(c.IsValid()); EXPECT_FALSE(c.IsValid());

View File

@ -97,7 +97,8 @@ TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) { TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<IfStatement>(nullptr, create<BlockStatement>())); body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
ElseStatementList{}));
ElseStatement e(body); ElseStatement e(body);
EXPECT_FALSE(e.IsValid()); EXPECT_FALSE(e.IsValid());

View File

@ -23,13 +23,14 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::IfStatement);
namespace tint { namespace tint {
namespace ast { namespace ast {
IfStatement::IfStatement(Expression* condition, BlockStatement* body)
: Base(), condition_(condition), body_(body) {}
IfStatement::IfStatement(const Source& source, IfStatement::IfStatement(const Source& source,
Expression* condition, Expression* condition,
BlockStatement* body) BlockStatement* body,
: Base(source), condition_(condition), body_(body) {} ElseStatementList else_stmts)
: Base(source),
condition_(condition),
body_(body),
else_statements_(std::move(else_stmts)) {}
IfStatement::IfStatement(IfStatement&&) = default; IfStatement::IfStatement(IfStatement&&) = default;
@ -37,8 +38,8 @@ IfStatement::~IfStatement() = default;
IfStatement* IfStatement::Clone(CloneContext* ctx) const { IfStatement* IfStatement::Clone(CloneContext* ctx) const {
auto* cloned = ctx->mod->create<IfStatement>( auto* cloned = ctx->mod->create<IfStatement>(
ctx->Clone(source()), ctx->Clone(condition_), ctx->Clone(body_)); ctx->Clone(source()), ctx->Clone(condition_), ctx->Clone(body_),
cloned->else_statements_ = ctx->Clone(else_statements_); ctx->Clone(else_statements_));
return cloned; return cloned;
} }

View File

@ -29,17 +29,15 @@ namespace ast {
/// An if statement /// An if statement
class IfStatement : public Castable<IfStatement, Statement> { class IfStatement : public Castable<IfStatement, Statement> {
public: public:
/// Constructor
/// @param condition the if condition
/// @param body the if body
IfStatement(Expression* condition, BlockStatement* body);
/// Constructor /// Constructor
/// @param source the source information /// @param source the source information
/// @param condition the if condition /// @param condition the if condition
/// @param body the if body /// @param body the if body
/// @param else_stmts the else statements
IfStatement(const Source& source, IfStatement(const Source& source,
Expression* condition, Expression* condition,
BlockStatement* body); BlockStatement* body,
ElseStatementList else_stmts);
/// Move constructor /// Move constructor
IfStatement(IfStatement&&); IfStatement(IfStatement&&);
~IfStatement() override; ~IfStatement() override;
@ -51,11 +49,6 @@ class IfStatement : public Castable<IfStatement, Statement> {
/// @returns the if body /// @returns the if body
BlockStatement* body() { return body_; } BlockStatement* body() { return body_; }
/// Sets the else statements
/// @param else_statements the else statements to set
void set_else_statements(ElseStatementList else_statements) {
else_statements_ = std::move(else_statements);
}
/// @returns the else statements /// @returns the else statements
const ElseStatementList& else_statements() const { return else_statements_; } const ElseStatementList& else_statements() const { return else_statements_; }
/// @returns the else statements /// @returns the else statements

View File

@ -25,30 +25,20 @@ namespace {
using IfStatementTest = TestHelper; using IfStatementTest = TestHelper;
TEST_F(IfStatementTest, Creation) { TEST_F(IfStatementTest, Creation) {
auto* cond = create<IdentifierExpression>("cond");
auto* body = create<BlockStatement>();
auto* discard = create<DiscardStatement>();
body->append(discard);
IfStatement stmt(cond, body);
EXPECT_EQ(stmt.condition(), cond);
ASSERT_EQ(stmt.body()->size(), 1u);
EXPECT_EQ(stmt.body()->get(0), discard);
}
TEST_F(IfStatementTest, Creation_WithSource) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>("cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
IfStatement stmt(Source{Source::Location{20, 2}}, cond, body); IfStatement stmt(Source{Source::Location{20, 2}}, cond, body,
ElseStatementList{});
auto src = stmt.source(); auto src = stmt.source();
EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u); EXPECT_EQ(src.range.begin.column, 2u);
} }
TEST_F(IfStatementTest, IsIf) { TEST_F(IfStatementTest, IsIf) {
IfStatement stmt(nullptr, create<BlockStatement>()); IfStatement stmt(Source{}, nullptr, create<BlockStatement>(),
ElseStatementList{});
EXPECT_TRUE(stmt.Is<IfStatement>()); EXPECT_TRUE(stmt.Is<IfStatement>());
} }
@ -57,7 +47,7 @@ TEST_F(IfStatementTest, IsValid) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
IfStatement stmt(cond, body); IfStatement stmt(Source{}, cond, body, ElseStatementList{});
EXPECT_TRUE(stmt.IsValid()); EXPECT_TRUE(stmt.IsValid());
} }
@ -66,13 +56,13 @@ TEST_F(IfStatementTest, IsValid_WithElseStatements) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
ElseStatementList else_stmts; IfStatement stmt(
else_stmts.push_back(create<ElseStatement>( Source{}, cond, body,
create<IdentifierExpression>("Ident"), create<BlockStatement>())); {
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>())); create<ElseStatement>(create<IdentifierExpression>("Ident"),
create<BlockStatement>()),
IfStatement stmt(cond, body); create<ElseStatement>(create<BlockStatement>()),
stmt.set_else_statements(else_stmts); });
EXPECT_TRUE(stmt.IsValid()); EXPECT_TRUE(stmt.IsValid());
} }
@ -80,7 +70,7 @@ TEST_F(IfStatementTest, IsValid_MissingCondition) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
IfStatement stmt(nullptr, body); IfStatement stmt(Source{}, nullptr, body, ElseStatementList{});
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -89,7 +79,7 @@ TEST_F(IfStatementTest, IsValid_InvalidCondition) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
IfStatement stmt(cond, body); IfStatement stmt(Source{}, cond, body, ElseStatementList{});
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -99,7 +89,7 @@ TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
body->append(nullptr); body->append(nullptr);
IfStatement stmt(cond, body); IfStatement stmt(Source{}, cond, body, ElseStatementList{});
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -107,9 +97,10 @@ TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>("cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
body->append(create<IfStatement>(nullptr, create<BlockStatement>())); body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
ast::ElseStatementList{}));
IfStatement stmt(cond, body); IfStatement stmt(Source{}, cond, body, ElseStatementList{});
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -118,14 +109,14 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
ElseStatementList else_stmts; IfStatement stmt(
else_stmts.push_back(create<ElseStatement>( Source{}, cond, body,
create<IdentifierExpression>("Ident"), create<BlockStatement>())); {
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>())); create<ElseStatement>(create<IdentifierExpression>("Ident"),
else_stmts.push_back(nullptr); create<BlockStatement>()),
create<ElseStatement>(create<BlockStatement>()),
IfStatement stmt(cond, body); nullptr,
stmt.set_else_statements(else_stmts); });
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -134,12 +125,11 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
ElseStatementList else_stmts; IfStatement stmt(Source{}, cond, body,
else_stmts.push_back(create<ElseStatement>(create<IdentifierExpression>(""), {
create<BlockStatement>())); create<ElseStatement>(create<IdentifierExpression>(""),
create<BlockStatement>()),
IfStatement stmt(cond, body); });
stmt.set_else_statements(else_stmts);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -148,12 +138,11 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
ElseStatementList else_stmts; IfStatement stmt(Source{}, cond, body,
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>())); {
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>())); create<ElseStatement>(create<BlockStatement>()),
create<ElseStatement>(create<BlockStatement>()),
IfStatement stmt(cond, body); });
stmt.set_else_statements(else_stmts);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -162,13 +151,13 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
ElseStatementList else_stmts; IfStatement stmt(
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>())); Source{}, cond, body,
else_stmts.push_back(create<ElseStatement>( {
create<IdentifierExpression>("ident"), create<BlockStatement>())); create<ElseStatement>(create<BlockStatement>()),
create<ElseStatement>(create<IdentifierExpression>("ident"),
IfStatement stmt(cond, body); create<BlockStatement>()),
stmt.set_else_statements(else_stmts); });
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -177,7 +166,7 @@ TEST_F(IfStatementTest, ToStr) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
IfStatement stmt(cond, body); IfStatement stmt(Source{}, cond, body, ElseStatementList{});
std::ostringstream out; std::ostringstream out;
stmt.to_str(out, 2); stmt.to_str(out, 2);
@ -204,13 +193,12 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) {
else_body->append(create<DiscardStatement>()); else_body->append(create<DiscardStatement>());
else_body->append(create<DiscardStatement>()); else_body->append(create<DiscardStatement>());
ElseStatementList else_stmts; IfStatement stmt(Source{}, cond, body,
else_stmts.push_back(create<ElseStatement>( {
create<IdentifierExpression>("ident"), else_if_body)); create<ElseStatement>(
else_stmts.push_back(create<ElseStatement>(else_body)); create<IdentifierExpression>("ident"), else_if_body),
create<ElseStatement>(else_body),
IfStatement stmt(cond, body); });
stmt.set_else_statements(else_stmts);
std::ostringstream out; std::ostringstream out;
stmt.to_str(out, 2); stmt.to_str(out, 2);

View File

@ -118,7 +118,8 @@ TEST_F(LoopStatementTest, IsValid_NullBodyStatement) {
TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) { TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
body->append(create<IfStatement>(nullptr, create<BlockStatement>())); body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
ElseStatementList{}));
auto* continuing = create<BlockStatement>(); auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>()); continuing->append(create<DiscardStatement>());
@ -145,7 +146,8 @@ TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) {
auto* continuing = create<BlockStatement>(); auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>()); continuing->append(create<DiscardStatement>());
continuing->append(create<IfStatement>(nullptr, create<BlockStatement>())); continuing->append(create<IfStatement>(
Source{}, nullptr, create<BlockStatement>(), ElseStatementList{}));
LoopStatement l(body, continuing); LoopStatement l(body, continuing);
EXPECT_FALSE(l.IsValid()); EXPECT_FALSE(l.IsValid());

View File

@ -572,7 +572,8 @@ void FunctionEmitter::PushGuard(const std::string& guard_name,
auto* cond = create<ast::IdentifierExpression>(guard_name); auto* cond = create<ast::IdentifierExpression>(guard_name);
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
AddStatement(create<ast::IfStatement>(cond, body)); AddStatement(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
PushNewStatementBlock(top.construct_, end_id, body, nullptr, nullptr); PushNewStatementBlock(top.construct_, end_id, body, nullptr, nullptr);
} }
@ -582,7 +583,8 @@ void FunctionEmitter::PushTrueGuard(uint32_t end_id) {
auto* cond = MakeTrue(); auto* cond = MakeTrue();
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
AddStatement(create<ast::IfStatement>(cond, body)); AddStatement(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
PushNewStatementBlock(top.construct_, end_id, body, nullptr, nullptr); PushNewStatementBlock(top.construct_, end_id, body, nullptr, nullptr);
} }
@ -2028,10 +2030,41 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
block_info.basic_block->terminator()->GetSingleWordInOperand(0); block_info.basic_block->terminator()->GetSingleWordInOperand(0);
auto* cond = MakeExpression(condition_id).expr; auto* cond = MakeExpression(condition_id).expr;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
auto* const if_stmt = AddStatement(create<ast::IfStatement>(cond, body))
->As<ast::IfStatement>();
// Generate the code for the condition. // Generate the code for the condition.
// Use the IfBuilder to create the if-statement. The IfBuilder is constructed
// as a std::shared_ptr and is captured by the then and else clause
// CompletionAction lambdas, and so will only be destructed when the last
// block is completed. The IfBuilder destructor constructs the IfStatement,
// inserting it at the current insertion point in the current
// ast::BlockStatement.
struct IfBuilder {
IfBuilder(ast::Module* mod,
StatementBlock& statement_block,
tint::ast::Expression* cond,
ast::BlockStatement* body)
: mod_(mod),
dst_block_(statement_block.statements_),
dst_block_insertion_point_(statement_block.statements_->size()),
cond_(cond),
body_(body) {}
~IfBuilder() {
dst_block_->insert(
dst_block_insertion_point_,
mod_->create<ast::IfStatement>(Source{}, cond_, body_, else_stmts_));
}
ast::Module* mod_;
ast::BlockStatement* dst_block_;
size_t dst_block_insertion_point_;
tint::ast::Expression* cond_;
ast::BlockStatement* body_;
ast::ElseStatementList else_stmts_;
};
auto if_builder = std::make_shared<IfBuilder>(
&ast_module_, statements_stack_.back(), cond, body);
// Compute the block IDs that should end the then-clause and the else-clause. // Compute the block IDs that should end the then-clause and the else-clause.
@ -2069,20 +2102,18 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
// Push statement blocks for the then-clause and the else-clause. // Push statement blocks for the then-clause and the else-clause.
// But make sure we do it in the right order. // But make sure we do it in the right order.
auto push_else = [this, if_builder, else_end, construct]() {
auto push_else = [this, if_stmt, else_end, construct]() {
// Push the else clause onto the stack first. // Push the else clause onto the stack first.
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
PushNewStatementBlock( PushNewStatementBlock(
construct, else_end, else_body, nullptr, [this, if_stmt, else_body]() { construct, else_end, else_body, nullptr,
[this, if_builder, else_body]() {
// Only set the else-clause if there are statements to fill it. // Only set the else-clause if there are statements to fill it.
if (!else_body->empty()) { if (!else_body->empty()) {
// The "else" consists of the statement list from the top of // The "else" consists of the statement list from the top of
// statments stack, without an elseif condition. // statements stack, without an elseif condition.
ast::ElseStatementList else_stmts; if_builder->else_stmts_.emplace_back(
else_stmts.emplace_back(
create<ast::ElseStatement>(nullptr, else_body)); create<ast::ElseStatement>(nullptr, else_body));
if_stmt->set_else_statements(else_stmts);
} }
}); });
}; };
@ -2121,7 +2152,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
} }
// Push the then clause onto the stack. // Push the then clause onto the stack.
PushNewStatementBlock(construct, then_end, body, nullptr, nullptr); PushNewStatementBlock(construct, then_end, body, nullptr, [if_builder] {});
} }
return success(); return success();
@ -2439,18 +2470,17 @@ ast::Statement* FunctionEmitter::MakeSimpleIf(ast::Expression* condition,
if ((then_stmt == nullptr) && (else_stmt == nullptr)) { if ((then_stmt == nullptr) && (else_stmt == nullptr)) {
return nullptr; return nullptr;
} }
auto* if_block = create<ast::BlockStatement>(); ast::ElseStatementList else_stmts;
auto* if_stmt = create<ast::IfStatement>(condition, if_block);
if (then_stmt != nullptr) {
if_block->append(then_stmt);
}
if (else_stmt != nullptr) { if (else_stmt != nullptr) {
auto* stmts = create<ast::BlockStatement>(); auto* stmts = create<ast::BlockStatement>();
stmts->append(else_stmt); stmts->append(else_stmt);
ast::ElseStatementList else_stmts;
else_stmts.emplace_back(create<ast::ElseStatement>(nullptr, stmts)); else_stmts.emplace_back(create<ast::ElseStatement>(nullptr, stmts));
if_stmt->set_else_statements(else_stmts); }
auto* if_block = create<ast::BlockStatement>();
auto* if_stmt =
create<ast::IfStatement>(Source{}, condition, if_block, else_stmts);
if (then_stmt != nullptr) {
if_block->append(then_stmt);
} }
return if_stmt; return if_stmt;
} }

View File

@ -1647,14 +1647,11 @@ Maybe<ast::IfStatement*> ParserImpl::if_stmt() {
auto el = else_stmt(); auto el = else_stmt();
if (el.errored) if (el.errored)
return Failure::kErrored; return Failure::kErrored;
if (el.matched)
auto* stmt = create<ast::IfStatement>(source, condition.value, body.value);
if (el.matched) {
elseif.value.push_back(el.value); elseif.value.push_back(el.value);
}
stmt->set_else_statements(elseif.value);
return stmt; return create<ast::IfStatement>(source, condition.value, body.value,
elseif.value);
} }
// elseif_stmt // elseif_stmt
@ -1945,8 +1942,9 @@ Maybe<ast::Statement*> ParserImpl::for_stmt() {
auto* break_body = create<ast::BlockStatement>(not_condition->source()); auto* break_body = create<ast::BlockStatement>(not_condition->source());
break_body->append(break_stmt); break_body->append(break_stmt);
// if (!condition) { break; } // if (!condition) { break; }
auto* break_if_not_condition = create<ast::IfStatement>( auto* break_if_not_condition =
not_condition->source(), not_condition, break_body); create<ast::IfStatement>(not_condition->source(), not_condition,
break_body, ast::ElseStatementList{});
body->insert(0, break_if_not_condition); body->insert(0, break_if_not_condition);
} }

View File

@ -225,9 +225,6 @@ TEST_F(TypeDeterminerTest, Stmt_If) {
create<ast::SintLiteral>(&i32, 3)), create<ast::SintLiteral>(&i32, 3)),
else_body); else_body);
ast::ElseStatementList else_stmts;
else_stmts.push_back(else_stmt);
auto* lhs = create<ast::ScalarConstructorExpression>( auto* lhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)); create<ast::SintLiteral>(&i32, 2));
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
@ -236,10 +233,10 @@ TEST_F(TypeDeterminerTest, Stmt_If) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(lhs, rhs)); body->append(create<ast::AssignmentStatement>(lhs, rhs));
ast::IfStatement stmt(create<ast::ScalarConstructorExpression>( ast::IfStatement stmt(Source{},
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3)), create<ast::SintLiteral>(&i32, 3)),
body); body, ast::ElseStatementList{else_stmt});
stmt.set_else_statements(else_stmts);
EXPECT_TRUE(td()->DetermineResultType(&stmt)); EXPECT_TRUE(td()->DetermineResultType(&stmt));
ASSERT_NE(stmt.condition()->result_type(), nullptr); ASSERT_NE(stmt.condition()->result_type(), nullptr);

View File

@ -353,7 +353,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
create<ast::FloatLiteral>(&f32, 3.14f)); create<ast::FloatLiteral>(&f32, 3.14f));
auto* outer_body = create<ast::BlockStatement>(); auto* outer_body = create<ast::BlockStatement>();
outer_body->append(create<ast::IfStatement>(cond, body)); outer_body->append(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
outer_body->append(create<ast::AssignmentStatement>( outer_body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs)); Source{Source::Location{12, 34}}, lhs, rhs));
@ -388,7 +389,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
auto* outer_body = create<ast::BlockStatement>(); auto* outer_body = create<ast::BlockStatement>();
outer_body->append(create<ast::VariableDeclStatement>(var)); outer_body->append(create<ast::VariableDeclStatement>(var));
outer_body->append(create<ast::IfStatement>(cond, body)); outer_body->append(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr); ASSERT_NE(rhs->result_type(), nullptr);
@ -554,7 +556,8 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
create<ast::FloatLiteral>(&f32, 3.14))); create<ast::FloatLiteral>(&f32, 3.14)));
auto* outer_body = create<ast::BlockStatement>(); auto* outer_body = create<ast::BlockStatement>();
outer_body->append(create<ast::IfStatement>(cond, body)); outer_body->append(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
outer_body->append(create<ast::VariableDeclStatement>( outer_body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var_a_float)); Source{Source::Location{12, 34}}, var_a_float));
@ -588,7 +591,8 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
auto* outer_body = create<ast::BlockStatement>(); auto* outer_body = create<ast::BlockStatement>();
outer_body->append(create<ast::VariableDeclStatement>(var_a_float)); outer_body->append(create<ast::VariableDeclStatement>(var_a_float));
outer_body->append(create<ast::IfStatement>(cond, body)); outer_body->append(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(outer_body)); EXPECT_FALSE(v()->ValidateStatements(outer_body));

View File

@ -388,21 +388,21 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
create<ast::IdentifierExpression>("c")), create<ast::IdentifierExpression>("c")),
body); body);
ast::ElseStatementList else_stmts;
else_stmts.push_back(else_if_stmt);
else_stmts.push_back(else_stmt);
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append( body->append(
create<ast::ReturnStatement>(create<ast::ScalarConstructorExpression>( create<ast::ReturnStatement>(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
ast::IfStatement expr( ast::IfStatement expr(
Source{},
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,
create<ast::IdentifierExpression>("a"), create<ast::IdentifierExpression>("a"),
create<ast::IdentifierExpression>("b")), create<ast::IdentifierExpression>("b")),
body); body,
expr.set_else_statements(else_stmts); {
else_if_stmt,
else_stmt,
});
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a; EXPECT_EQ(result(), R"(bool _tint_tmp = a;

View File

@ -889,12 +889,13 @@ TEST_F(HlslGeneratorImplTest_Function,
list->append(create<ast::ReturnStatement>()); list->append(create<ast::ReturnStatement>());
body->append(create<ast::IfStatement>( body->append(create<ast::IfStatement>(
Source{},
create<ast::BinaryExpression>(ast::BinaryOp::kEqual, create<ast::BinaryExpression>(ast::BinaryOp::kEqual,
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)), create<ast::SintLiteral>(&i32, 1)),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1))), create<ast::SintLiteral>(&i32, 1))),
list)); list, ast::ElseStatementList{}));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
auto* func_1 = create<ast::Function>("ep_1", params, &void_type, body); auto* func_1 = create<ast::Function>("ep_1", params, &void_type, body);

View File

@ -31,7 +31,7 @@ TEST_F(HlslGeneratorImplTest_If, Emit_If) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
ast::IfStatement i(cond, body); ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &i)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, &i)) << gen.error();
@ -46,15 +46,12 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses;
elses.push_back(create<ast::ElseStatement>(else_cond, else_body));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
ast::IfStatement i(cond, body); ast::IfStatement i(Source{}, cond, body,
i.set_else_statements(elses); {create<ast::ElseStatement>(else_cond, else_body)});
gen.increment_indent(); gen.increment_indent();
@ -73,15 +70,12 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses;
elses.push_back(create<ast::ElseStatement>(else_body));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
ast::IfStatement i(cond, body); ast::IfStatement i(Source{}, cond, body,
i.set_else_statements(elses); {create<ast::ElseStatement>(else_body)});
gen.increment_indent(); gen.increment_indent();
@ -103,16 +97,15 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
auto* else_body_2 = create<ast::BlockStatement>(); auto* else_body_2 = create<ast::BlockStatement>();
else_body_2->append(create<ast::ReturnStatement>()); else_body_2->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses;
elses.push_back(create<ast::ElseStatement>(else_cond, else_body));
elses.push_back(create<ast::ElseStatement>(else_body_2));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
ast::IfStatement i(cond, body); ast::IfStatement i(Source{}, cond, body,
i.set_else_statements(elses); {
create<ast::ElseStatement>(else_cond, else_body),
create<ast::ElseStatement>(else_body_2),
});
gen.increment_indent(); gen.increment_indent();

View File

@ -911,12 +911,13 @@ TEST_F(MslGeneratorImplTest,
list->append(create<ast::ReturnStatement>()); list->append(create<ast::ReturnStatement>());
body->append(create<ast::IfStatement>( body->append(create<ast::IfStatement>(
Source{},
create<ast::BinaryExpression>(ast::BinaryOp::kEqual, create<ast::BinaryExpression>(ast::BinaryOp::kEqual,
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)), create<ast::SintLiteral>(&i32, 1)),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1))), create<ast::SintLiteral>(&i32, 1))),
list)); list, ast::ElseStatementList{}));
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());

View File

@ -33,7 +33,7 @@ TEST_F(MslGeneratorImplTest, Emit_If) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
ast::IfStatement i(cond, body); ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
gen.increment_indent(); gen.increment_indent();
@ -49,15 +49,12 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses;
elses.push_back(create<ast::ElseStatement>(else_cond, else_body));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
ast::IfStatement i(cond, body); ast::IfStatement i(Source{}, cond, body,
i.set_else_statements(elses); {create<ast::ElseStatement>(else_cond, else_body)});
gen.increment_indent(); gen.increment_indent();
@ -74,15 +71,12 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses;
elses.push_back(create<ast::ElseStatement>(else_body));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
ast::IfStatement i(cond, body); ast::IfStatement i(Source{}, cond, body,
i.set_else_statements(elses); {create<ast::ElseStatement>(else_body)});
gen.increment_indent(); gen.increment_indent();
@ -104,16 +98,15 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
auto* else_body_2 = create<ast::BlockStatement>(); auto* else_body_2 = create<ast::BlockStatement>();
else_body_2->append(create<ast::ReturnStatement>()); else_body_2->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses;
elses.push_back(create<ast::ElseStatement>(else_cond, else_body));
elses.push_back(create<ast::ElseStatement>(else_body_2));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
ast::IfStatement i(cond, body); ast::IfStatement i(Source{}, cond, body,
i.set_else_statements(elses); {
create<ast::ElseStatement>(else_cond, else_body),
create<ast::ElseStatement>(else_body_2),
});
gen.increment_indent(); gen.increment_indent();

View File

@ -48,7 +48,8 @@ TEST_F(BuilderTest, If_Empty) {
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
ast::IfStatement expr(cond, create<ast::BlockStatement>()); ast::IfStatement expr(Source{}, cond, create<ast::BlockStatement>(),
ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -85,7 +86,7 @@ TEST_F(BuilderTest, If_WithStatements) {
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
ast::IfStatement expr(cond, body); ast::IfStatement expr(Source{}, cond, body, ast::ElseStatementList{});
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -135,14 +136,11 @@ TEST_F(BuilderTest, If_WithElse) {
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
ast::ElseStatementList else_stmts;
else_stmts.push_back(create<ast::ElseStatement>(else_body));
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
ast::IfStatement expr(cond, body); ast::IfStatement expr(Source{}, cond, body,
expr.set_else_statements(else_stmts); {create<ast::ElseStatement>(else_body)});
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
@ -200,14 +198,11 @@ TEST_F(BuilderTest, If_WithElseIf) {
auto* else_cond = create<ast::ScalarConstructorExpression>( auto* else_cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
ast::ElseStatementList else_stmts;
else_stmts.push_back(create<ast::ElseStatement>(else_cond, else_body));
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
ast::IfStatement expr(cond, body); ast::IfStatement expr(Source{}, cond, body,
expr.set_else_statements(else_stmts); {create<ast::ElseStatement>(else_cond, else_body)});
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
@ -285,18 +280,16 @@ TEST_F(BuilderTest, If_WithMultiple) {
auto* elseif_2_cond = create<ast::ScalarConstructorExpression>( auto* elseif_2_cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, false)); create<ast::BoolLiteral>(&bool_type, false));
ast::ElseStatementList else_stmts;
else_stmts.push_back(
create<ast::ElseStatement>(elseif_1_cond, elseif_1_body));
else_stmts.push_back(
create<ast::ElseStatement>(elseif_2_cond, elseif_2_body));
else_stmts.push_back(create<ast::ElseStatement>(else_body));
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
ast::IfStatement expr(cond, body); ast::IfStatement expr(
expr.set_else_statements(else_stmts); Source{}, cond, body,
{
create<ast::ElseStatement>(elseif_1_cond, elseif_1_body),
create<ast::ElseStatement>(elseif_2_cond, elseif_2_body),
create<ast::ElseStatement>(else_body),
});
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
@ -360,7 +353,8 @@ TEST_F(BuilderTest, If_WithBreak) {
auto* if_body = create<ast::BlockStatement>(); auto* if_body = create<ast::BlockStatement>();
if_body->append(create<ast::BreakStatement>()); if_body->append(create<ast::BreakStatement>());
auto* if_stmt = create<ast::IfStatement>(cond, if_body); auto* if_stmt = create<ast::IfStatement>(Source{}, cond, if_body,
ast::ElseStatementList{});
auto* loop_body = create<ast::BlockStatement>(); auto* loop_body = create<ast::BlockStatement>();
loop_body->append(if_stmt); loop_body->append(if_stmt);
@ -407,11 +401,9 @@ TEST_F(BuilderTest, If_WithElseBreak) {
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::BreakStatement>()); else_body->append(create<ast::BreakStatement>());
ast::ElseStatementList else_stmts; auto* if_stmt = create<ast::IfStatement>(
else_stmts.push_back(create<ast::ElseStatement>(else_body)); Source{}, cond, create<ast::BlockStatement>(),
ast::ElseStatementList{create<ast::ElseStatement>(else_body)});
auto* if_stmt = create<ast::IfStatement>(cond, create<ast::BlockStatement>());
if_stmt->set_else_statements(else_stmts);
auto* loop_body = create<ast::BlockStatement>(); auto* loop_body = create<ast::BlockStatement>();
loop_body->append(if_stmt); loop_body->append(if_stmt);
@ -459,7 +451,8 @@ TEST_F(BuilderTest, If_WithContinue) {
auto* if_body = create<ast::BlockStatement>(); auto* if_body = create<ast::BlockStatement>();
if_body->append(create<ast::ContinueStatement>()); if_body->append(create<ast::ContinueStatement>());
auto* if_stmt = create<ast::IfStatement>(cond, if_body); auto* if_stmt = create<ast::IfStatement>(Source{}, cond, if_body,
ast::ElseStatementList{});
auto* loop_body = create<ast::BlockStatement>(); auto* loop_body = create<ast::BlockStatement>();
loop_body->append(if_stmt); loop_body->append(if_stmt);
@ -506,11 +499,9 @@ TEST_F(BuilderTest, If_WithElseContinue) {
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ContinueStatement>()); else_body->append(create<ast::ContinueStatement>());
ast::ElseStatementList else_stmts; auto* if_stmt = create<ast::IfStatement>(
else_stmts.push_back(create<ast::ElseStatement>(else_body)); Source{}, cond, create<ast::BlockStatement>(),
ast::ElseStatementList{create<ast::ElseStatement>(else_body)});
auto* if_stmt = create<ast::IfStatement>(cond, create<ast::BlockStatement>());
if_stmt->set_else_statements(else_stmts);
auto* loop_body = create<ast::BlockStatement>(); auto* loop_body = create<ast::BlockStatement>();
loop_body->append(if_stmt); loop_body->append(if_stmt);
@ -556,7 +547,7 @@ TEST_F(BuilderTest, If_WithReturn) {
auto* if_body = create<ast::BlockStatement>(); auto* if_body = create<ast::BlockStatement>();
if_body->append(create<ast::ReturnStatement>()); if_body->append(create<ast::ReturnStatement>());
ast::IfStatement expr(cond, if_body); ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -588,7 +579,7 @@ TEST_F(BuilderTest, If_WithReturnValue) {
auto* if_body = create<ast::BlockStatement>(); auto* if_body = create<ast::BlockStatement>();
if_body->append(create<ast::ReturnStatement>(cond2)); if_body->append(create<ast::ReturnStatement>(cond2));
ast::IfStatement expr(cond, if_body); ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -618,8 +609,9 @@ TEST_F(BuilderTest, If_WithLoad_Bug327) {
create<ast::Variable>("a", ast::StorageClass::kFunction, &bool_type); create<ast::Variable>("a", ast::StorageClass::kFunction, &bool_type);
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
ast::IfStatement expr(create<ast::IdentifierExpression>("a"), ast::IfStatement expr(Source{}, create<ast::IdentifierExpression>("a"),
create<ast::BlockStatement>()); create<ast::BlockStatement>(),
ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();

View File

@ -447,9 +447,10 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
auto* case_1_body = create<ast::BlockStatement>(); auto* case_1_body = create<ast::BlockStatement>();
case_1_body->append( case_1_body->append(
create<ast::IfStatement>(create<ast::ScalarConstructorExpression>( create<ast::IfStatement>(Source{},
create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true)), create<ast::BoolLiteral>(&bool_type, true)),
if_body)); if_body, ast::ElseStatementList{}));
case_1_body->append( case_1_body->append(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),

View File

@ -32,7 +32,7 @@ TEST_F(WgslGeneratorImplTest, Emit_If) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
ast::IfStatement i(cond, body); ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
gen.increment_indent(); gen.increment_indent();
@ -48,15 +48,12 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithElseIf) {
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::DiscardStatement>()); else_body->append(create<ast::DiscardStatement>());
ast::ElseStatementList elses;
elses.push_back(create<ast::ElseStatement>(else_cond, else_body));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
ast::IfStatement i(cond, body); ast::IfStatement i(Source{}, cond, body,
i.set_else_statements(elses); {create<ast::ElseStatement>(else_cond, else_body)});
gen.increment_indent(); gen.increment_indent();
@ -73,15 +70,12 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::DiscardStatement>()); else_body->append(create<ast::DiscardStatement>());
ast::ElseStatementList elses;
elses.push_back(create<ast::ElseStatement>(else_body));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
ast::IfStatement i(cond, body); ast::IfStatement i(Source{}, cond, body,
i.set_else_statements(elses); {create<ast::ElseStatement>(else_body)});
gen.increment_indent(); gen.increment_indent();
@ -103,16 +97,15 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithMultiple) {
auto* else_body_2 = create<ast::BlockStatement>(); auto* else_body_2 = create<ast::BlockStatement>();
else_body_2->append(create<ast::DiscardStatement>()); else_body_2->append(create<ast::DiscardStatement>());
ast::ElseStatementList elses;
elses.push_back(create<ast::ElseStatement>(else_cond, else_body));
elses.push_back(create<ast::ElseStatement>(else_body_2));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
ast::IfStatement i(cond, body); ast::IfStatement i(Source{}, cond, body,
i.set_else_statements(elses); {
create<ast::ElseStatement>(else_cond, else_body),
create<ast::ElseStatement>(else_body_2),
});
gen.increment_indent(); gen.increment_indent();