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:
parent
1ff59cd0e2
commit
bbefff63a3
|
@ -22,9 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::AssignmentStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
AssignmentStatement::AssignmentStatement(Expression* lhs, Expression* rhs)
|
|
||||||
: Base(), lhs_(lhs), rhs_(rhs) {}
|
|
||||||
|
|
||||||
AssignmentStatement::AssignmentStatement(const Source& source,
|
AssignmentStatement::AssignmentStatement(const Source& source,
|
||||||
Expression* lhs,
|
Expression* lhs,
|
||||||
Expression* rhs)
|
Expression* rhs)
|
||||||
|
|
|
@ -28,10 +28,6 @@ namespace ast {
|
||||||
/// An assignment statement
|
/// An assignment statement
|
||||||
class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
|
class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
/// @param lhs the left side of the expression
|
|
||||||
/// @param rhs the right side of the expression
|
|
||||||
AssignmentStatement(Expression* lhs, Expression* rhs);
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the assignment statement source
|
/// @param source the assignment statement source
|
||||||
/// @param lhs the left side of the expression
|
/// @param lhs the left side of the expression
|
||||||
|
|
|
@ -29,7 +29,7 @@ TEST_F(AssignmentStatementTest, Creation) {
|
||||||
auto* rhs =
|
auto* rhs =
|
||||||
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "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.lhs(), lhs);
|
||||||
EXPECT_EQ(stmt.rhs(), rhs);
|
EXPECT_EQ(stmt.rhs(), rhs);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ TEST_F(AssignmentStatementTest, IsAssign) {
|
||||||
auto* rhs =
|
auto* rhs =
|
||||||
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
||||||
|
|
||||||
AssignmentStatement stmt(lhs, rhs);
|
AssignmentStatement stmt(Source{}, lhs, rhs);
|
||||||
EXPECT_TRUE(stmt.Is<AssignmentStatement>());
|
EXPECT_TRUE(stmt.Is<AssignmentStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ TEST_F(AssignmentStatementTest, IsValid) {
|
||||||
auto* rhs =
|
auto* rhs =
|
||||||
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
||||||
|
|
||||||
AssignmentStatement stmt(lhs, rhs);
|
AssignmentStatement stmt(Source{}, lhs, rhs);
|
||||||
EXPECT_TRUE(stmt.IsValid());
|
EXPECT_TRUE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ TEST_F(AssignmentStatementTest, IsValid_MissingLHS) {
|
||||||
auto* rhs =
|
auto* rhs =
|
||||||
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
||||||
|
|
||||||
AssignmentStatement stmt(nullptr, rhs);
|
AssignmentStatement stmt(Source{}, nullptr, rhs);
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ TEST_F(AssignmentStatementTest, IsValid_MissingRHS) {
|
||||||
auto* lhs =
|
auto* lhs =
|
||||||
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
|
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
|
||||||
|
|
||||||
AssignmentStatement stmt(lhs, nullptr);
|
AssignmentStatement stmt(Source{}, lhs, nullptr);
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ TEST_F(AssignmentStatementTest, IsValid_InvalidLHS) {
|
||||||
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
|
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
|
||||||
auto* rhs =
|
auto* rhs =
|
||||||
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
||||||
AssignmentStatement stmt(lhs, rhs);
|
AssignmentStatement stmt(Source{}, lhs, rhs);
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ TEST_F(AssignmentStatementTest, IsValid_InvalidRHS) {
|
||||||
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
|
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
|
||||||
auto* rhs =
|
auto* rhs =
|
||||||
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
|
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
|
||||||
AssignmentStatement stmt(lhs, rhs);
|
AssignmentStatement stmt(Source{}, lhs, rhs);
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ TEST_F(AssignmentStatementTest, ToStr) {
|
||||||
auto* rhs =
|
auto* rhs =
|
||||||
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
||||||
|
|
||||||
AssignmentStatement stmt(lhs, rhs);
|
AssignmentStatement stmt(Source{}, lhs, rhs);
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
stmt.to_str(out, 2);
|
stmt.to_str(out, 2);
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::BlockStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
BlockStatement::BlockStatement() : Base() {}
|
|
||||||
|
|
||||||
BlockStatement::BlockStatement(const Source& source) : Base(source) {}
|
BlockStatement::BlockStatement(const Source& source) : Base(source) {}
|
||||||
|
|
||||||
BlockStatement::BlockStatement(BlockStatement&&) = default;
|
BlockStatement::BlockStatement(BlockStatement&&) = default;
|
||||||
|
|
|
@ -27,8 +27,6 @@ namespace ast {
|
||||||
/// A block statement
|
/// A block statement
|
||||||
class BlockStatement : public Castable<BlockStatement, Statement> {
|
class BlockStatement : public Castable<BlockStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
BlockStatement();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the block statement source
|
/// @param source the block statement source
|
||||||
explicit BlockStatement(const Source& source);
|
explicit BlockStatement(const Source& source);
|
||||||
|
|
|
@ -28,10 +28,10 @@ namespace {
|
||||||
using BlockStatementTest = TestHelper;
|
using BlockStatementTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(BlockStatementTest, Creation) {
|
TEST_F(BlockStatementTest, Creation) {
|
||||||
auto* d = create<DiscardStatement>();
|
auto* d = create<DiscardStatement>(Source{});
|
||||||
auto* ptr = d;
|
auto* ptr = d;
|
||||||
|
|
||||||
BlockStatement b;
|
BlockStatement b(Source{});
|
||||||
b.append(d);
|
b.append(d);
|
||||||
|
|
||||||
ASSERT_EQ(b.size(), 1u);
|
ASSERT_EQ(b.size(), 1u);
|
||||||
|
@ -39,11 +39,11 @@ TEST_F(BlockStatementTest, Creation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BlockStatementTest, Creation_WithInsert) {
|
TEST_F(BlockStatementTest, Creation_WithInsert) {
|
||||||
auto* s1 = create<DiscardStatement>();
|
auto* s1 = create<DiscardStatement>(Source{});
|
||||||
auto* s2 = create<DiscardStatement>();
|
auto* s2 = create<DiscardStatement>(Source{});
|
||||||
auto* s3 = create<DiscardStatement>();
|
auto* s3 = create<DiscardStatement>(Source{});
|
||||||
|
|
||||||
BlockStatement b;
|
BlockStatement b(Source{});
|
||||||
b.insert(0, s1);
|
b.insert(0, s1);
|
||||||
b.insert(0, s2);
|
b.insert(0, s2);
|
||||||
b.insert(1, s3);
|
b.insert(1, s3);
|
||||||
|
@ -64,38 +64,39 @@ TEST_F(BlockStatementTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BlockStatementTest, IsBlock) {
|
TEST_F(BlockStatementTest, IsBlock) {
|
||||||
BlockStatement b;
|
BlockStatement b(Source{});
|
||||||
EXPECT_TRUE(b.Is<BlockStatement>());
|
EXPECT_TRUE(b.Is<BlockStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BlockStatementTest, IsValid) {
|
TEST_F(BlockStatementTest, IsValid) {
|
||||||
BlockStatement b;
|
BlockStatement b(Source{});
|
||||||
b.append(create<DiscardStatement>());
|
b.append(create<DiscardStatement>(Source{}));
|
||||||
EXPECT_TRUE(b.IsValid());
|
EXPECT_TRUE(b.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BlockStatementTest, IsValid_Empty) {
|
TEST_F(BlockStatementTest, IsValid_Empty) {
|
||||||
BlockStatement b;
|
BlockStatement b(Source{});
|
||||||
EXPECT_TRUE(b.IsValid());
|
EXPECT_TRUE(b.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BlockStatementTest, IsValid_NullBodyStatement) {
|
TEST_F(BlockStatementTest, IsValid_NullBodyStatement) {
|
||||||
BlockStatement b;
|
BlockStatement b(Source{});
|
||||||
b.append(create<DiscardStatement>());
|
b.append(create<DiscardStatement>(Source{}));
|
||||||
b.append(nullptr);
|
b.append(nullptr);
|
||||||
EXPECT_FALSE(b.IsValid());
|
EXPECT_FALSE(b.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BlockStatementTest, IsValid_InvalidBodyStatement) {
|
TEST_F(BlockStatementTest, IsValid_InvalidBodyStatement) {
|
||||||
BlockStatement b;
|
BlockStatement b(Source{});
|
||||||
b.append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
|
b.append(create<IfStatement>(Source{}, nullptr,
|
||||||
|
create<BlockStatement>(Source{}),
|
||||||
ElseStatementList{}));
|
ElseStatementList{}));
|
||||||
EXPECT_FALSE(b.IsValid());
|
EXPECT_FALSE(b.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BlockStatementTest, ToStr) {
|
TEST_F(BlockStatementTest, ToStr) {
|
||||||
BlockStatement b;
|
BlockStatement b(Source{});
|
||||||
b.append(create<DiscardStatement>());
|
b.append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
b.to_str(out, 2);
|
b.to_str(out, 2);
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::BreakStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
BreakStatement::BreakStatement() : Base() {}
|
|
||||||
|
|
||||||
BreakStatement::BreakStatement(const Source& source) : Base(source) {}
|
BreakStatement::BreakStatement(const Source& source) : Base(source) {}
|
||||||
|
|
||||||
BreakStatement::BreakStatement(BreakStatement&&) = default;
|
BreakStatement::BreakStatement(BreakStatement&&) = default;
|
||||||
|
|
|
@ -23,8 +23,6 @@ namespace ast {
|
||||||
/// An break statement
|
/// An break statement
|
||||||
class BreakStatement : public Castable<BreakStatement, Statement> {
|
class BreakStatement : public Castable<BreakStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
BreakStatement();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the break statement source
|
/// @param source the break statement source
|
||||||
explicit BreakStatement(const Source& source);
|
explicit BreakStatement(const Source& source);
|
||||||
|
|
|
@ -30,17 +30,17 @@ TEST_F(BreakStatementTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BreakStatementTest, IsBreak) {
|
TEST_F(BreakStatementTest, IsBreak) {
|
||||||
BreakStatement stmt;
|
BreakStatement stmt(Source{});
|
||||||
EXPECT_TRUE(stmt.Is<BreakStatement>());
|
EXPECT_TRUE(stmt.Is<BreakStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BreakStatementTest, IsValid) {
|
TEST_F(BreakStatementTest, IsValid) {
|
||||||
BreakStatement stmt;
|
BreakStatement stmt(Source{});
|
||||||
EXPECT_TRUE(stmt.IsValid());
|
EXPECT_TRUE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BreakStatementTest, ToStr) {
|
TEST_F(BreakStatementTest, ToStr) {
|
||||||
BreakStatement stmt;
|
BreakStatement stmt(Source{});
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
stmt.to_str(out, 2);
|
stmt.to_str(out, 2);
|
||||||
EXPECT_EQ(out.str(), R"( Break{}
|
EXPECT_EQ(out.str(), R"( Break{}
|
||||||
|
|
|
@ -23,14 +23,16 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::CallStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
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(CallStatement&&) = default;
|
||||||
|
|
||||||
CallStatement::~CallStatement() = default;
|
CallStatement::~CallStatement() = default;
|
||||||
|
|
||||||
CallStatement* CallStatement::Clone(CloneContext* ctx) const {
|
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 {
|
bool CallStatement::IsValid() const {
|
||||||
|
|
|
@ -28,8 +28,9 @@ namespace ast {
|
||||||
class CallStatement : public Castable<CallStatement, Statement> {
|
class CallStatement : public Castable<CallStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
|
/// @param source the input source for the statement
|
||||||
/// @param call the function
|
/// @param call the function
|
||||||
explicit CallStatement(CallExpression* call);
|
CallStatement(const Source& source, CallExpression* call);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
CallStatement(CallStatement&&);
|
CallStatement(CallStatement&&);
|
||||||
~CallStatement() override;
|
~CallStatement() override;
|
||||||
|
|
|
@ -31,17 +31,18 @@ TEST_F(CallStatementTest, Creation) {
|
||||||
Source{}, mod.RegisterSymbol("func"), "func"),
|
Source{}, mod.RegisterSymbol("func"), "func"),
|
||||||
ExpressionList{});
|
ExpressionList{});
|
||||||
|
|
||||||
CallStatement c(expr);
|
CallStatement c(Source{}, expr);
|
||||||
EXPECT_EQ(c.expr(), expr);
|
EXPECT_EQ(c.expr(), expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CallStatementTest, IsCall) {
|
TEST_F(CallStatementTest, IsCall) {
|
||||||
CallStatement c(nullptr);
|
CallStatement c(Source{}, nullptr);
|
||||||
EXPECT_TRUE(c.Is<CallStatement>());
|
EXPECT_TRUE(c.Is<CallStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CallStatementTest, IsValid) {
|
TEST_F(CallStatementTest, IsValid) {
|
||||||
CallStatement c(
|
CallStatement c(
|
||||||
|
Source{},
|
||||||
create<CallExpression>(Source{},
|
create<CallExpression>(Source{},
|
||||||
create<IdentifierExpression>(
|
create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("func"), "func"),
|
Source{}, mod.RegisterSymbol("func"), "func"),
|
||||||
|
@ -50,18 +51,19 @@ TEST_F(CallStatementTest, IsValid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CallStatementTest, IsValid_MissingExpr) {
|
TEST_F(CallStatementTest, IsValid_MissingExpr) {
|
||||||
CallStatement c(nullptr);
|
CallStatement c(Source{}, nullptr);
|
||||||
EXPECT_FALSE(c.IsValid());
|
EXPECT_FALSE(c.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CallStatementTest, IsValid_InvalidExpr) {
|
TEST_F(CallStatementTest, IsValid_InvalidExpr) {
|
||||||
CallExpression stmt(Source{}, nullptr, {});
|
CallExpression stmt(Source{}, nullptr, {});
|
||||||
CallStatement c(&stmt);
|
CallStatement c(Source{}, &stmt);
|
||||||
EXPECT_FALSE(c.IsValid());
|
EXPECT_FALSE(c.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CallStatementTest, ToStr) {
|
TEST_F(CallStatementTest, ToStr) {
|
||||||
CallStatement c(
|
CallStatement c(
|
||||||
|
Source{},
|
||||||
create<CallExpression>(Source{},
|
create<CallExpression>(Source{},
|
||||||
create<IdentifierExpression>(
|
create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("func"), "func"),
|
Source{}, mod.RegisterSymbol("func"), "func"),
|
||||||
|
|
|
@ -22,11 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::CaseStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
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,
|
CaseStatement::CaseStatement(const Source& source,
|
||||||
CaseSelectorList selectors,
|
CaseSelectorList selectors,
|
||||||
BlockStatement* body)
|
BlockStatement* body)
|
||||||
|
|
|
@ -33,14 +33,6 @@ using CaseSelectorList = std::vector<IntLiteral*>;
|
||||||
/// A case statement
|
/// A case statement
|
||||||
class CaseStatement : public Castable<CaseStatement, Statement> {
|
class CaseStatement : public Castable<CaseStatement, Statement> {
|
||||||
public:
|
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
|
/// Constructor
|
||||||
/// @param source the source information
|
/// @param source the source information
|
||||||
/// @param selectors the case selectors
|
/// @param selectors the case selectors
|
||||||
|
|
|
@ -35,11 +35,11 @@ TEST_F(CaseStatementTest, Creation_i32) {
|
||||||
auto* selector = create<SintLiteral>(Source{}, &i32, 2);
|
auto* selector = create<SintLiteral>(Source{}, &i32, 2);
|
||||||
b.push_back(selector);
|
b.push_back(selector);
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
auto* discard = create<DiscardStatement>();
|
auto* discard = create<DiscardStatement>(Source{});
|
||||||
body->append(discard);
|
body->append(discard);
|
||||||
|
|
||||||
CaseStatement c(b, body);
|
CaseStatement c(Source{}, b, body);
|
||||||
ASSERT_EQ(c.selectors().size(), 1u);
|
ASSERT_EQ(c.selectors().size(), 1u);
|
||||||
EXPECT_EQ(c.selectors()[0], selector);
|
EXPECT_EQ(c.selectors()[0], selector);
|
||||||
ASSERT_EQ(c.body()->size(), 1u);
|
ASSERT_EQ(c.body()->size(), 1u);
|
||||||
|
@ -53,11 +53,11 @@ TEST_F(CaseStatementTest, Creation_u32) {
|
||||||
auto* selector = create<SintLiteral>(Source{}, &u32, 2);
|
auto* selector = create<SintLiteral>(Source{}, &u32, 2);
|
||||||
b.push_back(selector);
|
b.push_back(selector);
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
auto* discard = create<DiscardStatement>();
|
auto* discard = create<DiscardStatement>(Source{});
|
||||||
body->append(discard);
|
body->append(discard);
|
||||||
|
|
||||||
CaseStatement c(b, body);
|
CaseStatement c(Source{}, b, body);
|
||||||
ASSERT_EQ(c.selectors().size(), 1u);
|
ASSERT_EQ(c.selectors().size(), 1u);
|
||||||
EXPECT_EQ(c.selectors()[0], selector);
|
EXPECT_EQ(c.selectors()[0], selector);
|
||||||
ASSERT_EQ(c.body()->size(), 1u);
|
ASSERT_EQ(c.body()->size(), 1u);
|
||||||
|
@ -69,8 +69,8 @@ TEST_F(CaseStatementTest, Creation_WithSource) {
|
||||||
CaseSelectorList b;
|
CaseSelectorList b;
|
||||||
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
|
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
CaseStatement c(Source{Source::Location{20, 2}}, b, body);
|
CaseStatement c(Source{Source::Location{20, 2}}, b, body);
|
||||||
auto src = c.source();
|
auto src = c.source();
|
||||||
|
@ -79,10 +79,10 @@ TEST_F(CaseStatementTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
|
TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
CaseStatement c(body);
|
CaseStatement c(Source{}, CaseSelectorList{}, body);
|
||||||
EXPECT_TRUE(c.IsDefault());
|
EXPECT_TRUE(c.IsDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,17 +91,19 @@ TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
|
||||||
CaseSelectorList b;
|
CaseSelectorList b;
|
||||||
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
|
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
CaseStatement c(b, create<BlockStatement>());
|
CaseStatement c(Source{}, b, create<BlockStatement>(Source{}));
|
||||||
EXPECT_FALSE(c.IsDefault());
|
EXPECT_FALSE(c.IsDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CaseStatementTest, IsCase) {
|
TEST_F(CaseStatementTest, IsCase) {
|
||||||
CaseStatement c(create<BlockStatement>());
|
CaseStatement c(Source{}, CaseSelectorList{},
|
||||||
|
create<BlockStatement>(Source{}));
|
||||||
EXPECT_TRUE(c.Is<CaseStatement>());
|
EXPECT_TRUE(c.Is<CaseStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CaseStatementTest, IsValid) {
|
TEST_F(CaseStatementTest, IsValid) {
|
||||||
CaseStatement c(create<BlockStatement>());
|
CaseStatement c(Source{}, CaseSelectorList{},
|
||||||
|
create<BlockStatement>(Source{}));
|
||||||
EXPECT_TRUE(c.IsValid());
|
EXPECT_TRUE(c.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,11 +112,11 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) {
|
||||||
CaseSelectorList b;
|
CaseSelectorList b;
|
||||||
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
|
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
body->append(nullptr);
|
body->append(nullptr);
|
||||||
|
|
||||||
CaseStatement c(b, body);
|
CaseStatement c(Source{}, b, body);
|
||||||
EXPECT_FALSE(c.IsValid());
|
EXPECT_FALSE(c.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,11 +125,12 @@ TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) {
|
||||||
CaseSelectorList b;
|
CaseSelectorList b;
|
||||||
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
|
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
|
body->append(create<IfStatement>(Source{}, nullptr,
|
||||||
|
create<BlockStatement>(Source{}),
|
||||||
ElseStatementList{}));
|
ElseStatementList{}));
|
||||||
|
|
||||||
CaseStatement c({b}, body);
|
CaseStatement c(Source{}, {b}, body);
|
||||||
EXPECT_FALSE(c.IsValid());
|
EXPECT_FALSE(c.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,9 +139,9 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) {
|
||||||
CaseSelectorList b;
|
CaseSelectorList b;
|
||||||
b.push_back(create<SintLiteral>(Source{}, &i32, -2));
|
b.push_back(create<SintLiteral>(Source{}, &i32, -2));
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
CaseStatement c({b}, body);
|
CaseStatement c(Source{}, {b}, body);
|
||||||
|
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
c.to_str(out, 2);
|
c.to_str(out, 2);
|
||||||
|
@ -153,9 +156,9 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) {
|
||||||
CaseSelectorList b;
|
CaseSelectorList b;
|
||||||
b.push_back(create<UintLiteral>(Source{}, &u32, 2));
|
b.push_back(create<UintLiteral>(Source{}, &u32, 2));
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
CaseStatement c({b}, body);
|
CaseStatement c(Source{}, {b}, body);
|
||||||
|
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
c.to_str(out, 2);
|
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, 1));
|
||||||
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
|
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
CaseStatement c(b, body);
|
CaseStatement c(Source{}, b, body);
|
||||||
|
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
c.to_str(out, 2);
|
c.to_str(out, 2);
|
||||||
|
@ -185,9 +188,9 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CaseStatementTest, ToStr_WithoutSelectors) {
|
TEST_F(CaseStatementTest, ToStr_WithoutSelectors) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
CaseStatement c(CaseSelectorList{}, body);
|
CaseStatement c(Source{}, CaseSelectorList{}, body);
|
||||||
|
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
c.to_str(out, 2);
|
c.to_str(out, 2);
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::ContinueStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
ContinueStatement::ContinueStatement() : Base() {}
|
|
||||||
|
|
||||||
ContinueStatement::ContinueStatement(const Source& source) : Base(source) {}
|
ContinueStatement::ContinueStatement(const Source& source) : Base(source) {}
|
||||||
|
|
||||||
ContinueStatement::ContinueStatement(ContinueStatement&&) = default;
|
ContinueStatement::ContinueStatement(ContinueStatement&&) = default;
|
||||||
|
|
|
@ -26,8 +26,6 @@ namespace ast {
|
||||||
/// An continue statement
|
/// An continue statement
|
||||||
class ContinueStatement : public Castable<ContinueStatement, Statement> {
|
class ContinueStatement : public Castable<ContinueStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
ContinueStatement();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the continue statement source
|
/// @param source the continue statement source
|
||||||
explicit ContinueStatement(const Source& source);
|
explicit ContinueStatement(const Source& source);
|
||||||
|
|
|
@ -30,17 +30,17 @@ TEST_F(ContinueStatementTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ContinueStatementTest, IsContinue) {
|
TEST_F(ContinueStatementTest, IsContinue) {
|
||||||
ContinueStatement stmt;
|
ContinueStatement stmt(Source{});
|
||||||
EXPECT_TRUE(stmt.Is<ContinueStatement>());
|
EXPECT_TRUE(stmt.Is<ContinueStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ContinueStatementTest, IsValid) {
|
TEST_F(ContinueStatementTest, IsValid) {
|
||||||
ContinueStatement stmt;
|
ContinueStatement stmt(Source{});
|
||||||
EXPECT_TRUE(stmt.IsValid());
|
EXPECT_TRUE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ContinueStatementTest, ToStr) {
|
TEST_F(ContinueStatementTest, ToStr) {
|
||||||
ContinueStatement stmt;
|
ContinueStatement stmt(Source{});
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
stmt.to_str(out, 2);
|
stmt.to_str(out, 2);
|
||||||
EXPECT_EQ(out.str(), R"( Continue{}
|
EXPECT_EQ(out.str(), R"( Continue{}
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::DiscardStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
DiscardStatement::DiscardStatement() : Base() {}
|
|
||||||
|
|
||||||
DiscardStatement::DiscardStatement(const Source& source) : Base(source) {}
|
DiscardStatement::DiscardStatement(const Source& source) : Base(source) {}
|
||||||
|
|
||||||
DiscardStatement::DiscardStatement(DiscardStatement&&) = default;
|
DiscardStatement::DiscardStatement(DiscardStatement&&) = default;
|
||||||
|
|
|
@ -23,8 +23,6 @@ namespace ast {
|
||||||
/// A discard statement
|
/// A discard statement
|
||||||
class DiscardStatement : public Castable<DiscardStatement, Statement> {
|
class DiscardStatement : public Castable<DiscardStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
DiscardStatement();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the discard statement source
|
/// @param source the discard statement source
|
||||||
explicit DiscardStatement(const Source& source);
|
explicit DiscardStatement(const Source& source);
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace {
|
||||||
using DiscardStatementTest = TestHelper;
|
using DiscardStatementTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(DiscardStatementTest, Creation) {
|
TEST_F(DiscardStatementTest, Creation) {
|
||||||
DiscardStatement stmt;
|
DiscardStatement stmt(Source{});
|
||||||
EXPECT_EQ(stmt.source().range.begin.line, 0u);
|
EXPECT_EQ(stmt.source().range.begin.line, 0u);
|
||||||
EXPECT_EQ(stmt.source().range.begin.column, 0u);
|
EXPECT_EQ(stmt.source().range.begin.column, 0u);
|
||||||
EXPECT_EQ(stmt.source().range.end.line, 0u);
|
EXPECT_EQ(stmt.source().range.end.line, 0u);
|
||||||
|
@ -42,17 +42,17 @@ TEST_F(DiscardStatementTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DiscardStatementTest, IsDiscard) {
|
TEST_F(DiscardStatementTest, IsDiscard) {
|
||||||
DiscardStatement stmt;
|
DiscardStatement stmt(Source{});
|
||||||
EXPECT_TRUE(stmt.Is<DiscardStatement>());
|
EXPECT_TRUE(stmt.Is<DiscardStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DiscardStatementTest, IsValid) {
|
TEST_F(DiscardStatementTest, IsValid) {
|
||||||
DiscardStatement stmt;
|
DiscardStatement stmt(Source{});
|
||||||
EXPECT_TRUE(stmt.IsValid());
|
EXPECT_TRUE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DiscardStatementTest, ToStr) {
|
TEST_F(DiscardStatementTest, ToStr) {
|
||||||
DiscardStatement stmt;
|
DiscardStatement stmt(Source{});
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
stmt.to_str(out, 2);
|
stmt.to_str(out, 2);
|
||||||
EXPECT_EQ(out.str(), R"( Discard{}
|
EXPECT_EQ(out.str(), R"( Discard{}
|
||||||
|
|
|
@ -22,14 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::ElseStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
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,
|
ElseStatement::ElseStatement(const Source& source,
|
||||||
Expression* condition,
|
Expression* condition,
|
||||||
BlockStatement* body)
|
BlockStatement* body)
|
||||||
|
|
|
@ -29,17 +29,6 @@ namespace ast {
|
||||||
/// An else statement
|
/// An else statement
|
||||||
class ElseStatement : public Castable<ElseStatement, Statement> {
|
class ElseStatement : public Castable<ElseStatement, Statement> {
|
||||||
public:
|
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
|
/// Constructor
|
||||||
/// @param source the source information
|
/// @param source the source information
|
||||||
/// @param condition the else condition
|
/// @param condition the else condition
|
||||||
|
|
|
@ -31,26 +31,27 @@ TEST_F(ElseStatementTest, Creation) {
|
||||||
type::Bool bool_type;
|
type::Bool bool_type;
|
||||||
auto* cond = create<ScalarConstructorExpression>(
|
auto* cond = create<ScalarConstructorExpression>(
|
||||||
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* discard = body->get(0);
|
auto* discard = body->get(0);
|
||||||
|
|
||||||
ElseStatement e(cond, body);
|
ElseStatement e(Source{}, cond, body);
|
||||||
EXPECT_EQ(e.condition(), cond);
|
EXPECT_EQ(e.condition(), cond);
|
||||||
ASSERT_EQ(e.body()->size(), 1u);
|
ASSERT_EQ(e.body()->size(), 1u);
|
||||||
EXPECT_EQ(e.body()->get(0), discard);
|
EXPECT_EQ(e.body()->get(0), discard);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, Creation_WithSource) {
|
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();
|
auto src = e.source();
|
||||||
EXPECT_EQ(src.range.begin.line, 20u);
|
EXPECT_EQ(src.range.begin.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, IsElse) {
|
TEST_F(ElseStatementTest, IsElse) {
|
||||||
ElseStatement e(create<BlockStatement>());
|
ElseStatement e(Source{}, nullptr, create<BlockStatement>(Source{}));
|
||||||
EXPECT_TRUE(e.Is<ElseStatement>());
|
EXPECT_TRUE(e.Is<ElseStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,49 +59,50 @@ TEST_F(ElseStatementTest, HasCondition) {
|
||||||
type::Bool bool_type;
|
type::Bool bool_type;
|
||||||
auto* cond = create<ScalarConstructorExpression>(
|
auto* cond = create<ScalarConstructorExpression>(
|
||||||
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
|
||||||
ElseStatement e(cond, create<BlockStatement>());
|
ElseStatement e(Source{}, cond, create<BlockStatement>(Source{}));
|
||||||
EXPECT_TRUE(e.HasCondition());
|
EXPECT_TRUE(e.HasCondition());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, HasContition_NullCondition) {
|
TEST_F(ElseStatementTest, HasContition_NullCondition) {
|
||||||
ElseStatement e(create<BlockStatement>());
|
ElseStatement e(Source{}, nullptr, create<BlockStatement>(Source{}));
|
||||||
EXPECT_FALSE(e.HasCondition());
|
EXPECT_FALSE(e.HasCondition());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, IsValid) {
|
TEST_F(ElseStatementTest, IsValid) {
|
||||||
ElseStatement e(create<BlockStatement>());
|
ElseStatement e(Source{}, nullptr, create<BlockStatement>(Source{}));
|
||||||
EXPECT_TRUE(e.IsValid());
|
EXPECT_TRUE(e.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, IsValid_WithBody) {
|
TEST_F(ElseStatementTest, IsValid_WithBody) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
ElseStatement e(body);
|
ElseStatement e(Source{}, nullptr, body);
|
||||||
EXPECT_TRUE(e.IsValid());
|
EXPECT_TRUE(e.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) {
|
TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
body->append(nullptr);
|
body->append(nullptr);
|
||||||
|
|
||||||
ElseStatement e(body);
|
ElseStatement e(Source{}, nullptr, body);
|
||||||
EXPECT_FALSE(e.IsValid());
|
EXPECT_FALSE(e.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
|
TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
|
||||||
auto* cond = create<ScalarConstructorExpression>(Source{}, nullptr);
|
auto* cond = create<ScalarConstructorExpression>(Source{}, nullptr);
|
||||||
ElseStatement e(cond, create<BlockStatement>());
|
ElseStatement e(Source{}, cond, create<BlockStatement>(Source{}));
|
||||||
EXPECT_FALSE(e.IsValid());
|
EXPECT_FALSE(e.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
|
TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
|
body->append(create<IfStatement>(Source{}, nullptr,
|
||||||
|
create<BlockStatement>(Source{}),
|
||||||
ElseStatementList{}));
|
ElseStatementList{}));
|
||||||
|
|
||||||
ElseStatement e(body);
|
ElseStatement e(Source{}, nullptr, body);
|
||||||
EXPECT_FALSE(e.IsValid());
|
EXPECT_FALSE(e.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,10 +110,10 @@ TEST_F(ElseStatementTest, ToStr) {
|
||||||
type::Bool bool_type;
|
type::Bool bool_type;
|
||||||
auto* cond = create<ScalarConstructorExpression>(
|
auto* cond = create<ScalarConstructorExpression>(
|
||||||
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
ElseStatement e(cond, body);
|
ElseStatement e(Source{}, cond, body);
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
e.to_str(out, 2);
|
e.to_str(out, 2);
|
||||||
EXPECT_EQ(out.str(), R"( Else{
|
EXPECT_EQ(out.str(), R"( Else{
|
||||||
|
@ -126,10 +128,10 @@ TEST_F(ElseStatementTest, ToStr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, ToStr_NoCondition) {
|
TEST_F(ElseStatementTest, ToStr_NoCondition) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
ElseStatement e(body);
|
ElseStatement e(Source{}, nullptr, body);
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
e.to_str(out, 2);
|
e.to_str(out, 2);
|
||||||
EXPECT_EQ(out.str(), R"( Else{
|
EXPECT_EQ(out.str(), R"( Else{
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::FallthroughStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
FallthroughStatement::FallthroughStatement() : Base() {}
|
|
||||||
|
|
||||||
FallthroughStatement::FallthroughStatement(const Source& source)
|
FallthroughStatement::FallthroughStatement(const Source& source)
|
||||||
: Base(source) {}
|
: Base(source) {}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,6 @@ namespace ast {
|
||||||
/// An fallthrough statement
|
/// An fallthrough statement
|
||||||
class FallthroughStatement : public Castable<FallthroughStatement, Statement> {
|
class FallthroughStatement : public Castable<FallthroughStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
FallthroughStatement();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the source information
|
/// @param source the source information
|
||||||
explicit FallthroughStatement(const Source& source);
|
explicit FallthroughStatement(const Source& source);
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace {
|
||||||
using FallthroughStatementTest = TestHelper;
|
using FallthroughStatementTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(FallthroughStatementTest, Creation) {
|
TEST_F(FallthroughStatementTest, Creation) {
|
||||||
FallthroughStatement stmt;
|
FallthroughStatement stmt(Source{});
|
||||||
EXPECT_EQ(stmt.source().range.begin.line, 0u);
|
EXPECT_EQ(stmt.source().range.begin.line, 0u);
|
||||||
EXPECT_EQ(stmt.source().range.begin.column, 0u);
|
EXPECT_EQ(stmt.source().range.begin.column, 0u);
|
||||||
EXPECT_EQ(stmt.source().range.end.line, 0u);
|
EXPECT_EQ(stmt.source().range.end.line, 0u);
|
||||||
|
@ -38,17 +38,17 @@ TEST_F(FallthroughStatementTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FallthroughStatementTest, IsFallthrough) {
|
TEST_F(FallthroughStatementTest, IsFallthrough) {
|
||||||
FallthroughStatement stmt;
|
FallthroughStatement stmt(Source{});
|
||||||
EXPECT_TRUE(stmt.Is<FallthroughStatement>());
|
EXPECT_TRUE(stmt.Is<FallthroughStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FallthroughStatementTest, IsValid) {
|
TEST_F(FallthroughStatementTest, IsValid) {
|
||||||
FallthroughStatement stmt;
|
FallthroughStatement stmt(Source{});
|
||||||
EXPECT_TRUE(stmt.IsValid());
|
EXPECT_TRUE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FallthroughStatementTest, ToStr) {
|
TEST_F(FallthroughStatementTest, ToStr) {
|
||||||
FallthroughStatement stmt;
|
FallthroughStatement stmt(Source{});
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
stmt.to_str(out, 2);
|
stmt.to_str(out, 2);
|
||||||
EXPECT_EQ(out.str(), R"( Fallthrough{}
|
EXPECT_EQ(out.str(), R"( Fallthrough{}
|
||||||
|
|
|
@ -44,7 +44,7 @@ TEST_F(FunctionTest, Creation) {
|
||||||
auto* var = params[0];
|
auto* var = params[0];
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", params, &void_type,
|
Function f(Source{}, func_sym, "func", params, &void_type,
|
||||||
create<BlockStatement>(), FunctionDecorationList{});
|
create<BlockStatement>(Source{}), FunctionDecorationList{});
|
||||||
EXPECT_EQ(f.symbol(), func_sym);
|
EXPECT_EQ(f.symbol(), func_sym);
|
||||||
EXPECT_EQ(f.name(), "func");
|
EXPECT_EQ(f.name(), "func");
|
||||||
ASSERT_EQ(f.params().size(), 1u);
|
ASSERT_EQ(f.params().size(), 1u);
|
||||||
|
@ -64,7 +64,8 @@ TEST_F(FunctionTest, Creation_WithSource) {
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{}));
|
||||||
|
|
||||||
Function f(Source{Source::Location{20, 2}}, func_sym, "func", params,
|
Function f(Source{Source::Location{20, 2}}, func_sym, "func", params,
|
||||||
&void_type, create<BlockStatement>(), FunctionDecorationList{});
|
&void_type, create<BlockStatement>(Source{}),
|
||||||
|
FunctionDecorationList{});
|
||||||
auto src = f.source();
|
auto src = f.source();
|
||||||
EXPECT_EQ(src.range.begin.line, 20u);
|
EXPECT_EQ(src.range.begin.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
|
@ -79,7 +80,7 @@ TEST_F(FunctionTest, AddDuplicateReferencedVariables) {
|
||||||
Variable v(Source{}, "var", StorageClass::kInput, &i32, false, nullptr,
|
Variable v(Source{}, "var", StorageClass::kInput, &i32, false, nullptr,
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
|
Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
|
||||||
create<BlockStatement>(), FunctionDecorationList{});
|
create<BlockStatement>(Source{}), FunctionDecorationList{});
|
||||||
|
|
||||||
f.add_referenced_module_variable(&v);
|
f.add_referenced_module_variable(&v);
|
||||||
ASSERT_EQ(f.referenced_module_variables().size(), 1u);
|
ASSERT_EQ(f.referenced_module_variables().size(), 1u);
|
||||||
|
@ -126,7 +127,7 @@ TEST_F(FunctionTest, GetReferenceLocations) {
|
||||||
});
|
});
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
|
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(loc1);
|
||||||
f.add_referenced_module_variable(builtin1);
|
f.add_referenced_module_variable(builtin1);
|
||||||
|
@ -173,7 +174,7 @@ TEST_F(FunctionTest, GetReferenceBuiltins) {
|
||||||
});
|
});
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
|
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(loc1);
|
||||||
f.add_referenced_module_variable(builtin1);
|
f.add_referenced_module_variable(builtin1);
|
||||||
|
@ -196,7 +197,7 @@ TEST_F(FunctionTest, AddDuplicateEntryPoints) {
|
||||||
auto main_sym = mod.RegisterSymbol("main");
|
auto main_sym = mod.RegisterSymbol("main");
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
|
Function f(Source{}, func_sym, "func", VariableList{}, &void_type,
|
||||||
create<BlockStatement>(), FunctionDecorationList{});
|
create<BlockStatement>(Source{}), FunctionDecorationList{});
|
||||||
|
|
||||||
f.add_ancestor_entry_point(main_sym);
|
f.add_ancestor_entry_point(main_sym);
|
||||||
ASSERT_EQ(1u, f.ancestor_entry_points().size());
|
ASSERT_EQ(1u, f.ancestor_entry_points().size());
|
||||||
|
@ -218,8 +219,8 @@ TEST_F(FunctionTest, IsValid) {
|
||||||
false, nullptr,
|
false, nullptr,
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{}));
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", params, &void_type, body,
|
Function f(Source{}, func_sym, "func", params, &void_type, body,
|
||||||
FunctionDecorationList{});
|
FunctionDecorationList{});
|
||||||
|
@ -237,8 +238,8 @@ TEST_F(FunctionTest, IsValid_InvalidName) {
|
||||||
false, nullptr,
|
false, nullptr,
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{}));
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "", params, &void_type, body,
|
Function f(Source{}, func_sym, "", params, &void_type, body,
|
||||||
FunctionDecorationList{});
|
FunctionDecorationList{});
|
||||||
|
@ -256,7 +257,7 @@ TEST_F(FunctionTest, IsValid_MissingReturnType) {
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{}));
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", params, nullptr,
|
Function f(Source{}, func_sym, "func", params, nullptr,
|
||||||
create<BlockStatement>(), FunctionDecorationList{});
|
create<BlockStatement>(Source{}), FunctionDecorationList{});
|
||||||
EXPECT_FALSE(f.IsValid());
|
EXPECT_FALSE(f.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,7 +274,7 @@ TEST_F(FunctionTest, IsValid_NullParam) {
|
||||||
params.push_back(nullptr);
|
params.push_back(nullptr);
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", params, &void_type,
|
Function f(Source{}, func_sym, "func", params, &void_type,
|
||||||
create<BlockStatement>(), FunctionDecorationList{});
|
create<BlockStatement>(Source{}), FunctionDecorationList{});
|
||||||
EXPECT_FALSE(f.IsValid());
|
EXPECT_FALSE(f.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +289,7 @@ TEST_F(FunctionTest, IsValid_InvalidParam) {
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{}));
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", params, &void_type,
|
Function f(Source{}, func_sym, "func", params, &void_type,
|
||||||
create<BlockStatement>(), FunctionDecorationList{});
|
create<BlockStatement>(Source{}), FunctionDecorationList{});
|
||||||
EXPECT_FALSE(f.IsValid());
|
EXPECT_FALSE(f.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,8 +304,8 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) {
|
||||||
false, nullptr,
|
false, nullptr,
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{}));
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
body->append(nullptr);
|
body->append(nullptr);
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", params, &void_type, body,
|
Function f(Source{}, func_sym, "func", params, &void_type, body,
|
||||||
|
@ -324,8 +325,8 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) {
|
||||||
false, nullptr,
|
false, nullptr,
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{}));
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
body->append(nullptr);
|
body->append(nullptr);
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", params, &void_type, body,
|
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 func_sym = mod.RegisterSymbol("func");
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", {}, &void_type, body,
|
Function f(Source{}, func_sym, "func", {}, &void_type, body,
|
||||||
FunctionDecorationList{});
|
FunctionDecorationList{});
|
||||||
|
@ -361,8 +362,8 @@ TEST_F(FunctionTest, ToStr_WithDecoration) {
|
||||||
|
|
||||||
auto func_sym = mod.RegisterSymbol("func");
|
auto func_sym = mod.RegisterSymbol("func");
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
Function f(
|
Function f(
|
||||||
Source{}, func_sym, "func", {}, &void_type, body,
|
Source{}, func_sym, "func", {}, &void_type, body,
|
||||||
|
@ -390,8 +391,8 @@ TEST_F(FunctionTest, ToStr_WithParams) {
|
||||||
false, nullptr,
|
false, nullptr,
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{}));
|
||||||
|
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", params, &void_type, body,
|
Function f(Source{}, func_sym, "func", params, &void_type, body,
|
||||||
FunctionDecorationList{});
|
FunctionDecorationList{});
|
||||||
|
@ -418,7 +419,7 @@ TEST_F(FunctionTest, TypeName) {
|
||||||
auto func_sym = mod.RegisterSymbol("func");
|
auto func_sym = mod.RegisterSymbol("func");
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", {}, &void_type,
|
Function f(Source{}, func_sym, "func", {}, &void_type,
|
||||||
create<BlockStatement>(), FunctionDecorationList{});
|
create<BlockStatement>(Source{}), FunctionDecorationList{});
|
||||||
EXPECT_EQ(f.type_name(), "__func__void");
|
EXPECT_EQ(f.type_name(), "__func__void");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,7 +439,7 @@ TEST_F(FunctionTest, TypeName_WithParams) {
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{}));
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", params, &void_type,
|
Function f(Source{}, func_sym, "func", params, &void_type,
|
||||||
create<BlockStatement>(), FunctionDecorationList{});
|
create<BlockStatement>(Source{}), FunctionDecorationList{});
|
||||||
EXPECT_EQ(f.type_name(), "__func__void__i32__f32");
|
EXPECT_EQ(f.type_name(), "__func__void__i32__f32");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,8 +449,8 @@ TEST_F(FunctionTest, GetLastStatement) {
|
||||||
auto func_sym = mod.RegisterSymbol("func");
|
auto func_sym = mod.RegisterSymbol("func");
|
||||||
|
|
||||||
VariableList params;
|
VariableList params;
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
auto* stmt = create<DiscardStatement>();
|
auto* stmt = create<DiscardStatement>(Source{});
|
||||||
body->append(stmt);
|
body->append(stmt);
|
||||||
Function f(Source{}, func_sym, "func", params, &void_type, body,
|
Function f(Source{}, func_sym, "func", params, &void_type, body,
|
||||||
FunctionDecorationList{});
|
FunctionDecorationList{});
|
||||||
|
@ -463,7 +464,7 @@ TEST_F(FunctionTest, GetLastStatement_nullptr) {
|
||||||
auto func_sym = mod.RegisterSymbol("func");
|
auto func_sym = mod.RegisterSymbol("func");
|
||||||
|
|
||||||
VariableList params;
|
VariableList params;
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
Function f(Source{}, func_sym, "func", params, &void_type, body,
|
Function f(Source{}, func_sym, "func", params, &void_type, body,
|
||||||
FunctionDecorationList{});
|
FunctionDecorationList{});
|
||||||
|
|
||||||
|
@ -476,7 +477,7 @@ TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
|
||||||
auto func_sym = mod.RegisterSymbol("func");
|
auto func_sym = mod.RegisterSymbol("func");
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", {}, &void_type,
|
Function f(Source{}, func_sym, "func", {}, &void_type,
|
||||||
create<BlockStatement>(), FunctionDecorationList{});
|
create<BlockStatement>(Source{}), FunctionDecorationList{});
|
||||||
uint32_t x = 0;
|
uint32_t x = 0;
|
||||||
uint32_t y = 0;
|
uint32_t y = 0;
|
||||||
uint32_t z = 0;
|
uint32_t z = 0;
|
||||||
|
@ -492,7 +493,7 @@ TEST_F(FunctionTest, WorkgroupSize) {
|
||||||
auto func_sym = mod.RegisterSymbol("func");
|
auto func_sym = mod.RegisterSymbol("func");
|
||||||
|
|
||||||
Function f(Source{}, func_sym, "func", {}, &void_type,
|
Function f(Source{}, func_sym, "func", {}, &void_type,
|
||||||
create<BlockStatement>(),
|
create<BlockStatement>(Source{}),
|
||||||
{create<WorkgroupDecoration>(2u, 4u, 6u, Source{})});
|
{create<WorkgroupDecoration>(2u, 4u, 6u, Source{})});
|
||||||
|
|
||||||
uint32_t x = 0;
|
uint32_t x = 0;
|
||||||
|
|
|
@ -27,8 +27,8 @@ using IfStatementTest = TestHelper;
|
||||||
TEST_F(IfStatementTest, Creation) {
|
TEST_F(IfStatementTest, Creation) {
|
||||||
auto* cond = create<IdentifierExpression>(Source{},
|
auto* cond = create<IdentifierExpression>(Source{},
|
||||||
mod.RegisterSymbol("cond"), "cond");
|
mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
IfStatement stmt(Source{Source::Location{20, 2}}, cond, body,
|
IfStatement stmt(Source{Source::Location{20, 2}}, cond, body,
|
||||||
ElseStatementList{});
|
ElseStatementList{});
|
||||||
|
@ -38,7 +38,7 @@ TEST_F(IfStatementTest, Creation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(IfStatementTest, IsIf) {
|
TEST_F(IfStatementTest, IsIf) {
|
||||||
IfStatement stmt(Source{}, nullptr, create<BlockStatement>(),
|
IfStatement stmt(Source{}, nullptr, create<BlockStatement>(Source{}),
|
||||||
ElseStatementList{});
|
ElseStatementList{});
|
||||||
EXPECT_TRUE(stmt.Is<IfStatement>());
|
EXPECT_TRUE(stmt.Is<IfStatement>());
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@ TEST_F(IfStatementTest, IsIf) {
|
||||||
TEST_F(IfStatementTest, IsValid) {
|
TEST_F(IfStatementTest, IsValid) {
|
||||||
auto* cond = create<IdentifierExpression>(Source{},
|
auto* cond = create<IdentifierExpression>(Source{},
|
||||||
mod.RegisterSymbol("cond"), "cond");
|
mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
IfStatement stmt(Source{}, cond, body, ElseStatementList{});
|
IfStatement stmt(Source{}, cond, body, ElseStatementList{});
|
||||||
EXPECT_TRUE(stmt.IsValid());
|
EXPECT_TRUE(stmt.IsValid());
|
||||||
|
@ -56,23 +56,25 @@ TEST_F(IfStatementTest, IsValid) {
|
||||||
TEST_F(IfStatementTest, IsValid_WithElseStatements) {
|
TEST_F(IfStatementTest, IsValid_WithElseStatements) {
|
||||||
auto* cond = create<IdentifierExpression>(Source{},
|
auto* cond = create<IdentifierExpression>(Source{},
|
||||||
mod.RegisterSymbol("cond"), "cond");
|
mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
IfStatement stmt(Source{}, cond, body,
|
IfStatement stmt(Source{}, cond, body,
|
||||||
{
|
{
|
||||||
create<ElseStatement>(
|
create<ElseStatement>(
|
||||||
|
Source{},
|
||||||
create<IdentifierExpression>(
|
create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("Ident"), "Ident"),
|
Source{}, mod.RegisterSymbol("Ident"), "Ident"),
|
||||||
create<BlockStatement>()),
|
create<BlockStatement>(Source{})),
|
||||||
create<ElseStatement>(create<BlockStatement>()),
|
create<ElseStatement>(Source{}, nullptr,
|
||||||
|
create<BlockStatement>(Source{})),
|
||||||
});
|
});
|
||||||
EXPECT_TRUE(stmt.IsValid());
|
EXPECT_TRUE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(IfStatementTest, IsValid_MissingCondition) {
|
TEST_F(IfStatementTest, IsValid_MissingCondition) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
IfStatement stmt(Source{}, nullptr, body, ElseStatementList{});
|
IfStatement stmt(Source{}, nullptr, body, ElseStatementList{});
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
|
@ -81,8 +83,8 @@ TEST_F(IfStatementTest, IsValid_MissingCondition) {
|
||||||
TEST_F(IfStatementTest, IsValid_InvalidCondition) {
|
TEST_F(IfStatementTest, IsValid_InvalidCondition) {
|
||||||
auto* cond =
|
auto* cond =
|
||||||
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
|
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
IfStatement stmt(Source{}, cond, body, ElseStatementList{});
|
IfStatement stmt(Source{}, cond, body, ElseStatementList{});
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
|
@ -91,8 +93,8 @@ TEST_F(IfStatementTest, IsValid_InvalidCondition) {
|
||||||
TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
|
TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
|
||||||
auto* cond = create<IdentifierExpression>(Source{},
|
auto* cond = create<IdentifierExpression>(Source{},
|
||||||
mod.RegisterSymbol("cond"), "cond");
|
mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
body->append(nullptr);
|
body->append(nullptr);
|
||||||
|
|
||||||
IfStatement stmt(Source{}, cond, body, ElseStatementList{});
|
IfStatement stmt(Source{}, cond, body, ElseStatementList{});
|
||||||
|
@ -102,9 +104,10 @@ TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
|
||||||
TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
|
TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
|
||||||
auto* cond = create<IdentifierExpression>(Source{},
|
auto* cond = create<IdentifierExpression>(Source{},
|
||||||
mod.RegisterSymbol("cond"), "cond");
|
mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
|
body->append(create<IfStatement>(Source{}, nullptr,
|
||||||
|
create<BlockStatement>(Source{}),
|
||||||
ast::ElseStatementList{}));
|
ast::ElseStatementList{}));
|
||||||
|
|
||||||
IfStatement stmt(Source{}, cond, body, ElseStatementList{});
|
IfStatement stmt(Source{}, cond, body, ElseStatementList{});
|
||||||
|
@ -114,16 +117,18 @@ TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
|
||||||
TEST_F(IfStatementTest, IsValid_NullElseStatement) {
|
TEST_F(IfStatementTest, IsValid_NullElseStatement) {
|
||||||
auto* cond = create<IdentifierExpression>(Source{},
|
auto* cond = create<IdentifierExpression>(Source{},
|
||||||
mod.RegisterSymbol("cond"), "cond");
|
mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
IfStatement stmt(Source{}, cond, body,
|
IfStatement stmt(Source{}, cond, body,
|
||||||
{
|
{
|
||||||
create<ElseStatement>(
|
create<ElseStatement>(
|
||||||
|
Source{},
|
||||||
create<IdentifierExpression>(
|
create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("Ident"), "Ident"),
|
Source{}, mod.RegisterSymbol("Ident"), "Ident"),
|
||||||
create<BlockStatement>()),
|
create<BlockStatement>(Source{})),
|
||||||
create<ElseStatement>(create<BlockStatement>()),
|
create<ElseStatement>(Source{}, nullptr,
|
||||||
|
create<BlockStatement>(Source{})),
|
||||||
nullptr,
|
nullptr,
|
||||||
});
|
});
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
|
@ -132,15 +137,16 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) {
|
||||||
TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
|
TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
|
||||||
auto* cond = create<IdentifierExpression>(Source{},
|
auto* cond = create<IdentifierExpression>(Source{},
|
||||||
mod.RegisterSymbol("cond"), "cond");
|
mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
IfStatement stmt(
|
IfStatement stmt(
|
||||||
Source{}, cond, body,
|
Source{}, cond, body,
|
||||||
{
|
{
|
||||||
create<ElseStatement>(create<IdentifierExpression>(
|
create<ElseStatement>(Source{},
|
||||||
|
create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol(""), ""),
|
Source{}, mod.RegisterSymbol(""), ""),
|
||||||
create<BlockStatement>()),
|
create<BlockStatement>(Source{})),
|
||||||
});
|
});
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
@ -148,13 +154,15 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
|
||||||
TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
|
TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
|
||||||
auto* cond = create<IdentifierExpression>(Source{},
|
auto* cond = create<IdentifierExpression>(Source{},
|
||||||
mod.RegisterSymbol("cond"), "cond");
|
mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
IfStatement stmt(Source{}, cond, body,
|
IfStatement stmt(Source{}, cond, body,
|
||||||
{
|
{
|
||||||
create<ElseStatement>(create<BlockStatement>()),
|
create<ElseStatement>(Source{}, nullptr,
|
||||||
create<ElseStatement>(create<BlockStatement>()),
|
create<BlockStatement>(Source{})),
|
||||||
|
create<ElseStatement>(Source{}, nullptr,
|
||||||
|
create<BlockStatement>(Source{})),
|
||||||
});
|
});
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
@ -162,16 +170,18 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
|
||||||
TEST_F(IfStatementTest, IsValid_ElseNotLast) {
|
TEST_F(IfStatementTest, IsValid_ElseNotLast) {
|
||||||
auto* cond = create<IdentifierExpression>(Source{},
|
auto* cond = create<IdentifierExpression>(Source{},
|
||||||
mod.RegisterSymbol("cond"), "cond");
|
mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
IfStatement stmt(Source{}, cond, body,
|
IfStatement stmt(Source{}, cond, body,
|
||||||
{
|
{
|
||||||
create<ElseStatement>(create<BlockStatement>()),
|
create<ElseStatement>(Source{}, nullptr,
|
||||||
|
create<BlockStatement>(Source{})),
|
||||||
create<ElseStatement>(
|
create<ElseStatement>(
|
||||||
|
Source{},
|
||||||
create<IdentifierExpression>(
|
create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("ident"), "ident"),
|
Source{}, mod.RegisterSymbol("ident"), "ident"),
|
||||||
create<BlockStatement>()),
|
create<BlockStatement>(Source{})),
|
||||||
});
|
});
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
@ -179,8 +189,8 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) {
|
||||||
TEST_F(IfStatementTest, ToStr) {
|
TEST_F(IfStatementTest, ToStr) {
|
||||||
auto* cond = create<IdentifierExpression>(Source{},
|
auto* cond = create<IdentifierExpression>(Source{},
|
||||||
mod.RegisterSymbol("cond"), "cond");
|
mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
IfStatement stmt(Source{}, cond, body, ElseStatementList{});
|
IfStatement stmt(Source{}, cond, body, ElseStatementList{});
|
||||||
|
|
||||||
|
@ -200,23 +210,24 @@ TEST_F(IfStatementTest, ToStr) {
|
||||||
TEST_F(IfStatementTest, ToStr_WithElseStatements) {
|
TEST_F(IfStatementTest, ToStr_WithElseStatements) {
|
||||||
auto* cond = create<IdentifierExpression>(Source{},
|
auto* cond = create<IdentifierExpression>(Source{},
|
||||||
mod.RegisterSymbol("cond"), "cond");
|
mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* else_if_body = create<BlockStatement>();
|
auto* else_if_body = create<BlockStatement>(Source{});
|
||||||
else_if_body->append(create<DiscardStatement>());
|
else_if_body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* else_body = create<BlockStatement>();
|
auto* else_body = create<BlockStatement>(Source{});
|
||||||
else_body->append(create<DiscardStatement>());
|
else_body->append(create<DiscardStatement>(Source{}));
|
||||||
else_body->append(create<DiscardStatement>());
|
else_body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
IfStatement stmt(Source{}, cond, body,
|
IfStatement stmt(Source{}, cond, body,
|
||||||
{
|
{
|
||||||
create<ElseStatement>(
|
create<ElseStatement>(
|
||||||
|
Source{},
|
||||||
create<IdentifierExpression>(
|
create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("ident"), "ident"),
|
Source{}, mod.RegisterSymbol("ident"), "ident"),
|
||||||
else_if_body),
|
else_if_body),
|
||||||
create<ElseStatement>(else_body),
|
create<ElseStatement>(Source{}, nullptr, else_body),
|
||||||
});
|
});
|
||||||
|
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
|
|
|
@ -22,9 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::LoopStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
LoopStatement::LoopStatement(BlockStatement* body, BlockStatement* continuing)
|
|
||||||
: Base(), body_(body), continuing_(continuing) {}
|
|
||||||
|
|
||||||
LoopStatement::LoopStatement(const Source& source,
|
LoopStatement::LoopStatement(const Source& source,
|
||||||
BlockStatement* body,
|
BlockStatement* body,
|
||||||
BlockStatement* continuing)
|
BlockStatement* continuing)
|
||||||
|
|
|
@ -27,10 +27,6 @@ namespace ast {
|
||||||
/// A loop statement
|
/// A loop statement
|
||||||
class LoopStatement : public Castable<LoopStatement, Statement> {
|
class LoopStatement : public Castable<LoopStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
/// @param body the body statements
|
|
||||||
/// @param continuing the continuing statements
|
|
||||||
LoopStatement(BlockStatement* body, BlockStatement* continuing);
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the loop statement source
|
/// @param source the loop statement source
|
||||||
/// @param body the body statements
|
/// @param body the body statements
|
||||||
|
|
|
@ -28,14 +28,14 @@ namespace {
|
||||||
using LoopStatementTest = TestHelper;
|
using LoopStatementTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, Creation) {
|
TEST_F(LoopStatementTest, Creation) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
auto* b = body->last();
|
auto* b = body->last();
|
||||||
|
|
||||||
auto* continuing = create<BlockStatement>();
|
auto* continuing = create<BlockStatement>(Source{});
|
||||||
continuing->append(create<DiscardStatement>());
|
continuing->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
LoopStatement l(body, continuing);
|
LoopStatement l(Source{}, body, continuing);
|
||||||
ASSERT_EQ(l.body()->size(), 1u);
|
ASSERT_EQ(l.body()->size(), 1u);
|
||||||
EXPECT_EQ(l.body()->get(0), b);
|
EXPECT_EQ(l.body()->get(0), b);
|
||||||
ASSERT_EQ(l.continuing()->size(), 1u);
|
ASSERT_EQ(l.continuing()->size(), 1u);
|
||||||
|
@ -43,11 +43,11 @@ TEST_F(LoopStatementTest, Creation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, Creation_WithSource) {
|
TEST_F(LoopStatementTest, Creation_WithSource) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* continuing = create<BlockStatement>();
|
auto* continuing = create<BlockStatement>(Source{});
|
||||||
continuing->append(create<DiscardStatement>());
|
continuing->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
LoopStatement l(Source{Source::Location{20, 2}}, body, continuing);
|
LoopStatement l(Source{Source::Location{20, 2}}, body, continuing);
|
||||||
auto src = l.source();
|
auto src = l.source();
|
||||||
|
@ -56,108 +56,112 @@ TEST_F(LoopStatementTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, IsLoop) {
|
TEST_F(LoopStatementTest, IsLoop) {
|
||||||
LoopStatement l(create<BlockStatement>(), create<BlockStatement>());
|
LoopStatement l(Source{}, create<BlockStatement>(Source{}),
|
||||||
|
create<BlockStatement>(Source{}));
|
||||||
EXPECT_TRUE(l.Is<LoopStatement>());
|
EXPECT_TRUE(l.Is<LoopStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) {
|
TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
LoopStatement l(body, {});
|
LoopStatement l(Source{}, body, {});
|
||||||
EXPECT_FALSE(l.has_continuing());
|
EXPECT_FALSE(l.has_continuing());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, HasContinuing_WithContinuing) {
|
TEST_F(LoopStatementTest, HasContinuing_WithContinuing) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* continuing = create<BlockStatement>();
|
auto* continuing = create<BlockStatement>(Source{});
|
||||||
continuing->append(create<DiscardStatement>());
|
continuing->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
LoopStatement l(body, continuing);
|
LoopStatement l(Source{}, body, continuing);
|
||||||
EXPECT_TRUE(l.has_continuing());
|
EXPECT_TRUE(l.has_continuing());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, IsValid) {
|
TEST_F(LoopStatementTest, IsValid) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* continuing = create<BlockStatement>();
|
auto* continuing = create<BlockStatement>(Source{});
|
||||||
continuing->append(create<DiscardStatement>());
|
continuing->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
LoopStatement l(body, continuing);
|
LoopStatement l(Source{}, body, continuing);
|
||||||
EXPECT_TRUE(l.IsValid());
|
EXPECT_TRUE(l.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, IsValid_WithoutContinuing) {
|
TEST_F(LoopStatementTest, IsValid_WithoutContinuing) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
LoopStatement l(body, create<BlockStatement>());
|
LoopStatement l(Source{}, body, create<BlockStatement>(Source{}));
|
||||||
EXPECT_TRUE(l.IsValid());
|
EXPECT_TRUE(l.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, IsValid_WithoutBody) {
|
TEST_F(LoopStatementTest, IsValid_WithoutBody) {
|
||||||
LoopStatement l(create<BlockStatement>(), create<BlockStatement>());
|
LoopStatement l(Source{}, create<BlockStatement>(Source{}),
|
||||||
|
create<BlockStatement>(Source{}));
|
||||||
EXPECT_TRUE(l.IsValid());
|
EXPECT_TRUE(l.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, IsValid_NullBodyStatement) {
|
TEST_F(LoopStatementTest, IsValid_NullBodyStatement) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
body->append(nullptr);
|
body->append(nullptr);
|
||||||
|
|
||||||
auto* continuing = create<BlockStatement>();
|
auto* continuing = create<BlockStatement>(Source{});
|
||||||
continuing->append(create<DiscardStatement>());
|
continuing->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
LoopStatement l(body, continuing);
|
LoopStatement l(Source{}, body, continuing);
|
||||||
EXPECT_FALSE(l.IsValid());
|
EXPECT_FALSE(l.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) {
|
TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
|
body->append(create<IfStatement>(Source{}, nullptr,
|
||||||
|
create<BlockStatement>(Source{}),
|
||||||
ElseStatementList{}));
|
ElseStatementList{}));
|
||||||
|
|
||||||
auto* continuing = create<BlockStatement>();
|
auto* continuing = create<BlockStatement>(Source{});
|
||||||
continuing->append(create<DiscardStatement>());
|
continuing->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
LoopStatement l(body, continuing);
|
LoopStatement l(Source{}, body, continuing);
|
||||||
EXPECT_FALSE(l.IsValid());
|
EXPECT_FALSE(l.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) {
|
TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* continuing = create<BlockStatement>();
|
auto* continuing = create<BlockStatement>(Source{});
|
||||||
continuing->append(create<DiscardStatement>());
|
continuing->append(create<DiscardStatement>(Source{}));
|
||||||
continuing->append(nullptr);
|
continuing->append(nullptr);
|
||||||
|
|
||||||
LoopStatement l(body, continuing);
|
LoopStatement l(Source{}, body, continuing);
|
||||||
EXPECT_FALSE(l.IsValid());
|
EXPECT_FALSE(l.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) {
|
TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* continuing = create<BlockStatement>();
|
auto* continuing = create<BlockStatement>(Source{});
|
||||||
continuing->append(create<DiscardStatement>());
|
continuing->append(create<DiscardStatement>(Source{}));
|
||||||
continuing->append(create<IfStatement>(
|
continuing->append(create<IfStatement>(Source{}, nullptr,
|
||||||
Source{}, nullptr, create<BlockStatement>(), ElseStatementList{}));
|
create<BlockStatement>(Source{}),
|
||||||
|
ElseStatementList{}));
|
||||||
|
|
||||||
LoopStatement l(body, continuing);
|
LoopStatement l(Source{}, body, continuing);
|
||||||
EXPECT_FALSE(l.IsValid());
|
EXPECT_FALSE(l.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, ToStr) {
|
TEST_F(LoopStatementTest, ToStr) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
LoopStatement l(body, {});
|
LoopStatement l(Source{}, body, {});
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
l.to_str(out, 2);
|
l.to_str(out, 2);
|
||||||
EXPECT_EQ(out.str(), R"( Loop{
|
EXPECT_EQ(out.str(), R"( Loop{
|
||||||
|
@ -167,13 +171,13 @@ TEST_F(LoopStatementTest, ToStr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoopStatementTest, ToStr_WithContinuing) {
|
TEST_F(LoopStatementTest, ToStr_WithContinuing) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>(Source{});
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* continuing = create<BlockStatement>();
|
auto* continuing = create<BlockStatement>(Source{});
|
||||||
continuing->append(create<DiscardStatement>());
|
continuing->append(create<DiscardStatement>(Source{}));
|
||||||
|
|
||||||
LoopStatement l(body, continuing);
|
LoopStatement l(Source{}, body, continuing);
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
l.to_str(out, 2);
|
l.to_str(out, 2);
|
||||||
EXPECT_EQ(out.str(), R"( Loop{
|
EXPECT_EQ(out.str(), R"( Loop{
|
||||||
|
|
|
@ -49,9 +49,9 @@ TEST_F(ModuleTest, LookupFunction) {
|
||||||
Module m;
|
Module m;
|
||||||
|
|
||||||
auto func_sym = m.RegisterSymbol("main");
|
auto func_sym = m.RegisterSymbol("main");
|
||||||
auto* func =
|
auto* func = create<Function>(Source{}, func_sym, "main", VariableList{},
|
||||||
create<Function>(Source{}, func_sym, "main", VariableList{}, &f32,
|
&f32, create<BlockStatement>(Source{}),
|
||||||
create<BlockStatement>(), ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
m.AddFunction(func);
|
m.AddFunction(func);
|
||||||
EXPECT_EQ(func, m.FindFunctionBySymbol(func_sym));
|
EXPECT_EQ(func, m.FindFunctionBySymbol(func_sym));
|
||||||
}
|
}
|
||||||
|
@ -131,9 +131,9 @@ TEST_F(ModuleTest, IsValid_Function) {
|
||||||
|
|
||||||
Module m;
|
Module m;
|
||||||
|
|
||||||
auto* func = create<Function>(Source{}, m.RegisterSymbol("main"), "main",
|
auto* func = create<Function>(
|
||||||
VariableList(), &f32, create<BlockStatement>(),
|
Source{}, m.RegisterSymbol("main"), "main", VariableList(), &f32,
|
||||||
ast::FunctionDecorationList{});
|
create<BlockStatement>(Source{}), ast::FunctionDecorationList{});
|
||||||
m.AddFunction(func);
|
m.AddFunction(func);
|
||||||
EXPECT_TRUE(m.IsValid());
|
EXPECT_TRUE(m.IsValid());
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::Statement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
Statement::Statement() = default;
|
|
||||||
|
|
||||||
Statement::Statement(const Source& source) : Base(source) {}
|
Statement::Statement(const Source& source) : Base(source) {}
|
||||||
|
|
||||||
Statement::Statement(Statement&&) = default;
|
Statement::Statement(Statement&&) = default;
|
||||||
|
|
|
@ -32,8 +32,6 @@ class Statement : public Castable<Statement, Node> {
|
||||||
const char* Name() const;
|
const char* Name() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Constructor
|
|
||||||
Statement();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the source of the expression
|
/// @param source the source of the expression
|
||||||
explicit Statement(const Source& source);
|
explicit Statement(const Source& source);
|
||||||
|
|
|
@ -23,9 +23,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::SwitchStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
SwitchStatement::SwitchStatement(Expression* condition, CaseStatementList body)
|
|
||||||
: condition_(condition), body_(body) {}
|
|
||||||
|
|
||||||
SwitchStatement::SwitchStatement(const Source& source,
|
SwitchStatement::SwitchStatement(const Source& source,
|
||||||
Expression* condition,
|
Expression* condition,
|
||||||
CaseStatementList body)
|
CaseStatementList body)
|
||||||
|
|
|
@ -29,10 +29,6 @@ namespace ast {
|
||||||
/// A switch statement
|
/// A switch statement
|
||||||
class SwitchStatement : public Castable<SwitchStatement, Statement> {
|
class SwitchStatement : public Castable<SwitchStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
/// @param condition the switch condition
|
|
||||||
/// @param body the switch body
|
|
||||||
SwitchStatement(Expression* condition, CaseStatementList body);
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the source information
|
/// @param source the source information
|
||||||
/// @param condition the switch condition
|
/// @param condition the switch condition
|
||||||
|
|
|
@ -37,10 +37,11 @@ TEST_F(SwitchStatementTest, Creation) {
|
||||||
auto* ident = create<IdentifierExpression>(
|
auto* ident = create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("ident"), "ident");
|
Source{}, mod.RegisterSymbol("ident"), "ident");
|
||||||
CaseStatementList body;
|
CaseStatementList body;
|
||||||
auto* case_stmt = create<CaseStatement>(lit, create<BlockStatement>());
|
auto* case_stmt =
|
||||||
|
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{}));
|
||||||
body.push_back(case_stmt);
|
body.push_back(case_stmt);
|
||||||
|
|
||||||
SwitchStatement stmt(ident, body);
|
SwitchStatement stmt(Source{}, ident, body);
|
||||||
EXPECT_EQ(stmt.condition(), ident);
|
EXPECT_EQ(stmt.condition(), ident);
|
||||||
ASSERT_EQ(stmt.body().size(), 1u);
|
ASSERT_EQ(stmt.body().size(), 1u);
|
||||||
EXPECT_EQ(stmt.body()[0], case_stmt);
|
EXPECT_EQ(stmt.body()[0], case_stmt);
|
||||||
|
@ -66,9 +67,10 @@ TEST_F(SwitchStatementTest, IsSwitch) {
|
||||||
auto* ident = create<IdentifierExpression>(
|
auto* ident = create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("ident"), "ident");
|
Source{}, mod.RegisterSymbol("ident"), "ident");
|
||||||
CaseStatementList body;
|
CaseStatementList body;
|
||||||
body.push_back(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>());
|
EXPECT_TRUE(stmt.Is<SwitchStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,9 +83,10 @@ TEST_F(SwitchStatementTest, IsValid) {
|
||||||
auto* ident = create<IdentifierExpression>(
|
auto* ident = create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("ident"), "ident");
|
Source{}, mod.RegisterSymbol("ident"), "ident");
|
||||||
CaseStatementList body;
|
CaseStatementList body;
|
||||||
body.push_back(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());
|
EXPECT_TRUE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +97,10 @@ TEST_F(SwitchStatementTest, IsValid_Null_Condition) {
|
||||||
lit.push_back(create<SintLiteral>(Source{}, &i32, 2));
|
lit.push_back(create<SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
CaseStatementList body;
|
CaseStatementList body;
|
||||||
body.push_back(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());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,9 +113,10 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) {
|
||||||
auto* ident =
|
auto* ident =
|
||||||
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
|
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
|
||||||
CaseStatementList body;
|
CaseStatementList body;
|
||||||
body.push_back(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());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,10 +129,11 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
|
||||||
auto* ident = create<IdentifierExpression>(
|
auto* ident = create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("ident"), "ident");
|
Source{}, mod.RegisterSymbol("ident"), "ident");
|
||||||
CaseStatementList body;
|
CaseStatementList body;
|
||||||
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
|
body.push_back(
|
||||||
|
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
|
||||||
body.push_back(nullptr);
|
body.push_back(nullptr);
|
||||||
|
|
||||||
SwitchStatement stmt(ident, body);
|
SwitchStatement stmt(Source{}, ident, body);
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,13 +141,14 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) {
|
||||||
auto* ident = create<IdentifierExpression>(
|
auto* ident = create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("ident"), "ident");
|
Source{}, mod.RegisterSymbol("ident"), "ident");
|
||||||
|
|
||||||
auto* case_body = create<BlockStatement>();
|
auto* case_body = create<BlockStatement>(Source{});
|
||||||
case_body->append(nullptr);
|
case_body->append(nullptr);
|
||||||
|
|
||||||
CaseStatementList body;
|
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());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +156,7 @@ TEST_F(SwitchStatementTest, ToStr_Empty) {
|
||||||
auto* ident = create<IdentifierExpression>(
|
auto* ident = create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("ident"), "ident");
|
Source{}, mod.RegisterSymbol("ident"), "ident");
|
||||||
|
|
||||||
SwitchStatement stmt(ident, {});
|
SwitchStatement stmt(Source{}, ident, {});
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
stmt.to_str(out, 2);
|
stmt.to_str(out, 2);
|
||||||
EXPECT_EQ(demangle(out.str()), R"( Switch{
|
EXPECT_EQ(demangle(out.str()), R"( Switch{
|
||||||
|
@ -169,9 +176,10 @@ TEST_F(SwitchStatementTest, ToStr) {
|
||||||
auto* ident = create<IdentifierExpression>(
|
auto* ident = create<IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("ident"), "ident");
|
Source{}, mod.RegisterSymbol("ident"), "ident");
|
||||||
CaseStatementList body;
|
CaseStatementList body;
|
||||||
body.push_back(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;
|
std::ostringstream out;
|
||||||
stmt.to_str(out, 2);
|
stmt.to_str(out, 2);
|
||||||
EXPECT_EQ(demangle(out.str()), R"( Switch{
|
EXPECT_EQ(demangle(out.str()), R"( Switch{
|
||||||
|
|
|
@ -22,9 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::VariableDeclStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
VariableDeclStatement::VariableDeclStatement(Variable* variable)
|
|
||||||
: Base(), variable_(variable) {}
|
|
||||||
|
|
||||||
VariableDeclStatement::VariableDeclStatement(const Source& source,
|
VariableDeclStatement::VariableDeclStatement(const Source& source,
|
||||||
Variable* variable)
|
Variable* variable)
|
||||||
: Base(source), variable_(variable) {}
|
: Base(source), variable_(variable) {}
|
||||||
|
|
|
@ -29,9 +29,6 @@ namespace ast {
|
||||||
class VariableDeclStatement
|
class VariableDeclStatement
|
||||||
: public Castable<VariableDeclStatement, Statement> {
|
: public Castable<VariableDeclStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
/// @param variable the variable
|
|
||||||
explicit VariableDeclStatement(Variable* variable);
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the variable statement source
|
/// @param source the variable statement source
|
||||||
/// @param variable the variable
|
/// @param variable the variable
|
||||||
|
|
|
@ -29,7 +29,7 @@ TEST_F(VariableDeclStatementTest, Creation) {
|
||||||
auto* var = create<Variable>(Source{}, "a", StorageClass::kNone, &f32, false,
|
auto* var = create<Variable>(Source{}, "a", StorageClass::kNone, &f32, false,
|
||||||
nullptr, ast::VariableDecorationList{});
|
nullptr, ast::VariableDecorationList{});
|
||||||
|
|
||||||
VariableDeclStatement stmt(var);
|
VariableDeclStatement stmt(Source{}, var);
|
||||||
EXPECT_EQ(stmt.variable(), var);
|
EXPECT_EQ(stmt.variable(), var);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,15 +49,15 @@ TEST_F(VariableDeclStatementTest, IsVariableDecl) {
|
||||||
auto* var = create<Variable>(Source{}, "a", StorageClass::kNone, &f32, false,
|
auto* var = create<Variable>(Source{}, "a", StorageClass::kNone, &f32, false,
|
||||||
nullptr, ast::VariableDecorationList{});
|
nullptr, ast::VariableDecorationList{});
|
||||||
|
|
||||||
VariableDeclStatement s(var);
|
VariableDeclStatement stmt(Source{}, var);
|
||||||
EXPECT_TRUE(s.Is<VariableDeclStatement>());
|
EXPECT_TRUE(stmt.Is<VariableDeclStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(VariableDeclStatementTest, IsValid) {
|
TEST_F(VariableDeclStatementTest, IsValid) {
|
||||||
type::F32 f32;
|
type::F32 f32;
|
||||||
auto* var = create<Variable>(Source{}, "a", StorageClass::kNone, &f32, false,
|
auto* var = create<Variable>(Source{}, "a", StorageClass::kNone, &f32, false,
|
||||||
nullptr, ast::VariableDecorationList{});
|
nullptr, ast::VariableDecorationList{});
|
||||||
VariableDeclStatement stmt(var);
|
VariableDeclStatement stmt(Source{}, var);
|
||||||
EXPECT_TRUE(stmt.IsValid());
|
EXPECT_TRUE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,12 +65,12 @@ TEST_F(VariableDeclStatementTest, IsValid_InvalidVariable) {
|
||||||
type::F32 f32;
|
type::F32 f32;
|
||||||
auto* var = create<Variable>(Source{}, "", StorageClass::kNone, &f32, false,
|
auto* var = create<Variable>(Source{}, "", StorageClass::kNone, &f32, false,
|
||||||
nullptr, ast::VariableDecorationList{});
|
nullptr, ast::VariableDecorationList{});
|
||||||
VariableDeclStatement stmt(var);
|
VariableDeclStatement stmt(Source{}, var);
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(VariableDeclStatementTest, IsValid_NullVariable) {
|
TEST_F(VariableDeclStatementTest, IsValid_NullVariable) {
|
||||||
VariableDeclStatement stmt(nullptr);
|
VariableDeclStatement stmt(Source{}, nullptr);
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ class InspectorHelper {
|
||||||
ast::Function* MakeEmptyBodyFunction(
|
ast::Function* MakeEmptyBodyFunction(
|
||||||
std::string name,
|
std::string name,
|
||||||
ast::FunctionDecorationList decorations = {}) {
|
ast::FunctionDecorationList decorations = {}) {
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
return create<ast::Function>(Source{}, mod()->RegisterSymbol(name), name,
|
return create<ast::Function>(Source{}, mod()->RegisterSymbol(name), name,
|
||||||
ast::VariableList(), void_type(), body,
|
ast::VariableList(), void_type(), body,
|
||||||
|
@ -97,12 +97,12 @@ class InspectorHelper {
|
||||||
std::string caller,
|
std::string caller,
|
||||||
std::string callee,
|
std::string callee,
|
||||||
ast::FunctionDecorationList decorations = {}) {
|
ast::FunctionDecorationList decorations = {}) {
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
auto* ident_expr = create<ast::IdentifierExpression>(
|
auto* ident_expr = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod()->RegisterSymbol(callee), callee);
|
Source{}, mod()->RegisterSymbol(callee), callee);
|
||||||
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
|
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
|
||||||
ast::ExpressionList());
|
ast::ExpressionList());
|
||||||
body->append(create<ast::CallStatement>(call_expr));
|
body->append(create<ast::CallStatement>(Source{}, call_expr));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
return create<ast::Function>(Source{}, mod()->RegisterSymbol(caller),
|
return create<ast::Function>(Source{}, mod()->RegisterSymbol(caller),
|
||||||
caller, ast::VariableList(), void_type(), body,
|
caller, ast::VariableList(), void_type(), body,
|
||||||
|
@ -148,11 +148,12 @@ class InspectorHelper {
|
||||||
std::string name,
|
std::string name,
|
||||||
std::vector<std::tuple<std::string, std::string>> inout_vars,
|
std::vector<std::tuple<std::string, std::string>> inout_vars,
|
||||||
ast::FunctionDecorationList decorations = {}) {
|
ast::FunctionDecorationList decorations = {}) {
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
for (auto inout : inout_vars) {
|
for (auto inout : inout_vars) {
|
||||||
std::string in, out;
|
std::string in, out;
|
||||||
std::tie(in, out) = inout;
|
std::tie(in, out) = inout;
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{},
|
create<ast::IdentifierExpression>(Source{},
|
||||||
mod()->RegisterSymbol(out), out),
|
mod()->RegisterSymbol(out), out),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod()->RegisterSymbol(in),
|
create<ast::IdentifierExpression>(Source{}, mod()->RegisterSymbol(in),
|
||||||
|
@ -177,11 +178,12 @@ class InspectorHelper {
|
||||||
std::string callee,
|
std::string callee,
|
||||||
std::vector<std::tuple<std::string, std::string>> inout_vars,
|
std::vector<std::tuple<std::string, std::string>> inout_vars,
|
||||||
ast::FunctionDecorationList decorations = {}) {
|
ast::FunctionDecorationList decorations = {}) {
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
for (auto inout : inout_vars) {
|
for (auto inout : inout_vars) {
|
||||||
std::string in, out;
|
std::string in, out;
|
||||||
std::tie(in, out) = inout;
|
std::tie(in, out) = inout;
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{},
|
create<ast::IdentifierExpression>(Source{},
|
||||||
mod()->RegisterSymbol(out), out),
|
mod()->RegisterSymbol(out), out),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod()->RegisterSymbol(in),
|
create<ast::IdentifierExpression>(Source{}, mod()->RegisterSymbol(in),
|
||||||
|
@ -191,7 +193,7 @@ class InspectorHelper {
|
||||||
Source{}, mod()->RegisterSymbol(callee), callee);
|
Source{}, mod()->RegisterSymbol(callee), callee);
|
||||||
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
|
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
|
||||||
ast::ExpressionList());
|
ast::ExpressionList());
|
||||||
body->append(create<ast::CallStatement>(call_expr));
|
body->append(create<ast::CallStatement>(Source{}, call_expr));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
return create<ast::Function>(Source{}, mod()->RegisterSymbol(caller),
|
return create<ast::Function>(Source{}, mod()->RegisterSymbol(caller),
|
||||||
caller, ast::VariableList(), void_type(), body,
|
caller, ast::VariableList(), void_type(), body,
|
||||||
|
@ -425,21 +427,22 @@ class InspectorHelper {
|
||||||
std::string func_name,
|
std::string func_name,
|
||||||
std::string struct_name,
|
std::string struct_name,
|
||||||
std::vector<std::tuple<size_t, ast::type::Type*>> members) {
|
std::vector<std::tuple<size_t, ast::type::Type*>> members) {
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
|
|
||||||
for (auto member : members) {
|
for (auto member : members) {
|
||||||
size_t member_idx;
|
size_t member_idx;
|
||||||
ast::type::Type* member_type;
|
ast::type::Type* member_type;
|
||||||
std::tie(member_idx, member_type) = member;
|
std::tie(member_idx, member_type) = member;
|
||||||
std::string member_name = StructMemberName(member_idx, member_type);
|
std::string member_name = StructMemberName(member_idx, member_type);
|
||||||
body->append(create<ast::VariableDeclStatement>(create<ast::Variable>(
|
body->append(create<ast::VariableDeclStatement>(
|
||||||
Source{}, // source
|
Source{}, create<ast::Variable>(
|
||||||
"local" + member_name, // name
|
Source{}, // source
|
||||||
ast::StorageClass::kNone, // storage_class
|
"local" + member_name, // name
|
||||||
member_type, // type
|
ast::StorageClass::kNone, // storage_class
|
||||||
false, // is_const
|
member_type, // type
|
||||||
nullptr, // constructor
|
false, // is_const
|
||||||
ast::VariableDecorationList{}))); // decorations
|
nullptr, // constructor
|
||||||
|
ast::VariableDecorationList{}))); // decorations
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto member : members) {
|
for (auto member : members) {
|
||||||
|
@ -448,10 +451,12 @@ class InspectorHelper {
|
||||||
std::tie(member_idx, member_type) = member;
|
std::tie(member_idx, member_type) = member;
|
||||||
std::string member_name = StructMemberName(member_idx, member_type);
|
std::string member_name = StructMemberName(member_idx, member_type);
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, mod()->RegisterSymbol("local" + member_name),
|
Source{}, mod()->RegisterSymbol("local" + member_name),
|
||||||
"local" + member_name),
|
"local" + member_name),
|
||||||
create<ast::MemberAccessorExpression>(Source{},
|
create<ast::MemberAccessorExpression>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, mod()->RegisterSymbol(struct_name), struct_name),
|
Source{}, mod()->RegisterSymbol(struct_name), struct_name),
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
|
@ -578,7 +583,7 @@ class InspectorHelper {
|
||||||
ast::FunctionDecorationList decorations = {}) {
|
ast::FunctionDecorationList decorations = {}) {
|
||||||
std::string result_name = "sampler_result";
|
std::string result_name = "sampler_result";
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
|
|
||||||
auto* call_result =
|
auto* call_result =
|
||||||
create<ast::Variable>(Source{}, // source
|
create<ast::Variable>(Source{}, // source
|
||||||
|
@ -588,7 +593,7 @@ class InspectorHelper {
|
||||||
false, // is_const
|
false, // is_const
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
body->append(create<ast::VariableDeclStatement>(call_result));
|
body->append(create<ast::VariableDeclStatement>(Source{}, call_result));
|
||||||
|
|
||||||
ast::ExpressionList call_params;
|
ast::ExpressionList call_params;
|
||||||
call_params.push_back(create<ast::IdentifierExpression>(
|
call_params.push_back(create<ast::IdentifierExpression>(
|
||||||
|
@ -604,6 +609,7 @@ class InspectorHelper {
|
||||||
call_params);
|
call_params);
|
||||||
|
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, mod()->RegisterSymbol("sampler_result"),
|
Source{}, mod()->RegisterSymbol("sampler_result"),
|
||||||
"sampler_result"),
|
"sampler_result"),
|
||||||
|
@ -634,7 +640,7 @@ class InspectorHelper {
|
||||||
ast::FunctionDecorationList decorations = {}) {
|
ast::FunctionDecorationList decorations = {}) {
|
||||||
std::string result_name = "sampler_result";
|
std::string result_name = "sampler_result";
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
|
|
||||||
auto* call_result =
|
auto* call_result =
|
||||||
create<ast::Variable>(Source{}, // source
|
create<ast::Variable>(Source{}, // source
|
||||||
|
@ -644,7 +650,7 @@ class InspectorHelper {
|
||||||
false, // is_const
|
false, // is_const
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
body->append(create<ast::VariableDeclStatement>(call_result));
|
body->append(create<ast::VariableDeclStatement>(Source{}, call_result));
|
||||||
|
|
||||||
ast::ExpressionList call_params;
|
ast::ExpressionList call_params;
|
||||||
call_params.push_back(create<ast::IdentifierExpression>(
|
call_params.push_back(create<ast::IdentifierExpression>(
|
||||||
|
@ -662,6 +668,7 @@ class InspectorHelper {
|
||||||
call_params);
|
call_params);
|
||||||
|
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, mod()->RegisterSymbol("sampler_result"),
|
Source{}, mod()->RegisterSymbol("sampler_result"),
|
||||||
"sampler_result"),
|
"sampler_result"),
|
||||||
|
@ -693,7 +700,7 @@ class InspectorHelper {
|
||||||
ast::FunctionDecorationList decorations = {}) {
|
ast::FunctionDecorationList decorations = {}) {
|
||||||
std::string result_name = "sampler_result";
|
std::string result_name = "sampler_result";
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
|
|
||||||
auto* call_result =
|
auto* call_result =
|
||||||
create<ast::Variable>(Source{}, // source
|
create<ast::Variable>(Source{}, // source
|
||||||
|
@ -703,7 +710,7 @@ class InspectorHelper {
|
||||||
false, // is_const
|
false, // is_const
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
body->append(create<ast::VariableDeclStatement>(call_result));
|
body->append(create<ast::VariableDeclStatement>(Source{}, call_result));
|
||||||
|
|
||||||
ast::ExpressionList call_params;
|
ast::ExpressionList call_params;
|
||||||
call_params.push_back(create<ast::IdentifierExpression>(
|
call_params.push_back(create<ast::IdentifierExpression>(
|
||||||
|
@ -722,6 +729,7 @@ class InspectorHelper {
|
||||||
call_params);
|
call_params);
|
||||||
|
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, mod()->RegisterSymbol("sampler_result"),
|
Source{}, mod()->RegisterSymbol("sampler_result"),
|
||||||
"sampler_result"),
|
"sampler_result"),
|
||||||
|
@ -1551,9 +1559,9 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
|
||||||
Source{}, mod()->RegisterSymbol(callee), callee);
|
Source{}, mod()->RegisterSymbol(callee), callee);
|
||||||
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
|
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
|
||||||
ast::ExpressionList());
|
ast::ExpressionList());
|
||||||
body->append(create<ast::CallStatement>(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_foo_func");
|
||||||
AddFuncCall(body, "ub_bar_func");
|
AddFuncCall(body, "ub_bar_func");
|
||||||
|
@ -1699,9 +1707,9 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
|
||||||
Source{}, mod()->RegisterSymbol(callee), callee);
|
Source{}, mod()->RegisterSymbol(callee), callee);
|
||||||
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
|
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
|
||||||
ast::ExpressionList());
|
ast::ExpressionList());
|
||||||
body->append(create<ast::CallStatement>(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_foo_func");
|
||||||
AddFuncCall(body, "sb_bar_func");
|
AddFuncCall(body, "sb_bar_func");
|
||||||
|
@ -1874,9 +1882,9 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
|
||||||
Source{}, mod()->RegisterSymbol(callee), callee);
|
Source{}, mod()->RegisterSymbol(callee), callee);
|
||||||
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
|
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
|
||||||
ast::ExpressionList());
|
ast::ExpressionList());
|
||||||
body->append(create<ast::CallStatement>(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_foo_func");
|
||||||
AddFuncCall(body, "sb_bar_func");
|
AddFuncCall(body, "sb_bar_func");
|
||||||
|
|
|
@ -667,7 +667,7 @@ void FunctionEmitter::PushNewStatementBlock(const Construct* construct,
|
||||||
ast::CaseStatementList* cases,
|
ast::CaseStatementList* cases,
|
||||||
CompletionAction action) {
|
CompletionAction action) {
|
||||||
if (block == nullptr) {
|
if (block == nullptr) {
|
||||||
block = create<ast::BlockStatement>();
|
block = create<ast::BlockStatement>(Source{});
|
||||||
}
|
}
|
||||||
|
|
||||||
statements_stack_.emplace_back(
|
statements_stack_.emplace_back(
|
||||||
|
@ -685,7 +685,7 @@ void FunctionEmitter::PushGuard(const std::string& guard_name,
|
||||||
|
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, ast_module_.RegisterSymbol(guard_name), guard_name);
|
Source{}, ast_module_.RegisterSymbol(guard_name), guard_name);
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
AddStatement(
|
AddStatement(
|
||||||
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
||||||
PushNewStatementBlock(top.construct_, end_id, body, nullptr, nullptr);
|
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();
|
const auto& top = statements_stack_.back();
|
||||||
|
|
||||||
auto* cond = MakeTrue(Source{});
|
auto* cond = MakeTrue(Source{});
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
AddStatement(
|
AddStatement(
|
||||||
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
||||||
PushNewStatementBlock(top.construct_, end_id, body, nullptr, nullptr);
|
PushNewStatementBlock(top.construct_, end_id, body, nullptr, nullptr);
|
||||||
|
@ -1865,7 +1865,7 @@ bool FunctionEmitter::EmitFunctionVariables() {
|
||||||
auto* var = parser_impl_.MakeVariable(
|
auto* var = parser_impl_.MakeVariable(
|
||||||
inst.result_id(), ast::StorageClass::kFunction, var_store_type, false,
|
inst.result_id(), ast::StorageClass::kFunction, var_store_type, false,
|
||||||
constructor, ast::VariableDecorationList{});
|
constructor, ast::VariableDecorationList{});
|
||||||
auto* var_decl_stmt = create<ast::VariableDeclStatement>(var);
|
auto* var_decl_stmt = create<ast::VariableDeclStatement>(Source{}, var);
|
||||||
AddStatement(var_decl_stmt);
|
AddStatement(var_decl_stmt);
|
||||||
// Save this as an already-named value.
|
// Save this as an already-named value.
|
||||||
identifier_values_.insert(inst.result_id());
|
identifier_values_.insert(inst.result_id());
|
||||||
|
@ -2145,14 +2145,14 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
|
||||||
false, // is_const
|
false, // is_const
|
||||||
MakeTrue(Source{}), // constructor
|
MakeTrue(Source{}), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
auto* guard_decl = create<ast::VariableDeclStatement>(guard_var);
|
auto* guard_decl = create<ast::VariableDeclStatement>(Source{}, guard_var);
|
||||||
AddStatement(guard_decl);
|
AddStatement(guard_decl);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto condition_id =
|
const auto condition_id =
|
||||||
block_info.basic_block->terminator()->GetSingleWordInOperand(0);
|
block_info.basic_block->terminator()->GetSingleWordInOperand(0);
|
||||||
auto* cond = MakeExpression(condition_id).expr;
|
auto* cond = MakeExpression(condition_id).expr;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
|
|
||||||
// Generate the code for the condition.
|
// Generate the code for the condition.
|
||||||
// Use the IfBuilder to create the if-statement. The IfBuilder is constructed
|
// 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.
|
// But make sure we do it in the right order.
|
||||||
auto push_else = [this, if_builder, else_end, construct]() {
|
auto push_else = [this, if_builder, else_end, construct]() {
|
||||||
// Push the else clause onto the stack first.
|
// Push the else clause onto the stack first.
|
||||||
auto* else_body = create<ast::BlockStatement>();
|
auto* else_body = create<ast::BlockStatement>(Source{});
|
||||||
PushNewStatementBlock(
|
PushNewStatementBlock(
|
||||||
construct, else_end, else_body, nullptr,
|
construct, else_end, else_body, nullptr,
|
||||||
[this, if_builder, else_body]() {
|
[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
|
// The "else" consists of the statement list from the top of
|
||||||
// statements stack, without an elseif condition.
|
// statements stack, without an elseif condition.
|
||||||
if_builder->else_stmts_.emplace_back(
|
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.
|
// First, push the statement block for the entire switch.
|
||||||
ast::CaseStatementList case_list;
|
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>();
|
AddStatement(swch)->As<ast::SwitchStatement>();
|
||||||
|
|
||||||
// Grab a pointer to the case list. It will get buried in the statement block
|
// 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
|
// Create the case clause. Temporarily put it in the wrong order
|
||||||
// on the case statement list.
|
// on the case statement list.
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
cases->emplace_back(create<ast::CaseStatement>(selectors, body));
|
cases->emplace_back(create<ast::CaseStatement>(Source{}, selectors, body));
|
||||||
|
|
||||||
PushNewStatementBlock(construct, end_id, body, nullptr, nullptr);
|
PushNewStatementBlock(construct, end_id, body, nullptr, nullptr);
|
||||||
|
|
||||||
if ((default_info == clause_heads[i]) && has_selectors &&
|
if ((default_info == clause_heads[i]) && has_selectors &&
|
||||||
construct->ContainsPos(default_info->pos)) {
|
construct->ContainsPos(default_info->pos)) {
|
||||||
// Generate a default clause with a just fallthrough.
|
// Generate a default clause with a just fallthrough.
|
||||||
auto* stmts = create<ast::BlockStatement>();
|
auto* stmts = create<ast::BlockStatement>(Source{});
|
||||||
stmts->append(create<ast::FallthroughStatement>());
|
stmts->append(create<ast::FallthroughStatement>(Source{}));
|
||||||
auto* case_stmt = create<ast::CaseStatement>(stmts);
|
auto* case_stmt =
|
||||||
|
create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, stmts);
|
||||||
cases->emplace_back(case_stmt);
|
cases->emplace_back(case_stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2396,8 +2397,9 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FunctionEmitter::EmitLoopStart(const Construct* construct) {
|
bool FunctionEmitter::EmitLoopStart(const Construct* construct) {
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
AddStatement(create<ast::LoopStatement>(body, create<ast::BlockStatement>()));
|
AddStatement(create<ast::LoopStatement>(
|
||||||
|
Source{}, body, create<ast::BlockStatement>(Source{})));
|
||||||
PushNewStatementBlock(construct, construct->end_id, body, nullptr, nullptr);
|
PushNewStatementBlock(construct, construct->end_id, body, nullptr, nullptr);
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
@ -2431,7 +2433,7 @@ bool FunctionEmitter::EmitNormalTerminator(const BlockInfo& block_info) {
|
||||||
case SpvOpKill:
|
case SpvOpKill:
|
||||||
// For now, assume SPIR-V OpKill has same semantics as WGSL discard.
|
// For now, assume SPIR-V OpKill has same semantics as WGSL discard.
|
||||||
// TODO(dneto): https://github.com/gpuweb/gpuweb/issues/676
|
// TODO(dneto): https://github.com/gpuweb/gpuweb/issues/676
|
||||||
AddStatement(create<ast::DiscardStatement>());
|
AddStatement(create<ast::DiscardStatement>(Source{}));
|
||||||
return true;
|
return true;
|
||||||
case SpvOpUnreachable:
|
case SpvOpUnreachable:
|
||||||
// Translate as if it's a return. This avoids the problem where WGSL
|
// Translate as if it's a return. This avoids the problem where WGSL
|
||||||
|
@ -2525,7 +2527,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
|
||||||
break;
|
break;
|
||||||
case EdgeKind::kSwitchBreak: {
|
case EdgeKind::kSwitchBreak: {
|
||||||
if (forced) {
|
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
|
// Unless forced, don't bother with a break at the end of a case/default
|
||||||
// clause.
|
// clause.
|
||||||
|
@ -2550,10 +2552,10 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// We need a break.
|
// We need a break.
|
||||||
return create<ast::BreakStatement>();
|
return create<ast::BreakStatement>(Source{});
|
||||||
}
|
}
|
||||||
case EdgeKind::kLoopBreak:
|
case EdgeKind::kLoopBreak:
|
||||||
return create<ast::BreakStatement>();
|
return create<ast::BreakStatement>(Source{});
|
||||||
case EdgeKind::kLoopContinue:
|
case EdgeKind::kLoopContinue:
|
||||||
// An unconditional continue to the next block is redundant and ugly.
|
// An unconditional continue to the next block is redundant and ugly.
|
||||||
// Skip it in that case.
|
// Skip it in that case.
|
||||||
|
@ -2561,7 +2563,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Otherwise, emit a regular continue statement.
|
// Otherwise, emit a regular continue statement.
|
||||||
return create<ast::ContinueStatement>();
|
return create<ast::ContinueStatement>(Source{});
|
||||||
case EdgeKind::kIfBreak: {
|
case EdgeKind::kIfBreak: {
|
||||||
const auto& flow_guard =
|
const auto& flow_guard =
|
||||||
GetBlockInfo(dest_info.header_for_merge)->flow_guard_name;
|
GetBlockInfo(dest_info.header_for_merge)->flow_guard_name;
|
||||||
|
@ -2571,6 +2573,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
|
||||||
}
|
}
|
||||||
// Signal an exit from the branch.
|
// Signal an exit from the branch.
|
||||||
return create<ast::AssignmentStatement>(
|
return create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, ast_module_.RegisterSymbol(flow_guard), flow_guard),
|
Source{}, ast_module_.RegisterSymbol(flow_guard), flow_guard),
|
||||||
MakeFalse(Source{}));
|
MakeFalse(Source{}));
|
||||||
|
@ -2581,7 +2584,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EdgeKind::kCaseFallThrough:
|
case EdgeKind::kCaseFallThrough:
|
||||||
return create<ast::FallthroughStatement>();
|
return create<ast::FallthroughStatement>(Source{});
|
||||||
case EdgeKind::kForward:
|
case EdgeKind::kForward:
|
||||||
// Unconditional forward branch is implicit.
|
// Unconditional forward branch is implicit.
|
||||||
break;
|
break;
|
||||||
|
@ -2597,11 +2600,12 @@ ast::Statement* FunctionEmitter::MakeSimpleIf(ast::Expression* condition,
|
||||||
}
|
}
|
||||||
ast::ElseStatementList else_stmts;
|
ast::ElseStatementList else_stmts;
|
||||||
if (else_stmt != nullptr) {
|
if (else_stmt != nullptr) {
|
||||||
auto* stmts = create<ast::BlockStatement>();
|
auto* stmts = create<ast::BlockStatement>(Source{});
|
||||||
stmts->append(else_stmt);
|
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 =
|
auto* if_stmt =
|
||||||
create<ast::IfStatement>(Source{}, condition, if_block, else_stmts);
|
create<ast::IfStatement>(Source{}, condition, if_block, else_stmts);
|
||||||
if (then_stmt != nullptr) {
|
if (then_stmt != nullptr) {
|
||||||
|
@ -2649,7 +2653,7 @@ bool FunctionEmitter::EmitConditionalCaseFallThrough(
|
||||||
} else {
|
} else {
|
||||||
AddStatement(MakeSimpleIf(cond, other_branch, nullptr));
|
AddStatement(MakeSimpleIf(cond, other_branch, nullptr));
|
||||||
}
|
}
|
||||||
AddStatement(create<ast::FallthroughStatement>());
|
AddStatement(create<ast::FallthroughStatement>(Source{}));
|
||||||
|
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
@ -2676,9 +2680,10 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
|
||||||
assert(def_inst);
|
assert(def_inst);
|
||||||
auto* ast_type =
|
auto* ast_type =
|
||||||
RemapStorageClass(parser_impl_.ConvertType(def_inst->type_id()), id);
|
RemapStorageClass(parser_impl_.ConvertType(def_inst->type_id()), id);
|
||||||
AddStatement(create<ast::VariableDeclStatement>(parser_impl_.MakeVariable(
|
AddStatement(create<ast::VariableDeclStatement>(
|
||||||
id, ast::StorageClass::kFunction, ast_type, false, nullptr,
|
Source{}, parser_impl_.MakeVariable(id, ast::StorageClass::kFunction,
|
||||||
ast::VariableDecorationList{})));
|
ast_type, false, nullptr,
|
||||||
|
ast::VariableDecorationList{})));
|
||||||
// Save this as an already-named value.
|
// Save this as an already-named value.
|
||||||
identifier_values_.insert(id);
|
identifier_values_.insert(id);
|
||||||
}
|
}
|
||||||
|
@ -2696,7 +2701,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
|
||||||
false, // is_const
|
false, // is_const
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
AddStatement(create<ast::VariableDeclStatement>(var));
|
AddStatement(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit regular statements.
|
// Emit regular statements.
|
||||||
|
@ -2727,6 +2732,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
|
||||||
const auto var_name = GetDefInfo(assignment.phi_id)->phi_var;
|
const auto var_name = GetDefInfo(assignment.phi_id)->phi_var;
|
||||||
auto expr = MakeExpression(assignment.value);
|
auto expr = MakeExpression(assignment.value);
|
||||||
AddStatement(create<ast::AssignmentStatement>(
|
AddStatement(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, ast_module_.RegisterSymbol(var_name), var_name),
|
Source{}, ast_module_.RegisterSymbol(var_name), var_name),
|
||||||
expr.expr));
|
expr.expr));
|
||||||
|
@ -2749,7 +2755,7 @@ bool FunctionEmitter::EmitConstDefinition(
|
||||||
if (!ast_const) {
|
if (!ast_const) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
AddStatement(create<ast::VariableDeclStatement>(ast_const));
|
AddStatement(create<ast::VariableDeclStatement>(Source{}, ast_const));
|
||||||
// Save this as an already-named value.
|
// Save this as an already-named value.
|
||||||
identifier_values_.insert(inst.result_id());
|
identifier_values_.insert(inst.result_id());
|
||||||
return success();
|
return success();
|
||||||
|
@ -2764,6 +2770,7 @@ bool FunctionEmitter::EmitConstDefOrWriteToHoistedVar(
|
||||||
auto name = namer_.Name(result_id);
|
auto name = namer_.Name(result_id);
|
||||||
// Emit an assignment of the expression to the hoisted variable.
|
// Emit an assignment of the expression to the hoisted variable.
|
||||||
AddStatement(create<ast::AssignmentStatement>(
|
AddStatement(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, ast_module_.RegisterSymbol(name), namer_.Name(result_id)),
|
Source{}, ast_module_.RegisterSymbol(name), namer_.Name(result_id)),
|
||||||
ast_expr.expr));
|
ast_expr.expr));
|
||||||
|
@ -2833,7 +2840,8 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
|
||||||
// TODO(dneto): Order of evaluation?
|
// TODO(dneto): Order of evaluation?
|
||||||
auto lhs = MakeExpression(ptr_id);
|
auto lhs = MakeExpression(ptr_id);
|
||||||
auto rhs = MakeExpression(value_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();
|
return success();
|
||||||
}
|
}
|
||||||
case SpvOpLoad: {
|
case SpvOpLoad: {
|
||||||
|
@ -3743,7 +3751,8 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result_type->Is<ast::type::Void>()) {
|
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});
|
return EmitConstDefOrWriteToHoistedVar(inst, {result_type, call_expr});
|
||||||
|
@ -3800,7 +3809,8 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
|
||||||
// The condition goes last.
|
// The condition goes last.
|
||||||
params.push_back(condition.expr);
|
params.push_back(condition.expr);
|
||||||
return {operand1.type,
|
return {operand1.type,
|
||||||
create<ast::CallExpression>(Source{},
|
create<ast::CallExpression>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, ast_module_.RegisterSymbol("select"), "select"),
|
Source{}, ast_module_.RegisterSymbol("select"), "select"),
|
||||||
std::move(params))};
|
std::move(params))};
|
||||||
|
@ -4014,7 +4024,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
|
||||||
} else {
|
} else {
|
||||||
// It's an image write. No value is returned, so make a statement out
|
// It's an image write. No value is returned, so make a statement out
|
||||||
// of the call.
|
// of the call.
|
||||||
AddStatement(create<ast::CallStatement>(call_expr));
|
AddStatement(create<ast::CallStatement>(Source{}, call_expr));
|
||||||
}
|
}
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
@ -4182,10 +4192,11 @@ ast::Expression* FunctionEmitter::ConvertTexelForStorage(
|
||||||
}
|
}
|
||||||
// If the texel has more components than necessary, then we will ignore the
|
// If the texel has more components than necessary, then we will ignore the
|
||||||
// higher-numbered components.
|
// higher-numbered components.
|
||||||
auto* texel_prefix = (src_count == dest_count)
|
auto* texel_prefix =
|
||||||
? texel.expr
|
(src_count == dest_count)
|
||||||
: create<ast::MemberAccessorExpression>(Source{},
|
? texel.expr
|
||||||
texel.expr, PrefixSwizzle(dest_count));
|
: create<ast::MemberAccessorExpression>(Source{}, texel.expr,
|
||||||
|
PrefixSwizzle(dest_count));
|
||||||
|
|
||||||
if (!(dest_type->is_float_scalar_or_vector() ||
|
if (!(dest_type->is_float_scalar_or_vector() ||
|
||||||
dest_type->is_unsigned_scalar_or_vector() ||
|
dest_type->is_unsigned_scalar_or_vector() ||
|
||||||
|
|
|
@ -1438,7 +1438,7 @@ Expect<ast::Expression*> ParserImpl::expect_paren_rhs_stmt() {
|
||||||
// : statement*
|
// : statement*
|
||||||
Expect<ast::BlockStatement*> ParserImpl::expect_statements() {
|
Expect<ast::BlockStatement*> ParserImpl::expect_statements() {
|
||||||
bool errored = false;
|
bool errored = false;
|
||||||
auto* ret = create<ast::BlockStatement>();
|
auto* ret = create<ast::BlockStatement>(Source{});
|
||||||
|
|
||||||
while (synchronized_) {
|
while (synchronized_) {
|
||||||
auto stmt = statement();
|
auto stmt = statement();
|
||||||
|
@ -1724,7 +1724,7 @@ Maybe<ast::ElseStatement*> ParserImpl::else_stmt() {
|
||||||
if (body.errored)
|
if (body.errored)
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
|
|
||||||
return create<ast::ElseStatement>(source, body.value);
|
return create<ast::ElseStatement>(source, nullptr, body.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch_stmt
|
// switch_stmt
|
||||||
|
@ -1827,7 +1827,7 @@ Expect<ast::CaseSelectorList> ParserImpl::expect_case_selectors() {
|
||||||
// | statement case_body
|
// | statement case_body
|
||||||
// | FALLTHROUGH SEMICOLON
|
// | FALLTHROUGH SEMICOLON
|
||||||
Maybe<ast::BlockStatement*> ParserImpl::case_body() {
|
Maybe<ast::BlockStatement*> ParserImpl::case_body() {
|
||||||
auto* ret = create<ast::BlockStatement>();
|
auto* ret = create<ast::BlockStatement>(Source{});
|
||||||
for (;;) {
|
for (;;) {
|
||||||
Source source;
|
Source source;
|
||||||
if (match(Token::Type::kFallthrough, &source)) {
|
if (match(Token::Type::kFallthrough, &source)) {
|
||||||
|
@ -2026,11 +2026,12 @@ Maybe<ast::CallStatement*> ParserImpl::func_call_stmt() {
|
||||||
if (!expect("call statement", Token::Type::kParenRight))
|
if (!expect("call statement", Token::Type::kParenRight))
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
|
|
||||||
return create<ast::CallStatement>(create<ast::CallExpression>(
|
return create<ast::CallStatement>(
|
||||||
source,
|
Source{}, create<ast::CallExpression>(
|
||||||
create<ast::IdentifierExpression>(Source{}, module_.RegisterSymbol(name),
|
source,
|
||||||
name),
|
create<ast::IdentifierExpression>(
|
||||||
std::move(params)));
|
source, module_.RegisterSymbol(name), name),
|
||||||
|
std::move(params)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// break_stmt
|
// break_stmt
|
||||||
|
@ -2057,7 +2058,7 @@ Maybe<ast::ContinueStatement*> ParserImpl::continue_stmt() {
|
||||||
// : CONTINUING body_stmt
|
// : CONTINUING body_stmt
|
||||||
Maybe<ast::BlockStatement*> ParserImpl::continuing_stmt() {
|
Maybe<ast::BlockStatement*> ParserImpl::continuing_stmt() {
|
||||||
if (!match(Token::Type::kContinuing))
|
if (!match(Token::Type::kContinuing))
|
||||||
return create<ast::BlockStatement>();
|
return create<ast::BlockStatement>(Source{});
|
||||||
|
|
||||||
return expect_body_stmt();
|
return expect_body_stmt();
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ class BoundArrayAccessorsTest : public testing::Test {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModuleBuilder : public ast::BuilderWithModule {
|
struct ModuleBuilder : public ast::BuilderWithModule {
|
||||||
ModuleBuilder() : body_(create<ast::BlockStatement>()) {
|
ModuleBuilder() : body_(create<ast::BlockStatement>(Source{})) {
|
||||||
mod->AddFunction(create<ast::Function>(
|
mod->AddFunction(create<ast::Function>(
|
||||||
Source{}, mod->RegisterSymbol("func"), "func", ast::VariableList{},
|
Source{}, mod->RegisterSymbol("func"), "func", ast::VariableList{},
|
||||||
ty.void_, body_, ast::FunctionDecorationList{}));
|
ty.void_, body_, ast::FunctionDecorationList{}));
|
||||||
|
@ -106,7 +106,7 @@ struct ModuleBuilder : public ast::BuilderWithModule {
|
||||||
virtual void Build() = 0;
|
virtual void Build() = 0;
|
||||||
void OnVariableBuilt(ast::Variable* var) override {
|
void OnVariableBuilt(ast::Variable* var) override {
|
||||||
ASSERT_NE(body_, nullptr);
|
ASSERT_NE(body_, nullptr);
|
||||||
body_->append(create<ast::VariableDeclStatement>(var));
|
body_->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
}
|
}
|
||||||
ast::BlockStatement* body_ = nullptr;
|
ast::BlockStatement* body_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -65,12 +65,12 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
|
||||||
mod->AddGlobalVariable(pointsize_var);
|
mod->AddGlobalVariable(pointsize_var);
|
||||||
|
|
||||||
// Build the AST expression & statement for assigning pointsize one.
|
// Build the AST expression & statement for assigning pointsize one.
|
||||||
auto* one = mod->create<ast::ScalarConstructorExpression>(Source{},
|
auto* one = mod->create<ast::ScalarConstructorExpression>(
|
||||||
mod->create<ast::FloatLiteral>(Source{}, f32, 1.0f));
|
Source{}, mod->create<ast::FloatLiteral>(Source{}, f32, 1.0f));
|
||||||
auto* pointsize_ident = mod->create<ast::IdentifierExpression>(
|
auto* pointsize_ident = mod->create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol(kPointSizeVar), kPointSizeVar);
|
Source{}, mod->RegisterSymbol(kPointSizeVar), kPointSizeVar);
|
||||||
auto* pointsize_assign =
|
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.
|
// Add the pointsize assignment statement to the front of all vertex stages.
|
||||||
for (auto* func : mod->functions()) {
|
for (auto* func : mod->functions()) {
|
||||||
|
|
|
@ -56,8 +56,8 @@ TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
|
||||||
auto* block = create<ast::BlockStatement>(Source{});
|
auto* block = create<ast::BlockStatement>(Source{});
|
||||||
|
|
||||||
block->append(create<ast::VariableDeclStatement>(
|
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)));
|
tint::ast::StorageClass::kFunction, ty.f32)));
|
||||||
|
|
||||||
auto a_sym = mod->RegisterSymbol("non_entry_a");
|
auto a_sym = mod->RegisterSymbol("non_entry_a");
|
||||||
mod->AddFunction(create<ast::Function>(
|
mod->AddFunction(create<ast::Function>(
|
||||||
|
|
|
@ -270,7 +270,7 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset(
|
||||||
true, // is_const
|
true, // is_const
|
||||||
constructor, // constructor
|
constructor, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
return mod->create<ast::VariableDeclStatement>(var);
|
return mod->create<ast::VariableDeclStatement>(Source{}, var);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace transform
|
} // namespace transform
|
||||||
|
|
|
@ -61,7 +61,7 @@ struct ModuleBuilder : public ast::BuilderWithModule {
|
||||||
ast::VariableList params = {}) {
|
ast::VariableList params = {}) {
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod->RegisterSymbol(name), name, std::move(params), ty.u32,
|
Source{}, mod->RegisterSymbol(name), name, std::move(params), ty.u32,
|
||||||
create<ast::BlockStatement>(), ast::FunctionDecorationList());
|
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList());
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,18 +292,18 @@ void VertexPulling::State::AddVertexPullingPreamble(
|
||||||
// location.
|
// location.
|
||||||
|
|
||||||
// A block statement allowing us to use append instead of insert
|
// 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
|
// Declare the |kPullingPosVarName| variable in the shader
|
||||||
auto* pos_declaration =
|
auto* pos_declaration = mod->create<ast::VariableDeclStatement>(
|
||||||
mod->create<ast::VariableDeclStatement>(mod->create<ast::Variable>(
|
Source{}, mod->create<ast::Variable>(
|
||||||
Source{}, // source
|
Source{}, // source
|
||||||
kPullingPosVarName, // name
|
kPullingPosVarName, // name
|
||||||
ast::StorageClass::kFunction, // storage_class
|
ast::StorageClass::kFunction, // storage_class
|
||||||
GetI32Type(), // type
|
GetI32Type(), // type
|
||||||
false, // is_const
|
false, // is_const
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
// |kPullingPosVarName| refers to the byte location of the current read. We
|
// |kPullingPosVarName| refers to the byte location of the current read. We
|
||||||
// declare a variable in the shader to avoid having to reuse Expression
|
// declare a variable in the shader to avoid having to reuse Expression
|
||||||
|
@ -338,10 +338,11 @@ void VertexPulling::State::AddVertexPullingPreamble(
|
||||||
|
|
||||||
// Update position of the read
|
// Update position of the read
|
||||||
auto* set_pos_expr = mod->create<ast::AssignmentStatement>(
|
auto* set_pos_expr = mod->create<ast::AssignmentStatement>(
|
||||||
CreatePullingPositionIdent(), pos_value);
|
Source{}, CreatePullingPositionIdent(), pos_value);
|
||||||
block->append(set_pos_expr);
|
block->append(set_pos_expr);
|
||||||
|
|
||||||
block->append(mod->create<ast::AssignmentStatement>(
|
block->append(mod->create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
mod->create<ast::IdentifierExpression>(
|
mod->create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol(v->name()), v->name()),
|
Source{}, mod->RegisterSymbol(v->name()), v->name()),
|
||||||
AccessByFormat(i, attribute_desc.format)));
|
AccessByFormat(i, attribute_desc.format)));
|
||||||
|
|
|
@ -48,7 +48,7 @@ class VertexPullingHelper {
|
||||||
void InitBasicModule() {
|
void InitBasicModule() {
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod_->RegisterSymbol("main"), "main", ast::VariableList{},
|
Source{}, mod_->RegisterSymbol("main"), "main", ast::VariableList{},
|
||||||
mod_->create<ast::type::Void>(), create<ast::BlockStatement>(),
|
mod_->create<ast::type::Void>(), create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{create<ast::StageDecoration>(
|
ast::FunctionDecorationList{create<ast::StageDecoration>(
|
||||||
ast::PipelineStage::kVertex, Source{})});
|
ast::PipelineStage::kVertex, Source{})});
|
||||||
mod()->AddFunction(func);
|
mod()->AddFunction(func);
|
||||||
|
@ -135,7 +135,7 @@ TEST_F(VertexPullingTest, Error_InvalidEntryPoint) {
|
||||||
TEST_F(VertexPullingTest, Error_EntryPointWrongStage) {
|
TEST_F(VertexPullingTest, Error_EntryPointWrongStage) {
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod()->RegisterSymbol("main"), "main", ast::VariableList{},
|
Source{}, mod()->RegisterSymbol("main"), "main", ast::VariableList{},
|
||||||
mod()->create<ast::type::Void>(), create<ast::BlockStatement>(),
|
mod()->create<ast::type::Void>(), create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
|
||||||
});
|
});
|
||||||
|
|
|
@ -132,7 +132,7 @@ TEST_F(TypeDeterminerTest, Stmt_Assign) {
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
||||||
|
|
||||||
ast::AssignmentStatement assign(lhs, rhs);
|
ast::AssignmentStatement assign(Source{}, lhs, rhs);
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&assign));
|
EXPECT_TRUE(td()->DetermineResultType(&assign));
|
||||||
ASSERT_NE(lhs->result_type(), nullptr);
|
ASSERT_NE(lhs->result_type(), nullptr);
|
||||||
|
@ -151,12 +151,12 @@ TEST_F(TypeDeterminerTest, Stmt_Case) {
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(lhs, rhs));
|
body->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 3));
|
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 3));
|
||||||
ast::CaseStatement cse(lit, body);
|
ast::CaseStatement cse(Source{}, lit, body);
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&cse));
|
EXPECT_TRUE(td()->DetermineResultType(&cse));
|
||||||
ASSERT_NE(lhs->result_type(), nullptr);
|
ASSERT_NE(lhs->result_type(), nullptr);
|
||||||
|
@ -174,8 +174,8 @@ TEST_F(TypeDeterminerTest, Stmt_Block) {
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
||||||
|
|
||||||
ast::BlockStatement block;
|
ast::BlockStatement block(Source{});
|
||||||
block.append(create<ast::AssignmentStatement>(lhs, rhs));
|
block.append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&block));
|
EXPECT_TRUE(td()->DetermineResultType(&block));
|
||||||
ASSERT_NE(lhs->result_type(), nullptr);
|
ASSERT_NE(lhs->result_type(), nullptr);
|
||||||
|
@ -193,10 +193,11 @@ TEST_F(TypeDeterminerTest, Stmt_Else) {
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(lhs, rhs));
|
body->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
|
||||||
|
|
||||||
ast::ElseStatement stmt(
|
ast::ElseStatement stmt(
|
||||||
|
Source{},
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)),
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)),
|
||||||
body);
|
body);
|
||||||
|
@ -219,10 +220,12 @@ TEST_F(TypeDeterminerTest, Stmt_If) {
|
||||||
auto* else_rhs = create<ast::ScalarConstructorExpression>(
|
auto* else_rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
||||||
|
|
||||||
auto* else_body = create<ast::BlockStatement>();
|
auto* else_body = create<ast::BlockStatement>(Source{});
|
||||||
else_body->append(create<ast::AssignmentStatement>(else_lhs, else_rhs));
|
else_body->append(
|
||||||
|
create<ast::AssignmentStatement>(Source{}, else_lhs, else_rhs));
|
||||||
|
|
||||||
auto* else_stmt = create<ast::ElseStatement>(
|
auto* else_stmt = create<ast::ElseStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)),
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)),
|
||||||
else_body);
|
else_body);
|
||||||
|
@ -232,8 +235,8 @@ TEST_F(TypeDeterminerTest, Stmt_If) {
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(lhs, rhs));
|
body->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
|
||||||
|
|
||||||
ast::IfStatement stmt(
|
ast::IfStatement stmt(
|
||||||
Source{},
|
Source{},
|
||||||
|
@ -263,19 +266,19 @@ TEST_F(TypeDeterminerTest, Stmt_Loop) {
|
||||||
auto* body_rhs = create<ast::ScalarConstructorExpression>(
|
auto* body_rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(body_lhs, body_rhs));
|
body->append(create<ast::AssignmentStatement>(Source{}, body_lhs, body_rhs));
|
||||||
|
|
||||||
auto* continuing_lhs = create<ast::ScalarConstructorExpression>(
|
auto* continuing_lhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
auto* continuing_rhs = create<ast::ScalarConstructorExpression>(
|
auto* continuing_rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
||||||
|
|
||||||
auto* continuing = create<ast::BlockStatement>();
|
auto* continuing = create<ast::BlockStatement>(Source{});
|
||||||
continuing->append(
|
continuing->append(create<ast::AssignmentStatement>(Source{}, continuing_lhs,
|
||||||
create<ast::AssignmentStatement>(continuing_lhs, continuing_rhs));
|
continuing_rhs));
|
||||||
|
|
||||||
ast::LoopStatement stmt(body, continuing);
|
ast::LoopStatement stmt(Source{}, body, continuing);
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&stmt));
|
EXPECT_TRUE(td()->DetermineResultType(&stmt));
|
||||||
ASSERT_NE(body_lhs->result_type(), nullptr);
|
ASSERT_NE(body_lhs->result_type(), nullptr);
|
||||||
|
@ -316,16 +319,17 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) {
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(lhs, rhs));
|
body->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 3));
|
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 3));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
ast::CaseStatementList cases;
|
||||||
cases.push_back(create<ast::CaseStatement>(lit, body));
|
cases.push_back(create<ast::CaseStatement>(Source{}, lit, body));
|
||||||
|
|
||||||
ast::SwitchStatement stmt(
|
ast::SwitchStatement stmt(
|
||||||
|
Source{},
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)),
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)),
|
||||||
cases);
|
cases);
|
||||||
|
@ -346,7 +350,7 @@ TEST_F(TypeDeterminerTest, Stmt_Call) {
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
|
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
|
||||||
create<ast::BlockStatement>(), ast::FunctionDecorationList{});
|
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList{});
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
|
|
||||||
// Register the function
|
// Register the function
|
||||||
|
@ -359,7 +363,7 @@ TEST_F(TypeDeterminerTest, Stmt_Call) {
|
||||||
Source{}, mod->RegisterSymbol("my_func"), "my_func"),
|
Source{}, mod->RegisterSymbol("my_func"), "my_func"),
|
||||||
call_params);
|
call_params);
|
||||||
|
|
||||||
ast::CallStatement call(expr);
|
ast::CallStatement call(Source{}, expr);
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&call));
|
EXPECT_TRUE(td()->DetermineResultType(&call));
|
||||||
ASSERT_NE(expr->result_type(), nullptr);
|
ASSERT_NE(expr->result_type(), nullptr);
|
||||||
EXPECT_TRUE(expr->result_type()->Is<ast::type::F32>());
|
EXPECT_TRUE(expr->result_type()->Is<ast::type::F32>());
|
||||||
|
@ -376,15 +380,15 @@ TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) {
|
||||||
mod->RegisterSymbol("func"), "func"),
|
mod->RegisterSymbol("func"), "func"),
|
||||||
call_params);
|
call_params);
|
||||||
ast::VariableList params0;
|
ast::VariableList params0;
|
||||||
auto* main_body = create<ast::BlockStatement>();
|
auto* main_body = create<ast::BlockStatement>(Source{});
|
||||||
main_body->append(create<ast::CallStatement>(call_expr));
|
main_body->append(create<ast::CallStatement>(Source{}, call_expr));
|
||||||
main_body->append(create<ast::ReturnStatement>(Source{}));
|
main_body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func_main = create<ast::Function>(Source{}, mod->RegisterSymbol("main"),
|
auto* func_main = create<ast::Function>(Source{}, mod->RegisterSymbol("main"),
|
||||||
"main", params0, &f32, main_body,
|
"main", params0, &f32, main_body,
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
mod->AddFunction(func_main);
|
mod->AddFunction(func_main);
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func =
|
auto* func =
|
||||||
create<ast::Function>(Source{}, mod->RegisterSymbol("func"), "func",
|
create<ast::Function>(Source{}, mod->RegisterSymbol("func"), "func",
|
||||||
|
@ -410,7 +414,7 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl) {
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
auto* init = var->constructor();
|
auto* init = var->constructor();
|
||||||
|
|
||||||
ast::VariableDeclStatement decl(var);
|
ast::VariableDeclStatement decl(Source{}, var);
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&decl));
|
EXPECT_TRUE(td()->DetermineResultType(&decl));
|
||||||
ASSERT_NE(init->result_type(), nullptr);
|
ASSERT_NE(init->result_type(), nullptr);
|
||||||
|
@ -671,7 +675,7 @@ TEST_F(TypeDeterminerTest, Expr_Call) {
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
|
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
|
||||||
create<ast::BlockStatement>(), ast::FunctionDecorationList{});
|
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList{});
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
|
|
||||||
// Register the function
|
// Register the function
|
||||||
|
@ -694,7 +698,7 @@ TEST_F(TypeDeterminerTest, Expr_Call_WithParams) {
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
|
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
|
||||||
create<ast::BlockStatement>(), ast::FunctionDecorationList{});
|
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList{});
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
|
|
||||||
// Register the function
|
// Register the function
|
||||||
|
@ -847,11 +851,12 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable_Const) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
my_var, create<ast::IdentifierExpression>(
|
Source{}, my_var,
|
||||||
Source{}, mod->RegisterSymbol("my_var"), "my_var")));
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_var"),
|
||||||
|
"my_var")));
|
||||||
|
|
||||||
ast::Function f(Source{}, mod->RegisterSymbol("my_func"), "my_func", {}, &f32,
|
ast::Function f(Source{}, mod->RegisterSymbol("my_func"), "my_func", {}, &f32,
|
||||||
body, ast::FunctionDecorationList{});
|
body, ast::FunctionDecorationList{});
|
||||||
|
@ -868,8 +873,9 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable) {
|
||||||
auto* my_var = create<ast::IdentifierExpression>(
|
auto* my_var = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol("my_var"), "my_var");
|
Source{}, mod->RegisterSymbol("my_var"), "my_var");
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(
|
body->append(create<ast::VariableDeclStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::Variable>(Source{}, // source
|
create<ast::Variable>(Source{}, // source
|
||||||
"my_var", // name
|
"my_var", // name
|
||||||
ast::StorageClass::kNone, // storage_class
|
ast::StorageClass::kNone, // storage_class
|
||||||
|
@ -879,8 +885,9 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable) {
|
||||||
ast::VariableDecorationList{}))); // decorations
|
ast::VariableDecorationList{}))); // decorations
|
||||||
|
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
my_var, create<ast::IdentifierExpression>(
|
Source{}, my_var,
|
||||||
Source{}, mod->RegisterSymbol("my_var"), "my_var")));
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_var"),
|
||||||
|
"my_var")));
|
||||||
|
|
||||||
ast::Function f(Source{}, mod->RegisterSymbol("myfunc"), "my_func", {}, &f32,
|
ast::Function f(Source{}, mod->RegisterSymbol("myfunc"), "my_func", {}, &f32,
|
||||||
body, ast::FunctionDecorationList{});
|
body, ast::FunctionDecorationList{});
|
||||||
|
@ -902,8 +909,9 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) {
|
||||||
auto* my_var = create<ast::IdentifierExpression>(
|
auto* my_var = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol("my_var"), "my_var");
|
Source{}, mod->RegisterSymbol("my_var"), "my_var");
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(
|
body->append(create<ast::VariableDeclStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::Variable>(Source{}, // source
|
create<ast::Variable>(Source{}, // source
|
||||||
"my_var", // name
|
"my_var", // name
|
||||||
ast::StorageClass::kNone, // storage_class
|
ast::StorageClass::kNone, // storage_class
|
||||||
|
@ -913,8 +921,9 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) {
|
||||||
ast::VariableDecorationList{}))); // decorations
|
ast::VariableDecorationList{}))); // decorations
|
||||||
|
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
my_var, create<ast::IdentifierExpression>(
|
Source{}, my_var,
|
||||||
Source{}, mod->RegisterSymbol("my_var"), "my_var")));
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_var"),
|
||||||
|
"my_var")));
|
||||||
|
|
||||||
ast::Function f(Source{}, mod->RegisterSymbol("my_func"), "my_func", {}, &f32,
|
ast::Function f(Source{}, mod->RegisterSymbol("my_func"), "my_func", {}, &f32,
|
||||||
body, ast::FunctionDecorationList{});
|
body, ast::FunctionDecorationList{});
|
||||||
|
@ -935,7 +944,7 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function) {
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
|
Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32,
|
||||||
create<ast::BlockStatement>(), ast::FunctionDecorationList{});
|
create<ast::BlockStatement>(Source{}), ast::FunctionDecorationList{});
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
|
|
||||||
// Register the function
|
// Register the function
|
||||||
|
@ -1004,23 +1013,27 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables) {
|
||||||
mod->AddGlobalVariable(priv_var);
|
mod->AddGlobalVariable(priv_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol("out_var"), "out_var"),
|
Source{}, mod->RegisterSymbol("out_var"), "out_var"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("in_var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("in_var"),
|
||||||
"in_var")));
|
"in_var")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"),
|
||||||
"wg_var"),
|
"wg_var"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"),
|
||||||
"wg_var")));
|
"wg_var")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"),
|
||||||
"sb_var"),
|
"sb_var"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"),
|
||||||
"sb_var")));
|
"sb_var")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol("priv_var"), "priv_var"),
|
Source{}, mod->RegisterSymbol("priv_var"), "priv_var"),
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
|
@ -1093,23 +1106,27 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
|
||||||
mod->AddGlobalVariable(wg_var);
|
mod->AddGlobalVariable(wg_var);
|
||||||
mod->AddGlobalVariable(priv_var);
|
mod->AddGlobalVariable(priv_var);
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol("out_var"), "out_var"),
|
Source{}, mod->RegisterSymbol("out_var"), "out_var"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("in_var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("in_var"),
|
||||||
"in_var")));
|
"in_var")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"),
|
||||||
"wg_var"),
|
"wg_var"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("wg_var"),
|
||||||
"wg_var")));
|
"wg_var")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"),
|
||||||
"sb_var"),
|
"sb_var"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("sb_var"),
|
||||||
"sb_var")));
|
"sb_var")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol("priv_var"), "priv_var"),
|
Source{}, mod->RegisterSymbol("priv_var"), "priv_var"),
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
|
@ -1121,8 +1138,9 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
|
||||||
|
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol("out_var"), "out_var"),
|
Source{}, mod->RegisterSymbol("out_var"), "out_var"),
|
||||||
create<ast::CallExpression>(
|
create<ast::CallExpression>(
|
||||||
|
@ -1160,9 +1178,10 @@ TEST_F(TypeDeterminerTest, Function_NotRegisterFunctionVariable) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
|
||||||
"var"),
|
"var"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
|
@ -2839,9 +2858,9 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) {
|
||||||
false, // is_const
|
false, // is_const
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
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);
|
body->append(stmt);
|
||||||
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"),
|
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"),
|
||||||
"func", ast::VariableList{}, &i32, body,
|
"func", ast::VariableList{}, &i32, body,
|
||||||
|
@ -2864,9 +2883,9 @@ TEST_F(TypeDeterminerTest, StorageClass_DoesNotSetOnConst) {
|
||||||
true, // is_const
|
true, // is_const
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
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);
|
body->append(stmt);
|
||||||
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"),
|
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"),
|
||||||
"func", ast::VariableList{}, &i32, body,
|
"func", ast::VariableList{}, &i32, body,
|
||||||
|
@ -2889,9 +2908,9 @@ TEST_F(TypeDeterminerTest, StorageClass_NonFunctionClassError) {
|
||||||
false, // is_const
|
false, // is_const
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
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);
|
body->append(stmt);
|
||||||
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"),
|
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("func"),
|
||||||
"func", ast::VariableList{}, &i32, body,
|
"func", ast::VariableList{}, &i32, body,
|
||||||
|
@ -5209,13 +5228,14 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
|
||||||
// ep_2 -> {}
|
// ep_2 -> {}
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
auto* func_b =
|
auto* func_b =
|
||||||
create<ast::Function>(Source{}, mod->RegisterSymbol("b"), "b", params,
|
create<ast::Function>(Source{}, mod->RegisterSymbol("b"), "b", params,
|
||||||
&f32, body, ast::FunctionDecorationList{});
|
&f32, body, ast::FunctionDecorationList{});
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("second"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("second"),
|
||||||
"second"),
|
"second"),
|
||||||
create<ast::CallExpression>(Source{},
|
create<ast::CallExpression>(Source{},
|
||||||
|
@ -5226,8 +5246,9 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
|
||||||
create<ast::Function>(Source{}, mod->RegisterSymbol("c"), "c", params,
|
create<ast::Function>(Source{}, mod->RegisterSymbol("c"), "c", params,
|
||||||
&f32, body, ast::FunctionDecorationList{});
|
&f32, body, ast::FunctionDecorationList{});
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("first"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("first"),
|
||||||
"first"),
|
"first"),
|
||||||
create<ast::CallExpression>(Source{},
|
create<ast::CallExpression>(Source{},
|
||||||
|
@ -5238,8 +5259,9 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
|
||||||
create<ast::Function>(Source{}, mod->RegisterSymbol("a"), "a", params,
|
create<ast::Function>(Source{}, mod->RegisterSymbol("a"), "a", params,
|
||||||
&f32, body, ast::FunctionDecorationList{});
|
&f32, body, ast::FunctionDecorationList{});
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("call_a"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("call_a"),
|
||||||
"call_a"),
|
"call_a"),
|
||||||
create<ast::CallExpression>(Source{},
|
create<ast::CallExpression>(Source{},
|
||||||
|
@ -5247,6 +5269,7 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
|
||||||
Source{}, mod->RegisterSymbol("a"), "a"),
|
Source{}, mod->RegisterSymbol("a"), "a"),
|
||||||
ast::ExpressionList{})));
|
ast::ExpressionList{})));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("call_b"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("call_b"),
|
||||||
"call_b"),
|
"call_b"),
|
||||||
create<ast::CallExpression>(Source{},
|
create<ast::CallExpression>(Source{},
|
||||||
|
@ -5259,8 +5282,9 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
|
||||||
});
|
});
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("call_c"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("call_c"),
|
||||||
"call_c"),
|
"call_c"),
|
||||||
create<ast::CallExpression>(Source{},
|
create<ast::CallExpression>(Source{},
|
||||||
|
|
|
@ -57,13 +57,14 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
|
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
|
||||||
ast::CaseSelectorList default_csl;
|
ast::CaseSelectorList default_csl;
|
||||||
auto* block_default = create<ast::BlockStatement>();
|
auto* block_default = create<ast::BlockStatement>(Source{});
|
||||||
ast::CaseStatementList body;
|
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>();
|
auto* block = create<ast::BlockStatement>(Source{});
|
||||||
block->append(create<ast::VariableDeclStatement>(var));
|
block->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
block->append(create<ast::SwitchStatement>(cond, body));
|
block->append(create<ast::SwitchStatement>(Source{}, cond, body));
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||||
|
@ -94,11 +95,11 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
|
||||||
ast::CaseSelectorList csl;
|
ast::CaseSelectorList csl;
|
||||||
csl.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
|
csl.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
|
||||||
ast::CaseStatementList body;
|
ast::CaseStatementList body;
|
||||||
body.push_back(
|
body.push_back(create<ast::CaseStatement>(
|
||||||
create<ast::CaseStatement>(csl, create<ast::BlockStatement>()));
|
Source{}, csl, create<ast::BlockStatement>(Source{})));
|
||||||
|
|
||||||
auto* block = create<ast::BlockStatement>();
|
auto* block = create<ast::BlockStatement>(Source{});
|
||||||
block->append(create<ast::VariableDeclStatement>(var));
|
block->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}},
|
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}},
|
||||||
cond, body));
|
cond, body));
|
||||||
|
|
||||||
|
@ -133,22 +134,23 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
|
||||||
Source{}, mod()->RegisterSymbol("a"), "a");
|
Source{}, mod()->RegisterSymbol("a"), "a");
|
||||||
|
|
||||||
ast::CaseSelectorList default_csl_1;
|
ast::CaseSelectorList default_csl_1;
|
||||||
auto* block_default_1 = create<ast::BlockStatement>();
|
auto* block_default_1 = create<ast::BlockStatement>(Source{});
|
||||||
switch_body.push_back(
|
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;
|
ast::CaseSelectorList csl_case_1;
|
||||||
csl_case_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
|
csl_case_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
|
||||||
auto* block_case_1 = create<ast::BlockStatement>();
|
auto* block_case_1 = create<ast::BlockStatement>(Source{});
|
||||||
switch_body.push_back(create<ast::CaseStatement>(csl_case_1, block_case_1));
|
switch_body.push_back(
|
||||||
|
create<ast::CaseStatement>(Source{}, csl_case_1, block_case_1));
|
||||||
|
|
||||||
ast::CaseSelectorList default_csl_2;
|
ast::CaseSelectorList default_csl_2;
|
||||||
auto* block_default_2 = create<ast::BlockStatement>();
|
auto* block_default_2 = create<ast::BlockStatement>(Source{});
|
||||||
switch_body.push_back(
|
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>();
|
auto* block = create<ast::BlockStatement>(Source{});
|
||||||
block->append(create<ast::VariableDeclStatement>(var));
|
block->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}},
|
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}},
|
||||||
cond, switch_body));
|
cond, switch_body));
|
||||||
|
|
||||||
|
@ -185,16 +187,18 @@ TEST_F(ValidateControlBlockTest,
|
||||||
|
|
||||||
ast::CaseSelectorList csl;
|
ast::CaseSelectorList csl;
|
||||||
csl.push_back(create<ast::UintLiteral>(Source{}, &u32, 1));
|
csl.push_back(create<ast::UintLiteral>(Source{}, &u32, 1));
|
||||||
switch_body.push_back(create<ast::CaseStatement>(
|
switch_body.push_back(
|
||||||
Source{Source::Location{12, 34}}, csl, create<ast::BlockStatement>()));
|
create<ast::CaseStatement>(Source{Source::Location{12, 34}}, csl,
|
||||||
|
create<ast::BlockStatement>(Source{})));
|
||||||
|
|
||||||
ast::CaseSelectorList default_csl;
|
ast::CaseSelectorList default_csl;
|
||||||
auto* block_default = create<ast::BlockStatement>();
|
auto* block_default = create<ast::BlockStatement>(Source{});
|
||||||
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
|
switch_body.push_back(
|
||||||
|
create<ast::CaseStatement>(Source{}, default_csl, block_default));
|
||||||
|
|
||||||
auto* block = create<ast::BlockStatement>();
|
auto* block = create<ast::BlockStatement>(Source{});
|
||||||
block->append(create<ast::VariableDeclStatement>(var));
|
block->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
block->append(create<ast::SwitchStatement>(cond, switch_body));
|
block->append(create<ast::SwitchStatement>(Source{}, cond, switch_body));
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||||
|
@ -229,16 +233,18 @@ TEST_F(ValidateControlBlockTest,
|
||||||
|
|
||||||
ast::CaseSelectorList csl;
|
ast::CaseSelectorList csl;
|
||||||
csl.push_back(create<ast::SintLiteral>(Source{}, &i32, -1));
|
csl.push_back(create<ast::SintLiteral>(Source{}, &i32, -1));
|
||||||
switch_body.push_back(create<ast::CaseStatement>(
|
switch_body.push_back(
|
||||||
Source{Source::Location{12, 34}}, csl, create<ast::BlockStatement>()));
|
create<ast::CaseStatement>(Source{Source::Location{12, 34}}, csl,
|
||||||
|
create<ast::BlockStatement>(Source{})));
|
||||||
|
|
||||||
ast::CaseSelectorList default_csl;
|
ast::CaseSelectorList default_csl;
|
||||||
auto* block_default = create<ast::BlockStatement>();
|
auto* block_default = create<ast::BlockStatement>(Source{});
|
||||||
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
|
switch_body.push_back(
|
||||||
|
create<ast::CaseStatement>(Source{}, default_csl, block_default));
|
||||||
|
|
||||||
auto* block = create<ast::BlockStatement>();
|
auto* block = create<ast::BlockStatement>(Source{});
|
||||||
block->append(create<ast::VariableDeclStatement>(var));
|
block->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
block->append(create<ast::SwitchStatement>(cond, switch_body));
|
block->append(create<ast::SwitchStatement>(Source{}, cond, switch_body));
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||||
|
@ -272,22 +278,24 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
|
||||||
|
|
||||||
ast::CaseSelectorList csl_1;
|
ast::CaseSelectorList csl_1;
|
||||||
csl_1.push_back(create<ast::UintLiteral>(Source{}, &u32, 0));
|
csl_1.push_back(create<ast::UintLiteral>(Source{}, &u32, 0));
|
||||||
switch_body.push_back(
|
switch_body.push_back(create<ast::CaseStatement>(
|
||||||
create<ast::CaseStatement>(csl_1, create<ast::BlockStatement>()));
|
Source{}, csl_1, create<ast::BlockStatement>(Source{})));
|
||||||
|
|
||||||
ast::CaseSelectorList csl_2;
|
ast::CaseSelectorList csl_2;
|
||||||
csl_2.push_back(create<ast::UintLiteral>(Source{}, &u32, 2));
|
csl_2.push_back(create<ast::UintLiteral>(Source{}, &u32, 2));
|
||||||
csl_2.push_back(create<ast::UintLiteral>(Source{}, &u32, 2));
|
csl_2.push_back(create<ast::UintLiteral>(Source{}, &u32, 2));
|
||||||
switch_body.push_back(create<ast::CaseStatement>(
|
switch_body.push_back(
|
||||||
Source{Source::Location{12, 34}}, csl_2, create<ast::BlockStatement>()));
|
create<ast::CaseStatement>(Source{Source::Location{12, 34}}, csl_2,
|
||||||
|
create<ast::BlockStatement>(Source{})));
|
||||||
|
|
||||||
ast::CaseSelectorList default_csl;
|
ast::CaseSelectorList default_csl;
|
||||||
auto* block_default = create<ast::BlockStatement>();
|
auto* block_default = create<ast::BlockStatement>(Source{});
|
||||||
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
|
switch_body.push_back(
|
||||||
|
create<ast::CaseStatement>(Source{}, default_csl, block_default));
|
||||||
|
|
||||||
auto* block = create<ast::BlockStatement>();
|
auto* block = create<ast::BlockStatement>(Source{});
|
||||||
block->append(create<ast::VariableDeclStatement>(var));
|
block->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
block->append(create<ast::SwitchStatement>(cond, switch_body));
|
block->append(create<ast::SwitchStatement>(Source{}, cond, switch_body));
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||||
|
@ -321,24 +329,26 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
|
||||||
|
|
||||||
ast::CaseSelectorList csl_1;
|
ast::CaseSelectorList csl_1;
|
||||||
csl_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 10));
|
csl_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 10));
|
||||||
switch_body.push_back(
|
switch_body.push_back(create<ast::CaseStatement>(
|
||||||
create<ast::CaseStatement>(csl_1, create<ast::BlockStatement>()));
|
Source{}, csl_1, create<ast::BlockStatement>(Source{})));
|
||||||
|
|
||||||
ast::CaseSelectorList csl_2;
|
ast::CaseSelectorList csl_2;
|
||||||
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 0));
|
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 0));
|
||||||
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
|
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
|
||||||
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 2));
|
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 10));
|
csl_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 10));
|
||||||
switch_body.push_back(create<ast::CaseStatement>(
|
switch_body.push_back(
|
||||||
Source{Source::Location{12, 34}}, csl_2, create<ast::BlockStatement>()));
|
create<ast::CaseStatement>(Source{Source::Location{12, 34}}, csl_2,
|
||||||
|
create<ast::BlockStatement>(Source{})));
|
||||||
|
|
||||||
ast::CaseSelectorList default_csl;
|
ast::CaseSelectorList default_csl;
|
||||||
auto* block_default = create<ast::BlockStatement>();
|
auto* block_default = create<ast::BlockStatement>(Source{});
|
||||||
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
|
switch_body.push_back(
|
||||||
|
create<ast::CaseStatement>(Source{}, default_csl, block_default));
|
||||||
|
|
||||||
auto* block = create<ast::BlockStatement>();
|
auto* block = create<ast::BlockStatement>(Source{});
|
||||||
block->append(create<ast::VariableDeclStatement>(var));
|
block->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
block->append(create<ast::SwitchStatement>(cond, switch_body));
|
block->append(create<ast::SwitchStatement>(Source{}, cond, switch_body));
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||||
|
@ -367,15 +377,16 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod()->RegisterSymbol("a"), "a");
|
Source{}, mod()->RegisterSymbol("a"), "a");
|
||||||
ast::CaseSelectorList default_csl;
|
ast::CaseSelectorList default_csl;
|
||||||
auto* block_default = create<ast::BlockStatement>();
|
auto* block_default = create<ast::BlockStatement>(Source{});
|
||||||
block_default->append(
|
block_default->append(
|
||||||
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}));
|
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}));
|
||||||
ast::CaseStatementList body;
|
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>();
|
auto* block = create<ast::BlockStatement>(Source{});
|
||||||
block->append(create<ast::VariableDeclStatement>(var));
|
block->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
block->append(create<ast::SwitchStatement>(cond, body));
|
block->append(create<ast::SwitchStatement>(Source{}, cond, body));
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||||
|
@ -405,18 +416,18 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod()->RegisterSymbol("a"), "a");
|
Source{}, mod()->RegisterSymbol("a"), "a");
|
||||||
ast::CaseSelectorList default_csl;
|
ast::CaseSelectorList default_csl;
|
||||||
auto* block_default = create<ast::BlockStatement>();
|
auto* block_default = create<ast::BlockStatement>(Source{});
|
||||||
ast::CaseStatementList body;
|
ast::CaseStatementList body;
|
||||||
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
|
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
|
||||||
default_csl, block_default));
|
default_csl, block_default));
|
||||||
ast::CaseSelectorList case_csl;
|
ast::CaseSelectorList case_csl;
|
||||||
case_csl.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
case_csl.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||||
auto* block_case = create<ast::BlockStatement>();
|
auto* block_case = create<ast::BlockStatement>(Source{});
|
||||||
body.push_back(create<ast::CaseStatement>(case_csl, block_case));
|
body.push_back(create<ast::CaseStatement>(Source{}, case_csl, block_case));
|
||||||
|
|
||||||
auto* block = create<ast::BlockStatement>();
|
auto* block = create<ast::BlockStatement>(Source{});
|
||||||
block->append(create<ast::VariableDeclStatement>(var));
|
block->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
block->append(create<ast::SwitchStatement>(cond, body));
|
block->append(create<ast::SwitchStatement>(Source{}, cond, body));
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||||
EXPECT_TRUE(v()->ValidateStatements(block)) << v()->error();
|
EXPECT_TRUE(v()->ValidateStatements(block)) << v()->error();
|
||||||
|
@ -446,14 +457,14 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod()->RegisterSymbol("a"), "a");
|
Source{}, mod()->RegisterSymbol("a"), "a");
|
||||||
ast::CaseSelectorList default_csl;
|
ast::CaseSelectorList default_csl;
|
||||||
auto* block_default = create<ast::BlockStatement>();
|
auto* block_default = create<ast::BlockStatement>(Source{});
|
||||||
ast::CaseStatementList body;
|
ast::CaseStatementList body;
|
||||||
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
|
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
|
||||||
default_csl, block_default));
|
default_csl, block_default));
|
||||||
|
|
||||||
auto* block = create<ast::BlockStatement>();
|
auto* block = create<ast::BlockStatement>(Source{});
|
||||||
block->append(create<ast::VariableDeclStatement>(var));
|
block->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
block->append(create<ast::SwitchStatement>(cond, body));
|
block->append(create<ast::SwitchStatement>(Source{}, cond, body));
|
||||||
|
|
||||||
mod()->AddConstructedType(&my_int);
|
mod()->AddConstructedType(&my_int);
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,8 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
|
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
|
||||||
params, &void_type, body,
|
params, &void_type, body,
|
||||||
|
@ -74,7 +74,7 @@ TEST_F(ValidateFunctionTest,
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
|
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
|
||||||
params, &void_type, create<ast::BlockStatement>(),
|
params, &void_type, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
|
||||||
});
|
});
|
||||||
|
@ -101,8 +101,8 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
|
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
|
||||||
params, &i32, body, ast::FunctionDecorationList{});
|
params, &i32, body, ast::FunctionDecorationList{});
|
||||||
|
@ -121,7 +121,7 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
|
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
|
||||||
params, &i32, create<ast::BlockStatement>(),
|
params, &i32, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
mod()->AddFunction(func);
|
mod()->AddFunction(func);
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod()->RegisterSymbol("func"), "func", params, &void_type, body,
|
Source{}, mod()->RegisterSymbol("func"), "func", params, &void_type, body,
|
||||||
|
@ -155,7 +155,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
auto* return_expr = create<ast::ScalarConstructorExpression>(
|
auto* return_expr = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
ast::type::F32 f32;
|
ast::type::F32 f32;
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
auto* return_expr = create<ast::ScalarConstructorExpression>(
|
auto* return_expr = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
auto* return_expr = create<ast::ScalarConstructorExpression>(
|
auto* return_expr = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
|
||||||
params, &i32, body, ast::FunctionDecorationList{});
|
params, &i32, body, ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ast::VariableList params_copy;
|
ast::VariableList params_copy;
|
||||||
auto* body_copy = create<ast::BlockStatement>();
|
auto* body_copy = create<ast::BlockStatement>(Source{});
|
||||||
auto* return_expr_copy = create<ast::ScalarConstructorExpression>(
|
auto* return_expr_copy = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
|
@ -243,8 +243,8 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
|
||||||
"func"),
|
"func"),
|
||||||
call_params);
|
call_params);
|
||||||
ast::VariableList params0;
|
ast::VariableList params0;
|
||||||
auto* body0 = create<ast::BlockStatement>();
|
auto* body0 = create<ast::BlockStatement>(Source{});
|
||||||
body0->append(create<ast::CallStatement>(call_expr));
|
body0->append(create<ast::CallStatement>(Source{}, call_expr));
|
||||||
body0->append(create<ast::ReturnStatement>(Source{}));
|
body0->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func0 = create<ast::Function>(Source{}, mod()->RegisterSymbol("func"),
|
auto* func0 = create<ast::Function>(Source{}, mod()->RegisterSymbol("func"),
|
||||||
"func", params0, &f32, body0,
|
"func", params0, &f32, body0,
|
||||||
|
@ -275,8 +275,8 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableList params0;
|
ast::VariableList params0;
|
||||||
auto* body0 = create<ast::BlockStatement>();
|
auto* body0 = create<ast::BlockStatement>(Source{});
|
||||||
body0->append(create<ast::VariableDeclStatement>(var));
|
body0->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
auto* return_expr = create<ast::ScalarConstructorExpression>(
|
auto* return_expr = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
|
||||||
auto* return_expr = create<ast::ScalarConstructorExpression>(
|
auto* return_expr = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 0));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 0));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}, return_expr));
|
body->append(create<ast::ReturnStatement>(Source{}, return_expr));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("vtx_main"),
|
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("vtx_main"),
|
||||||
|
@ -329,7 +329,7 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
|
||||||
false, // is_const
|
false, // is_const
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("vtx_func"),
|
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("vtx_func"),
|
||||||
|
@ -352,7 +352,7 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
|
||||||
// fn main() -> void { return; }
|
// fn main() -> void { return; }
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("main"), "main",
|
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("main"), "main",
|
||||||
|
@ -375,7 +375,7 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
|
||||||
// fn vtx_func() -> void { return; }
|
// fn vtx_func() -> void { return; }
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params,
|
Source{}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params,
|
||||||
|
@ -393,7 +393,7 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
|
||||||
// fn vtx_func() -> void { return; }
|
// fn vtx_func() -> void { return; }
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params,
|
Source{}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params,
|
||||||
|
|
|
@ -103,7 +103,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) {
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs));
|
Source{Source::Location{12, 34}}, lhs, rhs));
|
||||||
|
|
||||||
|
@ -199,8 +199,8 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs));
|
Source{Source::Location{12, 34}}, lhs, rhs));
|
||||||
|
|
||||||
|
@ -234,8 +234,8 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
|
||||||
|
|
||||||
ast::BlockStatement block;
|
ast::BlockStatement block(Source{});
|
||||||
block.append(create<ast::VariableDeclStatement>(var));
|
block.append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
block.append(create<ast::AssignmentStatement>(
|
block.append(create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs));
|
Source{Source::Location{12, 34}}, lhs, rhs));
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs));
|
Source{Source::Location{12, 34}}, lhs, rhs));
|
||||||
|
|
||||||
|
@ -379,7 +379,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs));
|
Source{Source::Location{12, 34}}, lhs, rhs));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
@ -415,15 +415,15 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
|
||||||
ast::type::Bool bool_type;
|
ast::type::Bool bool_type;
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
|
|
||||||
auto* lhs = create<ast::IdentifierExpression>(
|
auto* lhs = create<ast::IdentifierExpression>(
|
||||||
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
|
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
|
||||||
|
|
||||||
auto* outer_body = create<ast::BlockStatement>();
|
auto* outer_body = create<ast::BlockStatement>(Source{});
|
||||||
outer_body->append(
|
outer_body->append(
|
||||||
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
||||||
outer_body->append(create<ast::AssignmentStatement>(
|
outer_body->append(create<ast::AssignmentStatement>(
|
||||||
|
@ -461,12 +461,12 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
|
||||||
ast::type::Bool bool_type;
|
ast::type::Bool bool_type;
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs));
|
Source{Source::Location{12, 34}}, lhs, rhs));
|
||||||
|
|
||||||
auto* outer_body = create<ast::BlockStatement>();
|
auto* outer_body = create<ast::BlockStatement>(Source{});
|
||||||
outer_body->append(create<ast::VariableDeclStatement>(var));
|
outer_body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
outer_body->append(
|
outer_body->append(
|
||||||
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
||||||
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
||||||
|
@ -564,8 +564,8 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs));
|
Source{Source::Location{12, 34}}, lhs, rhs));
|
||||||
|
|
||||||
|
@ -609,7 +609,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
|
||||||
create<ast::FloatLiteral>(Source{}, &f32, 2.0)), // constructor
|
create<ast::FloatLiteral>(Source{}, &f32, 2.0)), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(
|
body->append(create<ast::VariableDeclStatement>(
|
||||||
Source{Source::Location{12, 34}}, var));
|
Source{Source::Location{12, 34}}, var));
|
||||||
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"),
|
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"),
|
||||||
|
@ -655,8 +655,8 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::VariableDeclStatement>(
|
body->append(create<ast::VariableDeclStatement>(
|
||||||
Source{Source::Location{12, 34}}, var_a_float));
|
Source{Source::Location{12, 34}}, var_a_float));
|
||||||
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"),
|
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"),
|
||||||
|
@ -691,8 +691,8 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
|
||||||
ast::type::Bool bool_type;
|
ast::type::Bool bool_type;
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
|
|
||||||
auto* var_a_float = create<ast::Variable>(
|
auto* var_a_float = create<ast::Variable>(
|
||||||
Source{}, // source
|
Source{}, // source
|
||||||
|
@ -705,7 +705,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
|
||||||
create<ast::FloatLiteral>(Source{}, &f32, 3.14)), // constructor
|
create<ast::FloatLiteral>(Source{}, &f32, 3.14)), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* outer_body = create<ast::BlockStatement>();
|
auto* outer_body = create<ast::BlockStatement>(Source{});
|
||||||
outer_body->append(
|
outer_body->append(
|
||||||
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
||||||
outer_body->append(create<ast::VariableDeclStatement>(
|
outer_body->append(create<ast::VariableDeclStatement>(
|
||||||
|
@ -748,12 +748,12 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
|
||||||
ast::type::Bool bool_type;
|
ast::type::Bool bool_type;
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(
|
body->append(create<ast::VariableDeclStatement>(
|
||||||
Source{Source::Location{12, 34}}, var));
|
Source{Source::Location{12, 34}}, var));
|
||||||
|
|
||||||
auto* outer_body = create<ast::BlockStatement>();
|
auto* outer_body = create<ast::BlockStatement>(Source{});
|
||||||
outer_body->append(create<ast::VariableDeclStatement>(var_a_float));
|
outer_body->append(create<ast::VariableDeclStatement>(Source{}, var_a_float));
|
||||||
outer_body->append(
|
outer_body->append(
|
||||||
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
||||||
|
|
||||||
|
@ -790,7 +790,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableList params0;
|
ast::VariableList params0;
|
||||||
auto* body0 = create<ast::BlockStatement>();
|
auto* body0 = create<ast::BlockStatement>(Source{});
|
||||||
body0->append(create<ast::VariableDeclStatement>(
|
body0->append(create<ast::VariableDeclStatement>(
|
||||||
Source{Source::Location{12, 34}}, var0));
|
Source{Source::Location{12, 34}}, var0));
|
||||||
body0->append(create<ast::ReturnStatement>(Source{}));
|
body0->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
@ -799,7 +799,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ast::VariableList params1;
|
ast::VariableList params1;
|
||||||
auto* body1 = create<ast::BlockStatement>();
|
auto* body1 = create<ast::BlockStatement>(Source{});
|
||||||
body1->append(create<ast::VariableDeclStatement>(
|
body1->append(create<ast::VariableDeclStatement>(
|
||||||
Source{Source::Location{13, 34}}, var1));
|
Source{Source::Location{13, 34}}, var1));
|
||||||
body1->append(create<ast::ReturnStatement>(Source{}));
|
body1->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
@ -838,8 +838,8 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs));
|
Source{Source::Location{12, 34}}, lhs, rhs));
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(
|
body->append(create<ast::VariableDeclStatement>(
|
||||||
Source{Source::Location{12, 34}}, var));
|
Source{Source::Location{12, 34}}, var));
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) {
|
||||||
Source{}, mod.RegisterSymbol("lhs"), "lhs");
|
Source{}, mod.RegisterSymbol("lhs"), "lhs");
|
||||||
auto* rhs = create<ast::IdentifierExpression>(
|
auto* rhs = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
||||||
ast::AssignmentStatement assign(lhs, rhs);
|
ast::AssignmentStatement assign(Source{}, lhs, rhs);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -464,17 +464,18 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
|
||||||
|
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::ScalarConstructorExpression>(
|
Source{}, create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))));
|
||||||
auto* else_stmt = create<ast::ElseStatement>(body);
|
auto* else_stmt = create<ast::ElseStatement>(Source{}, nullptr, body);
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::ScalarConstructorExpression>(
|
Source{}, create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
|
||||||
auto* else_if_stmt = create<ast::ElseStatement>(
|
auto* else_if_stmt = create<ast::ElseStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::BinaryExpression>(
|
create<ast::BinaryExpression>(
|
||||||
Source{}, ast::BinaryOp::kLogicalOr,
|
Source{}, ast::BinaryOp::kLogicalOr,
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
|
||||||
|
@ -483,7 +484,7 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
|
||||||
"c")),
|
"c")),
|
||||||
body);
|
body);
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::ScalarConstructorExpression>(
|
Source{}, create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
|
||||||
|
@ -563,11 +564,12 @@ TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) {
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"), "d");
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"), "d");
|
||||||
|
|
||||||
ast::AssignmentStatement expr(
|
ast::AssignmentStatement expr(
|
||||||
a, create<ast::BinaryExpression>(
|
Source{}, a,
|
||||||
Source{}, ast::BinaryOp::kLogicalAnd,
|
create<ast::BinaryExpression>(
|
||||||
create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kLogicalOr,
|
Source{}, ast::BinaryOp::kLogicalAnd,
|
||||||
b, c),
|
create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kLogicalOr, b,
|
||||||
d));
|
c),
|
||||||
|
d));
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
|
||||||
EXPECT_EQ(result(), R"(bool _tint_tmp = b;
|
EXPECT_EQ(result(), R"(bool _tint_tmp = b;
|
||||||
|
@ -606,7 +608,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) {
|
||||||
d), // constructor
|
d), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement expr(var);
|
ast::VariableDeclStatement expr(Source{}, var);
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
|
||||||
EXPECT_EQ(result(), R"(bool _tint_tmp = b;
|
EXPECT_EQ(result(), R"(bool _tint_tmp = b;
|
||||||
|
@ -657,9 +659,10 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
|
||||||
|
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("foo"), "foo",
|
||||||
Source{}, mod.RegisterSymbol("foo"), "foo", ast::VariableList{},
|
ast::VariableList{}, &void_type,
|
||||||
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
|
create<ast::BlockStatement>(Source{}),
|
||||||
|
ast::FunctionDecorationList{});
|
||||||
mod.AddFunction(func);
|
mod.AddFunction(func);
|
||||||
|
|
||||||
ast::ExpressionList params;
|
ast::ExpressionList params;
|
||||||
|
@ -688,11 +691,12 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"),
|
||||||
"d"))));
|
"d"))));
|
||||||
|
|
||||||
ast::CallStatement expr(create<ast::CallExpression>(
|
ast::CallStatement expr(Source{},
|
||||||
Source{},
|
create<ast::CallExpression>(
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
Source{},
|
||||||
"foo"),
|
create<ast::IdentifierExpression>(
|
||||||
params));
|
Source{}, mod.RegisterSymbol("foo"), "foo"),
|
||||||
|
params));
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
|
||||||
EXPECT_EQ(result(), R"(bool _tint_tmp = a;
|
EXPECT_EQ(result(), R"(bool _tint_tmp = a;
|
||||||
|
|
|
@ -26,8 +26,8 @@ namespace {
|
||||||
using HlslGeneratorImplTest_Block = TestHelper;
|
using HlslGeneratorImplTest_Block = TestHelper;
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
|
TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
|
||||||
ast::BlockStatement b;
|
ast::BlockStatement b(Source{});
|
||||||
b.append(create<ast::DiscardStatement>());
|
b.append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Block, Emit_Block_WithoutNewline) {
|
TEST_F(HlslGeneratorImplTest_Block, Emit_Block_WithoutNewline) {
|
||||||
ast::BlockStatement b;
|
ast::BlockStatement b(Source{});
|
||||||
b.append(create<ast::DiscardStatement>());
|
b.append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace {
|
||||||
using HlslGeneratorImplTest_Break = TestHelper;
|
using HlslGeneratorImplTest_Break = TestHelper;
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Break, Emit_Break) {
|
TEST_F(HlslGeneratorImplTest_Break, Emit_Break) {
|
||||||
ast::BreakStatement b;
|
ast::BreakStatement b(Source{});
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,10 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
|
||||||
Source{}, mod.RegisterSymbol("my_func"), "my_func");
|
Source{}, mod.RegisterSymbol("my_func"), "my_func");
|
||||||
ast::CallExpression call(Source{}, id, {});
|
ast::CallExpression call(Source{}, id, {});
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
|
"my_func", ast::VariableList{}, &void_type,
|
||||||
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
|
create<ast::BlockStatement>(Source{}),
|
||||||
|
ast::FunctionDecorationList{});
|
||||||
mod.AddFunction(func);
|
mod.AddFunction(func);
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
|
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"));
|
Source{}, mod.RegisterSymbol("param2"), "param2"));
|
||||||
ast::CallExpression call(Source{}, id, params);
|
ast::CallExpression call(Source{}, id, params);
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
|
"my_func", ast::VariableList{}, &void_type,
|
||||||
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
|
create<ast::BlockStatement>(Source{}),
|
||||||
|
ast::FunctionDecorationList{});
|
||||||
mod.AddFunction(func);
|
mod.AddFunction(func);
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
|
||||||
|
@ -76,11 +78,13 @@ TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
|
||||||
Source{}, mod.RegisterSymbol("param1"), "param1"));
|
Source{}, mod.RegisterSymbol("param1"), "param1"));
|
||||||
params.push_back(create<ast::IdentifierExpression>(
|
params.push_back(create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("param2"), "param2"));
|
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>(
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
|
"my_func", ast::VariableList{}, &void_type,
|
||||||
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
|
create<ast::BlockStatement>(Source{}),
|
||||||
|
ast::FunctionDecorationList{});
|
||||||
mod.AddFunction(func);
|
mod.AddFunction(func);
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &call)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &call)) << gen.error();
|
||||||
|
|
|
@ -33,12 +33,12 @@ using HlslGeneratorImplTest_Case = TestHelper;
|
||||||
TEST_F(HlslGeneratorImplTest_Case, Emit_Case) {
|
TEST_F(HlslGeneratorImplTest_Case, Emit_Case) {
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::BreakStatement>());
|
body->append(create<ast::BreakStatement>(Source{}));
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||||
ast::CaseStatement c(lit, body);
|
ast::CaseStatement c(Source{}, lit, body);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||||
ast::CaseStatement c(lit, create<ast::BlockStatement>());
|
ast::CaseStatement c(Source{}, lit, create<ast::BlockStatement>(Source{}));
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -68,12 +68,12 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
|
||||||
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
|
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::FallthroughStatement>());
|
body->append(create<ast::FallthroughStatement>(Source{}));
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||||
ast::CaseStatement c(lit, body);
|
ast::CaseStatement c(Source{}, lit, body);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -87,13 +87,13 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
|
||||||
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
|
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::BreakStatement>());
|
body->append(create<ast::BreakStatement>(Source{}));
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 6));
|
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 6));
|
||||||
ast::CaseStatement c(lit, body);
|
ast::CaseStatement c(Source{}, lit, body);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -106,9 +106,9 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) {
|
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) {
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::BreakStatement>());
|
body->append(create<ast::BreakStatement>(Source{}));
|
||||||
ast::CaseStatement c(body);
|
ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace {
|
||||||
using HlslGeneratorImplTest_Continue = TestHelper;
|
using HlslGeneratorImplTest_Continue = TestHelper;
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Continue, Emit_Continue) {
|
TEST_F(HlslGeneratorImplTest_Continue, Emit_Continue) {
|
||||||
ast::ContinueStatement c;
|
ast::ContinueStatement c(Source{});
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace {
|
||||||
using HlslGeneratorImplTest_Discard = TestHelper;
|
using HlslGeneratorImplTest_Discard = TestHelper;
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Discard, Emit_Discard) {
|
TEST_F(HlslGeneratorImplTest_Discard, Emit_Discard) {
|
||||||
ast::DiscardStatement stmt;
|
ast::DiscardStatement stmt(Source{});
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -82,13 +82,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo"),
|
"foo"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
|
@ -159,13 +161,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo"),
|
"foo"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
|
@ -236,13 +240,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo"),
|
"foo"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
|
@ -312,13 +318,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo"),
|
"foo"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
|
@ -385,13 +393,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo"),
|
"foo"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
|
@ -453,13 +463,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo"),
|
"foo"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
|
@ -528,8 +540,9 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
mod.AddGlobalVariable(depth_var);
|
mod.AddGlobalVariable(depth_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
||||||
"depth"),
|
"depth"),
|
||||||
create<ast::MemberAccessorExpression>(
|
create<ast::MemberAccessorExpression>(
|
||||||
|
|
|
@ -55,7 +55,7 @@ using HlslGeneratorImplTest_Function = TestHelper;
|
||||||
TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
|
TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
"my_func", ast::VariableList{}, &void_type,
|
"my_func", ast::VariableList{}, &void_type,
|
||||||
|
@ -75,7 +75,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
|
||||||
TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
|
TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("GeometryShader"), "GeometryShader",
|
Source{}, mod.RegisterSymbol("GeometryShader"), "GeometryShader",
|
||||||
|
@ -116,7 +116,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
|
||||||
|
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
"my_func", params, &void_type, body,
|
"my_func", params, &void_type, body,
|
||||||
|
@ -169,8 +169,9 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
|
@ -241,8 +242,9 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
mod.AddGlobalVariable(depth_var);
|
mod.AddGlobalVariable(depth_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
||||||
"depth"),
|
"depth"),
|
||||||
create<ast::MemberAccessorExpression>(
|
create<ast::MemberAccessorExpression>(
|
||||||
|
@ -317,8 +319,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
"x")), // constructor
|
"x")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
|
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
|
||||||
|
@ -394,8 +396,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
"x")), // constructor
|
"x")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
|
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
|
||||||
|
@ -473,8 +475,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
"b")), // constructor
|
"b")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
|
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
|
||||||
|
@ -548,8 +550,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
"b")), // constructor
|
"b")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
|
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
|
||||||
|
@ -621,7 +623,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f)));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f)));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(assign);
|
body->append(assign);
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
|
@ -705,13 +707,15 @@ TEST_F(
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("val"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("val"),
|
||||||
"val"),
|
"val"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("param"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("param"),
|
||||||
|
@ -729,8 +733,9 @@ TEST_F(
|
||||||
expr.push_back(create<ast::ScalarConstructorExpression>(
|
expr.push_back(create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::CallExpression>(
|
create<ast::CallExpression>(
|
||||||
|
@ -805,7 +810,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::IdentifierExpression>(
|
Source{}, create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("param"), "param")));
|
Source{}, mod.RegisterSymbol("param"), "param")));
|
||||||
|
@ -819,8 +824,9 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
expr.push_back(create<ast::ScalarConstructorExpression>(
|
expr.push_back(create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
||||||
"depth"),
|
"depth"),
|
||||||
create<ast::CallExpression>(
|
create<ast::CallExpression>(
|
||||||
|
@ -903,8 +909,9 @@ TEST_F(
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
||||||
"depth"),
|
"depth"),
|
||||||
create<ast::MemberAccessorExpression>(
|
create<ast::MemberAccessorExpression>(
|
||||||
|
@ -926,8 +933,9 @@ TEST_F(
|
||||||
expr.push_back(create<ast::ScalarConstructorExpression>(
|
expr.push_back(create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
||||||
"depth"),
|
"depth"),
|
||||||
create<ast::CallExpression>(
|
create<ast::CallExpression>(
|
||||||
|
@ -1001,7 +1009,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::MemberAccessorExpression>(
|
Source{}, create<ast::MemberAccessorExpression>(
|
||||||
Source{},
|
Source{},
|
||||||
|
@ -1032,8 +1040,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
expr), // constructor
|
expr), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
|
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
|
||||||
|
@ -1095,7 +1103,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::MemberAccessorExpression>(
|
Source{}, create<ast::MemberAccessorExpression>(
|
||||||
Source{},
|
Source{},
|
||||||
|
@ -1126,8 +1134,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
expr), // constructor
|
expr), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
|
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
|
||||||
|
@ -1176,14 +1184,15 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))));
|
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{}));
|
list->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
body->append(create<ast::IfStatement>(
|
body->append(create<ast::IfStatement>(
|
||||||
|
@ -1229,7 +1238,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("GeometryShader"), "GeometryShader",
|
Source{}, mod.RegisterSymbol("GeometryShader"), "GeometryShader",
|
||||||
ast::VariableList{}, &void_type, create<ast::BlockStatement>(),
|
ast::VariableList{}, &void_type, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
|
||||||
});
|
});
|
||||||
|
@ -1248,7 +1257,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,
|
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,
|
||||||
|
@ -1273,7 +1282,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,
|
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,
|
||||||
|
@ -1310,7 +1319,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
|
||||||
|
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
"my_func", params, &void_type, body,
|
"my_func", params, &void_type, body,
|
||||||
|
@ -1394,8 +1403,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
"d")), // constructor
|
"d")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("a"), "a", params, &void_type, body,
|
Source{}, mod.RegisterSymbol("a"), "a", params, &void_type, body,
|
||||||
|
@ -1423,8 +1432,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
"d")), // constructor
|
"d")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("b"), "b", params, &void_type, body,
|
Source{}, mod.RegisterSymbol("b"), "b", params, &void_type, body,
|
||||||
|
|
|
@ -29,7 +29,7 @@ using HlslGeneratorImplTest_If = TestHelper;
|
||||||
TEST_F(HlslGeneratorImplTest_If, Emit_If) {
|
TEST_F(HlslGeneratorImplTest_If, Emit_If) {
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("cond"), "cond");
|
Source{}, mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
|
ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
|
||||||
|
@ -45,16 +45,17 @@ TEST_F(HlslGeneratorImplTest_If, Emit_If) {
|
||||||
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
|
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
|
||||||
auto* else_cond = create<ast::IdentifierExpression>(
|
auto* else_cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
|
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
|
||||||
auto* else_body = create<ast::BlockStatement>();
|
auto* else_body = create<ast::BlockStatement>(Source{});
|
||||||
else_body->append(create<ast::ReturnStatement>(Source{}));
|
else_body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("cond"), "cond");
|
Source{}, mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
ast::IfStatement i(Source{}, cond, body,
|
ast::IfStatement i(
|
||||||
{create<ast::ElseStatement>(else_cond, else_body)});
|
Source{}, cond, body,
|
||||||
|
{create<ast::ElseStatement>(Source{}, else_cond, else_body)});
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -70,16 +71,17 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
|
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
|
||||||
auto* else_body = create<ast::BlockStatement>();
|
auto* else_body = create<ast::BlockStatement>(Source{});
|
||||||
else_body->append(create<ast::ReturnStatement>(Source{}));
|
else_body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("cond"), "cond");
|
Source{}, mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
ast::IfStatement i(Source{}, cond, body,
|
ast::IfStatement i(
|
||||||
{create<ast::ElseStatement>(else_body)});
|
Source{}, cond, body,
|
||||||
|
{create<ast::ElseStatement>(Source{}, nullptr, else_body)});
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -96,22 +98,23 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
|
||||||
auto* else_cond = create<ast::IdentifierExpression>(
|
auto* else_cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
|
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
|
||||||
|
|
||||||
auto* else_body = create<ast::BlockStatement>();
|
auto* else_body = create<ast::BlockStatement>(Source{});
|
||||||
else_body->append(create<ast::ReturnStatement>(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{}));
|
else_body_2->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("cond"), "cond");
|
Source{}, mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(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();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,10 @@ namespace {
|
||||||
using HlslGeneratorImplTest_Loop = TestHelper;
|
using HlslGeneratorImplTest_Loop = TestHelper;
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
|
TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::DiscardStatement>());
|
body->append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
ast::LoopStatement l(body, {});
|
ast::LoopStatement l(Source{}, body, {});
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &l)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &l)) << gen.error();
|
||||||
|
@ -48,13 +48,13 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
|
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::DiscardStatement>());
|
body->append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* continuing = create<ast::BlockStatement>();
|
auto* continuing = create<ast::BlockStatement>(Source{});
|
||||||
continuing->append(create<ast::ReturnStatement>(Source{}));
|
continuing->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
ast::LoopStatement l(body, continuing);
|
ast::LoopStatement l(Source{}, body, continuing);
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &l)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &l)) << gen.error();
|
||||||
|
@ -75,15 +75,15 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
|
||||||
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
|
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
|
||||||
ast::type::F32 f32;
|
ast::type::F32 f32;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::DiscardStatement>());
|
body->append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* continuing = create<ast::BlockStatement>();
|
auto* continuing = create<ast::BlockStatement>(Source{});
|
||||||
continuing->append(create<ast::ReturnStatement>(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);
|
body->append(inner);
|
||||||
|
|
||||||
auto* lhs = create<ast::IdentifierExpression>(
|
auto* lhs = create<ast::IdentifierExpression>(
|
||||||
|
@ -91,10 +91,10 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
|
||||||
auto* rhs = create<ast::IdentifierExpression>(
|
auto* rhs = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
||||||
|
|
||||||
continuing = create<ast::BlockStatement>();
|
continuing = create<ast::BlockStatement>(Source{});
|
||||||
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
|
continuing->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
|
||||||
|
|
||||||
ast::LoopStatement outer(body, continuing);
|
ast::LoopStatement outer(Source{}, body, continuing);
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &outer)) << gen.error();
|
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
|
create<ast::FloatLiteral>(Source{}, &f32, 2.4)), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::VariableDeclStatement>(
|
body->append(create<ast::VariableDeclStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::Variable>(Source{}, // source
|
create<ast::Variable>(Source{}, // source
|
||||||
"other", // name
|
"other", // name
|
||||||
ast::StorageClass::kFunction, // storage_class
|
ast::StorageClass::kFunction, // storage_class
|
||||||
|
@ -173,10 +174,10 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
|
||||||
auto* rhs = create<ast::IdentifierExpression>(
|
auto* rhs = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
||||||
|
|
||||||
auto* continuing = create<ast::BlockStatement>();
|
auto* continuing = create<ast::BlockStatement>(Source{});
|
||||||
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
|
continuing->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
|
||||||
|
|
||||||
ast::LoopStatement outer(body, continuing);
|
ast::LoopStatement outer(Source{}, body, continuing);
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &outer)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &outer)) << gen.error();
|
||||||
|
|
|
@ -244,7 +244,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
auto* rhs =
|
auto* rhs =
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b");
|
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(coord_var);
|
||||||
td.RegisterVariableForTesting(b_var);
|
td.RegisterVariableForTesting(b_var);
|
||||||
|
@ -311,7 +311,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &mat,
|
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &mat,
|
||||||
ast::ExpressionList{});
|
ast::ExpressionList{});
|
||||||
|
|
||||||
ast::AssignmentStatement assign(lhs, rhs);
|
ast::AssignmentStatement assign(Source{}, lhs, rhs);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
td.RegisterVariableForTesting(coord_var);
|
||||||
gen.register_global(coord_var);
|
gen.register_global(coord_var);
|
||||||
|
@ -730,7 +730,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
"b"));
|
"b"));
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f));
|
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(td.DetermineResultType(&assign));
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||||
|
@ -791,7 +791,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
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(td.DetermineResultType(&assign)) << td.error();
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||||
|
@ -849,7 +849,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
"a"));
|
"a"));
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
|
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(td.DetermineResultType(&assign));
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||||
|
@ -973,7 +973,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
"b"));
|
"b"));
|
||||||
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &fvec3, values);
|
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(td.DetermineResultType(&assign));
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||||
|
@ -1408,7 +1408,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &fvec3, values);
|
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(td.DetermineResultType(&assign));
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||||
|
@ -1500,7 +1500,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &i32, 1.f));
|
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(td.DetermineResultType(&assign));
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||||
|
|
|
@ -31,18 +31,19 @@ namespace {
|
||||||
using HlslGeneratorImplTest_Switch = TestHelper;
|
using HlslGeneratorImplTest_Switch = TestHelper;
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
|
TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
|
||||||
auto* def_body = create<ast::BlockStatement>();
|
auto* def_body = create<ast::BlockStatement>(Source{});
|
||||||
def_body->append(create<ast::BreakStatement>());
|
def_body->append(create<ast::BreakStatement>(Source{}));
|
||||||
auto* def = create<ast::CaseStatement>(def_body);
|
auto* def =
|
||||||
|
create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, def_body);
|
||||||
|
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
ast::CaseSelectorList case_val;
|
ast::CaseSelectorList case_val;
|
||||||
case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||||
|
|
||||||
auto* case_body = create<ast::BlockStatement>();
|
auto* case_body = create<ast::BlockStatement>(Source{});
|
||||||
case_body->append(create<ast::BreakStatement>());
|
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;
|
ast::CaseStatementList body;
|
||||||
body.push_back(case_stmt);
|
body.push_back(case_stmt);
|
||||||
|
@ -50,7 +51,7 @@ TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
|
||||||
|
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("cond"), "cond");
|
Source{}, mod.RegisterSymbol("cond"), "cond");
|
||||||
ast::SwitchStatement s(cond, body);
|
ast::SwitchStatement s(Source{}, cond, body);
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &s)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &s)) << gen.error();
|
||||||
|
|
|
@ -29,9 +29,10 @@ using HlslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest, Generate) {
|
TEST_F(HlslGeneratorImplTest, Generate) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
|
"my_func", ast::VariableList{}, &void_type,
|
||||||
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
|
create<ast::BlockStatement>(Source{}),
|
||||||
|
ast::FunctionDecorationList{});
|
||||||
mod.AddFunction(func);
|
mod.AddFunction(func);
|
||||||
|
|
||||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||||
|
|
|
@ -43,7 +43,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||||
|
@ -61,7 +61,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||||
|
@ -81,7 +81,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Array) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||||
|
@ -100,7 +100,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||||
|
@ -118,7 +118,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||||
|
@ -140,7 +140,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
|
||||||
ident, // constructor
|
ident, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||||
EXPECT_EQ(result(), R"(float a = initializer;
|
EXPECT_EQ(result(), R"(float a = initializer;
|
||||||
)");
|
)");
|
||||||
|
@ -164,7 +164,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
|
||||||
zero_vec, // constructor
|
zero_vec, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||||
EXPECT_EQ(result(), R"(float3 a = float3(0.0f);
|
EXPECT_EQ(result(), R"(float3 a = float3(0.0f);
|
||||||
)");
|
)");
|
||||||
|
@ -188,7 +188,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
|
||||||
zero_mat, // constructor
|
zero_mat, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||||
EXPECT_EQ(result(),
|
EXPECT_EQ(result(),
|
||||||
R"(float3x2 a = float3x2(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
|
R"(float3x2 a = float3x2(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
|
@ -34,7 +34,7 @@ TEST_F(MslGeneratorImplTest, Emit_Assign) {
|
||||||
Source{}, mod.RegisterSymbol("lhs"), "lhs");
|
Source{}, mod.RegisterSymbol("lhs"), "lhs");
|
||||||
auto* rhs = create<ast::IdentifierExpression>(
|
auto* rhs = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
||||||
ast::AssignmentStatement assign(lhs, rhs);
|
ast::AssignmentStatement assign(Source{}, lhs, rhs);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@ namespace {
|
||||||
using MslGeneratorImplTest = TestHelper;
|
using MslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Block) {
|
TEST_F(MslGeneratorImplTest, Emit_Block) {
|
||||||
ast::BlockStatement b;
|
ast::BlockStatement b(Source{});
|
||||||
b.append(create<ast::DiscardStatement>());
|
b.append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ TEST_F(MslGeneratorImplTest, Emit_Block) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Block_WithoutNewline) {
|
TEST_F(MslGeneratorImplTest, Emit_Block_WithoutNewline) {
|
||||||
ast::BlockStatement b;
|
ast::BlockStatement b(Source{});
|
||||||
b.append(create<ast::DiscardStatement>());
|
b.append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace {
|
||||||
using MslGeneratorImplTest = TestHelper;
|
using MslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Break) {
|
TEST_F(MslGeneratorImplTest, Emit_Break) {
|
||||||
ast::BreakStatement b;
|
ast::BreakStatement b(Source{});
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
|
||||||
Source{}, mod.RegisterSymbol("my_func"), "my_func");
|
Source{}, mod.RegisterSymbol("my_func"), "my_func");
|
||||||
ast::CallExpression call(Source{}, id, {});
|
ast::CallExpression call(Source{}, id, {});
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
|
"my_func", ast::VariableList{}, &void_type,
|
||||||
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
|
create<ast::BlockStatement>(Source{}),
|
||||||
|
ast::FunctionDecorationList{});
|
||||||
mod.AddFunction(func);
|
mod.AddFunction(func);
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
|
||||||
|
@ -59,9 +60,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
|
||||||
Source{}, mod.RegisterSymbol("param2"), "param2"));
|
Source{}, mod.RegisterSymbol("param2"), "param2"));
|
||||||
ast::CallExpression call(Source{}, id, params);
|
ast::CallExpression call(Source{}, id, params);
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
|
"my_func", ast::VariableList{}, &void_type,
|
||||||
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
|
create<ast::BlockStatement>(Source{}),
|
||||||
|
ast::FunctionDecorationList{});
|
||||||
mod.AddFunction(func);
|
mod.AddFunction(func);
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
|
||||||
|
@ -78,11 +80,13 @@ TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
|
||||||
Source{}, mod.RegisterSymbol("param1"), "param1"));
|
Source{}, mod.RegisterSymbol("param1"), "param1"));
|
||||||
params.push_back(create<ast::IdentifierExpression>(
|
params.push_back(create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("param2"), "param2"));
|
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>(
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
|
"my_func", ast::VariableList{}, &void_type,
|
||||||
&void_type, create<ast::BlockStatement>(), ast::FunctionDecorationList{});
|
create<ast::BlockStatement>(Source{}),
|
||||||
|
ast::FunctionDecorationList{});
|
||||||
mod.AddFunction(func);
|
mod.AddFunction(func);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
|
@ -35,12 +35,12 @@ using MslGeneratorImplTest = TestHelper;
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Case) {
|
TEST_F(MslGeneratorImplTest, Emit_Case) {
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::BreakStatement>());
|
body->append(create<ast::BreakStatement>(Source{}));
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||||
ast::CaseStatement c(lit, body);
|
ast::CaseStatement c(Source{}, lit, body);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||||
ast::CaseStatement c(lit, create<ast::BlockStatement>());
|
ast::CaseStatement c(Source{}, lit, create<ast::BlockStatement>(Source{}));
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -70,12 +70,12 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
|
TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::FallthroughStatement>());
|
body->append(create<ast::FallthroughStatement>(Source{}));
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||||
ast::CaseStatement c(lit, body);
|
ast::CaseStatement c(Source{}, lit, body);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -89,13 +89,13 @@ TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::BreakStatement>());
|
body->append(create<ast::BreakStatement>(Source{}));
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 6));
|
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 6));
|
||||||
ast::CaseStatement c(lit, body);
|
ast::CaseStatement c(Source{}, lit, body);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -108,9 +108,9 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Case_Default) {
|
TEST_F(MslGeneratorImplTest, Emit_Case_Default) {
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::BreakStatement>());
|
body->append(create<ast::BreakStatement>(Source{}));
|
||||||
ast::CaseStatement c(body);
|
ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace {
|
||||||
using MslGeneratorImplTest = TestHelper;
|
using MslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Continue) {
|
TEST_F(MslGeneratorImplTest, Emit_Continue) {
|
||||||
ast::ContinueStatement c;
|
ast::ContinueStatement c(Source{});
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace {
|
||||||
using MslGeneratorImplTest = TestHelper;
|
using MslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Discard) {
|
TEST_F(MslGeneratorImplTest, Emit_Discard) {
|
||||||
ast::DiscardStatement stmt;
|
ast::DiscardStatement stmt(Source{});
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -81,13 +81,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo"),
|
"foo"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
|
@ -155,13 +157,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo"),
|
"foo"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
|
@ -229,13 +233,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo"),
|
"foo"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
|
@ -302,13 +308,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo"),
|
"foo"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
|
@ -373,13 +381,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo"),
|
"foo"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
|
@ -439,13 +449,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo"),
|
"foo"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
|
@ -512,8 +524,9 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
||||||
"depth"),
|
"depth"),
|
||||||
create<ast::MemberAccessorExpression>(
|
create<ast::MemberAccessorExpression>(
|
||||||
|
|
|
@ -58,7 +58,7 @@ using MslGeneratorImplTest = TestHelper;
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Function) {
|
TEST_F(MslGeneratorImplTest, Emit_Function) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
"my_func", ast::VariableList{}, &void_type,
|
"my_func", ast::VariableList{}, &void_type,
|
||||||
|
@ -80,7 +80,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function) {
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) {
|
TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("main"),
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("main"),
|
||||||
"main", ast::VariableList{}, &void_type,
|
"main", ast::VariableList{}, &void_type,
|
||||||
|
@ -123,7 +123,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) {
|
||||||
|
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
"my_func", params, &void_type, body,
|
"my_func", params, &void_type, body,
|
||||||
|
@ -177,8 +177,9 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
|
@ -252,8 +253,9 @@ TEST_F(MslGeneratorImplTest,
|
||||||
mod.AddGlobalVariable(depth_var);
|
mod.AddGlobalVariable(depth_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
||||||
"depth"),
|
"depth"),
|
||||||
create<ast::MemberAccessorExpression>(
|
create<ast::MemberAccessorExpression>(
|
||||||
|
@ -328,8 +330,8 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
|
||||||
"x")), // constructor
|
"x")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
|
@ -408,8 +410,8 @@ TEST_F(MslGeneratorImplTest,
|
||||||
"b")), // constructor
|
"b")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
|
@ -493,8 +495,8 @@ TEST_F(MslGeneratorImplTest,
|
||||||
"b")), // constructor
|
"b")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
|
@ -584,13 +586,15 @@ TEST_F(
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
|
||||||
"foo")));
|
"foo")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("val"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("val"),
|
||||||
"val"),
|
"val"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("param"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("param"),
|
||||||
|
@ -608,8 +612,9 @@ TEST_F(
|
||||||
expr.push_back(create<ast::ScalarConstructorExpression>(
|
expr.push_back(create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::CallExpression>(
|
create<ast::CallExpression>(
|
||||||
|
@ -687,7 +692,7 @@ TEST_F(MslGeneratorImplTest,
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::IdentifierExpression>(
|
Source{}, create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("param"), "param")));
|
Source{}, mod.RegisterSymbol("param"), "param")));
|
||||||
|
@ -701,8 +706,9 @@ TEST_F(MslGeneratorImplTest,
|
||||||
expr.push_back(create<ast::ScalarConstructorExpression>(
|
expr.push_back(create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
||||||
"depth"),
|
"depth"),
|
||||||
create<ast::CallExpression>(
|
create<ast::CallExpression>(
|
||||||
|
@ -789,8 +795,9 @@ TEST_F(
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
||||||
"depth"),
|
"depth"),
|
||||||
create<ast::MemberAccessorExpression>(
|
create<ast::MemberAccessorExpression>(
|
||||||
|
@ -812,8 +819,9 @@ TEST_F(
|
||||||
expr.push_back(create<ast::ScalarConstructorExpression>(
|
expr.push_back(create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
|
||||||
"depth"),
|
"depth"),
|
||||||
create<ast::CallExpression>(
|
create<ast::CallExpression>(
|
||||||
|
@ -885,7 +893,7 @@ TEST_F(MslGeneratorImplTest,
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::MemberAccessorExpression>(
|
Source{}, create<ast::MemberAccessorExpression>(
|
||||||
Source{},
|
Source{},
|
||||||
|
@ -916,8 +924,8 @@ TEST_F(MslGeneratorImplTest,
|
||||||
expr), // constructor
|
expr), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
|
@ -993,7 +1001,7 @@ TEST_F(MslGeneratorImplTest,
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::MemberAccessorExpression>(
|
Source{}, create<ast::MemberAccessorExpression>(
|
||||||
Source{},
|
Source{},
|
||||||
|
@ -1024,8 +1032,8 @@ TEST_F(MslGeneratorImplTest,
|
||||||
expr), // constructor
|
expr), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
|
@ -1107,7 +1115,7 @@ TEST_F(MslGeneratorImplTest,
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::MemberAccessorExpression>(
|
Source{}, create<ast::MemberAccessorExpression>(
|
||||||
Source{},
|
Source{},
|
||||||
|
@ -1138,8 +1146,8 @@ TEST_F(MslGeneratorImplTest,
|
||||||
expr), // constructor
|
expr), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
body = create<ast::BlockStatement>();
|
body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
|
@ -1195,14 +1203,15 @@ TEST_F(MslGeneratorImplTest,
|
||||||
mod.AddGlobalVariable(bar_var);
|
mod.AddGlobalVariable(bar_var);
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
|
||||||
"bar"),
|
"bar"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))));
|
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{}));
|
list->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
body->append(create<ast::IfStatement>(
|
body->append(create<ast::IfStatement>(
|
||||||
|
@ -1251,7 +1260,7 @@ TEST_F(MslGeneratorImplTest,
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("main"), "main", ast::VariableList{},
|
Source{}, mod.RegisterSymbol("main"), "main", ast::VariableList{},
|
||||||
&void_type, create<ast::BlockStatement>(),
|
&void_type, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
|
||||||
});
|
});
|
||||||
|
@ -1283,7 +1292,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) {
|
||||||
|
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
auto* func = create<ast::Function>(Source{}, mod.RegisterSymbol("my_func"),
|
||||||
"my_func", params, &void_type, body,
|
"my_func", params, &void_type, body,
|
||||||
|
@ -1371,8 +1380,8 @@ TEST_F(MslGeneratorImplTest,
|
||||||
"d")), // constructor
|
"d")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
|
@ -1401,8 +1410,8 @@ TEST_F(MslGeneratorImplTest,
|
||||||
"d")), // constructor
|
"d")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
|
|
|
@ -31,7 +31,7 @@ using MslGeneratorImplTest = TestHelper;
|
||||||
TEST_F(MslGeneratorImplTest, Emit_If) {
|
TEST_F(MslGeneratorImplTest, Emit_If) {
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("cond"), "cond");
|
Source{}, mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
|
ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
|
||||||
|
@ -48,16 +48,17 @@ TEST_F(MslGeneratorImplTest, Emit_If) {
|
||||||
TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
|
TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
|
||||||
auto* else_cond = create<ast::IdentifierExpression>(
|
auto* else_cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
|
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
|
||||||
auto* else_body = create<ast::BlockStatement>();
|
auto* else_body = create<ast::BlockStatement>(Source{});
|
||||||
else_body->append(create<ast::ReturnStatement>(Source{}));
|
else_body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("cond"), "cond");
|
Source{}, mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
ast::IfStatement i(Source{}, cond, body,
|
ast::IfStatement i(
|
||||||
{create<ast::ElseStatement>(else_cond, else_body)});
|
Source{}, cond, body,
|
||||||
|
{create<ast::ElseStatement>(Source{}, else_cond, else_body)});
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -71,16 +72,17 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
|
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{}));
|
else_body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("cond"), "cond");
|
Source{}, mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
ast::IfStatement i(Source{}, cond, body,
|
ast::IfStatement i(
|
||||||
{create<ast::ElseStatement>(else_body)});
|
Source{}, cond, body,
|
||||||
|
{create<ast::ElseStatement>(Source{}, nullptr, else_body)});
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -97,22 +99,23 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
|
||||||
auto* else_cond = create<ast::IdentifierExpression>(
|
auto* else_cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
|
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
|
||||||
|
|
||||||
auto* else_body = create<ast::BlockStatement>();
|
auto* else_body = create<ast::BlockStatement>(Source{});
|
||||||
else_body->append(create<ast::ReturnStatement>(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{}));
|
else_body_2->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("cond"), "cond");
|
Source{}, mod.RegisterSymbol("cond"), "cond");
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(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();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,10 @@ namespace {
|
||||||
using MslGeneratorImplTest = TestHelper;
|
using MslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Loop) {
|
TEST_F(MslGeneratorImplTest, Emit_Loop) {
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::DiscardStatement>());
|
body->append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
ast::LoopStatement l(body, {});
|
ast::LoopStatement l(Source{}, body, {});
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -51,13 +51,13 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
|
TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::DiscardStatement>());
|
body->append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* continuing = create<ast::BlockStatement>();
|
auto* continuing = create<ast::BlockStatement>(Source{});
|
||||||
continuing->append(create<ast::ReturnStatement>(Source{}));
|
continuing->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
ast::LoopStatement l(body, continuing);
|
ast::LoopStatement l(Source{}, body, continuing);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -79,15 +79,15 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
|
||||||
TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
|
TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
|
||||||
ast::type::F32 f32;
|
ast::type::F32 f32;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::DiscardStatement>());
|
body->append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
auto* continuing = create<ast::BlockStatement>();
|
auto* continuing = create<ast::BlockStatement>(Source{});
|
||||||
continuing->append(create<ast::ReturnStatement>(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);
|
body->append(inner);
|
||||||
|
|
||||||
auto* lhs = create<ast::IdentifierExpression>(
|
auto* lhs = create<ast::IdentifierExpression>(
|
||||||
|
@ -95,10 +95,10 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
|
||||||
auto* rhs = create<ast::IdentifierExpression>(
|
auto* rhs = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
||||||
|
|
||||||
continuing = create<ast::BlockStatement>();
|
continuing = create<ast::BlockStatement>(Source{});
|
||||||
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
|
continuing->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
|
||||||
|
|
||||||
ast::LoopStatement outer(body, continuing);
|
ast::LoopStatement outer(Source{}, body, continuing);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -162,9 +162,10 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
|
||||||
create<ast::FloatLiteral>(Source{}, &f32, 2.4)), // constructor
|
create<ast::FloatLiteral>(Source{}, &f32, 2.4)), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::VariableDeclStatement>(
|
body->append(create<ast::VariableDeclStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::Variable>(Source{}, // source
|
create<ast::Variable>(Source{}, // source
|
||||||
"other", // name
|
"other", // name
|
||||||
ast::StorageClass::kFunction, // storage_class
|
ast::StorageClass::kFunction, // storage_class
|
||||||
|
@ -178,12 +179,12 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
|
||||||
auto* rhs = create<ast::IdentifierExpression>(
|
auto* rhs = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
||||||
|
|
||||||
auto* continuing = create<ast::BlockStatement>();
|
auto* continuing = create<ast::BlockStatement>(Source{});
|
||||||
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
|
continuing->append(create<ast::AssignmentStatement>(Source{}, lhs, rhs));
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
ast::LoopStatement outer(body, continuing);
|
ast::LoopStatement outer(Source{}, body, continuing);
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(&outer)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(&outer)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), R"( {
|
EXPECT_EQ(gen.result(), R"( {
|
||||||
|
|
|
@ -33,18 +33,19 @@ namespace {
|
||||||
using MslGeneratorImplTest = TestHelper;
|
using MslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_Switch) {
|
TEST_F(MslGeneratorImplTest, Emit_Switch) {
|
||||||
auto* def_body = create<ast::BlockStatement>();
|
auto* def_body = create<ast::BlockStatement>(Source{});
|
||||||
def_body->append(create<ast::BreakStatement>());
|
def_body->append(create<ast::BreakStatement>(Source{}));
|
||||||
auto* def = create<ast::CaseStatement>(def_body);
|
auto* def =
|
||||||
|
create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, def_body);
|
||||||
|
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
ast::CaseSelectorList case_val;
|
ast::CaseSelectorList case_val;
|
||||||
case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||||
|
|
||||||
auto* case_body = create<ast::BlockStatement>();
|
auto* case_body = create<ast::BlockStatement>(Source{});
|
||||||
case_body->append(create<ast::BreakStatement>());
|
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;
|
ast::CaseStatementList body;
|
||||||
body.push_back(case_stmt);
|
body.push_back(case_stmt);
|
||||||
|
@ -52,7 +53,7 @@ TEST_F(MslGeneratorImplTest, Emit_Switch) {
|
||||||
|
|
||||||
auto* cond = create<ast::IdentifierExpression>(
|
auto* cond = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("cond"), "cond");
|
Source{}, mod.RegisterSymbol("cond"), "cond");
|
||||||
ast::SwitchStatement s(cond, body);
|
ast::SwitchStatement s(Source{}, cond, body);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ TEST_F(MslGeneratorImplTest, Generate) {
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
|
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
|
||||||
&void_type, create<ast::BlockStatement>(),
|
&void_type, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
|
||||||
});
|
});
|
||||||
|
|
|
@ -51,7 +51,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) {
|
||||||
ident, // constructor
|
ident, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), R"(float a = initializer;
|
EXPECT_EQ(gen.result(), R"(float a = initializer;
|
||||||
|
@ -230,7 +230,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) {
|
||||||
zero_vec, // constructor
|
zero_vec, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
ast::VariableDeclStatement stmt(var);
|
ast::VariableDeclStatement stmt(Source{}, var);
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), R"(float3 a = float3(0.0f);
|
EXPECT_EQ(gen.result(), R"(float3 a = float3(0.0f);
|
||||||
|
|
|
@ -514,7 +514,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
|
||||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f));
|
||||||
|
|
||||||
ast::AssignmentStatement expr(lhs, rhs);
|
ast::AssignmentStatement expr(Source{}, lhs, rhs);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(&var);
|
td.RegisterVariableForTesting(&var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
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"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("a"),
|
||||||
"a"));
|
"a"));
|
||||||
|
|
||||||
ast::AssignmentStatement expr(lhs, rhs);
|
ast::AssignmentStatement expr(Source{}, lhs, rhs);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(&var);
|
td.RegisterVariableForTesting(&var);
|
||||||
td.RegisterVariableForTesting(&store);
|
td.RegisterVariableForTesting(&store);
|
||||||
|
|
|
@ -52,7 +52,7 @@ TEST_F(BuilderTest, Assign_Var) {
|
||||||
auto* val = create<ast::ScalarConstructorExpression>(
|
auto* val = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f));
|
||||||
|
|
||||||
ast::AssignmentStatement assign(ident, val);
|
ast::AssignmentStatement assign(Source{}, ident, val);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(&v);
|
td.RegisterVariableForTesting(&v);
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
|
||||||
ast::ExpressionList vals;
|
ast::ExpressionList vals;
|
||||||
auto* val = create<ast::TypeConstructorExpression>(Source{}, &vec, vals);
|
auto* val = create<ast::TypeConstructorExpression>(Source{}, &vec, vals);
|
||||||
|
|
||||||
ast::AssignmentStatement assign(ident, val);
|
ast::AssignmentStatement assign(Source{}, ident, val);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(&v);
|
td.RegisterVariableForTesting(&v);
|
||||||
|
|
||||||
|
@ -138,6 +138,7 @@ TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
|
||||||
nullptr, ast::VariableDecorationList{});
|
nullptr, ast::VariableDecorationList{});
|
||||||
|
|
||||||
ast::AssignmentStatement assign(
|
ast::AssignmentStatement assign(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
|
||||||
"var"),
|
"var"),
|
||||||
init);
|
init);
|
||||||
|
@ -189,6 +190,7 @@ TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
|
||||||
nullptr, ast::VariableDecorationList{});
|
nullptr, ast::VariableDecorationList{});
|
||||||
|
|
||||||
ast::AssignmentStatement assign(
|
ast::AssignmentStatement assign(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
|
||||||
"var"),
|
"var"),
|
||||||
init);
|
init);
|
||||||
|
@ -248,7 +250,7 @@ TEST_F(BuilderTest, Assign_StructMember) {
|
||||||
auto* val = create<ast::ScalarConstructorExpression>(
|
auto* val = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 4.0f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 4.0f));
|
||||||
|
|
||||||
ast::AssignmentStatement assign(ident, val);
|
ast::AssignmentStatement assign(Source{}, ident, val);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(&v);
|
td.RegisterVariableForTesting(&v);
|
||||||
|
|
||||||
|
@ -297,7 +299,7 @@ TEST_F(BuilderTest, Assign_Vector) {
|
||||||
|
|
||||||
auto* val = create<ast::TypeConstructorExpression>(Source{}, &vec3, vals);
|
auto* val = create<ast::TypeConstructorExpression>(Source{}, &vec3, vals);
|
||||||
|
|
||||||
ast::AssignmentStatement assign(ident, val);
|
ast::AssignmentStatement assign(Source{}, ident, val);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(&v);
|
td.RegisterVariableForTesting(&v);
|
||||||
|
|
||||||
|
@ -342,7 +344,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByName) {
|
||||||
auto* val = create<ast::ScalarConstructorExpression>(
|
auto* val = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f));
|
||||||
|
|
||||||
ast::AssignmentStatement assign(ident, val);
|
ast::AssignmentStatement assign(Source{}, ident, val);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(&v);
|
td.RegisterVariableForTesting(&v);
|
||||||
|
|
||||||
|
@ -391,7 +393,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
|
||||||
auto* val = create<ast::ScalarConstructorExpression>(
|
auto* val = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f));
|
||||||
|
|
||||||
ast::AssignmentStatement assign(ident, val);
|
ast::AssignmentStatement assign(Source{}, ident, val);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(&v);
|
td.RegisterVariableForTesting(&v);
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,10 @@ TEST_F(BuilderTest, Block) {
|
||||||
|
|
||||||
// Note, this test uses shadow variables which aren't allowed in WGSL but
|
// Note, this test uses shadow variables which aren't allowed in WGSL but
|
||||||
// serves to prove the block code is pushing new scopes as needed.
|
// serves to prove the block code is pushing new scopes as needed.
|
||||||
ast::BlockStatement outer;
|
ast::BlockStatement outer(Source{});
|
||||||
|
|
||||||
outer.append(create<ast::VariableDeclStatement>(
|
outer.append(create<ast::VariableDeclStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::Variable>(Source{}, // source
|
create<ast::Variable>(Source{}, // source
|
||||||
"var", // name
|
"var", // name
|
||||||
ast::StorageClass::kFunction, // storage_class
|
ast::StorageClass::kFunction, // storage_class
|
||||||
|
@ -50,13 +51,15 @@ TEST_F(BuilderTest, Block) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}))); // decorations
|
ast::VariableDecorationList{}))); // decorations
|
||||||
outer.append(create<ast::AssignmentStatement>(
|
outer.append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
|
||||||
"var"),
|
"var"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))));
|
||||||
|
|
||||||
auto* inner = create<ast::BlockStatement>();
|
auto* inner = create<ast::BlockStatement>(Source{});
|
||||||
inner->append(create<ast::VariableDeclStatement>(
|
inner->append(create<ast::VariableDeclStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::Variable>(Source{}, // source
|
create<ast::Variable>(Source{}, // source
|
||||||
"var", // name
|
"var", // name
|
||||||
ast::StorageClass::kFunction, // storage_class
|
ast::StorageClass::kFunction, // storage_class
|
||||||
|
@ -65,6 +68,7 @@ TEST_F(BuilderTest, Block) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}))); // decorations
|
ast::VariableDecorationList{}))); // decorations
|
||||||
inner->append(create<ast::AssignmentStatement>(
|
inner->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
|
||||||
"var"),
|
"var"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
|
@ -72,6 +76,7 @@ TEST_F(BuilderTest, Block) {
|
||||||
|
|
||||||
outer.append(inner);
|
outer.append(inner);
|
||||||
outer.append(create<ast::AssignmentStatement>(
|
outer.append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("var"),
|
||||||
"var"),
|
"var"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
|
|
|
@ -61,7 +61,7 @@ TEST_F(BuilderTest, Expression_Call) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::BinaryExpression>(
|
Source{}, create<ast::BinaryExpression>(
|
||||||
Source{}, ast::BinaryOp::kAdd,
|
Source{}, ast::BinaryOp::kAdd,
|
||||||
|
@ -73,7 +73,7 @@ TEST_F(BuilderTest, Expression_Call) {
|
||||||
func_params, &f32, body, ast::FunctionDecorationList{});
|
func_params, &f32, body, ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {},
|
||||||
&void_type, create<ast::BlockStatement>(),
|
&void_type, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ast::ExpressionList call_params;
|
ast::ExpressionList call_params;
|
||||||
|
@ -144,7 +144,7 @@ TEST_F(BuilderTest, Statement_Call) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{})); // decorations
|
ast::VariableDecorationList{})); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::BinaryExpression>(
|
Source{}, create<ast::BinaryExpression>(
|
||||||
Source{}, ast::BinaryOp::kAdd,
|
Source{}, ast::BinaryOp::kAdd,
|
||||||
|
@ -158,7 +158,7 @@ TEST_F(BuilderTest, Statement_Call) {
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {},
|
||||||
&void_type, create<ast::BlockStatement>(),
|
&void_type, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ast::ExpressionList call_params;
|
ast::ExpressionList call_params;
|
||||||
|
@ -167,11 +167,12 @@ TEST_F(BuilderTest, Statement_Call) {
|
||||||
call_params.push_back(create<ast::ScalarConstructorExpression>(
|
call_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
|
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
|
||||||
|
|
||||||
ast::CallStatement expr(create<ast::CallExpression>(
|
ast::CallStatement expr(
|
||||||
Source{},
|
Source{}, create<ast::CallExpression>(
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("a_func"),
|
Source{},
|
||||||
"a_func"),
|
create<ast::IdentifierExpression>(
|
||||||
call_params));
|
Source{}, mod->RegisterSymbol("a_func"), "a_func"),
|
||||||
|
call_params));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();
|
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();
|
||||||
ASSERT_TRUE(td.DetermineFunction(&a_func)) << td.error();
|
ASSERT_TRUE(td.DetermineFunction(&a_func)) << td.error();
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace {
|
||||||
using BuilderTest = TestHelper;
|
using BuilderTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(BuilderTest, Discard) {
|
TEST_F(BuilderTest, Discard) {
|
||||||
ast::DiscardStatement expr;
|
ast::DiscardStatement expr(Source{});
|
||||||
|
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
EXPECT_EQ(b.GenerateStatement(&expr), 1u) << b.error();
|
EXPECT_EQ(b.GenerateStatement(&expr), 1u) << b.error();
|
||||||
|
|
|
@ -43,7 +43,7 @@ TEST_F(BuilderTest, FunctionDecoration_Stage) {
|
||||||
|
|
||||||
ast::Function func(
|
ast::Function func(
|
||||||
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
|
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
|
||||||
create<ast::BlockStatement>(),
|
create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
|
||||||
});
|
});
|
||||||
|
@ -69,7 +69,7 @@ TEST_P(FunctionDecoration_StageTest, Emit) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {},
|
||||||
&void_type, create<ast::BlockStatement>(),
|
&void_type, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::StageDecoration>(params.stage, Source{}),
|
create<ast::StageDecoration>(params.stage, Source{}),
|
||||||
});
|
});
|
||||||
|
@ -99,7 +99,7 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
|
||||||
|
|
||||||
ast::Function func(
|
ast::Function func(
|
||||||
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
|
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
|
||||||
create<ast::BlockStatement>(),
|
create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
|
||||||
});
|
});
|
||||||
|
@ -163,19 +163,22 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
|
||||||
ast::type::F32 f32;
|
ast::type::F32 f32;
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_out"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_out"),
|
||||||
"my_out"),
|
"my_out"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_in"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_in"),
|
||||||
"my_in")));
|
"my_in")));
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_wg"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_wg"),
|
||||||
"my_wg"),
|
"my_wg"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_wg"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_wg"),
|
||||||
"my_wg")));
|
"my_wg")));
|
||||||
// Add duplicate usages so we show they don't get output multiple times.
|
// Add duplicate usages so we show they don't get output multiple times.
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_out"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_out"),
|
||||||
"my_out"),
|
"my_out"),
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_in"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("my_in"),
|
||||||
|
@ -253,7 +256,7 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_Fragment_OriginUpperLeft) {
|
||||||
|
|
||||||
ast::Function func(
|
ast::Function func(
|
||||||
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
|
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
|
||||||
create<ast::BlockStatement>(),
|
create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
|
||||||
});
|
});
|
||||||
|
@ -269,7 +272,7 @@ TEST_F(BuilderTest, FunctionDecoration_WorkgroupSize_Default) {
|
||||||
|
|
||||||
ast::Function func(
|
ast::Function func(
|
||||||
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
|
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
|
||||||
create<ast::BlockStatement>(),
|
create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
|
||||||
});
|
});
|
||||||
|
@ -285,7 +288,7 @@ TEST_F(BuilderTest, FunctionDecoration_WorkgroupSize) {
|
||||||
|
|
||||||
ast::Function func(
|
ast::Function func(
|
||||||
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
|
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type,
|
||||||
create<ast::BlockStatement>(),
|
create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::WorkgroupDecoration>(2u, 4u, 6u, Source{}),
|
create<ast::WorkgroupDecoration>(2u, 4u, 6u, Source{}),
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}),
|
||||||
|
@ -302,14 +305,14 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_MultipleFragment) {
|
||||||
|
|
||||||
ast::Function func1(
|
ast::Function func1(
|
||||||
Source{}, mod->RegisterSymbol("main1"), "main1", {}, &void_type,
|
Source{}, mod->RegisterSymbol("main1"), "main1", {}, &void_type,
|
||||||
create<ast::BlockStatement>(),
|
create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
|
||||||
});
|
});
|
||||||
|
|
||||||
ast::Function func2(
|
ast::Function func2(
|
||||||
Source{}, mod->RegisterSymbol("main2"), "main2", {}, &void_type,
|
Source{}, mod->RegisterSymbol("main2"), "main2", {}, &void_type,
|
||||||
create<ast::BlockStatement>(),
|
create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{
|
ast::FunctionDecorationList{
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
|
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
|
||||||
});
|
});
|
||||||
|
|
|
@ -48,7 +48,7 @@ using BuilderTest = TestHelper;
|
||||||
TEST_F(BuilderTest, Function_Empty) {
|
TEST_F(BuilderTest, Function_Empty) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
&void_type, create<ast::BlockStatement>(),
|
&void_type, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func));
|
ASSERT_TRUE(b.GenerateFunction(&func));
|
||||||
|
@ -65,7 +65,7 @@ OpFunctionEnd
|
||||||
TEST_F(BuilderTest, Function_Terminator_Return) {
|
TEST_F(BuilderTest, Function_Terminator_Return) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
|
@ -96,7 +96,7 @@ TEST_F(BuilderTest, Function_Terminator_ReturnValue) {
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
td.RegisterVariableForTesting(var_a);
|
td.RegisterVariableForTesting(var_a);
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::IdentifierExpression>(
|
Source{}, create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol("a"), "a")));
|
Source{}, mod->RegisterSymbol("a"), "a")));
|
||||||
|
@ -126,8 +126,8 @@ OpFunctionEnd
|
||||||
TEST_F(BuilderTest, Function_Terminator_Discard) {
|
TEST_F(BuilderTest, Function_Terminator_Discard) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::DiscardStatement>());
|
body->append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
&void_type, body, ast::FunctionDecorationList{});
|
&void_type, body, ast::FunctionDecorationList{});
|
||||||
|
@ -166,7 +166,7 @@ TEST_F(BuilderTest, Function_WithParams) {
|
||||||
ast::VariableDecorationList{}), // decorations
|
ast::VariableDecorationList{}), // decorations
|
||||||
};
|
};
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(
|
body->append(create<ast::ReturnStatement>(
|
||||||
Source{}, create<ast::IdentifierExpression>(
|
Source{}, create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol("a"), "a")));
|
Source{}, mod->RegisterSymbol("a"), "a")));
|
||||||
|
@ -196,7 +196,7 @@ OpFunctionEnd
|
||||||
TEST_F(BuilderTest, Function_WithBody) {
|
TEST_F(BuilderTest, Function_WithBody) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
|
@ -216,7 +216,7 @@ OpFunctionEnd
|
||||||
TEST_F(BuilderTest, FunctionType) {
|
TEST_F(BuilderTest, FunctionType) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
&void_type, create<ast::BlockStatement>(),
|
&void_type, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func));
|
ASSERT_TRUE(b.GenerateFunction(&func));
|
||||||
|
@ -228,10 +228,10 @@ TEST_F(BuilderTest, FunctionType) {
|
||||||
TEST_F(BuilderTest, FunctionType_DeDuplicate) {
|
TEST_F(BuilderTest, FunctionType_DeDuplicate) {
|
||||||
ast::type::Void void_type;
|
ast::type::Void void_type;
|
||||||
ast::Function func1(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func1(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
&void_type, create<ast::BlockStatement>(),
|
&void_type, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
ast::Function func2(Source{}, mod->RegisterSymbol("b_func"), "b_func", {},
|
ast::Function func2(Source{}, mod->RegisterSymbol("b_func"), "b_func", {},
|
||||||
&void_type, create<ast::BlockStatement>(),
|
&void_type, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func1));
|
ASSERT_TRUE(b.GenerateFunction(&func1));
|
||||||
|
@ -309,8 +309,8 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
||||||
"d")), // constructor
|
"d")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
|
@ -340,8 +340,8 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
||||||
"d")), // constructor
|
"d")), // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::VariableDeclStatement>(var));
|
body->append(create<ast::VariableDeclStatement>(Source{}, var));
|
||||||
body->append(create<ast::ReturnStatement>(Source{}));
|
body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
|
|
|
@ -48,7 +48,7 @@ TEST_F(BuilderTest, If_Empty) {
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||||
|
|
||||||
ast::IfStatement expr(Source{}, cond, create<ast::BlockStatement>(),
|
ast::IfStatement expr(Source{}, cond, create<ast::BlockStatement>(Source{}),
|
||||||
ast::ElseStatementList{});
|
ast::ElseStatementList{});
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
@ -84,8 +84,9 @@ TEST_F(BuilderTest, If_WithStatements) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
|
@ -139,15 +140,17 @@ TEST_F(BuilderTest, If_WithElse) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
|
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>(
|
else_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
|
@ -156,8 +159,9 @@ TEST_F(BuilderTest, If_WithElse) {
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||||
|
|
||||||
ast::IfStatement expr(Source{}, cond, body,
|
ast::IfStatement expr(
|
||||||
{create<ast::ElseStatement>(else_body)});
|
Source{}, cond, body,
|
||||||
|
{create<ast::ElseStatement>(Source{}, nullptr, else_body)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
|
|
||||||
|
@ -207,15 +211,17 @@ TEST_F(BuilderTest, If_WithElseIf) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
|
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>(
|
else_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
|
@ -227,8 +233,9 @@ TEST_F(BuilderTest, If_WithElseIf) {
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||||
|
|
||||||
ast::IfStatement expr(Source{}, cond, body,
|
ast::IfStatement expr(
|
||||||
{create<ast::ElseStatement>(else_cond, else_body)});
|
Source{}, cond, body,
|
||||||
|
{create<ast::ElseStatement>(Source{}, else_cond, else_body)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
|
|
||||||
|
@ -287,26 +294,30 @@ TEST_F(BuilderTest, If_WithMultiple) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
|
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>(
|
elseif_1_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))));
|
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>(
|
elseif_2_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 4))));
|
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>(
|
else_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
|
@ -323,9 +334,9 @@ TEST_F(BuilderTest, If_WithMultiple) {
|
||||||
ast::IfStatement expr(
|
ast::IfStatement expr(
|
||||||
Source{}, cond, body,
|
Source{}, cond, body,
|
||||||
{
|
{
|
||||||
create<ast::ElseStatement>(elseif_1_cond, elseif_1_body),
|
create<ast::ElseStatement>(Source{}, elseif_1_cond, elseif_1_body),
|
||||||
create<ast::ElseStatement>(elseif_2_cond, elseif_2_body),
|
create<ast::ElseStatement>(Source{}, elseif_2_cond, elseif_2_body),
|
||||||
create<ast::ElseStatement>(else_body),
|
create<ast::ElseStatement>(Source{}, nullptr, else_body),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
|
@ -387,16 +398,17 @@ TEST_F(BuilderTest, If_WithBreak) {
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||||
|
|
||||||
auto* if_body = create<ast::BlockStatement>();
|
auto* if_body = create<ast::BlockStatement>(Source{});
|
||||||
if_body->append(create<ast::BreakStatement>());
|
if_body->append(create<ast::BreakStatement>(Source{}));
|
||||||
|
|
||||||
auto* if_stmt = create<ast::IfStatement>(Source{}, cond, if_body,
|
auto* if_stmt = create<ast::IfStatement>(Source{}, cond, if_body,
|
||||||
ast::ElseStatementList{});
|
ast::ElseStatementList{});
|
||||||
|
|
||||||
auto* loop_body = create<ast::BlockStatement>();
|
auto* loop_body = create<ast::BlockStatement>(Source{});
|
||||||
loop_body->append(if_stmt);
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
|
@ -435,17 +447,19 @@ TEST_F(BuilderTest, If_WithElseBreak) {
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||||
|
|
||||||
auto* else_body = create<ast::BlockStatement>();
|
auto* else_body = create<ast::BlockStatement>(Source{});
|
||||||
else_body->append(create<ast::BreakStatement>());
|
else_body->append(create<ast::BreakStatement>(Source{}));
|
||||||
|
|
||||||
auto* if_stmt = create<ast::IfStatement>(
|
auto* if_stmt = create<ast::IfStatement>(
|
||||||
Source{}, cond, create<ast::BlockStatement>(),
|
Source{}, cond, create<ast::BlockStatement>(Source{}),
|
||||||
ast::ElseStatementList{create<ast::ElseStatement>(else_body)});
|
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);
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
|
@ -485,16 +499,17 @@ TEST_F(BuilderTest, If_WithContinue) {
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||||
|
|
||||||
auto* if_body = create<ast::BlockStatement>();
|
auto* if_body = create<ast::BlockStatement>(Source{});
|
||||||
if_body->append(create<ast::ContinueStatement>());
|
if_body->append(create<ast::ContinueStatement>(Source{}));
|
||||||
|
|
||||||
auto* if_stmt = create<ast::IfStatement>(Source{}, cond, if_body,
|
auto* if_stmt = create<ast::IfStatement>(Source{}, cond, if_body,
|
||||||
ast::ElseStatementList{});
|
ast::ElseStatementList{});
|
||||||
|
|
||||||
auto* loop_body = create<ast::BlockStatement>();
|
auto* loop_body = create<ast::BlockStatement>(Source{});
|
||||||
loop_body->append(if_stmt);
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
|
@ -533,17 +548,19 @@ TEST_F(BuilderTest, If_WithElseContinue) {
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||||
|
|
||||||
auto* else_body = create<ast::BlockStatement>();
|
auto* else_body = create<ast::BlockStatement>(Source{});
|
||||||
else_body->append(create<ast::ContinueStatement>());
|
else_body->append(create<ast::ContinueStatement>(Source{}));
|
||||||
|
|
||||||
auto* if_stmt = create<ast::IfStatement>(
|
auto* if_stmt = create<ast::IfStatement>(
|
||||||
Source{}, cond, create<ast::BlockStatement>(),
|
Source{}, cond, create<ast::BlockStatement>(Source{}),
|
||||||
ast::ElseStatementList{create<ast::ElseStatement>(else_body)});
|
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);
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
|
@ -581,7 +598,7 @@ TEST_F(BuilderTest, If_WithReturn) {
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||||
|
|
||||||
auto* if_body = create<ast::BlockStatement>();
|
auto* if_body = create<ast::BlockStatement>(Source{});
|
||||||
if_body->append(create<ast::ReturnStatement>(Source{}));
|
if_body->append(create<ast::ReturnStatement>(Source{}));
|
||||||
|
|
||||||
ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{});
|
ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{});
|
||||||
|
@ -613,7 +630,7 @@ TEST_F(BuilderTest, If_WithReturnValue) {
|
||||||
auto* cond2 = create<ast::ScalarConstructorExpression>(
|
auto* cond2 = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, false));
|
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, false));
|
||||||
|
|
||||||
auto* if_body = create<ast::BlockStatement>();
|
auto* if_body = create<ast::BlockStatement>(Source{});
|
||||||
if_body->append(create<ast::ReturnStatement>(Source{}, cond2));
|
if_body->append(create<ast::ReturnStatement>(Source{}, cond2));
|
||||||
|
|
||||||
ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{});
|
ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{});
|
||||||
|
@ -655,7 +672,7 @@ TEST_F(BuilderTest, If_WithLoad_Bug327) {
|
||||||
ast::IfStatement expr(Source{},
|
ast::IfStatement expr(Source{},
|
||||||
create<ast::IdentifierExpression>(
|
create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol("a"), "a"),
|
Source{}, mod->RegisterSymbol("a"), "a"),
|
||||||
create<ast::BlockStatement>(),
|
create<ast::BlockStatement>(Source{}),
|
||||||
ast::ElseStatementList{});
|
ast::ElseStatementList{});
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
|
@ -472,7 +472,7 @@ TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||||
|
@ -588,7 +588,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||||
|
@ -613,7 +613,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Vector) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||||
|
@ -640,7 +640,7 @@ TEST_F(IntrinsicBuilderTest, Call_Normalize) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||||
|
@ -738,7 +738,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||||
|
@ -764,7 +764,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||||
|
@ -793,7 +793,7 @@ TEST_F(IntrinsicBuilderTest, Call_Cross) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||||
|
@ -1277,7 +1277,7 @@ TEST_F(IntrinsicBuilderTest, Call_Determinant) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||||
|
@ -1321,7 +1321,7 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||||
|
@ -1361,7 +1361,7 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength_OtherMembersInStruct) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
ty.void_, create<ast::BlockStatement>(),
|
ty.void_, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||||
|
|
|
@ -39,13 +39,13 @@ TEST_F(BuilderTest, Loop_Empty) {
|
||||||
// loop {
|
// loop {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
ast::LoopStatement expr(create<ast::BlockStatement>(),
|
ast::LoopStatement loop(Source{}, create<ast::BlockStatement>(Source{}),
|
||||||
create<ast::BlockStatement>());
|
create<ast::BlockStatement>(Source{}));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
|
||||||
b.push_function(Function{});
|
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()),
|
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||||
R"(OpBranch %1
|
R"(OpBranch %1
|
||||||
%1 = OpLabel
|
%1 = OpLabel
|
||||||
|
@ -74,22 +74,24 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
|
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);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
|
||||||
|
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
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
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
|
||||||
%2 = OpTypePointer Private %3
|
%2 = OpTypePointer Private %3
|
||||||
%4 = OpConstantNull %3
|
%4 = OpConstantNull %3
|
||||||
|
@ -128,28 +130,30 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::AssignmentStatement>(
|
body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
|
||||||
|
|
||||||
auto* continuing = create<ast::BlockStatement>();
|
auto* continuing = create<ast::BlockStatement>(Source{});
|
||||||
continuing->append(create<ast::AssignmentStatement>(
|
continuing->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))));
|
||||||
ast::LoopStatement expr(body, continuing);
|
ast::LoopStatement loop(Source{}, body, continuing);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
|
||||||
|
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
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
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
|
||||||
%2 = OpTypePointer Private %3
|
%2 = OpTypePointer Private %3
|
||||||
%4 = OpConstantNull %3
|
%4 = OpConstantNull %3
|
||||||
|
@ -176,16 +180,17 @@ TEST_F(BuilderTest, Loop_WithContinue) {
|
||||||
// loop {
|
// loop {
|
||||||
// continue;
|
// continue;
|
||||||
// }
|
// }
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::ContinueStatement>());
|
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{});
|
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()),
|
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||||
R"(OpBranch %1
|
R"(OpBranch %1
|
||||||
%1 = OpLabel
|
%1 = OpLabel
|
||||||
|
@ -203,16 +208,17 @@ TEST_F(BuilderTest, Loop_WithBreak) {
|
||||||
// loop {
|
// loop {
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
auto* body = create<ast::BlockStatement>();
|
auto* body = create<ast::BlockStatement>(Source{});
|
||||||
body->append(create<ast::BreakStatement>());
|
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{});
|
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()),
|
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||||
R"(OpBranch %1
|
R"(OpBranch %1
|
||||||
%1 = OpLabel
|
%1 = OpLabel
|
||||||
|
|
|
@ -47,7 +47,7 @@ TEST_F(BuilderTest, Switch_Empty) {
|
||||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1));
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
|
@ -93,15 +93,17 @@ TEST_F(BuilderTest, Switch_WithCase) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
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>(
|
case_1_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
|
||||||
|
|
||||||
auto* case_2_body = create<ast::BlockStatement>();
|
auto* case_2_body = create<ast::BlockStatement>(Source{});
|
||||||
case_2_body->append(create<ast::AssignmentStatement>(
|
case_2_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
|
@ -114,10 +116,13 @@ TEST_F(BuilderTest, Switch_WithCase) {
|
||||||
selector_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 2));
|
selector_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
ast::CaseStatementList cases;
|
||||||
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
|
cases.push_back(
|
||||||
cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body));
|
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"),
|
Source{}, mod->RegisterSymbol("a"), "a"),
|
||||||
cases);
|
cases);
|
||||||
|
|
||||||
|
@ -126,7 +131,7 @@ TEST_F(BuilderTest, Switch_WithCase) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
&i32, create<ast::BlockStatement>(),
|
&i32, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||||
|
@ -190,17 +195,20 @@ TEST_F(BuilderTest, Switch_WithDefault) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* default_body = create<ast::BlockStatement>();
|
auto* default_body = create<ast::BlockStatement>(Source{});
|
||||||
default_body->append(create<ast::AssignmentStatement>(
|
default_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
ast::CaseStatementList cases;
|
||||||
cases.push_back(create<ast::CaseStatement>(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"),
|
Source{}, mod->RegisterSymbol("a"), "a"),
|
||||||
cases);
|
cases);
|
||||||
|
|
||||||
|
@ -209,7 +217,7 @@ TEST_F(BuilderTest, Switch_WithDefault) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
&i32, create<ast::BlockStatement>(),
|
&i32, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||||
|
@ -271,22 +279,25 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
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>(
|
case_1_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
|
||||||
|
|
||||||
auto* case_2_body = create<ast::BlockStatement>();
|
auto* case_2_body = create<ast::BlockStatement>(Source{});
|
||||||
case_2_body->append(create<ast::AssignmentStatement>(
|
case_2_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
|
||||||
|
|
||||||
auto* default_body = create<ast::BlockStatement>();
|
auto* default_body = create<ast::BlockStatement>(Source{});
|
||||||
default_body->append(create<ast::AssignmentStatement>(
|
default_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
|
@ -300,11 +311,15 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
|
||||||
selector_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 3));
|
selector_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 3));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
ast::CaseStatementList cases;
|
||||||
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
|
cases.push_back(
|
||||||
cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body));
|
create<ast::CaseStatement>(Source{}, selector_1, case_1_body));
|
||||||
cases.push_back(create<ast::CaseStatement>(default_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"),
|
Source{}, mod->RegisterSymbol("a"), "a"),
|
||||||
cases);
|
cases);
|
||||||
|
|
||||||
|
@ -313,7 +328,7 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
&i32, create<ast::BlockStatement>(),
|
&i32, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||||
|
@ -384,23 +399,26 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
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>(
|
case_1_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
|
||||||
case_1_body->append(create<ast::FallthroughStatement>());
|
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>(
|
case_2_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
|
||||||
|
|
||||||
auto* default_body = create<ast::BlockStatement>();
|
auto* default_body = create<ast::BlockStatement>(Source{});
|
||||||
default_body->append(create<ast::AssignmentStatement>(
|
default_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
|
@ -413,11 +431,15 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
|
||||||
selector_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 2));
|
selector_2.push_back(create<ast::SintLiteral>(Source{}, &i32, 2));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
ast::CaseStatementList cases;
|
||||||
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
|
cases.push_back(
|
||||||
cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body));
|
create<ast::CaseStatement>(Source{}, selector_1, case_1_body));
|
||||||
cases.push_back(create<ast::CaseStatement>(default_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"),
|
Source{}, mod->RegisterSymbol("a"), "a"),
|
||||||
cases);
|
cases);
|
||||||
|
|
||||||
|
@ -426,7 +448,7 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
&i32, create<ast::BlockStatement>(),
|
&i32, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||||
|
@ -493,21 +515,24 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
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>(
|
case_1_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
|
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
|
||||||
case_1_body->append(create<ast::FallthroughStatement>());
|
case_1_body->append(create<ast::FallthroughStatement>(Source{}));
|
||||||
|
|
||||||
ast::CaseSelectorList selector_1;
|
ast::CaseSelectorList selector_1;
|
||||||
selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
|
selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
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"),
|
Source{}, mod->RegisterSymbol("a"), "a"),
|
||||||
cases);
|
cases);
|
||||||
|
|
||||||
|
@ -516,7 +541,7 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
&i32, create<ast::BlockStatement>(),
|
&i32, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||||
|
@ -556,10 +581,10 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
|
||||||
nullptr, // constructor
|
nullptr, // constructor
|
||||||
ast::VariableDecorationList{}); // decorations
|
ast::VariableDecorationList{}); // decorations
|
||||||
|
|
||||||
auto* if_body = create<ast::BlockStatement>();
|
auto* if_body = create<ast::BlockStatement>(Source{});
|
||||||
if_body->append(create<ast::BreakStatement>());
|
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>(
|
case_1_body->append(create<ast::IfStatement>(
|
||||||
Source{},
|
Source{},
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
|
@ -567,6 +592,7 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
|
||||||
if_body, ast::ElseStatementList{}));
|
if_body, ast::ElseStatementList{}));
|
||||||
|
|
||||||
case_1_body->append(create<ast::AssignmentStatement>(
|
case_1_body->append(create<ast::AssignmentStatement>(
|
||||||
|
Source{},
|
||||||
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("v"),
|
||||||
"v"),
|
"v"),
|
||||||
create<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
|
@ -576,9 +602,11 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
|
||||||
selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
|
selector_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
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"),
|
Source{}, mod->RegisterSymbol("a"), "a"),
|
||||||
cases);
|
cases);
|
||||||
|
|
||||||
|
@ -587,7 +615,7 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
|
||||||
&i32, create<ast::BlockStatement>(),
|
&i32, create<ast::BlockStatement>(Source{}),
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||||
|
|
|
@ -33,7 +33,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Assign) {
|
||||||
Source{}, mod.RegisterSymbol("lhs"), "lhs");
|
Source{}, mod.RegisterSymbol("lhs"), "lhs");
|
||||||
auto* rhs = create<ast::IdentifierExpression>(
|
auto* rhs = create<ast::IdentifierExpression>(
|
||||||
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
Source{}, mod.RegisterSymbol("rhs"), "rhs");
|
||||||
ast::AssignmentStatement assign(lhs, rhs);
|
ast::AssignmentStatement assign(Source{}, lhs, rhs);
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@ namespace {
|
||||||
using WgslGeneratorImplTest = TestHelper;
|
using WgslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(WgslGeneratorImplTest, Emit_Block) {
|
TEST_F(WgslGeneratorImplTest, Emit_Block) {
|
||||||
ast::BlockStatement b;
|
ast::BlockStatement b(Source{});
|
||||||
b.append(create<ast::DiscardStatement>());
|
b.append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Block) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WgslGeneratorImplTest, Emit_Block_WithoutNewline) {
|
TEST_F(WgslGeneratorImplTest, Emit_Block_WithoutNewline) {
|
||||||
ast::BlockStatement b;
|
ast::BlockStatement b(Source{});
|
||||||
b.append(create<ast::DiscardStatement>());
|
b.append(create<ast::DiscardStatement>(Source{}));
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace {
|
||||||
using WgslGeneratorImplTest = TestHelper;
|
using WgslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(WgslGeneratorImplTest, Emit_Break) {
|
TEST_F(WgslGeneratorImplTest, Emit_Break) {
|
||||||
ast::BreakStatement b;
|
ast::BreakStatement b(Source{});
|
||||||
|
|
||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue