Remove BlockStatement::append()

Bug: tint:396
Bug: tint:390
Change-Id: I3b558a8961f9890f24d1aa3d6647ec095e5fe1cb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35421
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-12-14 20:25:27 +00:00 committed by Commit Bot service account
parent ed70caf6a5
commit db5ce658b5
60 changed files with 2696 additions and 2046 deletions

View File

@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::BlockStatement);
namespace tint { namespace tint {
namespace ast { namespace ast {
BlockStatement::BlockStatement(const Source& source) : Base(source) {}
BlockStatement::BlockStatement(const Source& source, BlockStatement::BlockStatement(const Source& source,
const StatementList& statements) const StatementList& statements)
: Base(source), statements_(std::move(statements)) {} : Base(source), statements_(std::move(statements)) {}
@ -33,9 +31,8 @@ BlockStatement::BlockStatement(BlockStatement&&) = default;
BlockStatement::~BlockStatement() = default; BlockStatement::~BlockStatement() = default;
BlockStatement* BlockStatement::Clone(CloneContext* ctx) const { BlockStatement* BlockStatement::Clone(CloneContext* ctx) const {
auto* cloned = ctx->mod->create<BlockStatement>(ctx->Clone(source())); return ctx->mod->create<BlockStatement>(ctx->Clone(source()),
cloned->statements_ = ctx->Clone(statements_); ctx->Clone(statements_));
return cloned;
} }
bool BlockStatement::IsValid() const { bool BlockStatement::IsValid() const {

View File

@ -29,19 +29,12 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
public: public:
/// Constructor /// Constructor
/// @param source the block statement source /// @param source the block statement source
explicit BlockStatement(const Source& source); /// @param statements the statements
/// Constructor
/// @param source the block statement source
/// @param statements the block statements
BlockStatement(const Source& source, const StatementList& statements); BlockStatement(const Source& source, const StatementList& statements);
/// Move constructor /// Move constructor
BlockStatement(BlockStatement&&); BlockStatement(BlockStatement&&);
~BlockStatement() override; ~BlockStatement() override;
/// Appends a statement to the block
/// @param stmt the statement to append
void append(Statement* stmt) { statements_.push_back(stmt); }
/// Insert a statement to the block /// Insert a statement to the block
/// @param index the index to insert at /// @param index the index to insert at
/// @param stmt the statement to insert /// @param stmt the statement to insert
@ -79,13 +72,9 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
const Statement* operator[](size_t idx) const { return statements_[idx]; } const Statement* operator[](size_t idx) const { return statements_[idx]; }
/// @returns the beginning iterator /// @returns the beginning iterator
std::vector<Statement*>::const_iterator begin() const { StatementList::const_iterator begin() const { return statements_.begin(); }
return statements_.begin();
}
/// @returns the ending iterator /// @returns the ending iterator
std::vector<Statement*>::const_iterator end() const { StatementList::const_iterator end() const { return statements_.end(); }
return statements_.end();
}
/// Clones this node and all transitive child nodes using the `CloneContext` /// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`. /// `ctx`.
@ -106,7 +95,7 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
private: private:
BlockStatement(const BlockStatement&) = delete; BlockStatement(const BlockStatement&) = delete;
std::vector<Statement*> statements_; StatementList statements_;
}; };
} // namespace ast } // namespace ast

View File

@ -31,8 +31,7 @@ TEST_F(BlockStatementTest, Creation) {
auto* d = create<DiscardStatement>(Source{}); auto* d = create<DiscardStatement>(Source{});
auto* ptr = d; auto* ptr = d;
BlockStatement b(Source{}); BlockStatement b(Source{}, StatementList{d});
b.append(d);
ASSERT_EQ(b.size(), 1u); ASSERT_EQ(b.size(), 1u);
EXPECT_EQ(b[0], ptr); EXPECT_EQ(b[0], ptr);
@ -43,7 +42,7 @@ TEST_F(BlockStatementTest, Creation_WithInsert) {
auto* s2 = create<DiscardStatement>(Source{}); auto* s2 = create<DiscardStatement>(Source{});
auto* s3 = create<DiscardStatement>(Source{}); auto* s3 = create<DiscardStatement>(Source{});
BlockStatement b(Source{}); BlockStatement b(Source{}, StatementList{});
b.insert(0, s1); b.insert(0, s1);
b.insert(0, s2); b.insert(0, s2);
b.insert(1, s3); b.insert(1, s3);
@ -57,46 +56,53 @@ TEST_F(BlockStatementTest, Creation_WithInsert) {
} }
TEST_F(BlockStatementTest, Creation_WithSource) { TEST_F(BlockStatementTest, Creation_WithSource) {
BlockStatement b(Source{Source::Location{20, 2}}); BlockStatement b(Source{Source::Location{20, 2}}, ast::StatementList{});
auto src = b.source(); auto src = b.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(BlockStatementTest, IsBlock) { TEST_F(BlockStatementTest, IsBlock) {
BlockStatement b(Source{}); BlockStatement b(Source{}, ast::StatementList{});
EXPECT_TRUE(b.Is<BlockStatement>()); EXPECT_TRUE(b.Is<BlockStatement>());
} }
TEST_F(BlockStatementTest, IsValid) { TEST_F(BlockStatementTest, IsValid) {
BlockStatement b(Source{}); BlockStatement b(Source{}, ast::StatementList{
b.append(create<DiscardStatement>(Source{})); create<DiscardStatement>(Source{}),
});
EXPECT_TRUE(b.IsValid()); EXPECT_TRUE(b.IsValid());
} }
TEST_F(BlockStatementTest, IsValid_Empty) { TEST_F(BlockStatementTest, IsValid_Empty) {
BlockStatement b(Source{}); BlockStatement b(Source{}, ast::StatementList{});
EXPECT_TRUE(b.IsValid()); EXPECT_TRUE(b.IsValid());
} }
TEST_F(BlockStatementTest, IsValid_NullBodyStatement) { TEST_F(BlockStatementTest, IsValid_NullBodyStatement) {
BlockStatement b(Source{}); BlockStatement b(Source{}, ast::StatementList{
b.append(create<DiscardStatement>(Source{})); create<DiscardStatement>(Source{}),
b.append(nullptr); nullptr,
});
EXPECT_FALSE(b.IsValid()); EXPECT_FALSE(b.IsValid());
} }
TEST_F(BlockStatementTest, IsValid_InvalidBodyStatement) { TEST_F(BlockStatementTest, IsValid_InvalidBodyStatement) {
BlockStatement b(Source{}); BlockStatement b(
b.append(create<IfStatement>(Source{}, nullptr, Source{},
create<BlockStatement>(Source{}), ast::StatementList{
ElseStatementList{})); create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}),
ElseStatementList{}),
});
EXPECT_FALSE(b.IsValid()); EXPECT_FALSE(b.IsValid());
} }
TEST_F(BlockStatementTest, ToStr) { TEST_F(BlockStatementTest, ToStr) {
BlockStatement b(Source{}); BlockStatement b(Source{}, ast::StatementList{
b.append(create<DiscardStatement>(Source{})); create<DiscardStatement>(Source{}),
});
std::ostringstream out; std::ostringstream out;
b.to_str(out, 2); b.to_str(out, 2);

View File

@ -35,9 +35,8 @@ TEST_F(CaseStatementTest, Creation_i32) {
auto* selector = create<SintLiteral>(Source{}, &i32, 2); auto* selector = create<SintLiteral>(Source{}, &i32, 2);
b.push_back(selector); b.push_back(selector);
auto* body = create<BlockStatement>(Source{});
auto* discard = create<DiscardStatement>(Source{}); auto* discard = create<DiscardStatement>(Source{});
body->append(discard); auto* body = create<BlockStatement>(Source{}, StatementList{discard});
CaseStatement c(Source{}, b, body); CaseStatement c(Source{}, b, body);
ASSERT_EQ(c.selectors().size(), 1u); ASSERT_EQ(c.selectors().size(), 1u);
@ -53,9 +52,8 @@ TEST_F(CaseStatementTest, Creation_u32) {
auto* selector = create<SintLiteral>(Source{}, &u32, 2); auto* selector = create<SintLiteral>(Source{}, &u32, 2);
b.push_back(selector); b.push_back(selector);
auto* body = create<BlockStatement>(Source{});
auto* discard = create<DiscardStatement>(Source{}); auto* discard = create<DiscardStatement>(Source{});
body->append(discard); auto* body = create<BlockStatement>(Source{}, StatementList{discard});
CaseStatement c(Source{}, b, body); CaseStatement c(Source{}, b, body);
ASSERT_EQ(c.selectors().size(), 1u); ASSERT_EQ(c.selectors().size(), 1u);
@ -69,9 +67,10 @@ TEST_F(CaseStatementTest, Creation_WithSource) {
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(Source{}, &i32, 2)); b.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
CaseStatement c(Source{Source::Location{20, 2}}, b, body); CaseStatement c(Source{Source::Location{20, 2}}, b, body);
auto src = c.source(); auto src = c.source();
EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.line, 20u);
@ -79,9 +78,10 @@ TEST_F(CaseStatementTest, Creation_WithSource) {
} }
TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) { TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
CaseStatement c(Source{}, CaseSelectorList{}, body); CaseStatement c(Source{}, CaseSelectorList{}, body);
EXPECT_TRUE(c.IsDefault()); EXPECT_TRUE(c.IsDefault());
} }
@ -91,19 +91,20 @@ TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(Source{}, &i32, 2)); b.push_back(create<SintLiteral>(Source{}, &i32, 2));
CaseStatement c(Source{}, b, create<BlockStatement>(Source{})); CaseStatement c(Source{}, b,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_FALSE(c.IsDefault()); EXPECT_FALSE(c.IsDefault());
} }
TEST_F(CaseStatementTest, IsCase) { TEST_F(CaseStatementTest, IsCase) {
CaseStatement c(Source{}, CaseSelectorList{}, CaseStatement c(Source{}, CaseSelectorList{},
create<BlockStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(c.Is<CaseStatement>()); EXPECT_TRUE(c.Is<CaseStatement>());
} }
TEST_F(CaseStatementTest, IsValid) { TEST_F(CaseStatementTest, IsValid) {
CaseStatement c(Source{}, CaseSelectorList{}, CaseStatement c(Source{}, CaseSelectorList{},
create<BlockStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(c.IsValid()); EXPECT_TRUE(c.IsValid());
} }
@ -112,10 +113,11 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) {
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(Source{}, &i32, 2)); b.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
body->append(nullptr); create<DiscardStatement>(Source{}),
nullptr,
});
CaseStatement c(Source{}, b, body); CaseStatement c(Source{}, b, body);
EXPECT_FALSE(c.IsValid()); EXPECT_FALSE(c.IsValid());
} }
@ -125,11 +127,13 @@ TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) {
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(Source{}, &i32, 2)); b.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<IfStatement>(Source{}, nullptr, Source{},
create<BlockStatement>(Source{}), StatementList{
ElseStatementList{})); create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}),
ElseStatementList{}),
});
CaseStatement c(Source{}, {b}, body); CaseStatement c(Source{}, {b}, body);
EXPECT_FALSE(c.IsValid()); EXPECT_FALSE(c.IsValid());
} }
@ -139,8 +143,10 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) {
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(Source{}, &i32, -2)); b.push_back(create<SintLiteral>(Source{}, &i32, -2));
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
CaseStatement c(Source{}, {b}, body); CaseStatement c(Source{}, {b}, body);
std::ostringstream out; std::ostringstream out;
@ -156,8 +162,10 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) {
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<UintLiteral>(Source{}, &u32, 2)); b.push_back(create<UintLiteral>(Source{}, &u32, 2));
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
CaseStatement c(Source{}, {b}, body); CaseStatement c(Source{}, {b}, body);
std::ostringstream out; std::ostringstream out;
@ -175,8 +183,10 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
b.push_back(create<SintLiteral>(Source{}, &i32, 1)); b.push_back(create<SintLiteral>(Source{}, &i32, 1));
b.push_back(create<SintLiteral>(Source{}, &i32, 2)); b.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
CaseStatement c(Source{}, b, body); CaseStatement c(Source{}, b, body);
std::ostringstream out; std::ostringstream out;
@ -188,8 +198,10 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
} }
TEST_F(CaseStatementTest, ToStr_WithoutSelectors) { TEST_F(CaseStatementTest, ToStr_WithoutSelectors) {
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
CaseStatement c(Source{}, CaseSelectorList{}, body); CaseStatement c(Source{}, CaseSelectorList{}, body);
std::ostringstream out; std::ostringstream out;

View File

@ -31,9 +31,10 @@ TEST_F(ElseStatementTest, Creation) {
type::Bool bool_type; type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>( auto* cond = create<ScalarConstructorExpression>(
Source{}, create<BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
auto* discard = body->get(0); auto* discard = body->get(0);
ElseStatement e(Source{}, cond, body); ElseStatement e(Source{}, cond, body);
@ -44,14 +45,15 @@ TEST_F(ElseStatementTest, Creation) {
TEST_F(ElseStatementTest, Creation_WithSource) { TEST_F(ElseStatementTest, Creation_WithSource) {
ElseStatement e(Source{Source::Location{20, 2}}, nullptr, ElseStatement e(Source{Source::Location{20, 2}}, nullptr,
create<BlockStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{}));
auto src = e.source(); auto src = e.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(ElseStatementTest, IsElse) { TEST_F(ElseStatementTest, IsElse) {
ElseStatement e(Source{}, nullptr, create<BlockStatement>(Source{})); ElseStatement e(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(e.Is<ElseStatement>()); EXPECT_TRUE(e.Is<ElseStatement>());
} }
@ -59,49 +61,57 @@ TEST_F(ElseStatementTest, HasCondition) {
type::Bool bool_type; type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>( auto* cond = create<ScalarConstructorExpression>(
Source{}, create<BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
ElseStatement e(Source{}, cond, create<BlockStatement>(Source{})); ElseStatement e(Source{}, cond,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(e.HasCondition()); EXPECT_TRUE(e.HasCondition());
} }
TEST_F(ElseStatementTest, HasContition_NullCondition) { TEST_F(ElseStatementTest, HasContition_NullCondition) {
ElseStatement e(Source{}, nullptr, create<BlockStatement>(Source{})); ElseStatement e(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_FALSE(e.HasCondition()); EXPECT_FALSE(e.HasCondition());
} }
TEST_F(ElseStatementTest, IsValid) { TEST_F(ElseStatementTest, IsValid) {
ElseStatement e(Source{}, nullptr, create<BlockStatement>(Source{})); ElseStatement e(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(e.IsValid()); EXPECT_TRUE(e.IsValid());
} }
TEST_F(ElseStatementTest, IsValid_WithBody) { TEST_F(ElseStatementTest, IsValid_WithBody) {
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
ElseStatement e(Source{}, nullptr, body); ElseStatement e(Source{}, nullptr, body);
EXPECT_TRUE(e.IsValid()); EXPECT_TRUE(e.IsValid());
} }
TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) { TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) {
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
body->append(nullptr); create<DiscardStatement>(Source{}),
nullptr,
});
ElseStatement e(Source{}, nullptr, body); ElseStatement e(Source{}, nullptr, body);
EXPECT_FALSE(e.IsValid()); EXPECT_FALSE(e.IsValid());
} }
TEST_F(ElseStatementTest, IsValid_InvalidCondition) { TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
auto* cond = create<ScalarConstructorExpression>(Source{}, nullptr); auto* cond = create<ScalarConstructorExpression>(Source{}, nullptr);
ElseStatement e(Source{}, cond, create<BlockStatement>(Source{})); ElseStatement e(Source{}, cond,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_FALSE(e.IsValid()); EXPECT_FALSE(e.IsValid());
} }
TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) { TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<IfStatement>(Source{}, nullptr, Source{},
create<BlockStatement>(Source{}), StatementList{
ElseStatementList{})); create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}),
ElseStatementList{}),
});
ElseStatement e(Source{}, nullptr, body); ElseStatement e(Source{}, nullptr, body);
EXPECT_FALSE(e.IsValid()); EXPECT_FALSE(e.IsValid());
} }
@ -110,9 +120,10 @@ TEST_F(ElseStatementTest, ToStr) {
type::Bool bool_type; type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>( auto* cond = create<ScalarConstructorExpression>(
Source{}, create<BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
ElseStatement e(Source{}, cond, body); ElseStatement e(Source{}, cond, body);
std::ostringstream out; std::ostringstream out;
e.to_str(out, 2); e.to_str(out, 2);
@ -128,9 +139,10 @@ TEST_F(ElseStatementTest, ToStr) {
} }
TEST_F(ElseStatementTest, ToStr_NoCondition) { TEST_F(ElseStatementTest, ToStr_NoCondition) {
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
ElseStatement e(Source{}, nullptr, body); ElseStatement e(Source{}, nullptr, body);
std::ostringstream out; std::ostringstream out;
e.to_str(out, 2); e.to_str(out, 2);

View File

@ -44,7 +44,8 @@ TEST_F(FunctionTest, Creation) {
auto* var = params[0]; auto* var = params[0];
Function f(Source{}, func_sym, "func", params, &void_type, Function f(Source{}, func_sym, "func", params, &void_type,
create<BlockStatement>(Source{}), FunctionDecorationList{}); create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{});
EXPECT_EQ(f.symbol(), func_sym); EXPECT_EQ(f.symbol(), func_sym);
EXPECT_EQ(f.name(), "func"); EXPECT_EQ(f.name(), "func");
ASSERT_EQ(f.params().size(), 1u); ASSERT_EQ(f.params().size(), 1u);
@ -64,7 +65,7 @@ TEST_F(FunctionTest, Creation_WithSource) {
ast::VariableDecorationList{})); ast::VariableDecorationList{}));
Function f(Source{Source::Location{20, 2}}, func_sym, "func", params, Function f(Source{Source::Location{20, 2}}, func_sym, "func", params,
&void_type, create<BlockStatement>(Source{}), &void_type, create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{}); FunctionDecorationList{});
auto src = f.source(); auto src = f.source();
EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.line, 20u);
@ -80,7 +81,8 @@ TEST_F(FunctionTest, AddDuplicateReferencedVariables) {
Variable v(Source{}, "var", StorageClass::kInput, &i32, false, nullptr, Variable v(Source{}, "var", StorageClass::kInput, &i32, false, nullptr,
ast::VariableDecorationList{}); ast::VariableDecorationList{});
Function f(Source{}, func_sym, "func", VariableList{}, &void_type, Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
create<BlockStatement>(Source{}), FunctionDecorationList{}); create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{});
f.add_referenced_module_variable(&v); f.add_referenced_module_variable(&v);
ASSERT_EQ(f.referenced_module_variables().size(), 1u); ASSERT_EQ(f.referenced_module_variables().size(), 1u);
@ -127,7 +129,8 @@ TEST_F(FunctionTest, GetReferenceLocations) {
}); });
Function f(Source{}, func_sym, "func", VariableList{}, &void_type, Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
create<BlockStatement>(Source{}), FunctionDecorationList{}); create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{});
f.add_referenced_module_variable(loc1); f.add_referenced_module_variable(loc1);
f.add_referenced_module_variable(builtin1); f.add_referenced_module_variable(builtin1);
@ -174,7 +177,8 @@ TEST_F(FunctionTest, GetReferenceBuiltins) {
}); });
Function f(Source{}, func_sym, "func", VariableList{}, &void_type, Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
create<BlockStatement>(Source{}), FunctionDecorationList{}); create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{});
f.add_referenced_module_variable(loc1); f.add_referenced_module_variable(loc1);
f.add_referenced_module_variable(builtin1); f.add_referenced_module_variable(builtin1);
@ -197,7 +201,8 @@ TEST_F(FunctionTest, AddDuplicateEntryPoints) {
auto main_sym = mod.RegisterSymbol("main"); auto main_sym = mod.RegisterSymbol("main");
Function f(Source{}, func_sym, "func", VariableList{}, &void_type, Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
create<BlockStatement>(Source{}), FunctionDecorationList{}); create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{});
f.add_ancestor_entry_point(main_sym); f.add_ancestor_entry_point(main_sym);
ASSERT_EQ(1u, f.ancestor_entry_points().size()); ASSERT_EQ(1u, f.ancestor_entry_points().size());
@ -219,8 +224,10 @@ TEST_F(FunctionTest, IsValid) {
false, nullptr, false, nullptr,
ast::VariableDecorationList{})); ast::VariableDecorationList{}));
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
Function f(Source{}, func_sym, "func", params, &void_type, body, Function f(Source{}, func_sym, "func", params, &void_type, body,
FunctionDecorationList{}); FunctionDecorationList{});
@ -238,10 +245,8 @@ TEST_F(FunctionTest, IsValid_InvalidName) {
false, nullptr, false, nullptr,
ast::VariableDecorationList{})); ast::VariableDecorationList{}));
auto* body = create<BlockStatement>(Source{}); Function f(Source{}, func_sym, "", params, &void_type,
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{}),
Function f(Source{}, func_sym, "", params, &void_type, body,
FunctionDecorationList{}); FunctionDecorationList{});
EXPECT_FALSE(f.IsValid()); EXPECT_FALSE(f.IsValid());
} }
@ -257,7 +262,8 @@ TEST_F(FunctionTest, IsValid_MissingReturnType) {
ast::VariableDecorationList{})); ast::VariableDecorationList{}));
Function f(Source{}, func_sym, "func", params, nullptr, Function f(Source{}, func_sym, "func", params, nullptr,
create<BlockStatement>(Source{}), FunctionDecorationList{}); create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{});
EXPECT_FALSE(f.IsValid()); EXPECT_FALSE(f.IsValid());
} }
@ -274,7 +280,8 @@ TEST_F(FunctionTest, IsValid_NullParam) {
params.push_back(nullptr); params.push_back(nullptr);
Function f(Source{}, func_sym, "func", params, &void_type, Function f(Source{}, func_sym, "func", params, &void_type,
create<BlockStatement>(Source{}), FunctionDecorationList{}); create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{});
EXPECT_FALSE(f.IsValid()); EXPECT_FALSE(f.IsValid());
} }
@ -289,7 +296,8 @@ TEST_F(FunctionTest, IsValid_InvalidParam) {
ast::VariableDecorationList{})); ast::VariableDecorationList{}));
Function f(Source{}, func_sym, "func", params, &void_type, Function f(Source{}, func_sym, "func", params, &void_type,
create<BlockStatement>(Source{}), FunctionDecorationList{}); create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{});
EXPECT_FALSE(f.IsValid()); EXPECT_FALSE(f.IsValid());
} }
@ -304,9 +312,11 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) {
false, nullptr, false, nullptr,
ast::VariableDecorationList{})); ast::VariableDecorationList{}));
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
body->append(nullptr); create<DiscardStatement>(Source{}),
nullptr,
});
Function f(Source{}, func_sym, "func", params, &void_type, body, Function f(Source{}, func_sym, "func", params, &void_type, body,
FunctionDecorationList{}); FunctionDecorationList{});
@ -325,9 +335,11 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) {
false, nullptr, false, nullptr,
ast::VariableDecorationList{})); ast::VariableDecorationList{}));
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
body->append(nullptr); create<DiscardStatement>(Source{}),
nullptr,
});
Function f(Source{}, func_sym, "func", params, &void_type, body, Function f(Source{}, func_sym, "func", params, &void_type, body,
FunctionDecorationList{}); FunctionDecorationList{});
@ -340,8 +352,10 @@ TEST_F(FunctionTest, ToStr) {
auto func_sym = mod.RegisterSymbol("func"); auto func_sym = mod.RegisterSymbol("func");
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
Function f(Source{}, func_sym, "func", {}, &void_type, body, Function f(Source{}, func_sym, "func", {}, &void_type, body,
FunctionDecorationList{}); FunctionDecorationList{});
@ -362,9 +376,10 @@ TEST_F(FunctionTest, ToStr_WithDecoration) {
auto func_sym = mod.RegisterSymbol("func"); auto func_sym = mod.RegisterSymbol("func");
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
Function f( Function f(
Source{}, func_sym, "func", {}, &void_type, body, Source{}, func_sym, "func", {}, &void_type, body,
FunctionDecorationList{create<WorkgroupDecoration>(2, 4, 6, Source{})}); FunctionDecorationList{create<WorkgroupDecoration>(2, 4, 6, Source{})});
@ -391,9 +406,10 @@ TEST_F(FunctionTest, ToStr_WithParams) {
false, nullptr, false, nullptr,
ast::VariableDecorationList{})); ast::VariableDecorationList{}));
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
Function f(Source{}, func_sym, "func", params, &void_type, body, Function f(Source{}, func_sym, "func", params, &void_type, body,
FunctionDecorationList{}); FunctionDecorationList{});
@ -419,7 +435,8 @@ TEST_F(FunctionTest, TypeName) {
auto func_sym = mod.RegisterSymbol("func"); auto func_sym = mod.RegisterSymbol("func");
Function f(Source{}, func_sym, "func", {}, &void_type, Function f(Source{}, func_sym, "func", {}, &void_type,
create<BlockStatement>(Source{}), FunctionDecorationList{}); create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{});
EXPECT_EQ(f.type_name(), "__func__void"); EXPECT_EQ(f.type_name(), "__func__void");
} }
@ -439,7 +456,8 @@ TEST_F(FunctionTest, TypeName_WithParams) {
ast::VariableDecorationList{})); ast::VariableDecorationList{}));
Function f(Source{}, func_sym, "func", params, &void_type, Function f(Source{}, func_sym, "func", params, &void_type,
create<BlockStatement>(Source{}), FunctionDecorationList{}); create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{});
EXPECT_EQ(f.type_name(), "__func__void__i32__f32"); EXPECT_EQ(f.type_name(), "__func__void__i32__f32");
} }
@ -449,9 +467,8 @@ TEST_F(FunctionTest, GetLastStatement) {
auto func_sym = mod.RegisterSymbol("func"); auto func_sym = mod.RegisterSymbol("func");
VariableList params; VariableList params;
auto* body = create<BlockStatement>(Source{});
auto* stmt = create<DiscardStatement>(Source{}); auto* stmt = create<DiscardStatement>(Source{});
body->append(stmt); auto* body = create<BlockStatement>(Source{}, StatementList{stmt});
Function f(Source{}, func_sym, "func", params, &void_type, body, Function f(Source{}, func_sym, "func", params, &void_type, body,
FunctionDecorationList{}); FunctionDecorationList{});
@ -464,7 +481,7 @@ TEST_F(FunctionTest, GetLastStatement_nullptr) {
auto func_sym = mod.RegisterSymbol("func"); auto func_sym = mod.RegisterSymbol("func");
VariableList params; VariableList params;
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(Source{}, StatementList{});
Function f(Source{}, func_sym, "func", params, &void_type, body, Function f(Source{}, func_sym, "func", params, &void_type, body,
FunctionDecorationList{}); FunctionDecorationList{});
@ -477,7 +494,8 @@ TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
auto func_sym = mod.RegisterSymbol("func"); auto func_sym = mod.RegisterSymbol("func");
Function f(Source{}, func_sym, "func", {}, &void_type, Function f(Source{}, func_sym, "func", {}, &void_type,
create<BlockStatement>(Source{}), FunctionDecorationList{}); create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{});
uint32_t x = 0; uint32_t x = 0;
uint32_t y = 0; uint32_t y = 0;
uint32_t z = 0; uint32_t z = 0;
@ -493,7 +511,7 @@ TEST_F(FunctionTest, WorkgroupSize) {
auto func_sym = mod.RegisterSymbol("func"); auto func_sym = mod.RegisterSymbol("func");
Function f(Source{}, func_sym, "func", {}, &void_type, Function f(Source{}, func_sym, "func", {}, &void_type,
create<BlockStatement>(Source{}), create<BlockStatement>(Source{}, StatementList{}),
{create<WorkgroupDecoration>(2u, 4u, 6u, Source{})}); {create<WorkgroupDecoration>(2u, 4u, 6u, Source{})});
uint32_t x = 0; uint32_t x = 0;

View File

@ -27,9 +27,8 @@ using IfStatementTest = TestHelper;
TEST_F(IfStatementTest, Creation) { TEST_F(IfStatementTest, Creation) {
auto* cond = create<IdentifierExpression>(Source{}, auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond"); mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{Source::Location{20, 2}}, cond, body, IfStatement stmt(Source{Source::Location{20, 2}}, cond, body,
ElseStatementList{}); ElseStatementList{});
auto src = stmt.source(); auto src = stmt.source();
@ -38,7 +37,8 @@ TEST_F(IfStatementTest, Creation) {
} }
TEST_F(IfStatementTest, IsIf) { TEST_F(IfStatementTest, IsIf) {
IfStatement stmt(Source{}, nullptr, create<BlockStatement>(Source{}), IfStatement stmt(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}),
ElseStatementList{}); ElseStatementList{});
EXPECT_TRUE(stmt.Is<IfStatement>()); EXPECT_TRUE(stmt.Is<IfStatement>());
} }
@ -46,9 +46,8 @@ TEST_F(IfStatementTest, IsIf) {
TEST_F(IfStatementTest, IsValid) { TEST_F(IfStatementTest, IsValid) {
auto* cond = create<IdentifierExpression>(Source{}, auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond"); mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body, ElseStatementList{}); IfStatement stmt(Source{}, cond, body, ElseStatementList{});
EXPECT_TRUE(stmt.IsValid()); EXPECT_TRUE(stmt.IsValid());
} }
@ -56,26 +55,25 @@ TEST_F(IfStatementTest, IsValid) {
TEST_F(IfStatementTest, IsValid_WithElseStatements) { TEST_F(IfStatementTest, IsValid_WithElseStatements) {
auto* cond = create<IdentifierExpression>(Source{}, auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond"); mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body, IfStatement stmt(Source{}, cond, body,
{ {
create<ElseStatement>( create<ElseStatement>(
Source{}, Source{},
create<IdentifierExpression>( create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("Ident"), "Ident"), Source{}, mod.RegisterSymbol("Ident"), "Ident"),
create<BlockStatement>(Source{})), create<BlockStatement>(Source{}, StatementList{})),
create<ElseStatement>(Source{}, nullptr, create<ElseStatement>(
create<BlockStatement>(Source{})), Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{})),
}); });
EXPECT_TRUE(stmt.IsValid()); EXPECT_TRUE(stmt.IsValid());
} }
TEST_F(IfStatementTest, IsValid_MissingCondition) { TEST_F(IfStatementTest, IsValid_MissingCondition) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, nullptr, body, ElseStatementList{}); IfStatement stmt(Source{}, nullptr, body, ElseStatementList{});
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -83,9 +81,8 @@ TEST_F(IfStatementTest, IsValid_MissingCondition) {
TEST_F(IfStatementTest, IsValid_InvalidCondition) { TEST_F(IfStatementTest, IsValid_InvalidCondition) {
auto* cond = auto* cond =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), ""); create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body, ElseStatementList{}); IfStatement stmt(Source{}, cond, body, ElseStatementList{});
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -93,10 +90,11 @@ TEST_F(IfStatementTest, IsValid_InvalidCondition) {
TEST_F(IfStatementTest, IsValid_NullBodyStatement) { TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
auto* cond = create<IdentifierExpression>(Source{}, auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond"); mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
body->append(nullptr); create<DiscardStatement>(Source{}),
nullptr,
});
IfStatement stmt(Source{}, cond, body, ElseStatementList{}); IfStatement stmt(Source{}, cond, body, ElseStatementList{});
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -104,12 +102,14 @@ TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) { TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
auto* cond = create<IdentifierExpression>(Source{}, auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond"); mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{},
body->append(create<IfStatement>(Source{}, nullptr, StatementList{
create<BlockStatement>(Source{}), create<DiscardStatement>(Source{}),
ast::ElseStatementList{})); create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}),
ast::ElseStatementList{}),
});
IfStatement stmt(Source{}, cond, body, ElseStatementList{}); IfStatement stmt(Source{}, cond, body, ElseStatementList{});
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -117,18 +117,18 @@ TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
TEST_F(IfStatementTest, IsValid_NullElseStatement) { TEST_F(IfStatementTest, IsValid_NullElseStatement) {
auto* cond = create<IdentifierExpression>(Source{}, auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond"); mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body, IfStatement stmt(Source{}, cond, body,
{ {
create<ElseStatement>( create<ElseStatement>(
Source{}, Source{},
create<IdentifierExpression>( create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("Ident"), "Ident"), Source{}, mod.RegisterSymbol("Ident"), "Ident"),
create<BlockStatement>(Source{})), create<BlockStatement>(Source{}, StatementList{})),
create<ElseStatement>(Source{}, nullptr, create<ElseStatement>(
create<BlockStatement>(Source{})), Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{})),
nullptr, nullptr,
}); });
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
@ -137,16 +137,15 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) {
TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
auto* cond = create<IdentifierExpression>(Source{}, auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond"); mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body,
IfStatement stmt(
Source{}, cond, body,
{ {
create<ElseStatement>(Source{}, create<ElseStatement>(
Source{},
create<IdentifierExpression>( create<IdentifierExpression>(
Source{}, mod.RegisterSymbol(""), ""), Source{}, mod.RegisterSymbol(""), ""),
create<BlockStatement>(Source{})), create<BlockStatement>(Source{}, StatementList{})),
}); });
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -154,15 +153,16 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
auto* cond = create<IdentifierExpression>(Source{}, auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond"); mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body, IfStatement stmt(Source{}, cond, body,
{ {
create<ElseStatement>(Source{}, nullptr, create<ElseStatement>(
create<BlockStatement>(Source{})), Source{}, nullptr,
create<ElseStatement>(Source{}, nullptr, create<BlockStatement>(Source{}, StatementList{})),
create<BlockStatement>(Source{})), create<ElseStatement>(
Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{})),
}); });
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -170,18 +170,18 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
TEST_F(IfStatementTest, IsValid_ElseNotLast) { TEST_F(IfStatementTest, IsValid_ElseNotLast) {
auto* cond = create<IdentifierExpression>(Source{}, auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond"); mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body, IfStatement stmt(Source{}, cond, body,
{ {
create<ElseStatement>(Source{}, nullptr, create<ElseStatement>(
create<BlockStatement>(Source{})), Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{})),
create<ElseStatement>( create<ElseStatement>(
Source{}, Source{},
create<IdentifierExpression>( create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident"), Source{}, mod.RegisterSymbol("Ident"), "Ident"),
create<BlockStatement>(Source{})), create<BlockStatement>(Source{}, StatementList{})),
}); });
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
@ -189,9 +189,8 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) {
TEST_F(IfStatementTest, ToStr) { TEST_F(IfStatementTest, ToStr) {
auto* cond = create<IdentifierExpression>(Source{}, auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond"); mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body, ElseStatementList{}); IfStatement stmt(Source{}, cond, body, ElseStatementList{});
std::ostringstream out; std::ostringstream out;
@ -210,16 +209,13 @@ TEST_F(IfStatementTest, ToStr) {
TEST_F(IfStatementTest, ToStr_WithElseStatements) { TEST_F(IfStatementTest, ToStr_WithElseStatements) {
auto* cond = create<IdentifierExpression>(Source{}, auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond"); mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* else_if_body = create<BlockStatement>(
auto* else_if_body = create<BlockStatement>(Source{}); Source{}, StatementList{create<DiscardStatement>(Source{})});
else_if_body->append(create<DiscardStatement>(Source{})); auto* else_body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{}),
auto* else_body = create<BlockStatement>(Source{}); create<DiscardStatement>(Source{})});
else_body->append(create<DiscardStatement>(Source{}));
else_body->append(create<DiscardStatement>(Source{}));
IfStatement stmt(Source{}, cond, body, IfStatement stmt(Source{}, cond, body,
{ {
create<ElseStatement>( create<ElseStatement>(

View File

@ -28,12 +28,12 @@ namespace {
using LoopStatementTest = TestHelper; using LoopStatementTest = TestHelper;
TEST_F(LoopStatementTest, Creation) { TEST_F(LoopStatementTest, Creation) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* b = body->last(); auto* b = body->last();
auto* continuing = create<BlockStatement>(Source{}); auto* continuing = create<BlockStatement>(
continuing->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, continuing); LoopStatement l(Source{}, body, continuing);
ASSERT_EQ(l.body()->size(), 1u); ASSERT_EQ(l.body()->size(), 1u);
@ -43,11 +43,11 @@ TEST_F(LoopStatementTest, Creation) {
} }
TEST_F(LoopStatementTest, Creation_WithSource) { TEST_F(LoopStatementTest, Creation_WithSource) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* continuing = create<BlockStatement>(Source{}); auto* continuing = create<BlockStatement>(
continuing->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{Source::Location{20, 2}}, body, continuing); LoopStatement l(Source{Source::Location{20, 2}}, body, continuing);
auto src = l.source(); auto src = l.source();
@ -56,110 +56,121 @@ TEST_F(LoopStatementTest, Creation_WithSource) {
} }
TEST_F(LoopStatementTest, IsLoop) { TEST_F(LoopStatementTest, IsLoop) {
LoopStatement l(Source{}, create<BlockStatement>(Source{}), LoopStatement l(Source{}, create<BlockStatement>(Source{}, StatementList{}),
create<BlockStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(l.Is<LoopStatement>()); EXPECT_TRUE(l.Is<LoopStatement>());
} }
TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) { TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, {}); LoopStatement l(Source{}, body, {});
EXPECT_FALSE(l.has_continuing()); EXPECT_FALSE(l.has_continuing());
} }
TEST_F(LoopStatementTest, HasContinuing_WithContinuing) { TEST_F(LoopStatementTest, HasContinuing_WithContinuing) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* continuing = create<BlockStatement>(Source{}); auto* continuing = create<BlockStatement>(
continuing->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, continuing); LoopStatement l(Source{}, body, continuing);
EXPECT_TRUE(l.has_continuing()); EXPECT_TRUE(l.has_continuing());
} }
TEST_F(LoopStatementTest, IsValid) { TEST_F(LoopStatementTest, IsValid) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* continuing = create<BlockStatement>(Source{}); auto* continuing = create<BlockStatement>(
continuing->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, continuing); LoopStatement l(Source{}, body, continuing);
EXPECT_TRUE(l.IsValid()); EXPECT_TRUE(l.IsValid());
} }
TEST_F(LoopStatementTest, IsValid_WithoutContinuing) { TEST_F(LoopStatementTest, IsValid_WithoutContinuing) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, create<BlockStatement>(Source{})); LoopStatement l(Source{}, body,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(l.IsValid()); EXPECT_TRUE(l.IsValid());
} }
TEST_F(LoopStatementTest, IsValid_WithoutBody) { TEST_F(LoopStatementTest, IsValid_WithoutBody) {
LoopStatement l(Source{}, create<BlockStatement>(Source{}), LoopStatement l(Source{}, create<BlockStatement>(Source{}, StatementList{}),
create<BlockStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(l.IsValid()); EXPECT_TRUE(l.IsValid());
} }
TEST_F(LoopStatementTest, IsValid_NullBodyStatement) { TEST_F(LoopStatementTest, IsValid_NullBodyStatement) {
auto* body = create<BlockStatement>(Source{}); auto* body =
body->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
body->append(nullptr); create<DiscardStatement>(Source{}),
nullptr,
});
auto* continuing = create<BlockStatement>(Source{}); auto* continuing = create<BlockStatement>(
continuing->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, continuing); LoopStatement l(Source{}, body, continuing);
EXPECT_FALSE(l.IsValid()); EXPECT_FALSE(l.IsValid());
} }
TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) { TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{},
body->append(create<IfStatement>(Source{}, nullptr, StatementList{
create<BlockStatement>(Source{}), create<DiscardStatement>(Source{}),
ElseStatementList{})); create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}),
ElseStatementList{}),
});
auto* continuing = create<BlockStatement>(Source{}); auto* continuing = create<BlockStatement>(
continuing->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, continuing); LoopStatement l(Source{}, body, continuing);
EXPECT_FALSE(l.IsValid()); EXPECT_FALSE(l.IsValid());
} }
TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) { TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* continuing = create<BlockStatement>(Source{}); auto* continuing =
continuing->append(create<DiscardStatement>(Source{})); create<BlockStatement>(Source{}, StatementList{
continuing->append(nullptr); create<DiscardStatement>(Source{}),
nullptr,
});
LoopStatement l(Source{}, body, continuing); LoopStatement l(Source{}, body, continuing);
EXPECT_FALSE(l.IsValid()); EXPECT_FALSE(l.IsValid());
} }
TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) { TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* continuing = create<BlockStatement>(Source{}); auto* continuing = create<BlockStatement>(
continuing->append(create<DiscardStatement>(Source{})); Source{},
continuing->append(create<IfStatement>(Source{}, nullptr, StatementList{
create<BlockStatement>(Source{}), create<DiscardStatement>(Source{}),
ElseStatementList{})); create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}),
ElseStatementList{}),
});
LoopStatement l(Source{}, body, continuing); LoopStatement l(Source{}, body, continuing);
EXPECT_FALSE(l.IsValid()); EXPECT_FALSE(l.IsValid());
} }
TEST_F(LoopStatementTest, ToStr) { TEST_F(LoopStatementTest, ToStr) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, {}); LoopStatement l(Source{}, body, {});
std::ostringstream out; std::ostringstream out;
@ -171,11 +182,11 @@ TEST_F(LoopStatementTest, ToStr) {
} }
TEST_F(LoopStatementTest, ToStr_WithContinuing) { TEST_F(LoopStatementTest, ToStr_WithContinuing) {
auto* body = create<BlockStatement>(Source{}); auto* body = create<BlockStatement>(
body->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* continuing = create<BlockStatement>(Source{}); auto* continuing = create<BlockStatement>(
continuing->append(create<DiscardStatement>(Source{})); Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, continuing); LoopStatement l(Source{}, body, continuing);
std::ostringstream out; std::ostringstream out;

View File

@ -49,8 +49,9 @@ TEST_F(ModuleTest, LookupFunction) {
Module m; Module m;
auto func_sym = m.RegisterSymbol("main"); auto func_sym = m.RegisterSymbol("main");
auto* func = create<Function>(Source{}, func_sym, "main", VariableList{}, auto* func =
&f32, create<BlockStatement>(Source{}), create<Function>(Source{}, func_sym, "main", VariableList{}, &f32,
create<BlockStatement>(Source{}, StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
m.AddFunction(func); m.AddFunction(func);
EXPECT_EQ(func, m.FindFunctionBySymbol(func_sym)); EXPECT_EQ(func, m.FindFunctionBySymbol(func_sym));
@ -133,7 +134,9 @@ TEST_F(ModuleTest, IsValid_Function) {
auto* func = create<Function>( auto* func = create<Function>(
Source{}, m.RegisterSymbol("main"), "main", VariableList(), &f32, Source{}, m.RegisterSymbol("main"), "main", VariableList(), &f32,
create<BlockStatement>(Source{}), ast::FunctionDecorationList{}); create<BlockStatement>(Source{}, StatementList{}),
ast::FunctionDecorationList{});
m.AddFunction(func); m.AddFunction(func);
EXPECT_TRUE(m.IsValid()); EXPECT_TRUE(m.IsValid());
} }

View File

@ -37,8 +37,8 @@ TEST_F(SwitchStatementTest, Creation) {
auto* ident = create<IdentifierExpression>( auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident"); Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body; CaseStatementList body;
auto* case_stmt = auto* case_stmt = create<CaseStatement>(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})); Source{}, lit, create<BlockStatement>(Source{}, StatementList{}));
body.push_back(case_stmt); body.push_back(case_stmt);
SwitchStatement stmt(Source{}, ident, body); SwitchStatement stmt(Source{}, ident, body);
@ -67,8 +67,8 @@ TEST_F(SwitchStatementTest, IsSwitch) {
auto* ident = create<IdentifierExpression>( auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident"); Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body; CaseStatementList body;
body.push_back( body.push_back(create<CaseStatement>(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{}))); Source{}, lit, create<BlockStatement>(Source{}, StatementList{})));
SwitchStatement stmt(Source{}, ident, body); SwitchStatement stmt(Source{}, ident, body);
EXPECT_TRUE(stmt.Is<SwitchStatement>()); EXPECT_TRUE(stmt.Is<SwitchStatement>());
@ -83,8 +83,8 @@ TEST_F(SwitchStatementTest, IsValid) {
auto* ident = create<IdentifierExpression>( auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident"); Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body; CaseStatementList body;
body.push_back( body.push_back(create<CaseStatement>(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{}))); Source{}, lit, create<BlockStatement>(Source{}, StatementList{})));
SwitchStatement stmt(Source{}, ident, body); SwitchStatement stmt(Source{}, ident, body);
EXPECT_TRUE(stmt.IsValid()); EXPECT_TRUE(stmt.IsValid());
@ -97,8 +97,8 @@ TEST_F(SwitchStatementTest, IsValid_Null_Condition) {
lit.push_back(create<SintLiteral>(Source{}, &i32, 2)); lit.push_back(create<SintLiteral>(Source{}, &i32, 2));
CaseStatementList body; CaseStatementList body;
body.push_back( body.push_back(create<CaseStatement>(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{}))); Source{}, lit, create<BlockStatement>(Source{}, StatementList{})));
SwitchStatement stmt(Source{}, nullptr, body); SwitchStatement stmt(Source{}, nullptr, body);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
@ -113,8 +113,8 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) {
auto* ident = auto* ident =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), ""); create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
CaseStatementList body; CaseStatementList body;
body.push_back( body.push_back(create<CaseStatement>(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{}))); Source{}, lit, create<BlockStatement>(Source{}, StatementList{})));
SwitchStatement stmt(Source{}, ident, body); SwitchStatement stmt(Source{}, ident, body);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
@ -129,8 +129,8 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
auto* ident = create<IdentifierExpression>( auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident"); Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body; CaseStatementList body;
body.push_back( body.push_back(create<CaseStatement>(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{}))); Source{}, lit, create<BlockStatement>(Source{}, StatementList{})));
body.push_back(nullptr); body.push_back(nullptr);
SwitchStatement stmt(Source{}, ident, body); SwitchStatement stmt(Source{}, ident, body);
@ -141,9 +141,9 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) {
auto* ident = create<IdentifierExpression>( auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident"); Source{}, mod.RegisterSymbol("ident"), "ident");
auto* case_body = create<BlockStatement>(Source{}); auto* case_body = create<BlockStatement>(Source{}, StatementList{
case_body->append(nullptr); nullptr,
});
CaseStatementList body; CaseStatementList body;
body.push_back( body.push_back(
create<CaseStatement>(Source{}, CaseSelectorList{}, case_body)); create<CaseStatement>(Source{}, CaseSelectorList{}, case_body));
@ -176,8 +176,8 @@ TEST_F(SwitchStatementTest, ToStr) {
auto* ident = create<IdentifierExpression>( auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident"); Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body; CaseStatementList body;
body.push_back( body.push_back(create<CaseStatement>(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{}))); Source{}, lit, create<BlockStatement>(Source{}, StatementList{})));
SwitchStatement stmt(Source{}, ident, body); SwitchStatement stmt(Source{}, ident, body);
std::ostringstream out; std::ostringstream out;

View File

@ -81,8 +81,10 @@ class InspectorHelper {
ast::Function* MakeEmptyBodyFunction( ast::Function* MakeEmptyBodyFunction(
std::string name, std::string name,
ast::FunctionDecorationList decorations = {}) { ast::FunctionDecorationList decorations = {}) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
return create<ast::Function>(Source{}, mod()->RegisterSymbol(name), name, return create<ast::Function>(Source{}, mod()->RegisterSymbol(name), name,
ast::VariableList(), void_type(), body, ast::VariableList(), void_type(), body,
decorations); decorations);
@ -97,13 +99,15 @@ class InspectorHelper {
std::string caller, std::string caller,
std::string callee, std::string callee,
ast::FunctionDecorationList decorations = {}) { ast::FunctionDecorationList decorations = {}) {
auto* body = create<ast::BlockStatement>(Source{});
auto* ident_expr = create<ast::IdentifierExpression>( auto* ident_expr = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol(callee), callee); Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr, auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList()); ast::ExpressionList());
body->append(create<ast::CallStatement>(Source{}, call_expr)); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::CallStatement>(Source{}, call_expr),
create<ast::ReturnStatement>(Source{}),
});
return create<ast::Function>(Source{}, mod()->RegisterSymbol(caller), return create<ast::Function>(Source{}, mod()->RegisterSymbol(caller),
caller, ast::VariableList(), void_type(), body, caller, ast::VariableList(), void_type(), body,
decorations); decorations);
@ -148,18 +152,19 @@ class InspectorHelper {
std::string name, std::string name,
std::vector<std::tuple<std::string, std::string>> inout_vars, std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::FunctionDecorationList decorations = {}) { ast::FunctionDecorationList decorations = {}) {
auto* body = create<ast::BlockStatement>(Source{}); ast::StatementList stmts;
for (auto inout : inout_vars) { for (auto inout : inout_vars) {
std::string in, out; std::string in, out;
std::tie(in, out) = inout; std::tie(in, out) = inout;
body->append(create<ast::AssignmentStatement>( stmts.emplace_back(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, create<ast::IdentifierExpression>(Source{},
mod()->RegisterSymbol(out), out), mod()->RegisterSymbol(out), out),
create<ast::IdentifierExpression>(Source{}, mod()->RegisterSymbol(in), create<ast::IdentifierExpression>(Source{}, mod()->RegisterSymbol(in),
in))); in)));
} }
body->append(create<ast::ReturnStatement>(Source{})); stmts.emplace_back(create<ast::ReturnStatement>(Source{}));
auto* body = create<ast::BlockStatement>(Source{}, stmts);
return create<ast::Function>(Source{}, mod()->RegisterSymbol(name), name, return create<ast::Function>(Source{}, mod()->RegisterSymbol(name), name,
ast::VariableList(), void_type(), body, ast::VariableList(), void_type(), body,
decorations); decorations);
@ -178,11 +183,11 @@ class InspectorHelper {
std::string callee, std::string callee,
std::vector<std::tuple<std::string, std::string>> inout_vars, std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::FunctionDecorationList decorations = {}) { ast::FunctionDecorationList decorations = {}) {
auto* body = create<ast::BlockStatement>(Source{}); ast::StatementList stmts;
for (auto inout : inout_vars) { for (auto inout : inout_vars) {
std::string in, out; std::string in, out;
std::tie(in, out) = inout; std::tie(in, out) = inout;
body->append(create<ast::AssignmentStatement>( stmts.emplace_back(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, create<ast::IdentifierExpression>(Source{},
mod()->RegisterSymbol(out), out), mod()->RegisterSymbol(out), out),
@ -193,8 +198,9 @@ class InspectorHelper {
Source{}, mod()->RegisterSymbol(callee), callee); Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr, auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList()); ast::ExpressionList());
body->append(create<ast::CallStatement>(Source{}, call_expr)); stmts.emplace_back(create<ast::CallStatement>(Source{}, call_expr));
body->append(create<ast::ReturnStatement>(Source{})); stmts.emplace_back(create<ast::ReturnStatement>(Source{}));
auto* body = create<ast::BlockStatement>(Source{}, stmts);
return create<ast::Function>(Source{}, mod()->RegisterSymbol(caller), return create<ast::Function>(Source{}, mod()->RegisterSymbol(caller),
caller, ast::VariableList(), void_type(), body, caller, ast::VariableList(), void_type(), body,
decorations); decorations);
@ -428,14 +434,13 @@ class InspectorHelper {
std::string func_name, std::string func_name,
std::string struct_name, std::string struct_name,
std::vector<std::tuple<size_t, ast::type::Type*>> members) { std::vector<std::tuple<size_t, ast::type::Type*>> members) {
auto* body = create<ast::BlockStatement>(Source{}); ast::StatementList stmts;
for (auto member : members) { for (auto member : members) {
size_t member_idx; size_t member_idx;
ast::type::Type* member_type; ast::type::Type* member_type;
std::tie(member_idx, member_type) = member; std::tie(member_idx, member_type) = member;
std::string member_name = StructMemberName(member_idx, member_type); std::string member_name = StructMemberName(member_idx, member_type);
body->append(create<ast::VariableDeclStatement>( stmts.emplace_back(create<ast::VariableDeclStatement>(
Source{}, create<ast::Variable>( Source{}, create<ast::Variable>(
Source{}, // source Source{}, // source
"local" + member_name, // name "local" + member_name, // name
@ -451,7 +456,7 @@ class InspectorHelper {
ast::type::Type* member_type; ast::type::Type* member_type;
std::tie(member_idx, member_type) = member; std::tie(member_idx, member_type) = member;
std::string member_name = StructMemberName(member_idx, member_type); std::string member_name = StructMemberName(member_idx, member_type);
body->append(create<ast::AssignmentStatement>( stmts.emplace_back(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("local" + member_name), Source{}, mod()->RegisterSymbol("local" + member_name),
@ -464,7 +469,8 @@ class InspectorHelper {
Source{}, mod()->RegisterSymbol(member_name), member_name)))); Source{}, mod()->RegisterSymbol(member_name), member_name))));
} }
body->append(create<ast::ReturnStatement>(Source{})); stmts.emplace_back(create<ast::ReturnStatement>(Source{}));
auto* body = create<ast::BlockStatement>(Source{}, stmts);
return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name), return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name),
func_name, ast::VariableList(), void_type(), func_name, ast::VariableList(), void_type(),
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -584,8 +590,7 @@ class InspectorHelper {
ast::FunctionDecorationList decorations = {}) { ast::FunctionDecorationList decorations = {}) {
std::string result_name = "sampler_result"; std::string result_name = "sampler_result";
auto* body = create<ast::BlockStatement>(Source{}); ast::StatementList stmts;
auto* call_result = auto* call_result =
create<ast::Variable>(Source{}, // source create<ast::Variable>(Source{}, // source
"sampler_result", // name "sampler_result", // name
@ -594,7 +599,8 @@ class InspectorHelper {
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
body->append(create<ast::VariableDeclStatement>(Source{}, call_result)); stmts.emplace_back(
create<ast::VariableDeclStatement>(Source{}, call_result));
ast::ExpressionList call_params; ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>( call_params.push_back(create<ast::IdentifierExpression>(
@ -609,14 +615,15 @@ class InspectorHelper {
Source{}, mod()->RegisterSymbol("textureSample"), "textureSample"), Source{}, mod()->RegisterSymbol("textureSample"), "textureSample"),
call_params); call_params);
body->append(create<ast::AssignmentStatement>( stmts.emplace_back(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("sampler_result"), Source{}, mod()->RegisterSymbol("sampler_result"),
"sampler_result"), "sampler_result"),
call_expr)); call_expr));
body->append(create<ast::ReturnStatement>(Source{})); stmts.emplace_back(create<ast::ReturnStatement>(Source{}));
auto* body = create<ast::BlockStatement>(Source{}, stmts);
return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name), return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name),
func_name, ast::VariableList(), void_type(), func_name, ast::VariableList(), void_type(),
body, decorations); body, decorations);
@ -641,7 +648,7 @@ class InspectorHelper {
ast::FunctionDecorationList decorations = {}) { ast::FunctionDecorationList decorations = {}) {
std::string result_name = "sampler_result"; std::string result_name = "sampler_result";
auto* body = create<ast::BlockStatement>(Source{}); ast::StatementList stmts;
auto* call_result = auto* call_result =
create<ast::Variable>(Source{}, // source create<ast::Variable>(Source{}, // source
@ -651,7 +658,8 @@ class InspectorHelper {
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
body->append(create<ast::VariableDeclStatement>(Source{}, call_result)); stmts.emplace_back(
create<ast::VariableDeclStatement>(Source{}, call_result));
ast::ExpressionList call_params; ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>( call_params.push_back(create<ast::IdentifierExpression>(
@ -668,14 +676,15 @@ class InspectorHelper {
Source{}, mod()->RegisterSymbol("textureSample"), "textureSample"), Source{}, mod()->RegisterSymbol("textureSample"), "textureSample"),
call_params); call_params);
body->append(create<ast::AssignmentStatement>( stmts.emplace_back(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("sampler_result"), Source{}, mod()->RegisterSymbol("sampler_result"),
"sampler_result"), "sampler_result"),
call_expr)); call_expr));
body->append(create<ast::ReturnStatement>(Source{})); stmts.emplace_back(create<ast::ReturnStatement>(Source{}));
auto* body = create<ast::BlockStatement>(Source{}, stmts);
return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name), return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name),
func_name, ast::VariableList(), void_type(), func_name, ast::VariableList(), void_type(),
body, decorations); body, decorations);
@ -701,7 +710,7 @@ class InspectorHelper {
ast::FunctionDecorationList decorations = {}) { ast::FunctionDecorationList decorations = {}) {
std::string result_name = "sampler_result"; std::string result_name = "sampler_result";
auto* body = create<ast::BlockStatement>(Source{}); ast::StatementList stmts;
auto* call_result = auto* call_result =
create<ast::Variable>(Source{}, // source create<ast::Variable>(Source{}, // source
@ -711,7 +720,8 @@ class InspectorHelper {
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
body->append(create<ast::VariableDeclStatement>(Source{}, call_result)); stmts.emplace_back(
create<ast::VariableDeclStatement>(Source{}, call_result));
ast::ExpressionList call_params; ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>( call_params.push_back(create<ast::IdentifierExpression>(
@ -729,14 +739,15 @@ class InspectorHelper {
"textureSampleCompare"), "textureSampleCompare"),
call_params); call_params);
body->append(create<ast::AssignmentStatement>( stmts.emplace_back(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("sampler_result"), Source{}, mod()->RegisterSymbol("sampler_result"),
"sampler_result"), "sampler_result"),
call_expr)); call_expr));
body->append(create<ast::ReturnStatement>(Source{})); stmts.emplace_back(create<ast::ReturnStatement>(Source{}));
auto* body = create<ast::BlockStatement>(Source{}, stmts);
return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name), return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name),
func_name, ast::VariableList(), void_type(), func_name, ast::VariableList(), void_type(),
body, decorations); body, decorations);
@ -1557,20 +1568,21 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
AddReferenceFunc("ub_bar_func", "ub_bar"); AddReferenceFunc("ub_bar_func", "ub_bar");
AddReferenceFunc("ub_baz_func", "ub_baz"); AddReferenceFunc("ub_baz_func", "ub_baz");
auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) { auto FuncCall = [&](const std::string& callee) {
auto* ident_expr = create<ast::IdentifierExpression>( auto* ident_expr = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol(callee), callee); Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr, auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList()); ast::ExpressionList());
body->append(create<ast::CallStatement>(Source{}, call_expr)); return create<ast::CallStatement>(Source{}, call_expr);
}; };
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
FuncCall("ub_foo_func"),
FuncCall("ub_bar_func"),
FuncCall("ub_baz_func"),
create<ast::ReturnStatement>(Source{}),
});
AddFuncCall(body, "ub_foo_func");
AddFuncCall(body, "ub_bar_func");
AddFuncCall(body, "ub_baz_func");
body->append(create<ast::ReturnStatement>(Source{}));
ast::Function* func = create<ast::Function>( ast::Function* func = create<ast::Function>(
Source{}, mod()->RegisterSymbol("ep_func"), "ep_func", Source{}, mod()->RegisterSymbol("ep_func"), "ep_func",
ast::VariableList(), void_type(), body, ast::VariableList(), void_type(), body,
@ -1705,20 +1717,21 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
AddReferenceFunc("sb_bar_func", "sb_bar"); AddReferenceFunc("sb_bar_func", "sb_bar");
AddReferenceFunc("sb_baz_func", "sb_baz"); AddReferenceFunc("sb_baz_func", "sb_baz");
auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) { auto FuncCall = [&](const std::string& callee) {
auto* ident_expr = create<ast::IdentifierExpression>( auto* ident_expr = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol(callee), callee); Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr, auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList()); ast::ExpressionList());
body->append(create<ast::CallStatement>(Source{}, call_expr)); return create<ast::CallStatement>(Source{}, call_expr);
}; };
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
FuncCall("sb_foo_func"),
FuncCall("sb_bar_func"),
FuncCall("sb_baz_func"),
create<ast::ReturnStatement>(Source{}),
});
AddFuncCall(body, "sb_foo_func");
AddFuncCall(body, "sb_bar_func");
AddFuncCall(body, "sb_baz_func");
body->append(create<ast::ReturnStatement>(Source{}));
ast::Function* func = create<ast::Function>( ast::Function* func = create<ast::Function>(
Source{}, mod()->RegisterSymbol("ep_func"), "ep_func", Source{}, mod()->RegisterSymbol("ep_func"), "ep_func",
ast::VariableList(), void_type(), body, ast::VariableList(), void_type(), body,
@ -1880,20 +1893,21 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
AddReferenceFunc("sb_bar_func", "sb_bar"); AddReferenceFunc("sb_bar_func", "sb_bar");
AddReferenceFunc("sb_baz_func", "sb_baz"); AddReferenceFunc("sb_baz_func", "sb_baz");
auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) { auto FuncCall = [&](const std::string& callee) {
auto* ident_expr = create<ast::IdentifierExpression>( auto* ident_expr = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol(callee), callee); Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr, auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList()); ast::ExpressionList());
body->append(create<ast::CallStatement>(Source{}, call_expr)); return create<ast::CallStatement>(Source{}, call_expr);
}; };
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
FuncCall("sb_foo_func"),
FuncCall("sb_bar_func"),
FuncCall("sb_baz_func"),
create<ast::ReturnStatement>(Source{}),
});
AddFuncCall(body, "sb_foo_func");
AddFuncCall(body, "sb_bar_func");
AddFuncCall(body, "sb_baz_func");
body->append(create<ast::ReturnStatement>(Source{}));
ast::Function* func = create<ast::Function>( ast::Function* func = create<ast::Function>(
Source{}, mod()->RegisterSymbol("ep_func"), "ep_func", Source{}, mod()->RegisterSymbol("ep_func"), "ep_func",
ast::VariableList(), void_type(), body, ast::VariableList(), void_type(), body,

View File

@ -608,7 +608,7 @@ class StructuredTraverser {
std::unordered_set<uint32_t> visited_; std::unordered_set<uint32_t> visited_;
}; };
/// A StatementBuilder for ast::SwitchStatment /// A StatementBuilder for ast::SwitchStatement
/// @see StatementBuilder /// @see StatementBuilder
struct SwitchStatementBuilder struct SwitchStatementBuilder
: public Castable<SwitchStatementBuilder, StatementBuilder> { : public Castable<SwitchStatementBuilder, StatementBuilder> {
@ -730,32 +730,17 @@ FunctionEmitter::StatementBlock::StatementBlock(
completion_action_(completion_action), completion_action_(completion_action),
cases_(cases) {} cases_(cases) {}
FunctionEmitter::StatementBlock::StatementBlock(StatementBlock&& other) FunctionEmitter::StatementBlock::StatementBlock(StatementBlock&& other) =
: construct_(other.construct_), default;
end_id_(other.end_id_),
completion_action_(std::move(other.completion_action_)),
statements_(std::move(other.statements_)),
cases_(std::move(other.cases_)) {
other.statements_.clear();
}
FunctionEmitter::StatementBlock::~StatementBlock() { FunctionEmitter::StatementBlock::~StatementBlock() = default;
if (!finalized_) {
// Delete builders that have not been built with Finalize()
for (auto* statement : statements_) {
if (auto* builder = statement->As<StatementBuilder>()) {
delete builder;
}
}
}
}
void FunctionEmitter::StatementBlock::Finalize(ast::Module* mod) { void FunctionEmitter::StatementBlock::Finalize(ast::Module* mod) {
assert(!finalized_ /* Finalize() must only be called once */); assert(!finalized_ /* Finalize() must only be called once */);
for (size_t i = 0; i < statements_.size(); i++) { for (size_t i = 0; i < statements_.size(); i++) {
if (auto* builder = statements_[i]->As<StatementBuilder>()) { if (auto* builder = statements_[i]->As<StatementBuilder>()) {
statements_[i] = builder->Build(mod); statements_[i] = builder->Build(mod);
delete builder;
} }
} }
@ -820,12 +805,10 @@ const ast::StatementList FunctionEmitter::ast_body() {
ast::Statement* FunctionEmitter::AddStatement(ast::Statement* statement) { ast::Statement* FunctionEmitter::AddStatement(ast::Statement* statement) {
assert(!statements_stack_.empty()); assert(!statements_stack_.empty());
auto* result = statement; if (statement != nullptr) {
if (result != nullptr) { statements_stack_.back().Add(statement);
auto& block = statements_stack_.back();
block.Add(statement);
} }
return result; return statement;
} }
ast::Statement* FunctionEmitter::LastStatement() { ast::Statement* FunctionEmitter::LastStatement() {

View File

@ -834,12 +834,15 @@ class FunctionEmitter {
/// @returns a pointer to the statement. /// @returns a pointer to the statement.
ast::Statement* AddStatement(ast::Statement* statement); ast::Statement* AddStatement(ast::Statement* statement);
/// AddStatementBuilder() constructs and adds the StatementBuilder of type
/// `T` to the top of the statement stack.
/// @param args the arguments forwarded to the T constructor
/// @return the built StatementBuilder
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
T* AddStatementBuilder(ARGS&&... args) { T* AddStatementBuilder(ARGS&&... args) {
// The builder is temporary and is not owned by the module. assert(!statements_stack_.empty());
auto builder = new T(std::forward<ARGS>(args)...); return statements_stack_.back().AddStatementBuilder<T>(
AddStatement(builder); std::forward<ARGS>(args)...);
return builder;
} }
/// Returns the source record for the given instruction. /// Returns the source record for the given instruction.
@ -876,6 +879,20 @@ class FunctionEmitter {
/// Add() must not be called after calling Finalize(). /// Add() must not be called after calling Finalize().
void Add(ast::Statement* statement); void Add(ast::Statement* statement);
/// AddStatementBuilder() constructs and adds the StatementBuilder of type
/// `T` to the block.
/// Add() must not be called after calling Finalize().
/// @param args the arguments forwarded to the T constructor
/// @return the built StatementBuilder
template <typename T, typename... ARGS>
T* AddStatementBuilder(ARGS&&... args) {
auto builder = std::make_unique<T>(std::forward<ARGS>(args)...);
auto* ptr = builder.get();
Add(ptr);
builders_.emplace_back(std::move(builder));
return ptr;
}
/// @param construct the construct which this construct constributes to /// @param construct the construct which this construct constributes to
void SetConstruct(const Construct* construct) { construct_ = construct; } void SetConstruct(const Construct* construct) { construct_ = construct; }
@ -883,7 +900,7 @@ class FunctionEmitter {
const Construct* Construct() const { return construct_; } const Construct* Construct() const { return construct_; }
/// @return the ID of the block at which the completion action should be /// @return the ID of the block at which the completion action should be
/// triggerd and this statement block discarded. This is often the `end_id` /// triggered and this statement block discarded. This is often the `end_id`
/// of `construct` itself. /// of `construct` itself.
uint32_t EndId() const { return end_id_; } uint32_t EndId() const { return end_id_; }
@ -901,7 +918,7 @@ class FunctionEmitter {
private: private:
/// The construct to which this construct constributes. /// The construct to which this construct constributes.
const spirv::Construct* construct_; const spirv::Construct* construct_;
/// The ID of the block at which the completion action should be triggerd /// The ID of the block at which the completion action should be triggered
/// and this statement block discarded. This is often the `end_id` of /// and this statement block discarded. This is often the `end_id` of
/// `construct` itself. /// `construct` itself.
uint32_t const end_id_; uint32_t const end_id_;
@ -914,6 +931,9 @@ class FunctionEmitter {
ast::StatementList statements_; ast::StatementList statements_;
/// The list of switch cases being built, if this construct is a switch. /// The list of switch cases being built, if this construct is a switch.
ast::CaseStatementList* cases_ = nullptr; ast::CaseStatementList* cases_ = nullptr;
/// Owned statement builders
std::vector<std::unique_ptr<StatementBuilder>> builders_;
/// True if Finalize() has been called. /// True if Finalize() has been called.
bool finalized_ = false; bool finalized_ = false;
}; };

View File

@ -1439,14 +1439,14 @@ Expect<ast::Expression*> ParserImpl::expect_paren_rhs_stmt() {
// : statement* // : statement*
Expect<ast::BlockStatement*> ParserImpl::expect_statements() { Expect<ast::BlockStatement*> ParserImpl::expect_statements() {
bool errored = false; bool errored = false;
auto* ret = create<ast::BlockStatement>(Source{}); ast::StatementList stmts;
while (synchronized_) { while (synchronized_) {
auto stmt = statement(); auto stmt = statement();
if (stmt.errored) { if (stmt.errored) {
errored = true; errored = true;
} else if (stmt.matched) { } else if (stmt.matched) {
ret->append(stmt.value); stmts.emplace_back(stmt.value);
} else { } else {
break; break;
} }
@ -1455,7 +1455,7 @@ Expect<ast::BlockStatement*> ParserImpl::expect_statements() {
if (errored) if (errored)
return Failure::kErrored; return Failure::kErrored;
return ret; return create<ast::BlockStatement>(Source{}, stmts);
} }
// statement // statement
@ -1828,14 +1828,14 @@ Expect<ast::CaseSelectorList> ParserImpl::expect_case_selectors() {
// | statement case_body // | statement case_body
// | FALLTHROUGH SEMICOLON // | FALLTHROUGH SEMICOLON
Maybe<ast::BlockStatement*> ParserImpl::case_body() { Maybe<ast::BlockStatement*> ParserImpl::case_body() {
auto* ret = create<ast::BlockStatement>(Source{}); ast::StatementList stmts;
for (;;) { for (;;) {
Source source; Source source;
if (match(Token::Type::kFallthrough, &source)) { if (match(Token::Type::kFallthrough, &source)) {
if (!expect("fallthrough statement", Token::Type::kSemicolon)) if (!expect("fallthrough statement", Token::Type::kSemicolon))
return Failure::kErrored; return Failure::kErrored;
ret->append(create<ast::FallthroughStatement>(source)); stmts.emplace_back(create<ast::FallthroughStatement>(source));
break; break;
} }
@ -1845,10 +1845,10 @@ Maybe<ast::BlockStatement*> ParserImpl::case_body() {
if (!stmt.matched) if (!stmt.matched)
break; break;
ret->append(stmt.value); stmts.emplace_back(stmt.value);
} }
return ret; return create<ast::BlockStatement>(Source{}, stmts);
} }
// loop_stmt // loop_stmt
@ -1972,8 +1972,10 @@ Maybe<ast::Statement*> ParserImpl::for_stmt() {
header->condition->source(), ast::UnaryOp::kNot, header->condition); header->condition->source(), ast::UnaryOp::kNot, header->condition);
// { break; } // { break; }
auto* break_stmt = create<ast::BreakStatement>(not_condition->source()); auto* break_stmt = create<ast::BreakStatement>(not_condition->source());
auto* break_body = create<ast::BlockStatement>(not_condition->source()); auto* break_body =
break_body->append(break_stmt); create<ast::BlockStatement>(not_condition->source(), ast::StatementList{
break_stmt,
});
// if (!condition) { break; } // if (!condition) { break; }
auto* break_if_not_condition = auto* break_if_not_condition =
create<ast::IfStatement>(not_condition->source(), not_condition, create<ast::IfStatement>(not_condition->source(), not_condition,
@ -1983,17 +1985,19 @@ Maybe<ast::Statement*> ParserImpl::for_stmt() {
ast::BlockStatement* continuing_body = nullptr; ast::BlockStatement* continuing_body = nullptr;
if (header->continuing != nullptr) { if (header->continuing != nullptr) {
continuing_body = create<ast::BlockStatement>(header->continuing->source()); continuing_body = create<ast::BlockStatement>(header->continuing->source(),
continuing_body->append(header->continuing); ast::StatementList{
header->continuing,
});
} }
auto* loop = create<ast::LoopStatement>(source, body.value, continuing_body); auto* loop = create<ast::LoopStatement>(source, body.value, continuing_body);
if (header->initializer != nullptr) { if (header->initializer != nullptr) {
auto* result = create<ast::BlockStatement>(source); return create<ast::BlockStatement>(source, ast::StatementList{
result->append(header->initializer); header->initializer,
result->append(loop); loop,
return result; });
} }
return loop; return loop;
@ -2059,7 +2063,7 @@ Maybe<ast::ContinueStatement*> ParserImpl::continue_stmt() {
// : CONTINUING body_stmt // : CONTINUING body_stmt
Maybe<ast::BlockStatement*> ParserImpl::continuing_stmt() { Maybe<ast::BlockStatement*> ParserImpl::continuing_stmt() {
if (!match(Token::Type::kContinuing)) if (!match(Token::Type::kContinuing))
return create<ast::BlockStatement>(Source{}); return create<ast::BlockStatement>(Source{}, ast::StatementList{});
return expect_body_stmt(); return expect_body_stmt();
} }

View File

@ -91,24 +91,21 @@ class BoundArrayAccessorsTest : public testing::Test {
}; };
struct ModuleBuilder : public ast::BuilderWithModule { struct ModuleBuilder : public ast::BuilderWithModule {
ModuleBuilder() : body_(create<ast::BlockStatement>(Source{})) {
mod->AddFunction(create<ast::Function>(
Source{}, mod->RegisterSymbol("func"), "func", ast::VariableList{},
ty.void_, body_, ast::FunctionDecorationList{}));
}
ast::Module Module() { ast::Module Module() {
Build(); Build();
auto* body = create<ast::BlockStatement>(Source{}, statements);
mod->AddFunction(create<ast::Function>(
Source{}, mod->RegisterSymbol("func"), "func", ast::VariableList{},
ty.void_, body, ast::FunctionDecorationList{}));
return std::move(*mod); return std::move(*mod);
} }
protected: protected:
virtual void Build() = 0; virtual void Build() = 0;
void OnVariableBuilt(ast::Variable* var) override { void OnVariableBuilt(ast::Variable* var) override {
ASSERT_NE(body_, nullptr); statements.emplace_back(create<ast::VariableDeclStatement>(Source{}, var));
body_->append(create<ast::VariableDeclStatement>(Source{}, var));
} }
ast::BlockStatement* body_ = nullptr; ast::StatementList statements;
}; };
TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) { TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) {

View File

@ -53,16 +53,18 @@ struct ModuleBuilder : public ast::BuilderWithModule {
TEST_F(EmitVertexPointSizeTest, VertexStageBasic) { TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
struct Builder : ModuleBuilder { struct Builder : ModuleBuilder {
void Build() override { void Build() override {
auto* block = create<ast::BlockStatement>(Source{}); auto* block = create<ast::BlockStatement>(
Source{},
block->append(create<ast::VariableDeclStatement>( ast::StatementList{
create<ast::VariableDeclStatement>(
Source{}, Var("builtin_assignments_should_happen_before_this", Source{}, Var("builtin_assignments_should_happen_before_this",
tint::ast::StorageClass::kFunction, ty.f32))); tint::ast::StorageClass::kFunction, ty.f32)),
});
auto a_sym = mod->RegisterSymbol("non_entry_a"); auto a_sym = mod->RegisterSymbol("non_entry_a");
mod->AddFunction(create<ast::Function>( mod->AddFunction(create<ast::Function>(
Source{}, a_sym, "non_entry_a", ast::VariableList{}, ty.void_, Source{}, a_sym, "non_entry_a", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{})); ast::FunctionDecorationList{}));
auto entry_sym = mod->RegisterSymbol("entry"); auto entry_sym = mod->RegisterSymbol("entry");
@ -77,7 +79,7 @@ TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
auto b_sym = mod->RegisterSymbol("non_entry_b"); auto b_sym = mod->RegisterSymbol("non_entry_b");
mod->AddFunction(create<ast::Function>( mod->AddFunction(create<ast::Function>(
Source{}, b_sym, "non_entry_b", ast::VariableList{}, ty.void_, Source{}, b_sym, "non_entry_b", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{})); ast::FunctionDecorationList{}));
} }
}; };
@ -131,13 +133,13 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
auto a_sym = mod->RegisterSymbol("non_entry_a"); auto a_sym = mod->RegisterSymbol("non_entry_a");
mod->AddFunction(create<ast::Function>( mod->AddFunction(create<ast::Function>(
Source{}, a_sym, "non_entry_a", ast::VariableList{}, ty.void_, Source{}, a_sym, "non_entry_a", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{})); ast::FunctionDecorationList{}));
auto entry_sym = mod->RegisterSymbol("entry"); auto entry_sym = mod->RegisterSymbol("entry");
mod->AddFunction(create<ast::Function>( mod->AddFunction(create<ast::Function>(
Source{}, entry_sym, "entry", ast::VariableList{}, ty.void_, Source{}, entry_sym, "entry", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, create<ast::StageDecoration>(ast::PipelineStage::kVertex,
Source{}), Source{}),
@ -146,7 +148,7 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
auto b_sym = mod->RegisterSymbol("non_entry_b"); auto b_sym = mod->RegisterSymbol("non_entry_b");
mod->AddFunction(create<ast::Function>( mod->AddFunction(create<ast::Function>(
Source{}, b_sym, "non_entry_b", ast::VariableList{}, ty.void_, Source{}, b_sym, "non_entry_b", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{})); ast::FunctionDecorationList{}));
} }
}; };
@ -193,7 +195,7 @@ TEST_F(EmitVertexPointSizeTest, NonVertexStage) {
auto frag_sym = mod->RegisterSymbol("fragment_entry"); auto frag_sym = mod->RegisterSymbol("fragment_entry");
auto* fragment_entry = create<ast::Function>( auto* fragment_entry = create<ast::Function>(
Source{}, frag_sym, "fragment_entry", ast::VariableList{}, ty.void_, Source{}, frag_sym, "fragment_entry", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment, create<ast::StageDecoration>(ast::PipelineStage::kFragment,
Source{}), Source{}),
@ -203,7 +205,7 @@ TEST_F(EmitVertexPointSizeTest, NonVertexStage) {
auto comp_sym = mod->RegisterSymbol("compute_entry"); auto comp_sym = mod->RegisterSymbol("compute_entry");
auto* compute_entry = create<ast::Function>( auto* compute_entry = create<ast::Function>(
Source{}, comp_sym, "compute_entry", ast::VariableList{}, ty.void_, Source{}, comp_sym, "compute_entry", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute, create<ast::StageDecoration>(ast::PipelineStage::kCompute,
Source{}), Source{}),

View File

@ -154,24 +154,25 @@ Transform::Output FirstIndexOffset::Run(ast::Module* in) {
if (buffer_var == nullptr) { if (buffer_var == nullptr) {
return nullptr; // no transform need, just clone func return nullptr; // no transform need, just clone func
} }
auto* body = ctx.mod->create<ast::BlockStatement>( ast::StatementList statements;
ctx.Clone(func->body()->source()));
for (const auto& data : func->local_referenced_builtin_variables()) { for (const auto& data : func->local_referenced_builtin_variables()) {
if (data.second->value() == ast::Builtin::kVertexIdx) { if (data.second->value() == ast::Builtin::kVertexIdx) {
body->append(CreateFirstIndexOffset( statements.emplace_back(CreateFirstIndexOffset(
vertex_index_name, kFirstVertexName, buffer_var, ctx.mod)); vertex_index_name, kFirstVertexName, buffer_var, ctx.mod));
} else if (data.second->value() == ast::Builtin::kInstanceIdx) { } else if (data.second->value() == ast::Builtin::kInstanceIdx) {
body->append(CreateFirstIndexOffset( statements.emplace_back(CreateFirstIndexOffset(
instance_index_name, kFirstInstanceName, buffer_var, ctx.mod)); instance_index_name, kFirstInstanceName, buffer_var, ctx.mod));
} }
} }
for (auto* s : *func->body()) { for (auto* s : *func->body()) {
body->append(ctx.Clone(s)); statements.emplace_back(ctx.Clone(s));
} }
return ctx.mod->create<ast::Function>( return ctx.mod->create<ast::Function>(
ctx.Clone(func->source()), func->symbol(), func->name(), ctx.Clone(func->source()), func->symbol(), func->name(),
ctx.Clone(func->params()), ctx.Clone(func->return_type()), ctx.Clone(func->params()), ctx.Clone(func->return_type()),
ctx.Clone(body), ctx.Clone(func->decorations())); ctx.mod->create<ast::BlockStatement>(
ctx.Clone(func->body()->source()), statements),
ctx.Clone(func->decorations()));
}); });
in->Clone(&ctx); in->Clone(&ctx);

View File

@ -58,10 +58,11 @@ struct ModuleBuilder : public ast::BuilderWithModule {
} }
ast::Function* AddFunction(const std::string& name, ast::Function* AddFunction(const std::string& name,
ast::VariableList params = {}) { ast::StatementList stmts) {
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol(name), name, std::move(params), ty.u32, Source{}, mod->RegisterSymbol(name), name, ast::VariableList{}, ty.u32,
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList()); create<ast::BlockStatement>(Source{}, stmts),
ast::FunctionDecorationList{});
mod->AddFunction(func); mod->AddFunction(func);
return func; return func;
} }
@ -73,10 +74,14 @@ TEST_F(FirstIndexOffsetTest, Error_AlreadyTransformed) {
struct Builder : public ModuleBuilder { struct Builder : public ModuleBuilder {
void Build() override { void Build() override {
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx); AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
AddFunction("test")->body()->append(create<ast::ReturnStatement>( AddFunction(
"test",
{
create<ast::ReturnStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx"))); Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx")),
});
} }
}; };
@ -116,10 +121,14 @@ TEST_F(FirstIndexOffsetTest, BasicModuleVertexIndex) {
struct Builder : public ModuleBuilder { struct Builder : public ModuleBuilder {
void Build() override { void Build() override {
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx); AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
AddFunction("test")->body()->append(create<ast::ReturnStatement>( AddFunction(
"test",
{
create<ast::ReturnStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx"))); Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx")),
});
} }
}; };
@ -194,10 +203,14 @@ TEST_F(FirstIndexOffsetTest, BasicModuleInstanceIndex) {
struct Builder : public ModuleBuilder { struct Builder : public ModuleBuilder {
void Build() override { void Build() override {
AddBuiltinInput("inst_idx", ast::Builtin::kInstanceIdx); AddBuiltinInput("inst_idx", ast::Builtin::kInstanceIdx);
AddFunction("test")->body()->append(create<ast::ReturnStatement>( AddFunction(
"test",
{
create<ast::ReturnStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("inst_idx"), "inst_idx"))); Source{}, mod->RegisterSymbol("inst_idx"), "inst_idx")),
});
} }
}; };
@ -272,8 +285,9 @@ TEST_F(FirstIndexOffsetTest, BasicModuleBothIndex) {
void Build() override { void Build() override {
AddBuiltinInput("inst_idx", ast::Builtin::kInstanceIdx); AddBuiltinInput("inst_idx", ast::Builtin::kInstanceIdx);
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx); AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
AddFunction("test")->body()->append( AddFunction("test", {
create<ast::ReturnStatement>(Source{}, Expr(1u))); create<ast::ReturnStatement>(Source{}, Expr(1u)),
});
} }
}; };
@ -348,18 +362,25 @@ TEST_F(FirstIndexOffsetTest, NestedCalls) {
struct Builder : public ModuleBuilder { struct Builder : public ModuleBuilder {
void Build() override { void Build() override {
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx); AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
ast::Function* func1 = AddFunction("func1"); AddFunction(
func1->body()->append(create<ast::ReturnStatement>( "func1",
{
create<ast::ReturnStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx"))); Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx")),
ast::Function* func2 = AddFunction("func2"); });
func2->body()->append(create<ast::ReturnStatement>( AddFunction(
Source{}, create<ast::CallExpression>( "func2",
{
create<ast::ReturnStatement>(
Source{},
create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("func1"), "func1"), Source{}, mod->RegisterSymbol("func1"), "func1"),
ast::ExpressionList{}))); ast::ExpressionList{})),
});
} }
}; };

View File

@ -105,7 +105,7 @@ Transform::Output VertexPulling::Run(ast::Module* in) {
state.FindOrInsertInstanceIndexIfUsed(); state.FindOrInsertInstanceIndexIfUsed();
state.ConvertVertexInputVariablesToPrivate(); state.ConvertVertexInputVariablesToPrivate();
state.AddVertexStorageBuffers(); state.AddVertexStorageBuffers();
state.AddVertexPullingPreamble(func); func->body()->insert(0, state.CreateVertexPullingPreamble());
return out; return out;
} }
@ -286,13 +286,11 @@ void VertexPulling::State::AddVertexStorageBuffers() {
mod->AddConstructedType(struct_type); mod->AddConstructedType(struct_type);
} }
void VertexPulling::State::AddVertexPullingPreamble( ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() {
ast::Function* vertex_func) {
// Assign by looking at the vertex descriptor to find attributes with matching // Assign by looking at the vertex descriptor to find attributes with matching
// location. // location.
// A block statement allowing us to use append instead of insert ast::StatementList stmts;
auto* block = mod->create<ast::BlockStatement>(Source{});
// Declare the |kPullingPosVarName| variable in the shader // Declare the |kPullingPosVarName| variable in the shader
auto* pos_declaration = mod->create<ast::VariableDeclStatement>( auto* pos_declaration = mod->create<ast::VariableDeclStatement>(
@ -308,7 +306,7 @@ void VertexPulling::State::AddVertexPullingPreamble(
// |kPullingPosVarName| refers to the byte location of the current read. We // |kPullingPosVarName| refers to the byte location of the current read. We
// declare a variable in the shader to avoid having to reuse Expression // declare a variable in the shader to avoid having to reuse Expression
// objects. // objects.
block->append(pos_declaration); stmts.emplace_back(pos_declaration);
for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) { for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) {
const VertexBufferLayoutDescriptor& buffer_layout = cfg.vertex_state[i]; const VertexBufferLayoutDescriptor& buffer_layout = cfg.vertex_state[i];
@ -339,9 +337,9 @@ void VertexPulling::State::AddVertexPullingPreamble(
// Update position of the read // Update position of the read
auto* set_pos_expr = mod->create<ast::AssignmentStatement>( auto* set_pos_expr = mod->create<ast::AssignmentStatement>(
Source{}, CreatePullingPositionIdent(), pos_value); Source{}, CreatePullingPositionIdent(), pos_value);
block->append(set_pos_expr); stmts.emplace_back(set_pos_expr);
block->append(mod->create<ast::AssignmentStatement>( stmts.emplace_back(mod->create<ast::AssignmentStatement>(
Source{}, Source{},
mod->create<ast::IdentifierExpression>( mod->create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol(v->name()), v->name()), Source{}, mod->RegisterSymbol(v->name()), v->name()),
@ -349,7 +347,7 @@ void VertexPulling::State::AddVertexPullingPreamble(
} }
} }
vertex_func->body()->insert(0, block); return mod->create<ast::BlockStatement>(Source{}, stmts);
} }
ast::Expression* VertexPulling::State::GenUint(uint32_t value) { ast::Expression* VertexPulling::State::GenUint(uint32_t value) {

View File

@ -197,8 +197,8 @@ class VertexPulling : public Transform {
/// Adds storage buffer decorated variables for the vertex buffers /// Adds storage buffer decorated variables for the vertex buffers
void AddVertexStorageBuffers(); void AddVertexStorageBuffers();
/// Adds assignment to the variables from the buffers /// Creates and returns the assignment to the variables from the buffers
void AddVertexPullingPreamble(ast::Function* vertex_func); ast::BlockStatement* CreateVertexPullingPreamble();
/// Generates an expression holding a constant uint /// Generates an expression holding a constant uint
/// @param value uint value /// @param value uint value

View File

@ -47,8 +47,9 @@ class VertexPullingHelper {
// Create basic module with an entry point and vertex function // Create basic module with an entry point and vertex function
void InitBasicModule() { void InitBasicModule() {
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod_->RegisterSymbol("main"), "main", ast::VariableList{}, Source{}, mod()->RegisterSymbol("main"), "main", ast::VariableList{},
mod_->create<ast::type::Void>(), create<ast::BlockStatement>(Source{}), mod_->create<ast::type::Void>(),
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{create<ast::StageDecoration>( ast::FunctionDecorationList{create<ast::StageDecoration>(
ast::PipelineStage::kVertex, Source{})}); ast::PipelineStage::kVertex, Source{})});
mod()->AddFunction(func); mod()->AddFunction(func);
@ -135,7 +136,8 @@ TEST_F(VertexPullingTest, Error_InvalidEntryPoint) {
TEST_F(VertexPullingTest, Error_EntryPointWrongStage) { TEST_F(VertexPullingTest, Error_EntryPointWrongStage) {
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod()->RegisterSymbol("main"), "main", ast::VariableList{}, Source{}, mod()->RegisterSymbol("main"), "main", ast::VariableList{},
mod()->create<ast::type::Void>(), create<ast::BlockStatement>(Source{}), mod()->create<ast::type::Void>(),
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
}); });

View File

@ -151,9 +151,10 @@ TEST_F(TypeDeterminerTest, Stmt_Case) {
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f)); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs)); Source{}, ast::StatementList{
create<ast::AssignmentStatement>(Source{}, lhs, rhs),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 3)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 3));
ast::CaseStatement cse(Source{}, lit, body); ast::CaseStatement cse(Source{}, lit, body);
@ -174,8 +175,10 @@ TEST_F(TypeDeterminerTest, Stmt_Block) {
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f)); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
ast::BlockStatement block(Source{}); ast::BlockStatement block(
block.append(create<ast::AssignmentStatement>(Source{}, lhs, rhs)); Source{}, ast::StatementList{
create<ast::AssignmentStatement>(Source{}, lhs, rhs),
});
EXPECT_TRUE(td()->DetermineResultType(&block)); EXPECT_TRUE(td()->DetermineResultType(&block));
ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(lhs->result_type(), nullptr);
@ -193,9 +196,10 @@ TEST_F(TypeDeterminerTest, Stmt_Else) {
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f)); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs)); Source{}, ast::StatementList{
create<ast::AssignmentStatement>(Source{}, lhs, rhs),
});
ast::ElseStatement stmt( ast::ElseStatement stmt(
Source{}, Source{},
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
@ -220,9 +224,11 @@ TEST_F(TypeDeterminerTest, Stmt_If) {
auto* else_rhs = create<ast::ScalarConstructorExpression>( auto* else_rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f)); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* else_body = create<ast::BlockStatement>(Source{}); auto* else_body = create<ast::BlockStatement>(
else_body->append( Source{},
create<ast::AssignmentStatement>(Source{}, else_lhs, else_rhs)); ast::StatementList{
create<ast::AssignmentStatement>(Source{}, else_lhs, else_rhs),
});
auto* else_stmt = create<ast::ElseStatement>( auto* else_stmt = create<ast::ElseStatement>(
Source{}, Source{},
@ -235,9 +241,10 @@ TEST_F(TypeDeterminerTest, Stmt_If) {
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f)); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs)); Source{}, ast::StatementList{
create<ast::AssignmentStatement>(Source{}, lhs, rhs),
});
ast::IfStatement stmt( ast::IfStatement stmt(
Source{}, Source{},
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
@ -266,18 +273,21 @@ TEST_F(TypeDeterminerTest, Stmt_Loop) {
auto* body_rhs = create<ast::ScalarConstructorExpression>( auto* body_rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f)); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(Source{}, body_lhs, body_rhs)); Source{},
ast::StatementList{
create<ast::AssignmentStatement>(Source{}, body_lhs, body_rhs),
});
auto* continuing_lhs = create<ast::ScalarConstructorExpression>( auto* continuing_lhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* continuing_rhs = create<ast::ScalarConstructorExpression>( auto* continuing_rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f)); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* continuing = create<ast::BlockStatement>(Source{}); auto* continuing = create<ast::BlockStatement>(
continuing->append(create<ast::AssignmentStatement>(Source{}, continuing_lhs, Source{}, ast::StatementList{
continuing_rhs)); create<ast::AssignmentStatement>(Source{}, continuing_lhs,
continuing_rhs),
});
ast::LoopStatement stmt(Source{}, body, continuing); ast::LoopStatement stmt(Source{}, body, continuing);
EXPECT_TRUE(td()->DetermineResultType(&stmt)); EXPECT_TRUE(td()->DetermineResultType(&stmt));
@ -319,9 +329,10 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) {
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f)); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs)); Source{}, ast::StatementList{
create<ast::AssignmentStatement>(Source{}, lhs, rhs),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 3)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 3));
@ -350,7 +361,8 @@ TEST_F(TypeDeterminerTest, Stmt_Call) {
ast::VariableList params; ast::VariableList params;
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32, Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList{}); create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{});
mod->AddFunction(func); mod->AddFunction(func);
// Register the function // Register the function
@ -380,16 +392,21 @@ TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) {
mod->RegisterSymbol("func"), "func"), mod->RegisterSymbol("func"), "func"),
call_params); call_params);
ast::VariableList params0; ast::VariableList params0;
auto* main_body = create<ast::BlockStatement>(Source{}); auto* main_body = create<ast::BlockStatement>(
main_body->append(create<ast::CallStatement>(Source{}, call_expr)); Source{}, ast::StatementList{
main_body->append(create<ast::ReturnStatement>(Source{})); create<ast::CallStatement>(Source{}, call_expr),
create<ast::ReturnStatement>(Source{}),
});
auto* func_main = create<ast::Function>(Source{}, mod->RegisterSymbol("main"), auto* func_main = create<ast::Function>(Source{}, mod->RegisterSymbol("main"),
"main", params0, &f32, main_body, "main", params0, &f32, main_body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func_main); mod->AddFunction(func_main);
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = auto* func =
create<ast::Function>(Source{}, mod->RegisterSymbol("func"), "func", create<ast::Function>(Source{}, mod->RegisterSymbol("func"), "func",
params0, &f32, body, ast::FunctionDecorationList{}); params0, &f32, body, ast::FunctionDecorationList{});
@ -675,7 +692,8 @@ TEST_F(TypeDeterminerTest, Expr_Call) {
ast::VariableList params; ast::VariableList params;
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32, Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList{}); create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{});
mod->AddFunction(func); mod->AddFunction(func);
// Register the function // Register the function
@ -698,7 +716,8 @@ TEST_F(TypeDeterminerTest, Expr_Call_WithParams) {
ast::VariableList params; ast::VariableList params;
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32, Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList{}); create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{});
mod->AddFunction(func); mod->AddFunction(func);
// Register the function // Register the function
@ -851,13 +870,14 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable_Const) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::AssignmentStatement>( create<ast::VariableDeclStatement>(Source{}, var),
create<ast::AssignmentStatement>(
Source{}, my_var, Source{}, my_var,
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_var"), create<ast::IdentifierExpression>(
"my_var"))); Source{}, mod->RegisterSymbol("my_var"), "my_var")),
});
ast::Function f(Source{}, mod->RegisterSymbol("my_func"), "my_func", {}, &f32, ast::Function f(Source{}, mod->RegisterSymbol("my_func"), "my_func", {}, &f32,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -873,21 +893,23 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable) {
auto* my_var = create<ast::IdentifierExpression>( auto* my_var = create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("my_var"), "my_var"); Source{}, mod->RegisterSymbol("my_var"), "my_var");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(
Source{}, Source{},
create<ast::Variable>(Source{}, // source ast::StatementList{
create<ast::VariableDeclStatement>(
Source{}, create<ast::Variable>(
Source{}, // source
"my_var", // name "my_var", // name
ast::StorageClass::kNone, // storage_class ast::StorageClass::kNone, // storage_class
&f32, // type &f32, // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}))); // decorations ast::VariableDecorationList{})), // decorations
create<ast::AssignmentStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, my_var, Source{}, my_var,
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_var"), create<ast::IdentifierExpression>(
"my_var"))); Source{}, mod->RegisterSymbol("my_var"), "my_var")),
});
ast::Function f(Source{}, mod->RegisterSymbol("myfunc"), "my_func", {}, &f32, ast::Function f(Source{}, mod->RegisterSymbol("myfunc"), "my_func", {}, &f32,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -909,21 +931,23 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) {
auto* my_var = create<ast::IdentifierExpression>( auto* my_var = create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("my_var"), "my_var"); Source{}, mod->RegisterSymbol("my_var"), "my_var");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(
Source{}, Source{},
create<ast::Variable>(Source{}, // source ast::StatementList{
create<ast::VariableDeclStatement>(
Source{}, create<ast::Variable>(
Source{}, // source
"my_var", // name "my_var", // name
ast::StorageClass::kNone, // storage_class ast::StorageClass::kNone, // storage_class
&ptr, // type &ptr, // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}))); // decorations ast::VariableDecorationList{})), // decorations
create<ast::AssignmentStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, my_var, Source{}, my_var,
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_var"), create<ast::IdentifierExpression>(
"my_var"))); Source{}, mod->RegisterSymbol("my_var"), "my_var")),
});
ast::Function f(Source{}, mod->RegisterSymbol("my_func"), "my_func", {}, &f32, ast::Function f(Source{}, mod->RegisterSymbol("my_func"), "my_func", {}, &f32,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -944,7 +968,8 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function) {
ast::VariableList params; ast::VariableList params;
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32, Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList{}); create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{});
mod->AddFunction(func); mod->AddFunction(func);
// Register the function // Register the function
@ -1013,31 +1038,34 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables) {
mod->AddGlobalVariable(priv_var); mod->AddGlobalVariable(priv_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{},
ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("out_var"), "out_var"), Source{}, mod->RegisterSymbol("out_var"), "out_var"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("in_var"), create<ast::IdentifierExpression>(
"in_var"))); Source{}, mod->RegisterSymbol("in_var"), "in_var")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"), create<ast::IdentifierExpression>(
"wg_var"), Source{}, mod->RegisterSymbol("wg_var"), "wg_var"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"), create<ast::IdentifierExpression>(
"wg_var"))); Source{}, mod->RegisterSymbol("wg_var"), "wg_var")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"), create<ast::IdentifierExpression>(
"sb_var"), Source{}, mod->RegisterSymbol("sb_var"), "sb_var"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"), create<ast::IdentifierExpression>(
"sb_var"))); Source{}, mod->RegisterSymbol("sb_var"), "sb_var")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("priv_var"), "priv_var"), Source{}, mod->RegisterSymbol("priv_var"), "priv_var"),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("priv_var"), "priv_var"))); Source{}, mod->RegisterSymbol("priv_var"), "priv_var")),
});
auto* func = auto* func =
create<ast::Function>(Source{}, mod->RegisterSymbol("my_func"), "my_func", create<ast::Function>(Source{}, mod->RegisterSymbol("my_func"), "my_func",
params, &f32, body, ast::FunctionDecorationList{}); params, &f32, body, ast::FunctionDecorationList{});
@ -1106,31 +1134,34 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
mod->AddGlobalVariable(wg_var); mod->AddGlobalVariable(wg_var);
mod->AddGlobalVariable(priv_var); mod->AddGlobalVariable(priv_var);
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{},
ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("out_var"), "out_var"), Source{}, mod->RegisterSymbol("out_var"), "out_var"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("in_var"), create<ast::IdentifierExpression>(
"in_var"))); Source{}, mod->RegisterSymbol("in_var"), "in_var")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"), create<ast::IdentifierExpression>(
"wg_var"), Source{}, mod->RegisterSymbol("wg_var"), "wg_var"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"), create<ast::IdentifierExpression>(
"wg_var"))); Source{}, mod->RegisterSymbol("wg_var"), "wg_var")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"), create<ast::IdentifierExpression>(
"sb_var"), Source{}, mod->RegisterSymbol("sb_var"), "sb_var"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"), create<ast::IdentifierExpression>(
"sb_var"))); Source{}, mod->RegisterSymbol("sb_var"), "sb_var")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("priv_var"), "priv_var"), Source{}, mod->RegisterSymbol("priv_var"), "priv_var"),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("priv_var"), "priv_var"))); Source{}, mod->RegisterSymbol("priv_var"), "priv_var")),
});
ast::VariableList params; ast::VariableList params;
auto* func = auto* func =
create<ast::Function>(Source{}, mod->RegisterSymbol("my_func"), "my_func", create<ast::Function>(Source{}, mod->RegisterSymbol("my_func"), "my_func",
@ -1138,8 +1169,10 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
mod->AddFunction(func); mod->AddFunction(func);
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{},
ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("out_var"), "out_var"), Source{}, mod->RegisterSymbol("out_var"), "out_var"),
@ -1147,7 +1180,9 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("my_func"), "my_func"), Source{}, mod->RegisterSymbol("my_func"), "my_func"),
ast::ExpressionList{}))); ast::ExpressionList{})),
});
auto* func2 = auto* func2 =
create<ast::Function>(Source{}, mod->RegisterSymbol("func"), "func", create<ast::Function>(Source{}, mod->RegisterSymbol("func"), "func",
params, &f32, body, ast::FunctionDecorationList{}); params, &f32, body, ast::FunctionDecorationList{});
@ -1178,15 +1213,17 @@ TEST_F(TypeDeterminerTest, Function_NotRegisterFunctionVariable) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"), ast::StatementList{
"var"), create<ast::VariableDeclStatement>(Source{}, var),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("var"), "var"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f))),
});
ast::VariableList params; ast::VariableList params;
auto* func = auto* func =
create<ast::Function>(Source{}, mod->RegisterSymbol("my_func"), "my_func", create<ast::Function>(Source{}, mod->RegisterSymbol("my_func"), "my_func",
@ -2869,8 +2906,9 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* stmt = create<ast::VariableDeclStatement>(Source{}, var); auto* stmt = create<ast::VariableDeclStatement>(Source{}, var);
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(Source{}, ast::StatementList{
body->append(stmt); stmt,
});
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"), auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"),
"func", ast::VariableList{}, &i32, body, "func", ast::VariableList{}, &i32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -2894,8 +2932,9 @@ TEST_F(TypeDeterminerTest, StorageClass_DoesNotSetOnConst) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* stmt = create<ast::VariableDeclStatement>(Source{}, var); auto* stmt = create<ast::VariableDeclStatement>(Source{}, var);
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(Source{}, ast::StatementList{
body->append(stmt); stmt,
});
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"), auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"),
"func", ast::VariableList{}, &i32, body, "func", ast::VariableList{}, &i32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -2919,8 +2958,9 @@ TEST_F(TypeDeterminerTest, StorageClass_NonFunctionClassError) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* stmt = create<ast::VariableDeclStatement>(Source{}, var); auto* stmt = create<ast::VariableDeclStatement>(Source{}, var);
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(Source{}, ast::StatementList{
body->append(stmt); stmt,
});
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"), auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"),
"func", ast::VariableList{}, &i32, body, "func", ast::VariableList{}, &i32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -5237,69 +5277,82 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
// ep_2 -> {} // ep_2 -> {}
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(Source{}, ast::StatementList{});
auto* func_b = auto* func_b =
create<ast::Function>(Source{}, mod->RegisterSymbol("b"), "b", params, create<ast::Function>(Source{}, mod->RegisterSymbol("b"), "b", params,
&f32, body, ast::FunctionDecorationList{}); &f32, body, ast::FunctionDecorationList{});
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("second"), "second"),
create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("second"),
"second"),
create<ast::CallExpression>(Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("b"), "b"), Source{}, mod->RegisterSymbol("b"), "b"),
ast::ExpressionList{}))); ast::ExpressionList{})),
});
auto* func_c = auto* func_c =
create<ast::Function>(Source{}, mod->RegisterSymbol("c"), "c", params, create<ast::Function>(Source{}, mod->RegisterSymbol("c"), "c", params,
&f32, body, ast::FunctionDecorationList{}); &f32, body, ast::FunctionDecorationList{});
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("first"), "first"),
create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("first"),
"first"),
create<ast::CallExpression>(Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("c"), "c"), Source{}, mod->RegisterSymbol("c"), "c"),
ast::ExpressionList{}))); ast::ExpressionList{})),
});
auto* func_a = auto* func_a =
create<ast::Function>(Source{}, mod->RegisterSymbol("a"), "a", params, create<ast::Function>(Source{}, mod->RegisterSymbol("a"), "a", params,
&f32, body, ast::FunctionDecorationList{}); &f32, body, ast::FunctionDecorationList{});
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("call_a"), "call_a"),
create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("call_a"),
"call_a"),
create<ast::CallExpression>(Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a"), Source{}, mod->RegisterSymbol("a"), "a"),
ast::ExpressionList{}))); ast::ExpressionList{})),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("call_b"), "call_b"),
create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("call_b"),
"call_b"),
create<ast::CallExpression>(Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("b"), "b"), Source{}, mod->RegisterSymbol("b"), "b"),
ast::ExpressionList{}))); ast::ExpressionList{})),
});
auto* ep_1 = create<ast::Function>( auto* ep_1 = create<ast::Function>(
Source{}, mod->RegisterSymbol("ep_1"), "ep_1", params, &f32, body, Source{}, mod->RegisterSymbol("ep_1"), "ep_1", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
}); });
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("call_c"), "call_c"),
create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("call_c"),
"call_c"),
create<ast::CallExpression>(Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("c"), "c"), Source{}, mod->RegisterSymbol("c"), "c"),
ast::ExpressionList{}))); ast::ExpressionList{})),
});
auto* ep_2 = create<ast::Function>( auto* ep_2 = create<ast::Function>(
Source{}, mod->RegisterSymbol("ep_2"), "ep_2", params, &f32, body, Source{}, mod->RegisterSymbol("ep_2"), "ep_2", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{

View File

@ -57,14 +57,17 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a"); Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(Source{}); auto* block_default =
create<ast::BlockStatement>(Source{}, ast::StatementList{});
ast::CaseStatementList body; ast::CaseStatementList body;
body.push_back( body.push_back(
create<ast::CaseStatement>(Source{}, default_csl, block_default)); create<ast::CaseStatement>(Source{}, default_csl, block_default));
auto* block = create<ast::BlockStatement>(Source{}); auto* block = create<ast::BlockStatement>(
block->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
block->append(create<ast::SwitchStatement>(Source{}, cond, body)); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::SwitchStatement>(Source{}, cond, body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_FALSE(v()->ValidateStatements(block));
@ -96,12 +99,15 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
csl.push_back(create<ast::SintLiteral>(Source{}, &i32, 1)); csl.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
ast::CaseStatementList body; ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>( body.push_back(create<ast::CaseStatement>(
Source{}, csl, create<ast::BlockStatement>(Source{}))); Source{}, csl,
create<ast::BlockStatement>(Source{}, ast::StatementList{})));
auto* block = create<ast::BlockStatement>(Source{}); auto* block = create<ast::BlockStatement>(
block->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}}, create<ast::VariableDeclStatement>(Source{}, var),
cond, body)); create<ast::SwitchStatement>(
Source{Source::Location{12, 34}}, cond, body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_FALSE(v()->ValidateStatements(block));
@ -134,25 +140,30 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
Source{}, mod()->RegisterSymbol("a"), "a"); Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl_1; ast::CaseSelectorList default_csl_1;
auto* block_default_1 = create<ast::BlockStatement>(Source{}); auto* block_default_1 =
create<ast::BlockStatement>(Source{}, ast::StatementList{});
switch_body.push_back( switch_body.push_back(
create<ast::CaseStatement>(Source{}, default_csl_1, block_default_1)); create<ast::CaseStatement>(Source{}, default_csl_1, block_default_1));
ast::CaseSelectorList csl_case_1; ast::CaseSelectorList csl_case_1;
csl_case_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1)); csl_case_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
auto* block_case_1 = create<ast::BlockStatement>(Source{}); auto* block_case_1 =
create<ast::BlockStatement>(Source{}, ast::StatementList{});
switch_body.push_back( switch_body.push_back(
create<ast::CaseStatement>(Source{}, csl_case_1, block_case_1)); create<ast::CaseStatement>(Source{}, csl_case_1, block_case_1));
ast::CaseSelectorList default_csl_2; ast::CaseSelectorList default_csl_2;
auto* block_default_2 = create<ast::BlockStatement>(Source{}); auto* block_default_2 =
create<ast::BlockStatement>(Source{}, ast::StatementList{});
switch_body.push_back( switch_body.push_back(
create<ast::CaseStatement>(Source{}, default_csl_2, block_default_2)); create<ast::CaseStatement>(Source{}, default_csl_2, block_default_2));
auto* block = create<ast::BlockStatement>(Source{}); auto* block = create<ast::BlockStatement>(
block->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}}, create<ast::VariableDeclStatement>(Source{}, var),
cond, switch_body)); create<ast::SwitchStatement>(
Source{Source::Location{12, 34}}, cond, switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_FALSE(v()->ValidateStatements(block));
@ -187,19 +198,21 @@ TEST_F(ValidateControlBlockTest,
ast::CaseSelectorList csl; ast::CaseSelectorList csl;
csl.push_back(create<ast::UintLiteral>(Source{}, &u32, 1)); csl.push_back(create<ast::UintLiteral>(Source{}, &u32, 1));
switch_body.push_back( switch_body.push_back(create<ast::CaseStatement>(
create<ast::CaseStatement>(Source{Source::Location{12, 34}}, csl, Source{Source::Location{12, 34}}, csl,
create<ast::BlockStatement>(Source{}))); create<ast::BlockStatement>(Source{}, ast::StatementList{})));
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(Source{}); auto* block_default =
create<ast::BlockStatement>(Source{}, ast::StatementList{});
switch_body.push_back( switch_body.push_back(
create<ast::CaseStatement>(Source{}, default_csl, block_default)); create<ast::CaseStatement>(Source{}, default_csl, block_default));
auto* block = create<ast::BlockStatement>(Source{}); auto* block = create<ast::BlockStatement>(
block->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
block->append(create<ast::SwitchStatement>(Source{}, cond, switch_body)); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::SwitchStatement>(Source{}, cond, switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_FALSE(v()->ValidateStatements(block));
EXPECT_EQ(v()->error(), EXPECT_EQ(v()->error(),
@ -233,19 +246,21 @@ TEST_F(ValidateControlBlockTest,
ast::CaseSelectorList csl; ast::CaseSelectorList csl;
csl.push_back(create<ast::SintLiteral>(Source{}, &i32, -1)); csl.push_back(create<ast::SintLiteral>(Source{}, &i32, -1));
switch_body.push_back( switch_body.push_back(create<ast::CaseStatement>(
create<ast::CaseStatement>(Source{Source::Location{12, 34}}, csl, Source{Source::Location{12, 34}}, csl,
create<ast::BlockStatement>(Source{}))); create<ast::BlockStatement>(Source{}, ast::StatementList{})));
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(Source{}); auto* block_default =
create<ast::BlockStatement>(Source{}, ast::StatementList{});
switch_body.push_back( switch_body.push_back(
create<ast::CaseStatement>(Source{}, default_csl, block_default)); create<ast::CaseStatement>(Source{}, default_csl, block_default));
auto* block = create<ast::BlockStatement>(Source{}); auto* block = create<ast::BlockStatement>(
block->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
block->append(create<ast::SwitchStatement>(Source{}, cond, switch_body)); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::SwitchStatement>(Source{}, cond, switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_FALSE(v()->ValidateStatements(block));
EXPECT_EQ(v()->error(), EXPECT_EQ(v()->error(),
@ -279,24 +294,27 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
ast::CaseSelectorList csl_1; ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::UintLiteral>(Source{}, &u32, 0)); csl_1.push_back(create<ast::UintLiteral>(Source{}, &u32, 0));
switch_body.push_back(create<ast::CaseStatement>( switch_body.push_back(create<ast::CaseStatement>(
Source{}, csl_1, create<ast::BlockStatement>(Source{}))); Source{}, csl_1,
create<ast::BlockStatement>(Source{}, ast::StatementList{})));
ast::CaseSelectorList csl_2; ast::CaseSelectorList csl_2;
csl_2.push_back(create<ast::UintLiteral>(Source{}, &u32, 2)); csl_2.push_back(create<ast::UintLiteral>(Source{}, &u32, 2));
csl_2.push_back(create<ast::UintLiteral>(Source{}, &u32, 2)); csl_2.push_back(create<ast::UintLiteral>(Source{}, &u32, 2));
switch_body.push_back( switch_body.push_back(create<ast::CaseStatement>(
create<ast::CaseStatement>(Source{Source::Location{12, 34}}, csl_2, Source{Source::Location{12, 34}}, csl_2,
create<ast::BlockStatement>(Source{}))); create<ast::BlockStatement>(Source{}, ast::StatementList{})));
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(Source{}); auto* block_default =
create<ast::BlockStatement>(Source{}, ast::StatementList{});
switch_body.push_back( switch_body.push_back(
create<ast::CaseStatement>(Source{}, default_csl, block_default)); create<ast::CaseStatement>(Source{}, default_csl, block_default));
auto* block = create<ast::BlockStatement>(Source{}); auto* block = create<ast::BlockStatement>(
block->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
block->append(create<ast::SwitchStatement>(Source{}, cond, switch_body)); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::SwitchStatement>(Source{}, cond, switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_FALSE(v()->ValidateStatements(block));
EXPECT_EQ(v()->error(), EXPECT_EQ(v()->error(),
@ -330,26 +348,29 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
ast::CaseSelectorList csl_1; ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 10)); csl_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 10));
switch_body.push_back(create<ast::CaseStatement>( switch_body.push_back(create<ast::CaseStatement>(
Source{}, csl_1, create<ast::BlockStatement>(Source{}))); Source{}, csl_1,
create<ast::BlockStatement>(Source{}, ast::StatementList{})));
ast::CaseSelectorList csl_2; ast::CaseSelectorList csl_2;
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 0)); csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 0));
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 1)); csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 2)); csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 2));
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 10)); csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 10));
switch_body.push_back( switch_body.push_back(create<ast::CaseStatement>(
create<ast::CaseStatement>(Source{Source::Location{12, 34}}, csl_2, Source{Source::Location{12, 34}}, csl_2,
create<ast::BlockStatement>(Source{}))); create<ast::BlockStatement>(Source{}, ast::StatementList{})));
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(Source{}); auto* block_default =
create<ast::BlockStatement>(Source{}, ast::StatementList{});
switch_body.push_back( switch_body.push_back(
create<ast::CaseStatement>(Source{}, default_csl, block_default)); create<ast::CaseStatement>(Source{}, default_csl, block_default));
auto* block = create<ast::BlockStatement>(Source{}); auto* block = create<ast::BlockStatement>(
block->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
block->append(create<ast::SwitchStatement>(Source{}, cond, switch_body)); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::SwitchStatement>(Source{}, cond, switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_FALSE(v()->ValidateStatements(block));
EXPECT_EQ(v()->error(), EXPECT_EQ(v()->error(),
@ -377,17 +398,20 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a"); Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(Source{}); auto* block_default = create<ast::BlockStatement>(
block_default->append( Source{},
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}})); ast::StatementList{
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}),
});
ast::CaseStatementList body; ast::CaseStatementList body;
body.push_back( body.push_back(
create<ast::CaseStatement>(Source{}, default_csl, block_default)); create<ast::CaseStatement>(Source{}, default_csl, block_default));
auto* block = create<ast::BlockStatement>(Source{}); auto* block = create<ast::BlockStatement>(
block->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
block->append(create<ast::SwitchStatement>(Source{}, cond, body)); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::SwitchStatement>(Source{}, cond, body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_FALSE(v()->ValidateStatements(block));
EXPECT_EQ(v()->error(), EXPECT_EQ(v()->error(),
@ -416,19 +440,22 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a"); Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(Source{}); auto* block_default =
create<ast::BlockStatement>(Source{}, ast::StatementList{});
ast::CaseStatementList body; ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}}, body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
default_csl, block_default)); default_csl, block_default));
ast::CaseSelectorList case_csl; ast::CaseSelectorList case_csl;
case_csl.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); case_csl.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
auto* block_case = create<ast::BlockStatement>(Source{}); auto* block_case =
create<ast::BlockStatement>(Source{}, ast::StatementList{});
body.push_back(create<ast::CaseStatement>(Source{}, case_csl, block_case)); body.push_back(create<ast::CaseStatement>(Source{}, case_csl, block_case));
auto* block = create<ast::BlockStatement>(Source{}); auto* block = create<ast::BlockStatement>(
block->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
block->append(create<ast::SwitchStatement>(Source{}, cond, body)); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::SwitchStatement>(Source{}, cond, body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_TRUE(v()->ValidateStatements(block)) << v()->error(); EXPECT_TRUE(v()->ValidateStatements(block)) << v()->error();
} }
@ -457,15 +484,17 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a"); Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(Source{}); auto* block_default =
create<ast::BlockStatement>(Source{}, ast::StatementList{});
ast::CaseStatementList body; ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}}, body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
default_csl, block_default)); default_csl, block_default));
auto* block = create<ast::BlockStatement>(Source{}); auto* block = create<ast::BlockStatement>(
block->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
block->append(create<ast::SwitchStatement>(Source{}, cond, body)); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::SwitchStatement>(Source{}, cond, body),
});
mod()->AddConstructedType(&my_int); mod()->AddConstructedType(&my_int);
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();

