ast: Remove statement constructors that don't take a Source

Parsers need fixing up.

Bug: tint:396
Bug: tint:390
Change-Id: I137f1017ca56125cf3d52ecbef2ff46d0574338b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35161
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-12-12 11:58:44 +00:00 committed by Commit Bot service account
parent 1ff59cd0e2
commit bbefff63a3
111 changed files with 1287 additions and 1145 deletions

View File

@ -22,9 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::AssignmentStatement);
namespace tint {
namespace ast {
AssignmentStatement::AssignmentStatement(Expression* lhs, Expression* rhs)
: Base(), lhs_(lhs), rhs_(rhs) {}
AssignmentStatement::AssignmentStatement(const Source& source,
Expression* lhs,
Expression* rhs)

View File

@ -28,10 +28,6 @@ namespace ast {
/// An assignment statement
class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
public:
/// Constructor
/// @param lhs the left side of the expression
/// @param rhs the right side of the expression
AssignmentStatement(Expression* lhs, Expression* rhs);
/// Constructor
/// @param source the assignment statement source
/// @param lhs the left side of the expression

View File

@ -29,7 +29,7 @@ TEST_F(AssignmentStatementTest, Creation) {
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs);
AssignmentStatement stmt(Source{}, lhs, rhs);
EXPECT_EQ(stmt.lhs(), lhs);
EXPECT_EQ(stmt.rhs(), rhs);
}
@ -52,7 +52,7 @@ TEST_F(AssignmentStatementTest, IsAssign) {
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs);
AssignmentStatement stmt(Source{}, lhs, rhs);
EXPECT_TRUE(stmt.Is<AssignmentStatement>());
}
@ -62,7 +62,7 @@ TEST_F(AssignmentStatementTest, IsValid) {
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs);
AssignmentStatement stmt(Source{}, lhs, rhs);
EXPECT_TRUE(stmt.IsValid());
}
@ -70,7 +70,7 @@ TEST_F(AssignmentStatementTest, IsValid_MissingLHS) {
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(nullptr, rhs);
AssignmentStatement stmt(Source{}, nullptr, rhs);
EXPECT_FALSE(stmt.IsValid());
}
@ -78,7 +78,7 @@ TEST_F(AssignmentStatementTest, IsValid_MissingRHS) {
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
AssignmentStatement stmt(lhs, nullptr);
AssignmentStatement stmt(Source{}, lhs, nullptr);
EXPECT_FALSE(stmt.IsValid());
}
@ -87,7 +87,7 @@ TEST_F(AssignmentStatementTest, IsValid_InvalidLHS) {
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs);
AssignmentStatement stmt(Source{}, lhs, rhs);
EXPECT_FALSE(stmt.IsValid());
}
@ -96,7 +96,7 @@ TEST_F(AssignmentStatementTest, IsValid_InvalidRHS) {
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
AssignmentStatement stmt(lhs, rhs);
AssignmentStatement stmt(Source{}, lhs, rhs);
EXPECT_FALSE(stmt.IsValid());
}
@ -106,7 +106,7 @@ TEST_F(AssignmentStatementTest, ToStr) {
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs);
AssignmentStatement stmt(Source{}, lhs, rhs);
std::ostringstream out;
stmt.to_str(out, 2);

View File

@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::BlockStatement);
namespace tint {
namespace ast {
BlockStatement::BlockStatement() : Base() {}
BlockStatement::BlockStatement(const Source& source) : Base(source) {}
BlockStatement::BlockStatement(BlockStatement&&) = default;

View File

@ -27,8 +27,6 @@ namespace ast {
/// A block statement
class BlockStatement : public Castable<BlockStatement, Statement> {
public:
/// Constructor
BlockStatement();
/// Constructor
/// @param source the block statement source
explicit BlockStatement(const Source& source);

View File

@ -28,10 +28,10 @@ namespace {
using BlockStatementTest = TestHelper;
TEST_F(BlockStatementTest, Creation) {
auto* d = create<DiscardStatement>();
auto* d = create<DiscardStatement>(Source{});
auto* ptr = d;
BlockStatement b;
BlockStatement b(Source{});
b.append(d);
ASSERT_EQ(b.size(), 1u);
@ -39,11 +39,11 @@ TEST_F(BlockStatementTest, Creation) {
}
TEST_F(BlockStatementTest, Creation_WithInsert) {
auto* s1 = create<DiscardStatement>();
auto* s2 = create<DiscardStatement>();
auto* s3 = create<DiscardStatement>();
auto* s1 = create<DiscardStatement>(Source{});
auto* s2 = create<DiscardStatement>(Source{});
auto* s3 = create<DiscardStatement>(Source{});
BlockStatement b;
BlockStatement b(Source{});
b.insert(0, s1);
b.insert(0, s2);
b.insert(1, s3);
@ -64,38 +64,39 @@ TEST_F(BlockStatementTest, Creation_WithSource) {
}
TEST_F(BlockStatementTest, IsBlock) {
BlockStatement b;
BlockStatement b(Source{});
EXPECT_TRUE(b.Is<BlockStatement>());
}
TEST_F(BlockStatementTest, IsValid) {
BlockStatement b;
b.append(create<DiscardStatement>());
BlockStatement b(Source{});
b.append(create<DiscardStatement>(Source{}));
EXPECT_TRUE(b.IsValid());
}
TEST_F(BlockStatementTest, IsValid_Empty) {
BlockStatement b;
BlockStatement b(Source{});
EXPECT_TRUE(b.IsValid());
}
TEST_F(BlockStatementTest, IsValid_NullBodyStatement) {
BlockStatement b;
b.append(create<DiscardStatement>());
BlockStatement b(Source{});
b.append(create<DiscardStatement>(Source{}));
b.append(nullptr);
EXPECT_FALSE(b.IsValid());
}
TEST_F(BlockStatementTest, IsValid_InvalidBodyStatement) {
BlockStatement b;
b.append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
BlockStatement b(Source{});
b.append(create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}),
ElseStatementList{}));
EXPECT_FALSE(b.IsValid());
}
TEST_F(BlockStatementTest, ToStr) {
BlockStatement b;
b.append(create<DiscardStatement>());
BlockStatement b(Source{});
b.append(create<DiscardStatement>(Source{}));
std::ostringstream out;
b.to_str(out, 2);

View File

@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::BreakStatement);
namespace tint {
namespace ast {
BreakStatement::BreakStatement() : Base() {}
BreakStatement::BreakStatement(const Source& source) : Base(source) {}
BreakStatement::BreakStatement(BreakStatement&&) = default;

View File

@ -23,8 +23,6 @@ namespace ast {
/// An break statement
class BreakStatement : public Castable<BreakStatement, Statement> {
public:
/// Constructor
BreakStatement();
/// Constructor
/// @param source the break statement source
explicit BreakStatement(const Source& source);

View File

@ -30,17 +30,17 @@ TEST_F(BreakStatementTest, Creation_WithSource) {
}
TEST_F(BreakStatementTest, IsBreak) {
BreakStatement stmt;
BreakStatement stmt(Source{});
EXPECT_TRUE(stmt.Is<BreakStatement>());
}
TEST_F(BreakStatementTest, IsValid) {
BreakStatement stmt;
BreakStatement stmt(Source{});
EXPECT_TRUE(stmt.IsValid());
}
TEST_F(BreakStatementTest, ToStr) {
BreakStatement stmt;
BreakStatement stmt(Source{});
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Break{}

View File

@ -23,14 +23,16 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::CallStatement);
namespace tint {
namespace ast {
CallStatement::CallStatement(CallExpression* call) : Base(), call_(call) {}
CallStatement::CallStatement(const Source& source, CallExpression* call)
: Base(source), call_(call) {}
CallStatement::CallStatement(CallStatement&&) = default;
CallStatement::~CallStatement() = default;
CallStatement* CallStatement::Clone(CloneContext* ctx) const {
return ctx->mod->create<CallStatement>(ctx->Clone(call_));
return ctx->mod->create<CallStatement>(ctx->Clone(source()),
ctx->Clone(call_));
}
bool CallStatement::IsValid() const {

View File

@ -28,8 +28,9 @@ namespace ast {
class CallStatement : public Castable<CallStatement, Statement> {
public:
/// Constructor
/// @param source the input source for the statement
/// @param call the function
explicit CallStatement(CallExpression* call);
CallStatement(const Source& source, CallExpression* call);
/// Move constructor
CallStatement(CallStatement&&);
~CallStatement() override;

View File

@ -31,17 +31,18 @@ TEST_F(CallStatementTest, Creation) {
Source{}, mod.RegisterSymbol("func"), "func"),
ExpressionList{});
CallStatement c(expr);
CallStatement c(Source{}, expr);
EXPECT_EQ(c.expr(), expr);
}
TEST_F(CallStatementTest, IsCall) {
CallStatement c(nullptr);
CallStatement c(Source{}, nullptr);
EXPECT_TRUE(c.Is<CallStatement>());
}
TEST_F(CallStatementTest, IsValid) {
CallStatement c(
Source{},
create<CallExpression>(Source{},
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("func"), "func"),
@ -50,18 +51,19 @@ TEST_F(CallStatementTest, IsValid) {
}
TEST_F(CallStatementTest, IsValid_MissingExpr) {
CallStatement c(nullptr);
CallStatement c(Source{}, nullptr);
EXPECT_FALSE(c.IsValid());
}
TEST_F(CallStatementTest, IsValid_InvalidExpr) {
CallExpression stmt(Source{}, nullptr, {});
CallStatement c(&stmt);
CallStatement c(Source{}, &stmt);
EXPECT_FALSE(c.IsValid());
}
TEST_F(CallStatementTest, ToStr) {
CallStatement c(
Source{},
create<CallExpression>(Source{},
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("func"), "func"),

View File

@ -22,11 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::CaseStatement);
namespace tint {
namespace ast {
CaseStatement::CaseStatement(BlockStatement* body) : Base(), body_(body) {}
CaseStatement::CaseStatement(CaseSelectorList selectors, BlockStatement* body)
: Base(), selectors_(selectors), body_(body) {}
CaseStatement::CaseStatement(const Source& source,
CaseSelectorList selectors,
BlockStatement* body)

View File

@ -33,14 +33,6 @@ using CaseSelectorList = std::vector<IntLiteral*>;
/// A case statement
class CaseStatement : public Castable<CaseStatement, Statement> {
public:
/// Constructor
/// Creates a default case statement
/// @param body the case body
explicit CaseStatement(BlockStatement* body);
/// Constructor
/// @param selectors the case selectors
/// @param body the case body
CaseStatement(CaseSelectorList selectors, BlockStatement* body);
/// Constructor
/// @param source the source information
/// @param selectors the case selectors

View File

@ -35,11 +35,11 @@ TEST_F(CaseStatementTest, Creation_i32) {
auto* selector = create<SintLiteral>(Source{}, &i32, 2);
b.push_back(selector);
auto* body = create<BlockStatement>();
auto* discard = create<DiscardStatement>();
auto* body = create<BlockStatement>(Source{});
auto* discard = create<DiscardStatement>(Source{});
body->append(discard);
CaseStatement c(b, body);
CaseStatement c(Source{}, b, body);
ASSERT_EQ(c.selectors().size(), 1u);
EXPECT_EQ(c.selectors()[0], selector);
ASSERT_EQ(c.body()->size(), 1u);
@ -53,11 +53,11 @@ TEST_F(CaseStatementTest, Creation_u32) {
auto* selector = create<SintLiteral>(Source{}, &u32, 2);
b.push_back(selector);
auto* body = create<BlockStatement>();
auto* discard = create<DiscardStatement>();
auto* body = create<BlockStatement>(Source{});
auto* discard = create<DiscardStatement>(Source{});
body->append(discard);
CaseStatement c(b, body);
CaseStatement c(Source{}, b, body);
ASSERT_EQ(c.selectors().size(), 1u);
EXPECT_EQ(c.selectors()[0], selector);
ASSERT_EQ(c.body()->size(), 1u);
@ -69,8 +69,8 @@ TEST_F(CaseStatementTest, Creation_WithSource) {
CaseSelectorList b;
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
CaseStatement c(Source{Source::Location{20, 2}}, b, body);
auto src = c.source();
@ -79,10 +79,10 @@ TEST_F(CaseStatementTest, Creation_WithSource) {
}
TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
CaseStatement c(body);
CaseStatement c(Source{}, CaseSelectorList{}, body);
EXPECT_TRUE(c.IsDefault());
}
@ -91,17 +91,19 @@ TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
CaseSelectorList b;
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
CaseStatement c(b, create<BlockStatement>());
CaseStatement c(Source{}, b, create<BlockStatement>(Source{}));
EXPECT_FALSE(c.IsDefault());
}
TEST_F(CaseStatementTest, IsCase) {
CaseStatement c(create<BlockStatement>());
CaseStatement c(Source{}, CaseSelectorList{},
create<BlockStatement>(Source{}));
EXPECT_TRUE(c.Is<CaseStatement>());
}
TEST_F(CaseStatementTest, IsValid) {
CaseStatement c(create<BlockStatement>());
CaseStatement c(Source{}, CaseSelectorList{},
create<BlockStatement>(Source{}));
EXPECT_TRUE(c.IsValid());
}
@ -110,11 +112,11 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) {
CaseSelectorList b;
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(nullptr);
CaseStatement c(b, body);
CaseStatement c(Source{}, b, body);
EXPECT_FALSE(c.IsValid());
}
@ -123,11 +125,12 @@ TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) {
CaseSelectorList b;
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* body = create<BlockStatement>();
body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
auto* body = create<BlockStatement>(Source{});
body->append(create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}),
ElseStatementList{}));
CaseStatement c({b}, body);
CaseStatement c(Source{}, {b}, body);
EXPECT_FALSE(c.IsValid());
}
@ -136,9 +139,9 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) {
CaseSelectorList b;
b.push_back(create<SintLiteral>(Source{}, &i32, -2));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
CaseStatement c({b}, body);
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
CaseStatement c(Source{}, {b}, body);
std::ostringstream out;
c.to_str(out, 2);
@ -153,9 +156,9 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) {
CaseSelectorList b;
b.push_back(create<UintLiteral>(Source{}, &u32, 2));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
CaseStatement c({b}, body);
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
CaseStatement c(Source{}, {b}, body);
std::ostringstream out;
c.to_str(out, 2);
@ -172,9 +175,9 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
b.push_back(create<SintLiteral>(Source{}, &i32, 1));
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
CaseStatement c(b, body);
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
CaseStatement c(Source{}, b, body);
std::ostringstream out;
c.to_str(out, 2);
@ -185,9 +188,9 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
}
TEST_F(CaseStatementTest, ToStr_WithoutSelectors) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
CaseStatement c(CaseSelectorList{}, body);
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
CaseStatement c(Source{}, CaseSelectorList{}, body);
std::ostringstream out;
c.to_str(out, 2);

View File

@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::ContinueStatement);
namespace tint {
namespace ast {
ContinueStatement::ContinueStatement() : Base() {}
ContinueStatement::ContinueStatement(const Source& source) : Base(source) {}
ContinueStatement::ContinueStatement(ContinueStatement&&) = default;

View File

@ -26,8 +26,6 @@ namespace ast {
/// An continue statement
class ContinueStatement : public Castable<ContinueStatement, Statement> {
public:
/// Constructor
ContinueStatement();
/// Constructor
/// @param source the continue statement source
explicit ContinueStatement(const Source& source);

View File

@ -30,17 +30,17 @@ TEST_F(ContinueStatementTest, Creation_WithSource) {
}
TEST_F(ContinueStatementTest, IsContinue) {
ContinueStatement stmt;
ContinueStatement stmt(Source{});
EXPECT_TRUE(stmt.Is<ContinueStatement>());
}
TEST_F(ContinueStatementTest, IsValid) {
ContinueStatement stmt;
ContinueStatement stmt(Source{});
EXPECT_TRUE(stmt.IsValid());
}
TEST_F(ContinueStatementTest, ToStr) {
ContinueStatement stmt;
ContinueStatement stmt(Source{});
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Continue{}

View File

@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::DiscardStatement);
namespace tint {
namespace ast {
DiscardStatement::DiscardStatement() : Base() {}
DiscardStatement::DiscardStatement(const Source& source) : Base(source) {}
DiscardStatement::DiscardStatement(DiscardStatement&&) = default;

View File

@ -23,8 +23,6 @@ namespace ast {
/// A discard statement
class DiscardStatement : public Castable<DiscardStatement, Statement> {
public:
/// Constructor
DiscardStatement();
/// Constructor
/// @param source the discard statement source
explicit DiscardStatement(const Source& source);

View File

@ -25,7 +25,7 @@ namespace {
using DiscardStatementTest = TestHelper;
TEST_F(DiscardStatementTest, Creation) {
DiscardStatement stmt;
DiscardStatement stmt(Source{});
EXPECT_EQ(stmt.source().range.begin.line, 0u);
EXPECT_EQ(stmt.source().range.begin.column, 0u);
EXPECT_EQ(stmt.source().range.end.line, 0u);
@ -42,17 +42,17 @@ TEST_F(DiscardStatementTest, Creation_WithSource) {
}
TEST_F(DiscardStatementTest, IsDiscard) {
DiscardStatement stmt;
DiscardStatement stmt(Source{});
EXPECT_TRUE(stmt.Is<DiscardStatement>());
}
TEST_F(DiscardStatementTest, IsValid) {
DiscardStatement stmt;
DiscardStatement stmt(Source{});
EXPECT_TRUE(stmt.IsValid());
}
TEST_F(DiscardStatementTest, ToStr) {
DiscardStatement stmt;
DiscardStatement stmt(Source{});
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Discard{}

View File

@ -22,14 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::ElseStatement);
namespace tint {
namespace ast {
ElseStatement::ElseStatement(BlockStatement* body) : Base(), body_(body) {}
ElseStatement::ElseStatement(Expression* condition, BlockStatement* body)
: Base(), condition_(condition), body_(body) {}
ElseStatement::ElseStatement(const Source& source, BlockStatement* body)
: Base(source), body_(body) {}
ElseStatement::ElseStatement(const Source& source,
Expression* condition,
BlockStatement* body)

View File

@ -29,17 +29,6 @@ namespace ast {
/// An else statement
class ElseStatement : public Castable<ElseStatement, Statement> {
public:
/// Constructor
/// @param body the else body
explicit ElseStatement(BlockStatement* body);
/// Constructor
/// @param condition the else condition
/// @param body the else body
ElseStatement(Expression* condition, BlockStatement* body);
/// Constructor
/// @param source the source information
/// @param body the else body
ElseStatement(const Source& source, BlockStatement* body);
/// Constructor
/// @param source the source information
/// @param condition the else condition

View File

@ -31,26 +31,27 @@ TEST_F(ElseStatementTest, Creation) {
type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>(
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* discard = body->get(0);
ElseStatement e(cond, body);
ElseStatement e(Source{}, cond, body);
EXPECT_EQ(e.condition(), cond);
ASSERT_EQ(e.body()->size(), 1u);
EXPECT_EQ(e.body()->get(0), discard);
}
TEST_F(ElseStatementTest, Creation_WithSource) {
ElseStatement e(Source{Source::Location{20, 2}}, create<BlockStatement>());
ElseStatement e(Source{Source::Location{20, 2}}, nullptr,
create<BlockStatement>(Source{}));
auto src = e.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}
TEST_F(ElseStatementTest, IsElse) {
ElseStatement e(create<BlockStatement>());
ElseStatement e(Source{}, nullptr, create<BlockStatement>(Source{}));
EXPECT_TRUE(e.Is<ElseStatement>());
}
@ -58,49 +59,50 @@ TEST_F(ElseStatementTest, HasCondition) {
type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>(
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
ElseStatement e(cond, create<BlockStatement>());
ElseStatement e(Source{}, cond, create<BlockStatement>(Source{}));
EXPECT_TRUE(e.HasCondition());
}
TEST_F(ElseStatementTest, HasContition_NullCondition) {
ElseStatement e(create<BlockStatement>());
ElseStatement e(Source{}, nullptr, create<BlockStatement>(Source{}));
EXPECT_FALSE(e.HasCondition());
}
TEST_F(ElseStatementTest, IsValid) {
ElseStatement e(create<BlockStatement>());
ElseStatement e(Source{}, nullptr, create<BlockStatement>(Source{}));
EXPECT_TRUE(e.IsValid());
}
TEST_F(ElseStatementTest, IsValid_WithBody) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
ElseStatement e(body);
ElseStatement e(Source{}, nullptr, body);
EXPECT_TRUE(e.IsValid());
}
TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(nullptr);
ElseStatement e(body);
ElseStatement e(Source{}, nullptr, body);
EXPECT_FALSE(e.IsValid());
}
TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
auto* cond = create<ScalarConstructorExpression>(Source{}, nullptr);
ElseStatement e(cond, create<BlockStatement>());
ElseStatement e(Source{}, cond, create<BlockStatement>(Source{}));
EXPECT_FALSE(e.IsValid());
}
TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
auto* body = create<BlockStatement>();
body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
auto* body = create<BlockStatement>(Source{});
body->append(create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}),
ElseStatementList{}));
ElseStatement e(body);
ElseStatement e(Source{}, nullptr, body);
EXPECT_FALSE(e.IsValid());
}
@ -108,10 +110,10 @@ TEST_F(ElseStatementTest, ToStr) {
type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>(
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
ElseStatement e(cond, body);
ElseStatement e(Source{}, cond, body);
std::ostringstream out;
e.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Else{
@ -126,10 +128,10 @@ TEST_F(ElseStatementTest, ToStr) {
}
TEST_F(ElseStatementTest, ToStr_NoCondition) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
ElseStatement e(body);
ElseStatement e(Source{}, nullptr, body);
std::ostringstream out;
e.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Else{

View File

@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::FallthroughStatement);
namespace tint {
namespace ast {
FallthroughStatement::FallthroughStatement() : Base() {}
FallthroughStatement::FallthroughStatement(const Source& source)
: Base(source) {}

View File

@ -23,8 +23,6 @@ namespace ast {
/// An fallthrough statement
class FallthroughStatement : public Castable<FallthroughStatement, Statement> {
public:
/// Constructor
FallthroughStatement();
/// Constructor
/// @param source the source information
explicit FallthroughStatement(const Source& source);

View File

@ -23,7 +23,7 @@ namespace {
using FallthroughStatementTest = TestHelper;
TEST_F(FallthroughStatementTest, Creation) {
FallthroughStatement stmt;
FallthroughStatement stmt(Source{});
EXPECT_EQ(stmt.source().range.begin.line, 0u);
EXPECT_EQ(stmt.source().range.begin.column, 0u);
EXPECT_EQ(stmt.source().range.end.line, 0u);
@ -38,17 +38,17 @@ TEST_F(FallthroughStatementTest, Creation_WithSource) {
}
TEST_F(FallthroughStatementTest, IsFallthrough) {
FallthroughStatement stmt;
FallthroughStatement stmt(Source{});
EXPECT_TRUE(stmt.Is<FallthroughStatement>());
}
TEST_F(FallthroughStatementTest, IsValid) {
FallthroughStatement stmt;
FallthroughStatement stmt(Source{});
EXPECT_TRUE(stmt.IsValid());
}
TEST_F(FallthroughStatementTest, ToStr) {
FallthroughStatement stmt;
FallthroughStatement stmt(Source{});
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Fallthrough{}

View File

@ -44,7 +44,7 @@ TEST_F(FunctionTest, Creation) {
auto* var = params[0];
Function f(Source{}, func_sym, "func", params, &void_type,
create<BlockStatement>(), FunctionDecorationList{});
create<BlockStatement>(Source{}), FunctionDecorationList{});
EXPECT_EQ(f.symbol(), func_sym);
EXPECT_EQ(f.name(), "func");
ASSERT_EQ(f.params().size(), 1u);
@ -64,7 +64,8 @@ TEST_F(FunctionTest, Creation_WithSource) {
ast::VariableDecorationList{}));
Function f(Source{Source::Location{20, 2}}, func_sym, "func", params,
&void_type, create<BlockStatement>(), FunctionDecorationList{});
&void_type, create<BlockStatement>(Source{}),
FunctionDecorationList{});
auto src = f.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -79,7 +80,7 @@ TEST_F(FunctionTest, AddDuplicateReferencedVariables) {
Variable v(Source{}, "var", StorageClass::kInput, &i32, false, nullptr,
ast::VariableDecorationList{});
Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
create<BlockStatement>(), FunctionDecorationList{});
create<BlockStatement>(Source{}), FunctionDecorationList{});
f.add_referenced_module_variable(&v);
ASSERT_EQ(f.referenced_module_variables().size(), 1u);
@ -126,7 +127,7 @@ TEST_F(FunctionTest, GetReferenceLocations) {
});
Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
create<BlockStatement>(), FunctionDecorationList{});
create<BlockStatement>(Source{}), FunctionDecorationList{});
f.add_referenced_module_variable(loc1);
f.add_referenced_module_variable(builtin1);
@ -173,7 +174,7 @@ TEST_F(FunctionTest, GetReferenceBuiltins) {
});
Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
create<BlockStatement>(), FunctionDecorationList{});
create<BlockStatement>(Source{}), FunctionDecorationList{});
f.add_referenced_module_variable(loc1);
f.add_referenced_module_variable(builtin1);
@ -196,7 +197,7 @@ TEST_F(FunctionTest, AddDuplicateEntryPoints) {
auto main_sym = mod.RegisterSymbol("main");
Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
create<BlockStatement>(), FunctionDecorationList{});
create<BlockStatement>(Source{}), FunctionDecorationList{});
f.add_ancestor_entry_point(main_sym);
ASSERT_EQ(1u, f.ancestor_entry_points().size());
@ -218,8 +219,8 @@ TEST_F(FunctionTest, IsValid) {
false, nullptr,
ast::VariableDecorationList{}));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
Function f(Source{}, func_sym, "func", params, &void_type, body,
FunctionDecorationList{});
@ -237,8 +238,8 @@ TEST_F(FunctionTest, IsValid_InvalidName) {
false, nullptr,
ast::VariableDecorationList{}));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
Function f(Source{}, func_sym, "", params, &void_type, body,
FunctionDecorationList{});
@ -256,7 +257,7 @@ TEST_F(FunctionTest, IsValid_MissingReturnType) {
ast::VariableDecorationList{}));
Function f(Source{}, func_sym, "func", params, nullptr,
create<BlockStatement>(), FunctionDecorationList{});
create<BlockStatement>(Source{}), FunctionDecorationList{});
EXPECT_FALSE(f.IsValid());
}
@ -273,7 +274,7 @@ TEST_F(FunctionTest, IsValid_NullParam) {
params.push_back(nullptr);
Function f(Source{}, func_sym, "func", params, &void_type,
create<BlockStatement>(), FunctionDecorationList{});
create<BlockStatement>(Source{}), FunctionDecorationList{});
EXPECT_FALSE(f.IsValid());
}
@ -288,7 +289,7 @@ TEST_F(FunctionTest, IsValid_InvalidParam) {
ast::VariableDecorationList{}));
Function f(Source{}, func_sym, "func", params, &void_type,
create<BlockStatement>(), FunctionDecorationList{});
create<BlockStatement>(Source{}), FunctionDecorationList{});
EXPECT_FALSE(f.IsValid());
}
@ -303,8 +304,8 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) {
false, nullptr,
ast::VariableDecorationList{}));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(nullptr);
Function f(Source{}, func_sym, "func", params, &void_type, body,
@ -324,8 +325,8 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) {
false, nullptr,
ast::VariableDecorationList{}));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(nullptr);
Function f(Source{}, func_sym, "func", params, &void_type, body,
@ -339,8 +340,8 @@ TEST_F(FunctionTest, ToStr) {
auto func_sym = mod.RegisterSymbol("func");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
Function f(Source{}, func_sym, "func", {}, &void_type, body,
FunctionDecorationList{});
@ -361,8 +362,8 @@ TEST_F(FunctionTest, ToStr_WithDecoration) {
auto func_sym = mod.RegisterSymbol("func");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
Function f(
Source{}, func_sym, "func", {}, &void_type, body,
@ -390,8 +391,8 @@ TEST_F(FunctionTest, ToStr_WithParams) {
false, nullptr,
ast::VariableDecorationList{}));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
Function f(Source{}, func_sym, "func", params, &void_type, body,
FunctionDecorationList{});
@ -418,7 +419,7 @@ TEST_F(FunctionTest, TypeName) {
auto func_sym = mod.RegisterSymbol("func");
Function f(Source{}, func_sym, "func", {}, &void_type,
create<BlockStatement>(), FunctionDecorationList{});
create<BlockStatement>(Source{}), FunctionDecorationList{});
EXPECT_EQ(f.type_name(), "__func__void");
}
@ -438,7 +439,7 @@ TEST_F(FunctionTest, TypeName_WithParams) {
ast::VariableDecorationList{}));
Function f(Source{}, func_sym, "func", params, &void_type,
create<BlockStatement>(), FunctionDecorationList{});
create<BlockStatement>(Source{}), FunctionDecorationList{});
EXPECT_EQ(f.type_name(), "__func__void__i32__f32");
}
@ -448,8 +449,8 @@ TEST_F(FunctionTest, GetLastStatement) {
auto func_sym = mod.RegisterSymbol("func");
VariableList params;
auto* body = create<BlockStatement>();
auto* stmt = create<DiscardStatement>();
auto* body = create<BlockStatement>(Source{});
auto* stmt = create<DiscardStatement>(Source{});
body->append(stmt);
Function f(Source{}, func_sym, "func", params, &void_type, body,
FunctionDecorationList{});
@ -463,7 +464,7 @@ TEST_F(FunctionTest, GetLastStatement_nullptr) {
auto func_sym = mod.RegisterSymbol("func");
VariableList params;
auto* body = create<BlockStatement>();
auto* body = create<BlockStatement>(Source{});
Function f(Source{}, func_sym, "func", params, &void_type, body,
FunctionDecorationList{});
@ -476,7 +477,7 @@ TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
auto func_sym = mod.RegisterSymbol("func");
Function f(Source{}, func_sym, "func", {}, &void_type,
create<BlockStatement>(), FunctionDecorationList{});
create<BlockStatement>(Source{}), FunctionDecorationList{});
uint32_t x = 0;
uint32_t y = 0;
uint32_t z = 0;
@ -492,7 +493,7 @@ TEST_F(FunctionTest, WorkgroupSize) {
auto func_sym = mod.RegisterSymbol("func");
Function f(Source{}, func_sym, "func", {}, &void_type,
create<BlockStatement>(),
create<BlockStatement>(Source{}),
{create<WorkgroupDecoration>(2u, 4u, 6u, Source{})});
uint32_t x = 0;

View File

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

View File

@ -22,9 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::LoopStatement);
namespace tint {
namespace ast {
LoopStatement::LoopStatement(BlockStatement* body, BlockStatement* continuing)
: Base(), body_(body), continuing_(continuing) {}
LoopStatement::LoopStatement(const Source& source,
BlockStatement* body,
BlockStatement* continuing)

View File

@ -27,10 +27,6 @@ namespace ast {
/// A loop statement
class LoopStatement : public Castable<LoopStatement, Statement> {
public:
/// Constructor
/// @param body the body statements
/// @param continuing the continuing statements
LoopStatement(BlockStatement* body, BlockStatement* continuing);
/// Constructor
/// @param source the loop statement source
/// @param body the body statements

View File

@ -28,14 +28,14 @@ namespace {
using LoopStatementTest = TestHelper;
TEST_F(LoopStatementTest, Creation) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* b = body->last();
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
LoopStatement l(body, continuing);
LoopStatement l(Source{}, body, continuing);
ASSERT_EQ(l.body()->size(), 1u);
EXPECT_EQ(l.body()->get(0), b);
ASSERT_EQ(l.continuing()->size(), 1u);
@ -43,11 +43,11 @@ TEST_F(LoopStatementTest, Creation) {
}
TEST_F(LoopStatementTest, Creation_WithSource) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
LoopStatement l(Source{Source::Location{20, 2}}, body, continuing);
auto src = l.source();
@ -56,108 +56,112 @@ TEST_F(LoopStatementTest, Creation_WithSource) {
}
TEST_F(LoopStatementTest, IsLoop) {
LoopStatement l(create<BlockStatement>(), create<BlockStatement>());
LoopStatement l(Source{}, create<BlockStatement>(Source{}),
create<BlockStatement>(Source{}));
EXPECT_TRUE(l.Is<LoopStatement>());
}
TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
LoopStatement l(body, {});
LoopStatement l(Source{}, body, {});
EXPECT_FALSE(l.has_continuing());
}
TEST_F(LoopStatementTest, HasContinuing_WithContinuing) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
LoopStatement l(body, continuing);
LoopStatement l(Source{}, body, continuing);
EXPECT_TRUE(l.has_continuing());
}
TEST_F(LoopStatementTest, IsValid) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
LoopStatement l(body, continuing);
LoopStatement l(Source{}, body, continuing);
EXPECT_TRUE(l.IsValid());
}
TEST_F(LoopStatementTest, IsValid_WithoutContinuing) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
LoopStatement l(body, create<BlockStatement>());
LoopStatement l(Source{}, body, create<BlockStatement>(Source{}));
EXPECT_TRUE(l.IsValid());
}
TEST_F(LoopStatementTest, IsValid_WithoutBody) {
LoopStatement l(create<BlockStatement>(), create<BlockStatement>());
LoopStatement l(Source{}, create<BlockStatement>(Source{}),
create<BlockStatement>(Source{}));
EXPECT_TRUE(l.IsValid());
}
TEST_F(LoopStatementTest, IsValid_NullBodyStatement) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(nullptr);
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
LoopStatement l(body, continuing);
LoopStatement l(Source{}, body, continuing);
EXPECT_FALSE(l.IsValid());
}
TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}),
ElseStatementList{}));
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
LoopStatement l(body, continuing);
LoopStatement l(Source{}, body, continuing);
EXPECT_FALSE(l.IsValid());
}
TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
continuing->append(nullptr);
LoopStatement l(body, continuing);
LoopStatement l(Source{}, body, continuing);
EXPECT_FALSE(l.IsValid());
}
TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
continuing->append(create<IfStatement>(
Source{}, nullptr, create<BlockStatement>(), ElseStatementList{}));
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
continuing->append(create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}),
ElseStatementList{}));
LoopStatement l(body, continuing);
LoopStatement l(Source{}, body, continuing);
EXPECT_FALSE(l.IsValid());
}
TEST_F(LoopStatementTest, ToStr) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
LoopStatement l(body, {});
LoopStatement l(Source{}, body, {});
std::ostringstream out;
l.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Loop{
@ -167,13 +171,13 @@ TEST_F(LoopStatementTest, ToStr) {
}
TEST_F(LoopStatementTest, ToStr_WithContinuing) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
LoopStatement l(body, continuing);
LoopStatement l(Source{}, body, continuing);
std::ostringstream out;
l.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Loop{

View File

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

View File

@ -36,8 +36,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::Statement);
namespace tint {
namespace ast {
Statement::Statement() = default;
Statement::Statement(const Source& source) : Base(source) {}
Statement::Statement(Statement&&) = default;

View File

@ -32,8 +32,6 @@ class Statement : public Castable<Statement, Node> {
const char* Name() const;
protected:
/// Constructor
Statement();
/// Constructor
/// @param source the source of the expression
explicit Statement(const Source& source);

View File

@ -23,9 +23,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::SwitchStatement);
namespace tint {
namespace ast {
SwitchStatement::SwitchStatement(Expression* condition, CaseStatementList body)
: condition_(condition), body_(body) {}
SwitchStatement::SwitchStatement(const Source& source,
Expression* condition,
CaseStatementList body)

View File

@ -29,10 +29,6 @@ namespace ast {
/// A switch statement
class SwitchStatement : public Castable<SwitchStatement, Statement> {
public:
/// Constructor
/// @param condition the switch condition
/// @param body the switch body
SwitchStatement(Expression* condition, CaseStatementList body);
/// Constructor
/// @param source the source information
/// @param condition the switch condition

View File

@ -37,10 +37,11 @@ TEST_F(SwitchStatementTest, Creation) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
auto* case_stmt = create<CaseStatement>(lit, create<BlockStatement>());
auto* case_stmt =
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{}));
body.push_back(case_stmt);
SwitchStatement stmt(ident, body);
SwitchStatement stmt(Source{}, ident, body);
EXPECT_EQ(stmt.condition(), ident);
ASSERT_EQ(stmt.body().size(), 1u);
EXPECT_EQ(stmt.body()[0], case_stmt);
@ -66,9 +67,10 @@ TEST_F(SwitchStatementTest, IsSwitch) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
body.push_back(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
SwitchStatement stmt(ident, body);
SwitchStatement stmt(Source{}, ident, body);
EXPECT_TRUE(stmt.Is<SwitchStatement>());
}
@ -81,9 +83,10 @@ TEST_F(SwitchStatementTest, IsValid) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
body.push_back(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
SwitchStatement stmt(ident, body);
SwitchStatement stmt(Source{}, ident, body);
EXPECT_TRUE(stmt.IsValid());
}
@ -94,9 +97,10 @@ TEST_F(SwitchStatementTest, IsValid_Null_Condition) {
lit.push_back(create<SintLiteral>(Source{}, &i32, 2));
CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
body.push_back(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
SwitchStatement stmt(nullptr, body);
SwitchStatement stmt(Source{}, nullptr, body);
EXPECT_FALSE(stmt.IsValid());
}
@ -109,9 +113,10 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) {
auto* ident =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
body.push_back(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
SwitchStatement stmt(ident, body);
SwitchStatement stmt(Source{}, ident, body);
EXPECT_FALSE(stmt.IsValid());
}
@ -124,10 +129,11 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
body.push_back(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
body.push_back(nullptr);
SwitchStatement stmt(ident, body);
SwitchStatement stmt(Source{}, ident, body);
EXPECT_FALSE(stmt.IsValid());
}
@ -135,13 +141,14 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
auto* case_body = create<BlockStatement>();
auto* case_body = create<BlockStatement>(Source{});
case_body->append(nullptr);
CaseStatementList body;
body.push_back(create<CaseStatement>(CaseSelectorList{}, case_body));
body.push_back(
create<CaseStatement>(Source{}, CaseSelectorList{}, case_body));
SwitchStatement stmt(ident, body);
SwitchStatement stmt(Source{}, ident, body);
EXPECT_FALSE(stmt.IsValid());
}
@ -149,7 +156,7 @@ TEST_F(SwitchStatementTest, ToStr_Empty) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
SwitchStatement stmt(ident, {});
SwitchStatement stmt(Source{}, ident, {});
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(demangle(out.str()), R"( Switch{
@ -169,9 +176,10 @@ TEST_F(SwitchStatementTest, ToStr) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
body.push_back(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
SwitchStatement stmt(ident, body);
SwitchStatement stmt(Source{}, ident, body);
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(demangle(out.str()), R"( Switch{

View File

@ -22,9 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::VariableDeclStatement);
namespace tint {
namespace ast {
VariableDeclStatement::VariableDeclStatement(Variable* variable)
: Base(), variable_(variable) {}
VariableDeclStatement::VariableDeclStatement(const Source& source,
Variable* variable)
: Base(source), variable_(variable) {}

View File

@ -29,9 +29,6 @@ namespace ast {
class VariableDeclStatement
: public Castable<VariableDeclStatement, Statement> {
public:
/// Constructor
/// @param variable the variable
explicit VariableDeclStatement(Variable* variable);
/// Constructor
/// @param source the variable statement source
/// @param variable the variable

View File

@ -29,7 +29,7 @@ TEST_F(VariableDeclStatementTest, Creation) {
auto* var = create<Variable>(Source{}, "a", StorageClass::kNone, &f32, false,
nullptr, ast::VariableDecorationList{});
VariableDeclStatement stmt(var);
VariableDeclStatement stmt(Source{}, var);
EXPECT_EQ(stmt.variable(), var);
}
@ -49,15 +49,15 @@ TEST_F(VariableDeclStatementTest, IsVariableDecl) {
auto* var = create<Variable>(Source{}, "a", StorageClass::kNone, &f32, false,
nullptr, ast::VariableDecorationList{});
VariableDeclStatement s(var);
EXPECT_TRUE(s.Is<VariableDeclStatement>());
VariableDeclStatement stmt(Source{}, var);
EXPECT_TRUE(stmt.Is<VariableDeclStatement>());
}
TEST_F(VariableDeclStatementTest, IsValid) {
type::F32 f32;
auto* var = create<Variable>(Source{}, "a", StorageClass::kNone, &f32, false,
nullptr, ast::VariableDecorationList{});
VariableDeclStatement stmt(var);
VariableDeclStatement stmt(Source{}, var);
EXPECT_TRUE(stmt.IsValid());
}
@ -65,12 +65,12 @@ TEST_F(VariableDeclStatementTest, IsValid_InvalidVariable) {
type::F32 f32;
auto* var = create<Variable>(Source{}, "", StorageClass::kNone, &f32, false,
nullptr, ast::VariableDecorationList{});
VariableDeclStatement stmt(var);
VariableDeclStatement stmt(Source{}, var);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(VariableDeclStatementTest, IsValid_NullVariable) {
VariableDeclStatement stmt(nullptr);
VariableDeclStatement stmt(Source{}, nullptr);
EXPECT_FALSE(stmt.IsValid());
}

View File

@ -81,7 +81,7 @@ class InspectorHelper {
ast::Function* MakeEmptyBodyFunction(
std::string name,
ast::FunctionDecorationList decorations = {}) {
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, mod()->RegisterSymbol(name), name,
ast::VariableList(), void_type(), body,
@ -97,12 +97,12 @@ class InspectorHelper {
std::string caller,
std::string callee,
ast::FunctionDecorationList decorations = {}) {
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
auto* ident_expr = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
body->append(create<ast::CallStatement>(Source{}, call_expr));
body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, mod()->RegisterSymbol(caller),
caller, ast::VariableList(), void_type(), body,
@ -148,11 +148,12 @@ class InspectorHelper {
std::string name,
std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::FunctionDecorationList decorations = {}) {
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
for (auto inout : inout_vars) {
std::string in, out;
std::tie(in, out) = inout;
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod()->RegisterSymbol(out), out),
create<ast::IdentifierExpression>(Source{}, mod()->RegisterSymbol(in),
@ -177,11 +178,12 @@ class InspectorHelper {
std::string callee,
std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::FunctionDecorationList decorations = {}) {
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
for (auto inout : inout_vars) {
std::string in, out;
std::tie(in, out) = inout;
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
mod()->RegisterSymbol(out), out),
create<ast::IdentifierExpression>(Source{}, mod()->RegisterSymbol(in),
@ -191,7 +193,7 @@ class InspectorHelper {
Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
body->append(create<ast::CallStatement>(Source{}, call_expr));
body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, mod()->RegisterSymbol(caller),
caller, ast::VariableList(), void_type(), body,
@ -425,14 +427,15 @@ class InspectorHelper {
std::string func_name,
std::string struct_name,
std::vector<std::tuple<size_t, ast::type::Type*>> members) {
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
for (auto member : members) {
size_t member_idx;
ast::type::Type* member_type;
std::tie(member_idx, member_type) = member;
std::string member_name = StructMemberName(member_idx, member_type);
body->append(create<ast::VariableDeclStatement>(create<ast::Variable>(
body->append(create<ast::VariableDeclStatement>(
Source{}, create<ast::Variable>(
Source{}, // source
"local" + member_name, // name
ast::StorageClass::kNone, // storage_class
@ -448,10 +451,12 @@ class InspectorHelper {
std::tie(member_idx, member_type) = member;
std::string member_name = StructMemberName(member_idx, member_type);
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("local" + member_name),
"local" + member_name),
create<ast::MemberAccessorExpression>(Source{},
create<ast::MemberAccessorExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol(struct_name), struct_name),
create<ast::IdentifierExpression>(
@ -578,7 +583,7 @@ class InspectorHelper {
ast::FunctionDecorationList decorations = {}) {
std::string result_name = "sampler_result";
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
auto* call_result =
create<ast::Variable>(Source{}, // source
@ -588,7 +593,7 @@ class InspectorHelper {
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
body->append(create<ast::VariableDeclStatement>(call_result));
body->append(create<ast::VariableDeclStatement>(Source{}, call_result));
ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>(
@ -604,6 +609,7 @@ class InspectorHelper {
call_params);
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("sampler_result"),
"sampler_result"),
@ -634,7 +640,7 @@ class InspectorHelper {
ast::FunctionDecorationList decorations = {}) {
std::string result_name = "sampler_result";
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
auto* call_result =
create<ast::Variable>(Source{}, // source
@ -644,7 +650,7 @@ class InspectorHelper {
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
body->append(create<ast::VariableDeclStatement>(call_result));
body->append(create<ast::VariableDeclStatement>(Source{}, call_result));
ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>(
@ -662,6 +668,7 @@ class InspectorHelper {
call_params);
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("sampler_result"),
"sampler_result"),
@ -693,7 +700,7 @@ class InspectorHelper {
ast::FunctionDecorationList decorations = {}) {
std::string result_name = "sampler_result";
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
auto* call_result =
create<ast::Variable>(Source{}, // source
@ -703,7 +710,7 @@ class InspectorHelper {
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
body->append(create<ast::VariableDeclStatement>(call_result));
body->append(create<ast::VariableDeclStatement>(Source{}, call_result));
ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>(
@ -722,6 +729,7 @@ class InspectorHelper {
call_params);
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("sampler_result"),
"sampler_result"),
@ -1551,9 +1559,9 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
body->append(create<ast::CallStatement>(Source{}, call_expr));
};
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
AddFuncCall(body, "ub_foo_func");
AddFuncCall(body, "ub_bar_func");
@ -1699,9 +1707,9 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
body->append(create<ast::CallStatement>(Source{}, call_expr));
};
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
AddFuncCall(body, "sb_foo_func");
AddFuncCall(body, "sb_bar_func");
@ -1874,9 +1882,9 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
body->append(create<ast::CallStatement>(Source{}, call_expr));
};
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
AddFuncCall(body, "sb_foo_func");
AddFuncCall(body, "sb_bar_func");

View File

@ -667,7 +667,7 @@ void FunctionEmitter::PushNewStatementBlock(const Construct* construct,
ast::CaseStatementList* cases,
CompletionAction action) {
if (block == nullptr) {
block = create<ast::BlockStatement>();
block = create<ast::BlockStatement>(Source{});
}
statements_stack_.emplace_back(
@ -685,7 +685,7 @@ void FunctionEmitter::PushGuard(const std::string& guard_name,
auto* cond = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(guard_name), guard_name);
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
AddStatement(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
PushNewStatementBlock(top.construct_, end_id, body, nullptr, nullptr);
@ -696,7 +696,7 @@ void FunctionEmitter::PushTrueGuard(uint32_t end_id) {
const auto& top = statements_stack_.back();
auto* cond = MakeTrue(Source{});
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
AddStatement(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
PushNewStatementBlock(top.construct_, end_id, body, nullptr, nullptr);
@ -1865,7 +1865,7 @@ bool FunctionEmitter::EmitFunctionVariables() {
auto* var = parser_impl_.MakeVariable(
inst.result_id(), ast::StorageClass::kFunction, var_store_type, false,
constructor, ast::VariableDecorationList{});
auto* var_decl_stmt = create<ast::VariableDeclStatement>(var);
auto* var_decl_stmt = create<ast::VariableDeclStatement>(Source{}, var);
AddStatement(var_decl_stmt);
// Save this as an already-named value.
identifier_values_.insert(inst.result_id());
@ -2145,14 +2145,14 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
false, // is_const
MakeTrue(Source{}), // constructor
ast::VariableDecorationList{}); // decorations
auto* guard_decl = create<ast::VariableDeclStatement>(guard_var);
auto* guard_decl = create<ast::VariableDeclStatement>(Source{}, guard_var);
AddStatement(guard_decl);
}
const auto condition_id =
block_info.basic_block->terminator()->GetSingleWordInOperand(0);
auto* cond = MakeExpression(condition_id).expr;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
// Generate the code for the condition.
// Use the IfBuilder to create the if-statement. The IfBuilder is constructed
@ -2227,7 +2227,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
// But make sure we do it in the right order.
auto push_else = [this, if_builder, else_end, construct]() {
// Push the else clause onto the stack first.
auto* else_body = create<ast::BlockStatement>();
auto* else_body = create<ast::BlockStatement>(Source{});
PushNewStatementBlock(
construct, else_end, else_body, nullptr,
[this, if_builder, else_body]() {
@ -2236,7 +2236,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
// The "else" consists of the statement list from the top of
// statements stack, without an elseif condition.
if_builder->else_stmts_.emplace_back(
create<ast::ElseStatement>(nullptr, else_body));
create<ast::ElseStatement>(Source{}, nullptr, else_body));
}
});
};
@ -2294,7 +2294,7 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
// First, push the statement block for the entire switch.
ast::CaseStatementList case_list;
auto* swch = create<ast::SwitchStatement>(selector.expr, case_list);
auto* swch = create<ast::SwitchStatement>(Source{}, selector.expr, case_list);
AddStatement(swch)->As<ast::SwitchStatement>();
// Grab a pointer to the case list. It will get buried in the statement block
@ -2369,17 +2369,18 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
// Create the case clause. Temporarily put it in the wrong order
// on the case statement list.
auto* body = create<ast::BlockStatement>();
cases->emplace_back(create<ast::CaseStatement>(selectors, body));
auto* body = create<ast::BlockStatement>(Source{});
cases->emplace_back(create<ast::CaseStatement>(Source{}, selectors, body));
PushNewStatementBlock(construct, end_id, body, nullptr, nullptr);
if ((default_info == clause_heads[i]) && has_selectors &&
construct->ContainsPos(default_info->pos)) {
// Generate a default clause with a just fallthrough.
auto* stmts = create<ast::BlockStatement>();
stmts->append(create<ast::FallthroughStatement>());
auto* case_stmt = create<ast::CaseStatement>(stmts);
auto* stmts = create<ast::BlockStatement>(Source{});
stmts->append(create<ast::FallthroughStatement>(Source{}));
auto* case_stmt =
create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, stmts);
cases->emplace_back(case_stmt);
}
@ -2396,8 +2397,9 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
}
bool FunctionEmitter::EmitLoopStart(const Construct* construct) {
auto* body = create<ast::BlockStatement>();
AddStatement(create<ast::LoopStatement>(body, create<ast::BlockStatement>()));
auto* body = create<ast::BlockStatement>(Source{});
AddStatement(create<ast::LoopStatement>(
Source{}, body, create<ast::BlockStatement>(Source{})));
PushNewStatementBlock(construct, construct->end_id, body, nullptr, nullptr);
return success();
}
@ -2431,7 +2433,7 @@ bool FunctionEmitter::EmitNormalTerminator(const BlockInfo& block_info) {
case SpvOpKill:
// For now, assume SPIR-V OpKill has same semantics as WGSL discard.
// TODO(dneto): https://github.com/gpuweb/gpuweb/issues/676
AddStatement(create<ast::DiscardStatement>());
AddStatement(create<ast::DiscardStatement>(Source{}));
return true;
case SpvOpUnreachable:
// Translate as if it's a return. This avoids the problem where WGSL
@ -2525,7 +2527,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
break;
case EdgeKind::kSwitchBreak: {
if (forced) {
return create<ast::BreakStatement>();
return create<ast::BreakStatement>(Source{});
}
// Unless forced, don't bother with a break at the end of a case/default
// clause.
@ -2550,10 +2552,10 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
}
}
// We need a break.
return create<ast::BreakStatement>();
return create<ast::BreakStatement>(Source{});
}
case EdgeKind::kLoopBreak:
return create<ast::BreakStatement>();
return create<ast::BreakStatement>(Source{});
case EdgeKind::kLoopContinue:
// An unconditional continue to the next block is redundant and ugly.
// Skip it in that case.
@ -2561,7 +2563,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
break;
}
// Otherwise, emit a regular continue statement.
return create<ast::ContinueStatement>();
return create<ast::ContinueStatement>(Source{});
case EdgeKind::kIfBreak: {
const auto& flow_guard =
GetBlockInfo(dest_info.header_for_merge)->flow_guard_name;
@ -2571,6 +2573,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
}
// Signal an exit from the branch.
return create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(flow_guard), flow_guard),
MakeFalse(Source{}));
@ -2581,7 +2584,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
break;
}
case EdgeKind::kCaseFallThrough:
return create<ast::FallthroughStatement>();
return create<ast::FallthroughStatement>(Source{});
case EdgeKind::kForward:
// Unconditional forward branch is implicit.
break;
@ -2597,11 +2600,12 @@ ast::Statement* FunctionEmitter::MakeSimpleIf(ast::Expression* condition,
}
ast::ElseStatementList else_stmts;
if (else_stmt != nullptr) {
auto* stmts = create<ast::BlockStatement>();
auto* stmts = create<ast::BlockStatement>(Source{});
stmts->append(else_stmt);
else_stmts.emplace_back(create<ast::ElseStatement>(nullptr, stmts));
else_stmts.emplace_back(
create<ast::ElseStatement>(Source{}, nullptr, stmts));
}
auto* if_block = create<ast::BlockStatement>();
auto* if_block = create<ast::BlockStatement>(Source{});
auto* if_stmt =
create<ast::IfStatement>(Source{}, condition, if_block, else_stmts);
if (then_stmt != nullptr) {
@ -2649,7 +2653,7 @@ bool FunctionEmitter::EmitConditionalCaseFallThrough(
} else {
AddStatement(MakeSimpleIf(cond, other_branch, nullptr));
}
AddStatement(create<ast::FallthroughStatement>());
AddStatement(create<ast::FallthroughStatement>(Source{}));
return success();
}
@ -2676,8 +2680,9 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
assert(def_inst);
auto* ast_type =
RemapStorageClass(parser_impl_.ConvertType(def_inst->type_id()), id);
AddStatement(create<ast::VariableDeclStatement>(parser_impl_.MakeVariable(
id, ast::StorageClass::kFunction, ast_type, false, nullptr,
AddStatement(create<ast::VariableDeclStatement>(
Source{}, parser_impl_.MakeVariable(id, ast::StorageClass::kFunction,
ast_type, false, nullptr,
ast::VariableDecorationList{})));
// Save this as an already-named value.
identifier_values_.insert(id);
@ -2696,7 +2701,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
AddStatement(create<ast::VariableDeclStatement>(var));
AddStatement(create<ast::VariableDeclStatement>(Source{}, var));
}
// Emit regular statements.
@ -2727,6 +2732,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
const auto var_name = GetDefInfo(assignment.phi_id)->phi_var;
auto expr = MakeExpression(assignment.value);
AddStatement(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(var_name), var_name),
expr.expr));
@ -2749,7 +2755,7 @@ bool FunctionEmitter::EmitConstDefinition(
if (!ast_const) {
return false;
}
AddStatement(create<ast::VariableDeclStatement>(ast_const));
AddStatement(create<ast::VariableDeclStatement>(Source{}, ast_const));
// Save this as an already-named value.
identifier_values_.insert(inst.result_id());
return success();
@ -2764,6 +2770,7 @@ bool FunctionEmitter::EmitConstDefOrWriteToHoistedVar(
auto name = namer_.Name(result_id);
// Emit an assignment of the expression to the hoisted variable.
AddStatement(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), namer_.Name(result_id)),
ast_expr.expr));
@ -2833,7 +2840,8 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
// TODO(dneto): Order of evaluation?
auto lhs = MakeExpression(ptr_id);
auto rhs = MakeExpression(value_id);
AddStatement(create<ast::AssignmentStatement>(lhs.expr, rhs.expr));
AddStatement(
create<ast::AssignmentStatement>(Source{}, lhs.expr, rhs.expr));
return success();
}
case SpvOpLoad: {
@ -3743,7 +3751,8 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
}
if (result_type->Is<ast::type::Void>()) {
return nullptr != AddStatement(create<ast::CallStatement>(call_expr));
return nullptr !=
AddStatement(create<ast::CallStatement>(Source{}, call_expr));
}
return EmitConstDefOrWriteToHoistedVar(inst, {result_type, call_expr});
@ -3800,7 +3809,8 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
// The condition goes last.
params.push_back(condition.expr);
return {operand1.type,
create<ast::CallExpression>(Source{},
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol("select"), "select"),
std::move(params))};
@ -4014,7 +4024,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
} else {
// It's an image write. No value is returned, so make a statement out
// of the call.
AddStatement(create<ast::CallStatement>(call_expr));
AddStatement(create<ast::CallStatement>(Source{}, call_expr));
}
return success();
}
@ -4182,10 +4192,11 @@ ast::Expression* FunctionEmitter::ConvertTexelForStorage(
}
// If the texel has more components than necessary, then we will ignore the
// higher-numbered components.
auto* texel_prefix = (src_count == dest_count)
auto* texel_prefix =
(src_count == dest_count)
? texel.expr
: create<ast::MemberAccessorExpression>(Source{},
texel.expr, PrefixSwizzle(dest_count));
: create<ast::MemberAccessorExpression>(Source{}, texel.expr,
PrefixSwizzle(dest_count));
if (!(dest_type->is_float_scalar_or_vector() ||
dest_type->is_unsigned_scalar_or_vector() ||

View File

@ -1438,7 +1438,7 @@ Expect<ast::Expression*> ParserImpl::expect_paren_rhs_stmt() {
// : statement*
Expect<ast::BlockStatement*> ParserImpl::expect_statements() {
bool errored = false;
auto* ret = create<ast::BlockStatement>();
auto* ret = create<ast::BlockStatement>(Source{});
while (synchronized_) {
auto stmt = statement();
@ -1724,7 +1724,7 @@ Maybe<ast::ElseStatement*> ParserImpl::else_stmt() {
if (body.errored)
return Failure::kErrored;
return create<ast::ElseStatement>(source, body.value);
return create<ast::ElseStatement>(source, nullptr, body.value);
}
// switch_stmt
@ -1827,7 +1827,7 @@ Expect<ast::CaseSelectorList> ParserImpl::expect_case_selectors() {
// | statement case_body
// | FALLTHROUGH SEMICOLON
Maybe<ast::BlockStatement*> ParserImpl::case_body() {
auto* ret = create<ast::BlockStatement>();
auto* ret = create<ast::BlockStatement>(Source{});
for (;;) {
Source source;
if (match(Token::Type::kFallthrough, &source)) {
@ -2026,10 +2026,11 @@ Maybe<ast::CallStatement*> ParserImpl::func_call_stmt() {
if (!expect("call statement", Token::Type::kParenRight))
return Failure::kErrored;
return create<ast::CallStatement>(create<ast::CallExpression>(
return create<ast::CallStatement>(
Source{}, create<ast::CallExpression>(
source,
create<ast::IdentifierExpression>(Source{}, module_.RegisterSymbol(name),
name),
create<ast::IdentifierExpression>(
source, module_.RegisterSymbol(name), name),
std::move(params)));
}
@ -2057,7 +2058,7 @@ Maybe<ast::ContinueStatement*> ParserImpl::continue_stmt() {
// : CONTINUING body_stmt
Maybe<ast::BlockStatement*> ParserImpl::continuing_stmt() {
if (!match(Token::Type::kContinuing))
return create<ast::BlockStatement>();
return create<ast::BlockStatement>(Source{});
return expect_body_stmt();
}

View File

@ -91,7 +91,7 @@ class BoundArrayAccessorsTest : public testing::Test {
};
struct ModuleBuilder : public ast::BuilderWithModule {
ModuleBuilder() : body_(create<ast::BlockStatement>()) {
ModuleBuilder() : body_(create<ast::BlockStatement>(Source{})) {
mod->AddFunction(create<ast::Function>(
Source{}, mod->RegisterSymbol("func"), "func", ast::VariableList{},
ty.void_, body_, ast::FunctionDecorationList{}));
@ -106,7 +106,7 @@ struct ModuleBuilder : public ast::BuilderWithModule {
virtual void Build() = 0;
void OnVariableBuilt(ast::Variable* var) override {
ASSERT_NE(body_, nullptr);
body_->append(create<ast::VariableDeclStatement>(var));
body_->append(create<ast::VariableDeclStatement>(Source{}, var));
}
ast::BlockStatement* body_ = nullptr;
};

View File

@ -65,12 +65,12 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
mod->AddGlobalVariable(pointsize_var);
// Build the AST expression & statement for assigning pointsize one.
auto* one = mod->create<ast::ScalarConstructorExpression>(Source{},
mod->create<ast::FloatLiteral>(Source{}, f32, 1.0f));
auto* one = mod->create<ast::ScalarConstructorExpression>(
Source{}, mod->create<ast::FloatLiteral>(Source{}, f32, 1.0f));
auto* pointsize_ident = mod->create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol(kPointSizeVar), kPointSizeVar);
auto* pointsize_assign =
mod->create<ast::AssignmentStatement>(pointsize_ident, one);
mod->create<ast::AssignmentStatement>(Source{}, pointsize_ident, one);
// Add the pointsize assignment statement to the front of all vertex stages.
for (auto* func : mod->functions()) {

View File

@ -56,7 +56,7 @@ TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
auto* block = create<ast::BlockStatement>(Source{});
block->append(create<ast::VariableDeclStatement>(
Var("builtin_assignments_should_happen_before_this",
Source{}, Var("builtin_assignments_should_happen_before_this",
tint::ast::StorageClass::kFunction, ty.f32)));
auto a_sym = mod->RegisterSymbol("non_entry_a");

View File

@ -270,7 +270,7 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset(
true, // is_const
constructor, // constructor
ast::VariableDecorationList{}); // decorations
return mod->create<ast::VariableDeclStatement>(var);
return mod->create<ast::VariableDeclStatement>(Source{}, var);
}
} // namespace transform

View File

@ -61,7 +61,7 @@ struct ModuleBuilder : public ast::BuilderWithModule {
ast::VariableList params = {}) {
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol(name), name, std::move(params), ty.u32,
create<ast::BlockStatement>(), ast::FunctionDecorationList());
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList());
mod->AddFunction(func);
return func;
}

View File

@ -292,11 +292,11 @@ void VertexPulling::State::AddVertexPullingPreamble(
// location.
// A block statement allowing us to use append instead of insert
auto* block = mod->create<ast::BlockStatement>();
auto* block = mod->create<ast::BlockStatement>(Source{});
// Declare the |kPullingPosVarName| variable in the shader
auto* pos_declaration =
mod->create<ast::VariableDeclStatement>(mod->create<ast::Variable>(
auto* pos_declaration = mod->create<ast::VariableDeclStatement>(
Source{}, mod->create<ast::Variable>(
Source{}, // source
kPullingPosVarName, // name
ast::StorageClass::kFunction, // storage_class
@ -338,10 +338,11 @@ void VertexPulling::State::AddVertexPullingPreamble(
// Update position of the read
auto* set_pos_expr = mod->create<ast::AssignmentStatement>(
CreatePullingPositionIdent(), pos_value);
Source{}, CreatePullingPositionIdent(), pos_value);
block->append(set_pos_expr);
block->append(mod->create<ast::AssignmentStatement>(
Source{},
mod->create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol(v->name()), v->name()),
AccessByFormat(i, attribute_desc.format)));

View File

@ -48,7 +48,7 @@ class VertexPullingHelper {
void InitBasicModule() {
auto* func = create<ast::Function>(
Source{}, mod_->RegisterSymbol("main"), "main", ast::VariableList{},
mod_->create<ast::type::Void>(), create<ast::BlockStatement>(),
mod_->create<ast::type::Void>(), create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{create<ast::StageDecoration>(
ast::PipelineStage::kVertex, Source{})});
mod()->AddFunction(func);
@ -135,7 +135,7 @@ TEST_F(VertexPullingTest, Error_InvalidEntryPoint) {
TEST_F(VertexPullingTest, Error_EntryPointWrongStage) {
auto* func = create<ast::Function>(
Source{}, mod()->RegisterSymbol("main"), "main", ast::VariableList{},
mod()->create<ast::type::Void>(), create<ast::BlockStatement>(),
mod()->create<ast::type::Void>(), create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
});

View File

@ -132,7 +132,7 @@ TEST_F(TypeDeterminerTest, Stmt_Assign) {
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
ast::AssignmentStatement assign(lhs, rhs);
ast::AssignmentStatement assign(Source{}, lhs, rhs);
EXPECT_TRUE(td()->DetermineResultType(&assign));
ASSERT_NE(lhs->result_type(), nullptr);
@ -151,12 +151,12 @@ TEST_F(TypeDeterminerTest, Stmt_Case) {
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(lhs, rhs));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 3));
ast::CaseStatement cse(lit, body);
ast::CaseStatement cse(Source{}, lit, body);
EXPECT_TRUE(td()->DetermineResultType(&cse));
ASSERT_NE(lhs->result_type(), nullptr);
@ -174,8 +174,8 @@ TEST_F(TypeDeterminerTest, Stmt_Block) {
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
ast::BlockStatement block;
block.append(create<ast::AssignmentStatement>(lhs, rhs));
ast::BlockStatement block(Source{});
block.append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
EXPECT_TRUE(td()->DetermineResultType(&block));
ASSERT_NE(lhs->result_type(), nullptr);
@ -193,10 +193,11 @@ TEST_F(TypeDeterminerTest, Stmt_Else) {
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(lhs, rhs));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
ast::ElseStatement stmt(
Source{},
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)),
body);
@ -219,10 +220,12 @@ TEST_F(TypeDeterminerTest, Stmt_If) {
auto* else_rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::AssignmentStatement>(else_lhs, else_rhs));
auto* else_body = create<ast::BlockStatement>(Source{});
else_body->append(
create<ast::AssignmentStatement>(Source{}, else_lhs, else_rhs));
auto* else_stmt = create<ast::ElseStatement>(
Source{},
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)),
else_body);
@ -232,8 +235,8 @@ TEST_F(TypeDeterminerTest, Stmt_If) {
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(lhs, rhs));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
ast::IfStatement stmt(
Source{},
@ -263,19 +266,19 @@ TEST_F(TypeDeterminerTest, Stmt_Loop) {
auto* body_rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(body_lhs, body_rhs));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(Source{}, body_lhs, body_rhs));
auto* continuing_lhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* continuing_rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* continuing = create<ast::BlockStatement>();
continuing->append(
create<ast::AssignmentStatement>(continuing_lhs, continuing_rhs));
auto* continuing = create<ast::BlockStatement>(Source{});
continuing->append(create<ast::AssignmentStatement>(Source{}, continuing_lhs,
continuing_rhs));
ast::LoopStatement stmt(body, continuing);
ast::LoopStatement stmt(Source{}, body, continuing);
EXPECT_TRUE(td()->DetermineResultType(&stmt));
ASSERT_NE(body_lhs->result_type(), nullptr);
@ -316,16 +319,17 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) {
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(lhs, rhs));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 3));
ast::CaseStatementList cases;
cases.push_back(create<ast::CaseStatement>(lit, body));
cases.push_back(create<ast::CaseStatement>(Source{}, lit, body));
ast::SwitchStatement stmt(
Source{},
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)),
cases);
@ -346,7 +350,7 @@ TEST_F(TypeDeterminerTest, Stmt_Call) {
ast::VariableList params;
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
create<ast::BlockStatement>(), ast::FunctionDecorationList{});
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList{});
mod->AddFunction(func);
// Register the function
@ -359,7 +363,7 @@ TEST_F(TypeDeterminerTest, Stmt_Call) {
Source{}, mod->RegisterSymbol("my_func"), "my_func"),
call_params);
ast::CallStatement call(expr);
ast::CallStatement call(Source{}, expr);
EXPECT_TRUE(td()->DetermineResultType(&call));
ASSERT_NE(expr->result_type(), nullptr);
EXPECT_TRUE(expr->result_type()->Is<ast::type::F32>());
@ -376,15 +380,15 @@ TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) {
mod->RegisterSymbol("func"), "func"),
call_params);
ast::VariableList params0;
auto* main_body = create<ast::BlockStatement>();
main_body->append(create<ast::CallStatement>(call_expr));
auto* main_body = create<ast::BlockStatement>(Source{});
main_body->append(create<ast::CallStatement>(Source{}, call_expr));
main_body->append(create<ast::ReturnStatement>(Source{}));
auto* func_main = create<ast::Function>(Source{}, mod->RegisterSymbol("main"),
"main", params0, &f32, main_body,
ast::FunctionDecorationList{});
mod->AddFunction(func_main);
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
auto* func =
create<ast::Function>(Source{}, mod->RegisterSymbol("func"), "func",
@ -410,7 +414,7 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl) {
ast::VariableDecorationList{}); // decorations
auto* init = var->constructor();
ast::VariableDeclStatement decl(var);
ast::VariableDeclStatement decl(Source{}, var);
EXPECT_TRUE(td()->DetermineResultType(&decl));
ASSERT_NE(init->result_type(), nullptr);
@ -671,7 +675,7 @@ TEST_F(TypeDeterminerTest, Expr_Call) {
ast::VariableList params;
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
create<ast::BlockStatement>(), ast::FunctionDecorationList{});
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList{});
mod->AddFunction(func);
// Register the function
@ -694,7 +698,7 @@ TEST_F(TypeDeterminerTest, Expr_Call_WithParams) {
ast::VariableList params;
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
create<ast::BlockStatement>(), ast::FunctionDecorationList{});
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList{});
mod->AddFunction(func);
// Register the function
@ -847,11 +851,12 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable_Const) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::AssignmentStatement>(
my_var, create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("my_var"), "my_var")));
Source{}, my_var,
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_var"),
"my_var")));
ast::Function f(Source{}, mod->RegisterSymbol("my_func"), "my_func", {}, &f32,
body, ast::FunctionDecorationList{});
@ -868,8 +873,9 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable) {
auto* my_var = create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("my_var"), "my_var");
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(
Source{},
create<ast::Variable>(Source{}, // source
"my_var", // name
ast::StorageClass::kNone, // storage_class
@ -879,8 +885,9 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable) {
ast::VariableDecorationList{}))); // decorations
body->append(create<ast::AssignmentStatement>(
my_var, create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("my_var"), "my_var")));
Source{}, my_var,
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_var"),
"my_var")));
ast::Function f(Source{}, mod->RegisterSymbol("myfunc"), "my_func", {}, &f32,
body, ast::FunctionDecorationList{});
@ -902,8 +909,9 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) {
auto* my_var = create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("my_var"), "my_var");
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(
Source{},
create<ast::Variable>(Source{}, // source
"my_var", // name
ast::StorageClass::kNone, // storage_class
@ -913,8 +921,9 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) {
ast::VariableDecorationList{}))); // decorations
body->append(create<ast::AssignmentStatement>(
my_var, create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("my_var"), "my_var")));
Source{}, my_var,
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_var"),
"my_var")));
ast::Function f(Source{}, mod->RegisterSymbol("my_func"), "my_func", {}, &f32,
body, ast::FunctionDecorationList{});
@ -935,7 +944,7 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function) {
ast::VariableList params;
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
create<ast::BlockStatement>(), ast::FunctionDecorationList{});
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList{});
mod->AddFunction(func);
// Register the function
@ -1004,23 +1013,27 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables) {
mod->AddGlobalVariable(priv_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("out_var"), "out_var"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("in_var"),
"in_var")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"),
"wg_var"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"),
"wg_var")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"),
"sb_var"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"),
"sb_var")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("priv_var"), "priv_var"),
create<ast::IdentifierExpression>(
@ -1093,23 +1106,27 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
mod->AddGlobalVariable(wg_var);
mod->AddGlobalVariable(priv_var);
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("out_var"), "out_var"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("in_var"),
"in_var")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"),
"wg_var"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"),
"wg_var")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"),
"sb_var"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"),
"sb_var")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("priv_var"), "priv_var"),
create<ast::IdentifierExpression>(
@ -1121,8 +1138,9 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
mod->AddFunction(func);
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("out_var"), "out_var"),
create<ast::CallExpression>(
@ -1160,9 +1178,10 @@ TEST_F(TypeDeterminerTest, Function_NotRegisterFunctionVariable) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
"var"),
create<ast::ScalarConstructorExpression>(
@ -2839,9 +2858,9 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) {
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* stmt = create<ast::VariableDeclStatement>(var);
auto* stmt = create<ast::VariableDeclStatement>(Source{}, var);
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(stmt);
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"),
"func", ast::VariableList{}, &i32, body,
@ -2864,9 +2883,9 @@ TEST_F(TypeDeterminerTest, StorageClass_DoesNotSetOnConst) {
true, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* stmt = create<ast::VariableDeclStatement>(var);
auto* stmt = create<ast::VariableDeclStatement>(Source{}, var);
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(stmt);
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"),
"func", ast::VariableList{}, &i32, body,
@ -2889,9 +2908,9 @@ TEST_F(TypeDeterminerTest, StorageClass_NonFunctionClassError) {
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* stmt = create<ast::VariableDeclStatement>(var);
auto* stmt = create<ast::VariableDeclStatement>(Source{}, var);
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(stmt);
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"),
"func", ast::VariableList{}, &i32, body,
@ -5209,13 +5228,14 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
// ep_2 -> {}
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
auto* func_b =
create<ast::Function>(Source{}, mod->RegisterSymbol("b"), "b", params,
&f32, body, ast::FunctionDecorationList{});
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("second"),
"second"),
create<ast::CallExpression>(Source{},
@ -5226,8 +5246,9 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
create<ast::Function>(Source{}, mod->RegisterSymbol("c"), "c", params,
&f32, body, ast::FunctionDecorationList{});
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("first"),
"first"),
create<ast::CallExpression>(Source{},
@ -5238,8 +5259,9 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
create<ast::Function>(Source{}, mod->RegisterSymbol("a"), "a", params,
&f32, body, ast::FunctionDecorationList{});
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("call_a"),
"call_a"),
create<ast::CallExpression>(Source{},
@ -5247,6 +5269,7 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
Source{}, mod->RegisterSymbol("a"), "a"),
ast::ExpressionList{})));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("call_b"),
"call_b"),
create<ast::CallExpression>(Source{},
@ -5259,8 +5282,9 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
});
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("call_c"),
"call_c"),
create<ast::CallExpression>(Source{},

View File

@ -57,13 +57,14 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
auto* cond = create<ast::IdentifierExpression>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
auto* block_default = create<ast::BlockStatement>(Source{});
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(default_csl, block_default));
body.push_back(
create<ast::CaseStatement>(Source{}, default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, body));
auto* block = create<ast::BlockStatement>(Source{});
block->append(create<ast::VariableDeclStatement>(Source{}, var));
block->append(create<ast::SwitchStatement>(Source{}, cond, body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -94,11 +95,11 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
ast::CaseSelectorList csl;
csl.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
ast::CaseStatementList body;
body.push_back(
create<ast::CaseStatement>(csl, create<ast::BlockStatement>()));
body.push_back(create<ast::CaseStatement>(
Source{}, csl, create<ast::BlockStatement>(Source{})));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(var));
auto* block = create<ast::BlockStatement>(Source{});
block->append(create<ast::VariableDeclStatement>(Source{}, var));
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}},
cond, body));
@ -133,22 +134,23 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl_1;
auto* block_default_1 = create<ast::BlockStatement>();
auto* block_default_1 = create<ast::BlockStatement>(Source{});
switch_body.push_back(
create<ast::CaseStatement>(default_csl_1, block_default_1));
create<ast::CaseStatement>(Source{}, default_csl_1, block_default_1));
ast::CaseSelectorList csl_case_1;
csl_case_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
auto* block_case_1 = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(csl_case_1, block_case_1));
auto* block_case_1 = create<ast::BlockStatement>(Source{});
switch_body.push_back(
create<ast::CaseStatement>(Source{}, csl_case_1, block_case_1));
ast::CaseSelectorList default_csl_2;
auto* block_default_2 = create<ast::BlockStatement>();
auto* block_default_2 = create<ast::BlockStatement>(Source{});
switch_body.push_back(
create<ast::CaseStatement>(default_csl_2, block_default_2));
create<ast::CaseStatement>(Source{}, default_csl_2, block_default_2));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(var));
auto* block = create<ast::BlockStatement>(Source{});
block->append(create<ast::VariableDeclStatement>(Source{}, var));
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}},
cond, switch_body));
@ -185,16 +187,18 @@ TEST_F(ValidateControlBlockTest,
ast::CaseSelectorList csl;
csl.push_back(create<ast::UintLiteral>(Source{}, &u32, 1));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, csl, create<ast::BlockStatement>()));
switch_body.push_back(
create<ast::CaseStatement>(Source{Source::Location{12, 34}}, csl,
create<ast::BlockStatement>(Source{})));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block_default = create<ast::BlockStatement>(Source{});
switch_body.push_back(
create<ast::CaseStatement>(Source{}, default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, switch_body));
auto* block = create<ast::BlockStatement>(Source{});
block->append(create<ast::VariableDeclStatement>(Source{}, var));
block->append(create<ast::SwitchStatement>(Source{}, cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -229,16 +233,18 @@ TEST_F(ValidateControlBlockTest,
ast::CaseSelectorList csl;
csl.push_back(create<ast::SintLiteral>(Source{}, &i32, -1));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, csl, create<ast::BlockStatement>()));
switch_body.push_back(
create<ast::CaseStatement>(Source{Source::Location{12, 34}}, csl,
create<ast::BlockStatement>(Source{})));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block_default = create<ast::BlockStatement>(Source{});
switch_body.push_back(
create<ast::CaseStatement>(Source{}, default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, switch_body));
auto* block = create<ast::BlockStatement>(Source{});
block->append(create<ast::VariableDeclStatement>(Source{}, var));
block->append(create<ast::SwitchStatement>(Source{}, cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -272,22 +278,24 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::UintLiteral>(Source{}, &u32, 0));
switch_body.push_back(
create<ast::CaseStatement>(csl_1, create<ast::BlockStatement>()));
switch_body.push_back(create<ast::CaseStatement>(
Source{}, csl_1, create<ast::BlockStatement>(Source{})));
ast::CaseSelectorList csl_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(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, csl_2, create<ast::BlockStatement>()));
switch_body.push_back(
create<ast::CaseStatement>(Source{Source::Location{12, 34}}, csl_2,
create<ast::BlockStatement>(Source{})));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block_default = create<ast::BlockStatement>(Source{});
switch_body.push_back(
create<ast::CaseStatement>(Source{}, default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, switch_body));
auto* block = create<ast::BlockStatement>(Source{});
block->append(create<ast::VariableDeclStatement>(Source{}, var));
block->append(create<ast::SwitchStatement>(Source{}, cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -321,24 +329,26 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 10));
switch_body.push_back(
create<ast::CaseStatement>(csl_1, create<ast::BlockStatement>()));
switch_body.push_back(create<ast::CaseStatement>(
Source{}, csl_1, create<ast::BlockStatement>(Source{})));
ast::CaseSelectorList csl_2;
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, 2));
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 10));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, csl_2, create<ast::BlockStatement>()));
switch_body.push_back(
create<ast::CaseStatement>(Source{Source::Location{12, 34}}, csl_2,
create<ast::BlockStatement>(Source{})));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block_default = create<ast::BlockStatement>(Source{});
switch_body.push_back(
create<ast::CaseStatement>(Source{}, default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, switch_body));
auto* block = create<ast::BlockStatement>(Source{});
block->append(create<ast::VariableDeclStatement>(Source{}, var));
block->append(create<ast::SwitchStatement>(Source{}, cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -367,15 +377,16 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
auto* block_default = create<ast::BlockStatement>(Source{});
block_default->append(
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}));
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(default_csl, block_default));
body.push_back(
create<ast::CaseStatement>(Source{}, default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, body));
auto* block = create<ast::BlockStatement>(Source{});
block->append(create<ast::VariableDeclStatement>(Source{}, var));
block->append(create<ast::SwitchStatement>(Source{}, cond, body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -405,18 +416,18 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
auto* block_default = create<ast::BlockStatement>(Source{});
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
default_csl, block_default));
ast::CaseSelectorList case_csl;
case_csl.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
auto* block_case = create<ast::BlockStatement>();
body.push_back(create<ast::CaseStatement>(case_csl, block_case));
auto* block_case = create<ast::BlockStatement>(Source{});
body.push_back(create<ast::CaseStatement>(Source{}, case_csl, block_case));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, body));
auto* block = create<ast::BlockStatement>(Source{});
block->append(create<ast::VariableDeclStatement>(Source{}, var));
block->append(create<ast::SwitchStatement>(Source{}, cond, body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_TRUE(v()->ValidateStatements(block)) << v()->error();
@ -446,14 +457,14 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
auto* block_default = create<ast::BlockStatement>(Source{});
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, body));
auto* block = create<ast::BlockStatement>(Source{});
block->append(create<ast::VariableDeclStatement>(Source{}, var));
block->append(create<ast::SwitchStatement>(Source{}, cond, body));
mod()->AddConstructedType(&my_int);

