Big cleanup now that AST nodes are raw pointers

Remove all redundant std::move()s. I've also removed calls to
std::move() in tests, even if they act as an optimization. This is for
two reasons:
(a) Performance is not important for testing, and this helps with
    readability.
(b) A whole bunch tests were relying on std::move() clearing vectors so
    they can be repopulated and used again. This is undefined behavior:

> Objects of types defined in the C++ standard library may be moved from
> (12.8). Move operations may be explicitly specified or implicitly
> generated. Unless otherwise specified, such moved-from objects shall
> be placed in a valid but unspecified state.

All of these UB cases have been fixed.

Removed all duplicate variables left over from:
  `auto* foo_ptr = foo.get()`
which became:
  `auto* foo_ptr = foo`

Bug: tint:322
Change-Id: Ibd08a2379671382320fd4d8da296ccc6a378b8af
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32900
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-16 16:41:47 +00:00 committed by Commit Bot service account
parent b053acf796
commit 4bfe461646
130 changed files with 3078 additions and 3708 deletions

View File

@ -27,19 +27,16 @@ TEST_F(ArrayAccessorExpressionTest, Create) {
auto* ary = create<IdentifierExpression>("ary");
auto* idx = create<IdentifierExpression>("idx");
auto* ary_ptr = ary;
auto* idx_ptr = idx;
ArrayAccessorExpression exp(std::move(ary), std::move(idx));
ASSERT_EQ(exp.array(), ary_ptr);
ASSERT_EQ(exp.idx_expr(), idx_ptr);
ArrayAccessorExpression exp(ary, idx);
ASSERT_EQ(exp.array(), ary);
ASSERT_EQ(exp.idx_expr(), idx);
}
TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
auto* ary = create<IdentifierExpression>("ary");
auto* idx = create<IdentifierExpression>("idx");
ArrayAccessorExpression exp(Source{Source::Location{20, 2}}, std::move(ary),
std::move(idx));
ArrayAccessorExpression exp(Source{Source::Location{20, 2}}, ary, idx);
auto src = exp.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -54,7 +51,7 @@ TEST_F(ArrayAccessorExpressionTest, IsValid) {
auto* ary = create<IdentifierExpression>("ary");
auto* idx = create<IdentifierExpression>("idx");
ArrayAccessorExpression exp(std::move(ary), std::move(idx));
ArrayAccessorExpression exp(ary, idx);
EXPECT_TRUE(exp.IsValid());
}
@ -62,7 +59,7 @@ TEST_F(ArrayAccessorExpressionTest, IsValid_MissingArray) {
auto* idx = create<IdentifierExpression>("idx");
ArrayAccessorExpression exp;
exp.set_idx_expr(std::move(idx));
exp.set_idx_expr(idx);
EXPECT_FALSE(exp.IsValid());
}
@ -70,21 +67,21 @@ TEST_F(ArrayAccessorExpressionTest, IsValid_MissingIndex) {
auto* ary = create<IdentifierExpression>("ary");
ArrayAccessorExpression exp;
exp.set_array(std::move(ary));
exp.set_array(ary);
EXPECT_FALSE(exp.IsValid());
}
TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidArray) {
auto* ary = create<IdentifierExpression>("");
auto* idx = create<IdentifierExpression>("idx");
ArrayAccessorExpression exp(std::move(ary), std::move(idx));
ArrayAccessorExpression exp(ary, idx);
EXPECT_FALSE(exp.IsValid());
}
TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidIndex) {
auto* ary = create<IdentifierExpression>("ary");
auto* idx = create<IdentifierExpression>("");
ArrayAccessorExpression exp(std::move(ary), std::move(idx));
ArrayAccessorExpression exp(ary, idx);
EXPECT_FALSE(exp.IsValid());
}
@ -92,7 +89,7 @@ TEST_F(ArrayAccessorExpressionTest, ToStr) {
auto* ary = create<IdentifierExpression>("ary");
auto* idx = create<IdentifierExpression>("idx");
ArrayAccessorExpression exp(std::move(ary), std::move(idx));
ArrayAccessorExpression exp(ary, idx);
std::ostringstream out;
exp.to_str(out, 2);

View File

@ -27,20 +27,16 @@ TEST_F(AssignmentStatementTest, Creation) {
auto* lhs = create<ast::IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs");
auto* lhs_ptr = lhs;
auto* rhs_ptr = rhs;
AssignmentStatement stmt(std::move(lhs), std::move(rhs));
EXPECT_EQ(stmt.lhs(), lhs_ptr);
EXPECT_EQ(stmt.rhs(), rhs_ptr);
AssignmentStatement stmt(lhs, rhs);
EXPECT_EQ(stmt.lhs(), lhs);
EXPECT_EQ(stmt.rhs(), rhs);
}
TEST_F(AssignmentStatementTest, CreationWithSource) {
auto* lhs = create<ast::IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs");
AssignmentStatement stmt(Source{Source::Location{20, 2}}, std::move(lhs),
std::move(rhs));
AssignmentStatement stmt(Source{Source::Location{20, 2}}, lhs, rhs);
auto src = stmt.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -50,7 +46,7 @@ TEST_F(AssignmentStatementTest, IsAssign) {
auto* lhs = create<ast::IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs");
AssignmentStatement stmt(std::move(lhs), std::move(rhs));
AssignmentStatement stmt(lhs, rhs);
EXPECT_TRUE(stmt.IsAssign());
}
@ -58,7 +54,7 @@ TEST_F(AssignmentStatementTest, IsValid) {
auto* lhs = create<ast::IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs");
AssignmentStatement stmt(std::move(lhs), std::move(rhs));
AssignmentStatement stmt(lhs, rhs);
EXPECT_TRUE(stmt.IsValid());
}
@ -66,7 +62,7 @@ TEST_F(AssignmentStatementTest, IsValid_MissingLHS) {
auto* rhs = create<ast::IdentifierExpression>("rhs");
AssignmentStatement stmt;
stmt.set_rhs(std::move(rhs));
stmt.set_rhs(rhs);
EXPECT_FALSE(stmt.IsValid());
}
@ -74,21 +70,21 @@ TEST_F(AssignmentStatementTest, IsValid_MissingRHS) {
auto* lhs = create<ast::IdentifierExpression>("lhs");
AssignmentStatement stmt;
stmt.set_lhs(std::move(lhs));
stmt.set_lhs(lhs);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(AssignmentStatementTest, IsValid_InvalidLHS) {
auto* lhs = create<ast::IdentifierExpression>("");
auto* rhs = create<ast::IdentifierExpression>("rhs");
AssignmentStatement stmt(std::move(lhs), std::move(rhs));
AssignmentStatement stmt(lhs, rhs);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(AssignmentStatementTest, IsValid_InvalidRHS) {
auto* lhs = create<ast::IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("");
AssignmentStatement stmt(std::move(lhs), std::move(rhs));
AssignmentStatement stmt(lhs, rhs);
EXPECT_FALSE(stmt.IsValid());
}
@ -96,7 +92,7 @@ TEST_F(AssignmentStatementTest, ToStr) {
auto* lhs = create<ast::IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs");
AssignmentStatement stmt(std::move(lhs), std::move(rhs));
AssignmentStatement stmt(lhs, rhs);
std::ostringstream out;
stmt.to_str(out, 2);

View File

@ -29,12 +29,9 @@ TEST_F(BinaryExpressionTest, Creation) {
auto* lhs = create<IdentifierExpression>("lhs");
auto* rhs = create<IdentifierExpression>("rhs");
auto* lhs_ptr = lhs;
auto* rhs_ptr = rhs;
BinaryExpression r(BinaryOp::kEqual, std::move(lhs), std::move(rhs));
EXPECT_EQ(r.lhs(), lhs_ptr);
EXPECT_EQ(r.rhs(), rhs_ptr);
BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
EXPECT_EQ(r.lhs(), lhs);
EXPECT_EQ(r.rhs(), rhs);
EXPECT_EQ(r.op(), BinaryOp::kEqual);
}
@ -42,8 +39,8 @@ TEST_F(BinaryExpressionTest, Creation_WithSource) {
auto* lhs = create<IdentifierExpression>("lhs");
auto* rhs = create<IdentifierExpression>("rhs");
BinaryExpression r(Source{Source::Location{20, 2}}, BinaryOp::kEqual,
std::move(lhs), std::move(rhs));
BinaryExpression r(Source{Source::Location{20, 2}}, BinaryOp::kEqual, lhs,
rhs);
auto src = r.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -58,7 +55,7 @@ TEST_F(BinaryExpressionTest, IsValid) {
auto* lhs = create<IdentifierExpression>("lhs");
auto* rhs = create<IdentifierExpression>("rhs");
BinaryExpression r(BinaryOp::kEqual, std::move(lhs), std::move(rhs));
BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
EXPECT_TRUE(r.IsValid());
}
@ -67,7 +64,7 @@ TEST_F(BinaryExpressionTest, IsValid_Null_LHS) {
BinaryExpression r;
r.set_op(BinaryOp::kEqual);
r.set_rhs(std::move(rhs));
r.set_rhs(rhs);
EXPECT_FALSE(r.IsValid());
}
@ -75,7 +72,7 @@ TEST_F(BinaryExpressionTest, IsValid_Invalid_LHS) {
auto* lhs = create<IdentifierExpression>("");
auto* rhs = create<IdentifierExpression>("rhs");
BinaryExpression r(BinaryOp::kEqual, std::move(lhs), std::move(rhs));
BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
EXPECT_FALSE(r.IsValid());
}
@ -84,7 +81,7 @@ TEST_F(BinaryExpressionTest, IsValid_Null_RHS) {
BinaryExpression r;
r.set_op(BinaryOp::kEqual);
r.set_lhs(std::move(lhs));
r.set_lhs(lhs);
EXPECT_FALSE(r.IsValid());
}
@ -92,7 +89,7 @@ TEST_F(BinaryExpressionTest, IsValid_Invalid_RHS) {
auto* lhs = create<IdentifierExpression>("lhs");
auto* rhs = create<IdentifierExpression>("");
BinaryExpression r(BinaryOp::kEqual, std::move(lhs), std::move(rhs));
BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
EXPECT_FALSE(r.IsValid());
}
@ -100,7 +97,7 @@ TEST_F(BinaryExpressionTest, IsValid_Binary_None) {
auto* lhs = create<IdentifierExpression>("lhs");
auto* rhs = create<IdentifierExpression>("rhs");
BinaryExpression r(BinaryOp::kNone, std::move(lhs), std::move(rhs));
BinaryExpression r(BinaryOp::kNone, lhs, rhs);
EXPECT_FALSE(r.IsValid());
}
@ -108,7 +105,7 @@ TEST_F(BinaryExpressionTest, ToStr) {
auto* lhs = create<IdentifierExpression>("lhs");
auto* rhs = create<IdentifierExpression>("rhs");
BinaryExpression r(BinaryOp::kEqual, std::move(lhs), std::move(rhs));
BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
std::ostringstream out;
r.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Binary[not set]{

View File

@ -28,18 +28,16 @@ TEST_F(BitcastExpressionTest, Create) {
type::F32Type f32;
auto* expr = create<IdentifierExpression>("expr");
auto* expr_ptr = expr;
BitcastExpression exp(&f32, std::move(expr));
BitcastExpression exp(&f32, expr);
ASSERT_EQ(exp.type(), &f32);
ASSERT_EQ(exp.expr(), expr_ptr);
ASSERT_EQ(exp.expr(), expr);
}
TEST_F(BitcastExpressionTest, CreateWithSource) {
type::F32Type f32;
auto* expr = create<IdentifierExpression>("expr");
BitcastExpression exp(Source{Source::Location{20, 2}}, &f32, std::move(expr));
BitcastExpression exp(Source{Source::Location{20, 2}}, &f32, expr);
auto src = exp.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -54,7 +52,7 @@ TEST_F(BitcastExpressionTest, IsValid) {
type::F32Type f32;
auto* expr = create<IdentifierExpression>("expr");
BitcastExpression exp(&f32, std::move(expr));
BitcastExpression exp(&f32, expr);
EXPECT_TRUE(exp.IsValid());
}
@ -62,7 +60,7 @@ TEST_F(BitcastExpressionTest, IsValid_MissingType) {
auto* expr = create<IdentifierExpression>("expr");
BitcastExpression exp;
exp.set_expr(std::move(expr));
exp.set_expr(expr);
EXPECT_FALSE(exp.IsValid());
}
@ -77,7 +75,7 @@ TEST_F(BitcastExpressionTest, IsValid_MissingExpr) {
TEST_F(BitcastExpressionTest, IsValid_InvalidExpr) {
type::F32Type f32;
auto* expr = create<IdentifierExpression>("");
BitcastExpression e(&f32, std::move(expr));
BitcastExpression e(&f32, expr);
EXPECT_FALSE(e.IsValid());
}
@ -85,7 +83,7 @@ TEST_F(BitcastExpressionTest, ToStr) {
type::F32Type f32;
auto* expr = create<IdentifierExpression>("expr");
BitcastExpression exp(&f32, std::move(expr));
BitcastExpression exp(&f32, expr);
std::ostringstream out;
exp.to_str(out, 2);

View File

@ -32,7 +32,7 @@ TEST_F(BlockStatementTest, Creation) {
auto* ptr = d;
BlockStatement b;
b.append(std::move(d));
b.append(d);
ASSERT_EQ(b.size(), 1u);
EXPECT_EQ(b[0], ptr);
@ -42,21 +42,18 @@ TEST_F(BlockStatementTest, Creation_WithInsert) {
auto* s1 = create<DiscardStatement>();
auto* s2 = create<DiscardStatement>();
auto* s3 = create<DiscardStatement>();
auto* p1 = s1;
auto* p2 = s2;
auto* p3 = s3;
BlockStatement b;
b.insert(0, std::move(s1));
b.insert(0, std::move(s2));
b.insert(1, std::move(s3));
b.insert(0, s1);
b.insert(0, s2);
b.insert(1, s3);
// |b| should contain s2, s3, s1
ASSERT_EQ(b.size(), 3u);
EXPECT_EQ(b[0], p2);
EXPECT_EQ(b[1], p3);
EXPECT_EQ(b[2], p1);
EXPECT_EQ(b[0], s2);
EXPECT_EQ(b[1], s3);
EXPECT_EQ(b[2], s1);
}
TEST_F(BlockStatementTest, Creation_WithSource) {

View File

@ -29,22 +29,18 @@ TEST_F(CallExpressionTest, Creation) {
params.push_back(create<IdentifierExpression>("param1"));
params.push_back(create<IdentifierExpression>("param2"));
auto* func_ptr = func;
auto* param1_ptr = params[0];
auto* param2_ptr = params[1];
CallExpression stmt(std::move(func), std::move(params));
EXPECT_EQ(stmt.func(), func_ptr);
CallExpression stmt(func, params);
EXPECT_EQ(stmt.func(), func);
const auto& vec = stmt.params();
ASSERT_EQ(vec.size(), 2u);
EXPECT_EQ(vec[0], param1_ptr);
EXPECT_EQ(vec[1], param2_ptr);
EXPECT_EQ(vec[0], params[0]);
EXPECT_EQ(vec[1], params[1]);
}
TEST_F(CallExpressionTest, Creation_WithSource) {
auto* func = create<IdentifierExpression>("func");
CallExpression stmt(Source{Source::Location{20, 2}}, std::move(func), {});
CallExpression stmt(Source{Source::Location{20, 2}}, func, {});
auto src = stmt.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -52,13 +48,13 @@ TEST_F(CallExpressionTest, Creation_WithSource) {
TEST_F(CallExpressionTest, IsCall) {
auto* func = create<IdentifierExpression>("func");
CallExpression stmt(std::move(func), {});
CallExpression stmt(func, {});
EXPECT_TRUE(stmt.IsCall());
}
TEST_F(CallExpressionTest, IsValid) {
auto* func = create<IdentifierExpression>("func");
CallExpression stmt(std::move(func), {});
CallExpression stmt(func, {});
EXPECT_TRUE(stmt.IsValid());
}
@ -74,7 +70,7 @@ TEST_F(CallExpressionTest, IsValid_NullParam) {
params.push_back(nullptr);
params.push_back(create<IdentifierExpression>("param2"));
CallExpression stmt(std::move(func), std::move(params));
CallExpression stmt(func, params);
EXPECT_FALSE(stmt.IsValid());
}
@ -83,7 +79,7 @@ TEST_F(CallExpressionTest, IsValid_InvalidFunction) {
ExpressionList params;
params.push_back(create<IdentifierExpression>("param1"));
CallExpression stmt(std::move(func), std::move(params));
CallExpression stmt(func, params);
EXPECT_FALSE(stmt.IsValid());
}
@ -92,13 +88,13 @@ TEST_F(CallExpressionTest, IsValid_InvalidParam) {
ExpressionList params;
params.push_back(create<IdentifierExpression>(""));
CallExpression stmt(std::move(func), std::move(params));
CallExpression stmt(func, params);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(CallExpressionTest, ToStr_NoParams) {
auto* func = create<IdentifierExpression>("func");
CallExpression stmt(std::move(func), {});
CallExpression stmt(func, {});
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Call[not set]{
@ -115,7 +111,7 @@ TEST_F(CallExpressionTest, ToStr_WithParams) {
params.push_back(create<IdentifierExpression>("param1"));
params.push_back(create<IdentifierExpression>("param2"));
CallExpression stmt(std::move(func), std::move(params));
CallExpression stmt(func, params);
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Call[not set]{

View File

@ -27,10 +27,9 @@ using CallStatementTest = TestHelper;
TEST_F(CallStatementTest, Creation) {
auto* expr = create<ast::CallExpression>(
create<ast::IdentifierExpression>("func"), ExpressionList{});
auto* expr_ptr = expr;
CallStatement c(std::move(expr));
EXPECT_EQ(c.expr(), expr_ptr);
CallStatement c(expr);
EXPECT_EQ(c.expr(), expr);
}
TEST_F(CallStatementTest, IsCall) {

View File

@ -32,38 +32,36 @@ TEST_F(CaseStatementTest, Creation_i32) {
ast::type::I32Type i32;
CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, 2));
auto* selector = create<SintLiteral>(&i32, 2);
b.push_back(selector);
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* discard = create<DiscardStatement>();
body->append(discard);
auto* int_ptr = b.back();
auto* discard_ptr = body->get(0);
CaseStatement c(std::move(b), std::move(body));
CaseStatement c(b, body);
ASSERT_EQ(c.selectors().size(), 1u);
EXPECT_EQ(c.selectors()[0], int_ptr);
EXPECT_EQ(c.selectors()[0], selector);
ASSERT_EQ(c.body()->size(), 1u);
EXPECT_EQ(c.body()->get(0), discard_ptr);
EXPECT_EQ(c.body()->get(0), discard);
}
TEST_F(CaseStatementTest, Creation_u32) {
ast::type::U32Type u32;
CaseSelectorList b;
b.push_back(create<UintLiteral>(&u32, 2));
auto* selector = create<SintLiteral>(&u32, 2);
b.push_back(selector);
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* discard = create<DiscardStatement>();
body->append(discard);
auto* int_ptr = b.back();
auto* discard_ptr = body->get(0);
CaseStatement c(std::move(b), std::move(body));
CaseStatement c(b, body);
ASSERT_EQ(c.selectors().size(), 1u);
EXPECT_EQ(c.selectors()[0], int_ptr);
EXPECT_EQ(c.selectors()[0], selector);
ASSERT_EQ(c.body()->size(), 1u);
EXPECT_EQ(c.body()->get(0), discard_ptr);
EXPECT_EQ(c.body()->get(0), discard);
}
TEST_F(CaseStatementTest, Creation_WithSource) {
@ -74,8 +72,7 @@ TEST_F(CaseStatementTest, Creation_WithSource) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
CaseStatement c(Source{Source::Location{20, 2}}, std::move(b),
std::move(body));
CaseStatement c(Source{Source::Location{20, 2}}, b, body);
auto src = c.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -86,7 +83,7 @@ TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
body->append(create<DiscardStatement>());
CaseStatement c(create<ast::BlockStatement>());
c.set_body(std::move(body));
c.set_body(body);
EXPECT_TRUE(c.IsDefault());
}
@ -96,7 +93,7 @@ TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
b.push_back(create<SintLiteral>(&i32, 2));
CaseStatement c(create<ast::BlockStatement>());
c.set_selectors(std::move(b));
c.set_selectors(b);
EXPECT_FALSE(c.IsDefault());
}
@ -119,7 +116,7 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) {
body->append(create<DiscardStatement>());
body->append(nullptr);
CaseStatement c(std::move(b), std::move(body));
CaseStatement c(b, body);
EXPECT_FALSE(c.IsValid());
}
@ -131,7 +128,7 @@ TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) {
auto* body = create<BlockStatement>();
body->append(create<IfStatement>(nullptr, create<ast::BlockStatement>()));
CaseStatement c({std::move(b)}, std::move(body));
CaseStatement c({b}, body);
EXPECT_FALSE(c.IsValid());
}
@ -142,7 +139,7 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
CaseStatement c({std::move(b)}, std::move(body));
CaseStatement c({b}, body);
std::ostringstream out;
c.to_str(out, 2);
@ -159,7 +156,7 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
CaseStatement c({std::move(b)}, std::move(body));
CaseStatement c({b}, body);
std::ostringstream out;
c.to_str(out, 2);
@ -178,7 +175,7 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
CaseStatement c(std::move(b), std::move(body));
CaseStatement c(b, body);
std::ostringstream out;
c.to_str(out, 2);
@ -191,7 +188,7 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
TEST_F(CaseStatementTest, ToStr_WithoutSelectors) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
CaseStatement c(CaseSelectorList{}, std::move(body));
CaseStatement c(CaseSelectorList{}, body);
std::ostringstream out;
c.to_str(out, 2);

View File

@ -35,7 +35,7 @@ using DecoratedVariableTest = TestHelper;
TEST_F(DecoratedVariableTest, Creation) {
type::I32Type t;
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
DecoratedVariable dv(std::move(var));
DecoratedVariable dv(var);
EXPECT_EQ(dv.name(), "my_var");
EXPECT_EQ(dv.storage_class(), StorageClass::kFunction);
@ -50,7 +50,7 @@ TEST_F(DecoratedVariableTest, CreationWithSource) {
Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}};
type::F32Type t;
auto* var = create<Variable>(s, "i", StorageClass::kPrivate, &t);
DecoratedVariable dv(std::move(var));
DecoratedVariable dv(var);
EXPECT_EQ(dv.name(), "i");
EXPECT_EQ(dv.storage_class(), StorageClass::kPrivate);
@ -64,7 +64,7 @@ TEST_F(DecoratedVariableTest, CreationWithSource) {
TEST_F(DecoratedVariableTest, NoDecorations) {
type::I32Type t;
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
DecoratedVariable dv(std::move(var));
DecoratedVariable dv(var);
EXPECT_FALSE(dv.HasLocationDecoration());
EXPECT_FALSE(dv.HasBuiltinDecoration());
EXPECT_FALSE(dv.HasConstantIdDecoration());
@ -73,14 +73,14 @@ TEST_F(DecoratedVariableTest, NoDecorations) {
TEST_F(DecoratedVariableTest, WithDecorations) {
type::F32Type t;
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
DecoratedVariable dv(std::move(var));
DecoratedVariable dv(var);
VariableDecorationList decos;
decos.push_back(create<LocationDecoration>(1, Source{}));
decos.push_back(create<BuiltinDecoration>(ast::Builtin::kPosition, Source{}));
decos.push_back(create<ConstantIdDecoration>(1200, Source{}));
dv.set_decorations(std::move(decos));
dv.set_decorations(decos);
EXPECT_TRUE(dv.HasLocationDecoration());
EXPECT_TRUE(dv.HasBuiltinDecoration());
@ -90,11 +90,11 @@ TEST_F(DecoratedVariableTest, WithDecorations) {
TEST_F(DecoratedVariableTest, ConstantId) {
type::F32Type t;
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
DecoratedVariable dv(std::move(var));
DecoratedVariable dv(var);
VariableDecorationList decos;
decos.push_back(create<ConstantIdDecoration>(1200, Source{}));
dv.set_decorations(std::move(decos));
dv.set_decorations(decos);
EXPECT_EQ(dv.constant_id(), 1200u);
}
@ -102,7 +102,7 @@ TEST_F(DecoratedVariableTest, ConstantId) {
TEST_F(DecoratedVariableTest, IsValid) {
type::I32Type t;
auto* var = create<Variable>("my_var", StorageClass::kNone, &t);
DecoratedVariable dv(std::move(var));
DecoratedVariable dv(var);
EXPECT_TRUE(dv.IsValid());
}
@ -114,14 +114,14 @@ TEST_F(DecoratedVariableTest, IsDecorated) {
TEST_F(DecoratedVariableTest, to_str) {
type::F32Type t;
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
DecoratedVariable dv(std::move(var));
DecoratedVariable dv(var);
dv.set_constructor(create<IdentifierExpression>("expr"));
VariableDecorationList decos;
decos.push_back(create<BindingDecoration>(2, Source{}));
decos.push_back(create<SetDecoration>(1, Source{}));
dv.set_decorations(std::move(decos));
dv.set_decorations(decos);
std::ostringstream out;
dv.to_str(out, 2);
EXPECT_EQ(out.str(), R"( DecoratedVariable{

View File

@ -34,13 +34,12 @@ TEST_F(ElseStatementTest, Creation) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* cond_ptr = cond;
auto* discard_ptr = body->get(0);
auto* discard = body->get(0);
ElseStatement e(std::move(cond), std::move(body));
EXPECT_EQ(e.condition(), cond_ptr);
ElseStatement e(cond, body);
EXPECT_EQ(e.condition(), cond);
ASSERT_EQ(e.body()->size(), 1u);
EXPECT_EQ(e.body()->get(0), discard_ptr);
EXPECT_EQ(e.body()->get(0), discard);
}
TEST_F(ElseStatementTest, Creation_WithSource) {
@ -59,7 +58,7 @@ TEST_F(ElseStatementTest, HasCondition) {
ast::type::BoolType bool_type;
auto* cond = create<ScalarConstructorExpression>(
create<BoolLiteral>(&bool_type, true));
ElseStatement e(std::move(cond), create<BlockStatement>());
ElseStatement e(cond, create<BlockStatement>());
EXPECT_TRUE(e.HasCondition());
}
@ -77,7 +76,7 @@ TEST_F(ElseStatementTest, IsValid_WithBody) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
ElseStatement e(std::move(body));
ElseStatement e(body);
EXPECT_TRUE(e.IsValid());
}
@ -86,13 +85,13 @@ TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) {
body->append(create<DiscardStatement>());
body->append(nullptr);
ElseStatement e(std::move(body));
ElseStatement e(body);
EXPECT_FALSE(e.IsValid());
}
TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
auto* cond = create<ScalarConstructorExpression>();
ElseStatement e(std::move(cond), create<BlockStatement>());
ElseStatement e(cond, create<BlockStatement>());
EXPECT_FALSE(e.IsValid());
}
@ -100,7 +99,7 @@ TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
auto* body = create<BlockStatement>();
body->append(create<IfStatement>(nullptr, create<ast::BlockStatement>()));
ElseStatement e(std::move(body));
ElseStatement e(body);
EXPECT_FALSE(e.IsValid());
}
@ -111,7 +110,7 @@ TEST_F(ElseStatementTest, ToStr) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
ElseStatement e(std::move(cond), std::move(body));
ElseStatement e(cond, body);
std::ostringstream out;
e.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Else{
@ -129,7 +128,7 @@ TEST_F(ElseStatementTest, ToStr_NoCondition) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
ElseStatement e(std::move(body));
ElseStatement e(body);
std::ostringstream out;
e.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Else{

View File

@ -38,14 +38,13 @@ TEST_F(FunctionTest, Creation) {
VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
auto* var_ptr = params[0];
auto* var = params[0];
Function f("func", std::move(params), &void_type,
create<ast::BlockStatement>());
Function f("func", params, &void_type, create<ast::BlockStatement>());
EXPECT_EQ(f.name(), "func");
ASSERT_EQ(f.params().size(), 1u);
EXPECT_EQ(f.return_type(), &void_type);
EXPECT_EQ(f.params()[0], var_ptr);
EXPECT_EQ(f.params()[0], var);
}
TEST_F(FunctionTest, Creation_WithSource) {
@ -55,8 +54,8 @@ TEST_F(FunctionTest, Creation_WithSource) {
VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
Function f(Source{Source::Location{20, 2}}, "func", std::move(params),
&void_type, create<ast::BlockStatement>());
Function f(Source{Source::Location{20, 2}}, "func", params, &void_type,
create<ast::BlockStatement>());
auto src = f.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -86,28 +85,23 @@ TEST_F(FunctionTest, GetReferenceLocations) {
type::VoidType void_type;
type::I32Type i32;
VariableDecorationList decos;
DecoratedVariable loc1(
create<ast::Variable>("loc1", StorageClass::kInput, &i32));
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
loc1.set_decorations(std::move(decos));
loc1.set_decorations({create<ast::LocationDecoration>(0, Source{})});
DecoratedVariable loc2(
create<ast::Variable>("loc2", StorageClass::kInput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
loc2.set_decorations(std::move(decos));
loc2.set_decorations({create<ast::LocationDecoration>(1, Source{})});
DecoratedVariable builtin1(
create<ast::Variable>("builtin1", StorageClass::kInput, &i32));
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kPosition, Source{}));
builtin1.set_decorations(std::move(decos));
builtin1.set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition, Source{})});
DecoratedVariable builtin2(
create<ast::Variable>("builtin2", StorageClass::kInput, &i32));
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{}));
builtin2.set_decorations(std::move(decos));
builtin2.set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{})});
Function f("func", VariableList{}, &void_type, create<ast::BlockStatement>());
@ -129,28 +123,23 @@ TEST_F(FunctionTest, GetReferenceBuiltins) {
type::VoidType void_type;
type::I32Type i32;
VariableDecorationList decos;
DecoratedVariable loc1(
create<ast::Variable>("loc1", StorageClass::kInput, &i32));
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
loc1.set_decorations(std::move(decos));
loc1.set_decorations({create<ast::LocationDecoration>(0, Source{})});
DecoratedVariable loc2(
create<ast::Variable>("loc2", StorageClass::kInput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
loc2.set_decorations(std::move(decos));
loc2.set_decorations({create<ast::LocationDecoration>(1, Source{})});
DecoratedVariable builtin1(
create<ast::Variable>("builtin1", StorageClass::kInput, &i32));
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kPosition, Source{}));
builtin1.set_decorations(std::move(decos));
builtin1.set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition, Source{})});
DecoratedVariable builtin2(
create<ast::Variable>("builtin2", StorageClass::kInput, &i32));
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{}));
builtin2.set_decorations(std::move(decos));
builtin2.set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{})});
Function f("func", VariableList{}, &void_type, create<ast::BlockStatement>());
@ -191,9 +180,8 @@ TEST_F(FunctionTest, IsValid) {
auto* block = create<ast::BlockStatement>();
block->append(create<DiscardStatement>());
Function f("func", std::move(params), &void_type,
create<ast::BlockStatement>());
f.set_body(std::move(block));
Function f("func", params, &void_type, create<ast::BlockStatement>());
f.set_body(block);
EXPECT_TRUE(f.IsValid());
}
@ -204,7 +192,7 @@ TEST_F(FunctionTest, IsValid_EmptyName) {
VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
Function f("", std::move(params), &void_type, create<ast::BlockStatement>());
Function f("", params, &void_type, create<ast::BlockStatement>());
EXPECT_FALSE(f.IsValid());
}
@ -214,7 +202,7 @@ TEST_F(FunctionTest, IsValid_MissingReturnType) {
VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
Function f("func", std::move(params), nullptr, create<ast::BlockStatement>());
Function f("func", params, nullptr, create<ast::BlockStatement>());
EXPECT_FALSE(f.IsValid());
}
@ -226,8 +214,7 @@ TEST_F(FunctionTest, IsValid_NullParam) {
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
params.push_back(nullptr);
Function f("func", std::move(params), &void_type,
create<ast::BlockStatement>());
Function f("func", params, &void_type, create<ast::BlockStatement>());
EXPECT_FALSE(f.IsValid());
}
@ -237,8 +224,7 @@ TEST_F(FunctionTest, IsValid_InvalidParam) {
VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, nullptr));
Function f("func", std::move(params), &void_type,
create<ast::BlockStatement>());
Function f("func", params, &void_type, create<ast::BlockStatement>());
EXPECT_FALSE(f.IsValid());
}
@ -253,9 +239,8 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) {
block->append(create<DiscardStatement>());
block->append(nullptr);
Function f("func", std::move(params), &void_type,
create<ast::BlockStatement>());
f.set_body(std::move(block));
Function f("func", params, &void_type, create<ast::BlockStatement>());
f.set_body(block);
EXPECT_FALSE(f.IsValid());
}
@ -270,9 +255,8 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) {
block->append(create<DiscardStatement>());
block->append(nullptr);
Function f("func", std::move(params), &void_type,
create<ast::BlockStatement>());
f.set_body(std::move(block));
Function f("func", params, &void_type, create<ast::BlockStatement>());
f.set_body(block);
EXPECT_FALSE(f.IsValid());
}
@ -284,7 +268,7 @@ TEST_F(FunctionTest, ToStr) {
block->append(create<DiscardStatement>());
Function f("func", {}, &void_type, create<ast::BlockStatement>());
f.set_body(std::move(block));
f.set_body(block);
std::ostringstream out;
f.to_str(out, 2);
@ -304,7 +288,7 @@ TEST_F(FunctionTest, ToStr_WithDecoration) {
block->append(create<DiscardStatement>());
Function f("func", {}, &void_type, create<ast::BlockStatement>());
f.set_body(std::move(block));
f.set_body(block);
f.add_decoration(create<WorkgroupDecoration>(2, 4, 6, Source{}));
std::ostringstream out;
@ -328,9 +312,8 @@ TEST_F(FunctionTest, ToStr_WithParams) {
auto* block = create<ast::BlockStatement>();
block->append(create<DiscardStatement>());
Function f("func", std::move(params), &void_type,
create<ast::BlockStatement>());
f.set_body(std::move(block));
Function f("func", params, &void_type, create<ast::BlockStatement>());
f.set_body(block);
std::ostringstream out;
f.to_str(out, 2);
@ -364,8 +347,7 @@ TEST_F(FunctionTest, TypeName_WithParams) {
params.push_back(create<Variable>("var1", StorageClass::kNone, &i32));
params.push_back(create<Variable>("var2", StorageClass::kNone, &f32));
Function f("func", std::move(params), &void_type,
create<ast::BlockStatement>());
Function f("func", params, &void_type, create<ast::BlockStatement>());
EXPECT_EQ(f.type_name(), "__func__void__i32__f32");
}
@ -375,13 +357,11 @@ TEST_F(FunctionTest, GetLastStatement) {
VariableList params;
auto* body = create<ast::BlockStatement>();
auto* stmt = create<DiscardStatement>();
auto* stmt_ptr = stmt;
body->append(std::move(stmt));
Function f("func", std::move(params), &void_type,
create<ast::BlockStatement>());
f.set_body(std::move(body));
body->append(stmt);
Function f("func", params, &void_type, create<ast::BlockStatement>());
f.set_body(body);
EXPECT_EQ(f.get_last_statement(), stmt_ptr);
EXPECT_EQ(f.get_last_statement(), stmt);
}
TEST_F(FunctionTest, GetLastStatement_nullptr) {
@ -389,9 +369,8 @@ TEST_F(FunctionTest, GetLastStatement_nullptr) {
VariableList params;
auto* body = create<ast::BlockStatement>();
Function f("func", std::move(params), &void_type,
create<ast::BlockStatement>());
f.set_body(std::move(body));
Function f("func", params, &void_type, create<ast::BlockStatement>());
f.set_body(body);
EXPECT_EQ(f.get_last_statement(), nullptr);
}

View File

@ -27,15 +27,13 @@ using IfStatementTest = TestHelper;
TEST_F(IfStatementTest, Creation) {
auto* cond = create<IdentifierExpression>("cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* discard = create<DiscardStatement>();
body->append(discard);
auto* cond_ptr = cond;
auto* stmt_ptr = body->get(0);
IfStatement stmt(std::move(cond), std::move(body));
EXPECT_EQ(stmt.condition(), cond_ptr);
IfStatement stmt(cond, body);
EXPECT_EQ(stmt.condition(), cond);
ASSERT_EQ(stmt.body()->size(), 1u);
EXPECT_EQ(stmt.body()->get(0), stmt_ptr);
EXPECT_EQ(stmt.body()->get(0), discard);
}
TEST_F(IfStatementTest, Creation_WithSource) {
@ -43,8 +41,7 @@ TEST_F(IfStatementTest, Creation_WithSource) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
IfStatement stmt(Source{Source::Location{20, 2}}, std::move(cond),
std::move(body));
IfStatement stmt(Source{Source::Location{20, 2}}, cond, body);
auto src = stmt.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -60,7 +57,7 @@ TEST_F(IfStatementTest, IsValid) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
IfStatement stmt(std::move(cond), std::move(body));
IfStatement stmt(cond, body);
EXPECT_TRUE(stmt.IsValid());
}
@ -74,8 +71,8 @@ TEST_F(IfStatementTest, IsValid_WithElseStatements) {
else_stmts[0]->set_condition(create<IdentifierExpression>("Ident"));
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
IfStatement stmt(std::move(cond), std::move(body));
stmt.set_else_statements(std::move(else_stmts));
IfStatement stmt(cond, body);
stmt.set_else_statements(else_stmts);
EXPECT_TRUE(stmt.IsValid());
}
@ -83,7 +80,7 @@ TEST_F(IfStatementTest, IsValid_MissingCondition) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
IfStatement stmt(nullptr, std::move(body));
IfStatement stmt(nullptr, body);
EXPECT_FALSE(stmt.IsValid());
}
@ -92,7 +89,7 @@ TEST_F(IfStatementTest, IsValid_InvalidCondition) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
IfStatement stmt(std::move(cond), std::move(body));
IfStatement stmt(cond, body);
EXPECT_FALSE(stmt.IsValid());
}
@ -102,7 +99,7 @@ TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
body->append(create<DiscardStatement>());
body->append(nullptr);
IfStatement stmt(std::move(cond), std::move(body));
IfStatement stmt(cond, body);
EXPECT_FALSE(stmt.IsValid());
}
@ -112,7 +109,7 @@ TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
body->append(create<DiscardStatement>());
body->append(create<IfStatement>(nullptr, create<BlockStatement>()));
IfStatement stmt(std::move(cond), std::move(body));
IfStatement stmt(cond, body);
EXPECT_FALSE(stmt.IsValid());
}
@ -127,8 +124,8 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) {
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
else_stmts.push_back(nullptr);
IfStatement stmt(std::move(cond), std::move(body));
stmt.set_else_statements(std::move(else_stmts));
IfStatement stmt(cond, body);
stmt.set_else_statements(else_stmts);
EXPECT_FALSE(stmt.IsValid());
}
@ -141,8 +138,8 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
else_stmts[0]->set_condition(create<IdentifierExpression>(""));
IfStatement stmt(std::move(cond), std::move(body));
stmt.set_else_statements(std::move(else_stmts));
IfStatement stmt(cond, body);
stmt.set_else_statements(else_stmts);
EXPECT_FALSE(stmt.IsValid());
}
@ -155,8 +152,8 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
IfStatement stmt(std::move(cond), std::move(body));
stmt.set_else_statements(std::move(else_stmts));
IfStatement stmt(cond, body);
stmt.set_else_statements(else_stmts);
EXPECT_FALSE(stmt.IsValid());
}
@ -170,8 +167,8 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) {
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
else_stmts[1]->set_condition(create<IdentifierExpression>("ident"));
IfStatement stmt(std::move(cond), std::move(body));
stmt.set_else_statements(std::move(else_stmts));
IfStatement stmt(cond, body);
stmt.set_else_statements(else_stmts);
EXPECT_FALSE(stmt.IsValid());
}
@ -180,7 +177,7 @@ TEST_F(IfStatementTest, ToStr) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
IfStatement stmt(std::move(cond), std::move(body));
IfStatement stmt(cond, body);
std::ostringstream out;
stmt.to_str(out, 2);
@ -210,12 +207,12 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) {
ElseStatementList else_stmts;
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
else_stmts[0]->set_condition(create<IdentifierExpression>("ident"));
else_stmts[0]->set_body(std::move(else_if_body));
else_stmts[0]->set_body(else_if_body);
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
else_stmts[1]->set_body(std::move(else_body));
else_stmts[1]->set_body(else_body);
IfStatement stmt(std::move(cond), std::move(body));
stmt.set_else_statements(std::move(else_stmts));
IfStatement stmt(cond, body);
stmt.set_else_statements(else_stmts);
std::ostringstream out;
stmt.to_str(out, 2);

View File

@ -30,17 +30,16 @@ using LoopStatementTest = TestHelper;
TEST_F(LoopStatementTest, Creation) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
auto* b_ptr = body->last();
auto* b = body->last();
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
auto* c_ptr = continuing->last();
LoopStatement l(std::move(body), std::move(continuing));
LoopStatement l(body, continuing);
ASSERT_EQ(l.body()->size(), 1u);
EXPECT_EQ(l.body()->get(0), b_ptr);
EXPECT_EQ(l.body()->get(0), b);
ASSERT_EQ(l.continuing()->size(), 1u);
EXPECT_EQ(l.continuing()->get(0), c_ptr);
EXPECT_EQ(l.continuing()->get(0), continuing->last());
}
TEST_F(LoopStatementTest, Creation_WithSource) {
@ -50,8 +49,7 @@ TEST_F(LoopStatementTest, Creation_WithSource) {
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
LoopStatement l(Source{Source::Location{20, 2}}, std::move(body),
std::move(continuing));
LoopStatement l(Source{Source::Location{20, 2}}, body, continuing);
auto src = l.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -66,7 +64,7 @@ TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
LoopStatement l(std::move(body), {});
LoopStatement l(body, {});
EXPECT_FALSE(l.has_continuing());
}
@ -77,7 +75,7 @@ TEST_F(LoopStatementTest, HasContinuing_WithContinuing) {
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
LoopStatement l(std::move(body), std::move(continuing));
LoopStatement l(body, continuing);
EXPECT_TRUE(l.has_continuing());
}
@ -88,7 +86,7 @@ TEST_F(LoopStatementTest, IsValid) {
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
LoopStatement l(std::move(body), std::move(continuing));
LoopStatement l(body, continuing);
EXPECT_TRUE(l.IsValid());
}
@ -96,7 +94,7 @@ TEST_F(LoopStatementTest, IsValid_WithoutContinuing) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
LoopStatement l(std::move(body), create<BlockStatement>());
LoopStatement l(body, create<BlockStatement>());
EXPECT_TRUE(l.IsValid());
}
@ -113,7 +111,7 @@ TEST_F(LoopStatementTest, IsValid_NullBodyStatement) {
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
LoopStatement l(std::move(body), std::move(continuing));
LoopStatement l(body, continuing);
EXPECT_FALSE(l.IsValid());
}
@ -125,7 +123,7 @@ TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) {
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
LoopStatement l(std::move(body), std::move(continuing));
LoopStatement l(body, continuing);
EXPECT_FALSE(l.IsValid());
}
@ -137,7 +135,7 @@ TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) {
continuing->append(create<DiscardStatement>());
continuing->append(nullptr);
LoopStatement l(std::move(body), std::move(continuing));
LoopStatement l(body, continuing);
EXPECT_FALSE(l.IsValid());
}
@ -149,7 +147,7 @@ TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) {
continuing->append(create<DiscardStatement>());
continuing->append(create<IfStatement>(nullptr, create<BlockStatement>()));
LoopStatement l(std::move(body), std::move(continuing));
LoopStatement l(body, continuing);
EXPECT_FALSE(l.IsValid());
}
@ -157,7 +155,7 @@ TEST_F(LoopStatementTest, ToStr) {
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
LoopStatement l(std::move(body), {});
LoopStatement l(body, {});
std::ostringstream out;
l.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Loop{
@ -173,7 +171,7 @@ TEST_F(LoopStatementTest, ToStr_WithContinuing) {
auto* continuing = create<BlockStatement>();
continuing->append(create<DiscardStatement>());
LoopStatement l(std::move(body), std::move(continuing));
LoopStatement l(body, continuing);
std::ostringstream out;
l.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Loop{

View File

@ -29,20 +29,16 @@ TEST_F(MemberAccessorExpressionTest, Creation) {
auto* str = create<IdentifierExpression>("structure");
auto* mem = create<IdentifierExpression>("member");
auto* str_ptr = str;
auto* mem_ptr = mem;
MemberAccessorExpression stmt(std::move(str), std::move(mem));
EXPECT_EQ(stmt.structure(), str_ptr);
EXPECT_EQ(stmt.member(), mem_ptr);
MemberAccessorExpression stmt(str, mem);
EXPECT_EQ(stmt.structure(), str);
EXPECT_EQ(stmt.member(), mem);
}
TEST_F(MemberAccessorExpressionTest, Creation_WithSource) {
auto* str = create<IdentifierExpression>("structure");
auto* mem = create<IdentifierExpression>("member");
MemberAccessorExpression stmt(Source{Source::Location{20, 2}}, std::move(str),
std::move(mem));
MemberAccessorExpression stmt(Source{Source::Location{20, 2}}, str, mem);
auto src = stmt.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -57,7 +53,7 @@ TEST_F(MemberAccessorExpressionTest, IsValid) {
auto* str = create<IdentifierExpression>("structure");
auto* mem = create<IdentifierExpression>("member");
MemberAccessorExpression stmt(std::move(str), std::move(mem));
MemberAccessorExpression stmt(str, mem);
EXPECT_TRUE(stmt.IsValid());
}
@ -65,7 +61,7 @@ TEST_F(MemberAccessorExpressionTest, IsValid_NullStruct) {
auto* mem = create<IdentifierExpression>("member");
MemberAccessorExpression stmt;
stmt.set_member(std::move(mem));
stmt.set_member(mem);
EXPECT_FALSE(stmt.IsValid());
}
@ -73,7 +69,7 @@ TEST_F(MemberAccessorExpressionTest, IsValid_InvalidStruct) {
auto* str = create<IdentifierExpression>("");
auto* mem = create<IdentifierExpression>("member");
MemberAccessorExpression stmt(std::move(str), std::move(mem));
MemberAccessorExpression stmt(str, mem);
EXPECT_FALSE(stmt.IsValid());
}
@ -81,7 +77,7 @@ TEST_F(MemberAccessorExpressionTest, IsValid_NullMember) {
auto* str = create<IdentifierExpression>("structure");
MemberAccessorExpression stmt;
stmt.set_structure(std::move(str));
stmt.set_structure(str);
EXPECT_FALSE(stmt.IsValid());
}
@ -89,7 +85,7 @@ TEST_F(MemberAccessorExpressionTest, IsValid_InvalidMember) {
auto* str = create<IdentifierExpression>("structure");
auto* mem = create<IdentifierExpression>("");
MemberAccessorExpression stmt(std::move(str), std::move(mem));
MemberAccessorExpression stmt(str, mem);
EXPECT_FALSE(stmt.IsValid());
}
@ -97,7 +93,7 @@ TEST_F(MemberAccessorExpressionTest, ToStr) {
auto* str = create<IdentifierExpression>("structure");
auto* mem = create<IdentifierExpression>("member");
MemberAccessorExpression stmt(std::move(str), std::move(mem));
MemberAccessorExpression stmt(str, mem);
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( MemberAccessor[not set]{

View File

@ -49,10 +49,9 @@ TEST_F(ModuleTest, LookupFunction) {
Module m;
auto* func = create<Function>("main", VariableList{}, &f32,
create<ast::BlockStatement>());
auto* func_ptr = func;
m.AddFunction(std::move(func));
EXPECT_EQ(func_ptr, m.FindFunctionByName("main"));
create<ast::BlockStatement>());
m.AddFunction(func);
EXPECT_EQ(func, m.FindFunctionByName("main"));
}
TEST_F(ModuleTest, LookupFunctionMissing) {
@ -70,7 +69,7 @@ TEST_F(ModuleTest, IsValid_GlobalVariable) {
auto* var = create<Variable>("var", StorageClass::kInput, &f32);
Module m;
m.AddGlobalVariable(std::move(var));
m.AddGlobalVariable(var);
EXPECT_TRUE(m.IsValid());
}
@ -84,7 +83,7 @@ TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) {
auto* var = create<Variable>("var", StorageClass::kInput, nullptr);
Module m;
m.AddGlobalVariable(std::move(var));
m.AddGlobalVariable(var);
EXPECT_FALSE(m.IsValid());
}
@ -126,10 +125,10 @@ TEST_F(ModuleTest, IsValid_Struct_EmptyName) {
TEST_F(ModuleTest, IsValid_Function) {
type::F32Type f32;
auto* func = create<Function>("main", VariableList(), &f32,
create<ast::BlockStatement>());
create<ast::BlockStatement>());
Module m;
m.AddFunction(std::move(func));
m.AddFunction(func);
EXPECT_TRUE(m.IsValid());
}
@ -143,7 +142,7 @@ TEST_F(ModuleTest, IsValid_Invalid_Function) {
auto* func = create<Function>();
Module m;
m.AddFunction(std::move(func));
m.AddFunction(func);
EXPECT_FALSE(m.IsValid());
}

View File

@ -27,10 +27,9 @@ using ReturnStatementTest = TestHelper;
TEST_F(ReturnStatementTest, Creation) {
auto* expr = create<IdentifierExpression>("expr");
auto* expr_ptr = expr;
ReturnStatement r(std::move(expr));
EXPECT_EQ(r.value(), expr_ptr);
ReturnStatement r(expr);
EXPECT_EQ(r.value(), expr);
}
TEST_F(ReturnStatementTest, Creation_WithSource) {
@ -52,7 +51,7 @@ TEST_F(ReturnStatementTest, HasValue_WithoutValue) {
TEST_F(ReturnStatementTest, HasValue_WithValue) {
auto* expr = create<IdentifierExpression>("expr");
ReturnStatement r(std::move(expr));
ReturnStatement r(expr);
EXPECT_TRUE(r.has_value());
}
@ -63,19 +62,19 @@ TEST_F(ReturnStatementTest, IsValid_WithoutValue) {
TEST_F(ReturnStatementTest, IsValid_WithValue) {
auto* expr = create<IdentifierExpression>("expr");
ReturnStatement r(std::move(expr));
ReturnStatement r(expr);
EXPECT_TRUE(r.IsValid());
}
TEST_F(ReturnStatementTest, IsValid_InvalidValue) {
auto* expr = create<IdentifierExpression>("");
ReturnStatement r(std::move(expr));
ReturnStatement r(expr);
EXPECT_FALSE(r.IsValid());
}
TEST_F(ReturnStatementTest, ToStr_WithValue) {
auto* expr = create<IdentifierExpression>("expr");
ReturnStatement r(std::move(expr));
ReturnStatement r(expr);
std::ostringstream out;
r.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Return{

View File

@ -27,15 +27,14 @@ using ScalarConstructorExpressionTest = TestHelper;
TEST_F(ScalarConstructorExpressionTest, Creation) {
ast::type::BoolType bool_type;
auto* b = create<BoolLiteral>(&bool_type, true);
auto* b_ptr = b;
ScalarConstructorExpression c(std::move(b));
EXPECT_EQ(c.literal(), b_ptr);
ScalarConstructorExpression c(b);
EXPECT_EQ(c.literal(), b);
}
TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) {
ast::type::BoolType bool_type;
auto* b = create<BoolLiteral>(&bool_type, true);
ScalarConstructorExpression c(Source{Source::Location{20, 2}}, std::move(b));
ScalarConstructorExpression c(Source{Source::Location{20, 2}}, b);
auto src = c.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -44,7 +43,7 @@ TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) {
TEST_F(ScalarConstructorExpressionTest, IsValid) {
ast::type::BoolType bool_type;
auto* b = create<BoolLiteral>(&bool_type, true);
ScalarConstructorExpression c(std::move(b));
ScalarConstructorExpression c(b);
EXPECT_TRUE(c.IsValid());
}
@ -56,7 +55,7 @@ TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) {
TEST_F(ScalarConstructorExpressionTest, ToStr) {
ast::type::BoolType bool_type;
auto* b = create<BoolLiteral>(&bool_type, true);
ScalarConstructorExpression c(std::move(b));
ScalarConstructorExpression c(b);
std::ostringstream out;
c.to_str(out, 2);
EXPECT_EQ(out.str(), R"( ScalarConstructor[not set]{true}

View File

@ -32,7 +32,7 @@ TEST_F(StructMemberTest, Creation) {
StructMemberDecorationList decorations;
decorations.emplace_back(create<StructMemberOffsetDecoration>(4, Source{}));
StructMember st{"a", &i32, std::move(decorations)};
StructMember st{"a", &i32, decorations};
EXPECT_EQ(st.name(), "a");
EXPECT_EQ(st.type(), &i32);
EXPECT_EQ(st.decorations().size(), 1u);
@ -80,7 +80,7 @@ TEST_F(StructMemberTest, IsValid_Null_Decoration) {
decorations.emplace_back(create<StructMemberOffsetDecoration>(4, Source{}));
decorations.push_back(nullptr);
StructMember st{"a", &i32, std::move(decorations)};
StructMember st{"a", &i32, decorations};
EXPECT_FALSE(st.IsValid());
}
@ -89,7 +89,7 @@ TEST_F(StructMemberTest, ToStr) {
StructMemberDecorationList decorations;
decorations.emplace_back(create<StructMemberOffsetDecoration>(4, Source{}));
StructMember st{"a", &i32, std::move(decorations)};
StructMember st{"a", &i32, decorations};
std::ostringstream out;
st.to_str(out, 2);
EXPECT_EQ(out.str(), " StructMember{[[ offset 4 ]] a: __i32}\n");

View File

@ -36,22 +36,19 @@ TEST_F(SwitchStatementTest, Creation) {
auto* ident = create<IdentifierExpression>("ident");
CaseStatementList body;
body.push_back(
create<CaseStatement>(std::move(lit), create<ast::BlockStatement>()));
auto* case_stmt = create<CaseStatement>(lit, create<ast::BlockStatement>());
body.push_back(case_stmt);
auto* ident_ptr = ident;
auto* case_ptr = body[0];
SwitchStatement stmt(std::move(ident), std::move(body));
EXPECT_EQ(stmt.condition(), ident_ptr);
SwitchStatement stmt(ident, body);
EXPECT_EQ(stmt.condition(), ident);
ASSERT_EQ(stmt.body().size(), 1u);
EXPECT_EQ(stmt.body()[0], case_ptr);
EXPECT_EQ(stmt.body()[0], case_stmt);
}
TEST_F(SwitchStatementTest, Creation_WithSource) {
auto* ident = create<IdentifierExpression>("ident");
SwitchStatement stmt(Source{Source::Location{20, 2}}, std::move(ident),
SwitchStatement stmt(Source{Source::Location{20, 2}}, ident,
CaseStatementList());
auto src = stmt.source();
EXPECT_EQ(src.range.begin.line, 20u);
@ -71,10 +68,9 @@ TEST_F(SwitchStatementTest, IsValid) {
auto* ident = create<IdentifierExpression>("ident");
CaseStatementList body;
body.push_back(
create<CaseStatement>(std::move(lit), create<ast::BlockStatement>()));
body.push_back(create<CaseStatement>(lit, create<ast::BlockStatement>()));
SwitchStatement stmt(std::move(ident), std::move(body));
SwitchStatement stmt(ident, body);
EXPECT_TRUE(stmt.IsValid());
}
@ -85,11 +81,10 @@ TEST_F(SwitchStatementTest, IsValid_Null_Condition) {
lit.push_back(create<SintLiteral>(&i32, 2));
CaseStatementList body;
body.push_back(
create<CaseStatement>(std::move(lit), create<ast::BlockStatement>()));
body.push_back(create<CaseStatement>(lit, create<ast::BlockStatement>()));
SwitchStatement stmt;
stmt.set_body(std::move(body));
stmt.set_body(body);
EXPECT_FALSE(stmt.IsValid());
}
@ -101,10 +96,9 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) {
auto* ident = create<IdentifierExpression>("");
CaseStatementList body;
body.push_back(
create<CaseStatement>(std::move(lit), create<ast::BlockStatement>()));
body.push_back(create<CaseStatement>(lit, create<ast::BlockStatement>()));
SwitchStatement stmt(std::move(ident), std::move(body));
SwitchStatement stmt(ident, body);
EXPECT_FALSE(stmt.IsValid());
}
@ -116,11 +110,10 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
auto* ident = create<IdentifierExpression>("ident");
CaseStatementList body;
body.push_back(
create<CaseStatement>(std::move(lit), create<ast::BlockStatement>()));
body.push_back(create<CaseStatement>(lit, create<ast::BlockStatement>()));
body.push_back(nullptr);
SwitchStatement stmt(std::move(ident), std::move(body));
SwitchStatement stmt(ident, body);
EXPECT_FALSE(stmt.IsValid());
}
@ -131,17 +124,16 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) {
case_body->append(nullptr);
CaseStatementList body;
body.push_back(
create<CaseStatement>(CaseSelectorList{}, std::move(case_body)));
body.push_back(create<CaseStatement>(CaseSelectorList{}, case_body));
SwitchStatement stmt(std::move(ident), std::move(body));
SwitchStatement stmt(ident, body);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(SwitchStatementTest, ToStr_Empty) {
auto* ident = create<IdentifierExpression>("ident");
SwitchStatement stmt(std::move(ident), {});
SwitchStatement stmt(ident, {});
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Switch{
@ -160,10 +152,9 @@ TEST_F(SwitchStatementTest, ToStr) {
auto* ident = create<IdentifierExpression>("ident");
CaseStatementList body;
body.push_back(
create<CaseStatement>(std::move(lit), create<ast::BlockStatement>()));
body.push_back(create<CaseStatement>(lit, create<ast::BlockStatement>()));
SwitchStatement stmt(std::move(ident), std::move(body));
SwitchStatement stmt(ident, body);
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Switch{

View File

@ -103,7 +103,7 @@ TEST_F(AccessControlTypeTest, MinBufferBindingSizeArray) {
ArrayType array(&u32, 4);
ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(std::move(decos));
array.set_decorations(decos);
AccessControlType at{AccessControl::kReadOnly, &array};
EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
}
@ -113,7 +113,7 @@ TEST_F(AccessControlTypeTest, MinBufferBindingSizeRuntimeArray) {
ArrayType array(&u32);
ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(std::move(decos));
array.set_decorations(decos);
AccessControlType at{AccessControl::kReadOnly, &array};
EXPECT_EQ(4u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
}
@ -124,16 +124,16 @@ TEST_F(AccessControlTypeTest, MinBufferBindingSizeStruct) {
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &u32, std::move(deco)));
members.push_back(create<StructMember>("foo", &u32, deco));
deco = StructMemberDecorationList();
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, std::move(deco)));
members.push_back(create<StructMember>("bar", &u32, deco));
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
AccessControlType at{AccessControl::kReadOnly, &struct_type};
EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(8u, at.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
@ -150,7 +150,7 @@ TEST_F(AccessControlTypeTest, BaseAlignmentArray) {
ArrayType array(&u32, 4);
ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(std::move(decos));
array.set_decorations(decos);
AccessControlType at{AccessControl::kReadOnly, &array};
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
}
@ -160,7 +160,7 @@ TEST_F(AccessControlTypeTest, BaseAlignmentRuntimeArray) {
ArrayType array(&u32);
ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(std::move(decos));
array.set_decorations(decos);
AccessControlType at{AccessControl::kReadOnly, &array};
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
}
@ -172,17 +172,17 @@ TEST_F(AccessControlTypeTest, BaseAlignmentStruct) {
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &u32, std::move(deco)));
members.push_back(create<StructMember>("foo", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, std::move(deco)));
members.push_back(create<StructMember>("bar", &u32, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
AccessControlType at{AccessControl::kReadOnly, &struct_type};
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, at.BaseAlignment(MemoryLayout::kStorageBuffer));

View File

@ -166,7 +166,7 @@ TEST_F(AliasTypeTest, MinBufferBindingSizeArray) {
ArrayType array(&u32, 4);
ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(std::move(decos));
array.set_decorations(decos);
AliasType alias{"alias", &array};
EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
}
@ -176,7 +176,7 @@ TEST_F(AliasTypeTest, MinBufferBindingSizeRuntimeArray) {
ArrayType array(&u32);
ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(std::move(decos));
array.set_decorations(decos);
AliasType alias{"alias", &array};
EXPECT_EQ(4u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
}
@ -188,17 +188,17 @@ TEST_F(AliasTypeTest, MinBufferBindingSizeStruct) {
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &u32, std::move(deco)));
members.push_back(create<StructMember>("foo", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, std::move(deco)));
members.push_back(create<StructMember>("bar", &u32, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
AliasType alias{"alias", &struct_type};
EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(8u, alias.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
@ -215,7 +215,7 @@ TEST_F(AliasTypeTest, BaseAlignmentArray) {
ArrayType array(&u32, 4);
ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(std::move(decos));
array.set_decorations(decos);
AliasType alias{"alias", &array};
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
}
@ -225,7 +225,7 @@ TEST_F(AliasTypeTest, BaseAlignmentRuntimeArray) {
ArrayType array(&u32);
ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(std::move(decos));
array.set_decorations(decos);
AliasType alias{"alias", &array};
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
}
@ -237,17 +237,17 @@ TEST_F(AliasTypeTest, BaseAlignmentStruct) {
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &u32, std::move(deco)));
members.push_back(create<StructMember>("foo", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, std::move(deco)));
members.push_back(create<StructMember>("bar", &u32, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
AliasType alias{"alias", &struct_type};
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, alias.BaseAlignment(MemoryLayout::kStorageBuffer));

View File

@ -84,7 +84,7 @@ TEST_F(ArrayTypeTest, TypeName_WithStride) {
decos.push_back(create<StrideDecoration>(16, Source{}));
ArrayType arr{&i32, 3};
arr.set_decorations(std::move(decos));
arr.set_decorations(decos);
EXPECT_EQ(arr.type_name(), "__array__i32_3_stride_16");
}
@ -100,7 +100,7 @@ TEST_F(ArrayTypeTest, MinBufferBindingSizeArray) {
decos.push_back(create<StrideDecoration>(4, Source{}));
ArrayType arr(&u32, 4);
arr.set_decorations(std::move(decos));
arr.set_decorations(decos);
EXPECT_EQ(16u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
}
@ -110,7 +110,7 @@ TEST_F(ArrayTypeTest, MinBufferBindingSizeRuntimeArray) {
decos.push_back(create<StrideDecoration>(4, Source{}));
ArrayType arr(&u32);
arr.set_decorations(std::move(decos));
arr.set_decorations(decos);
EXPECT_EQ(4u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
}
@ -120,7 +120,7 @@ TEST_F(ArrayTypeTest, BaseAlignmentArray) {
decos.push_back(create<StrideDecoration>(4, Source{}));
ArrayType arr(&u32, 4);
arr.set_decorations(std::move(decos));
arr.set_decorations(decos);
EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer));
}
@ -131,7 +131,7 @@ TEST_F(ArrayTypeTest, BaseAlignmentRuntimeArray) {
decos.push_back(create<StrideDecoration>(4, Source{}));
ArrayType arr(&u32);
arr.set_decorations(std::move(decos));
arr.set_decorations(decos);
EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer));
}

View File

@ -36,13 +36,13 @@ using StructTypeTest = TestHelper;
TEST_F(StructTypeTest, Creation) {
auto* impl = create<Struct>();
auto* ptr = impl;
StructType s{"S", std::move(impl)};
StructType s{"S", impl};
EXPECT_EQ(s.impl(), ptr);
}
TEST_F(StructTypeTest, Is) {
auto* impl = create<Struct>();
StructType s{"S", std::move(impl)};
StructType s{"S", impl};
EXPECT_FALSE(s.IsAccessControl());
EXPECT_FALSE(s.IsAlias());
EXPECT_FALSE(s.IsArray());
@ -60,7 +60,7 @@ TEST_F(StructTypeTest, Is) {
TEST_F(StructTypeTest, TypeName) {
auto* impl = create<Struct>();
StructType s{"my_struct", std::move(impl)};
StructType s{"my_struct", impl};
EXPECT_EQ(s.type_name(), "__struct_my_struct");
}
@ -71,17 +71,17 @@ TEST_F(StructTypeTest, MinBufferBindingSize) {
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &u32, std::move(deco)));
members.push_back(create<StructMember>("foo", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, std::move(deco)));
members.push_back(create<StructMember>("bar", &u32, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(8u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
@ -93,29 +93,29 @@ TEST_F(StructTypeTest, MinBufferBindingSizeArray) {
{
ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{}));
arr.set_decorations(std::move(decos));
arr.set_decorations(decos);
}
StructMemberList members;
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &u32, std::move(deco)));
members.push_back(create<StructMember>("foo", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, std::move(deco)));
members.push_back(create<StructMember>("bar", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(8, Source{}));
members.push_back(create<StructMember>("bar", &arr, std::move(deco)));
members.push_back(create<StructMember>("bar", &arr, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
EXPECT_EQ(32u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(24u,
@ -128,29 +128,29 @@ TEST_F(StructTypeTest, MinBufferBindingSizeRuntimeArray) {
{
ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{}));
arr.set_decorations(std::move(decos));
arr.set_decorations(decos);
}
StructMemberList members;
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &u32, std::move(deco)));
members.push_back(create<StructMember>("foo", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, std::move(deco)));
members.push_back(create<StructMember>("bar", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(8, Source{}));
members.push_back(create<StructMember>("bar", &u32, std::move(deco)));
members.push_back(create<StructMember>("bar", &u32, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
EXPECT_EQ(12u,
struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
}
@ -163,12 +163,12 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec2) {
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &vec2, std::move(deco)));
members.push_back(create<StructMember>("foo", &vec2, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(8u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
@ -182,12 +182,12 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec3) {
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &vec3, std::move(deco)));
members.push_back(create<StructMember>("foo", &vec3, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(16u,
@ -202,12 +202,12 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec4) {
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &vec4, std::move(deco)));
members.push_back(create<StructMember>("foo", &vec4, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(16u,
@ -221,17 +221,17 @@ TEST_F(StructTypeTest, BaseAlignment) {
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &u32, std::move(deco)));
members.push_back(create<StructMember>("foo", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, std::move(deco)));
members.push_back(create<StructMember>("bar", &u32, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
}
@ -242,29 +242,29 @@ TEST_F(StructTypeTest, BaseAlignmentArray) {
{
ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{}));
arr.set_decorations(std::move(decos));
arr.set_decorations(decos);
}
StructMemberList members;
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &u32, std::move(deco)));
members.push_back(create<StructMember>("foo", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, std::move(deco)));
members.push_back(create<StructMember>("bar", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(8, Source{}));
members.push_back(create<StructMember>("bar", &arr, std::move(deco)));
members.push_back(create<StructMember>("bar", &arr, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
}
@ -275,29 +275,29 @@ TEST_F(StructTypeTest, BaseAlignmentRuntimeArray) {
{
ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{}));
arr.set_decorations(std::move(decos));
arr.set_decorations(decos);
}
StructMemberList members;
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &u32, std::move(deco)));
members.push_back(create<StructMember>("foo", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, std::move(deco)));
members.push_back(create<StructMember>("bar", &u32, deco));
}
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(8, Source{}));
members.push_back(create<StructMember>("bar", &u32, std::move(deco)));
members.push_back(create<StructMember>("bar", &u32, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
}
@ -309,12 +309,12 @@ TEST_F(StructTypeTest, BaseAlignmentVec2) {
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &vec2, std::move(deco)));
members.push_back(create<StructMember>("foo", &vec2, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(8u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
}
@ -327,12 +327,12 @@ TEST_F(StructTypeTest, BaseAlignmentVec3) {
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &vec3, std::move(deco)));
members.push_back(create<StructMember>("foo", &vec3, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
}
@ -345,12 +345,12 @@ TEST_F(StructTypeTest, BaseAlignmentVec4) {
{
StructMemberDecorationList deco;
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &vec4, std::move(deco)));
members.push_back(create<StructMember>("foo", &vec4, deco));
}
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
StructType struct_type("struct_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str);
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
}

View File

@ -33,12 +33,11 @@ TEST_F(TypeConstructorExpressionTest, Creation) {
type::F32Type f32;
ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr"));
auto* expr_ptr = expr[0];
TypeConstructorExpression t(&f32, std::move(expr));
TypeConstructorExpression t(&f32, expr);
EXPECT_EQ(t.type(), &f32);
ASSERT_EQ(t.values().size(), 1u);
EXPECT_EQ(t.values()[0], expr_ptr);
EXPECT_EQ(t.values()[0], expr[0]);
}
TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
@ -46,8 +45,7 @@ TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr"));
TypeConstructorExpression t(Source{Source::Location{20, 2}}, &f32,
std::move(expr));
TypeConstructorExpression t(Source{Source::Location{20, 2}}, &f32, expr);
auto src = t.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -63,7 +61,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid) {
ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr"));
TypeConstructorExpression t(&f32, std::move(expr));
TypeConstructorExpression t(&f32, expr);
EXPECT_TRUE(t.IsValid());
}
@ -71,7 +69,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_EmptyValue) {
type::F32Type f32;
ExpressionList expr;
TypeConstructorExpression t(&f32, std::move(expr));
TypeConstructorExpression t(&f32, expr);
EXPECT_TRUE(t.IsValid());
}
@ -80,7 +78,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullType) {
expr.push_back(create<IdentifierExpression>("expr"));
TypeConstructorExpression t;
t.set_values(std::move(expr));
t.set_values(expr);
EXPECT_FALSE(t.IsValid());
}
@ -90,7 +88,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) {
expr.push_back(create<IdentifierExpression>("expr"));
expr.push_back(nullptr);
TypeConstructorExpression t(&f32, std::move(expr));
TypeConstructorExpression t(&f32, expr);
EXPECT_FALSE(t.IsValid());
}
@ -99,7 +97,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) {
ExpressionList expr;
expr.push_back(create<IdentifierExpression>(""));
TypeConstructorExpression t(&f32, std::move(expr));
TypeConstructorExpression t(&f32, expr);
EXPECT_FALSE(t.IsValid());
}
@ -111,7 +109,7 @@ TEST_F(TypeConstructorExpressionTest, ToStr) {
expr.push_back(create<IdentifierExpression>("expr_2"));
expr.push_back(create<IdentifierExpression>("expr_3"));
TypeConstructorExpression t(&vec, std::move(expr));
TypeConstructorExpression t(&vec, expr);
std::ostringstream out;
t.to_str(out, 2);
EXPECT_EQ(out.str(), R"( TypeConstructor[not set]{

View File

@ -27,17 +27,15 @@ using UnaryOpExpressionTest = TestHelper;
TEST_F(UnaryOpExpressionTest, Creation) {
auto* ident = create<IdentifierExpression>("ident");
auto* ident_ptr = ident;
UnaryOpExpression u(UnaryOp::kNot, std::move(ident));
UnaryOpExpression u(UnaryOp::kNot, ident);
EXPECT_EQ(u.op(), UnaryOp::kNot);
EXPECT_EQ(u.expr(), ident_ptr);
EXPECT_EQ(u.expr(), ident);
}
TEST_F(UnaryOpExpressionTest, Creation_WithSource) {
auto* ident = create<IdentifierExpression>("ident");
UnaryOpExpression u(Source{Source::Location{20, 2}}, UnaryOp::kNot,
std::move(ident));
UnaryOpExpression u(Source{Source::Location{20, 2}}, UnaryOp::kNot, ident);
auto src = u.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -50,7 +48,7 @@ TEST_F(UnaryOpExpressionTest, IsUnaryOp) {
TEST_F(UnaryOpExpressionTest, IsValid) {
auto* ident = create<IdentifierExpression>("ident");
UnaryOpExpression u(UnaryOp::kNot, std::move(ident));
UnaryOpExpression u(UnaryOp::kNot, ident);
EXPECT_TRUE(u.IsValid());
}
@ -62,13 +60,13 @@ TEST_F(UnaryOpExpressionTest, IsValid_NullExpression) {
TEST_F(UnaryOpExpressionTest, IsValid_InvalidExpression) {
auto* ident = create<IdentifierExpression>("");
UnaryOpExpression u(UnaryOp::kNot, std::move(ident));
UnaryOpExpression u(UnaryOp::kNot, ident);
EXPECT_FALSE(u.IsValid());
}
TEST_F(UnaryOpExpressionTest, ToStr) {
auto* ident = create<IdentifierExpression>("ident");
UnaryOpExpression u(UnaryOp::kNot, std::move(ident));
UnaryOpExpression u(UnaryOp::kNot, ident);
std::ostringstream out;
u.to_str(out, 2);
EXPECT_EQ(out.str(), R"( UnaryOp[not set]{

View File

@ -27,17 +27,16 @@ using VariableDeclStatementTest = TestHelper;
TEST_F(VariableDeclStatementTest, Creation) {
type::F32Type f32;
auto* var = create<Variable>("a", StorageClass::kNone, &f32);
auto* var_ptr = var;
VariableDeclStatement stmt(std::move(var));
EXPECT_EQ(stmt.variable(), var_ptr);
VariableDeclStatement stmt(var);
EXPECT_EQ(stmt.variable(), var);
}
TEST_F(VariableDeclStatementTest, Creation_WithSource) {
type::F32Type f32;
auto* var = create<Variable>("a", StorageClass::kNone, &f32);
VariableDeclStatement stmt(Source{Source::Location{20, 2}}, std::move(var));
VariableDeclStatement stmt(Source{Source::Location{20, 2}}, var);
auto src = stmt.source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@ -51,14 +50,14 @@ TEST_F(VariableDeclStatementTest, IsVariableDecl) {
TEST_F(VariableDeclStatementTest, IsValid) {
type::F32Type f32;
auto* var = create<Variable>("a", StorageClass::kNone, &f32);
VariableDeclStatement stmt(std::move(var));
VariableDeclStatement stmt(var);
EXPECT_TRUE(stmt.IsValid());
}
TEST_F(VariableDeclStatementTest, IsValid_InvalidVariable) {
type::F32Type f32;
auto* var = create<Variable>("", StorageClass::kNone, &f32);
VariableDeclStatement stmt(std::move(var));
VariableDeclStatement stmt(var);
EXPECT_FALSE(stmt.IsValid());
}
@ -71,7 +70,7 @@ TEST_F(VariableDeclStatementTest, ToStr) {
type::F32Type f32;
auto* var = create<Variable>("a", StorageClass::kNone, &f32);
VariableDeclStatement stmt(Source{Source::Location{20, 2}}, std::move(var));
VariableDeclStatement stmt(Source{Source::Location{20, 2}}, var);
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( VariableDeclStatement{

View File

@ -199,7 +199,7 @@ std::vector<ResourceBinding> Inspector::GetUniformBufferResourceBindings(
entry.min_buffer_binding_size = var->type()->MinBufferBindingSize(
ast::type::MemoryLayout::kUniformBuffer);
result.push_back(std::move(entry));
result.push_back(entry);
}
return result;
@ -234,7 +234,7 @@ std::vector<ResourceBinding> Inspector::GetSamplerResourceBindings(
entry.bind_group = binding_info.set->value();
entry.binding = binding_info.binding->value();
result.push_back(std::move(entry));
result.push_back(entry);
}
return result;
@ -258,7 +258,7 @@ std::vector<ResourceBinding> Inspector::GetComparisonSamplerResourceBindings(
entry.bind_group = binding_info.set->value();
entry.binding = binding_info.binding->value();
result.push_back(std::move(entry));
result.push_back(entry);
}
return result;
@ -321,7 +321,7 @@ std::vector<ResourceBinding> Inspector::GetStorageBufferResourceBindingsImpl(
entry.min_buffer_binding_size = var->type()->MinBufferBindingSize(
ast::type::MemoryLayout::kStorageBuffer);
result.push_back(std::move(entry));
result.push_back(entry);
}
return result;
@ -401,7 +401,7 @@ std::vector<ResourceBinding> Inspector::GetSampledTextureResourceBindingsImpl(
entry.sampled_kind = ResourceBinding::SampledKind::kUnknown;
}
result.push_back(std::move(entry));
result.push_back(entry);
}
return result;

View File

@ -81,8 +81,7 @@ class InspectorHelper {
ast::Function* MakeEmptyBodyFunction(std::string name) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
return create<ast::Function>(name, ast::VariableList(), void_type(),
std::move(body));
return create<ast::Function>(name, ast::VariableList(), void_type(), body);
}
/// Generates a function that calls another
@ -93,12 +92,12 @@ class InspectorHelper {
std::string callee) {
auto* body = create<ast::BlockStatement>();
auto* ident_expr = create<ast::IdentifierExpression>(callee);
auto* call_expr = create<ast::CallExpression>(std::move(ident_expr),
ast::ExpressionList());
body->append(create<ast::CallStatement>(std::move(call_expr)));
auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
body->append(create<ast::ReturnStatement>());
return create<ast::Function>(caller, ast::VariableList(), void_type(),
std::move(body));
body);
}
/// Add In/Out variables to the global variables
@ -113,8 +112,8 @@ class InspectorHelper {
create<ast::Variable>(in, ast::StorageClass::kInput, u32_type());
auto* out_var =
create<ast::Variable>(out, ast::StorageClass::kOutput, u32_type());
mod()->AddGlobalVariable(std::move(in_var));
mod()->AddGlobalVariable(std::move(out_var));
mod()->AddGlobalVariable(in_var);
mod()->AddGlobalVariable(out_var);
}
}
@ -135,8 +134,7 @@ class InspectorHelper {
create<ast::IdentifierExpression>(in)));
}
body->append(create<ast::ReturnStatement>());
return create<ast::Function>(name, ast::VariableList(), void_type(),
std::move(body));
return create<ast::Function>(name, ast::VariableList(), void_type(), body);
}
/// Generates a function that references in/out variables and calls another
@ -159,12 +157,12 @@ class InspectorHelper {
create<ast::IdentifierExpression>(in)));
}
auto* ident_expr = create<ast::IdentifierExpression>(callee);
auto* call_expr = create<ast::CallExpression>(std::move(ident_expr),
ast::ExpressionList());
body->append(create<ast::CallStatement>(std::move(call_expr)));
auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
body->append(create<ast::ReturnStatement>());
return create<ast::Function>(caller, ast::VariableList(), void_type(),
std::move(body));
body);
}
/// Add a Constant ID to the global variables.
@ -183,12 +181,12 @@ class InspectorHelper {
dvar->set_is_const(true);
ast::VariableDecorationList decos;
decos.push_back(create<ast::ConstantIdDecoration>(id, Source{}));
dvar->set_decorations(std::move(decos));
dvar->set_decorations(decos);
if (val) {
dvar->set_constructor(
create<ast::ScalarConstructorExpression>(MakeLiteral(type, val)));
}
mod()->AddGlobalVariable(std::move(dvar));
mod()->AddGlobalVariable(dvar);
}
/// @param type AST type of the literal, must resolve to BoolLiteral
@ -261,7 +259,7 @@ class InspectorHelper {
create<ast::StructMemberOffsetDecoration>(offset, Source{}));
members.push_back(create<ast::StructMember>(
StructMemberName(members.size(), type), type, std::move(deco)));
StructMemberName(members.size(), type), type, deco));
}
ast::StructDecorationList decos;
@ -269,9 +267,9 @@ class InspectorHelper {
decos.push_back(create<ast::StructBlockDecoration>(Source{}));
}
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
auto* str = create<ast::Struct>(decos, members);
return std::make_unique<ast::type::StructType>(name, std::move(str));
return std::make_unique<ast::type::StructType>(name, str);
}
/// Generates types appropriate for using in an uniform buffer
@ -345,9 +343,9 @@ class InspectorHelper {
decorations.push_back(create<ast::BindingDecoration>(binding, Source{}));
decorations.push_back(create<ast::SetDecoration>(set, Source{}));
var->set_decorations(std::move(decorations));
var->set_decorations(decorations);
mod()->AddGlobalVariable(std::move(var));
mod()->AddGlobalVariable(var);
}
/// Adds an uniform buffer variable to the module
@ -408,7 +406,7 @@ class InspectorHelper {
body->append(create<ast::ReturnStatement>());
return create<ast::Function>(func_name, ast::VariableList(), void_type(),
std::move(body));
body);
}
/// Adds a regular sampler variable to the module
@ -514,23 +512,21 @@ class InspectorHelper {
auto* call_result = create<ast::Variable>(
"sampler_result", ast::StorageClass::kFunction, vec_type(base_type, 4));
body->append(create<ast::VariableDeclStatement>(std::move(call_result)));
body->append(create<ast::VariableDeclStatement>(call_result));
ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>(texture_name));
call_params.push_back(create<ast::IdentifierExpression>(sampler_name));
call_params.push_back(create<ast::IdentifierExpression>(coords_name));
auto* call_expr = create<ast::CallExpression>(
create<ast::IdentifierExpression>("textureSample"),
std::move(call_params));
create<ast::IdentifierExpression>("textureSample"), call_params);
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("sampler_result"),
std::move(call_expr)));
create<ast::IdentifierExpression>("sampler_result"), call_expr));
body->append(create<ast::ReturnStatement>());
return create<ast::Function>(func_name, ast::VariableList(), void_type(),
std::move(body));
body);
}
/// Generates a function that references a specific comparison sampler
@ -554,7 +550,7 @@ class InspectorHelper {
auto* call_result = create<ast::Variable>(
"sampler_result", ast::StorageClass::kFunction, base_type);
body->append(create<ast::VariableDeclStatement>(std::move(call_result)));
body->append(create<ast::VariableDeclStatement>(call_result));
ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>(texture_name));
@ -562,16 +558,14 @@ class InspectorHelper {
call_params.push_back(create<ast::IdentifierExpression>(coords_name));
call_params.push_back(create<ast::IdentifierExpression>(depth_name));
auto* call_expr = create<ast::CallExpression>(
create<ast::IdentifierExpression>("textureSampleCompare"),
std::move(call_params));
create<ast::IdentifierExpression>("textureSampleCompare"), call_params);
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("sampler_result"),
std::move(call_expr)));
create<ast::IdentifierExpression>("sampler_result"), call_expr));
body->append(create<ast::ReturnStatement>());
return create<ast::Function>(func_name, ast::VariableList(), void_type(),
std::move(body));
body);
}
/// Gets an appropriate type for the data in a given texture type.
@ -623,7 +617,7 @@ class InspectorHelper {
std::make_unique<ast::type::ArrayType>(u32_type(), count);
ast::ArrayDecorationList decos;
decos.push_back(create<ast::StrideDecoration>(4, Source{}));
array_type_memo_[count]->set_decorations(std::move(decos));
array_type_memo_[count]->set_decorations(decos);
}
return array_type_memo_[count].get();
}
@ -726,7 +720,7 @@ TEST_F(InspectorGetEntryPointTest, OneEntryPoint) {
auto* foo = MakeEmptyBodyFunction("foo");
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -741,12 +735,12 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) {
auto* foo = MakeEmptyBodyFunction("foo");
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
auto* bar = MakeEmptyBodyFunction("bar");
bar->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
mod()->AddFunction(std::move(bar));
mod()->AddFunction(bar);
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -762,17 +756,17 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) {
TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) {
auto* func = MakeEmptyBodyFunction("func");
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
auto* foo = MakeCallerBodyFunction("foo", "func");
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
auto* bar = MakeCallerBodyFunction("bar", "func");
bar->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod()->AddFunction(std::move(bar));
mod()->AddFunction(bar);
auto result = inspector()->GetEntryPoints();
EXPECT_FALSE(inspector()->has_error());
@ -790,7 +784,7 @@ TEST_F(InspectorGetEntryPointTest, DefaultWorkgroupSize) {
auto* foo = MakeCallerBodyFunction("foo", "func");
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -808,7 +802,7 @@ TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) {
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
foo->add_decoration(create<ast::WorkgroupDecoration>(8u, 2u, 1u, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -823,12 +817,12 @@ TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) {
TEST_F(InspectorGetEntryPointTest, NoInOutVariables) {
auto* func = MakeEmptyBodyFunction("func");
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
auto* foo = MakeCallerBodyFunction("foo", "func");
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -844,7 +838,7 @@ TEST_F(InspectorGetEntryPointTest, EntryPointInOutVariables) {
auto* foo = MakeInOutVariableBodyFunction("foo", {{"in_var", "out_var"}});
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -863,12 +857,12 @@ TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) {
AddInOutVariables({{"in_var", "out_var"}});
auto* func = MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}});
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
auto* foo = MakeCallerBodyFunction("foo", "func");
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -887,13 +881,13 @@ TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) {
AddInOutVariables({{"in_var", "out_var"}});
auto* func = MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}});
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
auto* foo = MakeInOutVariableCallerBodyFunction("foo", "func",
{{"in_var", "out_var"}});
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -915,7 +909,7 @@ TEST_F(InspectorGetEntryPointTest, EntryPointMultipleInOutVariables) {
"foo", {{"in_var", "out_var"}, {"in2_var", "out2_var"}});
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -937,12 +931,12 @@ TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) {
auto* func = MakeInOutVariableBodyFunction(
"func", {{"in_var", "out_var"}, {"in2_var", "out2_var"}});
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
auto* foo = MakeCallerBodyFunction("foo", "func");
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -965,12 +959,12 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {
auto* foo = MakeInOutVariableBodyFunction("foo", {{"in_var", "out2_var"}});
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
auto* bar = MakeInOutVariableBodyFunction("bar", {{"in2_var", "out_var"}});
bar->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
mod()->AddFunction(std::move(bar));
mod()->AddFunction(bar);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -998,18 +992,18 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
AddInOutVariables({{"in_var", "out_var"}, {"in2_var", "out2_var"}});
auto* func = MakeInOutVariableBodyFunction("func", {{"in2_var", "out2_var"}});
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
auto* foo = MakeInOutVariableCallerBodyFunction("foo", "func",
{{"in_var", "out_var"}});
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
auto* bar = MakeCallerBodyFunction("bar", "func");
bar->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
mod()->AddFunction(std::move(bar));
mod()->AddFunction(bar);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1061,7 +1055,7 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) {
auto* foo = MakeEmptyBodyFunction("foo");
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
auto result = inspector()->GetRemappedNameForEntryPoint("foo");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -1076,12 +1070,12 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest,
auto* foo = MakeEmptyBodyFunction("foo");
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
auto* bar = MakeEmptyBodyFunction("bar");
bar->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
mod()->AddFunction(std::move(bar));
mod()->AddFunction(bar);
{
auto result = inspector()->GetRemappedNameForEntryPoint("foo");
@ -1199,12 +1193,12 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) {
auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub",
{{0, i32_type()}});
mod()->AddFunction(std::move(ub_func));
mod()->AddFunction(ub_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "ub_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1218,26 +1212,24 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) {
ast::StructMemberDecorationList deco;
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(
create<ast::StructMember>(StructMemberName(members.size(), i32_type()),
i32_type(), std::move(deco)));
members.push_back(create<ast::StructMember>(
StructMemberName(members.size(), i32_type()), i32_type(), deco));
ast::StructDecorationList decos;
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
auto foo_type =
std::make_unique<ast::type::StructType>("foo_type", std::move(str));
auto* str = create<ast::Struct>(decos, members);
auto foo_type = std::make_unique<ast::type::StructType>("foo_type", str);
AddUniformBuffer("foo_ub", foo_type.get(), 0, 0);
auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub",
{{0, i32_type()}});
mod()->AddFunction(std::move(ub_func));
mod()->AddFunction(ub_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "ub_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1255,12 +1247,12 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) {
auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub",
{{0, i32_type()}});
mod()->AddFunction(std::move(ub_func));
mod()->AddFunction(ub_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "ub_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1282,12 +1274,12 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) {
auto* ub_func = MakeStructVariableReferenceBodyFunction(
"ub_func", "foo_ub", {{0, i32_type()}, {1, u32_type()}, {2, f32_type()}});
mod()->AddFunction(std::move(ub_func));
mod()->AddFunction(ub_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "ub_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1314,7 +1306,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
auto* ub_func = MakeStructVariableReferenceBodyFunction(
func_name, var_name,
{{0, i32_type()}, {1, u32_type()}, {2, f32_type()}});
mod()->AddFunction(std::move(ub_func));
mod()->AddFunction(ub_func);
};
AddReferenceFunc("ub_foo_func", "ub_foo");
AddReferenceFunc("ub_bar_func", "ub_bar");
@ -1322,9 +1314,9 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) {
auto* ident_expr = create<ast::IdentifierExpression>(callee);
auto* call_expr = create<ast::CallExpression>(std::move(ident_expr),
ast::ExpressionList());
body->append(create<ast::CallStatement>(std::move(call_expr)));
auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
};
auto* body = create<ast::BlockStatement>();
@ -1333,12 +1325,12 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
AddFuncCall(body, "ub_baz_func");
body->append(create<ast::ReturnStatement>());
ast::Function* func = create<ast::Function>("ep_func", ast::VariableList(),
void_type(), std::move(body));
ast::Function* func =
create<ast::Function>("ep_func", ast::VariableList(), void_type(), body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1368,12 +1360,12 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) {
auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub",
{{0, i32_type()}});
mod()->AddFunction(std::move(ub_func));
mod()->AddFunction(ub_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "ub_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1395,12 +1387,12 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, i32_type()}});
mod()->AddFunction(std::move(sb_func));
mod()->AddFunction(sb_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "sb_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1422,12 +1414,12 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) {
auto* sb_func = MakeStructVariableReferenceBodyFunction(
"sb_func", "foo_sb", {{0, i32_type()}, {1, u32_type()}, {2, f32_type()}});
mod()->AddFunction(std::move(sb_func));
mod()->AddFunction(sb_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "sb_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1454,7 +1446,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
auto* sb_func = MakeStructVariableReferenceBodyFunction(
func_name, var_name,
{{0, i32_type()}, {1, u32_type()}, {2, f32_type()}});
mod()->AddFunction(std::move(sb_func));
mod()->AddFunction(sb_func);
};
AddReferenceFunc("sb_foo_func", "sb_foo");
AddReferenceFunc("sb_bar_func", "sb_bar");
@ -1462,9 +1454,9 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) {
auto* ident_expr = create<ast::IdentifierExpression>(callee);
auto* call_expr = create<ast::CallExpression>(std::move(ident_expr),
ast::ExpressionList());
body->append(create<ast::CallStatement>(std::move(call_expr)));
auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
};
auto* body = create<ast::BlockStatement>();
@ -1473,12 +1465,12 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
AddFuncCall(body, "sb_baz_func");
body->append(create<ast::ReturnStatement>());
ast::Function* func = create<ast::Function>("ep_func", ast::VariableList(),
void_type(), std::move(body));
ast::Function* func =
create<ast::Function>("ep_func", ast::VariableList(), void_type(), body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1508,12 +1500,12 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, i32_type()}});
mod()->AddFunction(std::move(sb_func));
mod()->AddFunction(sb_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "sb_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1535,12 +1527,12 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, i32_type()}});
mod()->AddFunction(std::move(sb_func));
mod()->AddFunction(sb_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "sb_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1562,12 +1554,12 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, i32_type()}});
mod()->AddFunction(std::move(sb_func));
mod()->AddFunction(sb_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "sb_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1585,12 +1577,12 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, i32_type()}});
mod()->AddFunction(std::move(sb_func));
mod()->AddFunction(sb_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "sb_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1619,7 +1611,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
auto* sb_func = MakeStructVariableReferenceBodyFunction(
func_name, var_name,
{{0, i32_type()}, {1, u32_type()}, {2, f32_type()}});
mod()->AddFunction(std::move(sb_func));
mod()->AddFunction(sb_func);
};
AddReferenceFunc("sb_foo_func", "sb_foo");
AddReferenceFunc("sb_bar_func", "sb_bar");
@ -1627,9 +1619,9 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) {
auto* ident_expr = create<ast::IdentifierExpression>(callee);
auto* call_expr = create<ast::CallExpression>(std::move(ident_expr),
ast::ExpressionList());
body->append(create<ast::CallStatement>(std::move(call_expr)));
auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
};
auto* body = create<ast::BlockStatement>();
@ -1638,12 +1630,12 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
AddFuncCall(body, "sb_baz_func");
body->append(create<ast::ReturnStatement>());
ast::Function* func = create<ast::Function>("ep_func", ast::VariableList(),
void_type(), std::move(body));
ast::Function* func =
create<ast::Function>("ep_func", ast::VariableList(), void_type(), body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1674,12 +1666,12 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, i32_type()}});
mod()->AddFunction(std::move(sb_func));
mod()->AddFunction(sb_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "sb_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1703,12 +1695,12 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, i32_type()}});
mod()->AddFunction(std::move(sb_func));
mod()->AddFunction(sb_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "sb_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1731,12 +1723,12 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, i32_type()}});
mod()->AddFunction(std::move(sb_func));
mod()->AddFunction(sb_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "sb_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1757,7 +1749,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) {
"ep", "foo_texture", "foo_sampler", "foo_coords", f32_type());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1773,7 +1765,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, NoSampler) {
auto* func = MakeEmptyBodyFunction("ep_func");
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1792,12 +1784,12 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) {
auto* foo_func = MakeSamplerReferenceBodyFunction(
"foo_func", "foo_texture", "foo_sampler", "foo_coords", f32_type());
mod()->AddFunction(std::move(foo_func));
mod()->AddFunction(foo_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "foo_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1820,7 +1812,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) {
"ep", "foo_texture", "foo_sampler", "foo_coords", f32_type());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1841,7 +1833,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) {
f32_type());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1864,7 +1856,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) {
f32_type());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1880,7 +1872,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, NoSampler) {
auto* func = MakeEmptyBodyFunction("ep_func");
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1901,12 +1893,12 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) {
auto* foo_func = MakeComparisonSamplerReferenceBodyFunction(
"foo_func", "foo_texture", "foo_sampler", "foo_coords", "foo_depth",
f32_type());
mod()->AddFunction(std::move(foo_func));
mod()->AddFunction(foo_func);
auto* ep_func = MakeCallerBodyFunction("ep_func", "foo_func");
ep_func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(ep_func));
mod()->AddFunction(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1931,7 +1923,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) {
f32_type());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1950,7 +1942,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) {
"ep", "foo_texture", "foo_sampler", "foo_coords", f32_type());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1964,7 +1956,7 @@ TEST_F(InspectorGetSampledTextureResourceBindingsTest, Empty) {
auto* foo = MakeEmptyBodyFunction("foo");
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
auto result = inspector()->GetSampledTextureResourceBindings("foo");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -1986,7 +1978,7 @@ TEST_P(InspectorGetSampledTextureResourceBindingsTestWithParam, textureSample) {
GetBaseType(GetParam().sampled_kind));
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -2093,7 +2085,7 @@ TEST_F(InspectorGetMultisampledTextureResourceBindingsTest, Empty) {
auto* foo = MakeEmptyBodyFunction("foo");
foo->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
mod()->AddFunction(foo);
auto result = inspector()->GetSampledTextureResourceBindings("foo");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -2116,7 +2108,7 @@ TEST_P(InspectorGetMultisampledTextureResourceBindingsTestWithParam,
GetBaseType(GetParam().sampled_kind));
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
ASSERT_TRUE(td()->Determine()) << td()->error();

View File

@ -517,11 +517,10 @@ void FunctionEmitter::PushGuard(const std::string& guard_name,
auto* cond = create<ast::IdentifierExpression>(guard_name);
auto* body = create<ast::BlockStatement>();
auto* const guard_stmt =
AddStatement(create<ast::IfStatement>(std::move(cond), std::move(body)))
->AsIf();
AddStatement(create<ast::IfStatement>(cond, body))->AsIf();
PushNewStatementBlock(top.construct_, end_id,
[guard_stmt](StatementBlock* s) {
guard_stmt->set_body(std::move(s->statements_));
guard_stmt->set_body(s->statements_);
});
}
@ -531,12 +530,11 @@ void FunctionEmitter::PushTrueGuard(uint32_t end_id) {
auto* cond = MakeTrue();
auto* body = create<ast::BlockStatement>();
auto* const guard_stmt =
AddStatement(create<ast::IfStatement>(std::move(cond), std::move(body)))
->AsIf();
AddStatement(create<ast::IfStatement>(cond, body))->AsIf();
guard_stmt->set_condition(MakeTrue());
PushNewStatementBlock(top.construct_, end_id,
[guard_stmt](StatementBlock* s) {
guard_stmt->set_body(std::move(s->statements_));
guard_stmt->set_body(s->statements_);
});
}
@ -549,7 +547,7 @@ ast::Statement* FunctionEmitter::AddStatement(ast::Statement* statement) {
assert(!statements_stack_.empty());
auto* result = statement;
if (result != nullptr) {
statements_stack_.back().statements_->append(std::move(statement));
statements_stack_.back().statements_->append(statement);
}
return result;
}
@ -557,7 +555,7 @@ ast::Statement* FunctionEmitter::AddStatement(ast::Statement* statement) {
ast::Statement* FunctionEmitter::AddStatementForInstruction(
ast::Statement* statement,
const spvtools::opt::Instruction& inst) {
auto* node = AddStatement(std::move(statement));
auto* node = AddStatement(statement);
ApplySourceForInstruction(node, inst);
return node;
}
@ -592,8 +590,8 @@ bool FunctionEmitter::Emit() {
"element but has "
<< statements_stack_.size();
}
auto* body = std::move(statements_stack_[0].statements_);
parser_impl_.get_module().functions().back()->set_body(std::move(body));
auto* body = statements_stack_[0].statements_;
parser_impl_.get_module().functions().back()->set_body(body);
// Maintain the invariant by repopulating the one and only element.
statements_stack_.clear();
PushNewStatementBlock(constructs_[0].get(), 0, nullptr);
@ -635,7 +633,7 @@ bool FunctionEmitter::EmitFunctionDeclaration() {
param->result_id(), ast::StorageClass::kNone, ast_type);
// Parameters are treated as const declarations.
ast_param->set_is_const(true);
ast_params.emplace_back(std::move(ast_param));
ast_params.emplace_back(ast_param);
// The value is accessible by name.
identifier_values_.insert(param->result_id());
} else {
@ -655,7 +653,7 @@ bool FunctionEmitter::EmitFunctionDeclaration() {
create<ast::StageDecoration>(ep_info_->stage, Source{}));
}
ast_module_.AddFunction(std::move(ast_fn));
ast_module_.AddFunction(ast_fn);
return success();
}
@ -1704,8 +1702,8 @@ bool FunctionEmitter::EmitFunctionVariables() {
parser_impl_.MakeConstantExpression(inst.GetSingleWordInOperand(1))
.expr);
}
auto* var_decl_stmt = create<ast::VariableDeclStatement>(std::move(var));
AddStatementForInstruction(std::move(var_decl_stmt), inst);
auto* var_decl_stmt = create<ast::VariableDeclStatement>(var);
AddStatementForInstruction(var_decl_stmt, inst);
// Save this as an already-named value.
identifier_values_.insert(inst.result_id());
}
@ -1972,8 +1970,8 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
auto* guard_var = create<ast::Variable>(
guard_name, ast::StorageClass::kFunction, parser_impl_.BoolType());
guard_var->set_constructor(MakeTrue());
auto* guard_decl = create<ast::VariableDeclStatement>(std::move(guard_var));
AddStatement(std::move(guard_decl));
auto* guard_decl = create<ast::VariableDeclStatement>(guard_var);
AddStatement(guard_decl);
}
const auto condition_id =
@ -1981,8 +1979,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
auto* cond = MakeExpression(condition_id).expr;
auto* body = create<ast::BlockStatement>();
auto* const if_stmt =
AddStatement(create<ast::IfStatement>(std::move(cond), std::move(body)))
->AsIf();
AddStatement(create<ast::IfStatement>(cond, body))->AsIf();
// Generate the code for the condition.
@ -2029,7 +2026,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
// The "then" consists of the statement list
// from the top of statments stack, without an
// elseif condition.
if_stmt->set_body(std::move(s->statements_));
if_stmt->set_body(s->statements_);
});
};
@ -2043,8 +2040,8 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
// statments stack, without an elseif condition.
ast::ElseStatementList else_stmts;
else_stmts.emplace_back(
create<ast::ElseStatement>(nullptr, std::move(s->statements_)));
if_stmt->set_else_statements(std::move(else_stmts));
create<ast::ElseStatement>(nullptr, s->statements_));
if_stmt->set_else_statements(else_stmts);
}
});
};
@ -2099,7 +2096,7 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
const auto selector_id = branch->GetSingleWordInOperand(0);
// Generate the code for the selector.
auto selector = MakeExpression(selector_id);
switch_stmt->set_condition(std::move(selector.expr));
switch_stmt->set_condition(selector.expr);
// First, push the statement block for the entire switch. All the actual
// work is done by completion actions of the case/default clauses.
@ -2177,7 +2174,7 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
create<ast::SintLiteral>(selector.type, value32));
}
}
clause->set_selectors(std::move(selectors));
clause->set_selectors(selectors);
}
// Where does this clause end?
@ -2185,7 +2182,7 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
: construct->end_id;
PushNewStatementBlock(construct, end_id, [clause](StatementBlock* s) {
clause->set_body(std::move(s->statements_));
clause->set_body(s->statements_);
});
if ((default_info == clause_heads[i]) && has_selectors &&
@ -2193,8 +2190,8 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
// Generate a default clause with a just fallthrough.
auto* stmts = create<ast::BlockStatement>();
stmts->append(create<ast::FallthroughStatement>());
auto* case_stmt = create<ast::CaseStatement>(std::move(stmts));
cases->emplace_back(std::move(case_stmt));
auto* case_stmt = create<ast::CaseStatement>(stmts);
cases->emplace_back(case_stmt);
}
if (i == 0) {
@ -2216,7 +2213,7 @@ bool FunctionEmitter::EmitLoopStart(const Construct* construct) {
->AsLoop();
PushNewStatementBlock(
construct, construct->end_id,
[loop](StatementBlock* s) { loop->set_body(std::move(s->statements_)); });
[loop](StatementBlock* s) { loop->set_body(s->statements_); });
return success();
}
@ -2229,10 +2226,9 @@ bool FunctionEmitter::EmitContinuingStart(const Construct* construct) {
"expected loop on top of stack";
}
auto* loop = loop_candidate->AsLoop();
PushNewStatementBlock(construct, construct->end_id,
[loop](StatementBlock* s) {
loop->set_continuing(std::move(s->statements_));
});
PushNewStatementBlock(
construct, construct->end_id,
[loop](StatementBlock* s) { loop->set_continuing(s->statements_); });
return success();
}
@ -2244,7 +2240,7 @@ bool FunctionEmitter::EmitNormalTerminator(const BlockInfo& block_info) {
return true;
case SpvOpReturnValue: {
auto value = MakeExpression(terminator.GetSingleWordInOperand(0));
AddStatement(create<ast::ReturnStatement>(std::move(value.expr)));
AddStatement(create<ast::ReturnStatement>(value.expr));
}
return true;
case SpvOpKill:
@ -2296,11 +2292,11 @@ bool FunctionEmitter::EmitNormalTerminator(const BlockInfo& block_info) {
// The fallthrough case is special because WGSL requires the fallthrough
// statement to be last in the case clause.
if (true_kind == EdgeKind::kCaseFallThrough) {
return EmitConditionalCaseFallThrough(block_info, std::move(cond),
false_kind, *false_info, true);
return EmitConditionalCaseFallThrough(block_info, cond, false_kind,
*false_info, true);
} else if (false_kind == EdgeKind::kCaseFallThrough) {
return EmitConditionalCaseFallThrough(block_info, std::move(cond),
true_kind, *true_info, false);
return EmitConditionalCaseFallThrough(block_info, cond, true_kind,
*true_info, false);
}
// At this point, at most one edge is kForward or kIfBreak.
@ -2317,8 +2313,7 @@ bool FunctionEmitter::EmitNormalTerminator(const BlockInfo& block_info) {
auto* false_branch =
MakeBranchDetailed(block_info, *false_info, false, &flow_guard);
AddStatement(MakeSimpleIf(std::move(cond), std::move(true_branch),
std::move(false_branch)));
AddStatement(MakeSimpleIf(cond, true_branch, false_branch));
if (!flow_guard.empty()) {
PushGuard(flow_guard, statements_stack_.back().end_id_);
}
@ -2413,20 +2408,19 @@ ast::Statement* FunctionEmitter::MakeSimpleIf(ast::Expression* condition,
if ((then_stmt == nullptr) && (else_stmt == nullptr)) {
return nullptr;
}
auto* if_stmt = create<ast::IfStatement>(std::move(condition),
create<ast::BlockStatement>());
auto* if_stmt =
create<ast::IfStatement>(condition, create<ast::BlockStatement>());
if (then_stmt != nullptr) {
auto* stmts = create<ast::BlockStatement>();
stmts->append(std::move(then_stmt));
if_stmt->set_body(std::move(stmts));
stmts->append(then_stmt);
if_stmt->set_body(stmts);
}
if (else_stmt != nullptr) {
auto* stmts = create<ast::BlockStatement>();
stmts->append(std::move(else_stmt));
stmts->append(else_stmt);
ast::ElseStatementList else_stmts;
else_stmts.emplace_back(
create<ast::ElseStatement>(nullptr, std::move(stmts)));
if_stmt->set_else_statements(std::move(else_stmts));
else_stmts.emplace_back(create<ast::ElseStatement>(nullptr, stmts));
if_stmt->set_else_statements(else_stmts);
}
return if_stmt;
}
@ -2466,11 +2460,9 @@ bool FunctionEmitter::EmitConditionalCaseFallThrough(
<< int(other_edge_kind);
}
if (fall_through_is_true_branch) {
AddStatement(
MakeSimpleIf(std::move(cond), nullptr, std::move(other_branch)));
AddStatement(MakeSimpleIf(cond, nullptr, other_branch));
} else {
AddStatement(
MakeSimpleIf(std::move(cond), std::move(other_branch), nullptr));
AddStatement(MakeSimpleIf(cond, other_branch, nullptr));
}
AddStatement(create<ast::FallthroughStatement>());
@ -2513,7 +2505,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
auto* var =
create<ast::Variable>(phi_var_name, ast::StorageClass::kFunction,
parser_impl_.ConvertType(def_inst->type_id()));
AddStatement(create<ast::VariableDeclStatement>(std::move(var)));
AddStatement(create<ast::VariableDeclStatement>(var));
}
// Emit regular statements.
@ -2544,7 +2536,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
const auto var_name = GetDefInfo(assignment.phi_id)->phi_var;
auto expr = MakeExpression(assignment.value);
AddStatement(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(var_name), std::move(expr.expr)));
create<ast::IdentifierExpression>(var_name), expr.expr));
}
}
@ -2563,10 +2555,10 @@ bool FunctionEmitter::EmitConstDefinition(
if (!ast_const) {
return false;
}
ast_const->set_constructor(std::move(ast_expr.expr));
ast_const->set_constructor(ast_expr.expr);
ast_const->set_is_const(true);
AddStatementForInstruction(
create<ast::VariableDeclStatement>(std::move(ast_const)), inst);
AddStatementForInstruction(create<ast::VariableDeclStatement>(ast_const),
inst);
// Save this as an already-named value.
identifier_values_.insert(inst.result_id());
return success();
@ -2582,11 +2574,11 @@ bool FunctionEmitter::EmitConstDefOrWriteToHoistedVar(
AddStatementForInstruction(
create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(namer_.Name(result_id)),
std::move(ast_expr.expr)),
ast_expr.expr),
inst);
return true;
}
return EmitConstDefinition(inst, std::move(ast_expr));
return EmitConstDefinition(inst, ast_expr);
}
bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
@ -2615,13 +2607,11 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
def_info->num_uses != 1) {
// Generate a const definition or an assignment to a hoisted definition
// now and later use the const or variable name at the uses of this value.
return EmitConstDefOrWriteToHoistedVar(inst,
std::move(combinatorial_expr));
return EmitConstDefOrWriteToHoistedVar(inst, combinatorial_expr);
}
// It is harmless to defer emitting the expression until it's used.
// Any supporting statements have already been emitted.
singly_used_values_.insert(
std::make_pair(result_id, std::move(combinatorial_expr)));
singly_used_values_.insert(std::make_pair(result_id, combinatorial_expr));
return success();
}
if (failed()) {
@ -2646,9 +2636,8 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
// TODO(dneto): Order of evaluation?
auto lhs = MakeExpression(ptr_id);
auto rhs = MakeExpression(value_id);
AddStatementForInstruction(create<ast::AssignmentStatement>(
std::move(lhs.expr), std::move(rhs.expr)),
inst);
AddStatementForInstruction(
create<ast::AssignmentStatement>(lhs.expr, rhs.expr), inst);
return success();
}
case SpvOpLoad: {
@ -2658,7 +2647,7 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
// The load result type is the pointee type of its operand.
assert(expr.type->IsPointer());
expr.type = expr.type->AsPointer()->type();
return EmitConstDefOrWriteToHoistedVar(inst, std::move(expr));
return EmitConstDefOrWriteToHoistedVar(inst, expr);
}
case SpvOpCopyObject: {
// Arguably, OpCopyObject is purely combinatorial. On the other hand,
@ -2666,14 +2655,14 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
// a new named constant definition.
auto expr = MakeExpression(inst.GetSingleWordInOperand(0));
expr.type = RemapStorageClass(expr.type, result_id);
return EmitConstDefOrWriteToHoistedVar(inst, std::move(expr));
return EmitConstDefOrWriteToHoistedVar(inst, expr);
}
case SpvOpPhi: {
// Emit a read from the associated state variable.
TypedExpression expr{
parser_impl_.ConvertType(inst.type_id()),
create<ast::IdentifierExpression>(def_info->phi_var)};
return EmitConstDefOrWriteToHoistedVar(inst, std::move(expr));
return EmitConstDefOrWriteToHoistedVar(inst, expr);
}
case SpvOpFunctionCall:
return EmitFunctionCall(inst);
@ -2706,21 +2695,18 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
if (binary_op != ast::BinaryOp::kNone) {
auto arg0 = MakeOperand(inst, 0);
auto arg1 = MakeOperand(inst, 1);
auto* binary_expr = create<ast::BinaryExpression>(
binary_op, std::move(arg0.expr), std::move(arg1.expr));
TypedExpression result{ast_type, std::move(binary_expr)};
return parser_impl_.RectifyForcedResultType(std::move(result), opcode,
arg0.type);
auto* binary_expr =
create<ast::BinaryExpression>(binary_op, arg0.expr, arg1.expr);
TypedExpression result{ast_type, binary_expr};
return parser_impl_.RectifyForcedResultType(result, opcode, arg0.type);
}
auto unary_op = ast::UnaryOp::kNegation;
if (GetUnaryOp(opcode, &unary_op)) {
auto arg0 = MakeOperand(inst, 0);
auto* unary_expr =
create<ast::UnaryOpExpression>(unary_op, std::move(arg0.expr));
TypedExpression result{ast_type, std::move(unary_expr)};
return parser_impl_.RectifyForcedResultType(std::move(result), opcode,
arg0.type);
auto* unary_expr = create<ast::UnaryOpExpression>(unary_op, arg0.expr);
TypedExpression result{ast_type, unary_expr};
return parser_impl_.RectifyForcedResultType(result, opcode, arg0.type);
}
const char* unary_builtin_name = GetUnaryBuiltInFunctionName(opcode);
@ -2750,11 +2736,11 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
if (negated_op != ast::BinaryOp::kNone) {
auto arg0 = MakeOperand(inst, 0);
auto arg1 = MakeOperand(inst, 1);
auto* binary_expr = create<ast::BinaryExpression>(
negated_op, std::move(arg0.expr), std::move(arg1.expr));
auto* negated_expr = create<ast::UnaryOpExpression>(ast::UnaryOp::kNot,
std::move(binary_expr));
return {ast_type, std::move(negated_expr)};
auto* binary_expr =
create<ast::BinaryExpression>(negated_op, arg0.expr, arg1.expr);
auto* negated_expr =
create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, binary_expr);
return {ast_type, negated_expr};
}
if (opcode == SpvOpExtInst) {
@ -2836,9 +2822,8 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(
operands.emplace_back(MakeOperand(inst, iarg).expr);
}
auto* ast_type = parser_impl_.ConvertType(inst.type_id());
auto* call =
create<ast::CallExpression>(std::move(func), std::move(operands));
return {ast_type, std::move(call)};
auto* call = create<ast::CallExpression>(func, std::move(operands));
return {ast_type, call};
}
TypedExpression FunctionEmitter::MakeAccessChain(
@ -2956,13 +2941,12 @@ TypedExpression FunctionEmitter::MakeAccessChain(
}
auto* letter_index =
create<ast::IdentifierExpression>(swizzles[index_const_val]);
next_expr = create<ast::MemberAccessorExpression>(
std::move(current_expr.expr), std::move(letter_index));
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
letter_index);
} else {
// Non-constant index. Use array syntax
next_expr = create<ast::ArrayAccessorExpression>(
std::move(current_expr.expr),
std::move(MakeOperand(inst, index).expr));
current_expr.expr, MakeOperand(inst, index).expr);
}
// All vector components are the same type.
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(0);
@ -2970,21 +2954,18 @@ TypedExpression FunctionEmitter::MakeAccessChain(
case SpvOpTypeMatrix:
// Use array syntax.
next_expr = create<ast::ArrayAccessorExpression>(
std::move(current_expr.expr),
std::move(MakeOperand(inst, index).expr));
current_expr.expr, MakeOperand(inst, index).expr);
// All matrix components are the same type.
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(0);
break;
case SpvOpTypeArray:
next_expr = create<ast::ArrayAccessorExpression>(
std::move(current_expr.expr),
std::move(MakeOperand(inst, index).expr));
current_expr.expr, MakeOperand(inst, index).expr);
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(0);
break;
case SpvOpTypeRuntimeArray:
next_expr = create<ast::ArrayAccessorExpression>(
std::move(current_expr.expr),
std::move(MakeOperand(inst, index).expr));
current_expr.expr, MakeOperand(inst, index).expr);
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(0);
break;
case SpvOpTypeStruct: {
@ -3005,8 +2986,8 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto* member_access = create<ast::IdentifierExpression>(
namer_.GetMemberName(pointee_type_id, uint32_t(index_const_val)));
next_expr = create<ast::MemberAccessorExpression>(
std::move(current_expr.expr), std::move(member_access));
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
member_access);
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(
static_cast<uint32_t>(index_const_val));
break;
@ -3021,7 +3002,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto* ast_pointer_type = parser_impl_.ConvertType(pointer_type_id);
assert(ast_pointer_type);
assert(ast_pointer_type->IsPointer());
current_expr = TypedExpression{ast_pointer_type, std::move(next_expr)};
current_expr = TypedExpression{ast_pointer_type, next_expr};
}
return current_expr;
}
@ -3080,8 +3061,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
}
auto* letter_index =
create<ast::IdentifierExpression>(swizzles[index_val]);
next_expr = create<ast::MemberAccessorExpression>(
std::move(current_expr.expr), std::move(letter_index));
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
letter_index);
// All vector components are the same type.
current_type_id = current_type_inst->GetSingleWordInOperand(0);
break;
@ -3101,8 +3082,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
<< ((sizeof(swizzles) / sizeof(swizzles[0])) - 1);
}
// Use array syntax.
next_expr = create<ast::ArrayAccessorExpression>(
std::move(current_expr.expr), make_index(index_val));
next_expr = create<ast::ArrayAccessorExpression>(current_expr.expr,
make_index(index_val));
// All matrix components are the same type.
current_type_id = current_type_inst->GetSingleWordInOperand(0);
break;
@ -3111,8 +3092,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
// The array size could be a spec constant, and so it's not always
// statically checkable. Instead, rely on a runtime index clamp
// or runtime check to keep this safe.
next_expr = create<ast::ArrayAccessorExpression>(
std::move(current_expr.expr), make_index(index_val));
next_expr = create<ast::ArrayAccessorExpression>(current_expr.expr,
make_index(index_val));
current_type_id = current_type_inst->GetSingleWordInOperand(0);
break;
case SpvOpTypeRuntimeArray:
@ -3129,8 +3110,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
auto* member_access = create<ast::IdentifierExpression>(
namer_.GetMemberName(current_type_id, uint32_t(index_val)));
next_expr = create<ast::MemberAccessorExpression>(
std::move(current_expr.expr), std::move(member_access));
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
member_access);
current_type_id = current_type_inst->GetSingleWordInOperand(index_val);
break;
}
@ -3139,8 +3120,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
<< current_type_inst->PrettyPrint();
return {};
}
current_expr = TypedExpression{parser_impl_.ConvertType(current_type_id),
std::move(next_expr)};
current_expr =
TypedExpression{parser_impl_.ConvertType(current_type_id), next_expr};
}
return current_expr;
}
@ -3197,8 +3178,8 @@ TypedExpression FunctionEmitter::MakeVectorShuffle(
return {};
}
}
return {result_type, create<ast::TypeConstructorExpression>(
result_type, std::move(values))};
return {result_type,
create<ast::TypeConstructorExpression>(result_type, values)};
}
bool FunctionEmitter::RegisterLocallyDefinedValues() {
@ -3487,15 +3468,15 @@ TypedExpression FunctionEmitter::MakeNumericConversion(
}
ast::ExpressionList params;
params.push_back(std::move(arg_expr.expr));
params.push_back(arg_expr.expr);
TypedExpression result{expr_type, create<ast::TypeConstructorExpression>(
expr_type, std::move(params))};
if (requested_type == expr_type) {
return result;
}
return {requested_type, create<ast::BitcastExpression>(
requested_type, std::move(result.expr))};
return {requested_type,
create<ast::BitcastExpression>(requested_type, result.expr)};
}
bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
@ -3507,8 +3488,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) {
params.emplace_back(MakeOperand(inst, iarg).expr);
}
auto* call_expr =
create<ast::CallExpression>(std::move(function), std::move(params));
auto* call_expr = create<ast::CallExpression>(function, std::move(params));
auto* result_type = parser_impl_.ConvertType(inst.type_id());
if (!result_type) {
return Fail() << "internal error: no mapped type result of call: "
@ -3516,13 +3496,11 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
}
if (result_type->IsVoid()) {
return nullptr !=
AddStatementForInstruction(
create<ast::CallStatement>(std::move(call_expr)), inst);
return nullptr != AddStatementForInstruction(
create<ast::CallStatement>(call_expr), inst);
}
return EmitConstDefOrWriteToHoistedVar(inst,
{result_type, std::move(call_expr)});
return EmitConstDefOrWriteToHoistedVar(inst, {result_type, call_expr});
}
TypedExpression FunctionEmitter::MakeIntrinsicCall(
@ -3537,15 +3515,14 @@ TypedExpression FunctionEmitter::MakeIntrinsicCall(
for (uint32_t iarg = 0; iarg < inst.NumInOperands(); ++iarg) {
params.emplace_back(MakeOperand(inst, iarg).expr);
}
auto* call_expr =
create<ast::CallExpression>(std::move(ident), std::move(params));
auto* call_expr = create<ast::CallExpression>(ident, std::move(params));
auto* result_type = parser_impl_.ConvertType(inst.type_id());
if (!result_type) {
Fail() << "internal error: no mapped type result of call: "
<< inst.PrettyPrint();
return {};
}
return {result_type, std::move(call_expr)};
return {result_type, call_expr};
}
TypedExpression FunctionEmitter::MakeSimpleSelect(
@ -3563,10 +3540,10 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
if (op_ty->IsVector() || op_ty->is_float_scalar() ||
op_ty->is_integer_scalar() || op_ty->IsBool()) {
ast::ExpressionList params;
params.push_back(std::move(operand1.expr));
params.push_back(std::move(operand2.expr));
params.push_back(operand1.expr);
params.push_back(operand2.expr);
// The condition goes last.
params.push_back(std::move(condition.expr));
params.push_back(condition.expr);
return {operand1.type, create<ast::CallExpression>(
create<ast::IdentifierExpression>("select"),
std::move(params))};

View File

@ -851,7 +851,7 @@ ast::type::Type* ParserImpl::ConvertType(
return nullptr;
}
if (ast_member_decoration) {
ast_member_decorations.push_back(std::move(ast_member_decoration));
ast_member_decorations.push_back(ast_member_decoration);
}
}
}
@ -863,7 +863,7 @@ ast::type::Type* ParserImpl::ConvertType(
const auto member_name = namer_.GetMemberName(type_id, member_index);
auto* ast_struct_member = create<ast::StructMember>(
member_name, ast_member_ty, std::move(ast_member_decorations));
ast_members.push_back(std::move(ast_struct_member));
ast_members.push_back(ast_struct_member);
}
// Now make the struct.
@ -872,7 +872,7 @@ ast::type::Type* ParserImpl::ConvertType(
namer_.SuggestSanitizedName(type_id, "S");
auto ast_struct_type = std::make_unique<ast::type::StructType>(
namer_.GetName(type_id), std::move(ast_struct));
namer_.GetName(type_id), ast_struct);
auto* result = ctx_.type_mgr().Get(std::move(ast_struct_type));
id_to_type_[type_id] = result;
@ -991,21 +991,21 @@ bool ParserImpl::EmitScalarSpecConstants() {
for (const auto& deco : GetDecorationsFor(inst.result_id())) {
if ((deco.size() == 2) && (deco[0] == SpvDecorationSpecId)) {
auto* cid = create<ast::ConstantIdDecoration>(deco[1], Source{});
spec_id_decos.push_back(std::move(cid));
spec_id_decos.push_back(cid);
break;
}
}
if (spec_id_decos.empty()) {
// Register it as a named constant, without specialization id.
ast_var->set_is_const(true);
ast_var->set_constructor(std::move(ast_expr));
ast_module_.AddGlobalVariable(std::move(ast_var));
ast_var->set_constructor(ast_expr);
ast_module_.AddGlobalVariable(ast_var);
} else {
auto* ast_deco_var = create<ast::DecoratedVariable>(std::move(ast_var));
auto* ast_deco_var = create<ast::DecoratedVariable>(ast_var);
ast_deco_var->set_is_const(true);
ast_deco_var->set_constructor(std::move(ast_expr));
ast_deco_var->set_constructor(ast_expr);
ast_deco_var->set_decorations(std::move(spec_id_decos));
ast_module_.AddGlobalVariable(std::move(ast_deco_var));
ast_module_.AddGlobalVariable(ast_deco_var);
}
scalar_spec_constants_.insert(inst.result_id());
}
@ -1112,7 +1112,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
MakeConstantExpression(var.GetSingleWordInOperand(1)).expr);
}
// TODO(dneto): initializers (a.k.a. constructor expression)
ast_module_.AddGlobalVariable(std::move(ast_var));
ast_module_.AddGlobalVariable(ast_var);
}
// Emit gl_Position instead of gl_PerVertex
@ -1129,7 +1129,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
create<ast::BuiltinDecoration>(ast::Builtin::kPosition, Source{}));
var->set_decorations(std::move(decos));
ast_module_.AddGlobalVariable(std::move(var));
ast_module_.AddGlobalVariable(var);
}
return success_;
}
@ -1202,7 +1202,7 @@ ast::Variable* ParserImpl::MakeVariable(uint32_t id,
}
}
if (!ast_decorations.empty()) {
auto* decorated_var = create<ast::DecoratedVariable>(std::move(ast_var));
auto* decorated_var = create<ast::DecoratedVariable>(ast_var);
decorated_var->set_decorations(std::move(ast_decorations));
ast_var = std::move(decorated_var);
}
@ -1284,7 +1284,7 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
// We've already emitted a diagnostic.
return {};
}
ast_components.emplace_back(std::move(ast_component.expr));
ast_components.emplace_back(ast_component.expr);
}
return {original_ast_type,
create<ast::TypeConstructorExpression>(original_ast_type,
@ -1394,15 +1394,14 @@ TypedExpression ParserImpl::RectifyOperandSignedness(SpvOp op,
auto* unsigned_ty = unsigned_type_for_[type];
if (unsigned_ty != nullptr) {
// Conversion is required.
return {unsigned_ty, create<ast::BitcastExpression>(
unsigned_ty, std::move(expr.expr))};
return {unsigned_ty,
create<ast::BitcastExpression>(unsigned_ty, expr.expr)};
}
} else if (requires_signed) {
auto* signed_ty = signed_type_for_[type];
if (signed_ty != nullptr) {
// Conversion is required.
return {signed_ty,
create<ast::BitcastExpression>(signed_ty, std::move(expr.expr))};
return {signed_ty, create<ast::BitcastExpression>(signed_ty, expr.expr)};
}
}
// We should not reach here.
@ -1465,8 +1464,7 @@ TypedExpression ParserImpl::RectifyForcedResultType(
if ((forced_result_ty == nullptr) || (forced_result_ty == expr.type)) {
return expr;
}
return {expr.type,
create<ast::BitcastExpression>(expr.type, std::move(expr.expr))};
return {expr.type, create<ast::BitcastExpression>(expr.type, expr.expr)};
}
bool ParserImpl::EmitFunctions() {

View File

@ -268,7 +268,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("variable declaration", Token::Type::kSemicolon))
return Failure::kErrored;
module_.AddGlobalVariable(std::move(gv.value));
module_.AddGlobalVariable(gv.value);
return true;
}
@ -280,7 +280,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("constant declaration", Token::Type::kSemicolon))
return Failure::kErrored;
module_.AddGlobalVariable(std::move(gc.value));
module_.AddGlobalVariable(gc.value);
return true;
}
@ -322,7 +322,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (func.errored)
errored = true;
if (func.matched) {
module_.AddFunction(std::move(func.value));
module_.AddFunction(func.value);
return true;
}
@ -348,23 +348,23 @@ Maybe<ast::Variable*> ParserImpl::global_variable_decl(
if (!decl.matched)
return Failure::kNoMatch;
auto* var = std::move(decl.value);
auto* var = decl.value;
auto var_decos = cast_decorations<ast::VariableDecoration>(decos);
if (var_decos.errored)
return Failure::kErrored;
if (var_decos.value.size() > 0) {
auto* dv = create<ast::DecoratedVariable>(std::move(var));
dv->set_decorations(std::move(var_decos.value));
var = std::move(dv);
auto* dv = create<ast::DecoratedVariable>(var);
dv->set_decorations(var_decos.value);
var = dv;
}
if (match(Token::Type::kEqual)) {
auto expr = expect_const_expr();
if (expr.errored)
return Failure::kErrored;
var->set_constructor(std::move(expr.value));
var->set_constructor(expr.value);
}
return var;
}
@ -392,7 +392,7 @@ Maybe<ast::Variable*> ParserImpl::global_constant_decl() {
if (init.errored)
return Failure::kErrored;
var->set_constructor(std::move(init.value));
var->set_constructor(init.value);
return var;
}
@ -1113,7 +1113,7 @@ Expect<ast::StructMemberList> ParserImpl::expect_struct_body_decl() {
if (member.errored) {
errored = true;
} else {
members.push_back(std::move(member.value));
members.push_back(member.value);
}
}
@ -1177,8 +1177,8 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
if (errored)
return Failure::kErrored;
f->set_body(std::move(body.value));
return std::move(f.value);
f->set_body(body.value);
return f.value;
}
// function_type_decl
@ -1252,7 +1252,7 @@ Expect<ast::VariableList> ParserImpl::expect_param_list() {
// that it's not updatable after intially set. This is unlike C or GLSL
// which treat formal parameters like local variables that can be updated.
var->set_is_const(true);
ret.push_back(std::move(var));
ret.push_back(var);
if (!match(Token::Type::kComma))
break;
@ -1311,7 +1311,7 @@ Expect<ast::Expression*> ParserImpl::expect_paren_rhs_stmt() {
if (!expr.matched)
return add_error(peek(), "unable to parse expression");
return std::move(expr.value);
return expr.value;
});
}
@ -1326,7 +1326,7 @@ Expect<ast::BlockStatement*> ParserImpl::expect_statements() {
if (stmt.errored) {
errored = true;
} else if (stmt.matched) {
ret->append(std::move(stmt.value));
ret->append(stmt.value);
} else {
break;
}
@ -1371,31 +1371,31 @@ Maybe<ast::Statement*> ParserImpl::statement() {
if (stmt_if.errored)
return Failure::kErrored;
if (stmt_if.matched)
return std::move(stmt_if.value);
return stmt_if.value;
auto sw = switch_stmt();
if (sw.errored)
return Failure::kErrored;
if (sw.matched)
return std::move(sw.value);
return sw.value;
auto loop = loop_stmt();
if (loop.errored)
return Failure::kErrored;
if (loop.matched)
return std::move(loop.value);
return loop.value;
auto stmt_for = for_stmt();
if (stmt_for.errored)
return Failure::kErrored;
if (stmt_for.matched)
return std::move(stmt_for.value);
return stmt_for.value;
if (peek().IsBraceLeft()) {
auto body = expect_body_stmt();
if (body.errored)
return Failure::kErrored;
return std::move(body.value);
return body.value;
}
return Failure::kNoMatch;
@ -1415,37 +1415,37 @@ Maybe<ast::Statement*> ParserImpl::non_block_statement() {
if (ret_stmt.errored)
return Failure::kErrored;
if (ret_stmt.matched)
return std::move(ret_stmt.value);
return ret_stmt.value;
auto func = func_call_stmt();
if (func.errored)
return Failure::kErrored;
if (func.matched)
return std::move(func.value);
return func.value;
auto var = variable_stmt();
if (var.errored)
return Failure::kErrored;
if (var.matched)
return std::move(var.value);
return var.value;
auto b = break_stmt();
if (b.errored)
return Failure::kErrored;
if (b.matched)
return std::move(b.value);
return b.value;
auto cont = continue_stmt();
if (cont.errored)
return Failure::kErrored;
if (cont.matched)
return std::move(cont.value);
return cont.value;
auto assign = assignment_stmt();
if (assign.errored)
return Failure::kErrored;
if (assign.matched)
return std::move(assign.value);
return assign.value;
Source source;
if (match(Token::Type::kDiscard, &source))
@ -1475,7 +1475,7 @@ Maybe<ast::ReturnStatement*> ParserImpl::return_stmt() {
return Failure::kErrored;
// TODO(bclayton): Check matched?
return create<ast::ReturnStatement>(source, std::move(expr.value));
return create<ast::ReturnStatement>(source, expr.value);
}
// variable_stmt
@ -1500,9 +1500,9 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
auto* var = create<ast::Variable>(decl->source, decl->name,
ast::StorageClass::kNone, decl->type);
var->set_is_const(true);
var->set_constructor(std::move(constructor.value));
var->set_constructor(constructor.value);
return create<ast::VariableDeclStatement>(decl->source, std::move(var));
return create<ast::VariableDeclStatement>(decl->source, var);
}
auto var = variable_decl();
@ -1518,11 +1518,10 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
if (!constructor.matched)
return add_error(peek(), "missing constructor for variable declaration");
var->set_constructor(std::move(constructor.value));
var->set_constructor(constructor.value);
}
return create<ast::VariableDeclStatement>(var->source(),
std::move(var.value));
return create<ast::VariableDeclStatement>(var->source(), var.value);
}
// if_stmt
@ -1548,12 +1547,11 @@ Maybe<ast::IfStatement*> ParserImpl::if_stmt() {
if (el.errored)
return Failure::kErrored;
auto* stmt = create<ast::IfStatement>(source, std::move(condition.value),
std::move(body.value));
auto* stmt = create<ast::IfStatement>(source, condition.value, body.value);
if (el.matched) {
elseif.value.push_back(std::move(el.value));
elseif.value.push_back(el.value);
}
stmt->set_else_statements(std::move(elseif.value));
stmt->set_else_statements(elseif.value);
return stmt;
}
@ -1575,8 +1573,8 @@ Maybe<ast::ElseStatementList> ParserImpl::elseif_stmt() {
if (body.errored)
return Failure::kErrored;
ret.push_back(create<ast::ElseStatement>(source, std::move(condition.value),
std::move(body.value)));
ret.push_back(
create<ast::ElseStatement>(source, condition.value, body.value));
if (!match(Token::Type::kElseIf, &source))
break;
@ -1596,7 +1594,7 @@ Maybe<ast::ElseStatement*> ParserImpl::else_stmt() {
if (body.errored)
return Failure::kErrored;
return create<ast::ElseStatement>(source, std::move(body.value));
return create<ast::ElseStatement>(source, body.value);
}
// switch_stmt
@ -1622,7 +1620,7 @@ Maybe<ast::SwitchStatement*> ParserImpl::switch_stmt() {
}
if (!stmt.matched)
break;
list.push_back(std::move(stmt.value));
list.push_back(stmt.value);
}
if (errored)
return Failure::kErrored;
@ -1632,8 +1630,7 @@ Maybe<ast::SwitchStatement*> ParserImpl::switch_stmt() {
if (body.errored)
return Failure::kErrored;
return create<ast::SwitchStatement>(source, std::move(condition.value),
std::move(body.value));
return create<ast::SwitchStatement>(source, condition.value, body.value);
}
// switch_body
@ -1669,7 +1666,7 @@ Maybe<ast::CaseStatement*> ParserImpl::switch_body() {
if (!body.matched)
return add_error(body.source, "expected case body");
stmt->set_body(std::move(body.value));
stmt->set_body(body.value);
return stmt;
}
@ -1720,7 +1717,7 @@ Maybe<ast::BlockStatement*> ParserImpl::case_body() {
if (!stmt.matched)
break;
ret->append(std::move(stmt.value));
ret->append(stmt.value);
}
return ret;
@ -1742,17 +1739,14 @@ Maybe<ast::LoopStatement*> ParserImpl::loop_stmt() {
if (continuing.errored)
return Failure::kErrored;
return create<ast::LoopStatement>(source, std::move(body.value),
std::move(continuing.value));
return create<ast::LoopStatement>(source, body.value, continuing.value);
});
}
ForHeader::ForHeader(ast::Statement* init,
ast::Expression* cond,
ast::Statement* cont)
: initializer(std::move(init)),
condition(std::move(cond)),
continuing(std::move(cont)) {}
: initializer(init), condition(cond), continuing(cont) {}
ForHeader::~ForHeader() = default;
@ -1762,19 +1756,19 @@ Maybe<ast::Statement*> ParserImpl::for_header_initializer() {
if (call.errored)
return Failure::kErrored;
if (call.matched)
return std::move(call.value);
return call.value;
auto var = variable_stmt();
if (var.errored)
return Failure::kErrored;
if (var.matched)
return std::move(var.value);
return var.value;
auto assign = assignment_stmt();
if (assign.errored)
return Failure::kErrored;
if (assign.matched)
return std::move(assign.value);
return assign.value;
return Failure::kNoMatch;
}
@ -1785,13 +1779,13 @@ Maybe<ast::Statement*> ParserImpl::for_header_continuing() {
if (call_stmt.errored)
return Failure::kErrored;
if (call_stmt.matched)
return std::move(call_stmt.value);
return call_stmt.value;
auto assign = assignment_stmt();
if (assign.errored)
return Failure::kErrored;
if (assign.matched)
return std::move(assign.value);
return assign.value;
return Failure::kNoMatch;
}
@ -1820,9 +1814,8 @@ Expect<std::unique_ptr<ForHeader>> ParserImpl::expect_for_header() {
if (continuing.errored)
return Failure::kErrored;
return std::make_unique<ForHeader>(std::move(initializer.value),
std::move(condition.value),
std::move(continuing.value));
return std::make_unique<ForHeader>(initializer.value, condition.value,
continuing.value);
}
// for_statement
@ -1848,32 +1841,29 @@ Maybe<ast::Statement*> ParserImpl::for_stmt() {
if (header->condition != nullptr) {
// !condition
auto* not_condition = create<ast::UnaryOpExpression>(
header->condition->source(), ast::UnaryOp::kNot,
std::move(header->condition));
header->condition->source(), ast::UnaryOp::kNot, header->condition);
// { break; }
auto* break_stmt = create<ast::BreakStatement>(not_condition->source());
auto* break_body = create<ast::BlockStatement>(not_condition->source());
break_body->append(std::move(break_stmt));
break_body->append(break_stmt);
// if (!condition) { break; }
auto* break_if_not_condition = create<ast::IfStatement>(
not_condition->source(), std::move(not_condition),
std::move(break_body));
body->insert(0, std::move(break_if_not_condition));
not_condition->source(), not_condition, break_body);
body->insert(0, break_if_not_condition);
}
ast::BlockStatement* continuing_body = nullptr;
if (header->continuing != nullptr) {
continuing_body = create<ast::BlockStatement>(header->continuing->source());
continuing_body->append(std::move(header->continuing));
continuing_body->append(header->continuing);
}
auto* loop = create<ast::LoopStatement>(source, std::move(body.value),
std::move(continuing_body));
auto* loop = create<ast::LoopStatement>(source, body.value, continuing_body);
if (header->initializer != nullptr) {
auto* result = create<ast::BlockStatement>(source);
result->append(std::move(header->initializer));
result->append(std::move(loop));
result->append(header->initializer);
result->append(loop);
return result;
}
@ -1955,15 +1945,14 @@ Maybe<ast::Expression*> ParserImpl::primary_expression() {
if (lit.errored)
return Failure::kErrored;
if (lit.matched)
return create<ast::ScalarConstructorExpression>(source,
std::move(lit.value));
return create<ast::ScalarConstructorExpression>(source, lit.value);
if (t.IsParenLeft()) {
auto paren = expect_paren_rhs_stmt();
if (paren.errored)
return Failure::kErrored;
return std::move(paren.value);
return paren.value;
}
if (match(Token::Type::kBitcast)) {
@ -1977,8 +1966,7 @@ Maybe<ast::Expression*> ParserImpl::primary_expression() {
if (params.errored)
return Failure::kErrored;
return create<ast::BitcastExpression>(source, type.value,
std::move(params.value));
return create<ast::BitcastExpression>(source, type.value, params.value);
}
if (match(Token::Type::kIdentifier))
@ -1999,14 +1987,14 @@ Maybe<ast::Expression*> ParserImpl::primary_expression() {
if (params.errored)
return Failure::kErrored;
return create<ast::TypeConstructorExpression>(
source, type.value, std::move(params.value));
return create<ast::TypeConstructorExpression>(source, type.value,
params.value);
});
if (expr.errored)
return Failure::kErrored;
return std::move(expr.value);
return expr.value;
}
return Failure::kNoMatch;
@ -2029,8 +2017,8 @@ Maybe<ast::Expression*> ParserImpl::postfix_expr(ast::Expression* prefix) {
if (!expect("array accessor", Token::Type::kBracketRight))
return Failure::kErrored;
return postfix_expr(create<ast::ArrayAccessorExpression>(
source, std::move(prefix), std::move(param.value)));
return postfix_expr(
create<ast::ArrayAccessorExpression>(source, prefix, param.value));
}
if (match(Token::Type::kParenLeft, &source)) {
@ -2041,14 +2029,13 @@ Maybe<ast::Expression*> ParserImpl::postfix_expr(ast::Expression* prefix) {
auto list = expect_argument_expression_list();
if (list.errored)
return Failure::kErrored;
params = std::move(list.value);
params = list.value;
}
if (!expect("call expression", Token::Type::kParenRight))
return Failure::kErrored;
return postfix_expr(create<ast::CallExpression>(source, std::move(prefix),
std::move(params)));
return postfix_expr(create<ast::CallExpression>(source, prefix, params));
}
if (match(Token::Type::kPeriod)) {
@ -2057,7 +2044,7 @@ Maybe<ast::Expression*> ParserImpl::postfix_expr(ast::Expression* prefix) {
return Failure::kErrored;
return postfix_expr(create<ast::MemberAccessorExpression>(
ident.source, std::move(prefix),
ident.source, prefix,
create<ast::IdentifierExpression>(ident.source, ident.value)));
}
@ -2073,7 +2060,7 @@ Maybe<ast::Expression*> ParserImpl::postfix_expression() {
if (!prefix.matched)
return Failure::kNoMatch;
return postfix_expr(std::move(prefix.value));
return postfix_expr(prefix.value);
}
// argument_expression_list
@ -2086,7 +2073,7 @@ Expect<ast::ExpressionList> ParserImpl::expect_argument_expression_list() {
return add_error(peek(), "unable to parse argument expression");
ast::ExpressionList ret;
ret.push_back(std::move(arg.value));
ret.push_back(arg.value);
while (match(Token::Type::kComma)) {
arg = logical_or_expression();
@ -2096,7 +2083,7 @@ Expect<ast::ExpressionList> ParserImpl::expect_argument_expression_list() {
return add_error(peek(),
"unable to parse argument expression after comma");
}
ret.push_back(std::move(arg.value));
ret.push_back(arg.value);
}
return ret;
}
@ -2124,7 +2111,7 @@ Maybe<ast::Expression*> ParserImpl::unary_expression() {
return add_error(peek(),
"unable to parse right side of " + name + " expression");
return create<ast::UnaryOpExpression>(source, op, std::move(expr.value));
return create<ast::UnaryOpExpression>(source, op, expr.value);
}
return postfix_expression();
}
@ -2160,8 +2147,8 @@ Expect<ast::Expression*> ParserImpl::expect_multiplicative_expr(
"unable to parse right side of " + name + " expression");
}
return expect_multiplicative_expr(create<ast::BinaryExpression>(
source, op, std::move(lhs), std::move(rhs.value)));
return expect_multiplicative_expr(
create<ast::BinaryExpression>(source, op, lhs, rhs.value));
}
// multiplicative_expression
@ -2173,7 +2160,7 @@ Maybe<ast::Expression*> ParserImpl::multiplicative_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_multiplicative_expr(std::move(lhs.value));
return expect_multiplicative_expr(lhs.value);
}
// additive_expr
@ -2201,8 +2188,8 @@ Expect<ast::Expression*> ParserImpl::expect_additive_expr(
if (!rhs.matched)
return add_error(peek(), "unable to parse right side of + expression");
return expect_additive_expr(create<ast::BinaryExpression>(
source, op, std::move(lhs), std::move(rhs.value)));
return expect_additive_expr(
create<ast::BinaryExpression>(source, op, lhs, rhs.value));
}
// additive_expression
@ -2214,7 +2201,7 @@ Maybe<ast::Expression*> ParserImpl::additive_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_additive_expr(std::move(lhs.value));
return expect_additive_expr(lhs.value);
}
// shift_expr
@ -2249,8 +2236,8 @@ Expect<ast::Expression*> ParserImpl::expect_shift_expr(ast::Expression* lhs) {
return add_error(peek(), std::string("unable to parse right side of ") +
name + " expression");
}
return expect_shift_expr(create<ast::BinaryExpression>(
source, op, std::move(lhs), std::move(rhs.value)));
return expect_shift_expr(
create<ast::BinaryExpression>(source, op, lhs, rhs.value));
} // namespace wgsl
// shift_expression
@ -2262,7 +2249,7 @@ Maybe<ast::Expression*> ParserImpl::shift_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_shift_expr(std::move(lhs.value));
return expect_shift_expr(lhs.value);
}
// relational_expr
@ -2298,8 +2285,8 @@ Expect<ast::Expression*> ParserImpl::expect_relational_expr(
"unable to parse right side of " + name + " expression");
}
return expect_relational_expr(create<ast::BinaryExpression>(
source, op, std::move(lhs), std::move(rhs.value)));
return expect_relational_expr(
create<ast::BinaryExpression>(source, op, lhs, rhs.value));
}
// relational_expression
@ -2311,7 +2298,7 @@ Maybe<ast::Expression*> ParserImpl::relational_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_relational_expr(std::move(lhs.value));
return expect_relational_expr(lhs.value);
}
// equality_expr
@ -2341,8 +2328,8 @@ Expect<ast::Expression*> ParserImpl::expect_equality_expr(
"unable to parse right side of " + name + " expression");
}
return expect_equality_expr(create<ast::BinaryExpression>(
source, op, std::move(lhs), std::move(rhs.value)));
return expect_equality_expr(
create<ast::BinaryExpression>(source, op, lhs, rhs.value));
}
// equality_expression
@ -2354,7 +2341,7 @@ Maybe<ast::Expression*> ParserImpl::equality_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_equality_expr(std::move(lhs.value));
return expect_equality_expr(lhs.value);
}
// and_expr
@ -2375,7 +2362,7 @@ Expect<ast::Expression*> ParserImpl::expect_and_expr(ast::Expression* lhs) {
return add_error(peek(), "unable to parse right side of & expression");
return expect_and_expr(create<ast::BinaryExpression>(
source, ast::BinaryOp::kAnd, std::move(lhs), std::move(rhs.value)));
source, ast::BinaryOp::kAnd, lhs, rhs.value));
}
// and_expression
@ -2387,7 +2374,7 @@ Maybe<ast::Expression*> ParserImpl::and_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_and_expr(std::move(lhs.value));
return expect_and_expr(lhs.value);
}
// exclusive_or_expr
@ -2406,7 +2393,7 @@ Expect<ast::Expression*> ParserImpl::expect_exclusive_or_expr(
return add_error(peek(), "unable to parse right side of ^ expression");
return expect_exclusive_or_expr(create<ast::BinaryExpression>(
source, ast::BinaryOp::kXor, std::move(lhs), std::move(rhs.value)));
source, ast::BinaryOp::kXor, lhs, rhs.value));
}
// exclusive_or_expression
@ -2418,7 +2405,7 @@ Maybe<ast::Expression*> ParserImpl::exclusive_or_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_exclusive_or_expr(std::move(lhs.value));
return expect_exclusive_or_expr(lhs.value);
}
// inclusive_or_expr
@ -2437,7 +2424,7 @@ Expect<ast::Expression*> ParserImpl::expect_inclusive_or_expr(
return add_error(peek(), "unable to parse right side of | expression");
return expect_inclusive_or_expr(create<ast::BinaryExpression>(
source, ast::BinaryOp::kOr, std::move(lhs), std::move(rhs.value)));
source, ast::BinaryOp::kOr, lhs, rhs.value));
}
// inclusive_or_expression
@ -2449,7 +2436,7 @@ Maybe<ast::Expression*> ParserImpl::inclusive_or_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_inclusive_or_expr(std::move(lhs.value));
return expect_inclusive_or_expr(lhs.value);
}
// logical_and_expr
@ -2470,9 +2457,8 @@ Expect<ast::Expression*> ParserImpl::expect_logical_and_expr(
if (!rhs.matched)
return add_error(peek(), "unable to parse right side of && expression");
return expect_logical_and_expr(
create<ast::BinaryExpression>(source, ast::BinaryOp::kLogicalAnd,
std::move(lhs), std::move(rhs.value)));
return expect_logical_and_expr(create<ast::BinaryExpression>(
source, ast::BinaryOp::kLogicalAnd, lhs, rhs.value));
}
// logical_and_expression
@ -2484,7 +2470,7 @@ Maybe<ast::Expression*> ParserImpl::logical_and_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_logical_and_expr(std::move(lhs.value));
return expect_logical_and_expr(lhs.value);
}
// logical_or_expr
@ -2503,7 +2489,7 @@ Expect<ast::Expression*> ParserImpl::expect_logical_or_expr(
return add_error(peek(), "unable to parse right side of || expression");
return expect_logical_or_expr(create<ast::BinaryExpression>(
source, ast::BinaryOp::kLogicalOr, std::move(lhs), std::move(rhs.value)));
source, ast::BinaryOp::kLogicalOr, lhs, rhs.value));
}
// logical_or_expression
@ -2515,7 +2501,7 @@ Maybe<ast::Expression*> ParserImpl::logical_or_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_logical_or_expr(std::move(lhs.value));
return expect_logical_or_expr(lhs.value);
}
// assignment_stmt
@ -2539,8 +2525,7 @@ Maybe<ast::AssignmentStatement*> ParserImpl::assignment_stmt() {
if (!rhs.matched)
return add_error(peek(), "unable to parse right side of assignment");
return create<ast::AssignmentStatement>(source, std::move(lhs.value),
std::move(rhs.value));
return create<ast::AssignmentStatement>(source, lhs.value, rhs.value);
}
// const_literal
@ -2601,12 +2586,12 @@ Expect<ast::ConstructorExpression*> ParserImpl::expect_const_expr_internal(
auto param = expect_const_expr_internal(depth + 1);
if (param.errored)
return Failure::kErrored;
list.emplace_back(std::move(param.value));
list.emplace_back(param.value);
while (match(Token::Type::kComma)) {
param = expect_const_expr_internal(depth + 1);
if (param.errored)
return Failure::kErrored;
list.emplace_back(std::move(param.value));
list.emplace_back(param.value);
}
return list;
});
@ -2615,7 +2600,7 @@ Expect<ast::ConstructorExpression*> ParserImpl::expect_const_expr_internal(
return Failure::kErrored;
return create<ast::TypeConstructorExpression>(source, type.value,
std::move(params.value));
params.value);
}
auto lit = const_literal();
@ -2624,7 +2609,7 @@ Expect<ast::ConstructorExpression*> ParserImpl::expect_const_expr_internal(
if (!lit.matched)
return add_error(peek(), "unable to parse const literal");
return create<ast::ScalarConstructorExpression>(source, std::move(lit.value));
return create<ast::ScalarConstructorExpression>(source, lit.value);
}
Maybe<ast::DecorationList> ParserImpl::decoration_list() {
@ -2669,7 +2654,7 @@ Maybe<bool> ParserImpl::decoration_bracketed_list(ast::DecorationList& decos) {
auto deco = expect_decoration();
if (deco.errored)
errored = true;
decos.emplace_back(std::move(deco.value));
decos.emplace_back(deco.value);
if (match(Token::Type::kComma))
continue;
@ -2701,7 +2686,7 @@ Expect<ast::Decoration*> ParserImpl::expect_decoration() {
if (deco.errored)
return Failure::kErrored;
if (deco.matched)
return std::move(deco.value);
return deco.value;
return add_error(t, "expected decoration");
}
@ -2824,7 +2809,7 @@ Expect<std::vector<T*>> ParserImpl::cast_decorations(ast::DecorationList& in) {
ok = false;
continue;
}
out.emplace_back(ast::As<T>(std::move(deco)));
out.emplace_back(ast::As<T>(deco));
}
// clear in so that we can verify decorations were consumed with
// expect_decorations_consumed()

View File

@ -30,8 +30,8 @@ TEST_F(ParserImplTest, FunctionDecorationList_Parses) {
EXPECT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 2u);
auto* deco_0 = ast::As<ast::FunctionDecoration>(std::move(decos.value[0]));
auto* deco_1 = ast::As<ast::FunctionDecoration>(std::move(decos.value[1]));
auto* deco_0 = ast::As<ast::FunctionDecoration>(decos.value[0]);
auto* deco_1 = ast::As<ast::FunctionDecoration>(decos.value[1]);
ASSERT_NE(deco_0, nullptr);
ASSERT_NE(deco_1, nullptr);

View File

@ -30,7 +30,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup) {
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
auto* func_deco = ast::As<ast::FunctionDecoration>(std::move(deco.value));
auto* func_deco = ast::As<ast::FunctionDecoration>(deco.value);
ASSERT_NE(func_deco, nullptr);
ASSERT_TRUE(func_deco->IsWorkgroup());
@ -50,7 +50,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_2Param) {
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
auto* func_deco = ast::As<ast::FunctionDecoration>(std::move(deco.value));
auto* func_deco = ast::As<ast::FunctionDecoration>(deco.value);
ASSERT_NE(func_deco, nullptr) << p->error();
ASSERT_TRUE(func_deco->IsWorkgroup());
@ -70,7 +70,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_3Param) {
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
auto* func_deco = ast::As<ast::FunctionDecoration>(std::move(deco.value));
auto* func_deco = ast::As<ast::FunctionDecoration>(deco.value);
ASSERT_NE(func_deco, nullptr);
ASSERT_TRUE(func_deco->IsWorkgroup());
@ -257,7 +257,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Stage) {
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
auto* func_deco = ast::As<ast::FunctionDecoration>(std::move(deco.value));
auto* func_deco = ast::As<ast::FunctionDecoration>(deco.value);
ASSERT_NE(func_deco, nullptr);
ASSERT_TRUE(func_deco->IsStage());
EXPECT_EQ(func_deco->AsStage()->value(), ast::PipelineStage::kCompute);

View File

@ -28,7 +28,7 @@ TEST_F(ParserImplTest, StructDecorationDecl_Parses) {
EXPECT_FALSE(decos.errored);
EXPECT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 1u);
auto* struct_deco = ast::As<ast::StructDecoration>(std::move(decos.value[0]));
auto* struct_deco = ast::As<ast::StructDecoration>(decos.value[0]);
EXPECT_TRUE(struct_deco->IsBlock());
}

View File

@ -43,7 +43,7 @@ TEST_P(StructDecorationTest, Parses) {
EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr);
auto* struct_deco = ast::As<ast::StructDecoration>(std::move(deco.value));
auto* struct_deco = ast::As<ast::StructDecoration>(deco.value);
ASSERT_NE(struct_deco, nullptr);
EXPECT_EQ(struct_deco->IsBlock(), params.is_block);
}

View File

@ -48,7 +48,7 @@ TEST_F(ParserImplTest, StructMemberDecorationDecl_Single) {
EXPECT_FALSE(decos.errored);
EXPECT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 1u);
auto* deco = ast::As<ast::StructMemberDecoration>(std::move(decos.value[0]));
auto* deco = ast::As<ast::StructMemberDecoration>(decos.value[0]);
ASSERT_NE(deco, nullptr);
EXPECT_TRUE(deco->IsOffset());
}

View File

@ -30,8 +30,7 @@ TEST_F(ParserImplTest, StructMemberDecoration_Offset) {
ASSERT_NE(deco.value, nullptr);
ASSERT_FALSE(p->has_error());
auto* member_deco =
ast::As<ast::StructMemberDecoration>(std::move(deco.value));
auto* member_deco = ast::As<ast::StructMemberDecoration>(deco.value);
ASSERT_NE(member_deco, nullptr);
ASSERT_TRUE(member_deco->IsOffset());

View File

@ -31,8 +31,8 @@ TEST_F(ParserImplTest, VariableDecorationList_Parses) {
ASSERT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 2u);
auto* deco_0 = ast::As<ast::VariableDecoration>(std::move(decos.value[0]));
auto* deco_1 = ast::As<ast::VariableDecoration>(std::move(decos.value[1]));
auto* deco_0 = ast::As<ast::VariableDecoration>(decos.value[0]);
auto* deco_1 = ast::As<ast::VariableDecoration>(decos.value[1]);
ASSERT_NE(deco_0, nullptr);
ASSERT_NE(deco_1, nullptr);

View File

@ -31,7 +31,7 @@ TEST_F(ParserImplTest, VariableDecoration_Location) {
EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr);
auto* var_deco = ast::As<ast::VariableDecoration>(std::move(deco.value));
auto* var_deco = ast::As<ast::VariableDecoration>(deco.value);
ASSERT_NE(var_deco, nullptr);
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(var_deco->IsLocation());
@ -101,7 +101,7 @@ TEST_P(BuiltinTest, VariableDecoration_Builtin) {
EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr);
auto* var_deco = ast::As<ast::VariableDecoration>(std::move(deco.value));
auto* var_deco = ast::As<ast::VariableDecoration>(deco.value);
ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(var_deco, nullptr);
ASSERT_TRUE(var_deco->IsBuiltin());
@ -180,7 +180,7 @@ TEST_F(ParserImplTest, VariableDecoration_Binding) {
EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr);
auto* var_deco = ast::As<ast::VariableDecoration>(std::move(deco.value));
auto* var_deco = ast::As<ast::VariableDecoration>(deco.value);
ASSERT_NE(var_deco, nullptr);
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(var_deco->IsBinding());
@ -237,7 +237,7 @@ TEST_F(ParserImplTest, VariableDecoration_set) {
EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr);
auto* var_deco = ast::As<ast::VariableDecoration>(std::move(deco.value));
auto* var_deco = ast::As<ast::VariableDecoration>(deco.value);
ASSERT_FALSE(p->has_error());
ASSERT_NE(var_deco, nullptr);
ASSERT_TRUE(var_deco->IsSet());

View File

@ -244,8 +244,7 @@ bool BoundArrayAccessorsTransform::ProcessAccessExpression(
cast_expr.push_back(expr->idx_expr());
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(u32, std::move(cast_expr)));
params.push_back(create<ast::TypeConstructorExpression>(u32, cast_expr));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(u32, size - 1)));
@ -253,7 +252,7 @@ bool BoundArrayAccessorsTransform::ProcessAccessExpression(
create<ast::IdentifierExpression>("min"), std::move(params));
call_expr->set_result_type(u32);
expr->set_idx_expr(std::move(call_expr));
expr->set_idx_expr(call_expr);
}
return true;
}

View File

@ -54,15 +54,15 @@ class BoundArrayAccessorsTest : public testing::Test {
ast::BlockStatement* SetupFunctionAndBody() {
auto* block = create<ast::BlockStatement>();
body_ = block;
auto* func = create<ast::Function>("func", ast::VariableList{}, &void_type_,
std::move(block));
mod_.AddFunction(std::move(func));
auto* func =
create<ast::Function>("func", ast::VariableList{}, &void_type_, block);
mod_.AddFunction(func);
return body_;
}
void DeclareVariable(ast::Variable* var) {
ASSERT_NE(body_, nullptr);
body_->append(create<ast::VariableDeclStatement>(std::move(var)));
body_->append(create<ast::VariableDeclStatement>(var));
}
TypeDeterminer* td() { return &td_; }
@ -105,19 +105,18 @@ TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) {
auto* c_var = create<ast::Variable>("c", ast::StorageClass::kFunction, &u32);
c_var->set_is_const(true);
DeclareVariable(std::move(c_var));
DeclareVariable(c_var);
auto* access_idx = create<ast::IdentifierExpression>("c");
auto* access_ptr = access_idx;
auto* accessor = create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>("a"), std::move(access_idx));
create<ast::IdentifierExpression>("a"), access_idx);
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &ptr_type);
b->set_constructor(std::move(accessor));
b->set_constructor(accessor);
b->set_is_const(true);
DeclareVariable(std::move(b));
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -136,7 +135,7 @@ TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) {
auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor();
EXPECT_TRUE(tc->type()->IsU32());
ASSERT_EQ(tc->values().size(), 1u);
ASSERT_EQ(tc->values()[0], access_ptr);
ASSERT_EQ(tc->values()[0], access_idx);
ASSERT_TRUE(idx->params()[1]->IsConstructor());
ASSERT_TRUE(idx->params()[1]->AsConstructor()->IsScalarConstructor());
@ -170,18 +169,17 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Nested_Scalar) {
create<ast::Variable>("i", ast::StorageClass::kFunction, &u32));
auto* b_access_idx = create<ast::IdentifierExpression>("i");
auto* b_access_ptr = b_access_idx;
auto* a_access_idx = create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>("b"), std::move(b_access_idx));
create<ast::IdentifierExpression>("b"), b_access_idx);
auto* accessor = create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>("a"), std::move(a_access_idx));
create<ast::IdentifierExpression>("a"), a_access_idx);
auto* ptr = accessor;
auto* b = create<ast::Variable>("c", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -214,7 +212,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Nested_Scalar) {
tc = sub_idx->params()[0]->AsConstructor()->AsTypeConstructor();
EXPECT_TRUE(tc->type()->IsU32());
ASSERT_EQ(tc->values().size(), 1u);
ASSERT_EQ(tc->values()[0], b_access_ptr);
ASSERT_EQ(tc->values()[0], b_access_idx);
ASSERT_TRUE(sub_idx->params()[1]->IsConstructor());
ASSERT_TRUE(sub_idx->params()[1]->AsConstructor()->IsScalarConstructor());
@ -253,8 +251,8 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Scalar) {
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -295,15 +293,14 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Expr) {
create<ast::UintLiteral>(&u32, 2)),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 3))));
auto* access_ptr = access_idx;
auto* accessor = create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>("a"), std::move(access_idx));
create<ast::IdentifierExpression>("a"), access_idx);
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -322,7 +319,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Expr) {
auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor();
EXPECT_TRUE(tc->type()->IsU32());
ASSERT_EQ(tc->values().size(), 1u);
ASSERT_EQ(tc->values()[0], access_ptr);
ASSERT_EQ(tc->values()[0], access_idx);
ASSERT_TRUE(idx->params()[1]->IsConstructor());
ASSERT_TRUE(idx->params()[1]->AsConstructor()->IsScalarConstructor());
@ -355,8 +352,8 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Negative) {
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -394,8 +391,8 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_OutOfBounds) {
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -433,8 +430,8 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Scalar) {
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -475,15 +472,14 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Expr) {
create<ast::UintLiteral>(&u32, 2)),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 3))));
auto* access_ptr = access_idx;
auto* accessor = create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>("a"), std::move(access_idx));
create<ast::IdentifierExpression>("a"), access_idx);
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -501,7 +497,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Expr) {
auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor();
EXPECT_TRUE(tc->type()->IsU32());
ASSERT_EQ(tc->values().size(), 1u);
ASSERT_EQ(tc->values()[0], access_ptr);
ASSERT_EQ(tc->values()[0], access_idx);
ASSERT_TRUE(idx->params()[1]->IsConstructor());
ASSERT_TRUE(idx->params()[1]->AsConstructor()->IsScalarConstructor());
@ -534,8 +530,8 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Negative) {
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -573,8 +569,8 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_OutOfBounds) {
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -615,8 +611,8 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Scalar) {
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -670,18 +666,17 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Column) {
create<ast::UintLiteral>(&u32, 2)),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 3))));
auto* access_ptr = access_idx;
auto* accessor = create<ast::ArrayAccessorExpression>(
create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>("a"), std::move(access_idx)),
create<ast::IdentifierExpression>("a"), access_idx),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1u)));
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -703,7 +698,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Column) {
auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor();
EXPECT_TRUE(tc->type()->IsU32());
ASSERT_EQ(tc->values().size(), 1u);
ASSERT_EQ(tc->values()[0], access_ptr);
ASSERT_EQ(tc->values()[0], access_idx);
ASSERT_TRUE(idx->params()[1]->IsConstructor());
ASSERT_TRUE(idx->params()[1]->AsConstructor()->IsScalarConstructor());
@ -749,19 +744,18 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Row) {
create<ast::UintLiteral>(&u32, 2)),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 3))));
auto* access_ptr = access_idx;
auto* accessor = create<ast::ArrayAccessorExpression>(
create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>("a"),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1u))),
std::move(access_idx));
access_idx);
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -790,7 +784,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Row) {
auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor();
EXPECT_TRUE(tc->type()->IsU32());
ASSERT_EQ(tc->values().size(), 1u);
ASSERT_EQ(tc->values()[0], access_ptr);
ASSERT_EQ(tc->values()[0], access_idx);
ASSERT_TRUE(idx->params()[1]->IsConstructor());
ASSERT_TRUE(idx->params()[1]->AsConstructor()->IsScalarConstructor());
@ -828,8 +822,8 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Column) {
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -882,8 +876,8 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Row) {
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -937,8 +931,8 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Column) {
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();
@ -992,8 +986,8 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Row) {
auto* ptr = accessor;
auto* b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
b->set_constructor(std::move(accessor));
DeclareVariable(std::move(b));
b->set_constructor(accessor);
DeclareVariable(b);
ASSERT_TRUE(td()->Determine()) << td()->error();

View File

@ -151,7 +151,7 @@ void VertexPullingTransform::FindOrInsertVertexIndexIfUsed() {
create<ast::BuiltinDecoration>(ast::Builtin::kVertexIdx, Source{}));
var->set_decorations(std::move(decorations));
mod_->AddGlobalVariable(std::move(var));
mod_->AddGlobalVariable(var);
}
void VertexPullingTransform::FindOrInsertInstanceIndexIfUsed() {
@ -193,7 +193,7 @@ void VertexPullingTransform::FindOrInsertInstanceIndexIfUsed() {
create<ast::BuiltinDecoration>(ast::Builtin::kInstanceIdx, Source{}));
var->set_decorations(std::move(decorations));
mod_->AddGlobalVariable(std::move(var));
mod_->AddGlobalVariable(var);
}
void VertexPullingTransform::ConvertVertexInputVariablesToPrivate() {
@ -257,7 +257,7 @@ void VertexPullingTransform::AddVertexStorageBuffers() {
decorations.push_back(create<ast::SetDecoration>(pulling_set_, Source{}));
var->set_decorations(std::move(decorations));
mod_->AddGlobalVariable(std::move(var));
mod_->AddGlobalVariable(var);
}
mod_->AddConstructedType(struct_type);
}
@ -278,7 +278,7 @@ void VertexPullingTransform::AddVertexPullingPreamble(
// |kPullingPosVarName| refers to the byte location of the current read. We
// declare a variable in the shader to avoid having to reuse Expression
// objects.
block->append(std::move(pos_declaration));
block->append(pos_declaration);
for (uint32_t i = 0; i < vertex_state_->vertex_buffers.size(); ++i) {
const VertexBufferLayoutDescriptor& buffer_layout =
@ -302,14 +302,14 @@ void VertexPullingTransform::AddVertexPullingPreamble(
auto* pos_value = create<ast::BinaryExpression>(
ast::BinaryOp::kAdd,
create<ast::BinaryExpression>(
ast::BinaryOp::kMultiply, std::move(index_identifier),
ast::BinaryOp::kMultiply, index_identifier,
GenUint(static_cast<uint32_t>(buffer_layout.array_stride))),
GenUint(static_cast<uint32_t>(attribute_desc.offset)));
// Update position of the read
auto* set_pos_expr = create<ast::AssignmentStatement>(
CreatePullingPositionIdent(), std::move(pos_value));
block->append(std::move(set_pos_expr));
CreatePullingPositionIdent(), pos_value);
block->append(set_pos_expr);
block->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(v->name()),
@ -317,7 +317,7 @@ void VertexPullingTransform::AddVertexPullingPreamble(
}
}
vertex_func->body()->insert(0, std::move(block));
vertex_func->body()->insert(0, block);
}
ast::Expression* VertexPullingTransform::GenUint(uint32_t value) {
@ -367,22 +367,19 @@ ast::Expression* VertexPullingTransform::AccessU32(uint32_t buffer,
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(GetVertexBufferName(buffer)),
create<ast::IdentifierExpression>(kStructBufferName)),
create<ast::BinaryExpression>(ast::BinaryOp::kDivide, std::move(pos),
GenUint(4)));
create<ast::BinaryExpression>(ast::BinaryOp::kDivide, pos, GenUint(4)));
}
ast::Expression* VertexPullingTransform::AccessI32(uint32_t buffer,
ast::Expression* pos) {
// as<T> reinterprets bits
return create<ast::BitcastExpression>(GetI32Type(),
AccessU32(buffer, std::move(pos)));
return create<ast::BitcastExpression>(GetI32Type(), AccessU32(buffer, pos));
}
ast::Expression* VertexPullingTransform::AccessF32(uint32_t buffer,
ast::Expression* pos) {
// as<T> reinterprets bits
return create<ast::BitcastExpression>(GetF32Type(),
AccessU32(buffer, std::move(pos)));
return create<ast::BitcastExpression>(GetF32Type(), AccessU32(buffer, pos));
}
ast::Expression* VertexPullingTransform::AccessPrimitive(uint32_t buffer,
@ -394,11 +391,11 @@ ast::Expression* VertexPullingTransform::AccessPrimitive(uint32_t buffer,
// from the position variable.
switch (format) {
case VertexFormat::kU32:
return AccessU32(buffer, std::move(pos));
return AccessU32(buffer, pos);
case VertexFormat::kI32:
return AccessI32(buffer, std::move(pos));
return AccessI32(buffer, pos);
case VertexFormat::kF32:
return AccessF32(buffer, std::move(pos));
return AccessF32(buffer, pos);
default:
return nullptr;
}
@ -415,8 +412,7 @@ ast::Expression* VertexPullingTransform::AccessVec(uint32_t buffer,
auto* cur_pos = create<ast::BinaryExpression>(ast::BinaryOp::kAdd,
CreatePullingPositionIdent(),
GenUint(element_stride * i));
expr_list.push_back(
AccessPrimitive(buffer, std::move(cur_pos), base_format));
expr_list.push_back(AccessPrimitive(buffer, cur_pos, base_format));
}
return create<ast::TypeConstructorExpression>(
@ -443,8 +439,8 @@ VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor(
uint64_t in_array_stride,
InputStepMode in_step_mode,
std::vector<VertexAttributeDescriptor> in_attributes)
: array_stride(std::move(in_array_stride)),
step_mode(std::move(in_step_mode)),
: array_stride(in_array_stride),
step_mode(in_step_mode),
attributes(std::move(in_attributes)) {}
VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor(

View File

@ -47,7 +47,7 @@ class VertexPullingTransformHelper {
create<ast::BlockStatement>());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
}
// Set up the transformation, after building the module
@ -58,7 +58,7 @@ class VertexPullingTransformHelper {
EXPECT_TRUE(td.Determine());
transform_->SetVertexState(
std::make_unique<VertexStateDescriptor>(std::move(vertex_state)));
std::make_unique<VertexStateDescriptor>(vertex_state));
transform_->SetEntryPoint("main");
}
@ -72,8 +72,8 @@ class VertexPullingTransformHelper {
ast::VariableDecorationList decorations;
decorations.push_back(create<ast::LocationDecoration>(location, Source{}));
var->set_decorations(std::move(decorations));
mod_->AddGlobalVariable(std::move(var));
var->set_decorations(decorations);
mod_->AddGlobalVariable(var);
}
Context* ctx() { return &ctx_; }
@ -125,7 +125,7 @@ TEST_F(VertexPullingTransformTest, Error_EntryPointWrongStage) {
create<ast::BlockStatement>());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
InitTransform({});
EXPECT_FALSE(transform()->Run());
@ -410,8 +410,8 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
decorations.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kVertexIdx, Source{}));
vertex_index_var->set_decorations(std::move(decorations));
mod()->AddGlobalVariable(std::move(vertex_index_var));
vertex_index_var->set_decorations(decorations);
mod()->AddGlobalVariable(vertex_index_var);
}
{
@ -423,8 +423,8 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
decorations.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kInstanceIdx, Source{}));
instance_index_var->set_decorations(std::move(decorations));
mod()->AddGlobalVariable(std::move(instance_index_var));
instance_index_var->set_decorations(decorations);
mod()->AddGlobalVariable(instance_index_var);
}
InitTransform(

File diff suppressed because it is too large Load Diff

View File

@ -52,12 +52,11 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(std::move(default_csl),
std::move(block_default)));
body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(create<ast::SwitchStatement>(std::move(cond), std::move(body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -80,13 +79,13 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
ast::CaseSelectorList csl;
csl.push_back(create<ast::SintLiteral>(&i32, 1));
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(std::move(csl),
create<ast::BlockStatement>()));
body.push_back(
create<ast::CaseStatement>(csl, create<ast::BlockStatement>()));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}},
std::move(cond), std::move(body)));
cond, body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -112,25 +111,23 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
ast::CaseSelectorList default_csl_1;
auto* block_default_1 = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl_1),
std::move(block_default_1)));
switch_body.push_back(
create<ast::CaseStatement>(default_csl_1, block_default_1));
ast::CaseSelectorList csl_case_1;
csl_case_1.push_back(create<ast::SintLiteral>(&i32, 1));
auto* block_case_1 = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(csl_case_1),
std::move(block_case_1)));
switch_body.push_back(create<ast::CaseStatement>(csl_case_1, block_case_1));
ast::CaseSelectorList default_csl_2;
auto* block_default_2 = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl_2),
std::move(block_default_2)));
switch_body.push_back(
create<ast::CaseStatement>(default_csl_2, block_default_2));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}},
std::move(cond),
std::move(switch_body)));
cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -158,18 +155,15 @@ TEST_F(ValidateControlBlockTest,
ast::CaseSelectorList csl;
csl.push_back(create<ast::UintLiteral>(&u32, 1));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, std::move(csl),
create<ast::BlockStatement>()));
Source{Source::Location{12, 34}}, csl, create<ast::BlockStatement>()));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl),
std::move(block_default)));
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(
create<ast::SwitchStatement>(std::move(cond), std::move(switch_body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -197,18 +191,15 @@ TEST_F(ValidateControlBlockTest,
ast::CaseSelectorList csl;
csl.push_back(create<ast::SintLiteral>(&i32, -1));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, std::move(csl),
create<ast::BlockStatement>()));
Source{Source::Location{12, 34}}, csl, create<ast::BlockStatement>()));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl),
std::move(block_default)));
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(
create<ast::SwitchStatement>(std::move(cond), std::move(switch_body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -234,25 +225,22 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::UintLiteral>(&u32, 0));
switch_body.push_back(create<ast::CaseStatement>(
std::move(csl_1), create<ast::BlockStatement>()));
switch_body.push_back(
create<ast::CaseStatement>(csl_1, create<ast::BlockStatement>()));
ast::CaseSelectorList csl_2;
csl_2.push_back(create<ast::UintLiteral>(&u32, 2));
csl_2.push_back(create<ast::UintLiteral>(&u32, 2));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, std::move(csl_2),
create<ast::BlockStatement>()));
Source{Source::Location{12, 34}}, csl_2, create<ast::BlockStatement>()));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl),
std::move(block_default)));
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(
create<ast::SwitchStatement>(std::move(cond), std::move(switch_body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -278,8 +266,8 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::SintLiteral>(&i32, 10));
switch_body.push_back(create<ast::CaseStatement>(
std::move(csl_1), create<ast::BlockStatement>()));
switch_body.push_back(
create<ast::CaseStatement>(csl_1, create<ast::BlockStatement>()));
ast::CaseSelectorList csl_2;
csl_2.push_back(create<ast::SintLiteral>(&i32, 0));
@ -287,18 +275,15 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
csl_2.push_back(create<ast::SintLiteral>(&i32, 2));
csl_2.push_back(create<ast::SintLiteral>(&i32, 10));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, std::move(csl_2),
create<ast::BlockStatement>()));
Source{Source::Location{12, 34}}, csl_2, create<ast::BlockStatement>()));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl),
std::move(block_default)));
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(
create<ast::SwitchStatement>(std::move(cond), std::move(switch_body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -323,12 +308,11 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
block_default->append(
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}));
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(std::move(default_csl),
std::move(block_default)));
body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(create<ast::SwitchStatement>(std::move(cond), std::move(body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@ -353,17 +337,15 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
auto* block_default = create<ast::BlockStatement>();
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
std::move(default_csl),
std::move(block_default)));
default_csl, block_default));
ast::CaseSelectorList case_csl;
case_csl.push_back(create<ast::SintLiteral>(&i32, 5));
auto* block_case = create<ast::BlockStatement>();
body.push_back(
create<ast::CaseStatement>(std::move(case_csl), std::move(block_case)));
body.push_back(create<ast::CaseStatement>(case_csl, block_case));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(create<ast::SwitchStatement>(std::move(cond), std::move(body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_TRUE(v()->ValidateStatements(block)) << v()->error();
@ -388,12 +370,11 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
auto* block_default = create<ast::BlockStatement>();
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
std::move(default_csl),
std::move(block_default)));
default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(create<ast::SwitchStatement>(std::move(cond), std::move(body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, body));
mod()->AddConstructedType(&my_int);

View File

@ -46,13 +46,12 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
ast::VariableList params;
ast::type::VoidType void_type;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "func",
std::move(params), &void_type, std::move(body));
body->append(create<ast::VariableDeclStatement>(var));
auto* func = create<ast::Function>(Source{Source::Location{12, 34}}, "func",
params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod()));
@ -64,12 +63,12 @@ TEST_F(ValidateFunctionTest,
// fn func -> void {}
ast::type::VoidType void_type;
ast::VariableList params;
auto* func = create<ast::Function>(Source{Source::Location{12, 34}}, "func",
std::move(params), &void_type,
create<ast::BlockStatement>());
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "func", params,
&void_type, create<ast::BlockStatement>());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod()));
@ -86,10 +85,10 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
ast::VariableList params;
ast::type::VoidType void_type;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
auto* func = create<ast::Function>(Source{Source::Location{12, 34}}, "func",
std::move(params), &i32, std::move(body));
mod()->AddFunction(std::move(func));
params, &i32, body);
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
@ -103,10 +102,10 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
ast::type::VoidType void_type;
ast::type::I32Type i32;
ast::VariableList params;
auto* func = create<ast::Function>(Source{Source::Location{12, 34}}, "func",
std::move(params), &i32,
create<ast::BlockStatement>());
mod()->AddFunction(std::move(func));
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "func", params,
&i32, create<ast::BlockStatement>());
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
@ -123,11 +122,10 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("func", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("func", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->DetermineFunctions(mod()->functions())) << td()->error();
EXPECT_TRUE(v()->ValidateFunctions(mod()->functions())) << v()->error();
@ -143,10 +141,9 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
create<ast::SintLiteral>(&i32, 2));
body->append(create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
std::move(return_expr)));
auto* func = create<ast::Function>("func", std::move(params), &void_type,
std::move(body));
mod()->AddFunction(std::move(func));
return_expr));
auto* func = create<ast::Function>("func", params, &void_type, body);
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
@ -166,10 +163,9 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
create<ast::SintLiteral>(&i32, 2));
body->append(create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
std::move(return_expr)));
auto* func =
create<ast::Function>("func", std::move(params), &f32, std::move(body));
mod()->AddFunction(std::move(func));
return_expr));
auto* func = create<ast::Function>("func", params, &f32, body);
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
@ -190,22 +186,20 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
auto* return_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
body->append(create<ast::ReturnStatement>(std::move(return_expr)));
auto* func =
create<ast::Function>("func", std::move(params), &i32, std::move(body));
body->append(create<ast::ReturnStatement>(return_expr));
auto* func = create<ast::Function>("func", params, &i32, body);
ast::VariableList params_copy;
auto* body_copy = create<ast::BlockStatement>();
auto* return_expr_copy = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
body_copy->append(create<ast::ReturnStatement>(std::move(return_expr_copy)));
auto* func_copy =
create<ast::Function>(Source{Source::Location{12, 34}}, "func",
std::move(params_copy), &i32, std::move(body_copy));
body_copy->append(create<ast::ReturnStatement>(return_expr_copy));
auto* func_copy = create<ast::Function>(Source{Source::Location{12, 34}},
"func", params_copy, &i32, body_copy);
mod()->AddFunction(std::move(func));
mod()->AddFunction(std::move(func_copy));
mod()->AddFunction(func);
mod()->AddFunction(func_copy);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
@ -220,14 +214,13 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
ast::ExpressionList call_params;
auto* call_expr = create<ast::CallExpression>(
Source{Source::Location{12, 34}},
create<ast::IdentifierExpression>("func"), std::move(call_params));
create<ast::IdentifierExpression>("func"), call_params);
ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>();
body0->append(create<ast::CallStatement>(std::move(call_expr)));
body0->append(create<ast::CallStatement>(call_expr));
body0->append(create<ast::ReturnStatement>());
auto* func0 =
create<ast::Function>("func", std::move(params0), &f32, std::move(body0));
mod()->AddFunction(std::move(func0));
auto* func0 = create<ast::Function>("func", params0, &f32, body0);
mod()->AddFunction(func0);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod())) << v()->error();
@ -241,18 +234,17 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
ast::ExpressionList call_params;
auto* call_expr = create<ast::CallExpression>(
Source{Source::Location{12, 34}},
create<ast::IdentifierExpression>("func"), std::move(call_params));
var->set_constructor(std::move(call_expr));
create<ast::IdentifierExpression>("func"), call_params);
var->set_constructor(call_expr);
ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>();
body0->append(create<ast::VariableDeclStatement>(std::move(var)));
body0->append(create<ast::VariableDeclStatement>(var));
auto* return_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
body0->append(create<ast::ReturnStatement>(std::move(return_expr)));
auto* func0 =
create<ast::Function>("func", std::move(params0), &i32, std::move(body0));
mod()->AddFunction(std::move(func0));
body0->append(create<ast::ReturnStatement>(return_expr));
auto* func0 = create<ast::Function>("func", params0, &i32, body0);
mod()->AddFunction(func0);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod())) << v()->error();
@ -268,14 +260,13 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
create<ast::SintLiteral>(&i32, 0));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(std::move(return_expr)));
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "vtx_main",
std::move(params), &i32, std::move(body));
body->append(create<ast::ReturnStatement>(return_expr));
auto* func = create<ast::Function>(Source{Source::Location{12, 34}},
"vtx_main", params, &i32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(v()->error(),
@ -291,13 +282,12 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
params.push_back(create<ast::Variable>("a", ast::StorageClass::kNone, &i32));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "vtx_func",
std::move(params), &void_type, std::move(body));
auto* func = create<ast::Function>(Source{Source::Location{12, 34}},
"vtx_func", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(v()->error(),
@ -313,14 +303,13 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "main",
std::move(params), &void_type, std::move(body));
auto* func = create<ast::Function>(Source{Source::Location{12, 34}}, "main",
params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(
@ -335,11 +324,10 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("vtx_func", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("vtx_func", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod())) << v()->error();
@ -351,9 +339,8 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("vtx_func", std::move(params), &void_type,
std::move(body));
mod()->AddFunction(std::move(func));
auto* func = create<ast::Function>("vtx_func", params, &void_type, body);
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));

View File

@ -271,21 +271,19 @@ bool ValidatorImpl::ValidateSwitch(const ast::SwitchStatement* s) {
}
for (auto* selector : case_stmt->selectors()) {
auto* selector_ptr = selector;
if (cond_type != selector_ptr->type()) {
if (cond_type != selector->type()) {
set_error(case_stmt->source(),
"v-0026: the case selector values must have the same "
"type as the selector expression.");
return false;
}
auto v = static_cast<int32_t>(selector_ptr->type()->IsU32()
? selector_ptr->AsUint()->value()
: selector_ptr->AsSint()->value());
auto v = static_cast<int32_t>(selector->type()->IsU32()
? selector->AsUint()->value()
: selector->AsSint()->value());
if (selector_set.count(v)) {
auto v_str = selector_ptr->type()->IsU32()
? selector_ptr->AsUint()->to_str()
: selector_ptr->AsSint()->to_str();
auto v_str = selector->type()->IsU32() ? selector->AsUint()->to_str()
: selector->AsSint()->to_str();
set_error(case_stmt->source(),
"v-0027: a literal value must not appear more than once in "
"the case selectors for a switch statement: '" +

View File

@ -67,8 +67,7 @@ TEST_F(ValidatorTest, DISABLED_AssignToScalar_Fail) {
auto* lhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1));
auto* rhs = create<ast::IdentifierExpression>("my_var");
ast::AssignmentStatement assign(Source{Source::Location{12, 34}},
std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(Source{Source::Location{12, 34}}, lhs, rhs);
// TODO(sarahM0): Invalidate assignment to scalar.
ASSERT_TRUE(v()->has_error());
@ -85,7 +84,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariable_Fail) {
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs));
Source{Source::Location{12, 34}}, lhs, rhs);
EXPECT_FALSE(td()->DetermineResultType(assign));
EXPECT_EQ(td()->error(),
@ -105,7 +104,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
EXPECT_FALSE(td()->DetermineStatements(body));
EXPECT_EQ(td()->error(),
@ -121,17 +120,14 @@ TEST_F(ValidatorTest, AssignCompatibleTypes_Pass) {
create<ast::SintLiteral>(&i32, 2)));
auto* lhs = create<ast::IdentifierExpression>("a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
auto* rhs_ptr = rhs;
ast::AssignmentStatement assign(Source{Source::Location{12, 34}},
std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(Source{Source::Location{12, 34}}, lhs, rhs);
td()->RegisterVariableForTesting(var);
EXPECT_TRUE(td()->DetermineResultType(&assign)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_TRUE(v()->ValidateResultTypes(&assign));
}
@ -147,17 +143,14 @@ TEST_F(ValidatorTest, AssignIncompatibleTypes_Fail) {
var->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)));
auto* lhs = create<ast::IdentifierExpression>("a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.3f));
auto* rhs_ptr = rhs;
ast::AssignmentStatement assign(Source{Source::Location{12, 34}},
std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(Source{Source::Location{12, 34}}, lhs, rhs);
td()->RegisterVariableForTesting(var);
EXPECT_TRUE(td()->DetermineResultType(&assign)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_FALSE(v()->ValidateResultTypes(&assign));
ASSERT_TRUE(v()->has_error());
@ -177,19 +170,17 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
create<ast::SintLiteral>(&i32, 2)));
auto* lhs = create<ast::IdentifierExpression>("a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
auto* rhs_ptr = rhs;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_TRUE(v()->ValidateStatements(body)) << v()->error();
}
@ -206,19 +197,17 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
var->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)));
auto* lhs = create<ast::IdentifierExpression>("a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.3f));
auto* rhs_ptr = rhs;
ast::BlockStatement block;
block.append(create<ast::VariableDeclStatement>(std::move(var)));
block.append(create<ast::VariableDeclStatement>(var));
block.append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
EXPECT_TRUE(td()->DetermineStatements(&block)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_FALSE(v()->ValidateStatements(&block));
ASSERT_TRUE(v()->has_error());
@ -233,7 +222,7 @@ TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
auto* global_var =
create<ast::Variable>(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kInput, &f32);
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
EXPECT_TRUE(v()->ValidateGlobalVariables(mod()->global_variables()))
<< v()->error();
}
@ -244,7 +233,7 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
auto* global_var =
create<ast::Variable>(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kNone, &f32);
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(v()->error(),
@ -258,7 +247,7 @@ TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
ast::StorageClass::kInput, &f32);
global_var->set_is_const(true);
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(
@ -274,7 +263,7 @@ TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) {
ast::StorageClass::kNone, &f32);
global_var->set_is_const(true);
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod())) << v()->error();
}
@ -289,7 +278,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
create<ast::Variable>("global_var", ast::StorageClass::kPrivate, &f32);
global_var->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.1)));
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
auto* lhs = create<ast::IdentifierExpression>(
Source{Source::Location{12, 34}}, "not_global_var");
@ -299,11 +288,10 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
auto* func = create<ast::Function>("my_func", std::move(params), &f32,
std::move(body));
mod()->AddFunction(std::move(func));
auto* func = create<ast::Function>("my_func", params, &f32, body);
mod()->AddFunction(func);
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(v()->error(), "12:34: v-0006: 'not_global_var' is not declared");
@ -322,7 +310,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
create<ast::Variable>("global_var", ast::StorageClass::kPrivate, &f32);
global_var->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.1)));
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
auto* lhs = create<ast::IdentifierExpression>("global_var");
auto* rhs = create<ast::ScalarConstructorExpression>(
@ -332,13 +320,12 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("my_func", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("my_func", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod())) << v()->error();
@ -358,24 +345,21 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
auto* lhs =
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.14f));
auto* rhs_ptr = rhs;
auto* outer_body = create<ast::BlockStatement>();
outer_body->append(
create<ast::IfStatement>(std::move(cond), std::move(body)));
outer_body->append(create<ast::IfStatement>(cond, body));
outer_body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_FALSE(v()->ValidateStatements(outer_body));
EXPECT_EQ(v()->error(), "12:34: v-0006: 'a' is not declared");
}
@ -392,24 +376,22 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
auto* lhs =
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.14f));
auto* rhs_ptr = rhs;
ast::type::BoolType bool_type;
auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
auto* outer_body = create<ast::BlockStatement>();
outer_body->append(create<ast::VariableDeclStatement>(std::move(var)));
outer_body->append(
create<ast::IfStatement>(std::move(cond), std::move(body)));
outer_body->append(create<ast::VariableDeclStatement>(var));
outer_body->append(create<ast::IfStatement>(cond, body));
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_TRUE(v()->ValidateStatements(outer_body)) << v()->error();
}
@ -422,14 +404,14 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
create<ast::Variable>("global_var0", ast::StorageClass::kPrivate, &f32);
var0->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 0.1)));
mod()->AddGlobalVariable(std::move(var0));
mod()->AddGlobalVariable(var0);
auto* var1 =
create<ast::Variable>(Source{Source::Location{12, 34}}, "global_var1",
ast::StorageClass::kPrivate, &f32);
var1->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 0)));
mod()->AddGlobalVariable(std::move(var1));
mod()->AddGlobalVariable(var1);
EXPECT_TRUE(v()->ValidateGlobalVariables(mod()->global_variables()))
<< v()->error();
@ -444,14 +426,14 @@ TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
create<ast::Variable>("global_var", ast::StorageClass::kPrivate, &f32);
var0->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 0.1)));
mod()->AddGlobalVariable(std::move(var0));
mod()->AddGlobalVariable(var0);
auto* var1 =
create<ast::Variable>(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kPrivate, &f32);
var1->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 0)));
mod()->AddGlobalVariable(std::move(var1));
mod()->AddGlobalVariable(var1);
EXPECT_FALSE(v()->ValidateGlobalVariables(mod()->global_variables()));
EXPECT_EQ(v()->error(),
@ -470,19 +452,17 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
var->set_is_const(true);
auto* lhs = create<ast::IdentifierExpression>("a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
auto* rhs_ptr = rhs;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_FALSE(v()->ValidateStatements(body));
EXPECT_EQ(v()->error(), "12:34: v-0021: cannot re-assign a constant: 'a'");
@ -501,7 +481,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
create<ast::Variable>("a", ast::StorageClass::kPrivate, &f32);
global_var->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.1)));
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
var->set_constructor(create<ast::ScalarConstructorExpression>(
@ -509,14 +489,13 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, std::move(var)));
auto* func = create<ast::Function>("my_func", std::move(params), &void_type,
std::move(body));
auto* func_ptr = func;
mod()->AddFunction(std::move(func));
Source{Source::Location{12, 34}}, var));
auto* func = create<ast::Function>("my_func", params, &void_type, body);
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(td()->DetermineFunction(func_ptr)) << td()->error();
EXPECT_TRUE(td()->DetermineFunction(func)) << td()->error();
EXPECT_FALSE(v()->Validate(mod())) << v()->error();
EXPECT_EQ(v()->error(), "12:34: v-0013: redeclared identifier 'a'");
}
@ -540,16 +519,15 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, std::move(var_a_float)));
auto* func = create<ast::Function>("my_func", std::move(params), &void_type,
std::move(body));
auto* func_ptr = func;
mod()->AddFunction(std::move(func));
Source{Source::Location{12, 34}}, var_a_float));
auto* func = create<ast::Function>("my_func", params, &void_type, body);
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(td()->DetermineFunction(func_ptr)) << td()->error();
EXPECT_TRUE(td()->DetermineFunction(func)) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(v()->error(), "12:34: v-0014: redeclared identifier 'a'");
}
@ -568,7 +546,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
auto* var_a_float =
create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
@ -576,10 +554,9 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
create<ast::FloatLiteral>(&f32, 3.14)));
auto* outer_body = create<ast::BlockStatement>();
outer_body->append(
create<ast::IfStatement>(std::move(cond), std::move(body)));
outer_body->append(create<ast::IfStatement>(cond, body));
outer_body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, std::move(var_a_float)));
Source{Source::Location{12, 34}}, var_a_float));
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
EXPECT_TRUE(v()->ValidateStatements(outer_body)) << v()->error();
@ -607,13 +584,11 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
create<ast::BoolLiteral>(&bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, std::move(var)));
Source{Source::Location{12, 34}}, var));
auto* outer_body = create<ast::BlockStatement>();
outer_body->append(
create<ast::VariableDeclStatement>(std::move(var_a_float)));
outer_body->append(
create<ast::IfStatement>(std::move(cond), std::move(body)));
outer_body->append(create<ast::VariableDeclStatement>(var_a_float));
outer_body->append(create<ast::IfStatement>(cond, body));
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(outer_body));
@ -636,23 +611,21 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>();
body0->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, std::move(var0)));
Source{Source::Location{12, 34}}, var0));
body0->append(create<ast::ReturnStatement>());
auto* func0 = create<ast::Function>("func0", std::move(params0), &void_type,
std::move(body0));
auto* func0 = create<ast::Function>("func0", params0, &void_type, body0);
ast::VariableList params1;
auto* body1 = create<ast::BlockStatement>();
body1->append(create<ast::VariableDeclStatement>(
Source{Source::Location{13, 34}}, std::move(var1)));
Source{Source::Location{13, 34}}, var1));
body1->append(create<ast::ReturnStatement>());
auto* func1 = create<ast::Function>("func1", std::move(params1), &void_type,
std::move(body1));
auto* func1 = create<ast::Function>("func1", params1, &void_type, body1);
func1->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func0));
mod()->AddFunction(std::move(func1));
mod()->AddFunction(func0);
mod()->AddFunction(func1);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod())) << v()->error();
@ -668,19 +641,17 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
td()->RegisterVariableForTesting(var);
auto* lhs = create<ast::IdentifierExpression>("a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
auto* rhs_ptr = rhs;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_TRUE(v()->ValidateStatements(body)) << v()->error();
}

View File

@ -50,18 +50,16 @@ TEST_F(HlslGeneratorImplTest_AliasType, EmitAliasType_Struct) {
ast::type::I32Type i32;
ast::type::F32Type f32;
ast::StructMemberList members;
members.push_back(
create<ast::StructMember>("a", &f32, ast::StructMemberDecorationList{}));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &i32, std::move(b_deco)));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members({
create<ast::StructMember>("a", &f32, ast::StructMemberDecorationList{}),
create<ast::StructMember>(
"b", &i32,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(4, Source{})}),
});
ast::type::StructType s("A", std::move(str));
ast::type::StructType s("A", str);
ast::type::AliasType alias("B", &s);
ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error();

View File

@ -32,10 +32,10 @@ using HlslGeneratorImplTest_Expression = TestHelper;
TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) {
ast::type::I32Type i32;
auto* lit = create<ast::SintLiteral>(&i32, 5);
auto* idx = create<ast::ScalarConstructorExpression>(std::move(lit));
auto* idx = create<ast::ScalarConstructorExpression>(lit);
auto* ary = create<ast::IdentifierExpression>("ary");
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));
ast::ArrayAccessorExpression expr(ary, idx);
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "ary[5]");
@ -45,7 +45,7 @@ TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) {
auto* ary = create<ast::IdentifierExpression>("ary");
auto* idx = create<ast::IdentifierExpression>("idx");
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));
ast::ArrayAccessorExpression expr(ary, idx);
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "ary[idx]");

View File

@ -30,7 +30,7 @@ using HlslGeneratorImplTest_Assign = TestHelper;
TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) {
auto* lhs = create<ast::IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs");
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(lhs, rhs);
gen.increment_indent();

View File

@ -57,7 +57,7 @@ TEST_P(HlslBinaryTest, Emit) {
auto* left = create<ast::IdentifierExpression>("left");
auto* right = create<ast::IdentifierExpression>("right");
ast::BinaryExpression expr(params.op, std::move(left), std::move(right));
ast::BinaryExpression expr(params.op, left, right);
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), params.result);
@ -87,8 +87,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Logical_And) {
auto* left = create<ast::IdentifierExpression>("left");
auto* right = create<ast::IdentifierExpression>("right");
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, std::move(left),
std::move(right));
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, left, right);
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp)");
@ -108,10 +107,8 @@ TEST_F(HlslGeneratorImplTest_Binary, Logical_Multi) {
ast::BinaryExpression expr(
ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, std::move(a),
std::move(b)),
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, std::move(c),
std::move(d)));
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, a, b),
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, c, d));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp_0)");
@ -134,8 +131,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Logical_Or) {
auto* left = create<ast::IdentifierExpression>("left");
auto* right = create<ast::IdentifierExpression>("right");
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, std::move(left),
std::move(right));
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, left, right);
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp)");
@ -161,7 +157,7 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
body->append(
create<ast::ReturnStatement>(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3))));
auto* else_stmt = create<ast::ElseStatement>(std::move(body));
auto* else_stmt = create<ast::ElseStatement>(body);
body = create<ast::BlockStatement>();
body->append(
@ -171,11 +167,11 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>("b"),
create<ast::IdentifierExpression>("c")),
std::move(body));
body);
ast::ElseStatementList else_stmts;
else_stmts.push_back(std::move(else_if_stmt));
else_stmts.push_back(std::move(else_stmt));
else_stmts.push_back(else_if_stmt);
else_stmts.push_back(else_stmt);
body = create<ast::BlockStatement>();
body->append(
@ -186,8 +182,8 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,
create<ast::IdentifierExpression>("a"),
create<ast::IdentifierExpression>("b")),
std::move(body));
expr.set_else_statements(std::move(else_stmts));
body);
expr.set_else_statements(else_stmts);
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a;
@ -218,9 +214,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Return_WithLogical) {
ast::ReturnStatement expr(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, std::move(a),
std::move(b)),
std::move(c)));
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, a, b), c));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a;
@ -243,12 +237,10 @@ TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) {
auto* d = create<ast::IdentifierExpression>("d");
ast::AssignmentStatement expr(
std::move(a),
a,
create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd,
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, std::move(b),
std::move(c)),
std::move(d)));
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, b, c), d));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = b;
@ -275,11 +267,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) {
create<ast::Variable>("a", ast::StorageClass::kFunction, &bool_type);
var->set_constructor(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, std::move(b),
std::move(c)),
std::move(d)));
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, b, c), d));
ast::VariableDeclStatement expr(std::move(var));
ast::VariableDeclStatement expr(var);
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = b;
@ -302,11 +292,10 @@ TEST_F(HlslGeneratorImplTest_Binary, Bitcast_WithLogical) {
auto* b = create<ast::IdentifierExpression>("b");
auto* c = create<ast::IdentifierExpression>("c");
ast::BitcastExpression expr(
&i32, create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, std::move(a),
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
std::move(b), std::move(c))));
ast::BitcastExpression expr(&i32, create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, a,
create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr, b, c)));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = a;
@ -328,7 +317,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
auto* func = create<ast::Function>("foo", ast::VariableList{}, &void_type,
create<ast::BlockStatement>());
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ast::ExpressionList params;
params.push_back(create<ast::BinaryExpression>(
@ -347,7 +336,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
create<ast::IdentifierExpression>("d"))));
ast::CallStatement expr(create<ast::CallExpression>(
create<ast::IdentifierExpression>("foo"), std::move(params)));
create<ast::IdentifierExpression>("foo"), params));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a;

View File

@ -32,7 +32,7 @@ using HlslGeneratorImplTest_Bitcast = TestHelper;
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
ast::type::F32Type f32;
auto* id = create<ast::IdentifierExpression>("id");
ast::BitcastExpression bitcast(&f32, std::move(id));
ast::BitcastExpression bitcast(&f32, id);
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
EXPECT_EQ(result(), "asfloat(id)");
@ -41,7 +41,7 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
ast::type::I32Type i32;
auto* id = create<ast::IdentifierExpression>("id");
ast::BitcastExpression bitcast(&i32, std::move(id));
ast::BitcastExpression bitcast(&i32, id);
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
EXPECT_EQ(result(), "asint(id)");
@ -50,7 +50,7 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
ast::type::U32Type u32;
auto* id = create<ast::IdentifierExpression>("id");
ast::BitcastExpression bitcast(&u32, std::move(id));
ast::BitcastExpression bitcast(&u32, id);
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
EXPECT_EQ(result(), "asuint(id)");

View File

@ -33,11 +33,11 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
ast::type::VoidType void_type;
auto* id = create<ast::IdentifierExpression>("my_func");
ast::CallExpression call(std::move(id), {});
ast::CallExpression call(id, {});
auto* func = create<ast::Function>("my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>());
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
EXPECT_EQ(result(), "my_func()");
@ -50,11 +50,11 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("param1"));
params.push_back(create<ast::IdentifierExpression>("param2"));
ast::CallExpression call(std::move(id), std::move(params));
ast::CallExpression call(id, params);
auto* func = create<ast::Function>("my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>());
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
EXPECT_EQ(result(), "my_func(param1, param2)");
@ -67,12 +67,11 @@ TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("param1"));
params.push_back(create<ast::IdentifierExpression>("param2"));
ast::CallStatement call(
create<ast::CallExpression>(std::move(id), std::move(params)));
ast::CallStatement call(create<ast::CallExpression>(id, params));
auto* func = create<ast::Function>("my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>());
mod.AddFunction(std::move(func));
mod.AddFunction(func);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &call)) << gen.error();
EXPECT_EQ(result(), " my_func(param1, param2);\n");

View File

@ -38,7 +38,7 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case) {
ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(&i32, 5));
ast::CaseStatement c(std::move(lit), std::move(body));
ast::CaseStatement c(lit, body);
gen.increment_indent();
@ -54,7 +54,7 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(&i32, 5));
ast::CaseStatement c(std::move(lit), create<ast::BlockStatement>());
ast::CaseStatement c(lit, create<ast::BlockStatement>());
gen.increment_indent();
@ -73,7 +73,7 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(&i32, 5));
ast::CaseStatement c(std::move(lit), std::move(body));
ast::CaseStatement c(lit, body);
gen.increment_indent();
@ -93,7 +93,7 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(&i32, 5));
lit.push_back(create<ast::SintLiteral>(&i32, 6));
ast::CaseStatement c(std::move(lit), std::move(body));
ast::CaseStatement c(lit, body);
gen.increment_indent();
@ -108,7 +108,7 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::BreakStatement>());
ast::CaseStatement c(std::move(body));
ast::CaseStatement c(body);
gen.increment_indent();

View File

@ -34,7 +34,7 @@ TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Scalar) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("id"));
ast::TypeConstructorExpression cast(&f32, std::move(params));
ast::TypeConstructorExpression cast(&f32, params);
ASSERT_TRUE(gen.EmitExpression(pre, out, &cast)) << gen.error();
EXPECT_EQ(result(), "float(id)");
@ -47,7 +47,7 @@ TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Vector) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("id"));
ast::TypeConstructorExpression cast(&vec3, std::move(params));
ast::TypeConstructorExpression cast(&vec3, params);
ASSERT_TRUE(gen.EmitExpression(pre, out, &cast)) << gen.error();
EXPECT_EQ(result(), "vector<float, 3>(id)");

View File

@ -38,7 +38,7 @@ using HlslGeneratorImplTest_Constructor = TestHelper;
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) {
ast::type::BoolType bool_type;
auto* lit = create<ast::BoolLiteral>(&bool_type, false);
ast::ScalarConstructorExpression expr(std::move(lit));
ast::ScalarConstructorExpression expr(lit);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "false");
@ -47,7 +47,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) {
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) {
ast::type::I32Type i32;
auto* lit = create<ast::SintLiteral>(&i32, -12345);
ast::ScalarConstructorExpression expr(std::move(lit));
ast::ScalarConstructorExpression expr(lit);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "-12345");
@ -56,7 +56,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) {
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_UInt) {
ast::type::U32Type u32;
auto* lit = create<ast::UintLiteral>(&u32, 56779);
ast::ScalarConstructorExpression expr(std::move(lit));
ast::ScalarConstructorExpression expr(lit);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "56779u");
@ -67,7 +67,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Float) {
// Use a number close to 1<<30 but whose decimal representation ends in 0.
auto* lit =
create<ast::FloatLiteral>(&f32, static_cast<float>((1 << 30) - 4));
ast::ScalarConstructorExpression expr(std::move(lit));
ast::ScalarConstructorExpression expr(lit);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "1.07374182e+09f");
@ -78,9 +78,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Float) {
auto* lit = create<ast::FloatLiteral>(&f32, -1.2e-5);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
values.push_back(create<ast::ScalarConstructorExpression>(lit));
ast::TypeConstructorExpression expr(&f32, std::move(values));
ast::TypeConstructorExpression expr(&f32, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "float(-1.20000004e-05f)");
@ -91,9 +91,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Bool) {
auto* lit = create<ast::BoolLiteral>(&b, true);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
values.push_back(create<ast::ScalarConstructorExpression>(lit));
ast::TypeConstructorExpression expr(&b, std::move(values));
ast::TypeConstructorExpression expr(&b, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "bool(true)");
@ -104,9 +104,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Int) {
auto* lit = create<ast::SintLiteral>(&i32, -12345);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
values.push_back(create<ast::ScalarConstructorExpression>(lit));
ast::TypeConstructorExpression expr(&i32, std::move(values));
ast::TypeConstructorExpression expr(&i32, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "int(-12345)");
@ -117,9 +117,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Uint) {
auto* lit = create<ast::UintLiteral>(&u32, 12345);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
values.push_back(create<ast::ScalarConstructorExpression>(lit));
ast::TypeConstructorExpression expr(&u32, std::move(values));
ast::TypeConstructorExpression expr(&u32, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "uint(12345u)");
@ -133,11 +133,11 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec) {
auto* lit2 = create<ast::FloatLiteral>(&f32, 2.f);
auto* lit3 = create<ast::FloatLiteral>(&f32, 3.f);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
ast::TypeConstructorExpression expr(&vec, std::move(values));
ast::TypeConstructorExpression expr(&vec, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(),
@ -149,7 +149,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec_Empty) {
ast::type::VectorType vec(&f32, 3);
ast::ExpressionList values;
ast::TypeConstructorExpression expr(&vec, std::move(values));
ast::TypeConstructorExpression expr(&vec, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "vector<float, 3>(0.0f)");
@ -174,15 +174,14 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) {
create<ast::FloatLiteral>(&f32, static_cast<float>(3 + (i * 2)));
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
mat_values.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(values)));
mat_values.push_back(create<ast::TypeConstructorExpression>(&vec, values));
}
ast::TypeConstructorExpression expr(&mat, std::move(mat_values));
ast::TypeConstructorExpression expr(&mat, mat_values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
@ -210,15 +209,14 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Array) {
create<ast::FloatLiteral>(&f32, static_cast<float>(3 + (i * 3)));
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
ary_values.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(values)));
ary_values.push_back(create<ast::TypeConstructorExpression>(&vec, values));
}
ast::TypeConstructorExpression expr(&ary, std::move(ary_values));
ast::TypeConstructorExpression expr(&ary, ary_values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(),

View File

@ -55,21 +55,17 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
auto* foo_var = create<ast::DecoratedVariable>(
create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations({create<ast::LocationDecoration>(1, Source{})});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -80,18 +76,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("bar")));
auto* func = create<ast::Function>("vtx_main", std::move(params), &f32,
std::move(body));
auto* func = create<ast::Function>("vtx_main", params, &f32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
std::unordered_set<std::string> globals;
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(result(), R"(struct vtx_main_in {
float foo : TEXCOORD0;
int bar : TEXCOORD1;
@ -115,21 +109,17 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
auto* foo_var = create<ast::DecoratedVariable>(
create<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations({create<ast::LocationDecoration>(1, Source{})});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
@ -141,18 +131,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("bar")));
auto* func = create<ast::Function>("vtx_main", std::move(params), &f32,
std::move(body));
auto* func = create<ast::Function>("vtx_main", params, &f32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
std::unordered_set<std::string> globals;
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(result(), R"(struct vtx_main_out {
float foo : TEXCOORD0;
int bar : TEXCOORD1;
@ -176,21 +164,17 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
auto* foo_var = create<ast::DecoratedVariable>(
create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations({create<ast::LocationDecoration>(1, Source{})});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
@ -202,18 +186,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("bar")));
auto* func =
create<ast::Function>("main", std::move(params), &f32, std::move(body));
auto* func = create<ast::Function>("main", params, &f32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
std::unordered_set<std::string> globals;
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(result(), R"(struct main_in {
float foo : TEXCOORD0;
int bar : TEXCOORD1;
@ -237,21 +219,17 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
auto* foo_var = create<ast::DecoratedVariable>(
create<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations({create<ast::LocationDecoration>(1, Source{})});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -262,18 +240,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("bar")));
auto* func =
create<ast::Function>("main", std::move(params), &f32, std::move(body));
auto* func = create<ast::Function>("main", params, &f32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
std::unordered_set<std::string> globals;
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(result(), R"(struct main_out {
float foo : SV_Target0;
int bar : SV_Target1;
@ -297,18 +273,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations(decos);
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations(decos);
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -319,18 +295,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("bar")));
auto* func =
create<ast::Function>("main", std::move(params), &f32, std::move(body));
auto* func = create<ast::Function>("main", params, &f32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
std::unordered_set<std::string> globals;
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_FALSE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
ASSERT_FALSE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)");
}
@ -349,18 +323,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations(decos);
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations(decos);
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -371,18 +345,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("bar")));
auto* func =
create<ast::Function>("main", std::move(params), &f32, std::move(body));
auto* func = create<ast::Function>("main", params, &f32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
std::unordered_set<std::string> globals;
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_FALSE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
ASSERT_FALSE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)");
}
@ -405,23 +377,19 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("coord", ast::StorageClass::kInput, &vec4));
ast::VariableDecorationList decos;
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{})});
auto* depth_var = create<ast::DecoratedVariable>(
create<ast::Variable>("depth", ast::StorageClass::kOutput, &f32));
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{}));
depth_var->set_decorations(std::move(decos));
depth_var->set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{})});
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(std::move(depth_var));
mod.AddGlobalVariable(coord_var);
mod.AddGlobalVariable(depth_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -431,18 +399,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x"))));
auto* func = create<ast::Function>("main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
std::unordered_set<std::string> globals;
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(result(), R"(struct main_in {
vector<float, 4> coord : SV_Position;
};

View File

@ -59,10 +59,10 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("my_func", ast::VariableList{}, &void_type,
std::move(body));
auto* func =
create<ast::Function>("my_func", ast::VariableList{}, &void_type, body);
mod.AddFunction(std::move(func));
mod.AddFunction(func);
gen.increment_indent();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -79,9 +79,9 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("GeometryShader", ast::VariableList{},
&void_type, std::move(body));
&void_type, body);
mod.AddFunction(std::move(func));
mod.AddFunction(func);
gen.increment_indent();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -104,10 +104,9 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("my_func", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("my_func", params, &void_type, body);
mod.AddFunction(std::move(func));
mod.AddFunction(func);
gen.increment_indent();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -125,21 +124,17 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* foo_var = create<ast::DecoratedVariable>(
create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kOutput, &f32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations({create<ast::LocationDecoration>(1, Source{})});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -147,12 +142,11 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("foo")));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -182,22 +176,19 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("coord", ast::StorageClass::kInput, &vec4));
ast::VariableDecorationList decos;
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{})});
auto* depth_var = create<ast::DecoratedVariable>(
create<ast::Variable>("depth", ast::StorageClass::kOutput, &f32));
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{}));
depth_var->set_decorations(std::move(decos));
depth_var->set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{})});
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(std::move(depth_var));
mod.AddGlobalVariable(coord_var);
mod.AddGlobalVariable(depth_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -207,12 +198,11 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x"))));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -245,10 +235,10 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
auto* var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
@ -257,14 +247,13 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::IdentifierExpression>("x")));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -291,9 +280,9 @@ TEST_F(HlslGeneratorImplTest_Function,
"coord", &vec4, ast::StructMemberDecorationList{}));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Uniforms", std::move(str));
ast::type::StructType s("Uniforms", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("uniforms", ast::StorageClass::kUniform, &s));
@ -303,10 +292,10 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
auto* var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
@ -317,14 +306,13 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::IdentifierExpression>("x")));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -351,16 +339,16 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s);
auto* coord_var = create<ast::DecoratedVariable>(
@ -369,10 +357,10 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
auto* var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
@ -381,14 +369,13 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::IdentifierExpression>("b")));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -411,16 +398,16 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
ast::type::AccessControlType ac(ast::AccessControl::kReadOnly, &s);
auto* coord_var = create<ast::DecoratedVariable>(
@ -429,10 +416,10 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
auto* var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
@ -441,14 +428,13 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::IdentifierExpression>("b")));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -471,16 +457,16 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s);
auto* coord_var = create<ast::DecoratedVariable>(
@ -489,11 +475,11 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
auto* assign = create<ast::AssignmentStatement>(
@ -504,14 +490,13 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::FloatLiteral>(&f32, 2.0f)));
auto* body = create<ast::BlockStatement>();
body->append(std::move(assign));
body->append(assign);
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -533,28 +518,23 @@ TEST_F(
auto* foo_var = create<ast::DecoratedVariable>(
create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kOutput, &f32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations({create<ast::LocationDecoration>(1, Source{})});
auto* val_var = create<ast::DecoratedVariable>(
create<ast::Variable>("val", ast::StorageClass::kOutput, &f32));
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
val_var->set_decorations(std::move(decos));
val_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
td.RegisterVariableForTesting(val_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(std::move(val_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
mod.AddGlobalVariable(val_var);
ast::VariableList params;
params.push_back(
@ -569,10 +549,9 @@ TEST_F(
create<ast::IdentifierExpression>("param")));
body->append(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("foo")));
auto* sub_func = create<ast::Function>("sub_func", std::move(params), &f32,
std::move(body));
auto* sub_func = create<ast::Function>("sub_func", params, &f32, body);
mod.AddFunction(std::move(sub_func));
mod.AddFunction(sub_func);
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
@ -582,14 +561,13 @@ TEST_F(
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"),
std::move(expr))));
expr)));
body->append(create<ast::ReturnStatement>());
auto* func_1 = create<ast::Function>("ep_1", std::move(params), &void_type,
std::move(body));
auto* func_1 = create<ast::Function>("ep_1", params, &void_type, body);
func_1->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func_1));
mod.AddFunction(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -629,11 +607,11 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableDecorationList decos;
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{}));
depth_var->set_decorations(std::move(decos));
depth_var->set_decorations(decos);
td.RegisterVariableForTesting(depth_var);
mod.AddGlobalVariable(std::move(depth_var));
mod.AddGlobalVariable(depth_var);
ast::VariableList params;
params.push_back(
@ -642,10 +620,9 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>();
body->append(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("param")));
auto* sub_func = create<ast::Function>("sub_func", std::move(params), &f32,
std::move(body));
auto* sub_func = create<ast::Function>("sub_func", params, &f32, body);
mod.AddFunction(std::move(sub_func));
mod.AddFunction(sub_func);
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
@ -655,14 +632,13 @@ TEST_F(HlslGeneratorImplTest_Function,
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"),
std::move(expr))));
expr)));
body->append(create<ast::ReturnStatement>());
auto* func_1 = create<ast::Function>("ep_1", std::move(params), &void_type,
std::move(body));
auto* func_1 = create<ast::Function>("ep_1", params, &void_type, body);
func_1->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func_1));
mod.AddFunction(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -692,23 +668,19 @@ TEST_F(
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("coord", ast::StorageClass::kInput, &vec4));
ast::VariableDecorationList decos;
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{})});
auto* depth_var = create<ast::DecoratedVariable>(
create<ast::Variable>("depth", ast::StorageClass::kOutput, &f32));
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{}));
depth_var->set_decorations(std::move(decos));
depth_var->set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{})});
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(std::move(depth_var));
mod.AddGlobalVariable(coord_var);
mod.AddGlobalVariable(depth_var);
ast::VariableList params;
params.push_back(
@ -722,10 +694,9 @@ TEST_F(
create<ast::IdentifierExpression>("x"))));
body->append(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("param")));
auto* sub_func = create<ast::Function>("sub_func", std::move(params), &f32,
std::move(body));
auto* sub_func = create<ast::Function>("sub_func", params, &f32, body);
mod.AddFunction(std::move(sub_func));
mod.AddFunction(sub_func);
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
@ -735,14 +706,13 @@ TEST_F(
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"),
std::move(expr))));
expr)));
body->append(create<ast::ReturnStatement>());
auto* func_1 = create<ast::Function>("ep_1", std::move(params), &void_type,
std::move(body));
auto* func_1 = create<ast::Function>("ep_1", params, &void_type, body);
func_1->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func_1));
mod.AddFunction(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -780,11 +750,11 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
params.push_back(
@ -795,10 +765,9 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::ReturnStatement>(create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x"))));
auto* sub_func = create<ast::Function>("sub_func", std::move(params), &f32,
std::move(body));
auto* sub_func = create<ast::Function>("sub_func", params, &f32, body);
mod.AddFunction(std::move(sub_func));
mod.AddFunction(sub_func);
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
@ -806,17 +775,16 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
var->set_constructor(create<ast::CallExpression>(
create<ast::IdentifierExpression>("sub_func"), std::move(expr)));
create<ast::IdentifierExpression>("sub_func"), expr));
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -848,11 +816,11 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
params.push_back(
@ -863,10 +831,9 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::ReturnStatement>(create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x"))));
auto* sub_func = create<ast::Function>("sub_func", std::move(params), &f32,
std::move(body));
auto* sub_func = create<ast::Function>("sub_func", params, &f32, body);
mod.AddFunction(std::move(sub_func));
mod.AddFunction(sub_func);
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
@ -874,17 +841,16 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
var->set_constructor(create<ast::CallExpression>(
create<ast::IdentifierExpression>("sub_func"), std::move(expr)));
create<ast::IdentifierExpression>("sub_func"), expr));
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -912,10 +878,10 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::Variable>("bar", ast::StorageClass::kOutput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations(decos);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -933,15 +899,14 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::SintLiteral>(&i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1))),
std::move(list)));
list));
body->append(create<ast::ReturnStatement>());
auto* func_1 = create<ast::Function>("ep_1", std::move(params), &void_type,
std::move(body));
auto* func_1 = create<ast::Function>("ep_1", params, &void_type, body);
func_1->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func_1));
mod.AddFunction(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -970,7 +935,7 @@ TEST_F(HlslGeneratorImplTest_Function,
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(void GeometryShader_tint_0() {
@ -986,12 +951,11 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -1010,13 +974,12 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
func->add_decoration(create<ast::WorkgroupDecoration>(2u, 4u, 6u, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -1039,10 +1002,9 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("my_func", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("my_func", params, &void_type, body);
mod.AddFunction(std::move(func));
mod.AddFunction(func);
gen.increment_indent();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -1077,14 +1039,14 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("d", &f32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("d", &f32, a_deco));
ast::StructDecorationList s_decos;
s_decos.push_back(create<ast::StructBlockDecoration>(Source{}));
auto* str = create<ast::Struct>(std::move(s_decos), std::move(members));
auto* str = create<ast::Struct>(s_decos, members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s);
auto* data_var = create<ast::DecoratedVariable>(
@ -1093,11 +1055,11 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(0, Source{}));
data_var->set_decorations(std::move(decos));
data_var->set_decorations(decos);
mod.AddConstructedType(&s);
td.RegisterVariableForTesting(data_var);
mod.AddGlobalVariable(std::move(data_var));
mod.AddGlobalVariable(data_var);
{
ast::VariableList params;
@ -1107,14 +1069,13 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::IdentifierExpression>("d")));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("a", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("a", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
}
{
@ -1125,14 +1086,13 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::IdentifierExpression>("d")));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("b", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("b", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
}
ASSERT_TRUE(td.Determine()) << td.error();

View File

@ -31,7 +31,7 @@ TEST_F(HlslGeneratorImplTest_If, Emit_If) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
ast::IfStatement i(std::move(cond), std::move(body));
ast::IfStatement i(cond, body);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &i)) << gen.error();
@ -47,15 +47,14 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
else_body->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses;
elses.push_back(
create<ast::ElseStatement>(std::move(else_cond), std::move(else_body)));
elses.push_back(create<ast::ElseStatement>(else_cond, else_body));
auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
ast::IfStatement i(std::move(cond), std::move(body));
i.set_else_statements(std::move(elses));
ast::IfStatement i(cond, body);
i.set_else_statements(elses);
gen.increment_indent();
@ -75,14 +74,14 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
else_body->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses;
elses.push_back(create<ast::ElseStatement>(std::move(else_body)));
elses.push_back(create<ast::ElseStatement>(else_body));
auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
ast::IfStatement i(std::move(cond), std::move(body));
i.set_else_statements(std::move(elses));
ast::IfStatement i(cond, body);
i.set_else_statements(elses);
gen.increment_indent();
@ -105,16 +104,15 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
else_body_2->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses;
elses.push_back(
create<ast::ElseStatement>(std::move(else_cond), std::move(else_body)));
elses.push_back(create<ast::ElseStatement>(std::move(else_body_2)));
elses.push_back(create<ast::ElseStatement>(else_cond, else_body));
elses.push_back(create<ast::ElseStatement>(else_body_2));
auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
ast::IfStatement i(std::move(cond), std::move(body));
i.set_else_statements(std::move(elses));
ast::IfStatement i(cond, body);
i.set_else_statements(elses);
gen.increment_indent();

View File

@ -58,7 +58,7 @@ TEST_P(HlslImportData_SingleParamTest, FloatScalar) {
create<ast::FloatLiteral>(&f32, 1.f)));
auto* ident = create<ast::IdentifierExpression>(param.name);
ast::CallExpression expr(std::move(ident), std::move(params));
ast::CallExpression expr(ident, params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -103,7 +103,7 @@ TEST_P(HlslImportData_SingleIntParamTest, IntScalar) {
create<ast::SintLiteral>(&i32, 1)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::move(params));
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -126,7 +126,7 @@ TEST_P(HlslImportData_DualParamTest, FloatScalar) {
create<ast::FloatLiteral>(&f32, 2.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::move(params));
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -150,29 +150,29 @@ TEST_P(HlslImportData_DualParam_VectorTest, FloatVector) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
ast::ExpressionList type_params;
type_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
type_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.f)));
type_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.f)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(type_params)));
params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.f)),
}));
type_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 4.f)));
type_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 5.f)));
type_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 6.f)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(type_params)));
params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 4.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 5.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 6.f)),
}));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::move(params));
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -198,7 +198,7 @@ TEST_P(HlslImportData_DualParam_Int_Test, IntScalar) {
create<ast::SintLiteral>(&i32, 2)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::move(params));
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -224,7 +224,7 @@ TEST_P(HlslImportData_TripleParamTest, FloatScalar) {
create<ast::FloatLiteral>(&f32, 3.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::move(params));
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -258,7 +258,7 @@ TEST_P(HlslImportData_TripleParam_Int_Test, IntScalar) {
create<ast::SintLiteral>(&i32, 3)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::move(params));
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -278,9 +278,9 @@ TEST_F(HlslGeneratorImplTest_Import, HlslImportData_Determinant) {
params.push_back(create<ast::IdentifierExpression>("var"));
ast::CallExpression expr(create<ast::IdentifierExpression>("determinant"),
std::move(params));
params);
mod.AddGlobalVariable(std::move(var));
mod.AddGlobalVariable(var);
// Register the global
ASSERT_TRUE(td.Determine()) << td.error();

View File

@ -84,13 +84,13 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, DISABLED_Intrinsic_OuterProduct) {
params.push_back(create<ast::IdentifierExpression>("b"));
ast::CallExpression call(create<ast::IdentifierExpression>("outer_product"),
std::move(params));
params);
td.RegisterVariableForTesting(a);
td.RegisterVariableForTesting(b);
mod.AddGlobalVariable(std::move(a));
mod.AddGlobalVariable(std::move(b));
mod.AddGlobalVariable(a);
mod.AddGlobalVariable(b);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();
@ -112,8 +112,7 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
params.push_back(create<ast::IdentifierExpression>("param1"));
params.push_back(create<ast::IdentifierExpression>("param2"));
ast::CallExpression call(create<ast::IdentifierExpression>("dot"),
std::move(params));
ast::CallExpression call(create<ast::IdentifierExpression>("dot"), params);
ast::Variable v1("param1", ast::StorageClass::kFunction, &vec);
ast::Variable v2("param2", ast::StorageClass::kFunction, &vec);

View File

@ -37,7 +37,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>());
ast::LoopStatement l(std::move(body), {});
ast::LoopStatement l(body, {});
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &l)) << gen.error();
@ -54,7 +54,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::ReturnStatement>());
ast::LoopStatement l(std::move(body), std::move(continuing));
ast::LoopStatement l(body, continuing);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &l)) << gen.error();
@ -81,20 +81,18 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::ReturnStatement>());
auto* inner =
create<ast::LoopStatement>(std::move(body), std::move(continuing));
auto* inner = create<ast::LoopStatement>(body, continuing);
body = create<ast::BlockStatement>();
body->append(std::move(inner));
body->append(inner);
auto* lhs = create<ast::IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs");
continuing = create<ast::BlockStatement>();
continuing->append(
create<ast::AssignmentStatement>(std::move(lhs), std::move(rhs)));
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
ast::LoopStatement outer(std::move(body), std::move(continuing));
ast::LoopStatement outer(body, continuing);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &outer)) << gen.error();
@ -151,7 +149,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
create<ast::FloatLiteral>(&f32, 2.4)));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::VariableDeclStatement>(
create<ast::Variable>("other", ast::StorageClass::kFunction, &f32)));
@ -159,10 +157,9 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
auto* rhs = create<ast::IdentifierExpression>("rhs");
auto* continuing = create<ast::BlockStatement>();
continuing->append(
create<ast::AssignmentStatement>(std::move(lhs), std::move(rhs)));
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
ast::LoopStatement outer(std::move(body), std::move(continuing));
ast::LoopStatement outer(body, continuing);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &outer)) << gen.error();

View File

@ -52,12 +52,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
ast::StructMemberList members;
ast::StructMemberDecorationList deco;
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("mem", &f32, std::move(deco)));
members.push_back(create<ast::StructMember>("mem", &f32, deco));
auto* strct = create<ast::Struct>();
strct->set_members(std::move(members));
strct->set_members(members);
ast::type::StructType s("Str", std::move(strct));
ast::type::StructType s("Str", strct);
auto* str_var = create<ast::DecoratedVariable>(
create<ast::Variable>("str", ast::StorageClass::kPrivate, &s));
@ -65,11 +65,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
auto* str = create<ast::IdentifierExpression>("str");
auto* mem = create<ast::IdentifierExpression>("mem");
ast::MemberAccessorExpression expr(std::move(str), std::move(mem));
ast::MemberAccessorExpression expr(str, mem);
td.RegisterVariableForTesting(str_var);
gen.register_global(str_var);
mod.AddGlobalVariable(std::move(str_var));
mod.AddGlobalVariable(str_var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -92,16 +92,16 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
@ -111,7 +111,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&expr));
@ -136,16 +136,16 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
@ -155,7 +155,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&expr));
@ -180,19 +180,19 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::type::I32Type i32;
ast::type::MatrixType mat(&f32, 3, 2);
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("z", &i32, std::move(a_deco)));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("a", &mat, std::move(b_deco)));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members({
create<ast::StructMember>(
"z", &i32,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})}),
create<ast::StructMember>(
"a", &mat,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(4, Source{})}),
});
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* b_var = create<ast::Variable>("b", ast::StorageClass::kPrivate, &mat);
@ -204,14 +204,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
create<ast::IdentifierExpression>("a"));
auto* rhs = create<ast::IdentifierExpression>("b");
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(lhs, rhs);
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(b_var);
gen.register_global(coord_var);
gen.register_global(b_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(std::move(b_var));
mod.AddGlobalVariable(coord_var);
mod.AddGlobalVariable(b_var);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&assign));
@ -243,16 +243,16 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("z", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("z", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("a", &mat, std::move(b_deco)));
members.push_back(create<ast::StructMember>("a", &mat, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
@ -263,11 +263,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* rhs =
create<ast::TypeConstructorExpression>(&mat, ast::ExpressionList{});
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(lhs, rhs);
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&assign));
@ -299,16 +299,16 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("z", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("z", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("a", &mat, std::move(b_deco)));
members.push_back(create<ast::StructMember>("a", &mat, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
@ -318,7 +318,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&expr));
@ -350,16 +350,16 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("z", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("z", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("a", &mat, std::move(b_deco)));
members.push_back(create<ast::StructMember>("a", &mat, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
@ -369,7 +369,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&expr));
@ -398,12 +398,12 @@ TEST_F(
ast::StructMemberList members;
ast::StructMemberDecorationList deco;
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &mat, std::move(deco)));
members.push_back(create<ast::StructMember>("a", &mat, deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
@ -413,7 +413,7 @@ TEST_F(
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&expr));
@ -441,16 +441,16 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("z", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("z", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
members.push_back(create<ast::StructMember>("a", &mat, std::move(b_deco)));
members.push_back(create<ast::StructMember>("a", &mat, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
@ -467,7 +467,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&expr));
@ -488,19 +488,17 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::type::F32Type f32;
ast::type::I32Type i32;
ast::type::ArrayType ary(&i32, 5);
ast::ArrayDecorationList decos;
decos.push_back(create<ast::StrideDecoration>(4, Source{}));
ary.set_decorations(std::move(decos));
ary.set_decorations({create<ast::StrideDecoration>(4, Source{})});
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &ary, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &ary, a_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
@ -514,7 +512,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -535,19 +533,17 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::type::F32Type f32;
ast::type::I32Type i32;
ast::type::ArrayType ary(&i32, 5);
ast::ArrayDecorationList decos;
decos.push_back(create<ast::StrideDecoration>(4, Source{}));
ary.set_decorations(std::move(decos));
ary.set_decorations({create<ast::StrideDecoration>(4, Source{})});
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &ary, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &ary, a_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
@ -569,7 +565,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -595,23 +591,23 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
@ -620,7 +616,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
create<ast::IdentifierExpression>("b"));
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0f));
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
@ -641,26 +637,24 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::type::F32Type f32;
ast::type::I32Type i32;
ast::type::ArrayType ary(&i32, 5);
ast::ArrayDecorationList decos;
decos.push_back(create<ast::StrideDecoration>(4, Source{}));
ary.set_decorations(std::move(decos));
ary.set_decorations({create<ast::StrideDecoration>(4, Source{})});
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &ary, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &ary, a_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
@ -672,7 +666,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
create<ast::SintLiteral>(&i32, 2)));
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
@ -697,23 +691,23 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
@ -722,7 +716,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
create<ast::IdentifierExpression>("a"));
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
@ -749,23 +743,23 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &ivec3, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &ivec3, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
members.push_back(create<ast::StructMember>("b", &fvec3, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &fvec3, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
@ -796,23 +790,23 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &ivec3, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &ivec3, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
members.push_back(create<ast::StructMember>("b", &fvec3, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &fvec3, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &s));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
@ -820,16 +814,16 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* lit2 = create<ast::FloatLiteral>(&f32, 2.f);
auto* lit3 = create<ast::FloatLiteral>(&f32, 3.f);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"),
create<ast::IdentifierExpression>("b"));
auto* rhs = create<ast::TypeConstructorExpression>(&fvec3, std::move(values));
auto* rhs = create<ast::TypeConstructorExpression>(&fvec3, values);
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
@ -859,38 +853,39 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::type::VectorType ivec3(&i32, 3);
ast::type::VectorType fvec3(&f32, 3);
ast::StructMemberList members;
ast::StructMemberDecorationList deco;
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &ivec3, std::move(deco)));
deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
members.push_back(create<ast::StructMember>("b", &fvec3, std::move(deco)));
auto* data_str = create<ast::Struct>();
data_str->set_members(std::move(members));
data_str->set_members({
create<ast::StructMember>(
"a", &ivec3,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})}),
create<ast::StructMember>(
"b", &fvec3,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(16, Source{})}),
});
ast::type::StructType data("Data", std::move(data_str));
ast::type::StructType data("Data", data_str);
ast::type::ArrayType ary(&data, 4);
ast::ArrayDecorationList decos;
decos.push_back(create<ast::StrideDecoration>(32, Source{}));
ary.set_decorations(std::move(decos));
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("c", &ary, std::move(deco)));
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
auto* pre_str = create<ast::Struct>();
pre_str->set_members(std::move(members));
pre_str->set_members({
create<ast::StructMember>(
"c", &ary,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})}),
});
ast::type::StructType pre_struct("Pre", std::move(pre_str));
ast::type::StructType pre_struct("Pre", pre_str);
auto* coord_var = create<ast::DecoratedVariable>(create<ast::Variable>(
"data", ast::StorageClass::kStorageBuffer, &pre_struct));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
@ -930,36 +925,38 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList members;
ast::StructMemberDecorationList deco;
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &ivec3, std::move(deco)));
deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
members.push_back(create<ast::StructMember>("b", &fvec3, std::move(deco)));
auto* data_str = create<ast::Struct>();
data_str->set_members(std::move(members));
data_str->set_members({
create<ast::StructMember>(
"a", &ivec3,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})}),
create<ast::StructMember>(
"b", &fvec3,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(16, Source{})}),
});
ast::type::StructType data("Data", std::move(data_str));
ast::type::StructType data("Data", data_str);
ast::type::ArrayType ary(&data, 4);
ast::ArrayDecorationList decos;
decos.push_back(create<ast::StrideDecoration>(32, Source{}));
ary.set_decorations(std::move(decos));
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("c", &ary, std::move(deco)));
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
auto* pre_str = create<ast::Struct>();
pre_str->set_members(std::move(members));
pre_str->set_members({create<ast::StructMember>(
"c", &ary,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
ast::type::StructType pre_struct("Pre", std::move(pre_str));
ast::type::StructType pre_struct("Pre", pre_str);
auto* coord_var = create<ast::DecoratedVariable>(create<ast::Variable>(
"data", ast::StorageClass::kStorageBuffer, &pre_struct));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
@ -1000,38 +997,37 @@ TEST_F(
ast::type::VectorType ivec3(&i32, 3);
ast::type::VectorType fvec3(&f32, 3);
ast::StructMemberList members;
ast::StructMemberDecorationList deco;
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &ivec3, std::move(deco)));
deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
members.push_back(create<ast::StructMember>("b", &fvec3, std::move(deco)));
auto* data_str = create<ast::Struct>();
data_str->set_members(std::move(members));
data_str->set_members({
create<ast::StructMember>(
"a", &ivec3,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})}),
create<ast::StructMember>(
"b", &fvec3,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(16, Source{})}),
});
ast::type::StructType data("Data", std::move(data_str));
ast::type::StructType data("Data", data_str);
ast::type::ArrayType ary(&data, 4);
ast::ArrayDecorationList decos;
decos.push_back(create<ast::StrideDecoration>(32, Source{}));
ary.set_decorations(std::move(decos));
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("c", &ary, std::move(deco)));
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
auto* pre_str = create<ast::Struct>();
pre_str->set_members(std::move(members));
pre_str->set_members({create<ast::StructMember>(
"c", &ary,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
ast::type::StructType pre_struct("Pre", std::move(pre_str));
ast::type::StructType pre_struct("Pre", pre_str);
auto* coord_var = create<ast::DecoratedVariable>(create<ast::Variable>(
"data", ast::StorageClass::kStorageBuffer, &pre_struct));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
@ -1071,38 +1067,37 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::type::VectorType ivec3(&i32, 3);
ast::type::VectorType fvec3(&f32, 3);
ast::StructMemberList members;
ast::StructMemberDecorationList deco;
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &ivec3, std::move(deco)));
deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
members.push_back(create<ast::StructMember>("b", &fvec3, std::move(deco)));
auto* data_str = create<ast::Struct>();
data_str->set_members(std::move(members));
data_str->set_members({
create<ast::StructMember>(
"a", &ivec3,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})}),
create<ast::StructMember>(
"b", &fvec3,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(16, Source{})}),
});
ast::type::StructType data("Data", std::move(data_str));
ast::type::StructType data("Data", data_str);
ast::type::ArrayType ary(&data, 4);
ast::ArrayDecorationList decos;
decos.push_back(create<ast::StrideDecoration>(32, Source{}));
ary.set_decorations(std::move(decos));
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("c", &ary, std::move(deco)));
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
auto* pre_str = create<ast::Struct>();
pre_str->set_members(std::move(members));
pre_str->set_members({create<ast::StructMember>(
"c", &ary,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
ast::type::StructType pre_struct("Pre", std::move(pre_str));
ast::type::StructType pre_struct("Pre", pre_str);
auto* coord_var = create<ast::DecoratedVariable>(create<ast::Variable>(
"data", ast::StorageClass::kStorageBuffer, &pre_struct));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
@ -1143,38 +1138,37 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::type::VectorType ivec3(&i32, 3);
ast::type::VectorType fvec3(&f32, 3);
ast::StructMemberList members;
ast::StructMemberDecorationList deco;
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &ivec3, std::move(deco)));
deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
members.push_back(create<ast::StructMember>("b", &fvec3, std::move(deco)));
auto* data_str = create<ast::Struct>();
data_str->set_members(std::move(members));
data_str->set_members({
create<ast::StructMember>(
"a", &ivec3,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})}),
create<ast::StructMember>(
"b", &fvec3,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(16, Source{})}),
});
ast::type::StructType data("Data", std::move(data_str));
ast::type::StructType data("Data", data_str);
ast::type::ArrayType ary(&data, 4);
ast::ArrayDecorationList decos;
decos.push_back(create<ast::StrideDecoration>(32, Source{}));
ary.set_decorations(std::move(decos));
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("c", &ary, std::move(deco)));
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
auto* pre_str = create<ast::Struct>();
pre_str->set_members(std::move(members));
pre_str->set_members({create<ast::StructMember>(
"c", &ary,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
ast::type::StructType pre_struct("Pre", std::move(pre_str));
ast::type::StructType pre_struct("Pre", pre_str);
auto* coord_var = create<ast::DecoratedVariable>(create<ast::Variable>(
"data", ast::StorageClass::kStorageBuffer, &pre_struct));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
@ -1191,13 +1185,13 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* lit2 = create<ast::FloatLiteral>(&f32, 2.f);
auto* lit3 = create<ast::FloatLiteral>(&f32, 3.f);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
auto* rhs = create<ast::TypeConstructorExpression>(&fvec3, std::move(values));
auto* rhs = create<ast::TypeConstructorExpression>(&fvec3, values);
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
@ -1227,38 +1221,37 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::type::VectorType ivec3(&i32, 3);
ast::type::VectorType fvec3(&f32, 3);
ast::StructMemberList members;
ast::StructMemberDecorationList deco;
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &ivec3, std::move(deco)));
deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
members.push_back(create<ast::StructMember>("b", &fvec3, std::move(deco)));
auto* data_str = create<ast::Struct>();
data_str->set_members(std::move(members));
data_str->set_members({
create<ast::StructMember>(
"a", &ivec3,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})}),
create<ast::StructMember>(
"b", &fvec3,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(16, Source{})}),
});
ast::type::StructType data("Data", std::move(data_str));
ast::type::StructType data("Data", data_str);
ast::type::ArrayType ary(&data, 4);
ast::ArrayDecorationList decos;
decos.push_back(create<ast::StrideDecoration>(32, Source{}));
ary.set_decorations(std::move(decos));
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("c", &ary, std::move(deco)));
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
auto* pre_str = create<ast::Struct>();
pre_str->set_members(std::move(members));
pre_str->set_members({create<ast::StructMember>(
"c", &ary,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
ast::type::StructType pre_struct("Pre", std::move(pre_str));
ast::type::StructType pre_struct("Pre", pre_str);
auto* coord_var = create<ast::DecoratedVariable>(create<ast::Variable>(
"data", ast::StorageClass::kStorageBuffer, &pre_struct));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ASSERT_TRUE(td.Determine()) << td.error();
@ -1276,7 +1269,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&i32, 1.f));
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();

View File

@ -47,8 +47,7 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
auto* var = create<ast::Variable>("pos", ast::StorageClass::kNone, &ary);
var->set_is_const(true);
var->set_constructor(
create<ast::TypeConstructorExpression>(&ary, std::move(exprs)));
var->set_constructor(create<ast::TypeConstructorExpression>(&ary, exprs));
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var)) << gen.error();
EXPECT_EQ(
@ -64,7 +63,7 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant) {
auto* var = create<ast::DecoratedVariable>(
create<ast::Variable>("pos", ast::StorageClass::kNone, &f32));
var->set_decorations(std::move(decos));
var->set_decorations(decos);
var->set_is_const(true);
var->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.0f)));
@ -86,7 +85,7 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant_NoConstructor) {
auto* var = create<ast::DecoratedVariable>(
create<ast::Variable>("pos", ast::StorageClass::kNone, &f32));
var->set_decorations(std::move(decos));
var->set_decorations(decos);
var->set_is_const(true);
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var)) << gen.error();

View File

@ -37,7 +37,7 @@ TEST_F(HlslGeneratorImplTest_Return, Emit_Return) {
TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) {
auto* expr = create<ast::IdentifierExpression>("expr");
ast::ReturnStatement r(std::move(expr));
ast::ReturnStatement r(expr);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &r)) << gen.error();

View File

@ -33,7 +33,7 @@ using HlslGeneratorImplTest_Switch = TestHelper;
TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
auto* def_body = create<ast::BlockStatement>();
def_body->append(create<ast::BreakStatement>());
auto* def = create<ast::CaseStatement>(std::move(def_body));
auto* def = create<ast::CaseStatement>(def_body);
ast::type::I32Type i32;
ast::CaseSelectorList case_val;
@ -42,15 +42,14 @@ TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
auto* case_body = create<ast::BlockStatement>();
case_body->append(create<ast::BreakStatement>());
auto* case_stmt =
create<ast::CaseStatement>(std::move(case_val), std::move(case_body));
auto* case_stmt = create<ast::CaseStatement>(case_val, case_body);
ast::CaseStatementList body;
body.push_back(std::move(case_stmt));
body.push_back(std::move(def));
body.push_back(case_stmt);
body.push_back(def);
auto* cond = create<ast::IdentifierExpression>("cond");
ast::SwitchStatement s(std::move(cond), std::move(body));
ast::SwitchStatement s(cond, body);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &s)) << gen.error();

View File

@ -31,7 +31,7 @@ TEST_F(HlslGeneratorImplTest, Generate) {
ast::type::VoidType void_type;
auto* func = create<ast::Function>("my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>());
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(void my_func() {

View File

@ -179,12 +179,12 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl) {
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("S", std::move(str));
ast::type::StructType s("S", str);
ASSERT_TRUE(gen.EmitStructType(out, &s, "S")) << gen.error();
EXPECT_EQ(result(), R"(struct S {
@ -204,12 +204,12 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) {
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("S", std::move(str));
ast::type::StructType s("S", str);
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
EXPECT_EQ(result(), "S");
@ -223,18 +223,18 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_InjectPadding) {
decos.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
ast::StructMemberList members;
members.push_back(create<ast::StructMember>("a", &i32, std::move(decos)));
members.push_back(create<ast::StructMember>("a", &i32, decos));
decos.push_back(create<ast::StructMemberOffsetDecoration>(32, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("b", &f32, decos));
decos.push_back(create<ast::StructMemberOffsetDecoration>(128, Source{}));
members.push_back(create<ast::StructMember>("c", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("c", &f32, decos));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("S", std::move(str));
ast::type::StructType s("S", str);
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
EXPECT_EQ(result(), R"(struct {
@ -256,13 +256,12 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
"double", &i32, ast::StructMemberDecorationList{}));
ast::StructMemberDecorationList b_deco;
members.push_back(
create<ast::StructMember>("float", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("float", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("S", std::move(str));
ast::type::StructType s("S", str);
ASSERT_TRUE(gen.EmitStructType(out, &s, "S")) << gen.error();
EXPECT_EQ(result(), R"(struct S {
@ -283,14 +282,14 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) {
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
ast::StructDecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>(Source{}));
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
auto* str = create<ast::Struct>(decos, members);
ast::type::StructType s("S", std::move(str));
ast::type::StructType s("S", str);
ASSERT_TRUE(gen.EmitStructType(out, &s, "B")) << gen.error();
EXPECT_EQ(result(), R"(struct B {

View File

@ -38,7 +38,7 @@ TEST_P(HlslUnaryOpTest, Emit) {
auto params = GetParam();
auto* expr = create<ast::IdentifierExpression>("expr");
ast::UnaryOpExpression op(params.op, std::move(expr));
ast::UnaryOpExpression op(params.op, expr);
ASSERT_TRUE(gen.EmitExpression(pre, out, &op)) << gen.error();
EXPECT_EQ(result(), std::string(params.name) + "(expr)");

View File

@ -36,7 +36,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
ast::type::F32Type f32;
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
@ -48,7 +48,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
var->set_is_const(true);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
@ -61,7 +61,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Array) {
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &ary);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
@ -73,7 +73,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
ast::type::F32Type f32;
auto* var = create<ast::Variable>("a", ast::StorageClass::kFunction, &f32);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
@ -84,7 +84,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) {
ast::type::F32Type f32;
auto* var = create<ast::Variable>("a", ast::StorageClass::kPrivate, &f32);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
@ -97,9 +97,9 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
ast::type::F32Type f32;
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
var->set_constructor(std::move(ident));
var->set_constructor(ident);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
EXPECT_EQ(result(), R"(float a = initializer;
)");
@ -111,13 +111,12 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
ast::type::VectorType vec(&f32, 3);
ast::ExpressionList values;
auto* zero_vec =
create<ast::TypeConstructorExpression>(&vec, std::move(values));
auto* zero_vec = create<ast::TypeConstructorExpression>(&vec, values);
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &vec);
var->set_constructor(std::move(zero_vec));
var->set_constructor(zero_vec);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
EXPECT_EQ(result(), R"(vector<float, 3> a = vector<float, 3>(0.0f);
)");
@ -129,13 +128,12 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
ast::type::MatrixType mat(&f32, 3, 2);
ast::ExpressionList values;
auto* zero_mat =
create<ast::TypeConstructorExpression>(&mat, std::move(values));
auto* zero_mat = create<ast::TypeConstructorExpression>(&mat, values);
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &mat);
var->set_constructor(std::move(zero_mat));
var->set_constructor(zero_mat);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
EXPECT_EQ(
result(),

View File

@ -59,12 +59,12 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_Struct) {
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &i32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &i32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("a", std::move(str));
ast::type::StructType s("a", str);
ASSERT_TRUE(gen.EmitConstructedType(&s)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct a {
@ -84,12 +84,12 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_AliasStructIdent) {
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &i32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &i32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("b", std::move(str));
ast::type::StructType s("b", str);
ast::type::AliasType alias("a", &s);
ASSERT_TRUE(gen.EmitConstructedType(&alias)) << gen.error();

View File

@ -34,10 +34,10 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_ArrayAccessor) {
ast::type::I32Type i32;
auto* lit = create<ast::SintLiteral>(&i32, 5);
auto* idx = create<ast::ScalarConstructorExpression>(std::move(lit));
auto* idx = create<ast::ScalarConstructorExpression>(lit);
auto* ary = create<ast::IdentifierExpression>("ary");
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));
ast::ArrayAccessorExpression expr(ary, idx);
ASSERT_TRUE(gen.EmitExpression(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "ary[5]");
@ -47,7 +47,7 @@ TEST_F(MslGeneratorImplTest, EmitArrayAccessor) {
auto* ary = create<ast::IdentifierExpression>("ary");
auto* idx = create<ast::IdentifierExpression>("idx");
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));
ast::ArrayAccessorExpression expr(ary, idx);
ASSERT_TRUE(gen.EmitArrayAccessor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "ary[idx]");

View File

@ -32,7 +32,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Assign) {
auto* lhs = create<ast::IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs");
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(lhs, rhs);
gen.increment_indent();

View File

@ -41,7 +41,7 @@ TEST_P(MslBinaryTest, Emit) {
auto* left = create<ast::IdentifierExpression>("left");
auto* right = create<ast::IdentifierExpression>("right");
ast::BinaryExpression expr(params.op, std::move(left), std::move(right));
ast::BinaryExpression expr(params.op, left, right);
ASSERT_TRUE(gen.EmitExpression(&expr)) << gen.error();
EXPECT_EQ(gen.result(), params.result);

View File

@ -32,7 +32,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) {
ast::type::F32Type f32;
auto* id = create<ast::IdentifierExpression>("id");
ast::BitcastExpression bitcast(&f32, std::move(id));
ast::BitcastExpression bitcast(&f32, id);
ASSERT_TRUE(gen.EmitExpression(&bitcast)) << gen.error();
EXPECT_EQ(gen.result(), "as_type<float>(id)");

View File

@ -35,11 +35,11 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
ast::type::VoidType void_type;
auto* id = create<ast::IdentifierExpression>("my_func");
ast::CallExpression call(std::move(id), {});
ast::CallExpression call(id, {});
auto* func = create<ast::Function>("my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>());
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
EXPECT_EQ(gen.result(), "my_func()");
@ -52,11 +52,11 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("param1"));
params.push_back(create<ast::IdentifierExpression>("param2"));
ast::CallExpression call(std::move(id), std::move(params));
ast::CallExpression call(id, params);
auto* func = create<ast::Function>("my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>());
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
EXPECT_EQ(gen.result(), "my_func(param1, param2)");
@ -69,12 +69,11 @@ TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("param1"));
params.push_back(create<ast::IdentifierExpression>("param2"));
ast::CallStatement call(
create<ast::CallExpression>(std::move(id), std::move(params)));
ast::CallStatement call(create<ast::CallExpression>(id, params));
auto* func = create<ast::Function>("my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>());
mod.AddFunction(std::move(func));
mod.AddFunction(func);
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(&call)) << gen.error();

View File

@ -40,7 +40,7 @@ TEST_F(MslGeneratorImplTest, Emit_Case) {
ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(&i32, 5));
ast::CaseStatement c(std::move(lit), std::move(body));
ast::CaseStatement c(lit, body);
gen.increment_indent();
@ -56,7 +56,7 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(&i32, 5));
ast::CaseStatement c(std::move(lit), create<ast::BlockStatement>());
ast::CaseStatement c(lit, create<ast::BlockStatement>());
gen.increment_indent();
@ -75,7 +75,7 @@ TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(&i32, 5));
ast::CaseStatement c(std::move(lit), std::move(body));
ast::CaseStatement c(lit, body);
gen.increment_indent();
@ -95,7 +95,7 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(&i32, 5));
lit.push_back(create<ast::SintLiteral>(&i32, 6));
ast::CaseStatement c(std::move(lit), std::move(body));
ast::CaseStatement c(lit, body);
gen.increment_indent();
@ -110,7 +110,7 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
TEST_F(MslGeneratorImplTest, Emit_Case_Default) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::BreakStatement>());
ast::CaseStatement c(std::move(body));
ast::CaseStatement c(body);
gen.increment_indent();

View File

@ -36,7 +36,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("id"));
ast::TypeConstructorExpression cast(&f32, std::move(params));
ast::TypeConstructorExpression cast(&f32, params);
ASSERT_TRUE(gen.EmitExpression(&cast)) << gen.error();
EXPECT_EQ(gen.result(), "float(id)");
@ -49,7 +49,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("id"));
ast::TypeConstructorExpression cast(&vec3, std::move(params));
ast::TypeConstructorExpression cast(&vec3, params);
ASSERT_TRUE(gen.EmitExpression(&cast)) << gen.error();
EXPECT_EQ(gen.result(), "float3(id)");

View File

@ -40,7 +40,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitConstructor_Bool) {
ast::type::BoolType bool_type;
auto* lit = create<ast::BoolLiteral>(&bool_type, false);
ast::ScalarConstructorExpression expr(std::move(lit));
ast::ScalarConstructorExpression expr(lit);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "false");
@ -49,7 +49,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Bool) {
TEST_F(MslGeneratorImplTest, EmitConstructor_Int) {
ast::type::I32Type i32;
auto* lit = create<ast::SintLiteral>(&i32, -12345);
ast::ScalarConstructorExpression expr(std::move(lit));
ast::ScalarConstructorExpression expr(lit);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "-12345");
@ -58,7 +58,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Int) {
TEST_F(MslGeneratorImplTest, EmitConstructor_UInt) {
ast::type::U32Type u32;
auto* lit = create<ast::UintLiteral>(&u32, 56779);
ast::ScalarConstructorExpression expr(std::move(lit));
ast::ScalarConstructorExpression expr(lit);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "56779u");
@ -69,7 +69,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Float) {
// Use a number close to 1<<30 but whose decimal representation ends in 0.
auto* lit =
create<ast::FloatLiteral>(&f32, static_cast<float>((1 << 30) - 4));
ast::ScalarConstructorExpression expr(std::move(lit));
ast::ScalarConstructorExpression expr(lit);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "1.07374182e+09f");
@ -80,9 +80,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Float) {
auto* lit = create<ast::FloatLiteral>(&f32, -1.2e-5);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
values.push_back(create<ast::ScalarConstructorExpression>(lit));
ast::TypeConstructorExpression expr(&f32, std::move(values));
ast::TypeConstructorExpression expr(&f32, values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "float(-1.20000004e-05f)");
@ -93,9 +93,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Bool) {
auto* lit = create<ast::BoolLiteral>(&b, true);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
values.push_back(create<ast::ScalarConstructorExpression>(lit));
ast::TypeConstructorExpression expr(&b, std::move(values));
ast::TypeConstructorExpression expr(&b, values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "bool(true)");
@ -106,9 +106,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Int) {
auto* lit = create<ast::SintLiteral>(&i32, -12345);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
values.push_back(create<ast::ScalarConstructorExpression>(lit));
ast::TypeConstructorExpression expr(&i32, std::move(values));
ast::TypeConstructorExpression expr(&i32, values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "int(-12345)");
@ -119,9 +119,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Uint) {
auto* lit = create<ast::UintLiteral>(&u32, 12345);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
values.push_back(create<ast::ScalarConstructorExpression>(lit));
ast::TypeConstructorExpression expr(&u32, std::move(values));
ast::TypeConstructorExpression expr(&u32, values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "uint(12345u)");
@ -135,11 +135,11 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec) {
auto* lit2 = create<ast::FloatLiteral>(&f32, 2.f);
auto* lit3 = create<ast::FloatLiteral>(&f32, 3.f);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
ast::TypeConstructorExpression expr(&vec, std::move(values));
ast::TypeConstructorExpression expr(&vec, values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "float3(1.00000000f, 2.00000000f, 3.00000000f)");
@ -150,7 +150,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec_Empty) {
ast::type::VectorType vec(&f32, 3);
ast::ExpressionList values;
ast::TypeConstructorExpression expr(&vec, std::move(values));
ast::TypeConstructorExpression expr(&vec, values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "float3(0.0f)");
@ -175,15 +175,14 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
create<ast::FloatLiteral>(&f32, static_cast<float>(3 + (i * 2)));
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
mat_values.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(values)));
mat_values.push_back(create<ast::TypeConstructorExpression>(&vec, values));
}
ast::TypeConstructorExpression expr(&mat, std::move(mat_values));
ast::TypeConstructorExpression expr(&mat, mat_values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
// A matrix of type T with n columns and m rows can also be constructed from
@ -210,15 +209,14 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) {
create<ast::FloatLiteral>(&f32, static_cast<float>(3 + (i * 3)));
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
ary_values.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(values)));
ary_values.push_back(create<ast::TypeConstructorExpression>(&vec, values));
}
ast::TypeConstructorExpression expr(&ary, std::move(ary_values));
ast::TypeConstructorExpression expr(&ary, ary_values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(),
std::string("{") +

View File

@ -54,21 +54,17 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
auto* foo_var = create<ast::DecoratedVariable>(
create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations({create<ast::LocationDecoration>(1, Source{})});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -79,17 +75,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("bar")));
auto* func = create<ast::Function>("vtx_main", std::move(params), &f32,
std::move(body));
auto* func = create<ast::Function>("vtx_main", params, &f32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.EmitEntryPointData(func_ptr)) << gen.error();
ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct vtx_main_in {
float foo [[attribute(0)]];
int bar [[attribute(1)]];
@ -112,21 +106,17 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
auto* foo_var = create<ast::DecoratedVariable>(
create<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations({create<ast::LocationDecoration>(1, Source{})});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -137,17 +127,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("bar")));
auto* func = create<ast::Function>("vtx_main", std::move(params), &f32,
std::move(body));
auto* func = create<ast::Function>("vtx_main", params, &f32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.EmitEntryPointData(func_ptr)) << gen.error();
ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct vtx_main_out {
float foo [[user(locn0)]];
int bar [[user(locn1)]];
@ -170,21 +158,17 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
auto* foo_var = create<ast::DecoratedVariable>(
create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations({create<ast::LocationDecoration>(1, Source{})});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -194,17 +178,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("bar")));
auto* func =
create<ast::Function>("main", std::move(params), &f32, std::move(body));
auto* func = create<ast::Function>("main", params, &f32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.EmitEntryPointData(func_ptr)) << gen.error();
ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct main_in {
float foo [[user(locn0)]];
int bar [[user(locn1)]];
@ -227,21 +209,17 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
auto* foo_var = create<ast::DecoratedVariable>(
create<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations({create<ast::LocationDecoration>(1, Source{})});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -252,17 +230,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("bar")));
auto* func =
create<ast::Function>("main", std::move(params), &f32, std::move(body));
auto* func = create<ast::Function>("main", params, &f32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.EmitEntryPointData(func_ptr)) << gen.error();
ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct main_out {
float foo [[color(0)]];
int bar [[color(1)]];
@ -285,18 +261,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations(decos);
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations(decos);
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -307,17 +283,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("bar")));
auto* func =
create<ast::Function>("main", std::move(params), &f32, std::move(body));
auto* func = create<ast::Function>("main", params, &f32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_FALSE(gen.EmitEntryPointData(func_ptr)) << gen.error();
ASSERT_FALSE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)");
}
@ -335,18 +309,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations(decos);
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations(decos);
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -357,17 +331,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
create<ast::IdentifierExpression>("bar"),
create<ast::IdentifierExpression>("bar")));
auto* func =
create<ast::Function>("main", std::move(params), &f32, std::move(body));
auto* func = create<ast::Function>("main", params, &f32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_FALSE(gen.EmitEntryPointData(func_ptr)) << gen.error();
ASSERT_FALSE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)");
}
@ -388,23 +360,19 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("coord", ast::StorageClass::kInput, &vec4));
ast::VariableDecorationList decos;
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{})});
auto* depth_var = create<ast::DecoratedVariable>(
create<ast::Variable>("depth", ast::StorageClass::kOutput, &f32));
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{}));
depth_var->set_decorations(std::move(decos));
depth_var->set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{})});
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(std::move(depth_var));
mod.AddGlobalVariable(coord_var);
mod.AddGlobalVariable(depth_var);
ast::VariableList params;
@ -415,17 +383,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x"))));
auto* func = create<ast::Function>("main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
auto* func_ptr = func;
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.EmitEntryPointData(func_ptr)) << gen.error();
ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct main_out {
float depth [[depth(any)]];
};

View File

@ -62,10 +62,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("my_func", ast::VariableList{}, &void_type,
std::move(body));
auto* func =
create<ast::Function>("my_func", ast::VariableList{}, &void_type, body);
mod.AddFunction(std::move(func));
mod.AddFunction(func);
gen.increment_indent();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -83,10 +83,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("main", ast::VariableList{}, &void_type,
std::move(body));
auto* func =
create<ast::Function>("main", ast::VariableList{}, &void_type, body);
mod.AddFunction(std::move(func));
mod.AddFunction(func);
gen.increment_indent();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -111,10 +111,9 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("my_func", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("my_func", params, &void_type, body);
mod.AddFunction(std::move(func));
mod.AddFunction(func);
gen.increment_indent();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -133,21 +132,17 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
auto* foo_var = create<ast::DecoratedVariable>(
create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kOutput, &f32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations({create<ast::LocationDecoration>(1, Source{})});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -156,12 +151,11 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
create<ast::IdentifierExpression>("foo")));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
@ -193,23 +187,19 @@ TEST_F(MslGeneratorImplTest,
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("coord", ast::StorageClass::kInput, &vec4));
ast::VariableDecorationList decos;
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{})});
auto* depth_var = create<ast::DecoratedVariable>(
create<ast::Variable>("depth", ast::StorageClass::kOutput, &f32));
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{}));
depth_var->set_decorations(std::move(decos));
depth_var->set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{})});
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(std::move(depth_var));
mod.AddGlobalVariable(coord_var);
mod.AddGlobalVariable(depth_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -220,12 +210,11 @@ TEST_F(MslGeneratorImplTest,
create<ast::IdentifierExpression>("x"))));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
@ -256,11 +245,11 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
auto* var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
@ -269,15 +258,14 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
create<ast::IdentifierExpression>("x")));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
@ -301,16 +289,16 @@ TEST_F(MslGeneratorImplTest,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s);
mod.AddConstructedType(&s);
@ -321,11 +309,11 @@ TEST_F(MslGeneratorImplTest,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
auto* var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
@ -334,15 +322,14 @@ TEST_F(MslGeneratorImplTest,
create<ast::IdentifierExpression>("b")));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -370,16 +357,16 @@ TEST_F(MslGeneratorImplTest,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
ast::type::AccessControlType ac(ast::AccessControl::kReadOnly, &s);
mod.AddConstructedType(&s);
@ -390,11 +377,11 @@ TEST_F(MslGeneratorImplTest,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
@ -404,15 +391,14 @@ TEST_F(MslGeneratorImplTest,
create<ast::IdentifierExpression>("b")));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
@ -440,28 +426,23 @@ TEST_F(
auto* foo_var = create<ast::DecoratedVariable>(
create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos));
foo_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
auto* bar_var = create<ast::DecoratedVariable>(
create<ast::Variable>("bar", ast::StorageClass::kOutput, &f32));
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations({create<ast::LocationDecoration>(1, Source{})});
auto* val_var = create<ast::DecoratedVariable>(
create<ast::Variable>("val", ast::StorageClass::kOutput, &f32));
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
val_var->set_decorations(std::move(decos));
val_var->set_decorations({create<ast::LocationDecoration>(0, Source{})});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
td.RegisterVariableForTesting(val_var);
mod.AddGlobalVariable(std::move(foo_var));
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(std::move(val_var));
mod.AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var);
mod.AddGlobalVariable(val_var);
ast::VariableList params;
params.push_back(
@ -476,10 +457,9 @@ TEST_F(
create<ast::IdentifierExpression>("param")));
body->append(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("foo")));
auto* sub_func = create<ast::Function>("sub_func", std::move(params), &f32,
std::move(body));
auto* sub_func = create<ast::Function>("sub_func", params, &f32, body);
mod.AddFunction(std::move(sub_func));
mod.AddFunction(sub_func);
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
@ -489,14 +469,13 @@ TEST_F(
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"),
std::move(expr))));
expr)));
body->append(create<ast::ReturnStatement>());
auto* func_1 = create<ast::Function>("ep_1", std::move(params), &void_type,
std::move(body));
auto* func_1 = create<ast::Function>("ep_1", params, &void_type, body);
func_1->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func_1));
mod.AddFunction(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
@ -539,11 +518,11 @@ TEST_F(MslGeneratorImplTest,
ast::VariableDecorationList decos;
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{}));
depth_var->set_decorations(std::move(decos));
depth_var->set_decorations(decos);
td.RegisterVariableForTesting(depth_var);
mod.AddGlobalVariable(std::move(depth_var));
mod.AddGlobalVariable(depth_var);
ast::VariableList params;
params.push_back(
@ -552,10 +531,9 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>();
body->append(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("param")));
auto* sub_func = create<ast::Function>("sub_func", std::move(params), &f32,
std::move(body));
auto* sub_func = create<ast::Function>("sub_func", params, &f32, body);
mod.AddFunction(std::move(sub_func));
mod.AddFunction(sub_func);
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
@ -565,15 +543,14 @@ TEST_F(MslGeneratorImplTest,
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"),
std::move(expr))));
expr)));
body->append(create<ast::ReturnStatement>());
auto* func_1 = create<ast::Function>("ep_1", std::move(params), &void_type,
std::move(body));
auto* func_1 = create<ast::Function>("ep_1", params, &void_type, body);
func_1->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func_1));
mod.AddFunction(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
@ -606,23 +583,19 @@ TEST_F(
auto* coord_var = create<ast::DecoratedVariable>(
create<ast::Variable>("coord", ast::StorageClass::kInput, &vec4));
ast::VariableDecorationList decos;
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{})});
auto* depth_var = create<ast::DecoratedVariable>(
create<ast::Variable>("depth", ast::StorageClass::kOutput, &f32));
decos.push_back(
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{}));
depth_var->set_decorations(std::move(decos));
depth_var->set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{})});
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(std::move(depth_var));
mod.AddGlobalVariable(coord_var);
mod.AddGlobalVariable(depth_var);
ast::VariableList params;
params.push_back(
@ -636,10 +609,9 @@ TEST_F(
create<ast::IdentifierExpression>("x"))));
body->append(
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("param")));
auto* sub_func = create<ast::Function>("sub_func", std::move(params), &f32,
std::move(body));
auto* sub_func = create<ast::Function>("sub_func", params, &f32, body);
mod.AddFunction(std::move(sub_func));
mod.AddFunction(sub_func);
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
@ -649,14 +621,13 @@ TEST_F(
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"),
std::move(expr))));
expr)));
body->append(create<ast::ReturnStatement>());
auto* func_1 = create<ast::Function>("ep_1", std::move(params), &void_type,
std::move(body));
auto* func_1 = create<ast::Function>("ep_1", params, &void_type, body);
func_1->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func_1));
mod.AddFunction(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -692,11 +663,11 @@ TEST_F(MslGeneratorImplTest,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
params.push_back(
@ -707,10 +678,9 @@ TEST_F(MslGeneratorImplTest,
create<ast::ReturnStatement>(create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("x"))));
auto* sub_func = create<ast::Function>("sub_func", std::move(params), &f32,
std::move(body));
auto* sub_func = create<ast::Function>("sub_func", params, &f32, body);
mod.AddFunction(std::move(sub_func));
mod.AddFunction(sub_func);
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
@ -718,18 +688,17 @@ TEST_F(MslGeneratorImplTest,
auto* var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
var->set_constructor(create<ast::CallExpression>(
create<ast::IdentifierExpression>("sub_func"), std::move(expr)));
create<ast::IdentifierExpression>("sub_func"), expr));
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -756,16 +725,16 @@ TEST_F(MslGeneratorImplTest,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s);
mod.AddConstructedType(&s);
@ -776,10 +745,10 @@ TEST_F(MslGeneratorImplTest,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
params.push_back(
@ -790,10 +759,9 @@ TEST_F(MslGeneratorImplTest,
create<ast::ReturnStatement>(create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("b"))));
auto* sub_func = create<ast::Function>("sub_func", std::move(params), &f32,
std::move(body));
auto* sub_func = create<ast::Function>("sub_func", params, &f32, body);
mod.AddFunction(std::move(sub_func));
mod.AddFunction(sub_func);
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
@ -801,18 +769,17 @@ TEST_F(MslGeneratorImplTest,
auto* var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
var->set_constructor(create<ast::CallExpression>(
create<ast::IdentifierExpression>("sub_func"), std::move(expr)));
create<ast::IdentifierExpression>("sub_func"), expr));
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
@ -845,16 +812,16 @@ TEST_F(MslGeneratorImplTest,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("a", &i32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("a", &i32, a_deco));
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
ast::type::AccessControlType ac(ast::AccessControl::kReadOnly, &s);
mod.AddConstructedType(&s);
@ -865,10 +832,10 @@ TEST_F(MslGeneratorImplTest,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(1, Source{}));
coord_var->set_decorations(std::move(decos));
coord_var->set_decorations(decos);
td.RegisterVariableForTesting(coord_var);
mod.AddGlobalVariable(std::move(coord_var));
mod.AddGlobalVariable(coord_var);
ast::VariableList params;
params.push_back(
@ -879,10 +846,9 @@ TEST_F(MslGeneratorImplTest,
create<ast::ReturnStatement>(create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"),
create<ast::IdentifierExpression>("b"))));
auto* sub_func = create<ast::Function>("sub_func", std::move(params), &f32,
std::move(body));
auto* sub_func = create<ast::Function>("sub_func", params, &f32, body);
mod.AddFunction(std::move(sub_func));
mod.AddFunction(sub_func);
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
@ -890,18 +856,17 @@ TEST_F(MslGeneratorImplTest,
auto* var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
var->set_constructor(create<ast::CallExpression>(
create<ast::IdentifierExpression>("sub_func"), std::move(expr)));
create<ast::IdentifierExpression>("sub_func"), expr));
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("frag_main", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("frag_main", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(td.Determine()) << td.error();
@ -935,10 +900,10 @@ TEST_F(MslGeneratorImplTest,
create<ast::Variable>("bar", ast::StorageClass::kOutput, &f32));
ast::VariableDecorationList decos;
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos));
bar_var->set_decorations(decos);
td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(std::move(bar_var));
mod.AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -956,16 +921,15 @@ TEST_F(MslGeneratorImplTest,
create<ast::SintLiteral>(&i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1))),
std::move(list)));
list));
body->append(create<ast::ReturnStatement>());
auto* func_1 = create<ast::Function>("ep_1", std::move(params), &void_type,
std::move(body));
auto* func_1 = create<ast::Function>("ep_1", params, &void_type, body);
func_1->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod.AddFunction(std::move(func_1));
mod.AddFunction(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -996,7 +960,7 @@ TEST_F(MslGeneratorImplTest,
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
@ -1018,10 +982,9 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("my_func", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("my_func", params, &void_type, body);
mod.AddFunction(std::move(func));
mod.AddFunction(func);
gen.increment_indent();
@ -1059,14 +1022,14 @@ TEST_F(MslGeneratorImplTest,
ast::StructMemberList members;
ast::StructMemberDecorationList a_deco;
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("d", &f32, std::move(a_deco)));
members.push_back(create<ast::StructMember>("d", &f32, a_deco));
ast::StructDecorationList s_decos;
s_decos.push_back(create<ast::StructBlockDecoration>(Source{}));
auto* str = create<ast::Struct>(std::move(s_decos), std::move(members));
auto* str = create<ast::Struct>(s_decos, members);
ast::type::StructType s("Data", std::move(str));
ast::type::StructType s("Data", str);
ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s);
auto* data_var = create<ast::DecoratedVariable>(
@ -1075,12 +1038,12 @@ TEST_F(MslGeneratorImplTest,
ast::VariableDecorationList decos;
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(create<ast::SetDecoration>(0, Source{}));
data_var->set_decorations(std::move(decos));
data_var->set_decorations(decos);
mod.AddConstructedType(&s);
td.RegisterVariableForTesting(data_var);
mod.AddGlobalVariable(std::move(data_var));
mod.AddGlobalVariable(data_var);
{
ast::VariableList params;
@ -1090,15 +1053,14 @@ TEST_F(MslGeneratorImplTest,
create<ast::IdentifierExpression>("d")));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("a", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("a", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
}
{
@ -1109,15 +1071,14 @@ TEST_F(MslGeneratorImplTest,
create<ast::IdentifierExpression>("d")));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("b", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("b", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
}
ASSERT_TRUE(td.Determine()) << td.error();

View File

@ -33,7 +33,7 @@ TEST_F(MslGeneratorImplTest, Emit_If) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
ast::IfStatement i(std::move(cond), std::move(body));
ast::IfStatement i(cond, body);
gen.increment_indent();
@ -50,15 +50,14 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
else_body->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses;
elses.push_back(
create<ast::ElseStatement>(std::move(else_cond), std::move(else_body)));
elses.push_back(create<ast::ElseStatement>(else_cond, else_body));
auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
ast::IfStatement i(std::move(cond), std::move(body));
i.set_else_statements(std::move(elses));
ast::IfStatement i(cond, body);
i.set_else_statements(elses);
gen.increment_indent();
@ -76,14 +75,14 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
else_body->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses;
elses.push_back(create<ast::ElseStatement>(std::move(else_body)));
elses.push_back(create<ast::ElseStatement>(else_body));
auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
ast::IfStatement i(std::move(cond), std::move(body));
i.set_else_statements(std::move(elses));
ast::IfStatement i(cond, body);
i.set_else_statements(elses);
gen.increment_indent();
@ -106,16 +105,15 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
else_body_2->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses;
elses.push_back(
create<ast::ElseStatement>(std::move(else_cond), std::move(else_body)));
elses.push_back(create<ast::ElseStatement>(std::move(else_body_2)));
elses.push_back(create<ast::ElseStatement>(else_cond, else_body));
elses.push_back(create<ast::ElseStatement>(else_body_2));
auto* cond = create<ast::IdentifierExpression>("cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
ast::IfStatement i(std::move(cond), std::move(body));
i.set_else_statements(std::move(elses));
ast::IfStatement i(cond, body);
i.set_else_statements(elses);
gen.increment_indent();

View File

@ -59,14 +59,13 @@ TEST_P(MslImportData_SingleParamTest, FloatScalar) {
create<ast::FloatLiteral>(&f32, 1.f)));
auto* ident = create<ast::IdentifierExpression>(param.name);
auto* ident_ptr = ident;
ast::CallExpression call(std::move(ident), std::move(params));
ast::CallExpression call(ident, params);
// The call type determination will set the intrinsic data for the ident
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();
ASSERT_EQ(gen.generate_builtin_name(ident_ptr),
ASSERT_EQ(gen.generate_builtin_name(ident),
std::string("metal::") + param.msl_name);
}
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
@ -102,8 +101,7 @@ TEST_F(MslGeneratorImplTest, MslImportData_SingleParamTest_IntScalar) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
ast::CallExpression expr(create<ast::IdentifierExpression>("abs"),
std::move(params));
ast::CallExpression expr(create<ast::IdentifierExpression>("abs"), params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -124,7 +122,7 @@ TEST_P(MslImportData_DualParamTest, FloatScalar) {
create<ast::FloatLiteral>(&f32, 2.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::move(params));
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
@ -149,28 +147,30 @@ TEST_P(MslImportData_DualParam_VectorTest, FloatVector) {
ast::type::VectorType vec(&f32, 3);
ast::ExpressionList type_params;
type_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
type_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.f)));
type_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.f)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(type_params)));
params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.f)),
}));
type_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 4.f)));
type_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 5.f)));
type_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 6.f)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(type_params)));
params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 4.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 5.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 6.f)),
}));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::move(params));
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
@ -195,7 +195,7 @@ TEST_P(MslImportData_DualParam_Int_Test, IntScalar) {
create<ast::SintLiteral>(&i32, 2)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::move(params));
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
@ -221,7 +221,7 @@ TEST_P(MslImportData_TripleParamTest, FloatScalar) {
create<ast::FloatLiteral>(&f32, 3.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::move(params));
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
@ -252,7 +252,7 @@ TEST_P(MslImportData_TripleParam_Int_Test, IntScalar) {
create<ast::SintLiteral>(&i32, 3)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::move(params));
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
@ -274,9 +274,9 @@ TEST_F(MslGeneratorImplTest, MslImportData_Determinant) {
params.push_back(create<ast::IdentifierExpression>("var"));
ast::CallExpression expr(create<ast::IdentifierExpression>("determinant"),
std::move(params));
params);
mod.AddGlobalVariable(std::move(var));
mod.AddGlobalVariable(var);
// Register the global
ASSERT_TRUE(td.Determine()) << td.error();

View File

@ -79,13 +79,13 @@ TEST_F(MslGeneratorImplTest, DISABLED_Intrinsic_OuterProduct) {
params.push_back(create<ast::IdentifierExpression>("b"));
ast::CallExpression call(create<ast::IdentifierExpression>("outer_product"),
std::move(params));
params);
td.RegisterVariableForTesting(a);
td.RegisterVariableForTesting(b);
mod.AddGlobalVariable(std::move(a));
mod.AddGlobalVariable(std::move(b));
mod.AddGlobalVariable(a);
mod.AddGlobalVariable(b);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();
@ -107,8 +107,7 @@ TEST_F(MslGeneratorImplTest, Intrinsic_Call) {
params.push_back(create<ast::IdentifierExpression>("param1"));
params.push_back(create<ast::IdentifierExpression>("param2"));
ast::CallExpression call(create<ast::IdentifierExpression>("dot"),
std::move(params));
ast::CallExpression call(create<ast::IdentifierExpression>("dot"), params);
ast::Variable v1("param1", ast::StorageClass::kFunction, &vec);
ast::Variable v2("param2", ast::StorageClass::kFunction, &vec);

View File

@ -39,7 +39,7 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::DiscardStatement>());
ast::LoopStatement l(std::move(body), {});
ast::LoopStatement l(body, {});
gen.increment_indent();
@ -57,7 +57,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::ReturnStatement>());
ast::LoopStatement l(std::move(body), std::move(continuing));
ast::LoopStatement l(body, continuing);
gen.increment_indent();
@ -85,20 +85,18 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::ReturnStatement>());
auto* inner =
create<ast::LoopStatement>(std::move(body), std::move(continuing));
auto* inner = create<ast::LoopStatement>(body, continuing);
body = create<ast::BlockStatement>();
body->append(std::move(inner));
body->append(inner);
auto* lhs = create<ast::IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs");
continuing = create<ast::BlockStatement>();
continuing->append(
create<ast::AssignmentStatement>(std::move(lhs), std::move(rhs)));
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
ast::LoopStatement outer(std::move(body), std::move(continuing));
ast::LoopStatement outer(body, continuing);
gen.increment_indent();
@ -156,7 +154,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
create<ast::FloatLiteral>(&f32, 2.4)));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::VariableDeclStatement>(
create<ast::Variable>("other", ast::StorageClass::kFunction, &f32)));
@ -164,12 +162,11 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
auto* rhs = create<ast::IdentifierExpression>("rhs");
auto* continuing = create<ast::BlockStatement>();
continuing->append(
create<ast::AssignmentStatement>(std::move(lhs), std::move(rhs)));
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
gen.increment_indent();
ast::LoopStatement outer(std::move(body), std::move(continuing));
ast::LoopStatement outer(body, continuing);
ASSERT_TRUE(gen.EmitStatement(&outer)) << gen.error();
EXPECT_EQ(gen.result(), R"( {

View File

@ -32,7 +32,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
auto* str = create<ast::IdentifierExpression>("str");
auto* mem = create<ast::IdentifierExpression>("mem");
ast::MemberAccessorExpression expr(std::move(str), std::move(mem));
ast::MemberAccessorExpression expr(str, mem);
ASSERT_TRUE(gen.EmitExpression(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "str.mem");

View File

@ -49,8 +49,7 @@ TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) {
auto* var = create<ast::Variable>("pos", ast::StorageClass::kNone, &ary);
var->set_is_const(true);
var->set_constructor(
create<ast::TypeConstructorExpression>(&ary, std::move(exprs)));
var->set_constructor(create<ast::TypeConstructorExpression>(&ary, exprs));
ASSERT_TRUE(gen.EmitProgramConstVariable(var)) << gen.error();
EXPECT_EQ(
@ -66,7 +65,7 @@ TEST_F(MslGeneratorImplTest, Emit_SpecConstant) {
auto* var = create<ast::DecoratedVariable>(
create<ast::Variable>("pos", ast::StorageClass::kNone, &f32));
var->set_decorations(std::move(decos));
var->set_decorations(decos);
var->set_is_const(true);
var->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.0f)));

View File

@ -40,7 +40,7 @@ TEST_F(MslGeneratorImplTest, Emit_Return) {
TEST_F(MslGeneratorImplTest, Emit_ReturnWithValue) {
auto* expr = create<ast::IdentifierExpression>("expr");
ast::ReturnStatement r(std::move(expr));
ast::ReturnStatement r(expr);
gen.increment_indent();

View File

@ -35,7 +35,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Switch) {
auto* def_body = create<ast::BlockStatement>();
def_body->append(create<ast::BreakStatement>());
auto* def = create<ast::CaseStatement>(std::move(def_body));
auto* def = create<ast::CaseStatement>(def_body);
ast::type::I32Type i32;
ast::CaseSelectorList case_val;
@ -44,15 +44,14 @@ TEST_F(MslGeneratorImplTest, Emit_Switch) {
auto* case_body = create<ast::BlockStatement>();
case_body->append(create<ast::BreakStatement>());
auto* case_stmt =
create<ast::CaseStatement>(std::move(case_val), std::move(case_body));
auto* case_stmt = create<ast::CaseStatement>(case_val, case_body);
ast::CaseStatementList body;
body.push_back(std::move(case_stmt));
body.push_back(std::move(def));
body.push_back(case_stmt);
body.push_back(def);
auto* cond = create<ast::IdentifierExpression>("cond");
ast::SwitchStatement s(std::move(cond), std::move(body));
ast::SwitchStatement s(cond, body);
gen.increment_indent();

View File

@ -54,7 +54,7 @@ TEST_F(MslGeneratorImplTest, Generate) {
create<ast::BlockStatement>());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
mod.AddFunction(std::move(func));
mod.AddFunction(func);
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
@ -160,18 +160,18 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct) {
decos.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
ast::StructMemberList members;
members.push_back(create<ast::StructMember>("a", &i32, std::move(decos)));
members.push_back(create<ast::StructMember>("a", &i32, decos));
decos.push_back(create<ast::StructMemberOffsetDecoration>(32, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("b", &f32, decos));
decos.push_back(create<ast::StructMemberOffsetDecoration>(128, Source{}));
members.push_back(create<ast::StructMember>("c", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("c", &f32, decos));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("S", std::move(str));
ast::type::StructType s("S", str);
EXPECT_EQ(132u, gen.calculate_alignment_size(&s));
}
@ -185,32 +185,32 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) {
decos.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
ast::StructMemberList members;
members.push_back(create<ast::StructMember>("a", &i32, std::move(decos)));
members.push_back(create<ast::StructMember>("a", &i32, decos));
decos.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
members.push_back(create<ast::StructMember>("b", &fvec, std::move(decos)));
members.push_back(create<ast::StructMember>("b", &fvec, decos));
decos.push_back(create<ast::StructMemberOffsetDecoration>(32, Source{}));
members.push_back(create<ast::StructMember>("c", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("c", &f32, decos));
auto* inner_str = create<ast::Struct>();
inner_str->set_members(std::move(members));
inner_str->set_members(members);
ast::type::StructType inner_s("Inner", std::move(inner_str));
ast::type::StructType inner_s("Inner", inner_str);
decos.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<ast::StructMember>("d", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("d", &f32, decos));
decos.push_back(create<ast::StructMemberOffsetDecoration>(32, Source{}));
members.push_back(create<ast::StructMember>("e", &inner_s, std::move(decos)));
members.push_back(create<ast::StructMember>("e", &inner_s, decos));
decos.push_back(create<ast::StructMemberOffsetDecoration>(64, Source{}));
members.push_back(create<ast::StructMember>("f", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("f", &f32, decos));
auto* outer_str = create<ast::Struct>();
outer_str->set_members(std::move(members));
outer_str->set_members(members);
ast::type::StructType outer_s("Outer", std::move(outer_str));
ast::type::StructType outer_s("Outer", outer_str);
EXPECT_EQ(80u, gen.calculate_alignment_size(&outer_s));
}

View File

@ -181,12 +181,12 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct) {
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("S", std::move(str));
ast::type::StructType s("S", str);
ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error();
EXPECT_EQ(gen.result(), "S");
@ -202,12 +202,12 @@ TEST_F(MslGeneratorImplTest, EmitType_StructDecl) {
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("S", std::move(str));
ast::type::StructType s("S", str);
ASSERT_TRUE(gen.EmitStructType(&s)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct S {
@ -221,22 +221,23 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_InjectPadding) {
ast::type::I32Type i32;
ast::type::F32Type f32;
ast::StructMemberDecorationList decos;
decos.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
ast::StructMemberList members;
members.push_back(create<ast::StructMember>("a", &i32, std::move(decos)));
decos.push_back(create<ast::StructMemberOffsetDecoration>(32, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(decos)));
decos.push_back(create<ast::StructMemberOffsetDecoration>(128, Source{}));
members.push_back(create<ast::StructMember>("c", &f32, std::move(decos)));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members({
create<ast::StructMember>(
"a", &i32,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(4, Source{})}),
create<ast::StructMember>(
"b", &f32,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(32, Source{})}),
create<ast::StructMember>(
"c", &f32,
ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(128, Source{})}),
});
ast::type::StructType s("S", std::move(str));
ast::type::StructType s("S", str);
ASSERT_TRUE(gen.EmitStructType(&s)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct S {
@ -259,13 +260,12 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_NameCollision) {
"main", &i32, ast::StructMemberDecorationList{}));
ast::StructMemberDecorationList b_deco;
members.push_back(
create<ast::StructMember>("float", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("float", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("S", std::move(str));
ast::type::StructType s("S", str);
ASSERT_TRUE(gen.EmitStructType(&s)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct S {
@ -286,13 +286,13 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) {
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
ast::StructDecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>(Source{}));
auto* str = create<ast::Struct>(std::move(decos), std::move(members));
auto* str = create<ast::Struct>(decos, members);
ast::type::StructType s("S", std::move(str));
ast::type::StructType s("S", str);
ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error();
EXPECT_EQ(gen.result(), R"(struct {

View File

@ -40,7 +40,7 @@ TEST_P(MslUnaryOpTest, Emit) {
auto params = GetParam();
auto* expr = create<ast::IdentifierExpression>("expr");
ast::UnaryOpExpression op(params.op, std::move(expr));
ast::UnaryOpExpression op(params.op, expr);
ASSERT_TRUE(gen.EmitExpression(&op)) << gen.error();
EXPECT_EQ(gen.result(), std::string(params.name) + "(expr)");

View File

@ -44,7 +44,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
ast::type::F32Type f32;
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
gen.increment_indent();
@ -57,7 +57,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
var->set_is_const(true);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
gen.increment_indent();
@ -71,7 +71,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &ary);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
gen.increment_indent();
@ -88,16 +88,16 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
auto* str = create<ast::Struct>();
str->set_members(std::move(members));
str->set_members(members);
ast::type::StructType s("S", std::move(str));
ast::type::StructType s("S", str);
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &s);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
gen.increment_indent();
@ -112,7 +112,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
auto* var = create<ast::Variable>("a", ast::StorageClass::kFunction, &vec);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
gen.increment_indent();
@ -125,7 +125,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
ast::type::MatrixType mat(&f32, 2, 3);
auto* var = create<ast::Variable>("a", ast::StorageClass::kFunction, &mat);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
gen.increment_indent();
@ -137,7 +137,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
ast::type::F32Type f32;
auto* var = create<ast::Variable>("a", ast::StorageClass::kPrivate, &f32);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
gen.increment_indent();
@ -150,9 +150,9 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) {
ast::type::F32Type f32;
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
var->set_constructor(std::move(ident));
var->set_constructor(ident);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
EXPECT_EQ(gen.result(), R"(float a = initializer;
@ -164,13 +164,12 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) {
ast::type::VectorType vec(&f32, 3);
ast::ExpressionList values;
auto* zero_vec =
create<ast::TypeConstructorExpression>(&vec, std::move(values));
auto* zero_vec = create<ast::TypeConstructorExpression>(&vec, values);
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &vec);
var->set_constructor(std::move(zero_vec));
var->set_constructor(zero_vec);
ast::VariableDeclStatement stmt(std::move(var));
ast::VariableDeclStatement stmt(var);
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
EXPECT_EQ(gen.result(), R"(float3 a = float3(0.0f);

View File

@ -60,7 +60,7 @@ TEST_F(BuilderTest, ArrayAccessor) {
auto* idx_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1));
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx_expr));
ast::ArrayAccessorExpression expr(ary, idx_expr);
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -101,7 +101,7 @@ TEST_F(BuilderTest, Accessor_Array_LoadIndex) {
auto* ary = create<ast::IdentifierExpression>("ary");
auto* idx_expr = create<ast::IdentifierExpression>("idx");
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx_expr));
ast::ArrayAccessorExpression expr(ary, idx_expr);
td.RegisterVariableForTesting(&var);
td.RegisterVariableForTesting(&idx);
@ -145,7 +145,7 @@ TEST_F(BuilderTest, ArrayAccessor_Dynamic) {
auto* ary = create<ast::IdentifierExpression>("ary");
ast::ArrayAccessorExpression expr(
std::move(ary),
ary,
create<ast::BinaryExpression>(ast::BinaryOp::kAdd,
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
@ -284,11 +284,11 @@ TEST_F(BuilderTest, MemberAccessor) {
ast::StructMemberDecorationList decos;
ast::StructMemberList members;
members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("b", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("a", &f32, decos));
members.push_back(create<ast::StructMember>("b", &f32, decos));
auto* s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("my_struct", std::move(s));
auto* s = create<ast::Struct>(members);
ast::type::StructType s_type("my_struct", s);
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
@ -333,20 +333,17 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
// ident.inner.a
ast::StructMemberDecorationList decos;
ast::StructMemberList inner_members;
inner_members.push_back(
create<ast::StructMember>("a", &f32, std::move(decos)));
inner_members.push_back(
create<ast::StructMember>("b", &f32, std::move(decos)));
inner_members.push_back(create<ast::StructMember>("a", &f32, decos));
inner_members.push_back(create<ast::StructMember>("b", &f32, decos));
ast::type::StructType inner_struct(
"Inner", create<ast::Struct>(std::move(inner_members)));
ast::type::StructType inner_struct("Inner",
create<ast::Struct>(inner_members));
ast::StructMemberList outer_members;
outer_members.push_back(
create<ast::StructMember>("inner", &inner_struct, std::move(decos)));
create<ast::StructMember>("inner", &inner_struct, decos));
ast::type::StructType s_type("my_struct",
create<ast::Struct>(std::move(outer_members)));
ast::type::StructType s_type("my_struct", create<ast::Struct>(outer_members));
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
@ -396,22 +393,18 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
// ident.inner.a
ast::StructMemberDecorationList decos;
ast::StructMemberList inner_members;
inner_members.push_back(
create<ast::StructMember>("a", &f32, std::move(decos)));
inner_members.push_back(
create<ast::StructMember>("b", &f32, std::move(decos)));
inner_members.push_back(create<ast::StructMember>("a", &f32, decos));
inner_members.push_back(create<ast::StructMember>("b", &f32, decos));
ast::type::StructType inner_struct(
"Inner", create<ast::Struct>(std::move(inner_members)));
ast::type::StructType inner_struct("Inner",
create<ast::Struct>(inner_members));
ast::type::AliasType alias("Inner", &inner_struct);
ast::StructMemberList outer_members;
outer_members.push_back(
create<ast::StructMember>("inner", &alias, std::move(decos)));
outer_members.push_back(create<ast::StructMember>("inner", &alias, decos));
ast::type::StructType s_type("Outer",
create<ast::Struct>(std::move(outer_members)));
ast::type::StructType s_type("Outer", create<ast::Struct>(outer_members));
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
@ -461,20 +454,17 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
ast::StructMemberDecorationList decos;
ast::StructMemberList inner_members;
inner_members.push_back(
create<ast::StructMember>("a", &f32, std::move(decos)));
inner_members.push_back(
create<ast::StructMember>("b", &f32, std::move(decos)));
inner_members.push_back(create<ast::StructMember>("a", &f32, decos));
inner_members.push_back(create<ast::StructMember>("b", &f32, decos));
ast::type::StructType inner_struct(
"Inner", create<ast::Struct>(std::move(inner_members)));
ast::type::StructType inner_struct("Inner",
create<ast::Struct>(inner_members));
ast::StructMemberList outer_members;
outer_members.push_back(
create<ast::StructMember>("inner", &inner_struct, std::move(decos)));
create<ast::StructMember>("inner", &inner_struct, decos));
ast::type::StructType s_type("my_struct",
create<ast::Struct>(std::move(outer_members)));
ast::type::StructType s_type("my_struct", create<ast::Struct>(outer_members));
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
@ -487,7 +477,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.f));
ast::AssignmentStatement expr(std::move(lhs), std::move(rhs));
ast::AssignmentStatement expr(lhs, rhs);
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -531,20 +521,17 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
ast::StructMemberDecorationList decos;
ast::StructMemberList inner_members;
inner_members.push_back(
create<ast::StructMember>("a", &f32, std::move(decos)));
inner_members.push_back(
create<ast::StructMember>("b", &f32, std::move(decos)));
inner_members.push_back(create<ast::StructMember>("a", &f32, decos));
inner_members.push_back(create<ast::StructMember>("b", &f32, decos));
ast::type::StructType inner_struct(
"Inner", create<ast::Struct>(std::move(inner_members)));
ast::type::StructType inner_struct("Inner",
create<ast::Struct>(inner_members));
ast::StructMemberList outer_members;
outer_members.push_back(
create<ast::StructMember>("inner", &inner_struct, std::move(decos)));
create<ast::StructMember>("inner", &inner_struct, decos));
ast::type::StructType s_type("my_struct",
create<ast::Struct>(std::move(outer_members)));
ast::type::StructType s_type("my_struct", create<ast::Struct>(outer_members));
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
ast::Variable store("store", ast::StorageClass::kFunction, &f32);
@ -557,7 +544,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
create<ast::IdentifierExpression>("inner")),
create<ast::IdentifierExpression>("a"));
ast::AssignmentStatement expr(std::move(lhs), std::move(rhs));
ast::AssignmentStatement expr(lhs, rhs);
td.RegisterVariableForTesting(&var);
td.RegisterVariableForTesting(&store);
@ -793,22 +780,20 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
// index[0].foo[2].bar.baz.yx
ast::StructMemberDecorationList decos;
ast::StructMemberList members;
members.push_back(create<ast::StructMember>("baz", &vec3, std::move(decos)));
auto* s = create<ast::Struct>(std::move(members));
ast::type::StructType c_type("C", std::move(s));
members.push_back(
create<ast::StructMember>("bar", &c_type, std::move(decos)));
s = create<ast::Struct>(std::move(members));
ast::type::StructType b_type("B", std::move(s));
auto* s = create<ast::Struct>(
ast::StructMemberList{create<ast::StructMember>("baz", &vec3, decos)});
ast::type::StructType c_type("C", s);
s = create<ast::Struct>(
ast::StructMemberList{create<ast::StructMember>("bar", &c_type, decos)});
ast::type::StructType b_type("B", s);
ast::type::ArrayType b_ary_type(&b_type, 3);
members.push_back(
create<ast::StructMember>("foo", &b_ary_type, std::move(decos)));
s = create<ast::Struct>(std::move(members));
ast::type::StructType a_type("A", std::move(s));
s = create<ast::Struct>(ast::StructMemberList{
create<ast::StructMember>("foo", &b_ary_type, decos)});
ast::type::StructType a_type("A", s);
ast::type::ArrayType a_ary_type(&a_type, 2);
@ -880,33 +865,33 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) {
ast::type::ArrayType arr(&vec, 3);
ast::ExpressionList ary_params;
ary_params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 0.0)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 0.5)),
}));
ast::ExpressionList vec_params;
vec_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 0.0)));
vec_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 0.5)));
ary_params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
ary_params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, -0.5)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, -0.5)),
}));
vec_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, -0.5)));
vec_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, -0.5)));
ary_params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
vec_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 0.5)));
vec_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, -0.5)));
ary_params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
ary_params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 0.5)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, -0.5)),
}));
ast::Variable var("pos", ast::StorageClass::kPrivate, &arr);
var.set_is_const(true);
var.set_constructor(
create<ast::TypeConstructorExpression>(&arr, std::move(ary_params)));
var.set_constructor(create<ast::TypeConstructorExpression>(&arr, ary_params));
ast::ArrayAccessorExpression expr(create<ast::IdentifierExpression>("pos"),
create<ast::ScalarConstructorExpression>(

View File

@ -51,7 +51,7 @@ TEST_F(BuilderTest, Assign_Var) {
auto* val = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f));
ast::AssignmentStatement assign(std::move(ident), std::move(val));
ast::AssignmentStatement assign(ident, val);
td.RegisterVariableForTesting(&v);
@ -83,9 +83,9 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
auto* ident = create<ast::IdentifierExpression>("var");
ast::ExpressionList vals;
auto* val = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
auto* val = create<ast::TypeConstructorExpression>(&vec, vals);
ast::AssignmentStatement assign(std::move(ident), std::move(val));
ast::AssignmentStatement assign(ident, val);
td.RegisterVariableForTesting(&v);
@ -114,23 +114,25 @@ TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
ast::type::VectorType vec3(&f32, 3);
ast::type::VectorType vec2(&f32, 2);
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0f)));
auto* first = create<ast::TypeConstructorExpression>(&vec2, std::move(vals));
auto* first = create<ast::TypeConstructorExpression>(
&vec2, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0f)),
});
vals.push_back(std::move(first));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.0f)));
auto* init = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* init = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
first,
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.0f)),
});
ast::Variable v("var", ast::StorageClass::kOutput, &vec3);
ast::AssignmentStatement assign(create<ast::IdentifierExpression>("var"),
std::move(init));
init);
td.RegisterVariableForTesting(&v);
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
@ -173,12 +175,12 @@ TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.0f)));
auto* init = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* init = create<ast::TypeConstructorExpression>(&vec3, vals);
ast::Variable v("var", ast::StorageClass::kOutput, &vec3);
ast::AssignmentStatement assign(create<ast::IdentifierExpression>("var"),
std::move(init));
init);
td.RegisterVariableForTesting(&v);
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
@ -216,11 +218,11 @@ TEST_F(BuilderTest, Assign_StructMember) {
ast::StructMemberDecorationList decos;
ast::StructMemberList members;
members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("b", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("a", &f32, decos));
members.push_back(create<ast::StructMember>("b", &f32, decos));
auto* s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("my_struct", std::move(s));
auto* s = create<ast::Struct>(members);
ast::type::StructType s_type("my_struct", s);
ast::Variable v("ident", ast::StorageClass::kFunction, &s_type);
@ -231,7 +233,7 @@ TEST_F(BuilderTest, Assign_StructMember) {
auto* val = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 4.0f));
ast::AssignmentStatement assign(std::move(ident), std::move(val));
ast::AssignmentStatement assign(ident, val);
td.RegisterVariableForTesting(&v);
@ -276,9 +278,9 @@ TEST_F(BuilderTest, Assign_Vector) {
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.0f)));
auto* val = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* val = create<ast::TypeConstructorExpression>(&vec3, vals);
ast::AssignmentStatement assign(std::move(ident), std::move(val));
ast::AssignmentStatement assign(ident, val);
td.RegisterVariableForTesting(&v);
@ -319,7 +321,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByName) {
auto* val = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f));
ast::AssignmentStatement assign(std::move(ident), std::move(val));
ast::AssignmentStatement assign(ident, val);
td.RegisterVariableForTesting(&v);
@ -365,7 +367,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
auto* val = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f));
ast::AssignmentStatement assign(std::move(ident), std::move(val));
ast::AssignmentStatement assign(ident, val);
td.RegisterVariableForTesting(&v);

View File

@ -62,7 +62,7 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar) {
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 4));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -82,24 +82,27 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
ast::type::I32Type i32;
ast::type::VectorType vec3(&i32, 3);
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
auto* lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* lhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
});
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
auto* rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* rhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
});
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -124,7 +127,7 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar_Loads) {
auto* lhs = create<ast::IdentifierExpression>("param");
auto* rhs = create<ast::IdentifierExpression>("param");
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
td.RegisterVariableForTesting(&var);
EXPECT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -174,7 +177,7 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 4));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -194,24 +197,27 @@ TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
ast::type::U32Type u32;
ast::type::VectorType vec3(&u32, 3);
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)));
auto* lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* lhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)),
});
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)));
auto* rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* rhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)),
});
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -252,7 +258,7 @@ TEST_P(BinaryArithFloatTest, Scalar) {
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 4.5f));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
b.push_function(Function{});
@ -272,24 +278,27 @@ TEST_P(BinaryArithFloatTest, Vector) {
ast::type::F32Type f32;
ast::type::VectorType vec3(&f32, 3);
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
auto* lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* lhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
});
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
auto* rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* rhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
});
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -324,7 +333,7 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 4));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -346,24 +355,27 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Vector) {
ast::type::U32Type u32;
ast::type::VectorType vec3(&u32, 3);
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)));
auto* lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* lhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)),
});
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)));
auto* rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* rhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1)),
});
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -402,7 +414,7 @@ TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 4));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -424,24 +436,27 @@ TEST_P(BinaryCompareSignedIntegerTest, Vector) {
ast::type::I32Type i32;
ast::type::VectorType vec3(&i32, 3);
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
auto* lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* lhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
});
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
auto* rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* rhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)),
});
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -480,7 +495,7 @@ TEST_P(BinaryCompareFloatTest, Scalar) {
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 4.5f));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -502,24 +517,27 @@ TEST_P(BinaryCompareFloatTest, Vector) {
ast::type::F32Type f32;
ast::type::VectorType vec3(&f32, 3);
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
auto* lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* lhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
});
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
auto* rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* rhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
});
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -551,20 +569,20 @@ TEST_F(BuilderTest, Binary_Multiply_VectorScalar) {
ast::type::F32Type f32;
ast::type::VectorType vec3(&f32, 3);
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
auto* lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* lhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)),
});
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f));
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -594,10 +612,9 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector) {
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
auto* rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* rhs = create<ast::TypeConstructorExpression>(&vec3, vals);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -624,8 +641,7 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -657,8 +673,7 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -694,12 +709,11 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
auto* rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* rhs = create<ast::TypeConstructorExpression>(&vec3, vals);
td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -735,14 +749,13 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
auto* lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto* lhs = create<ast::TypeConstructorExpression>(&vec3, vals);
auto* rhs = create<ast::IdentifierExpression>("mat");
td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -775,8 +788,7 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -814,8 +826,7 @@ TEST_F(BuilderTest, Binary_LogicalAnd) {
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 4)));
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, std::move(lhs),
std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -861,8 +872,7 @@ TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
td.RegisterVariableForTesting(a_var);
td.RegisterVariableForTesting(b_var);
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, std::move(lhs),
std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -910,8 +920,7 @@ TEST_F(BuilderTest, Binary_LogicalOr) {
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 4)));
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, std::move(lhs),
std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -957,8 +966,7 @@ TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
td.RegisterVariableForTesting(a_var);
td.RegisterVariableForTesting(b_var);
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, std::move(lhs),
std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();

View File

@ -57,7 +57,7 @@ TEST_F(BuilderTest, Block) {
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0f))));
outer.append(std::move(inner));
outer.append(inner);
outer.append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("var"),
create<ast::ScalarConstructorExpression>(

View File

@ -53,7 +53,7 @@ TEST_F(BuilderTest, Expression_Call) {
body->append(create<ast::ReturnStatement>(create<ast::BinaryExpression>(
ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("a"),
create<ast::IdentifierExpression>("b"))));
ast::Function a_func("a_func", std::move(func_params), &f32, std::move(body));
ast::Function a_func("a_func", func_params, &f32, body);
ast::Function func("main", {}, &void_type, create<ast::BlockStatement>());
@ -64,7 +64,7 @@ TEST_F(BuilderTest, Expression_Call) {
create<ast::FloatLiteral>(&f32, 1.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>("a_func"),
std::move(call_params));
call_params);
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();
ASSERT_TRUE(td.DetermineFunction(&a_func)) << td.error();
@ -114,8 +114,7 @@ TEST_F(BuilderTest, Statement_Call) {
ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("a"),
create<ast::IdentifierExpression>("b"))));
ast::Function a_func("a_func", std::move(func_params), &void_type,
std::move(body));
ast::Function a_func("a_func", func_params, &void_type, body);
ast::Function func("main", {}, &void_type, create<ast::BlockStatement>());
@ -126,7 +125,7 @@ TEST_F(BuilderTest, Statement_Call) {
create<ast::FloatLiteral>(&f32, 1.f)));
ast::CallStatement expr(create<ast::CallExpression>(
create<ast::IdentifierExpression>("a_func"), std::move(call_params)));
create<ast::IdentifierExpression>("a_func"), call_params));
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();
ASSERT_TRUE(td.DetermineFunction(&a_func)) << td.error();

View File

@ -53,7 +53,7 @@ using BuilderTest = TestHelper;
TEST_F(BuilderTest, Constructor_Const) {
ast::type::F32Type f32;
auto* fl = create<ast::FloatLiteral>(&f32, 42.2f);
ast::ScalarConstructorExpression c(std::move(fl));
ast::ScalarConstructorExpression c(fl);
EXPECT_EQ(b.GenerateConstructorExpression(nullptr, &c, true), 2u);
ASSERT_FALSE(b.has_error()) << b.error();
@ -75,7 +75,7 @@ TEST_F(BuilderTest, Constructor_Type) {
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.0f)));
ast::TypeConstructorExpression t(&vec, std::move(vals));
ast::TypeConstructorExpression t(&vec, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -100,15 +100,13 @@ TEST_F(BuilderTest, Constructor_Type_WithCasts) {
create<ast::SintLiteral>(&i32, 1)));
ast::ExpressionList vals;
vals.push_back(
create<ast::TypeConstructorExpression>(&f32, std::move(type_vals)));
vals.push_back(create<ast::TypeConstructorExpression>(&f32, type_vals));
type_vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
vals.push_back(
create<ast::TypeConstructorExpression>(&f32, std::move(type_vals)));
vals.push_back(create<ast::TypeConstructorExpression>(&f32, type_vals));
ast::TypeConstructorExpression t(&vec, std::move(vals));
ast::TypeConstructorExpression t(&vec, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -142,7 +140,7 @@ TEST_F(BuilderTest, Constructor_Type_WithAlias) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.3)));
ast::TypeConstructorExpression cast(&alias, std::move(params));
ast::TypeConstructorExpression cast(&alias, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -170,7 +168,7 @@ TEST_F(BuilderTest, Constructor_Type_IdentifierExpression_Param) {
create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(create<ast::IdentifierExpression>("ident"));
ast::TypeConstructorExpression t(&vec, std::move(vals));
ast::TypeConstructorExpression t(&vec, vals);
td.RegisterVariableForTesting(var);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -208,7 +206,7 @@ TEST_F(BuilderTest, Constructor_Vector_Bitcast_Params) {
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
ast::TypeConstructorExpression t(&vec, std::move(vals));
ast::TypeConstructorExpression t(&vec, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -243,9 +241,9 @@ TEST_F(BuilderTest, Constructor_Type_NonConst_Value_Fails) {
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::move(rel));
vals.push_back(rel);
ast::TypeConstructorExpression t(&vec, std::move(vals));
ast::TypeConstructorExpression t(&vec, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -261,7 +259,7 @@ TEST_F(BuilderTest, Constructor_Type_Bool_With_Bool) {
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true)));
ast::TypeConstructorExpression t(&bool_type, std::move(vals));
ast::TypeConstructorExpression t(&bool_type, vals);
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -285,7 +283,7 @@ TEST_F(BuilderTest, Constructor_Type_I32_With_I32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)));
ast::TypeConstructorExpression cast(&i32, std::move(params));
ast::TypeConstructorExpression cast(&i32, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -307,7 +305,7 @@ TEST_F(BuilderTest, Constructor_Type_U32_With_U32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 2)));
ast::TypeConstructorExpression cast(&u32, std::move(params));
ast::TypeConstructorExpression cast(&u32, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -329,7 +327,7 @@ TEST_F(BuilderTest, Constructor_Type_F32_With_F32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&f32, std::move(params));
ast::TypeConstructorExpression cast(&f32, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -354,7 +352,7 @@ TEST_F(BuilderTest, Constructor_Type_Vec2_With_F32_F32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&vec, std::move(params));
ast::TypeConstructorExpression cast(&vec, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -380,7 +378,7 @@ TEST_F(BuilderTest, Constructor_Type_Vec3_With_F32_F32_F32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&vec, std::move(params));
ast::TypeConstructorExpression cast(&vec, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -408,10 +406,9 @@ TEST_F(BuilderTest, Constructor_Type_Vec3_With_F32_Vec2) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec_params));
ast::TypeConstructorExpression cast(&vec3, std::move(params));
ast::TypeConstructorExpression cast(&vec3, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -443,12 +440,11 @@ TEST_F(BuilderTest, Constructor_Type_Vec3_With_Vec2_F32) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec_params));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&vec3, std::move(params));
ast::TypeConstructorExpression cast(&vec3, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -482,7 +478,7 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_F32_F32_F32_F32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&vec, std::move(params));
ast::TypeConstructorExpression cast(&vec, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -512,10 +508,9 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_F32_F32_Vec2) {
create<ast::FloatLiteral>(&f32, 2.0)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec_params));
ast::TypeConstructorExpression cast(&vec4, std::move(params));
ast::TypeConstructorExpression cast(&vec4, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -549,12 +544,11 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_F32_Vec2_F32) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec_params));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&vec4, std::move(params));
ast::TypeConstructorExpression cast(&vec4, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -586,14 +580,13 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_Vec2_F32_F32) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec_params));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&vec4, std::move(params));
ast::TypeConstructorExpression cast(&vec4, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -631,12 +624,10 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_Vec2_Vec2) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec2_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec2_params));
ast::TypeConstructorExpression cast(&vec4, std::move(params));
ast::TypeConstructorExpression cast(&vec4, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -674,10 +665,9 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_F32_Vec3) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec3, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec3, vec_params));
ast::TypeConstructorExpression cast(&vec4, std::move(params));
ast::TypeConstructorExpression cast(&vec4, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -712,12 +702,11 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_Vec3_F32) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec3, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec3, vec_params));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&vec4, std::move(params));
ast::TypeConstructorExpression cast(&vec4, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -752,10 +741,9 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec3_With_F32_Vec2) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec_params));
ast::TypeConstructorExpression cast(&vec3, std::move(params));
ast::TypeConstructorExpression cast(&vec3, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -788,12 +776,11 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec3_With_Vec2_F32) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec_params));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&vec3, std::move(params));
ast::TypeConstructorExpression cast(&vec3, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -830,10 +817,9 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec4_With_F32_F32_Vec2) {
create<ast::FloatLiteral>(&f32, 2.0)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec_params));
ast::TypeConstructorExpression cast(&vec4, std::move(params));
ast::TypeConstructorExpression cast(&vec4, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -868,12 +854,11 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec4_With_F32_Vec2_F32) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec_params));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&vec4, std::move(params));
ast::TypeConstructorExpression cast(&vec4, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -906,14 +891,13 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec4_With_Vec2_F32_F32) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec_params));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&vec4, std::move(params));
ast::TypeConstructorExpression cast(&vec4, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -952,12 +936,10 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec4_With_Vec2_Vec2) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec2, std::move(vec2_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec2, vec2_params));
ast::TypeConstructorExpression cast(&vec4, std::move(params));
ast::TypeConstructorExpression cast(&vec4, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -996,10 +978,9 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec4_With_F32_Vec3) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec3, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec3, vec_params));
ast::TypeConstructorExpression cast(&vec4, std::move(params));
ast::TypeConstructorExpression cast(&vec4, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1036,12 +1017,11 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec4_With_Vec3_F32) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec3, std::move(vec_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec3, vec_params));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&vec4, std::move(params));
ast::TypeConstructorExpression cast(&vec4, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1082,12 +1062,10 @@ TEST_F(BuilderTest, Constructor_Type_Mat2x2_With_Vec2_Vec2) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec2_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec2_params));
ast::TypeConstructorExpression cast(&mat, std::move(params));
ast::TypeConstructorExpression cast(&mat, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1127,14 +1105,11 @@ TEST_F(BuilderTest, Constructor_Type_Mat3x2_With_Vec2_Vec2_Vec2) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec2_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec3_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec2_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec3_params));
ast::TypeConstructorExpression cast(&mat, std::move(params));
ast::TypeConstructorExpression cast(&mat, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1180,16 +1155,12 @@ TEST_F(BuilderTest, Constructor_Type_Mat4x2_With_Vec2_Vec2_Vec2_Vec2) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec2_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec3_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec4_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec2_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec3_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec4_params));
ast::TypeConstructorExpression cast(&mat, std::move(params));
ast::TypeConstructorExpression cast(&mat, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1227,12 +1198,10 @@ TEST_F(BuilderTest, Constructor_Type_Mat2x3_With_Vec3_Vec3) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec2_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec2_params));
ast::TypeConstructorExpression cast(&mat, std::move(params));
ast::TypeConstructorExpression cast(&mat, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1278,14 +1247,11 @@ TEST_F(BuilderTest, Constructor_Type_Mat3x3_With_Vec3_Vec3_Vec3) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec2_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec3_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec2_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec3_params));
ast::TypeConstructorExpression cast(&mat, std::move(params));
ast::TypeConstructorExpression cast(&mat, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1339,16 +1305,12 @@ TEST_F(BuilderTest, Constructor_Type_Mat4x3_With_Vec3_Vec3_Vec3_Vec3) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec2_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec3_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec4_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec2_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec3_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec4_params));
ast::TypeConstructorExpression cast(&mat, std::move(params));
ast::TypeConstructorExpression cast(&mat, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1390,12 +1352,10 @@ TEST_F(BuilderTest, Constructor_Type_Mat2x4_With_Vec4_Vec4) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec2_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec2_params));
ast::TypeConstructorExpression cast(&mat, std::move(params));
ast::TypeConstructorExpression cast(&mat, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1447,14 +1407,11 @@ TEST_F(BuilderTest, Constructor_Type_Mat3x4_With_Vec4_Vec4_Vec4) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec2_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec3_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec2_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec3_params));
ast::TypeConstructorExpression cast(&mat, std::move(params));
ast::TypeConstructorExpression cast(&mat, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1516,16 +1473,12 @@ TEST_F(BuilderTest, Constructor_Type_Mat4x4_With_Vec4_Vec4_Vec4_Vec4) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec2_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec3_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec4_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec2_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec3_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec4_params));
ast::TypeConstructorExpression cast(&mat, std::move(params));
ast::TypeConstructorExpression cast(&mat, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1557,7 +1510,7 @@ TEST_F(BuilderTest, Constructor_Type_Array_5_F32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
ast::TypeConstructorExpression cast(&ary, std::move(params));
ast::TypeConstructorExpression cast(&ary, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1595,12 +1548,10 @@ TEST_F(BuilderTest, Constructor_Type_Array_2_Vec3) {
create<ast::FloatLiteral>(&f32, 2.0)));
ast::ExpressionList params;
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
params.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec2_params)));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec_params));
params.push_back(create<ast::TypeConstructorExpression>(&vec, vec2_params));
ast::TypeConstructorExpression cast(&ary, std::move(params));
ast::TypeConstructorExpression cast(&ary, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1624,11 +1575,11 @@ TEST_F(BuilderTest, Constructor_Type_Struct) {
ast::StructMemberDecorationList decos;
ast::StructMemberList members;
members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("b", &vec, std::move(decos)));
members.push_back(create<ast::StructMember>("a", &f32, decos));
members.push_back(create<ast::StructMember>("b", &vec, decos));
auto* s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("my_struct", std::move(s));
auto* s = create<ast::Struct>(members);
ast::type::StructType s_type("my_struct", s);
ast::ExpressionList vec_vals;
vec_vals.push_back(create<ast::ScalarConstructorExpression>(
@ -1641,10 +1592,9 @@ TEST_F(BuilderTest, Constructor_Type_Struct) {
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2)));
vals.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_vals)));
vals.push_back(create<ast::TypeConstructorExpression>(&vec, vec_vals));
ast::TypeConstructorExpression t(&s_type, std::move(vals));
ast::TypeConstructorExpression t(&s_type, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -1666,7 +1616,7 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_F32) {
ast::type::F32Type f32;
ast::ExpressionList vals;
ast::TypeConstructorExpression t(&f32, std::move(vals));
ast::TypeConstructorExpression t(&f32, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -1684,7 +1634,7 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_I32) {
ast::type::I32Type i32;
ast::ExpressionList vals;
ast::TypeConstructorExpression t(&i32, std::move(vals));
ast::TypeConstructorExpression t(&i32, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -1702,7 +1652,7 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_U32) {
ast::type::U32Type u32;
ast::ExpressionList vals;
ast::TypeConstructorExpression t(&u32, std::move(vals));
ast::TypeConstructorExpression t(&u32, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -1720,7 +1670,7 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_Bool) {
ast::type::BoolType bool_type;
ast::ExpressionList vals;
ast::TypeConstructorExpression t(&bool_type, std::move(vals));
ast::TypeConstructorExpression t(&bool_type, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -1739,7 +1689,7 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_Vector) {
ast::type::VectorType vec(&i32, 2);
ast::ExpressionList vals;
ast::TypeConstructorExpression t(&vec, std::move(vals));
ast::TypeConstructorExpression t(&vec, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -1759,7 +1709,7 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_Matrix) {
ast::type::MatrixType mat(&f32, 2, 4);
ast::ExpressionList vals;
ast::TypeConstructorExpression t(&mat, std::move(vals));
ast::TypeConstructorExpression t(&mat, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -1780,7 +1730,7 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_Array) {
ast::type::ArrayType ary(&i32, 2);
ast::ExpressionList vals;
ast::TypeConstructorExpression t(&ary, std::move(vals));
ast::TypeConstructorExpression t(&ary, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -1802,13 +1752,13 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_Struct) {
ast::StructMemberDecorationList decos;
ast::StructMemberList members;
members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("a", &f32, decos));
auto* s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("my_struct", std::move(s));
auto* s = create<ast::Struct>(members);
ast::type::StructType s_type("my_struct", s);
ast::ExpressionList vals;
ast::TypeConstructorExpression t(&s_type, std::move(vals));
ast::TypeConstructorExpression t(&s_type, vals);
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -1831,7 +1781,7 @@ TEST_F(BuilderTest, Constructor_Type_Convert_U32_To_I32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 2)));
ast::TypeConstructorExpression cast(&i32, std::move(params));
ast::TypeConstructorExpression cast(&i32, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1855,7 +1805,7 @@ TEST_F(BuilderTest, Constructor_Type_Convert_I32_To_U32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)));
ast::TypeConstructorExpression cast(&u32, std::move(params));
ast::TypeConstructorExpression cast(&u32, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1879,7 +1829,7 @@ TEST_F(BuilderTest, Constructor_Type_Convert_F32_To_I32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.4)));
ast::TypeConstructorExpression cast(&i32, std::move(params));
ast::TypeConstructorExpression cast(&i32, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1903,7 +1853,7 @@ TEST_F(BuilderTest, Constructor_Type_Convert_F32_To_U32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.4)));
ast::TypeConstructorExpression cast(&u32, std::move(params));
ast::TypeConstructorExpression cast(&u32, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1927,7 +1877,7 @@ TEST_F(BuilderTest, Constructor_Type_Convert_I32_To_F32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)));
ast::TypeConstructorExpression cast(&f32, std::move(params));
ast::TypeConstructorExpression cast(&f32, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1951,7 +1901,7 @@ TEST_F(BuilderTest, Constructor_Type_Convert_U32_To_F32) {
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 2)));
ast::TypeConstructorExpression cast(&f32, std::move(params));
ast::TypeConstructorExpression cast(&f32, params);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -1978,7 +1928,7 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_U32_to_I32) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("i"));
ast::TypeConstructorExpression cast(&ivec3, std::move(params));
ast::TypeConstructorExpression cast(&ivec3, params);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -2012,7 +1962,7 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_F32_to_I32) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("i"));
ast::TypeConstructorExpression cast(&ivec3, std::move(params));
ast::TypeConstructorExpression cast(&ivec3, params);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -2046,7 +1996,7 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_I32_to_U32) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("i"));
ast::TypeConstructorExpression cast(&uvec3, std::move(params));
ast::TypeConstructorExpression cast(&uvec3, params);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -2080,7 +2030,7 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_F32_to_U32) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("i"));
ast::TypeConstructorExpression cast(&uvec3, std::move(params));
ast::TypeConstructorExpression cast(&uvec3, params);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -2114,7 +2064,7 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_I32_to_F32) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("i"));
ast::TypeConstructorExpression cast(&fvec3, std::move(params));
ast::TypeConstructorExpression cast(&fvec3, params);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -2148,7 +2098,7 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_U32_to_F32) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("i"));
ast::TypeConstructorExpression cast(&fvec3, std::move(params));
ast::TypeConstructorExpression cast(&fvec3, params);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
@ -2183,7 +2133,7 @@ TEST_F(BuilderTest, IsConstructorConst_GlobalVectorWithAllConstConstructors) {
create<ast::FloatLiteral>(&f32, 2.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.f)));
ast::TypeConstructorExpression t(&vec, std::move(params));
ast::TypeConstructorExpression t(&vec, params);
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -2200,7 +2150,7 @@ TEST_F(BuilderTest, IsConstructorConst_GlobalVector_WithIdent) {
params.push_back(create<ast::IdentifierExpression>("a"));
params.push_back(create<ast::IdentifierExpression>("b"));
params.push_back(create<ast::IdentifierExpression>("c"));
ast::TypeConstructorExpression t(&vec, std::move(params));
ast::TypeConstructorExpression t(&vec, params);
ast::Variable var_a("a", ast::StorageClass::kPrivate, &f32);
ast::Variable var_b("b", ast::StorageClass::kPrivate, &f32);
@ -2230,7 +2180,7 @@ TEST_F(BuilderTest, IsConstructorConst_GlobalArrayWithAllConstConstructors) {
create<ast::FloatLiteral>(&f32, 2.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.f)));
auto* first = create<ast::TypeConstructorExpression>(&vec, std::move(params));
auto* first = create<ast::TypeConstructorExpression>(&vec, params);
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
@ -2238,13 +2188,12 @@ TEST_F(BuilderTest, IsConstructorConst_GlobalArrayWithAllConstConstructors) {
create<ast::FloatLiteral>(&f32, 2.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.f)));
auto* second =
create<ast::TypeConstructorExpression>(&vec, std::move(params));
auto* second = create<ast::TypeConstructorExpression>(&vec, params);
ast::ExpressionList ary_params;
ary_params.push_back(std::move(first));
ary_params.push_back(std::move(second));
ast::TypeConstructorExpression t(&ary, std::move(ary_params));
ary_params.push_back(first);
ary_params.push_back(second);
ast::TypeConstructorExpression t(&ary, ary_params);
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -2263,15 +2212,13 @@ TEST_F(BuilderTest,
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0)));
vec_params.push_back(
create<ast::TypeConstructorExpression>(&f32, std::move(params)));
vec_params.push_back(create<ast::TypeConstructorExpression>(&f32, params));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0)));
vec_params.push_back(
create<ast::TypeConstructorExpression>(&f32, std::move(params)));
vec_params.push_back(create<ast::TypeConstructorExpression>(&f32, params));
ast::TypeConstructorExpression t(&vec, std::move(vec_params));
ast::TypeConstructorExpression t(&vec, vec_params);
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -2290,15 +2237,13 @@ TEST_F(BuilderTest, IsConstructorConst_GlobalWithTypeCastConstructor) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
vec_params.push_back(
create<ast::TypeConstructorExpression>(&f32, std::move(params)));
vec_params.push_back(create<ast::TypeConstructorExpression>(&f32, params));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)));
vec_params.push_back(
create<ast::TypeConstructorExpression>(&f32, std::move(params)));
vec_params.push_back(create<ast::TypeConstructorExpression>(&f32, params));
ast::TypeConstructorExpression t(&vec, std::move(vec_params));
ast::TypeConstructorExpression t(&vec, vec_params);
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -2318,7 +2263,7 @@ TEST_F(BuilderTest, IsConstructorConst_VectorWithAllConstConstructors) {
create<ast::FloatLiteral>(&f32, 2.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.f)));
ast::TypeConstructorExpression t(&vec, std::move(params));
ast::TypeConstructorExpression t(&vec, params);
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -2335,7 +2280,7 @@ TEST_F(BuilderTest, IsConstructorConst_Vector_WithIdent) {
params.push_back(create<ast::IdentifierExpression>("a"));
params.push_back(create<ast::IdentifierExpression>("b"));
params.push_back(create<ast::IdentifierExpression>("c"));
ast::TypeConstructorExpression t(&vec, std::move(params));
ast::TypeConstructorExpression t(&vec, params);
ast::Variable var_a("a", ast::StorageClass::kPrivate, &f32);
ast::Variable var_b("b", ast::StorageClass::kPrivate, &f32);
@ -2364,7 +2309,7 @@ TEST_F(BuilderTest, IsConstructorConst_ArrayWithAllConstConstructors) {
create<ast::FloatLiteral>(&f32, 2.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.f)));
auto* first = create<ast::TypeConstructorExpression>(&vec, std::move(params));
auto* first = create<ast::TypeConstructorExpression>(&vec, params);
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)));
@ -2372,13 +2317,12 @@ TEST_F(BuilderTest, IsConstructorConst_ArrayWithAllConstConstructors) {
create<ast::FloatLiteral>(&f32, 2.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.f)));
auto* second =
create<ast::TypeConstructorExpression>(&vec, std::move(params));
auto* second = create<ast::TypeConstructorExpression>(&vec, params);
ast::ExpressionList ary_params;
ary_params.push_back(std::move(first));
ary_params.push_back(std::move(second));
ast::TypeConstructorExpression t(&ary, std::move(ary_params));
ary_params.push_back(first);
ary_params.push_back(second);
ast::TypeConstructorExpression t(&ary, ary_params);
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -2397,15 +2341,13 @@ TEST_F(BuilderTest, IsConstructorConst_VectorWith_TypeCastConstConstructors) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
vec_params.push_back(
create<ast::TypeConstructorExpression>(&f32, std::move(params)));
vec_params.push_back(create<ast::TypeConstructorExpression>(&f32, params));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)));
vec_params.push_back(
create<ast::TypeConstructorExpression>(&f32, std::move(params)));
vec_params.push_back(create<ast::TypeConstructorExpression>(&f32, params));
ast::TypeConstructorExpression t(&vec, std::move(vec_params));
ast::TypeConstructorExpression t(&vec, vec_params);
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -2424,15 +2366,13 @@ TEST_F(BuilderTest, IsConstructorConst_WithTypeCastConstructor) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
vec_params.push_back(
create<ast::TypeConstructorExpression>(&f32, std::move(params)));
vec_params.push_back(create<ast::TypeConstructorExpression>(&f32, params));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)));
vec_params.push_back(
create<ast::TypeConstructorExpression>(&f32, std::move(params)));
vec_params.push_back(create<ast::TypeConstructorExpression>(&f32, params));
ast::TypeConstructorExpression t(&vec, std::move(vec_params));
ast::TypeConstructorExpression t(&vec, vec_params);
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -2451,7 +2391,7 @@ TEST_F(BuilderTest, IsConstructorConst_BitCastScalars) {
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)));
ast::TypeConstructorExpression t(&vec, std::move(vals));
ast::TypeConstructorExpression t(&vec, vals);
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -2465,11 +2405,11 @@ TEST_F(BuilderTest, IsConstructorConst_Struct) {
ast::StructMemberDecorationList decos;
ast::StructMemberList members;
members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("b", &vec, std::move(decos)));
members.push_back(create<ast::StructMember>("a", &f32, decos));
members.push_back(create<ast::StructMember>("b", &vec, decos));
auto* s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("my_struct", std::move(s));
auto* s = create<ast::Struct>(members);
ast::type::StructType s_type("my_struct", s);
ast::ExpressionList vec_vals;
vec_vals.push_back(create<ast::ScalarConstructorExpression>(
@ -2482,10 +2422,9 @@ TEST_F(BuilderTest, IsConstructorConst_Struct) {
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2)));
vals.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_vals)));
vals.push_back(create<ast::TypeConstructorExpression>(&vec, vec_vals));
ast::TypeConstructorExpression t(&s_type, std::move(vals));
ast::TypeConstructorExpression t(&s_type, vals);
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
@ -2499,11 +2438,11 @@ TEST_F(BuilderTest, IsConstructorConst_Struct_WithIdentSubExpression) {
ast::StructMemberDecorationList decos;
ast::StructMemberList members;
members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
members.push_back(create<ast::StructMember>("b", &vec, std::move(decos)));
members.push_back(create<ast::StructMember>("a", &f32, decos));
members.push_back(create<ast::StructMember>("b", &vec, decos));
auto* s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("my_struct", std::move(s));
auto* s = create<ast::Struct>(members);
ast::type::StructType s_type("my_struct", s);
ast::ExpressionList vec_vals;
vec_vals.push_back(create<ast::ScalarConstructorExpression>(
@ -2515,10 +2454,9 @@ TEST_F(BuilderTest, IsConstructorConst_Struct_WithIdentSubExpression) {
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2)));
vals.push_back(
create<ast::TypeConstructorExpression>(&vec, std::move(vec_vals)));
vals.push_back(create<ast::TypeConstructorExpression>(&vec, vec_vals));
ast::TypeConstructorExpression t(&s_type, std::move(vals));
ast::TypeConstructorExpression t(&s_type, vals);
ast::Variable var_a("a", ast::StorageClass::kPrivate, &f32);
ast::Variable var_b("b", ast::StorageClass::kPrivate, &f32);

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