View File

@ -52,8 +52,10 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
ast::VariableList params; ast::VariableList params;
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func", Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
params, &void_type, body, params, &void_type, body,
@ -74,7 +76,8 @@ TEST_F(ValidateFunctionTest,
ast::VariableList params; ast::VariableList params;
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func", Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
params, &void_type, create<ast::BlockStatement>(Source{}), params, &void_type,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
}); });
@ -101,8 +104,10 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
ast::VariableList params; ast::VariableList params;
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func", Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
params, &i32, body, ast::FunctionDecorationList{}); params, &i32, body, ast::FunctionDecorationList{});
@ -121,7 +126,7 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
ast::VariableList params; ast::VariableList params;
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func", Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
params, &i32, create<ast::BlockStatement>(Source{}), params, &i32, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod()->AddFunction(func); mod()->AddFunction(func);
@ -137,8 +142,10 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
ast::type::Void void_type; ast::type::Void void_type;
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod()->RegisterSymbol("func"), "func", params, &void_type, body, Source{}, mod()->RegisterSymbol("func"), "func", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -155,12 +162,15 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
ast::type::Void void_type; ast::type::Void void_type;
ast::type::I32 i32; ast::type::I32 i32;
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{});
auto* return_expr = create<ast::ScalarConstructorExpression>( auto* return_expr = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
body->append(create<ast::ReturnStatement>(Source{Source::Location{12, 34}}, auto* body = create<ast::BlockStatement>(
return_expr)); Source{}, ast::StatementList{
create<ast::ReturnStatement>(
Source{Source::Location{12, 34}}, return_expr),
});
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("func"), auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("func"),
"func", params, &void_type, body, "func", params, &void_type, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -179,12 +189,15 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
ast::type::I32 i32; ast::type::I32 i32;
ast::type::F32 f32; ast::type::F32 f32;
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{});
auto* return_expr = create<ast::ScalarConstructorExpression>( auto* return_expr = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
body->append(create<ast::ReturnStatement>(Source{Source::Location{12, 34}}, auto* body = create<ast::BlockStatement>(
return_expr)); Source{}, ast::StatementList{
create<ast::ReturnStatement>(
Source{Source::Location{12, 34}}, return_expr),
});
auto* func = auto* func =
create<ast::Function>(Source{}, mod()->RegisterSymbol("func"), "func", create<ast::Function>(Source{}, mod()->RegisterSymbol("func"), "func",
params, &f32, body, ast::FunctionDecorationList{}); params, &f32, body, ast::FunctionDecorationList{});
@ -205,21 +218,25 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
ast::type::I32 i32; ast::type::I32 i32;
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{});
auto* return_expr = create<ast::ScalarConstructorExpression>( auto* return_expr = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
body->append(create<ast::ReturnStatement>(Source{}, return_expr)); auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}, return_expr),
});
auto* func = auto* func =
create<ast::Function>(Source{}, mod()->RegisterSymbol("func"), "func", create<ast::Function>(Source{}, mod()->RegisterSymbol("func"), "func",
params, &i32, body, ast::FunctionDecorationList{}); params, &i32, body, ast::FunctionDecorationList{});
ast::VariableList params_copy; ast::VariableList params_copy;
auto* body_copy = create<ast::BlockStatement>(Source{});
auto* return_expr_copy = create<ast::ScalarConstructorExpression>( auto* return_expr_copy = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body_copy = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}, return_expr_copy),
});
body_copy->append(create<ast::ReturnStatement>(Source{}, return_expr_copy));
auto* func_copy = create<ast::Function>( auto* func_copy = create<ast::Function>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func", Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
params_copy, &i32, body_copy, ast::FunctionDecorationList{}); params_copy, &i32, body_copy, ast::FunctionDecorationList{});
@ -243,9 +260,11 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
"func"), "func"),
call_params); call_params);
ast::VariableList params0; ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>(Source{}); auto* body0 = create<ast::BlockStatement>(
body0->append(create<ast::CallStatement>(Source{}, call_expr)); Source{}, ast::StatementList{
body0->append(create<ast::ReturnStatement>(Source{})); create<ast::CallStatement>(Source{}, call_expr),
create<ast::ReturnStatement>(Source{}),
});
auto* func0 = create<ast::Function>(Source{}, mod()->RegisterSymbol("func"), auto* func0 = create<ast::Function>(Source{}, mod()->RegisterSymbol("func"),
"func", params0, &f32, body0, "func", params0, &f32, body0,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -275,12 +294,15 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::VariableList params0; ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>(Source{});
body0->append(create<ast::VariableDeclStatement>(Source{}, var));
auto* return_expr = create<ast::ScalarConstructorExpression>( auto* return_expr = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
body0->append(create<ast::ReturnStatement>(Source{}, return_expr)); auto* body0 = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}, return_expr),
});
auto* func0 = create<ast::Function>(Source{}, mod()->RegisterSymbol("func"), auto* func0 = create<ast::Function>(Source{}, mod()->RegisterSymbol("func"),
"func", params0, &i32, body0, "func", params0, &i32, body0,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -299,8 +321,10 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
auto* return_expr = create<ast::ScalarConstructorExpression>( auto* return_expr = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 0)); Source{}, create<ast::SintLiteral>(Source{}, &i32, 0));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{}, return_expr)); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}, return_expr),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("vtx_main"), Source{Source::Location{12, 34}}, mod()->RegisterSymbol("vtx_main"),
"vtx_main", params, &i32, body, "vtx_main", params, &i32, body,
@ -329,8 +353,10 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("vtx_func"), Source{Source::Location{12, 34}}, mod()->RegisterSymbol("vtx_func"),
"vtx_func", params, &void_type, body, "vtx_func", params, &void_type, body,
@ -352,8 +378,10 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
// fn main() -> void { return; } // fn main() -> void { return; }
ast::type::Void void_type; ast::type::Void void_type;
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("main"), "main", Source{Source::Location{12, 34}}, mod()->RegisterSymbol("main"), "main",
params, &void_type, body, params, &void_type, body,
@ -375,8 +403,10 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
// fn vtx_func() -> void { return; } // fn vtx_func() -> void { return; }
ast::type::Void void_type; ast::type::Void void_type;
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params, Source{}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params,
&void_type, body, &void_type, body,
@ -393,8 +423,10 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
// fn vtx_func() -> void { return; } // fn vtx_func() -> void { return; }
ast::type::Void void_type; ast::type::Void void_type;
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params, Source{}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params,
&void_type, body, ast::FunctionDecorationList{}); &void_type, body, ast::FunctionDecorationList{});

View File

@ -103,9 +103,11 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) {
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
Source{Source::Location{12, 34}}, lhs, rhs)); create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs),
});
EXPECT_FALSE(td()->DetermineStatements(body)); EXPECT_FALSE(td()->DetermineStatements(body));
EXPECT_EQ(td()->error(), EXPECT_EQ(td()->error(),
@ -199,10 +201,12 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::AssignmentStatement>( create<ast::VariableDeclStatement>(Source{}, var),
Source{Source::Location{12, 34}}, lhs, rhs)); create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs),
});
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(lhs->result_type(), nullptr);
@ -234,10 +238,12 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f)); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
ast::BlockStatement block(Source{}); ast::BlockStatement block(
block.append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
block.append(create<ast::AssignmentStatement>( create<ast::VariableDeclStatement>(Source{}, var),
Source{Source::Location{12, 34}}, lhs, rhs)); create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs),
});
EXPECT_TRUE(td()->DetermineStatements(&block)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(&block)) << td()->error();
ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(lhs->result_type(), nullptr);
@ -339,9 +345,11 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f)); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
Source{Source::Location{12, 34}}, lhs, rhs)); create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs),
});
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"), auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"),
"my_func", params, &f32, body, "my_func", params, &f32, body,
@ -379,10 +387,13 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
Source{Source::Location{12, 34}}, lhs, rhs)); create<ast::AssignmentStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{Source::Location{12, 34}}, lhs, rhs),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod()->RegisterSymbol("my_func"), "my_func", params, &void_type, Source{}, mod()->RegisterSymbol("my_func"), "my_func", params, &void_type,
body, body,
@ -415,19 +426,23 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
ast::type::Bool bool_type; ast::type::Bool bool_type;
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
});
auto* lhs = create<ast::IdentifierExpression>( auto* lhs = create<ast::IdentifierExpression>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a"); Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f)); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
auto* outer_body = create<ast::BlockStatement>(Source{}); auto* outer_body = create<ast::BlockStatement>(
outer_body->append( Source{}, ast::StatementList{
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{})); create<ast::IfStatement>(Source{}, cond, body,
outer_body->append(create<ast::AssignmentStatement>( ast::ElseStatementList{}),
Source{Source::Location{12, 34}}, lhs, rhs)); create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs),
});
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);
@ -461,14 +476,19 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
ast::type::Bool bool_type; ast::type::Bool bool_type;
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
Source{Source::Location{12, 34}}, lhs, rhs)); create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs),
});
auto* outer_body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::IfStatement>(Source{}, cond, body,
ast::ElseStatementList{}),
});
auto* outer_body = create<ast::BlockStatement>(Source{});
outer_body->append(create<ast::VariableDeclStatement>(Source{}, var));
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);
@ -564,10 +584,12 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::AssignmentStatement>( create<ast::VariableDeclStatement>(Source{}, var),
Source{Source::Location{12, 34}}, lhs, rhs)); create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs),
});
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(lhs->result_type(), nullptr);
@ -609,9 +631,12 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
create<ast::FloatLiteral>(Source{}, &f32, 2.0)), // constructor create<ast::FloatLiteral>(Source{}, &f32, 2.0)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>( Source{}, ast::StatementList{
Source{Source::Location{12, 34}}, var)); create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var),
});
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"), auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"),
"my_func", params, &void_type, body, "my_func", params, &void_type, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -655,10 +680,13 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::VariableDeclStatement>( create<ast::VariableDeclStatement>(Source{}, var),
Source{Source::Location{12, 34}}, var_a_float)); create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var_a_float),
});
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"), auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"),
"my_func", params, &void_type, body, "my_func", params, &void_type, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -691,8 +719,10 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
ast::type::Bool bool_type; ast::type::Bool bool_type;
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
});
auto* var_a_float = create<ast::Variable>( auto* var_a_float = create<ast::Variable>(
Source{}, // source Source{}, // source
@ -705,11 +735,13 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
create<ast::FloatLiteral>(Source{}, &f32, 3.14)), // constructor create<ast::FloatLiteral>(Source{}, &f32, 3.14)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* outer_body = create<ast::BlockStatement>(Source{}); auto* outer_body = create<ast::BlockStatement>(
outer_body->append( Source{}, ast::StatementList{
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{})); create<ast::IfStatement>(Source{}, cond, body,
outer_body->append(create<ast::VariableDeclStatement>( ast::ElseStatementList{}),
Source{Source::Location{12, 34}}, var_a_float)); create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var_a_float),
});
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
EXPECT_TRUE(v()->ValidateStatements(outer_body)) << v()->error(); EXPECT_TRUE(v()->ValidateStatements(outer_body)) << v()->error();
@ -748,14 +780,18 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
ast::type::Bool bool_type; ast::type::Bool bool_type;
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>( Source{}, ast::StatementList{
Source{Source::Location{12, 34}}, var)); create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var),
});
auto* outer_body = create<ast::BlockStatement>(Source{}); auto* outer_body = create<ast::BlockStatement>(
outer_body->append(create<ast::VariableDeclStatement>(Source{}, var_a_float)); Source{}, ast::StatementList{
outer_body->append( create<ast::VariableDeclStatement>(Source{}, var_a_float),
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{})); 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));
@ -790,19 +826,24 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::VariableList params0; ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>(Source{}); auto* body0 = create<ast::BlockStatement>(
body0->append(create<ast::VariableDeclStatement>( Source{}, ast::StatementList{
Source{Source::Location{12, 34}}, var0)); create<ast::VariableDeclStatement>(
body0->append(create<ast::ReturnStatement>(Source{})); Source{Source::Location{12, 34}}, var0),
create<ast::ReturnStatement>(Source{}),
});
auto* func0 = create<ast::Function>(Source{}, mod()->RegisterSymbol("func0"), auto* func0 = create<ast::Function>(Source{}, mod()->RegisterSymbol("func0"),
"func0", params0, &void_type, body0, "func0", params0, &void_type, body0,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ast::VariableList params1; ast::VariableList params1;
auto* body1 = create<ast::BlockStatement>(Source{}); auto* body1 = create<ast::BlockStatement>(
body1->append(create<ast::VariableDeclStatement>( Source{}, ast::StatementList{
Source{Source::Location{13, 34}}, var1)); create<ast::VariableDeclStatement>(
body1->append(create<ast::ReturnStatement>(Source{})); Source{Source::Location{13, 34}}, var1),
create<ast::ReturnStatement>(Source{}),
});
auto* func1 = create<ast::Function>( auto* func1 = create<ast::Function>(
Source{}, mod()->RegisterSymbol("func1"), "func1", params1, &void_type, Source{}, mod()->RegisterSymbol("func1"), "func1", params1, &void_type,
body1, body1,
@ -838,10 +879,12 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::AssignmentStatement>( create<ast::VariableDeclStatement>(Source{}, var),
Source{Source::Location{12, 34}}, lhs, rhs)); create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs),
});
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error(); EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(lhs->result_type(), nullptr);

View File

@ -203,10 +203,11 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::VariableList params; ast::VariableList params;
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>( Source{}, ast::StatementList{
Source{Source::Location{12, 34}}, var)); create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod()->RegisterSymbol("func"), "func", params, &void_type, body, Source{}, mod()->RegisterSymbol("func"), "func", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{

View File

@ -464,16 +464,22 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
ast::type::I32 i32; ast::type::I32 i32;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{}, ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::ScalarConstructorExpression>( Source{}, create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)))); Source{}, create<ast::SintLiteral>(
Source{}, &i32, 3))),
});
auto* else_stmt = create<ast::ElseStatement>(Source{}, nullptr, body); auto* else_stmt = create<ast::ElseStatement>(Source{}, nullptr, body);
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{}, ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::ScalarConstructorExpression>( Source{}, create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)))); Source{}, create<ast::SintLiteral>(
Source{}, &i32, 2))),
});
auto* else_if_stmt = create<ast::ElseStatement>( auto* else_if_stmt = create<ast::ElseStatement>(
Source{}, Source{},
create<ast::BinaryExpression>( create<ast::BinaryExpression>(
@ -484,10 +490,13 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
"c")), "c")),
body); body);
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{}, ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::ScalarConstructorExpression>( Source{}, create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)))); Source{}, create<ast::SintLiteral>(
Source{}, &i32, 1))),
});
ast::IfStatement expr(Source{}, ast::IfStatement expr(Source{},
create<ast::BinaryExpression>( create<ast::BinaryExpression>(
@ -659,9 +668,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
ast::type::Void void_type; ast::type::Void void_type;
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("foo"), "foo", auto* func = create<ast::Function>(
ast::VariableList{}, &void_type, Source{}, mod.RegisterSymbol("foo"), "foo", ast::VariableList{},
create<ast::BlockStatement>(Source{}), &void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod.AddFunction(func);

View File

@ -26,9 +26,9 @@ namespace {
using HlslGeneratorImplTest_Block = TestHelper; using HlslGeneratorImplTest_Block = TestHelper;
TEST_F(HlslGeneratorImplTest_Block, Emit_Block) { TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
ast::BlockStatement b(Source{}); ast::BlockStatement b(Source{}, ast::StatementList{
b.append(create<ast::DiscardStatement>(Source{})); create<ast::DiscardStatement>(Source{}),
});
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &b)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, &b)) << gen.error();
@ -39,9 +39,9 @@ TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
} }
TEST_F(HlslGeneratorImplTest_Block, Emit_Block_WithoutNewline) { TEST_F(HlslGeneratorImplTest_Block, Emit_Block_WithoutNewline) {
ast::BlockStatement b(Source{}); ast::BlockStatement b(Source{}, ast::StatementList{
b.append(create<ast::DiscardStatement>(Source{})); create<ast::DiscardStatement>(Source{}),
});
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitBlock(out, &b)) << gen.error(); ASSERT_TRUE(gen.EmitBlock(out, &b)) << gen.error();

View File

@ -36,9 +36,9 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
Source{}, mod.RegisterSymbol("my_func"), "my_func"); Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::CallExpression call(Source{}, id, {}); ast::CallExpression call(Source{}, id, {});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(
"my_func", ast::VariableList{}, &void_type, Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
create<ast::BlockStatement>(Source{}), &void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod.AddFunction(func);
@ -58,9 +58,9 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
Source{}, mod.RegisterSymbol("param2"), "param2")); Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(Source{}, id, params); ast::CallExpression call(Source{}, id, params);
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(
"my_func", ast::VariableList{}, &void_type, Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
create<ast::BlockStatement>(Source{}), &void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod.AddFunction(func);
@ -81,9 +81,9 @@ TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
ast::CallStatement call(Source{}, ast::CallStatement call(Source{},
create<ast::CallExpression>(Source{}, id, params)); create<ast::CallExpression>(Source{}, id, params));
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(
"my_func", ast::VariableList{}, &void_type, Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
create<ast::BlockStatement>(Source{}), &void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod.AddFunction(func);
gen.increment_indent(); gen.increment_indent();

View File

@ -33,9 +33,10 @@ using HlslGeneratorImplTest_Case = TestHelper;
TEST_F(HlslGeneratorImplTest_Case, Emit_Case) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case) {
ast::type::I32 i32; ast::type::I32 i32;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
ast::CaseStatement c(Source{}, lit, body); ast::CaseStatement c(Source{}, lit, body);
@ -54,7 +55,9 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
ast::CaseStatement c(Source{}, lit, create<ast::BlockStatement>(Source{})); ast::CaseStatement c(
Source{}, lit,
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
gen.increment_indent(); gen.increment_indent();
@ -68,9 +71,10 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
ast::type::I32 i32; ast::type::I32 i32;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::FallthroughStatement>(Source{})); Source{}, ast::StatementList{
create<ast::FallthroughStatement>(Source{}),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
ast::CaseStatement c(Source{}, lit, body); ast::CaseStatement c(Source{}, lit, body);
@ -87,9 +91,10 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
ast::type::I32 i32; ast::type::I32 i32;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 6)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 6));
@ -106,8 +111,10 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
} }
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body); ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body);
gen.increment_indent(); gen.increment_indent();

View File

@ -82,20 +82,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"), Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"))); Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -161,20 +162,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"), Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"))); Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -240,20 +242,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"), Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"))); Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -318,20 +321,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"), Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"))); Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -393,20 +397,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"), Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"))); Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -463,20 +468,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"), Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"))); Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -540,18 +546,19 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(depth_var); mod.AddGlobalVariable(depth_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"), create<ast::IdentifierExpression>(
"depth"), Source{}, mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"), Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"), create<ast::IdentifierExpression>(
"x")))); Source{}, mod.RegisterSymbol("x"), "x"))),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body, Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{

View File

@ -55,8 +55,10 @@ using HlslGeneratorImplTest_Function = TestHelper;
TEST_F(HlslGeneratorImplTest_Function, Emit_Function) { TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", ast::VariableList{}, &void_type, "my_func", ast::VariableList{}, &void_type,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -75,8 +77,10 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) { TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("GeometryShader"), "GeometryShader", Source{}, mod.RegisterSymbol("GeometryShader"), "GeometryShader",
ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{}); ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{});
@ -116,8 +120,10 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", params, &void_type, body, "my_func", params, &void_type, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -169,14 +175,16 @@ TEST_F(HlslGeneratorImplTest_Function,
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::ReturnStatement>(Source{})); create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -242,18 +250,20 @@ TEST_F(HlslGeneratorImplTest_Function,
mod.AddGlobalVariable(depth_var); mod.AddGlobalVariable(depth_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"), create<ast::IdentifierExpression>(
"depth"), Source{}, mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"), Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"), create<ast::IdentifierExpression>(
"x")))); Source{}, mod.RegisterSymbol("x"), "x"))),
body->append(create<ast::ReturnStatement>(Source{})); create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -319,9 +329,11 @@ TEST_F(HlslGeneratorImplTest_Function,
"x")), // constructor "x")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -397,9 +409,11 @@ TEST_F(HlslGeneratorImplTest_Function,
"x")), // constructor "x")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -477,9 +491,11 @@ TEST_F(HlslGeneratorImplTest_Function,
"b")), // constructor "b")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -553,9 +569,11 @@ TEST_F(HlslGeneratorImplTest_Function,
"b")), // constructor "b")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -615,24 +633,25 @@ TEST_F(HlslGeneratorImplTest_Function,
mod.AddGlobalVariable(coord_var); mod.AddGlobalVariable(coord_var);
ast::VariableList params; auto* body = create<ast::BlockStatement>(
auto* assign = create<ast::AssignmentStatement>( Source{},
ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"), Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), create<ast::IdentifierExpression>(
"b")), Source{}, mod.RegisterSymbol("b"), "b")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f))),
create<ast::ReturnStatement>(Source{}),
});
auto* body = create<ast::BlockStatement>(Source{});
body->append(assign);
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main",
&void_type, body, ast::VariableList{}, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
}); });
@ -711,22 +730,25 @@ TEST_F(
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), ast::StatementList{
"bar"), create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("val"), create<ast::IdentifierExpression>(
"val"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("param"), create<ast::IdentifierExpression>(
"param"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::ReturnStatement>( create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("val"), "val"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param"), "param")),
create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>( Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
});
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -737,17 +759,20 @@ TEST_F(
expr.push_back(create<ast::ScalarConstructorExpression>( expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), ast::StatementList{
"bar"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::CallExpression>( create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr))); expr)),
body->append(create<ast::ReturnStatement>(Source{})); create<ast::ReturnStatement>(Source{}),
});
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -814,10 +839,13 @@ TEST_F(HlslGeneratorImplTest_Function,
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{},
ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>( Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param"), "param"))); Source{}, mod.RegisterSymbol("param"), "param")),
});
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -828,17 +856,20 @@ TEST_F(HlslGeneratorImplTest_Function,
expr.push_back(create<ast::ScalarConstructorExpression>( expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"), ast::StatementList{
"depth"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("depth"), "depth"),
create<ast::CallExpression>( create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr))); expr)),
body->append(create<ast::ReturnStatement>(Source{})); create<ast::ReturnStatement>(Source{}),
});
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -913,20 +944,23 @@ TEST_F(
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"), ast::StatementList{
"depth"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"), Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"), create<ast::IdentifierExpression>(
"x")))); Source{}, mod.RegisterSymbol("x"), "x"))),
body->append(create<ast::ReturnStatement>( create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>( Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param"), "param"))); Source{}, mod.RegisterSymbol("param"), "param")),
});
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -937,17 +971,20 @@ TEST_F(
expr.push_back(create<ast::ScalarConstructorExpression>( expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"), ast::StatementList{
"depth"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("depth"), "depth"),
create<ast::CallExpression>( create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr))); expr)),
body->append(create<ast::ReturnStatement>(Source{})); create<ast::ReturnStatement>(Source{}),
});
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -1013,14 +1050,18 @@ TEST_F(HlslGeneratorImplTest_Function,
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{},
ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>( Source{}, create<ast::MemberAccessorExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"), Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("x"), "x")))); Source{}, mod.RegisterSymbol("x"), "x"))),
});
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -1044,9 +1085,12 @@ TEST_F(HlslGeneratorImplTest_Function,
expr), // constructor expr), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -1107,14 +1151,18 @@ TEST_F(HlslGeneratorImplTest_Function,
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{},
ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>( Source{}, create<ast::MemberAccessorExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"), Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("x"), "x")))); Source{}, mod.RegisterSymbol("x"), "x"))),
});
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -1138,9 +1186,12 @@ TEST_F(HlslGeneratorImplTest_Function,
expr), // constructor expr), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -1187,19 +1238,22 @@ TEST_F(HlslGeneratorImplTest_Function,
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
auto* list = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), ast::StatementList{
"bar"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))),
create<ast::IfStatement>(
auto* list = create<ast::BlockStatement>(Source{});
list->append(create<ast::ReturnStatement>(Source{}));
body->append(create<ast::IfStatement>(
Source{}, Source{},
create<ast::BinaryExpression>( create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kEqual, Source{}, ast::BinaryOp::kEqual,
@ -1207,9 +1261,10 @@ TEST_F(HlslGeneratorImplTest_Function,
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)), Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))), Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))),
list, ast::ElseStatementList{})); list, ast::ElseStatementList{}),
create<ast::ReturnStatement>(Source{}),
});
body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -1242,7 +1297,8 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("GeometryShader"), "GeometryShader", Source{}, mod.RegisterSymbol("GeometryShader"), "GeometryShader",
ast::VariableList{}, &void_type, create<ast::BlockStatement>(Source{}), ast::VariableList{}, &void_type,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
}); });
@ -1261,8 +1317,11 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::type::Void void_type; ast::type::Void void_type;
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body, Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -1286,8 +1345,11 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::type::Void void_type; ast::type::Void void_type;
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body, Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -1323,8 +1385,10 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", params, &void_type, body, "my_func", params, &void_type, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -1407,9 +1471,12 @@ TEST_F(HlslGeneratorImplTest_Function,
"d")), // constructor "d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("a"), "a", params, &void_type, body, Source{}, mod.RegisterSymbol("a"), "a", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -1436,9 +1503,12 @@ TEST_F(HlslGeneratorImplTest_Function,
"d")), // constructor "d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("b"), "b", params, &void_type, body, Source{}, mod.RegisterSymbol("b"), "b", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{