View File

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

View File

@ -103,7 +103,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) {
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs));
@ -199,8 +199,8 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs));
@ -234,8 +234,8 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
ast::BlockStatement block;
block.append(create<ast::VariableDeclStatement>(var));
ast::BlockStatement block(Source{});
block.append(create<ast::VariableDeclStatement>(Source{}, var));
block.append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs));
@ -339,7 +339,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs));
@ -379,7 +379,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs));
body->append(create<ast::ReturnStatement>(Source{}));
@ -415,15 +415,15 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
ast::type::Bool bool_type;
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
auto* lhs = create<ast::IdentifierExpression>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
auto* outer_body = create<ast::BlockStatement>();
auto* outer_body = create<ast::BlockStatement>(Source{});
outer_body->append(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
outer_body->append(create<ast::AssignmentStatement>(
@ -461,12 +461,12 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
ast::type::Bool bool_type;
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs));
auto* outer_body = create<ast::BlockStatement>();
outer_body->append(create<ast::VariableDeclStatement>(var));
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();
@ -564,8 +564,8 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs));
@ -609,7 +609,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
create<ast::FloatLiteral>(Source{}, &f32, 2.0)), // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var));
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"),
@ -655,8 +655,8 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
ast::VariableDecorationList{}); // decorations
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var_a_float));
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"),
@ -691,8 +691,8 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
ast::type::Bool bool_type;
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
auto* var_a_float = create<ast::Variable>(
Source{}, // source
@ -705,7 +705,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
create<ast::FloatLiteral>(Source{}, &f32, 3.14)), // constructor
ast::VariableDecorationList{}); // decorations
auto* outer_body = create<ast::BlockStatement>();
auto* outer_body = create<ast::BlockStatement>(Source{});
outer_body->append(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
outer_body->append(create<ast::VariableDeclStatement>(
@ -748,12 +748,12 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
ast::type::Bool bool_type;
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var));
auto* outer_body = create<ast::BlockStatement>();
outer_body->append(create<ast::VariableDeclStatement>(var_a_float));
auto* outer_body = create<ast::BlockStatement>(Source{});
outer_body->append(create<ast::VariableDeclStatement>(Source{}, var_a_float));
outer_body->append(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
@ -790,7 +790,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
ast::VariableDecorationList{}); // decorations
ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>();
auto* body0 = create<ast::BlockStatement>(Source{});
body0->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var0));
body0->append(create<ast::ReturnStatement>(Source{}));
@ -799,7 +799,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
ast::FunctionDecorationList{});
ast::VariableList params1;
auto* body1 = create<ast::BlockStatement>();
auto* body1 = create<ast::BlockStatement>(Source{});
body1->append(create<ast::VariableDeclStatement>(
Source{Source::Location{13, 34}}, var1));
body1->append(create<ast::ReturnStatement>(Source{}));
@ -838,8 +838,8 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs));