View File

@ -29,9 +29,10 @@ using HlslGeneratorImplTest_If = TestHelper;
TEST_F(HlslGeneratorImplTest_If, Emit_If) { TEST_F(HlslGeneratorImplTest_If, Emit_If) {
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond"); Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{}); ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
gen.increment_indent(); gen.increment_indent();
@ -45,14 +46,17 @@ TEST_F(HlslGeneratorImplTest_If, Emit_If) {
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
auto* else_cond = create<ast::IdentifierExpression>( auto* else_cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>(Source{}); auto* else_body = create<ast::BlockStatement>(
else_body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond"); Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::IfStatement i( ast::IfStatement i(
Source{}, cond, body, Source{}, cond, body,
{create<ast::ElseStatement>(Source{}, else_cond, else_body)}); {create<ast::ElseStatement>(Source{}, else_cond, else_body)});
@ -71,14 +75,17 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
} }
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>(Source{}); auto* else_body = create<ast::BlockStatement>(
else_body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond"); Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::IfStatement i( ast::IfStatement i(
Source{}, cond, body, Source{}, cond, body,
{create<ast::ElseStatement>(Source{}, nullptr, else_body)}); {create<ast::ElseStatement>(Source{}, nullptr, else_body)});
@ -98,17 +105,22 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
auto* else_cond = create<ast::IdentifierExpression>( auto* else_cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>(Source{}); auto* else_body = create<ast::BlockStatement>(
else_body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* else_body_2 = create<ast::BlockStatement>(Source{}); auto* else_body_2 = create<ast::BlockStatement>(
else_body_2->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond"); Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::IfStatement i( ast::IfStatement i(
Source{}, cond, body, Source{}, cond, body,
{ {

View File

@ -34,9 +34,10 @@ namespace {
using HlslGeneratorImplTest_Loop = TestHelper; using HlslGeneratorImplTest_Loop = TestHelper;
TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) { TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
ast::LoopStatement l(Source{}, body, {}); ast::LoopStatement l(Source{}, body, {});
gen.increment_indent(); gen.increment_indent();
@ -48,12 +49,14 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
} }
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) { TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
auto* continuing = create<ast::BlockStatement>(Source{}); });
continuing->append(create<ast::ReturnStatement>(Source{})); auto* continuing = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::LoopStatement l(Source{}, body, continuing); ast::LoopStatement l(Source{}, body, continuing);
gen.increment_indent(); gen.increment_indent();
@ -75,24 +78,29 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) { TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
ast::type::F32 f32; ast::type::F32 f32;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
auto* continuing = create<ast::BlockStatement>(Source{}); });
continuing->append(create<ast::ReturnStatement>(Source{})); auto* continuing = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* inner = create<ast::LoopStatement>(Source{}, body, continuing); auto* inner = create<ast::LoopStatement>(Source{}, body, continuing);
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(Source{}, ast::StatementList{
body->append(inner); inner,
});
auto* lhs = create<ast::IdentifierExpression>( auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("lhs"), "lhs"); Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>( auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs"); Source{}, mod.RegisterSymbol("rhs"), "rhs");
continuing = create<ast::BlockStatement>(Source{}); continuing = create<ast::BlockStatement>(
continuing->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs)); Source{}, ast::StatementList{
create<ast::AssignmentStatement>(Source{}, lhs, rhs),
});
ast::LoopStatement outer(Source{}, body, continuing); ast::LoopStatement outer(Source{}, body, continuing);
gen.increment_indent(); gen.increment_indent();
@ -157,26 +165,30 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
create<ast::FloatLiteral>(Source{}, &f32, 2.4)), // constructor create<ast::FloatLiteral>(Source{}, &f32, 2.4)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::VariableDeclStatement>(
Source{}, Source{},
create<ast::Variable>(Source{}, // source ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::VariableDeclStatement>(
Source{}, create<ast::Variable>(
Source{}, // source
"other", // name "other", // name
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
&f32, // type &f32, // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}))); // decorations ast::VariableDecorationList{})),
});
auto* lhs = create<ast::IdentifierExpression>( auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("lhs"), "lhs"); Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>( auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs"); Source{}, mod.RegisterSymbol("rhs"), "rhs");
auto* continuing = create<ast::BlockStatement>(Source{}); auto* continuing = create<ast::BlockStatement>(
continuing->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs)); Source{}, ast::StatementList{
create<ast::AssignmentStatement>(Source{}, lhs, rhs),
});
ast::LoopStatement outer(Source{}, body, continuing); ast::LoopStatement outer(Source{}, body, continuing);
gen.increment_indent(); gen.increment_indent();

View File

@ -31,8 +31,10 @@ namespace {
using HlslGeneratorImplTest_Switch = TestHelper; using HlslGeneratorImplTest_Switch = TestHelper;
TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) { TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
auto* def_body = create<ast::BlockStatement>(Source{}); auto* def_body = create<ast::BlockStatement>(
def_body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
auto* def = auto* def =
create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, def_body); create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, def_body);
@ -40,8 +42,10 @@ TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
ast::CaseSelectorList case_val; ast::CaseSelectorList case_val;
case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
auto* case_body = create<ast::BlockStatement>(Source{}); auto* case_body = create<ast::BlockStatement>(
case_body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
auto* case_stmt = create<ast::CaseStatement>(Source{}, case_val, case_body); auto* case_stmt = create<ast::CaseStatement>(Source{}, case_val, case_body);

View File

@ -29,9 +29,9 @@ using HlslGeneratorImplTest = TestHelper;
TEST_F(HlslGeneratorImplTest, Generate) { TEST_F(HlslGeneratorImplTest, Generate) {
ast::type::Void void_type; ast::type::Void void_type;
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(
"my_func", ast::VariableList{}, &void_type, Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
create<ast::BlockStatement>(Source{}), &void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod.AddFunction(func);

View File

@ -28,9 +28,9 @@ namespace {
using MslGeneratorImplTest = TestHelper; using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Block) { TEST_F(MslGeneratorImplTest, Emit_Block) {
ast::BlockStatement b(Source{}); ast::BlockStatement b(Source{}, ast::StatementList{
b.append(create<ast::DiscardStatement>(Source{})); create<ast::DiscardStatement>(Source{}),
});
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(&b)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(&b)) << gen.error();
@ -41,9 +41,9 @@ TEST_F(MslGeneratorImplTest, Emit_Block) {
} }
TEST_F(MslGeneratorImplTest, Emit_Block_WithoutNewline) { TEST_F(MslGeneratorImplTest, Emit_Block_WithoutNewline) {
ast::BlockStatement b(Source{}); ast::BlockStatement b(Source{}, ast::StatementList{
b.append(create<ast::DiscardStatement>(Source{})); create<ast::DiscardStatement>(Source{}),
});
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitBlock(&b)) << gen.error(); ASSERT_TRUE(gen.EmitBlock(&b)) << gen.error();

View File

@ -38,9 +38,9 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
Source{}, mod.RegisterSymbol("my_func"), "my_func"); Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::CallExpression call(Source{}, id, {}); ast::CallExpression call(Source{}, id, {});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(
"my_func", ast::VariableList{}, &void_type, Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
create<ast::BlockStatement>(Source{}), &void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod.AddFunction(func);
@ -60,9 +60,9 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
Source{}, mod.RegisterSymbol("param2"), "param2")); Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(Source{}, id, params); ast::CallExpression call(Source{}, id, params);
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(
"my_func", ast::VariableList{}, &void_type, Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
create<ast::BlockStatement>(Source{}), &void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod.AddFunction(func);
@ -83,9 +83,9 @@ TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
ast::CallStatement call(Source{}, ast::CallStatement call(Source{},
create<ast::CallExpression>(Source{}, id, params)); create<ast::CallExpression>(Source{}, id, params));
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(
"my_func", ast::VariableList{}, &void_type, Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
create<ast::BlockStatement>(Source{}), &void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod.AddFunction(func);

View File

@ -35,9 +35,10 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Case) { TEST_F(MslGeneratorImplTest, Emit_Case) {
ast::type::I32 i32; ast::type::I32 i32;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
ast::CaseStatement c(Source{}, lit, body); ast::CaseStatement c(Source{}, lit, body);
@ -56,7 +57,9 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
ast::CaseStatement c(Source{}, lit, create<ast::BlockStatement>(Source{})); ast::CaseStatement c(
Source{}, lit,
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
gen.increment_indent(); gen.increment_indent();
@ -70,9 +73,10 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) { TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
ast::type::I32 i32; ast::type::I32 i32;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::FallthroughStatement>(Source{})); Source{}, ast::StatementList{
create<ast::FallthroughStatement>(Source{}),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
ast::CaseStatement c(Source{}, lit, body); ast::CaseStatement c(Source{}, lit, body);
@ -89,9 +93,10 @@ TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) { TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
ast::type::I32 i32; ast::type::I32 i32;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 6)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 6));
@ -108,8 +113,10 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
} }
TEST_F(MslGeneratorImplTest, Emit_Case_Default) { TEST_F(MslGeneratorImplTest, Emit_Case_Default) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body); ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body);
gen.increment_indent(); gen.increment_indent();

View File

@ -81,20 +81,21 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"), Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"))); Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -157,20 +158,21 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"), Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"))); Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -233,19 +235,21 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"), Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"))); Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -308,20 +312,21 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"), Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"))); Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -381,20 +386,21 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"), Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"))); Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -449,20 +455,21 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"), Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"))); Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -524,18 +531,19 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"), create<ast::IdentifierExpression>(
"depth"), Source{}, mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"), Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"), create<ast::IdentifierExpression>(
"x")))); Source{}, mod.RegisterSymbol("x"), "x"))),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body, Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{

View File

@ -58,8 +58,11 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Function) { TEST_F(MslGeneratorImplTest, Emit_Function) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", ast::VariableList{}, &void_type, "my_func", ast::VariableList{}, &void_type,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -80,8 +83,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function) {
TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) { TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("main"), auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("main"),
"main", ast::VariableList{}, &void_type, "main", ast::VariableList{}, &void_type,
body, ast::FunctionDecorationList{}); body, ast::FunctionDecorationList{});
@ -123,8 +129,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", params, &void_type, body, "my_func", params, &void_type, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -177,15 +186,16 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), create<ast::IdentifierExpression>(
"bar"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"), create<ast::IdentifierExpression>(
"foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::ReturnStatement>(Source{})); create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -253,19 +263,20 @@ TEST_F(MslGeneratorImplTest,
mod.AddGlobalVariable(depth_var); mod.AddGlobalVariable(depth_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"), create<ast::IdentifierExpression>(
"depth"), Source{}, mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"), Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"), create<ast::IdentifierExpression>(
"x")))); Source{}, mod.RegisterSymbol("x"), "x"))),
body->append(create<ast::ReturnStatement>(Source{})); create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -330,10 +341,11 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
"x")), // constructor "x")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -411,10 +423,11 @@ TEST_F(MslGeneratorImplTest,
"b")), // constructor "b")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -497,10 +510,11 @@ TEST_F(MslGeneratorImplTest,
"b")), // constructor "b")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body, &void_type, body,
@ -588,22 +602,25 @@ TEST_F(
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), ast::StatementList{
"bar"), create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("val"), create<ast::IdentifierExpression>(
"val"), Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("param"), create<ast::IdentifierExpression>(
"param"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
body->append(create<ast::ReturnStatement>( create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("val"), "val"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param"), "param")),
create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>( Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo"))); Source{}, mod.RegisterSymbol("foo"), "foo")),
});
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -614,17 +631,20 @@ TEST_F(
expr.push_back(create<ast::ScalarConstructorExpression>( expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), ast::StatementList{
"bar"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::CallExpression>( create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr))); expr)),
body->append(create<ast::ReturnStatement>(Source{})); create<ast::ReturnStatement>(Source{}),
});
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -694,10 +714,13 @@ TEST_F(MslGeneratorImplTest,
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{},
ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>( Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param"), "param"))); Source{}, mod.RegisterSymbol("param"), "param")),
});
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -708,17 +731,20 @@ TEST_F(MslGeneratorImplTest,
expr.push_back(create<ast::ScalarConstructorExpression>( expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"), ast::StatementList{
"depth"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("depth"), "depth"),
create<ast::CallExpression>( create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr))); expr)),
body->append(create<ast::ReturnStatement>(Source{})); create<ast::ReturnStatement>(Source{}),
});
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body,
@ -797,20 +823,23 @@ TEST_F(
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"), ast::StatementList{
"depth"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"), Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"), create<ast::IdentifierExpression>(
"x")))); Source{}, mod.RegisterSymbol("x"), "x"))),
body->append(create<ast::ReturnStatement>( create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>( Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param"), "param"))); Source{}, mod.RegisterSymbol("param"), "param")),
});
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -821,17 +850,20 @@ TEST_F(
expr.push_back(create<ast::ScalarConstructorExpression>( expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"), ast::StatementList{
"depth"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("depth"), "depth"),
create<ast::CallExpression>( create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr))); expr)),
body->append(create<ast::ReturnStatement>(Source{})); create<ast::ReturnStatement>(Source{}),
});
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -895,14 +927,17 @@ TEST_F(MslGeneratorImplTest,
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{},
ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>( Source{}, create<ast::MemberAccessorExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"), Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("x"), "x")))); Source{}, mod.RegisterSymbol("x"), "x"))),
});
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -926,9 +961,11 @@ TEST_F(MslGeneratorImplTest,
expr), // constructor expr), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -1004,14 +1041,17 @@ TEST_F(MslGeneratorImplTest,
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{},
ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>( Source{}, create<ast::MemberAccessorExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"), Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("b"), "b")))); Source{}, mod.RegisterSymbol("b"), "b"))),
});
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -1035,9 +1075,11 @@ TEST_F(MslGeneratorImplTest,
expr), // constructor expr), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -1119,14 +1161,17 @@ TEST_F(MslGeneratorImplTest,
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{},
ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>( Source{}, create<ast::MemberAccessorExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"), Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("b"), "b")))); Source{}, mod.RegisterSymbol("b"), "b"))),
});
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -1150,9 +1195,11 @@ TEST_F(MslGeneratorImplTest,
expr), // constructor expr), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -1207,18 +1254,21 @@ TEST_F(MslGeneratorImplTest,
mod.AddGlobalVariable(bar_var); mod.AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(Source{}); auto* list = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* body = create<ast::BlockStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"), ast::StatementList{
"bar"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))),
create<ast::IfStatement>(
auto* list = create<ast::BlockStatement>(Source{});
list->append(create<ast::ReturnStatement>(Source{}));
body->append(create<ast::IfStatement>(
Source{}, Source{},
create<ast::BinaryExpression>( create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kEqual, Source{}, ast::BinaryOp::kEqual,
@ -1226,9 +1276,9 @@ TEST_F(MslGeneratorImplTest,
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)), Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))), Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))),
list, ast::ElseStatementList{})); list, ast::ElseStatementList{}),
create<ast::ReturnStatement>(Source{}),
body->append(create<ast::ReturnStatement>(Source{})); });
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body,
@ -1264,7 +1314,7 @@ TEST_F(MslGeneratorImplTest,
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", ast::VariableList{}, Source{}, mod.RegisterSymbol("main"), "main", ast::VariableList{},
&void_type, create<ast::BlockStatement>(Source{}), &void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
}); });
@ -1296,8 +1346,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"), auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", params, &void_type, body, "my_func", params, &void_type, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -1384,10 +1437,11 @@ TEST_F(MslGeneratorImplTest,
"d")), // constructor "d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("a"), "a", params, &void_type, body, Source{}, mod.RegisterSymbol("a"), "a", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -1414,10 +1468,11 @@ TEST_F(MslGeneratorImplTest,
"d")), // constructor "d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("b"), "b", params, &void_type, body, Source{}, mod.RegisterSymbol("b"), "b", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{

View File

@ -31,9 +31,10 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_If) { TEST_F(MslGeneratorImplTest, Emit_If) {
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond"); Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{}); ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
gen.increment_indent(); gen.increment_indent();
@ -48,14 +49,17 @@ TEST_F(MslGeneratorImplTest, Emit_If) {
TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) { TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
auto* else_cond = create<ast::IdentifierExpression>( auto* else_cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>(Source{}); auto* else_body = create<ast::BlockStatement>(
else_body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond"); Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::IfStatement i( ast::IfStatement i(
Source{}, cond, body, Source{}, cond, body,
{create<ast::ElseStatement>(Source{}, else_cond, else_body)}); {create<ast::ElseStatement>(Source{}, else_cond, else_body)});
@ -72,14 +76,17 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
} }
TEST_F(MslGeneratorImplTest, Emit_IfWithElse) { TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>(Source{}); auto* else_body = create<ast::BlockStatement>(
else_body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond"); Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::IfStatement i( ast::IfStatement i(
Source{}, cond, body, Source{}, cond, body,
{create<ast::ElseStatement>(Source{}, nullptr, else_body)}); {create<ast::ElseStatement>(Source{}, nullptr, else_body)});
@ -99,17 +106,22 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
auto* else_cond = create<ast::IdentifierExpression>( auto* else_cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>(Source{}); auto* else_body = create<ast::BlockStatement>(
else_body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* else_body_2 = create<ast::BlockStatement>(Source{}); auto* else_body_2 = create<ast::BlockStatement>(
else_body_2->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond"); Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::IfStatement i( ast::IfStatement i(
Source{}, cond, body, Source{}, cond, body,
{ {

View File

@ -36,9 +36,10 @@ namespace {
using MslGeneratorImplTest = TestHelper; using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Loop) { TEST_F(MslGeneratorImplTest, Emit_Loop) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
ast::LoopStatement l(Source{}, body, {}); ast::LoopStatement l(Source{}, body, {});
gen.increment_indent(); gen.increment_indent();
@ -51,12 +52,14 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
} }
TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) { TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
auto* continuing = create<ast::BlockStatement>(Source{}); });
continuing->append(create<ast::ReturnStatement>(Source{})); auto* continuing = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::LoopStatement l(Source{}, body, continuing); ast::LoopStatement l(Source{}, body, continuing);
gen.increment_indent(); gen.increment_indent();
@ -79,24 +82,29 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) { TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
ast::type::F32 f32; ast::type::F32 f32;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
auto* continuing = create<ast::BlockStatement>(Source{}); });
continuing->append(create<ast::ReturnStatement>(Source{})); auto* continuing = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* inner = create<ast::LoopStatement>(Source{}, body, continuing); auto* inner = create<ast::LoopStatement>(Source{}, body, continuing);
body = create<ast::BlockStatement>(Source{}); body = create<ast::BlockStatement>(Source{}, ast::StatementList{
body->append(inner); inner,
});
auto* lhs = create<ast::IdentifierExpression>( auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("lhs"), "lhs"); Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>( auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs"); Source{}, mod.RegisterSymbol("rhs"), "rhs");
continuing = create<ast::BlockStatement>(Source{}); continuing = create<ast::BlockStatement>(
continuing->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs)); Source{}, ast::StatementList{
create<ast::AssignmentStatement>(Source{}, lhs, rhs),
});
ast::LoopStatement outer(Source{}, body, continuing); ast::LoopStatement outer(Source{}, body, continuing);
@ -162,26 +170,30 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
create<ast::FloatLiteral>(Source{}, &f32, 2.4)), // constructor create<ast::FloatLiteral>(Source{}, &f32, 2.4)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::VariableDeclStatement>(
Source{}, Source{},
create<ast::Variable>(Source{}, // source ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::VariableDeclStatement>(
Source{}, create<ast::Variable>(
Source{}, // source
"other", // name "other", // name
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
&f32, // type &f32, // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}))); // decorations ast::VariableDecorationList{})), // decorations
});
auto* lhs = create<ast::IdentifierExpression>( auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("lhs"), "lhs"); Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>( auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs"); Source{}, mod.RegisterSymbol("rhs"), "rhs");
auto* continuing = create<ast::BlockStatement>(Source{}); auto* continuing = create<ast::BlockStatement>(
continuing->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs)); Source{}, ast::StatementList{
create<ast::AssignmentStatement>(Source{}, lhs, rhs),
});
gen.increment_indent(); gen.increment_indent();
ast::LoopStatement outer(Source{}, body, continuing); ast::LoopStatement outer(Source{}, body, continuing);

View File

@ -33,8 +33,10 @@ namespace {
using MslGeneratorImplTest = TestHelper; using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Switch) { TEST_F(MslGeneratorImplTest, Emit_Switch) {
auto* def_body = create<ast::BlockStatement>(Source{}); auto* def_body = create<ast::BlockStatement>(
def_body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
auto* def = auto* def =
create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, def_body); create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, def_body);
@ -42,8 +44,10 @@ TEST_F(MslGeneratorImplTest, Emit_Switch) {
ast::CaseSelectorList case_val; ast::CaseSelectorList case_val;
case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
auto* case_body = create<ast::BlockStatement>(Source{}); auto* case_body = create<ast::BlockStatement>(
case_body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
auto* case_stmt = create<ast::CaseStatement>(Source{}, case_val, case_body); auto* case_stmt = create<ast::CaseStatement>(Source{}, case_val, case_body);

View File

@ -52,7 +52,7 @@ TEST_F(MslGeneratorImplTest, Generate) {
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(Source{}), &void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
}); });

View File

@ -39,48 +39,51 @@ TEST_F(BuilderTest, Block) {
// Note, this test uses shadow variables which aren't allowed in WGSL but // Note, this test uses shadow variables which aren't allowed in WGSL but
// serves to prove the block code is pushing new scopes as needed. // serves to prove the block code is pushing new scopes as needed.
ast::BlockStatement outer(Source{}); auto* inner = create<ast::BlockStatement>(
outer.append(create<ast::VariableDeclStatement>(
Source{}, Source{},
create<ast::Variable>(Source{}, // source ast::StatementList{
create<ast::VariableDeclStatement>(
Source{}, create<ast::Variable>(
Source{}, // source
"var", // name "var", // name
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
&f32, // type &f32, // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}))); // decorations ast::VariableDecorationList{})),
outer.append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"), create<ast::IdentifierExpression>(
"var"), Source{}, mod->RegisterSymbol("var"), "var"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f))),
}); // decorations
auto* inner = create<ast::BlockStatement>(Source{}); ast::BlockStatement outer(
inner->append(create<ast::VariableDeclStatement>(
Source{}, Source{},
create<ast::Variable>(Source{}, // source ast::StatementList{
create<ast::VariableDeclStatement>(
Source{}, create<ast::Variable>(
Source{}, // source
"var", // name "var", // name
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
&f32, // type &f32, // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}))); // decorations ast::VariableDecorationList{})), // decorations
inner->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"), create<ast::IdentifierExpression>(
"var"), Source{}, mod->RegisterSymbol("var"), "var"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f)))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))),
inner,
outer.append(inner); create<ast::AssignmentStatement>(
outer.append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"), create<ast::IdentifierExpression>(
"var"), Source{}, mod->RegisterSymbol("var"), "var"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.0f)))); Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.0f))),
});
ASSERT_TRUE(td.DetermineResultType(&outer)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&outer)) << td.error();

View File

@ -61,19 +61,23 @@ TEST_F(BuilderTest, Expression_Call) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{},
ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::BinaryExpression>( Source{}, create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kAdd, Source{}, ast::BinaryOp::kAdd,
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a"), Source{}, mod->RegisterSymbol("a"), "a"),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("b"), "b")))); Source{}, mod->RegisterSymbol("b"), "b"))),
});
ast::Function a_func(Source{}, mod->RegisterSymbol("a_func"), "a_func", ast::Function a_func(Source{}, mod->RegisterSymbol("a_func"), "a_func",
func_params, &f32, body, ast::FunctionDecorationList{}); func_params, &f32, body, ast::FunctionDecorationList{});
ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {}, ast::Function func(
&void_type, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ast::ExpressionList call_params; ast::ExpressionList call_params;
@ -144,21 +148,24 @@ TEST_F(BuilderTest, Statement_Call) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{},
ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::BinaryExpression>( Source{}, create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kAdd, Source{}, ast::BinaryOp::kAdd,
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a"), Source{}, mod->RegisterSymbol("a"), "a"),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("b"), "b")))); Source{}, mod->RegisterSymbol("b"), "b"))),
});
ast::Function a_func(Source{}, mod->RegisterSymbol("a_func"), "a_func", ast::Function a_func(Source{}, mod->RegisterSymbol("a_func"), "a_func",
func_params, &void_type, body, func_params, &void_type, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {}, ast::Function func(
&void_type, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ast::ExpressionList call_params; ast::ExpressionList call_params;

View File

@ -43,7 +43,7 @@ TEST_F(BuilderTest, FunctionDecoration_Stage) {
ast::Function func( ast::Function func(
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
}); });
@ -68,8 +68,9 @@ TEST_P(FunctionDecoration_StageTest, Emit) {
ast::type::Void void_type; ast::type::Void void_type;
ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {}, ast::Function func(
&void_type, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(params.stage, Source{}), create<ast::StageDecoration>(params.stage, Source{}),
}); });
@ -99,7 +100,7 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
ast::Function func( ast::Function func(
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
}); });
@ -163,26 +164,29 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
ast::type::F32 f32; ast::type::F32 f32;
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>( Source{}, ast::StatementList{
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_out"), create<ast::IdentifierExpression>(
"my_out"), Source{}, mod->RegisterSymbol("my_out"), "my_out"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_in"), create<ast::IdentifierExpression>(
"my_in"))); Source{}, mod->RegisterSymbol("my_in"), "my_in")),
body->append(create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_wg"), create<ast::IdentifierExpression>(
"my_wg"), Source{}, mod->RegisterSymbol("my_wg"), "my_wg"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_wg"), create<ast::IdentifierExpression>(
"my_wg"))); Source{}, mod->RegisterSymbol("my_wg"), "my_wg")),
// Add duplicate usages so we show they don't get output multiple times. // Add duplicate usages so we show they don't get output
body->append(create<ast::AssignmentStatement>( // multiple times.
create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_out"), create<ast::IdentifierExpression>(
"my_out"), Source{}, mod->RegisterSymbol("my_out"), "my_out"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_in"), create<ast::IdentifierExpression>(
"my_in"))); Source{}, mod->RegisterSymbol("my_in"), "my_in")),
});
ast::Function func( ast::Function func(
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, body, Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, body,
@ -256,7 +260,7 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_Fragment_OriginUpperLeft) {
ast::Function func( ast::Function func(
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
}); });
@ -272,7 +276,7 @@ TEST_F(BuilderTest, FunctionDecoration_WorkgroupSize_Default) {
ast::Function func( ast::Function func(
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
}); });
@ -288,7 +292,7 @@ TEST_F(BuilderTest, FunctionDecoration_WorkgroupSize) {
ast::Function func( ast::Function func(
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::WorkgroupDecoration>(2u, 4u, 6u, Source{}), create<ast::WorkgroupDecoration>(2u, 4u, 6u, Source{}),
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
@ -305,14 +309,14 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_MultipleFragment) {
ast::Function func1( ast::Function func1(
Source{}, mod->RegisterSymbol("main1"), "main1", {}, &void_type, Source{}, mod->RegisterSymbol("main1"), "main1", {}, &void_type,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
}); });
ast::Function func2( ast::Function func2(
Source{}, mod->RegisterSymbol("main2"), "main2", {}, &void_type, Source{}, mod->RegisterSymbol("main2"), "main2", {}, &void_type,
create<ast::BlockStatement>(Source{}), create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}), create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
}); });

View File