View File

@ -203,7 +203,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
ast::VariableDecorationList{}); // decorations
ast::VariableList params;
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var));

View File

@ -32,7 +32,7 @@ TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) {
Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
ast::AssignmentStatement assign(lhs, rhs);
ast::AssignmentStatement assign(Source{}, lhs, rhs);
gen.increment_indent();

View File

@ -464,17 +464,18 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
ast::type::I32 i32;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))));
auto* else_stmt = create<ast::ElseStatement>(body);
auto* else_stmt = create<ast::ElseStatement>(Source{}, nullptr, body);
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
auto* else_if_stmt = create<ast::ElseStatement>(
Source{},
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
@ -483,7 +484,7 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
"c")),
body);
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
@ -563,10 +564,11 @@ TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) {
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"), "d");
ast::AssignmentStatement expr(
a, create<ast::BinaryExpression>(
Source{}, a,
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalAnd,
create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kLogicalOr,
b, c),
create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kLogicalOr, b,
c),
d));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
@ -606,7 +608,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) {
d), // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement expr(var);
ast::VariableDeclStatement expr(Source{}, var);
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = b;
@ -657,9 +659,10 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
ast::type::Void void_type;
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("foo"), "foo", ast::VariableList{},
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("foo"), "foo",
ast::VariableList{}, &void_type,
create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
mod.AddFunction(func);
ast::ExpressionList params;
@ -688,10 +691,11 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"),
"d"))));
ast::CallStatement expr(create<ast::CallExpression>(
ast::CallStatement expr(Source{},
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo"),
params));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();

View File

@ -26,8 +26,8 @@ namespace {
using HlslGeneratorImplTest_Block = TestHelper;
TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
ast::BlockStatement b;
b.append(create<ast::DiscardStatement>());
ast::BlockStatement b(Source{});
b.append(create<ast::DiscardStatement>(Source{}));
gen.increment_indent();
@ -39,8 +39,8 @@ TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
}
TEST_F(HlslGeneratorImplTest_Block, Emit_Block_WithoutNewline) {
ast::BlockStatement b;
b.append(create<ast::DiscardStatement>());
ast::BlockStatement b(Source{});
b.append(create<ast::DiscardStatement>(Source{}));
gen.increment_indent();

View File

@ -27,7 +27,7 @@ namespace {
using HlslGeneratorImplTest_Break = TestHelper;
TEST_F(HlslGeneratorImplTest_Break, Emit_Break) {
ast::BreakStatement b;
ast::BreakStatement b(Source{});
gen.increment_indent();

View File

@ -36,9 +36,10 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::CallExpression call(Source{}, id, {});
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
mod.AddFunction(func);
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
@ -57,9 +58,10 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(Source{}, id, params);
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
mod.AddFunction(func);
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
@ -76,11 +78,13 @@ TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallStatement call(create<ast::CallExpression>(Source{}, id, params));
ast::CallStatement call(Source{},
create<ast::CallExpression>(Source{}, id, params));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
mod.AddFunction(func);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &call)) << gen.error();

View File

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

View File

@ -27,7 +27,7 @@ namespace {
using HlslGeneratorImplTest_Continue = TestHelper;
TEST_F(HlslGeneratorImplTest_Continue, Emit_Continue) {
ast::ContinueStatement c;
ast::ContinueStatement c(Source{});
gen.increment_indent();

View File

@ -24,7 +24,7 @@ namespace {
using HlslGeneratorImplTest_Discard = TestHelper;
TEST_F(HlslGeneratorImplTest_Discard, Emit_Discard) {
ast::DiscardStatement stmt;
ast::DiscardStatement stmt(Source{});
gen.increment_indent();

View File

@ -82,13 +82,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
@ -159,13 +161,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
@ -236,13 +240,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
@ -312,13 +318,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
@ -385,13 +393,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
@ -453,13 +463,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
@ -528,8 +540,9 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(depth_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::MemberAccessorExpression>(

View File

@ -55,7 +55,7 @@ using HlslGeneratorImplTest_Function = TestHelper;
TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", ast::VariableList{}, &void_type,
@ -75,7 +75,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("GeometryShader"), "GeometryShader",
@ -116,7 +116,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", params, &void_type, body,
@ -169,8 +169,9 @@ TEST_F(HlslGeneratorImplTest_Function,
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
@ -241,8 +242,9 @@ TEST_F(HlslGeneratorImplTest_Function,
mod.AddGlobalVariable(depth_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::MemberAccessorExpression>(
@ -317,8 +319,8 @@ TEST_F(HlslGeneratorImplTest_Function,
"x")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -394,8 +396,8 @@ TEST_F(HlslGeneratorImplTest_Function,
"x")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -473,8 +475,8 @@ TEST_F(HlslGeneratorImplTest_Function,
"b")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -548,8 +550,8 @@ TEST_F(HlslGeneratorImplTest_Function,
"b")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -621,7 +623,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f)));
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(assign);
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
@ -705,13 +707,15 @@ TEST_F(
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("val"),
"val"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("param"),
@ -729,8 +733,9 @@ TEST_F(
expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::CallExpression>(
@ -805,7 +810,7 @@ TEST_F(HlslGeneratorImplTest_Function,
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param"), "param")));
@ -819,8 +824,9 @@ TEST_F(HlslGeneratorImplTest_Function,
expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::CallExpression>(
@ -903,8 +909,9 @@ TEST_F(
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::MemberAccessorExpression>(
@ -926,8 +933,9 @@ TEST_F(
expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::CallExpression>(
@ -1001,7 +1009,7 @@ TEST_F(HlslGeneratorImplTest_Function,
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>(
Source{},
@ -1032,8 +1040,8 @@ TEST_F(HlslGeneratorImplTest_Function,
expr), // constructor
ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -1095,7 +1103,7 @@ TEST_F(HlslGeneratorImplTest_Function,
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>(
Source{},
@ -1126,8 +1134,8 @@ TEST_F(HlslGeneratorImplTest_Function,
expr), // constructor
ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -1176,14 +1184,15 @@ TEST_F(HlslGeneratorImplTest_Function,
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))));
auto* list = create<ast::BlockStatement>();
auto* list = create<ast::BlockStatement>(Source{});
list->append(create<ast::ReturnStatement>(Source{}));
body->append(create<ast::IfStatement>(
@ -1229,7 +1238,7 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("GeometryShader"), "GeometryShader",
ast::VariableList{}, &void_type, create<ast::BlockStatement>(),
ast::VariableList{}, &void_type, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
});
@ -1248,7 +1257,7 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::type::Void void_type;
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,
@ -1273,7 +1282,7 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::type::Void void_type;
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,
@ -1310,7 +1319,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", params, &void_type, body,
@ -1394,8 +1403,8 @@ TEST_F(HlslGeneratorImplTest_Function,
"d")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("a"), "a", params, &void_type, body,
@ -1423,8 +1432,8 @@ TEST_F(HlslGeneratorImplTest_Function,
"d")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("b"), "b", params, &void_type, body,

View File

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

View File

@ -34,10 +34,10 @@ namespace {
using HlslGeneratorImplTest_Loop = TestHelper;
TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>());
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::DiscardStatement>(Source{}));
ast::LoopStatement l(body, {});
ast::LoopStatement l(Source{}, body, {});
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &l)) << gen.error();
@ -48,13 +48,13 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
}
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>());
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::DiscardStatement>(Source{}));
auto* continuing = create<ast::BlockStatement>();
auto* continuing = create<ast::BlockStatement>(Source{});
continuing->append(create<ast::ReturnStatement>(Source{}));
ast::LoopStatement l(body, continuing);
ast::LoopStatement l(Source{}, body, continuing);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &l)) << gen.error();
@ -75,15 +75,15 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
ast::type::F32 f32;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>());
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::DiscardStatement>(Source{}));
auto* continuing = create<ast::BlockStatement>();
auto* continuing = create<ast::BlockStatement>(Source{});
continuing->append(create<ast::ReturnStatement>(Source{}));
auto* inner = create<ast::LoopStatement>(body, continuing);
auto* inner = create<ast::LoopStatement>(Source{}, body, continuing);
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(inner);
auto* lhs = create<ast::IdentifierExpression>(
@ -91,10 +91,10 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
continuing = create<ast::BlockStatement>();
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
continuing = create<ast::BlockStatement>(Source{});
continuing->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
ast::LoopStatement outer(body, continuing);
ast::LoopStatement outer(Source{}, body, continuing);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &outer)) << gen.error();
@ -157,9 +157,10 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
create<ast::FloatLiteral>(Source{}, &f32, 2.4)), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::VariableDeclStatement>(
Source{},
create<ast::Variable>(Source{}, // source
"other", // name
ast::StorageClass::kFunction, // storage_class
@ -173,10 +174,10 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
auto* continuing = create<ast::BlockStatement>(Source{});
continuing->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
ast::LoopStatement outer(body, continuing);
ast::LoopStatement outer(Source{}, body, continuing);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &outer)) << gen.error();

View File

@ -244,7 +244,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* rhs =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b");
ast::AssignmentStatement assign(lhs, rhs);
ast::AssignmentStatement assign(Source{}, lhs, rhs);
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(b_var);
@ -311,7 +311,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &mat,
ast::ExpressionList{});
ast::AssignmentStatement assign(lhs, rhs);
ast::AssignmentStatement assign(Source{}, lhs, rhs);
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
@ -730,7 +730,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
"b"));
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f));
ast::AssignmentStatement assign(lhs, rhs);
ast::AssignmentStatement assign(Source{}, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
@ -791,7 +791,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
ast::AssignmentStatement assign(lhs, rhs);
ast::AssignmentStatement assign(Source{}, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
@ -849,7 +849,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
"a"));
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
ast::AssignmentStatement assign(lhs, rhs);
ast::AssignmentStatement assign(Source{}, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
@ -973,7 +973,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
"b"));
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &fvec3, values);
ast::AssignmentStatement assign(lhs, rhs);
ast::AssignmentStatement assign(Source{}, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
@ -1408,7 +1408,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &fvec3, values);
ast::AssignmentStatement assign(lhs, rhs);
ast::AssignmentStatement assign(Source{}, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
@ -1500,7 +1500,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &i32, 1.f));
ast::AssignmentStatement assign(lhs, rhs);
ast::AssignmentStatement assign(Source{}, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();

View File

@ -31,18 +31,19 @@ namespace {
using HlslGeneratorImplTest_Switch = TestHelper;
TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
auto* def_body = create<ast::BlockStatement>();
def_body->append(create<ast::BreakStatement>());
auto* def = create<ast::CaseStatement>(def_body);
auto* def_body = create<ast::BlockStatement>(Source{});
def_body->append(create<ast::BreakStatement>(Source{}));
auto* def =
create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, def_body);
ast::type::I32 i32;
ast::CaseSelectorList case_val;
case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
auto* case_body = create<ast::BlockStatement>();
case_body->append(create<ast::BreakStatement>());
auto* case_body = create<ast::BlockStatement>(Source{});
case_body->append(create<ast::BreakStatement>(Source{}));
auto* case_stmt = create<ast::CaseStatement>(case_val, case_body);
auto* case_stmt = create<ast::CaseStatement>(Source{}, case_val, case_body);
ast::CaseStatementList body;
body.push_back(case_stmt);
@ -50,7 +51,7 @@ TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond");
ast::SwitchStatement s(cond, body);
ast::SwitchStatement s(Source{}, cond, body);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &s)) << gen.error();