@ -47,8 +47,9 @@ using BuilderTest = TestHelper;
TEST_F(BuilderTest, Function_Empty) { TEST_F(BuilderTest, Function_Empty) {
ast::type::Void void_type; ast::type::Void void_type;
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
&void_type, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &void_type,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)); ASSERT_TRUE(b.GenerateFunction(&func));
@ -65,9 +66,10 @@ OpFunctionEnd
TEST_F(BuilderTest, Function_Terminator_Return) { TEST_F(BuilderTest, Function_Terminator_Return) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&void_type, body, ast::FunctionDecorationList{}); &void_type, body, ast::FunctionDecorationList{});
@ -96,10 +98,12 @@ TEST_F(BuilderTest, Function_Terminator_ReturnValue) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
td.RegisterVariableForTesting(var_a); td.RegisterVariableForTesting(var_a);
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{}, ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>( Source{}, create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a"))); Source{}, mod->RegisterSymbol("a"), "a")),
});
ASSERT_TRUE(td.DetermineResultType(body)) << td.error(); ASSERT_TRUE(td.DetermineResultType(body)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
@ -126,9 +130,10 @@ OpFunctionEnd
TEST_F(BuilderTest, Function_Terminator_Discard) { TEST_F(BuilderTest, Function_Terminator_Discard) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&void_type, body, ast::FunctionDecorationList{}); &void_type, body, ast::FunctionDecorationList{});
@ -166,10 +171,12 @@ TEST_F(BuilderTest, Function_WithParams) {
ast::VariableDecorationList{}), // decorations ast::VariableDecorationList{}), // decorations
}; };
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>( Source{}, ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>( Source{}, create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a"))); Source{}, mod->RegisterSymbol("a"), "a")),
});
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", params, ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", params,
&f32, body, ast::FunctionDecorationList{}); &f32, body, ast::FunctionDecorationList{});
@ -196,9 +203,10 @@ OpFunctionEnd
TEST_F(BuilderTest, Function_WithBody) { TEST_F(BuilderTest, Function_WithBody) {
ast::type::Void void_type; ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&void_type, body, ast::FunctionDecorationList{}); &void_type, body, ast::FunctionDecorationList{});
@ -215,8 +223,9 @@ OpFunctionEnd
TEST_F(BuilderTest, FunctionType) { TEST_F(BuilderTest, FunctionType) {
ast::type::Void void_type; ast::type::Void void_type;
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
&void_type, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &void_type,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)); ASSERT_TRUE(b.GenerateFunction(&func));
@ -227,11 +236,13 @@ TEST_F(BuilderTest, FunctionType) {
TEST_F(BuilderTest, FunctionType_DeDuplicate) { TEST_F(BuilderTest, FunctionType_DeDuplicate) {
ast::type::Void void_type; ast::type::Void void_type;
ast::Function func1(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func1(
&void_type, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &void_type,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ast::Function func2(Source{}, mod->RegisterSymbol("b_func"), "b_func", {}, ast::Function func2(
&void_type, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("b_func"), "b_func", {}, &void_type,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func1)); ASSERT_TRUE(b.GenerateFunction(&func1));
@ -309,10 +320,11 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
"d")), // constructor "d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("a"), "a", params, &void_type, body, Source{}, mod->RegisterSymbol("a"), "a", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -340,10 +352,11 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
"d")), // constructor "d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("b"), "b", params, &void_type, body, Source{}, mod->RegisterSymbol("b"), "b", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{

View File

@ -48,7 +48,9 @@ TEST_F(BuilderTest, If_Empty) {
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
ast::IfStatement expr(Source{}, cond, create<ast::BlockStatement>(Source{}), ast::IfStatement expr(
Source{}, cond,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::ElseStatementList{}); ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -84,14 +86,16 @@ TEST_F(BuilderTest, If_WithStatements) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
});
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
@ -140,21 +144,26 @@ TEST_F(BuilderTest, If_WithElse) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
auto* else_body = create<ast::BlockStatement>(Source{});
else_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), create<ast::IdentifierExpression>(Source{},
"v"), mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
});
auto* else_body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))),
});
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
@ -211,21 +220,26 @@ TEST_F(BuilderTest, If_WithElseIf) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
auto* else_body = create<ast::BlockStatement>(Source{});
else_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), create<ast::IdentifierExpression>(Source{},
"v"), mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
});
auto* else_body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))),
});
auto* else_cond = create<ast::ScalarConstructorExpression>( auto* else_cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
@ -294,34 +308,46 @@ TEST_F(BuilderTest, If_WithMultiple) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
auto* elseif_1_body = create<ast::BlockStatement>(Source{});
elseif_1_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), create<ast::IdentifierExpression>(Source{},
"v"), mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
auto* elseif_2_body = create<ast::BlockStatement>(Source{}); });
elseif_2_body->append(create<ast::AssignmentStatement>( auto* elseif_1_body = create<ast::BlockStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 4))));
auto* else_body = create<ast::BlockStatement>(Source{});
else_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), create<ast::IdentifierExpression>(Source{},
"v"), mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 5)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))),
});
auto* elseif_2_body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 4))),
});
auto* else_body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 5))),
});
auto* elseif_1_cond = create<ast::ScalarConstructorExpression>( auto* elseif_1_cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
@ -398,17 +424,21 @@ TEST_F(BuilderTest, If_WithBreak) {
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* if_body = create<ast::BlockStatement>(Source{}); auto* if_body = create<ast::BlockStatement>(
if_body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
auto* if_stmt = create<ast::IfStatement>(Source{}, cond, if_body, auto* if_stmt = create<ast::IfStatement>(Source{}, cond, if_body,
ast::ElseStatementList{}); ast::ElseStatementList{});
auto* loop_body = create<ast::BlockStatement>(Source{}); auto* loop_body = create<ast::BlockStatement>(Source{}, ast::StatementList{
loop_body->append(if_stmt); if_stmt,
});
ast::LoopStatement expr(Source{}, loop_body, ast::LoopStatement expr(
create<ast::BlockStatement>(Source{})); Source{}, loop_body,
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -447,19 +477,24 @@ TEST_F(BuilderTest, If_WithElseBreak) {
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* else_body = create<ast::BlockStatement>(Source{}); auto* else_body = create<ast::BlockStatement>(
else_body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
auto* if_stmt = create<ast::IfStatement>( auto* if_stmt = create<ast::IfStatement>(
Source{}, cond, create<ast::BlockStatement>(Source{}), Source{}, cond,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::ElseStatementList{ ast::ElseStatementList{
create<ast::ElseStatement>(Source{}, nullptr, else_body)}); create<ast::ElseStatement>(Source{}, nullptr, else_body)});
auto* loop_body = create<ast::BlockStatement>(Source{}); auto* loop_body = create<ast::BlockStatement>(Source{}, ast::StatementList{
loop_body->append(if_stmt); if_stmt,
});
ast::LoopStatement expr(Source{}, loop_body, ast::LoopStatement expr(
create<ast::BlockStatement>(Source{})); Source{}, loop_body,
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -499,17 +534,21 @@ TEST_F(BuilderTest, If_WithContinue) {
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* if_body = create<ast::BlockStatement>(Source{}); auto* if_body = create<ast::BlockStatement>(
if_body->append(create<ast::ContinueStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ContinueStatement>(Source{}),
});
auto* if_stmt = create<ast::IfStatement>(Source{}, cond, if_body, auto* if_stmt = create<ast::IfStatement>(Source{}, cond, if_body,
ast::ElseStatementList{}); ast::ElseStatementList{});
auto* loop_body = create<ast::BlockStatement>(Source{}); auto* loop_body = create<ast::BlockStatement>(Source{}, ast::StatementList{
loop_body->append(if_stmt); if_stmt,
});
ast::LoopStatement expr(Source{}, loop_body, ast::LoopStatement expr(
create<ast::BlockStatement>(Source{})); Source{}, loop_body,
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -548,19 +587,24 @@ TEST_F(BuilderTest, If_WithElseContinue) {
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* else_body = create<ast::BlockStatement>(Source{}); auto* else_body = create<ast::BlockStatement>(
else_body->append(create<ast::ContinueStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ContinueStatement>(Source{}),
});
auto* if_stmt = create<ast::IfStatement>( auto* if_stmt = create<ast::IfStatement>(
Source{}, cond, create<ast::BlockStatement>(Source{}), Source{}, cond,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::ElseStatementList{ ast::ElseStatementList{
create<ast::ElseStatement>(Source{}, nullptr, else_body)}); create<ast::ElseStatement>(Source{}, nullptr, else_body)});
auto* loop_body = create<ast::BlockStatement>(Source{}); auto* loop_body = create<ast::BlockStatement>(Source{}, ast::StatementList{
loop_body->append(if_stmt); if_stmt,
});
ast::LoopStatement expr(Source{}, loop_body, ast::LoopStatement expr(
create<ast::BlockStatement>(Source{})); Source{}, loop_body,
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -598,8 +642,10 @@ TEST_F(BuilderTest, If_WithReturn) {
auto* cond = create<ast::ScalarConstructorExpression>( auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* if_body = create<ast::BlockStatement>(Source{}); auto* if_body = create<ast::BlockStatement>(
if_body->append(create<ast::ReturnStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{}); ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{});
@ -630,8 +676,10 @@ TEST_F(BuilderTest, If_WithReturnValue) {
auto* cond2 = create<ast::ScalarConstructorExpression>( auto* cond2 = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, false)); Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, false));
auto* if_body = create<ast::BlockStatement>(Source{}); auto* if_body = create<ast::BlockStatement>(
if_body->append(create<ast::ReturnStatement>(Source{}, cond2)); Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}, cond2),
});
ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{}); ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{});
@ -669,10 +717,11 @@ TEST_F(BuilderTest, If_WithLoad_Bug327) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
ast::IfStatement expr(Source{}, ast::IfStatement expr(
create<ast::IdentifierExpression>( Source{},
Source{}, mod->RegisterSymbol("a"), "a"), create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("a"),
create<ast::BlockStatement>(Source{}), "a"),
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::ElseStatementList{}); ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();

View File

@ -471,8 +471,9 @@ TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
@ -505,8 +506,9 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Scalar) {
auto expr = Call(param.name, 1.0f); auto expr = Call(param.name, 1.0f);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -533,8 +535,9 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Vector) {
auto expr = Call(param.name, vec2<f32>(1.0f, 1.0f)); auto expr = Call(param.name, vec2<f32>(1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -587,8 +590,9 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -612,8 +616,9 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Vector) {
auto expr = Call("length", vec2<f32>(1.0f, 1.0f)); auto expr = Call("length", vec2<f32>(1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -639,8 +644,9 @@ TEST_F(IntrinsicBuilderTest, Call_Normalize) {
auto expr = Call("normalize", vec2<f32>(1.0f, 1.0f)); auto expr = Call("normalize", vec2<f32>(1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -671,8 +677,9 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -700,8 +707,9 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -737,8 +745,9 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -763,8 +772,9 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -792,8 +802,9 @@ TEST_F(IntrinsicBuilderTest, Call_Cross) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -823,8 +834,9 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Scalar) {
auto expr = Call(param.name, 1.0f, 1.0f, 1.0f); auto expr = Call(param.name, 1.0f, 1.0f, 1.0f);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -853,8 +865,9 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -894,8 +907,9 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Scalar) {
auto expr = Call(param.name, 1); auto expr = Call(param.name, 1);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -922,8 +936,9 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Vector) {
auto expr = Call(param.name, vec2<i32>(1, 1)); auto expr = Call(param.name, vec2<i32>(1, 1));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -957,8 +972,9 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Scalar) {
auto expr = Call(param.name, 1u); auto expr = Call(param.name, 1u);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -985,8 +1001,9 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Vector) {
auto expr = Call(param.name, vec2<u32>(1u, 1u)); auto expr = Call(param.name, vec2<u32>(1u, 1u));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1020,8 +1037,9 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Scalar) {
auto expr = Call(param.name, 1, 1); auto expr = Call(param.name, 1, 1);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1048,8 +1066,9 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Vector) {
auto expr = Call(param.name, vec2<i32>(1, 1), vec2<i32>(1, 1)); auto expr = Call(param.name, vec2<i32>(1, 1), vec2<i32>(1, 1));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1084,8 +1103,9 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Scalar) {
auto expr = Call(param.name, 1u, 1u); auto expr = Call(param.name, 1u, 1u);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1112,8 +1132,9 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Vector) {
auto expr = Call(param.name, vec2<u32>(1u, 1u), vec2<u32>(1u, 1u)); auto expr = Call(param.name, vec2<u32>(1u, 1u), vec2<u32>(1u, 1u));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1148,8 +1169,9 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Scalar) {
auto expr = Call(param.name, 1, 1, 1); auto expr = Call(param.name, 1, 1, 1);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1178,8 +1200,9 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1213,8 +1236,9 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Scalar) {
auto expr = Call(param.name, 1u, 1u, 1u); auto expr = Call(param.name, 1u, 1u, 1u);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1243,8 +1267,9 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1276,8 +1301,9 @@ TEST_F(IntrinsicBuilderTest, Call_Determinant) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1321,8 +1347,9 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1362,8 +1389,9 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength_OtherMembersInStruct) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1409,8 +1437,9 @@ TEST_F(IntrinsicBuilderTest, DISABLED_Call_ArrayLength_Ptr) {
auto expr = Call("arrayLength", "ptr_var"); auto expr = Call("arrayLength", "ptr_var");
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
ty.void_, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();

View File

@ -39,8 +39,9 @@ TEST_F(BuilderTest, Loop_Empty) {
// loop { // loop {
// } // }
ast::LoopStatement loop(Source{}, create<ast::BlockStatement>(Source{}), ast::LoopStatement loop(
create<ast::BlockStatement>(Source{})); Source{}, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
b.push_function(Function{}); b.push_function(Function{});
@ -74,16 +75,19 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
});
ast::LoopStatement loop(Source{}, body, ast::LoopStatement loop(
create<ast::BlockStatement>(Source{})); Source{}, body,
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
@ -130,21 +134,26 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
auto* continuing = create<ast::BlockStatement>(Source{});
continuing->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), create<ast::IdentifierExpression>(Source{},
"v"), mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
});
auto* continuing = create<ast::BlockStatement>(
Source{},
ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))),
});
ast::LoopStatement loop(Source{}, body, continuing); ast::LoopStatement loop(Source{}, body, continuing);
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
@ -180,11 +189,13 @@ TEST_F(BuilderTest, Loop_WithContinue) {
// loop { // loop {
// continue; // continue;
// } // }
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::ContinueStatement>(Source{})); Source{}, ast::StatementList{
create<ast::ContinueStatement>(Source{}),
ast::LoopStatement loop(Source{}, body, });
create<ast::BlockStatement>(Source{})); ast::LoopStatement loop(
Source{}, body,
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
@ -208,11 +219,13 @@ TEST_F(BuilderTest, Loop_WithBreak) {
// loop { // loop {
// break; // break;
// } // }
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
ast::LoopStatement loop(Source{}, body, });
create<ast::BlockStatement>(Source{})); ast::LoopStatement loop(
Source{}, body,
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();

View File

@ -93,21 +93,27 @@ TEST_F(BuilderTest, Switch_WithCase) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* case_1_body = create<ast::BlockStatement>(Source{}); auto* case_1_body = create<ast::BlockStatement>(
case_1_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))),
});
auto* case_2_body = create<ast::BlockStatement>(Source{}); auto* case_2_body = create<ast::BlockStatement>(
case_2_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
});
ast::CaseSelectorList selector_1; ast::CaseSelectorList selector_1;
selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1)); selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
@ -130,8 +136,9 @@ TEST_F(BuilderTest, Switch_WithCase) {
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
&i32, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &i32,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
@ -195,13 +202,16 @@ TEST_F(BuilderTest, Switch_WithDefault) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* default_body = create<ast::BlockStatement>(Source{}); auto* default_body = create<ast::BlockStatement>(
default_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))),
});
ast::CaseStatementList cases; ast::CaseStatementList cases;
cases.push_back(create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, cases.push_back(create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{},
@ -216,8 +226,9 @@ TEST_F(BuilderTest, Switch_WithDefault) {
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
&i32, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &i32,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
@ -279,29 +290,38 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* case_1_body = create<ast::BlockStatement>(Source{}); auto* case_1_body = create<ast::BlockStatement>(
case_1_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))),
});
auto* case_2_body = create<ast::BlockStatement>(Source{}); auto* case_2_body = create<ast::BlockStatement>(
case_2_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
});
auto* default_body = create<ast::BlockStatement>(Source{}); auto* default_body = create<ast::BlockStatement>(
default_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))),
});
ast::CaseSelectorList selector_1; ast::CaseSelectorList selector_1;
selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1)); selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
@ -327,8 +347,9 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
&i32, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &i32,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
@ -399,30 +420,38 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* case_1_body = create<ast::BlockStatement>(Source{}); auto* case_1_body = create<ast::BlockStatement>(
case_1_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))),
case_1_body->append(create<ast::FallthroughStatement>(Source{})); create<ast::FallthroughStatement>(Source{})});
auto* case_2_body = create<ast::BlockStatement>(Source{}); auto* case_2_body = create<ast::BlockStatement>(
case_2_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
});
auto* default_body = create<ast::BlockStatement>(Source{}); auto* default_body = create<ast::BlockStatement>(
default_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))),
});
ast::CaseSelectorList selector_1; ast::CaseSelectorList selector_1;
selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1)); selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
@ -447,8 +476,9 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
&i32, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &i32,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
@ -515,14 +545,16 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* case_1_body = create<ast::BlockStatement>(Source{}); auto* case_1_body = create<ast::BlockStatement>(
case_1_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), ast::StatementList{
"v"), create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))),
case_1_body->append(create<ast::FallthroughStatement>(Source{})); create<ast::FallthroughStatement>(Source{})});
ast::CaseSelectorList selector_1; ast::CaseSelectorList selector_1;
selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1)); selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
@ -540,8 +572,9 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
&i32, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &i32,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
@ -581,22 +614,26 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* if_body = create<ast::BlockStatement>(Source{}); auto* if_body = create<ast::BlockStatement>(
if_body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
auto* case_1_body = create<ast::BlockStatement>(Source{}); auto* case_1_body = create<ast::BlockStatement>(
case_1_body->append(create<ast::IfStatement>( Source{},
ast::StatementList{
create<ast::IfStatement>(
Source{}, Source{},
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true)),
if_body, ast::ElseStatementList{}));
case_1_body->append(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"), create<ast::BoolLiteral>(Source{}, &bool_type, true)),
"v"), if_body, ast::ElseStatementList{}),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)))); Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)))});
ast::CaseSelectorList selector_1; ast::CaseSelectorList selector_1;
selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1)); selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
@ -614,8 +651,9 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(
&i32, create<ast::BlockStatement>(Source{}), Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &i32,
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();

View File

@ -28,9 +28,9 @@ namespace {
using WgslGeneratorImplTest = TestHelper; using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Block) { TEST_F(WgslGeneratorImplTest, Emit_Block) {
ast::BlockStatement b(Source{}); ast::BlockStatement b(Source{}, ast::StatementList{
b.append(create<ast::DiscardStatement>(Source{})); create<ast::DiscardStatement>(Source{}),
});
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(&b)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(&b)) << gen.error();
@ -41,9 +41,9 @@ TEST_F(WgslGeneratorImplTest, Emit_Block) {
} }
TEST_F(WgslGeneratorImplTest, Emit_Block_WithoutNewline) { TEST_F(WgslGeneratorImplTest, Emit_Block_WithoutNewline) {
ast::BlockStatement b(Source{}); ast::BlockStatement b(Source{}, ast::StatementList{
b.append(create<ast::DiscardStatement>(Source{})); create<ast::DiscardStatement>(Source{}),
});
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitBlock(&b)) << gen.error(); ASSERT_TRUE(gen.EmitBlock(&b)) << gen.error();

View File

@ -33,9 +33,10 @@ using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Case) { TEST_F(WgslGeneratorImplTest, Emit_Case) {
ast::type::I32 i32; ast::type::I32 i32;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
ast::CaseStatement c(Source{}, lit, body); ast::CaseStatement c(Source{}, lit, body);
@ -52,9 +53,10 @@ TEST_F(WgslGeneratorImplTest, Emit_Case) {
TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) { TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) {
ast::type::I32 i32; ast::type::I32 i32;
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 6)); lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 6));
@ -70,8 +72,10 @@ TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) {
} }
TEST_F(WgslGeneratorImplTest, Emit_Case_Default) { TEST_F(WgslGeneratorImplTest, Emit_Case_Default) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body); ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body);
gen.increment_indent(); gen.increment_indent();

View File

@ -41,10 +41,11 @@ namespace {
using WgslGeneratorImplTest = TestHelper; using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Function) { TEST_F(WgslGeneratorImplTest, Emit_Function) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::DiscardStatement>(Source{}),
create<ast::ReturnStatement>(Source{}),
});
ast::type::Void void_type; ast::type::Void void_type;
ast::Function func(Source{}, mod.RegisterSymbol("my_func"), "my_func", {}, ast::Function func(Source{}, mod.RegisterSymbol("my_func"), "my_func", {},
&void_type, body, ast::FunctionDecorationList{}); &void_type, body, ast::FunctionDecorationList{});
@ -60,10 +61,11 @@ TEST_F(WgslGeneratorImplTest, Emit_Function) {
} }
TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) { TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::DiscardStatement>(Source{}),
create<ast::ReturnStatement>(Source{}),
});
ast::type::F32 f32; ast::type::F32 f32;
ast::type::I32 i32; ast::type::I32 i32;
ast::VariableList params; ast::VariableList params;
@ -99,10 +101,11 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) {
} }
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) { TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::DiscardStatement>(Source{}),
create<ast::ReturnStatement>(Source{}),
});
ast::type::Void void_type; ast::type::Void void_type;
ast::Function func(Source{}, mod.RegisterSymbol("my_func"), "my_func", {}, ast::Function func(Source{}, mod.RegisterSymbol("my_func"), "my_func", {},
&void_type, body, &void_type, body,
@ -122,10 +125,11 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) {
} }
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) { TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::DiscardStatement>(Source{}),
create<ast::ReturnStatement>(Source{}),
});
ast::type::Void void_type; ast::type::Void void_type;
ast::Function func( ast::Function func(
Source{}, mod.RegisterSymbol("my_func"), "my_func", {}, &void_type, body, Source{}, mod.RegisterSymbol("my_func"), "my_func", {}, &void_type, body,
@ -145,10 +149,11 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) {
} }
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) { TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::DiscardStatement>(Source{}),
create<ast::ReturnStatement>(Source{}),
});
ast::type::Void void_type; ast::type::Void void_type;
ast::Function func( ast::Function func(
Source{}, mod.RegisterSymbol("my_func"), "my_func", {}, &void_type, body, Source{}, mod.RegisterSymbol("my_func"), "my_func", {}, &void_type, body,
@ -237,10 +242,11 @@ TEST_F(WgslGeneratorImplTest,
"d")), // constructor "d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("a"), "a", params, &void_type, body, Source{}, mod.RegisterSymbol("a"), "a", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -267,10 +273,11 @@ TEST_F(WgslGeneratorImplTest,
"d")), // constructor "d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::VariableDeclStatement>(Source{}, var)); Source{}, ast::StatementList{
body->append(create<ast::ReturnStatement>(Source{})); create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("b"), "b", params, &void_type, body, Source{}, mod.RegisterSymbol("b"), "b", params, &void_type, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{

View File

@ -30,9 +30,10 @@ using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_If) { TEST_F(WgslGeneratorImplTest, Emit_If) {
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond"); Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{}); ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
gen.increment_indent(); gen.increment_indent();
@ -47,14 +48,17 @@ TEST_F(WgslGeneratorImplTest, Emit_If) {
TEST_F(WgslGeneratorImplTest, Emit_IfWithElseIf) { TEST_F(WgslGeneratorImplTest, Emit_IfWithElseIf) {
auto* else_cond = create<ast::IdentifierExpression>( auto* else_cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>(Source{}); auto* else_body = create<ast::BlockStatement>(
else_body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond"); Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
ast::IfStatement i( ast::IfStatement i(
Source{}, cond, body, Source{}, cond, body,
{create<ast::ElseStatement>(Source{}, else_cond, else_body)}); {create<ast::ElseStatement>(Source{}, else_cond, else_body)});
@ -71,14 +75,17 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithElseIf) {
} }
TEST_F(WgslGeneratorImplTest, Emit_IfWithElse) { TEST_F(WgslGeneratorImplTest, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>(Source{}); auto* else_body = create<ast::BlockStatement>(
else_body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond"); Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
ast::IfStatement i( ast::IfStatement i(
Source{}, cond, body, Source{}, cond, body,
{create<ast::ElseStatement>(Source{}, nullptr, else_body)}); {create<ast::ElseStatement>(Source{}, nullptr, else_body)});
@ -98,17 +105,22 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithMultiple) {
auto* else_cond = create<ast::IdentifierExpression>( auto* else_cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>(Source{}); auto* else_body = create<ast::BlockStatement>(
else_body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
auto* else_body_2 = create<ast::BlockStatement>(Source{}); auto* else_body_2 = create<ast::BlockStatement>(
else_body_2->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond"); Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
ast::IfStatement i( ast::IfStatement i(
Source{}, cond, body, Source{}, cond, body,
{ {

View File

@ -28,8 +28,10 @@ namespace {
using WgslGeneratorImplTest = TestHelper; using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Loop) { TEST_F(WgslGeneratorImplTest, Emit_Loop) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
ast::LoopStatement l(Source{}, body, {}); ast::LoopStatement l(Source{}, body, {});
gen.increment_indent(); gen.increment_indent();
@ -42,12 +44,14 @@ TEST_F(WgslGeneratorImplTest, Emit_Loop) {
} }
TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing) { TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing) {
auto* body = create<ast::BlockStatement>(Source{}); auto* body = create<ast::BlockStatement>(
body->append(create<ast::DiscardStatement>(Source{})); Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
auto* continuing = create<ast::BlockStatement>(Source{}); });
continuing->append(create<ast::DiscardStatement>(Source{})); auto* continuing = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::DiscardStatement>(Source{}),
});
ast::LoopStatement l(Source{}, body, continuing); ast::LoopStatement l(Source{}, body, continuing);
gen.increment_indent(); gen.increment_indent();

View File

@ -32,8 +32,10 @@ namespace {
using WgslGeneratorImplTest = TestHelper; using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Switch) { TEST_F(WgslGeneratorImplTest, Emit_Switch) {
auto* def_body = create<ast::BlockStatement>(Source{}); auto* def_body = create<ast::BlockStatement>(
def_body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
auto* def = auto* def =
create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, def_body); create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, def_body);
@ -41,8 +43,10 @@ TEST_F(WgslGeneratorImplTest, Emit_Switch) {
ast::CaseSelectorList case_val; ast::CaseSelectorList case_val;
case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
auto* case_body = create<ast::BlockStatement>(Source{}); auto* case_body = create<ast::BlockStatement>(
case_body->append(create<ast::BreakStatement>(Source{})); Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
auto* case_stmt = create<ast::CaseStatement>(Source{}, case_val, case_body); auto* case_stmt = create<ast::CaseStatement>(Source{}, case_val, case_body);

View File

@ -34,7 +34,7 @@ TEST_F(WgslGeneratorImplTest, Generate) {
mod.AddFunction(create<ast::Function>( mod.AddFunction(create<ast::Function>(
Source{}, mod.RegisterSymbol("a_func"), "my_func", ast::VariableList{}, Source{}, mod.RegisterSymbol("a_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(Source{}), &void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{})); ast::FunctionDecorationList{}));
ASSERT_TRUE(gen.Generate(mod)) << gen.error(); ASSERT_TRUE(gen.Generate(mod)) << gen.error();