View File

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

View File

@ -43,7 +43,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
@ -61,7 +61,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
@ -81,7 +81,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Array) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
@ -100,7 +100,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
@ -118,7 +118,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
@ -140,7 +140,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
ident, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
EXPECT_EQ(result(), R"(float a = initializer;
)");
@ -164,7 +164,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
zero_vec, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
EXPECT_EQ(result(), R"(float3 a = float3(0.0f);
)");
@ -188,7 +188,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
zero_mat, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
EXPECT_EQ(result(),
R"(float3x2 a = float3x2(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);

View File

@ -34,7 +34,7 @@ TEST_F(MslGeneratorImplTest, Emit_Assign) {
Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
ast::AssignmentStatement assign(lhs, rhs);
ast::AssignmentStatement assign(Source{}, lhs, rhs);
gen.increment_indent();

View File

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

View File

@ -29,7 +29,7 @@ namespace {
using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Break) {
ast::BreakStatement b;
ast::BreakStatement b(Source{});
gen.increment_indent();

View File

@ -38,9 +38,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::CallExpression call(Source{}, id, {});
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
mod.AddFunction(func);
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
@ -59,9 +60,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(Source{}, id, params);
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
mod.AddFunction(func);
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
@ -78,11 +80,13 @@ TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallStatement call(create<ast::CallExpression>(Source{}, id, params));
ast::CallStatement call(Source{},
create<ast::CallExpression>(Source{}, id, params));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
mod.AddFunction(func);
gen.increment_indent();

View File

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

View File

@ -29,7 +29,7 @@ namespace {
using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Continue) {
ast::ContinueStatement c;
ast::ContinueStatement c(Source{});
gen.increment_indent();

View File

@ -26,7 +26,7 @@ namespace {
using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Discard) {
ast::DiscardStatement stmt;
ast::DiscardStatement stmt(Source{});
gen.increment_indent();

View File

@ -81,13 +81,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
@ -155,13 +157,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
@ -229,13 +233,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
@ -302,13 +308,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
@ -373,13 +381,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
@ -439,13 +449,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
@ -512,8 +524,9 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::MemberAccessorExpression>(

View File

@ -58,7 +58,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Function) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", ast::VariableList{}, &void_type,
@ -80,7 +80,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function) {
TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("main"),
"main", ast::VariableList{}, &void_type,
@ -123,7 +123,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", params, &void_type, body,
@ -177,8 +177,9 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
@ -252,8 +253,9 @@ TEST_F(MslGeneratorImplTest,
mod.AddGlobalVariable(depth_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::MemberAccessorExpression>(
@ -328,8 +330,8 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
"x")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
@ -408,8 +410,8 @@ TEST_F(MslGeneratorImplTest,
"b")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
@ -493,8 +495,8 @@ TEST_F(MslGeneratorImplTest,
"b")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
@ -584,13 +586,15 @@ TEST_F(
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("val"),
"val"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("param"),
@ -608,8 +612,9 @@ TEST_F(
expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::CallExpression>(
@ -687,7 +692,7 @@ TEST_F(MslGeneratorImplTest,
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param"), "param")));
@ -701,8 +706,9 @@ TEST_F(MslGeneratorImplTest,
expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::CallExpression>(
@ -789,8 +795,9 @@ TEST_F(
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::MemberAccessorExpression>(
@ -812,8 +819,9 @@ TEST_F(
expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::CallExpression>(
@ -885,7 +893,7 @@ TEST_F(MslGeneratorImplTest,
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>(
Source{},
@ -916,8 +924,8 @@ TEST_F(MslGeneratorImplTest,
expr), // constructor
ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
@ -993,7 +1001,7 @@ TEST_F(MslGeneratorImplTest,
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>(
Source{},
@ -1024,8 +1032,8 @@ TEST_F(MslGeneratorImplTest,
expr), // constructor
ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
@ -1107,7 +1115,7 @@ TEST_F(MslGeneratorImplTest,
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>(
Source{},
@ -1138,8 +1146,8 @@ TEST_F(MslGeneratorImplTest,
expr), // constructor
ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
@ -1195,14 +1203,15 @@ TEST_F(MslGeneratorImplTest,
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))));
auto* list = create<ast::BlockStatement>();
auto* list = create<ast::BlockStatement>(Source{});
list->append(create<ast::ReturnStatement>(Source{}));
body->append(create<ast::IfStatement>(
@ -1251,7 +1260,7 @@ TEST_F(MslGeneratorImplTest,
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", ast::VariableList{},
&void_type, create<ast::BlockStatement>(),
&void_type, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
});
@ -1283,7 +1292,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
"my_func", params, &void_type, body,
@ -1371,8 +1380,8 @@ TEST_F(MslGeneratorImplTest,
"d")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
@ -1401,8 +1410,8 @@ TEST_F(MslGeneratorImplTest,
"d")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(

View File

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

View File

@ -36,10 +36,10 @@ namespace {
using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Loop) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>());
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::DiscardStatement>(Source{}));
ast::LoopStatement l(body, {});
ast::LoopStatement l(Source{}, body, {});
gen.increment_indent();
@ -51,13 +51,13 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
}
TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>());
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::DiscardStatement>(Source{}));
auto* continuing = create<ast::BlockStatement>();
auto* continuing = create<ast::BlockStatement>(Source{});
continuing->append(create<ast::ReturnStatement>(Source{}));
ast::LoopStatement l(body, continuing);
ast::LoopStatement l(Source{}, body, continuing);
gen.increment_indent();
@ -79,15 +79,15 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
ast::type::F32 f32;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>());
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::DiscardStatement>(Source{}));
auto* continuing = create<ast::BlockStatement>();
auto* continuing = create<ast::BlockStatement>(Source{});
continuing->append(create<ast::ReturnStatement>(Source{}));
auto* inner = create<ast::LoopStatement>(body, continuing);
auto* inner = create<ast::LoopStatement>(Source{}, body, continuing);
body = create<ast::BlockStatement>();
body = create<ast::BlockStatement>(Source{});
body->append(inner);
auto* lhs = create<ast::IdentifierExpression>(
@ -95,10 +95,10 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
continuing = create<ast::BlockStatement>();
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
continuing = create<ast::BlockStatement>(Source{});
continuing->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
ast::LoopStatement outer(body, continuing);
ast::LoopStatement outer(Source{}, body, continuing);
gen.increment_indent();
@ -162,9 +162,10 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
create<ast::FloatLiteral>(Source{}, &f32, 2.4)), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::VariableDeclStatement>(
Source{},
create<ast::Variable>(Source{}, // source
"other", // name
ast::StorageClass::kFunction, // storage_class
@ -178,12 +179,12 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
auto* continuing = create<ast::BlockStatement>(Source{});
continuing->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
gen.increment_indent();
ast::LoopStatement outer(body, continuing);
ast::LoopStatement outer(Source{}, body, continuing);
ASSERT_TRUE(gen.EmitStatement(&outer)) << gen.error();
EXPECT_EQ(gen.result(), R"( {

View File

@ -33,18 +33,19 @@ namespace {
using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Switch) {
auto* def_body = create<ast::BlockStatement>();
def_body->append(create<ast::BreakStatement>());
auto* def = create<ast::CaseStatement>(def_body);
auto* def_body = create<ast::BlockStatement>(Source{});
def_body->append(create<ast::BreakStatement>(Source{}));
auto* def =
create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, def_body);
ast::type::I32 i32;
ast::CaseSelectorList case_val;
case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
auto* case_body = create<ast::BlockStatement>();
case_body->append(create<ast::BreakStatement>());
auto* case_body = create<ast::BlockStatement>(Source{});
case_body->append(create<ast::BreakStatement>(Source{}));
auto* case_stmt = create<ast::CaseStatement>(case_val, case_body);
auto* case_stmt = create<ast::CaseStatement>(Source{}, case_val, case_body);
ast::CaseStatementList body;
body.push_back(case_stmt);
@ -52,7 +53,7 @@ TEST_F(MslGeneratorImplTest, Emit_Switch) {
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond");
ast::SwitchStatement s(cond, body);
ast::SwitchStatement s(Source{}, cond, body);
gen.increment_indent();

View File

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

View File

@ -51,7 +51,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent();
@ -70,7 +70,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent();
@ -91,7 +91,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent();
@ -123,7 +123,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent();
@ -145,7 +145,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent();
@ -165,7 +165,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent();
@ -184,7 +184,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent();
@ -206,7 +206,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) {
ident, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
EXPECT_EQ(gen.result(), R"(float a = initializer;
@ -230,7 +230,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) {
zero_vec, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(var);
ast::VariableDeclStatement stmt(Source{}, var);
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
EXPECT_EQ(gen.result(), R"(float3 a = float3(0.0f);

View File

@ -514,7 +514,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f));
ast::AssignmentStatement expr(lhs, rhs);
ast::AssignmentStatement expr(Source{}, lhs, rhs);
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -588,7 +588,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("a"),
"a"));
ast::AssignmentStatement expr(lhs, rhs);
ast::AssignmentStatement expr(Source{}, lhs, rhs);
td.RegisterVariableForTesting(&var);
td.RegisterVariableForTesting(&store);

View File

@ -52,7 +52,7 @@ TEST_F(BuilderTest, Assign_Var) {
auto* val = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f));
ast::AssignmentStatement assign(ident, val);
ast::AssignmentStatement assign(Source{}, ident, val);
td.RegisterVariableForTesting(&v);
@ -88,7 +88,7 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
ast::ExpressionList vals;
auto* val = create<ast::TypeConstructorExpression>(Source{}, &vec, vals);
ast::AssignmentStatement assign(ident, val);
ast::AssignmentStatement assign(Source{}, ident, val);
td.RegisterVariableForTesting(&v);
@ -138,6 +138,7 @@ TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
nullptr, ast::VariableDecorationList{});
ast::AssignmentStatement assign(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
"var"),
init);
@ -189,6 +190,7 @@ TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
nullptr, ast::VariableDecorationList{});
ast::AssignmentStatement assign(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
"var"),
init);
@ -248,7 +250,7 @@ TEST_F(BuilderTest, Assign_StructMember) {
auto* val = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 4.0f));
ast::AssignmentStatement assign(ident, val);
ast::AssignmentStatement assign(Source{}, ident, val);
td.RegisterVariableForTesting(&v);
@ -297,7 +299,7 @@ TEST_F(BuilderTest, Assign_Vector) {
auto* val = create<ast::TypeConstructorExpression>(Source{}, &vec3, vals);
ast::AssignmentStatement assign(ident, val);
ast::AssignmentStatement assign(Source{}, ident, val);
td.RegisterVariableForTesting(&v);
@ -342,7 +344,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByName) {
auto* val = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f));
ast::AssignmentStatement assign(ident, val);
ast::AssignmentStatement assign(Source{}, ident, val);
td.RegisterVariableForTesting(&v);
@ -391,7 +393,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
auto* val = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f));
ast::AssignmentStatement assign(ident, val);
ast::AssignmentStatement assign(Source{}, ident, val);
td.RegisterVariableForTesting(&v);

View File

@ -39,9 +39,10 @@ TEST_F(BuilderTest, Block) {
// 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.
ast::BlockStatement outer;
ast::BlockStatement outer(Source{});
outer.append(create<ast::VariableDeclStatement>(
Source{},
create<ast::Variable>(Source{}, // source
"var", // name
ast::StorageClass::kFunction, // storage_class
@ -50,13 +51,15 @@ TEST_F(BuilderTest, Block) {
nullptr, // constructor
ast::VariableDecorationList{}))); // decorations
outer.append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
"var"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))));
auto* inner = create<ast::BlockStatement>();
auto* inner = create<ast::BlockStatement>(Source{});
inner->append(create<ast::VariableDeclStatement>(
Source{},
create<ast::Variable>(Source{}, // source
"var", // name
ast::StorageClass::kFunction, // storage_class
@ -65,6 +68,7 @@ TEST_F(BuilderTest, Block) {
nullptr, // constructor
ast::VariableDecorationList{}))); // decorations
inner->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
"var"),
create<ast::ScalarConstructorExpression>(
@ -72,6 +76,7 @@ TEST_F(BuilderTest, Block) {
outer.append(inner);
outer.append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
"var"),
create<ast::ScalarConstructorExpression>(

View File

@ -61,7 +61,7 @@ TEST_F(BuilderTest, Expression_Call) {
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kAdd,
@ -73,7 +73,7 @@ TEST_F(BuilderTest, Expression_Call) {
func_params, &f32, body, ast::FunctionDecorationList{});
ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {},
&void_type, create<ast::BlockStatement>(),
&void_type, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ast::ExpressionList call_params;
@ -144,7 +144,7 @@ TEST_F(BuilderTest, Statement_Call) {
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kAdd,
@ -158,7 +158,7 @@ TEST_F(BuilderTest, Statement_Call) {
ast::FunctionDecorationList{});
ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {},
&void_type, create<ast::BlockStatement>(),
&void_type, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ast::ExpressionList call_params;
@ -167,10 +167,11 @@ TEST_F(BuilderTest, Statement_Call) {
call_params.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
ast::CallStatement expr(create<ast::CallExpression>(
ast::CallStatement expr(
Source{}, create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("a_func"),
"a_func"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a_func"), "a_func"),
call_params));
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();

View File

@ -27,7 +27,7 @@ namespace {
using BuilderTest = TestHelper;
TEST_F(BuilderTest, Discard) {
ast::DiscardStatement expr;
ast::DiscardStatement expr(Source{});
b.push_function(Function{});
EXPECT_EQ(b.GenerateStatement(&expr), 1u) << b.error();

View File

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

View File

@ -48,7 +48,7 @@ using BuilderTest = TestHelper;
TEST_F(BuilderTest, Function_Empty) {
ast::type::Void void_type;
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&void_type, create<ast::BlockStatement>(),
&void_type, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func));
@ -65,7 +65,7 @@ OpFunctionEnd
TEST_F(BuilderTest, Function_Terminator_Return) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
@ -96,7 +96,7 @@ TEST_F(BuilderTest, Function_Terminator_ReturnValue) {
ast::VariableDecorationList{}); // decorations
td.RegisterVariableForTesting(var_a);
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a")));
@ -126,8 +126,8 @@ OpFunctionEnd
TEST_F(BuilderTest, Function_Terminator_Discard) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>());
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::DiscardStatement>(Source{}));
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&void_type, body, ast::FunctionDecorationList{});
@ -166,7 +166,7 @@ TEST_F(BuilderTest, Function_WithParams) {
ast::VariableDecorationList{}), // decorations
};
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a")));
@ -196,7 +196,7 @@ OpFunctionEnd
TEST_F(BuilderTest, Function_WithBody) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ReturnStatement>(Source{}));
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
@ -216,7 +216,7 @@ OpFunctionEnd
TEST_F(BuilderTest, FunctionType) {
ast::type::Void void_type;
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&void_type, create<ast::BlockStatement>(),
&void_type, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func));
@ -228,10 +228,10 @@ TEST_F(BuilderTest, FunctionType) {
TEST_F(BuilderTest, FunctionType_DeDuplicate) {
ast::type::Void void_type;
ast::Function func1(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&void_type, create<ast::BlockStatement>(),
&void_type, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ast::Function func2(Source{}, mod->RegisterSymbol("b_func"), "b_func", {},
&void_type, create<ast::BlockStatement>(),
&void_type, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func1));
@ -309,8 +309,8 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
"d")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
@ -340,8 +340,8 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
"d")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::VariableDeclStatement>(Source{}, var));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(

View File

@ -48,7 +48,7 @@ TEST_F(BuilderTest, If_Empty) {
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
ast::IfStatement expr(Source{}, cond, create<ast::BlockStatement>(),
ast::IfStatement expr(Source{}, cond, create<ast::BlockStatement>(Source{}),
ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -84,8 +84,9 @@ TEST_F(BuilderTest, If_WithStatements) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
@ -139,15 +140,17 @@ TEST_F(BuilderTest, If_WithElse) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
auto* else_body = create<ast::BlockStatement>();
auto* else_body = create<ast::BlockStatement>(Source{});
else_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
@ -156,8 +159,9 @@ TEST_F(BuilderTest, If_WithElse) {
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
ast::IfStatement expr(Source{}, cond, body,
{create<ast::ElseStatement>(else_body)});
ast::IfStatement expr(
Source{}, cond, body,
{create<ast::ElseStatement>(Source{}, nullptr, else_body)});
td.RegisterVariableForTesting(var);
@ -207,15 +211,17 @@ TEST_F(BuilderTest, If_WithElseIf) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
auto* else_body = create<ast::BlockStatement>();
auto* else_body = create<ast::BlockStatement>(Source{});
else_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
@ -227,8 +233,9 @@ TEST_F(BuilderTest, If_WithElseIf) {
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
ast::IfStatement expr(Source{}, cond, body,
{create<ast::ElseStatement>(else_cond, else_body)});
ast::IfStatement expr(
Source{}, cond, body,
{create<ast::ElseStatement>(Source{}, else_cond, else_body)});
td.RegisterVariableForTesting(var);
@ -287,26 +294,30 @@ TEST_F(BuilderTest, If_WithMultiple) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
auto* elseif_1_body = create<ast::BlockStatement>();
auto* elseif_1_body = create<ast::BlockStatement>(Source{});
elseif_1_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))));
auto* elseif_2_body = create<ast::BlockStatement>();
auto* elseif_2_body = create<ast::BlockStatement>(Source{});
elseif_2_body->append(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>();
auto* else_body = create<ast::BlockStatement>(Source{});
else_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
@ -323,9 +334,9 @@ TEST_F(BuilderTest, If_WithMultiple) {
ast::IfStatement expr(
Source{}, cond, body,
{
create<ast::ElseStatement>(elseif_1_cond, elseif_1_body),
create<ast::ElseStatement>(elseif_2_cond, elseif_2_body),
create<ast::ElseStatement>(else_body),
create<ast::ElseStatement>(Source{}, elseif_1_cond, elseif_1_body),
create<ast::ElseStatement>(Source{}, elseif_2_cond, elseif_2_body),
create<ast::ElseStatement>(Source{}, nullptr, else_body),
});
td.RegisterVariableForTesting(var);
@ -387,16 +398,17 @@ TEST_F(BuilderTest, If_WithBreak) {
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* if_body = create<ast::BlockStatement>();
if_body->append(create<ast::BreakStatement>());
auto* if_body = create<ast::BlockStatement>(Source{});
if_body->append(create<ast::BreakStatement>(Source{}));
auto* if_stmt = create<ast::IfStatement>(Source{}, cond, if_body,
ast::ElseStatementList{});
auto* loop_body = create<ast::BlockStatement>();
auto* loop_body = create<ast::BlockStatement>(Source{});
loop_body->append(if_stmt);
ast::LoopStatement expr(loop_body, create<ast::BlockStatement>());
ast::LoopStatement expr(Source{}, loop_body,
create<ast::BlockStatement>(Source{}));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -435,17 +447,19 @@ TEST_F(BuilderTest, If_WithElseBreak) {
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::BreakStatement>());
auto* else_body = create<ast::BlockStatement>(Source{});
else_body->append(create<ast::BreakStatement>(Source{}));
auto* if_stmt = create<ast::IfStatement>(
Source{}, cond, create<ast::BlockStatement>(),
ast::ElseStatementList{create<ast::ElseStatement>(else_body)});
Source{}, cond, create<ast::BlockStatement>(Source{}),
ast::ElseStatementList{
create<ast::ElseStatement>(Source{}, nullptr, else_body)});
auto* loop_body = create<ast::BlockStatement>();
auto* loop_body = create<ast::BlockStatement>(Source{});
loop_body->append(if_stmt);
ast::LoopStatement expr(loop_body, create<ast::BlockStatement>());
ast::LoopStatement expr(Source{}, loop_body,
create<ast::BlockStatement>(Source{}));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -485,16 +499,17 @@ TEST_F(BuilderTest, If_WithContinue) {
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* if_body = create<ast::BlockStatement>();
if_body->append(create<ast::ContinueStatement>());
auto* if_body = create<ast::BlockStatement>(Source{});
if_body->append(create<ast::ContinueStatement>(Source{}));
auto* if_stmt = create<ast::IfStatement>(Source{}, cond, if_body,
ast::ElseStatementList{});
auto* loop_body = create<ast::BlockStatement>();
auto* loop_body = create<ast::BlockStatement>(Source{});
loop_body->append(if_stmt);
ast::LoopStatement expr(loop_body, create<ast::BlockStatement>());
ast::LoopStatement expr(Source{}, loop_body,
create<ast::BlockStatement>(Source{}));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -533,17 +548,19 @@ TEST_F(BuilderTest, If_WithElseContinue) {
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ContinueStatement>());
auto* else_body = create<ast::BlockStatement>(Source{});
else_body->append(create<ast::ContinueStatement>(Source{}));
auto* if_stmt = create<ast::IfStatement>(
Source{}, cond, create<ast::BlockStatement>(),
ast::ElseStatementList{create<ast::ElseStatement>(else_body)});
Source{}, cond, create<ast::BlockStatement>(Source{}),
ast::ElseStatementList{
create<ast::ElseStatement>(Source{}, nullptr, else_body)});
auto* loop_body = create<ast::BlockStatement>();
auto* loop_body = create<ast::BlockStatement>(Source{});
loop_body->append(if_stmt);
ast::LoopStatement expr(loop_body, create<ast::BlockStatement>());
ast::LoopStatement expr(Source{}, loop_body,
create<ast::BlockStatement>(Source{}));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -581,7 +598,7 @@ TEST_F(BuilderTest, If_WithReturn) {
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* if_body = create<ast::BlockStatement>();
auto* if_body = create<ast::BlockStatement>(Source{});
if_body->append(create<ast::ReturnStatement>(Source{}));
ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{});
@ -613,7 +630,7 @@ TEST_F(BuilderTest, If_WithReturnValue) {
auto* cond2 = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, false));
auto* if_body = create<ast::BlockStatement>();
auto* if_body = create<ast::BlockStatement>(Source{});
if_body->append(create<ast::ReturnStatement>(Source{}, cond2));
ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{});
@ -655,7 +672,7 @@ TEST_F(BuilderTest, If_WithLoad_Bug327) {
ast::IfStatement expr(Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a"),
create<ast::BlockStatement>(),
create<ast::BlockStatement>(Source{}),
ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();

View File

@ -472,7 +472,7 @@ TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
@ -506,7 +506,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -534,7 +534,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -588,7 +588,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -613,7 +613,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -640,7 +640,7 @@ TEST_F(IntrinsicBuilderTest, Call_Normalize) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -672,7 +672,7 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -701,7 +701,7 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -738,7 +738,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -764,7 +764,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -793,7 +793,7 @@ TEST_F(IntrinsicBuilderTest, Call_Cross) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -824,7 +824,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -854,7 +854,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -895,7 +895,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -923,7 +923,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -958,7 +958,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -986,7 +986,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1021,7 +1021,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1049,7 +1049,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1085,7 +1085,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1113,7 +1113,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1149,7 +1149,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1179,7 +1179,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1214,7 +1214,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Scalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1244,7 +1244,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Vector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1277,7 +1277,7 @@ TEST_F(IntrinsicBuilderTest, Call_Determinant) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1321,7 +1321,7 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1361,7 +1361,7 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength_OtherMembersInStruct) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -1407,7 +1407,7 @@ TEST_F(IntrinsicBuilderTest, DISABLED_Call_ArrayLength_Ptr) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
ty.void_, create<ast::BlockStatement>(),
ty.void_, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();

View File

@ -39,13 +39,13 @@ TEST_F(BuilderTest, Loop_Empty) {
// loop {
// }
ast::LoopStatement expr(create<ast::BlockStatement>(),
create<ast::BlockStatement>());
ast::LoopStatement loop(Source{}, create<ast::BlockStatement>(Source{}),
create<ast::BlockStatement>(Source{}));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
b.push_function(Function{});
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
EXPECT_TRUE(b.GenerateLoopStatement(&loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
R"(OpBranch %1
%1 = OpLabel
@ -74,22 +74,24 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
ast::LoopStatement expr(body, create<ast::BlockStatement>());
ast::LoopStatement loop(Source{}, body,
create<ast::BlockStatement>(Source{}));
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
EXPECT_TRUE(b.GenerateLoopStatement(&loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
@ -128,28 +130,30 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>();
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
auto* continuing = create<ast::BlockStatement>();
auto* continuing = create<ast::BlockStatement>(Source{});
continuing->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))));
ast::LoopStatement expr(body, continuing);
ast::LoopStatement loop(Source{}, body, continuing);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
EXPECT_TRUE(b.GenerateLoopStatement(&loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
@ -176,16 +180,17 @@ TEST_F(BuilderTest, Loop_WithContinue) {
// loop {
// continue;
// }
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ContinueStatement>());
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::ContinueStatement>(Source{}));
ast::LoopStatement expr(body, create<ast::BlockStatement>());
ast::LoopStatement loop(Source{}, body,
create<ast::BlockStatement>(Source{}));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
b.push_function(Function{});
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
EXPECT_TRUE(b.GenerateLoopStatement(&loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
R"(OpBranch %1
%1 = OpLabel
@ -203,16 +208,17 @@ TEST_F(BuilderTest, Loop_WithBreak) {
// loop {
// break;
// }
auto* body = create<ast::BlockStatement>();
body->append(create<ast::BreakStatement>());
auto* body = create<ast::BlockStatement>(Source{});
body->append(create<ast::BreakStatement>(Source{}));
ast::LoopStatement expr(body, create<ast::BlockStatement>());
ast::LoopStatement loop(Source{}, body,
create<ast::BlockStatement>(Source{}));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
b.push_function(Function{});
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
EXPECT_TRUE(b.GenerateLoopStatement(&loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
R"(OpBranch %1
%1 = OpLabel

View File

@ -47,7 +47,7 @@ TEST_F(BuilderTest, Switch_Empty) {
auto* cond = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1));
ast::SwitchStatement expr(cond, ast::CaseStatementList{});
ast::SwitchStatement expr(Source{}, cond, ast::CaseStatementList{});
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -93,15 +93,17 @@ TEST_F(BuilderTest, Switch_WithCase) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* case_1_body = create<ast::BlockStatement>();
auto* case_1_body = create<ast::BlockStatement>(Source{});
case_1_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
auto* case_2_body = create<ast::BlockStatement>();
auto* case_2_body = create<ast::BlockStatement>(Source{});
case_2_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
@ -114,10 +116,13 @@ TEST_F(BuilderTest, Switch_WithCase) {
selector_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 2));
ast::CaseStatementList cases;
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body));
cases.push_back(
create<ast::CaseStatement>(Source{}, selector_1, case_1_body));
cases.push_back(
create<ast::CaseStatement>(Source{}, selector_2, case_2_body));
ast::SwitchStatement expr(create<ast::IdentifierExpression>(
ast::SwitchStatement expr(Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a"),
cases);
@ -126,7 +131,7 @@ TEST_F(BuilderTest, Switch_WithCase) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&i32, create<ast::BlockStatement>(),
&i32, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
@ -190,17 +195,20 @@ TEST_F(BuilderTest, Switch_WithDefault) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* default_body = create<ast::BlockStatement>();
auto* default_body = create<ast::BlockStatement>(Source{});
default_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
ast::CaseStatementList cases;
cases.push_back(create<ast::CaseStatement>(default_body));
cases.push_back(create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{},
default_body));
ast::SwitchStatement expr(create<ast::IdentifierExpression>(
ast::SwitchStatement expr(Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a"),
cases);
@ -209,7 +217,7 @@ TEST_F(BuilderTest, Switch_WithDefault) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&i32, create<ast::BlockStatement>(),
&i32, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
@ -271,22 +279,25 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* case_1_body = create<ast::BlockStatement>();
auto* case_1_body = create<ast::BlockStatement>(Source{});
case_1_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
auto* case_2_body = create<ast::BlockStatement>();
auto* case_2_body = create<ast::BlockStatement>(Source{});
case_2_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
auto* default_body = create<ast::BlockStatement>();
auto* default_body = create<ast::BlockStatement>(Source{});
default_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
@ -300,11 +311,15 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
selector_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 3));
ast::CaseStatementList cases;
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body));
cases.push_back(create<ast::CaseStatement>(default_body));
cases.push_back(
create<ast::CaseStatement>(Source{}, selector_1, case_1_body));
cases.push_back(
create<ast::CaseStatement>(Source{}, selector_2, case_2_body));
cases.push_back(create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{},
default_body));
ast::SwitchStatement expr(create<ast::IdentifierExpression>(
ast::SwitchStatement expr(Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a"),
cases);
@ -313,7 +328,7 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&i32, create<ast::BlockStatement>(),
&i32, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
@ -384,23 +399,26 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* case_1_body = create<ast::BlockStatement>();
auto* case_1_body = create<ast::BlockStatement>(Source{});
case_1_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
case_1_body->append(create<ast::FallthroughStatement>());
case_1_body->append(create<ast::FallthroughStatement>(Source{}));
auto* case_2_body = create<ast::BlockStatement>();
auto* case_2_body = create<ast::BlockStatement>(Source{});
case_2_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
auto* default_body = create<ast::BlockStatement>();
auto* default_body = create<ast::BlockStatement>(Source{});
default_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
@ -413,11 +431,15 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
selector_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 2));
ast::CaseStatementList cases;
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body));
cases.push_back(create<ast::CaseStatement>(default_body));
cases.push_back(
create<ast::CaseStatement>(Source{}, selector_1, case_1_body));
cases.push_back(
create<ast::CaseStatement>(Source{}, selector_2, case_2_body));
cases.push_back(create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{},
default_body));
ast::SwitchStatement expr(create<ast::IdentifierExpression>(
ast::SwitchStatement expr(Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a"),
cases);
@ -426,7 +448,7 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&i32, create<ast::BlockStatement>(),
&i32, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
@ -493,21 +515,24 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* case_1_body = create<ast::BlockStatement>();
auto* case_1_body = create<ast::BlockStatement>(Source{});
case_1_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
case_1_body->append(create<ast::FallthroughStatement>());
case_1_body->append(create<ast::FallthroughStatement>(Source{}));
ast::CaseSelectorList selector_1;
selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
ast::CaseStatementList cases;
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
cases.push_back(
create<ast::CaseStatement>(Source{}, selector_1, case_1_body));
ast::SwitchStatement expr(create<ast::IdentifierExpression>(
ast::SwitchStatement expr(Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a"),
cases);
@ -516,7 +541,7 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&i32, create<ast::BlockStatement>(),
&i32, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
@ -556,10 +581,10 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* if_body = create<ast::BlockStatement>();
if_body->append(create<ast::BreakStatement>());
auto* if_body = create<ast::BlockStatement>(Source{});
if_body->append(create<ast::BreakStatement>(Source{}));
auto* case_1_body = create<ast::BlockStatement>();
auto* case_1_body = create<ast::BlockStatement>(Source{});
case_1_body->append(create<ast::IfStatement>(
Source{},
create<ast::ScalarConstructorExpression>(
@ -567,6 +592,7 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
if_body, ast::ElseStatementList{}));
case_1_body->append(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
"v"),
create<ast::ScalarConstructorExpression>(
@ -576,9 +602,11 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
ast::CaseStatementList cases;
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
cases.push_back(
create<ast::CaseStatement>(Source{}, selector_1, case_1_body));
ast::SwitchStatement expr(create<ast::IdentifierExpression>(
ast::SwitchStatement expr(Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("a"), "a"),
cases);
@ -587,7 +615,7 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
&i32, create<ast::BlockStatement>(),
&i32, create<ast::BlockStatement>(Source{}),
ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();

View File

@ -33,7 +33,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Assign) {
Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
ast::AssignmentStatement assign(lhs, rhs);
ast::AssignmentStatement assign(Source{}, lhs, rhs);
gen.increment_indent();

View File

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

View File

@ -28,7 +28,7 @@ namespace {
using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Break) {
ast::BreakStatement b;
ast::BreakStatement b(Source{});
gen.increment_indent();

Some files were not shown because too many files have changed in this diff Show More