validator tests: Replace std::make_unique<T> -> create<T>
create() is currently just a simple forwarder to std::make_unique<>, but will be later replaced with a function that returns a raw pointer, and owned by the context. Bug: tint:322 Change-Id: I69487200d9595f3176615ee1edf81da9fe1f5abc Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32670 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
a1f4d4fda9
commit
16b12fa9a4
|
@ -43,23 +43,21 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
|
|||
// default: {}
|
||||
// }
|
||||
ast::type::F32Type f32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&f32, 3.14f)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&f32, 3.14f)));
|
||||
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "a");
|
||||
auto cond =
|
||||
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "a");
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
auto block_default = create<ast::BlockStatement>();
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(default_csl), std::move(block_default)));
|
||||
body.push_back(create<ast::CaseStatement>(std::move(default_csl),
|
||||
std::move(block_default)));
|
||||
|
||||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(
|
||||
std::make_unique<ast::SwitchStatement>(std::move(cond), std::move(body)));
|
||||
auto block = create<ast::BlockStatement>();
|
||||
block->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(create<ast::SwitchStatement>(std::move(cond), std::move(body)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block.get())) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block.get()));
|
||||
|
@ -74,22 +72,21 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
|
|||
// case 1: {}
|
||||
// }
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto cond = create<ast::IdentifierExpression>("a");
|
||||
ast::CaseSelectorList csl;
|
||||
csl.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||
csl.push_back(create<ast::SintLiteral>(&i32, 1));
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(csl), std::make_unique<ast::BlockStatement>()));
|
||||
body.push_back(create<ast::CaseStatement>(std::move(csl),
|
||||
create<ast::BlockStatement>()));
|
||||
|
||||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(std::make_unique<ast::SwitchStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(cond), std::move(body)));
|
||||
auto block = create<ast::BlockStatement>();
|
||||
block->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}},
|
||||
std::move(cond), std::move(body)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block.get())) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block.get()));
|
||||
|
@ -106,35 +103,34 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
|
|||
// default: {}
|
||||
// }
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto cond = create<ast::IdentifierExpression>("a");
|
||||
|
||||
ast::CaseSelectorList default_csl_1;
|
||||
auto block_default_1 = std::make_unique<ast::BlockStatement>();
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(default_csl_1), std::move(block_default_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)));
|
||||
|
||||
ast::CaseSelectorList csl_case_1;
|
||||
csl_case_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||
auto block_case_1 = std::make_unique<ast::BlockStatement>();
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(csl_case_1), std::move(block_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)));
|
||||
|
||||
ast::CaseSelectorList default_csl_2;
|
||||
auto block_default_2 = std::make_unique<ast::BlockStatement>();
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(default_csl_2), std::move(block_default_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)));
|
||||
|
||||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(std::make_unique<ast::SwitchStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(cond),
|
||||
std::move(switch_body)));
|
||||
auto block = create<ast::BlockStatement>();
|
||||
block->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}},
|
||||
std::move(cond),
|
||||
std::move(switch_body)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block.get())) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block.get()));
|
||||
|
@ -152,29 +148,28 @@ TEST_F(ValidateControlBlockTest,
|
|||
// }
|
||||
ast::type::U32Type u32;
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto cond = create<ast::IdentifierExpression>("a");
|
||||
|
||||
ast::CaseSelectorList csl;
|
||||
csl.push_back(std::make_unique<ast::UintLiteral>(&u32, 1));
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
csl.push_back(create<ast::UintLiteral>(&u32, 1));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(csl),
|
||||
std::make_unique<ast::BlockStatement>()));
|
||||
create<ast::BlockStatement>()));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(default_csl), std::move(block_default)));
|
||||
auto block_default = create<ast::BlockStatement>();
|
||||
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl),
|
||||
std::move(block_default)));
|
||||
|
||||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(std::make_unique<ast::SwitchStatement>(std::move(cond),
|
||||
std::move(switch_body)));
|
||||
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)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block.get())) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block.get()));
|
||||
|
@ -192,29 +187,28 @@ TEST_F(ValidateControlBlockTest,
|
|||
// }
|
||||
ast::type::U32Type u32;
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &u32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &u32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 2)));
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto cond = create<ast::IdentifierExpression>("a");
|
||||
|
||||
ast::CaseSelectorList csl;
|
||||
csl.push_back(std::make_unique<ast::SintLiteral>(&i32, -1));
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
csl.push_back(create<ast::SintLiteral>(&i32, -1));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(csl),
|
||||
std::make_unique<ast::BlockStatement>()));
|
||||
create<ast::BlockStatement>()));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(default_csl), std::move(block_default)));
|
||||
auto block_default = create<ast::BlockStatement>();
|
||||
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl),
|
||||
std::move(block_default)));
|
||||
|
||||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(std::make_unique<ast::SwitchStatement>(std::move(cond),
|
||||
std::move(switch_body)));
|
||||
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)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block.get())) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block.get()));
|
||||
|
@ -231,35 +225,34 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
|
|||
// default: {}
|
||||
// }
|
||||
ast::type::U32Type u32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &u32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 3)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &u32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 3)));
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto cond = create<ast::IdentifierExpression>("a");
|
||||
|
||||
ast::CaseSelectorList csl_1;
|
||||
csl_1.push_back(std::make_unique<ast::UintLiteral>(&u32, 0));
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(csl_1), std::make_unique<ast::BlockStatement>()));
|
||||
csl_1.push_back(create<ast::UintLiteral>(&u32, 0));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
std::move(csl_1), create<ast::BlockStatement>()));
|
||||
|
||||
ast::CaseSelectorList csl_2;
|
||||
csl_2.push_back(std::make_unique<ast::UintLiteral>(&u32, 2));
|
||||
csl_2.push_back(std::make_unique<ast::UintLiteral>(&u32, 2));
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
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),
|
||||
std::make_unique<ast::BlockStatement>()));
|
||||
create<ast::BlockStatement>()));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(default_csl), std::move(block_default)));
|
||||
auto block_default = create<ast::BlockStatement>();
|
||||
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl),
|
||||
std::move(block_default)));
|
||||
|
||||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(std::make_unique<ast::SwitchStatement>(std::move(cond),
|
||||
std::move(switch_body)));
|
||||
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)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block.get())) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block.get()));
|
||||
|
@ -276,37 +269,36 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
|
|||
// default: {}
|
||||
// }
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto cond = create<ast::IdentifierExpression>("a");
|
||||
|
||||
ast::CaseSelectorList csl_1;
|
||||
csl_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 10));
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(csl_1), std::make_unique<ast::BlockStatement>()));
|
||||
csl_1.push_back(create<ast::SintLiteral>(&i32, 10));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
std::move(csl_1), create<ast::BlockStatement>()));
|
||||
|
||||
ast::CaseSelectorList csl_2;
|
||||
csl_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 0));
|
||||
csl_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||
csl_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
csl_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 10));
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
csl_2.push_back(create<ast::SintLiteral>(&i32, 0));
|
||||
csl_2.push_back(create<ast::SintLiteral>(&i32, 1));
|
||||
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),
|
||||
std::make_unique<ast::BlockStatement>()));
|
||||
create<ast::BlockStatement>()));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(default_csl), std::move(block_default)));
|
||||
auto block_default = create<ast::BlockStatement>();
|
||||
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl),
|
||||
std::move(block_default)));
|
||||
|
||||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(std::make_unique<ast::SwitchStatement>(std::move(cond),
|
||||
std::move(switch_body)));
|
||||
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)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block.get())) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block.get()));
|
||||
|
@ -321,24 +313,22 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
|
|||
// default: { fallthrough; }
|
||||
// }
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto cond = create<ast::IdentifierExpression>("a");
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
block_default->append(std::make_unique<ast::FallthroughStatement>(
|
||||
Source{Source::Location{12, 34}}));
|
||||
auto block_default = create<ast::BlockStatement>();
|
||||
block_default->append(
|
||||
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}));
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(default_csl), std::move(block_default)));
|
||||
body.push_back(create<ast::CaseStatement>(std::move(default_csl),
|
||||
std::move(block_default)));
|
||||
|
||||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(
|
||||
std::make_unique<ast::SwitchStatement>(std::move(cond), std::move(body)));
|
||||
auto block = create<ast::BlockStatement>();
|
||||
block->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(create<ast::SwitchStatement>(std::move(cond), std::move(body)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block.get())) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block.get()));
|
||||
|
@ -354,28 +344,26 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
|
|||
// case 5: {}
|
||||
// }
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto cond = create<ast::IdentifierExpression>("a");
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
auto block_default = create<ast::BlockStatement>();
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(default_csl),
|
||||
std::move(block_default)));
|
||||
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
|
||||
std::move(default_csl),
|
||||
std::move(block_default)));
|
||||
ast::CaseSelectorList case_csl;
|
||||
case_csl.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
auto block_case = std::make_unique<ast::BlockStatement>();
|
||||
body.push_back(std::make_unique<ast::CaseStatement>(std::move(case_csl),
|
||||
std::move(block_case)));
|
||||
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)));
|
||||
|
||||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(
|
||||
std::make_unique<ast::SwitchStatement>(std::move(cond), std::move(body)));
|
||||
auto block = create<ast::BlockStatement>();
|
||||
block->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(create<ast::SwitchStatement>(std::move(cond), std::move(body)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block.get())) << td()->error();
|
||||
EXPECT_TRUE(v()->ValidateStatements(block.get())) << v()->error();
|
||||
|
@ -391,23 +379,21 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
|
|||
ast::type::U32Type u32;
|
||||
ast::type::AliasType my_int{"MyInt", &u32};
|
||||
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &my_int);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&u32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &my_int);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&u32, 2)));
|
||||
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto cond = create<ast::IdentifierExpression>("a");
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
auto block_default = create<ast::BlockStatement>();
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(default_csl),
|
||||
std::move(block_default)));
|
||||
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
|
||||
std::move(default_csl),
|
||||
std::move(block_default)));
|
||||
|
||||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(
|
||||
std::make_unique<ast::SwitchStatement>(std::move(cond), std::move(body)));
|
||||
auto block = create<ast::BlockStatement>();
|
||||
block->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(create<ast::SwitchStatement>(std::move(cond), std::move(body)));
|
||||
|
||||
mod()->AddConstructedType(&my_int);
|
||||
|
||||
|
|
|
@ -39,20 +39,19 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
|
|||
// [[stage(vertex)]]
|
||||
// fn func -> void { var a:i32 = 2; }
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
ast::VariableList params;
|
||||
ast::type::VoidType void_type;
|
||||
auto func = std::make_unique<ast::Function>(
|
||||
Source{Source::Location{12, 34}}, "func", std::move(params), &void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
auto func = create<ast::Function>(Source{Source::Location{12, 34}}, "func",
|
||||
std::move(params), &void_type);
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
func->set_body(std::move(body));
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
@ -65,10 +64,10 @@ TEST_F(ValidateFunctionTest,
|
|||
// fn func -> void {}
|
||||
ast::type::VoidType void_type;
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>(
|
||||
Source{Source::Location{12, 34}}, "func", std::move(params), &void_type);
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
auto func = create<ast::Function>(Source{Source::Location{12, 34}}, "func",
|
||||
std::move(params), &void_type);
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
@ -79,17 +78,16 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
|
|||
// fn func -> int { var a:i32 = 2; }
|
||||
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
ast::VariableList params;
|
||||
ast::type::VoidType void_type;
|
||||
auto func = std::make_unique<ast::Function>(Source{Source::Location{12, 34}},
|
||||
"func", std::move(params), &i32);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
auto func = create<ast::Function>(Source{Source::Location{12, 34}}, "func",
|
||||
std::move(params), &i32);
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
func->set_body(std::move(body));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
|
@ -105,8 +103,8 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
|
|||
ast::type::VoidType void_type;
|
||||
ast::type::I32Type i32;
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>(Source{Source::Location{12, 34}},
|
||||
"func", std::move(params), &i32);
|
||||
auto func = create<ast::Function>(Source{Source::Location{12, 34}}, "func",
|
||||
std::move(params), &i32);
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
@ -122,13 +120,12 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
|
|||
ast::type::VoidType void_type;
|
||||
ast::VariableList params;
|
||||
|
||||
auto func =
|
||||
std::make_unique<ast::Function>("func", std::move(params), &void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto func = create<ast::Function>("func", std::move(params), &void_type);
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineFunctions(mod()->functions())) << td()->error();
|
||||
|
@ -140,14 +137,13 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
|
|||
ast::type::VoidType void_type;
|
||||
ast::type::I32Type i32;
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
std::make_unique<ast::Function>("func", std::move(params), &void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
auto return_expr = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto func = create<ast::Function>("func", std::move(params), &void_type);
|
||||
auto body = create<ast::BlockStatement>();
|
||||
auto return_expr = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2));
|
||||
|
||||
body->append(std::make_unique<ast::ReturnStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(return_expr)));
|
||||
body->append(create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
|
||||
std::move(return_expr)));
|
||||
func->set_body(std::move(body));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
|
@ -164,13 +160,13 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
|
|||
ast::type::I32Type i32;
|
||||
ast::type::F32Type f32;
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("func", std::move(params), &f32);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
auto return_expr = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto func = create<ast::Function>("func", std::move(params), &f32);
|
||||
auto body = create<ast::BlockStatement>();
|
||||
auto return_expr = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2));
|
||||
|
||||
body->append(std::make_unique<ast::ReturnStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(return_expr)));
|
||||
body->append(create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
|
||||
std::move(return_expr)));
|
||||
func->set_body(std::move(body));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
|
@ -189,23 +185,22 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
|
|||
ast::type::I32Type i32;
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("func", std::move(params), &i32);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
auto return_expr = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto func = create<ast::Function>("func", std::move(params), &i32);
|
||||
auto body = create<ast::BlockStatement>();
|
||||
auto return_expr = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2));
|
||||
|
||||
body->append(std::make_unique<ast::ReturnStatement>(std::move(return_expr)));
|
||||
body->append(create<ast::ReturnStatement>(std::move(return_expr)));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
ast::VariableList params_copy;
|
||||
auto func_copy = std::make_unique<ast::Function>(
|
||||
Source{Source::Location{12, 34}}, "func", std::move(params_copy), &i32);
|
||||
auto body_copy = std::make_unique<ast::BlockStatement>();
|
||||
auto return_expr_copy = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto func_copy = create<ast::Function>(Source{Source::Location{12, 34}},
|
||||
"func", std::move(params_copy), &i32);
|
||||
auto body_copy = create<ast::BlockStatement>();
|
||||
auto return_expr_copy = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2));
|
||||
|
||||
body_copy->append(
|
||||
std::make_unique<ast::ReturnStatement>(std::move(return_expr_copy)));
|
||||
body_copy->append(create<ast::ReturnStatement>(std::move(return_expr_copy)));
|
||||
func_copy->set_body(std::move(body_copy));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
@ -222,16 +217,14 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::VoidType void_type;
|
||||
ast::ExpressionList call_params;
|
||||
auto call_expr = std::make_unique<ast::CallExpression>(
|
||||
auto call_expr = create<ast::CallExpression>(
|
||||
Source{Source::Location{12, 34}},
|
||||
std::make_unique<ast::IdentifierExpression>("func"),
|
||||
std::move(call_params));
|
||||
create<ast::IdentifierExpression>("func"), std::move(call_params));
|
||||
ast::VariableList params0;
|
||||
auto func0 =
|
||||
std::make_unique<ast::Function>("func", std::move(params0), &f32);
|
||||
auto body0 = std::make_unique<ast::BlockStatement>();
|
||||
body0->append(std::make_unique<ast::CallStatement>(std::move(call_expr)));
|
||||
body0->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto func0 = create<ast::Function>("func", std::move(params0), &f32);
|
||||
auto body0 = create<ast::BlockStatement>();
|
||||
body0->append(create<ast::CallStatement>(std::move(call_expr)));
|
||||
body0->append(create<ast::ReturnStatement>());
|
||||
func0->set_body(std::move(body0));
|
||||
mod()->AddFunction(std::move(func0));
|
||||
|
||||
|
@ -243,23 +236,20 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
|
|||
TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
|
||||
// fn func() -> i32 {var a: i32 = func(); return 2; }
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
ast::ExpressionList call_params;
|
||||
auto call_expr = std::make_unique<ast::CallExpression>(
|
||||
auto call_expr = create<ast::CallExpression>(
|
||||
Source{Source::Location{12, 34}},
|
||||
std::make_unique<ast::IdentifierExpression>("func"),
|
||||
std::move(call_params));
|
||||
create<ast::IdentifierExpression>("func"), std::move(call_params));
|
||||
var->set_constructor(std::move(call_expr));
|
||||
ast::VariableList params0;
|
||||
auto func0 =
|
||||
std::make_unique<ast::Function>("func", std::move(params0), &i32);
|
||||
auto body0 = std::make_unique<ast::BlockStatement>();
|
||||
body0->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
auto return_expr = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto func0 = create<ast::Function>("func", std::move(params0), &i32);
|
||||
auto body0 = create<ast::BlockStatement>();
|
||||
body0->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
auto return_expr = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2));
|
||||
|
||||
body0->append(std::make_unique<ast::ReturnStatement>(std::move(return_expr)));
|
||||
body0->append(create<ast::ReturnStatement>(std::move(return_expr)));
|
||||
func0->set_body(std::move(body0));
|
||||
mod()->AddFunction(std::move(func0));
|
||||
|
||||
|
@ -273,16 +263,16 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
|
|||
// fn vtx_main() -> i32 { return 0; }
|
||||
ast::type::I32Type i32;
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>(
|
||||
Source{Source::Location{12, 34}}, "vtx_main", std::move(params), &i32);
|
||||
auto return_expr = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 0));
|
||||
auto func = create<ast::Function>(Source{Source::Location{12, 34}},
|
||||
"vtx_main", std::move(params), &i32);
|
||||
auto return_expr = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 0));
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>(std::move(return_expr)));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>(std::move(return_expr)));
|
||||
func->set_body(std::move(body));
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
@ -297,16 +287,14 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
|
|||
ast::type::I32Type i32;
|
||||
ast::type::VoidType void_type;
|
||||
ast::VariableList params;
|
||||
params.push_back(
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32));
|
||||
auto func = std::make_unique<ast::Function>(Source{Source::Location{12, 34}},
|
||||
"vtx_func", std::move(params),
|
||||
&void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
params.push_back(create<ast::Variable>("a", ast::StorageClass::kNone, &i32));
|
||||
auto func = create<ast::Function>(Source{Source::Location{12, 34}},
|
||||
"vtx_func", std::move(params), &void_type);
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
@ -322,15 +310,15 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
|
|||
// fn main() -> void { return; }
|
||||
ast::type::VoidType void_type;
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>(
|
||||
Source{Source::Location{12, 34}}, "main", std::move(params), &void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto func = create<ast::Function>(Source{Source::Location{12, 34}}, "main",
|
||||
std::move(params), &void_type);
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kFragment, Source{}));
|
||||
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));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate(mod()));
|
||||
|
@ -344,13 +332,12 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
|
|||
// fn vtx_func() -> void { return; }
|
||||
ast::type::VoidType void_type;
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("vtx_func", std::move(params),
|
||||
&void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto func = create<ast::Function>("vtx_func", std::move(params), &void_type);
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
@ -361,10 +348,9 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
|
|||
// fn vtx_func() -> void { return; }
|
||||
ast::type::VoidType void_type;
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("vtx_func", std::move(params),
|
||||
&void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto func = create<ast::Function>("vtx_func", std::move(params), &void_type);
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
|
|
|
@ -64,9 +64,9 @@ TEST_F(ValidatorTest, DISABLED_AssignToScalar_Fail) {
|
|||
// 1 = my_var;
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("my_var");
|
||||
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));
|
||||
|
||||
|
@ -80,11 +80,11 @@ TEST_F(ValidatorTest, UsingUndefinedVariable_Fail) {
|
|||
// b = 2;
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "b");
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto assign = std::make_unique<ast::AssignmentStatement>(
|
||||
auto lhs =
|
||||
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "b");
|
||||
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));
|
||||
|
||||
EXPECT_FALSE(td()->DetermineResultType(assign.get()));
|
||||
|
@ -98,13 +98,13 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) {
|
|||
// }
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "b");
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto lhs =
|
||||
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "b");
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2));
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
EXPECT_FALSE(td()->DetermineStatements(body.get()));
|
||||
|
@ -116,15 +116,14 @@ TEST_F(ValidatorTest, AssignCompatibleTypes_Pass) {
|
|||
// var a :i32 = 2;
|
||||
// a = 2
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto lhs = create<ast::IdentifierExpression>("a");
|
||||
auto* lhs_ptr = lhs.get();
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2));
|
||||
auto* rhs_ptr = rhs.get();
|
||||
|
||||
ast::AssignmentStatement assign(Source{Source::Location{12, 34}},
|
||||
|
@ -144,14 +143,13 @@ TEST_F(ValidatorTest, AssignIncompatibleTypes_Fail) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
auto lhs = create<ast::IdentifierExpression>("a");
|
||||
auto* lhs_ptr = lhs.get();
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.3f));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.3f));
|
||||
auto* rhs_ptr = rhs.get();
|
||||
|
||||
ast::AssignmentStatement assign(Source{Source::Location{12, 34}},
|
||||
|
@ -174,20 +172,19 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
|
|||
// a = 2
|
||||
// }
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto lhs = create<ast::IdentifierExpression>("a");
|
||||
auto* lhs_ptr = lhs.get();
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2));
|
||||
auto* rhs_ptr = rhs.get();
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(body.get())) << td()->error();
|
||||
|
@ -205,19 +202,18 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
auto lhs = create<ast::IdentifierExpression>("a");
|
||||
auto* lhs_ptr = lhs.get();
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.3f));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.3f));
|
||||
auto* rhs_ptr = rhs.get();
|
||||
|
||||
ast::BlockStatement block;
|
||||
block.append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block.append(std::make_unique<ast::AssignmentStatement>(
|
||||
block.append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
block.append(create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(&block)) << td()->error();
|
||||
|
@ -234,9 +230,9 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
|
|||
TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
|
||||
// var<in> gloabl_var: f32;
|
||||
ast::type::F32Type f32;
|
||||
auto global_var = std::make_unique<ast::Variable>(
|
||||
Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kInput,
|
||||
&f32);
|
||||
auto global_var =
|
||||
create<ast::Variable>(Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kInput, &f32);
|
||||
mod()->AddGlobalVariable(std::move(global_var));
|
||||
EXPECT_TRUE(v()->ValidateGlobalVariables(mod()->global_variables()))
|
||||
<< v()->error();
|
||||
|
@ -245,9 +241,9 @@ TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
|
|||
TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
|
||||
// var gloabl_var: f32;
|
||||
ast::type::F32Type f32;
|
||||
auto global_var = std::make_unique<ast::Variable>(
|
||||
Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kNone,
|
||||
&f32);
|
||||
auto global_var =
|
||||
create<ast::Variable>(Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kNone, &f32);
|
||||
mod()->AddGlobalVariable(std::move(global_var));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate(mod()));
|
||||
|
@ -257,9 +253,9 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
|
|||
TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
|
||||
// const<in> gloabl_var: f32;
|
||||
ast::type::F32Type f32;
|
||||
auto global_var = std::make_unique<ast::Variable>(
|
||||
Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kInput,
|
||||
&f32);
|
||||
auto global_var =
|
||||
create<ast::Variable>(Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kInput, &f32);
|
||||
global_var->set_is_const(true);
|
||||
|
||||
mod()->AddGlobalVariable(std::move(global_var));
|
||||
|
@ -273,9 +269,9 @@ TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
|
|||
TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) {
|
||||
// const gloabl_var: f32;
|
||||
ast::type::F32Type f32;
|
||||
auto global_var = std::make_unique<ast::Variable>(
|
||||
Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kNone,
|
||||
&f32);
|
||||
auto global_var =
|
||||
create<ast::Variable>(Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kNone, &f32);
|
||||
global_var->set_is_const(true);
|
||||
|
||||
mod()->AddGlobalVariable(std::move(global_var));
|
||||
|
@ -289,24 +285,22 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
|
|||
// not_global_var = 3.14f;
|
||||
// }
|
||||
ast::type::F32Type f32;
|
||||
auto global_var = std::make_unique<ast::Variable>(
|
||||
"global_var", ast::StorageClass::kPrivate, &f32);
|
||||
global_var->set_constructor(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.1)));
|
||||
auto global_var =
|
||||
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));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "not_global_var");
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.14f));
|
||||
auto lhs = create<ast::IdentifierExpression>(Source{Source::Location{12, 34}},
|
||||
"not_global_var");
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.14f));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
std::make_unique<ast::Function>("my_func", std::move(params), &f32);
|
||||
auto func = create<ast::Function>("my_func", std::move(params), &f32);
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
func->set_body(std::move(body));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
@ -324,28 +318,26 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::VoidType void_type;
|
||||
|
||||
auto global_var = std::make_unique<ast::Variable>(
|
||||
"global_var", ast::StorageClass::kPrivate, &f32);
|
||||
global_var->set_constructor(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.1)));
|
||||
auto global_var =
|
||||
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));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("global_var");
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.14f));
|
||||
auto lhs = create<ast::IdentifierExpression>("global_var");
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.14f));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
std::make_unique<ast::Function>("my_func", std::move(params), &void_type);
|
||||
auto func = create<ast::Function>("my_func", std::move(params), &void_type);
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
@ -358,28 +350,27 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
|
|||
// a = 3.14;
|
||||
// }
|
||||
ast::type::F32Type f32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0)));
|
||||
|
||||
ast::type::BoolType bool_type;
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "a");
|
||||
auto lhs =
|
||||
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "a");
|
||||
auto* lhs_ptr = lhs.get();
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.14f));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.14f));
|
||||
auto* rhs_ptr = rhs.get();
|
||||
|
||||
auto outer_body = std::make_unique<ast::BlockStatement>();
|
||||
auto outer_body = create<ast::BlockStatement>();
|
||||
outer_body->append(
|
||||
std::make_unique<ast::IfStatement>(std::move(cond), std::move(body)));
|
||||
outer_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
create<ast::IfStatement>(std::move(cond), std::move(body)));
|
||||
outer_body->append(create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(outer_body.get())) << td()->error();
|
||||
|
@ -395,29 +386,27 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
|
|||
// if (true) { a = 3.14; }
|
||||
// }
|
||||
ast::type::F32Type f32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0)));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "a");
|
||||
auto lhs =
|
||||
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "a");
|
||||
auto* lhs_ptr = lhs.get();
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.14f));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.14f));
|
||||
auto* rhs_ptr = rhs.get();
|
||||
ast::type::BoolType bool_type;
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
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)));
|
||||
|
||||
auto outer_body = std::make_unique<ast::BlockStatement>();
|
||||
auto outer_body = create<ast::BlockStatement>();
|
||||
outer_body->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
outer_body->append(
|
||||
std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
outer_body->append(
|
||||
std::make_unique<ast::IfStatement>(std::move(cond), std::move(body)));
|
||||
create<ast::IfStatement>(std::move(cond), std::move(body)));
|
||||
EXPECT_TRUE(td()->DetermineStatements(outer_body.get())) << td()->error();
|
||||
ASSERT_NE(lhs_ptr->result_type(), nullptr);
|
||||
ASSERT_NE(rhs_ptr->result_type(), nullptr);
|
||||
|
@ -429,17 +418,17 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
|
|||
// var global_var1 : i32 = 0;
|
||||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
auto var0 = std::make_unique<ast::Variable>(
|
||||
"global_var0", ast::StorageClass::kPrivate, &f32);
|
||||
var0->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 0.1)));
|
||||
auto var0 =
|
||||
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));
|
||||
|
||||
auto var1 = std::make_unique<ast::Variable>(
|
||||
Source{Source::Location{12, 34}}, "global_var1",
|
||||
ast::StorageClass::kPrivate, &f32);
|
||||
var1->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 0)));
|
||||
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));
|
||||
|
||||
EXPECT_TRUE(v()->ValidateGlobalVariables(mod()->global_variables()))
|
||||
|
@ -451,17 +440,17 @@ TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
|
|||
// var global_var : i32 = 0;
|
||||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
auto var0 = std::make_unique<ast::Variable>(
|
||||
"global_var", ast::StorageClass::kPrivate, &f32);
|
||||
var0->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 0.1)));
|
||||
auto var0 =
|
||||
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));
|
||||
|
||||
auto var1 = std::make_unique<ast::Variable>(
|
||||
Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kPrivate, &f32);
|
||||
var1->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 0)));
|
||||
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));
|
||||
|
||||
EXPECT_FALSE(v()->ValidateGlobalVariables(mod()->global_variables()));
|
||||
|
@ -475,21 +464,20 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
|
|||
// a = 2
|
||||
// }
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
var->set_is_const(true);
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto lhs = create<ast::IdentifierExpression>("a");
|
||||
auto* lhs_ptr = lhs.get();
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2));
|
||||
auto* rhs_ptr = rhs.get();
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(body.get())) << td()->error();
|
||||
|
@ -510,21 +498,18 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
|
|||
ast::type::VoidType void_type;
|
||||
ast::type::F32Type f32;
|
||||
auto global_var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &f32);
|
||||
global_var->set_constructor(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.1)));
|
||||
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));
|
||||
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0)));
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
std::make_unique<ast::Function>("my_func", std::move(params), &void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
auto func = create<ast::Function>("my_func", std::move(params), &void_type);
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(var)));
|
||||
func->set_body(std::move(body));
|
||||
auto* func_ptr = func.get();
|
||||
|
@ -544,23 +529,19 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
|
|||
ast::type::VoidType void_type;
|
||||
ast::type::I32Type i32;
|
||||
ast::type::F32Type f32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
auto var_a_float =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var_a_float->set_constructor(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 0.1)));
|
||||
auto var_a_float = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var_a_float->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 0.1)));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
std::make_unique<ast::Function>("my_func", std::move(params), &void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
auto func = create<ast::Function>("my_func", std::move(params), &void_type);
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(create<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(var_a_float)));
|
||||
func->set_body(std::move(body));
|
||||
auto* func_ptr = func.get();
|
||||
|
@ -578,27 +559,24 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
|
|||
// var a : f32 = 3.14;
|
||||
// }
|
||||
ast::type::F32Type f32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0)));
|
||||
|
||||
ast::type::BoolType bool_type;
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
|
||||
auto var_a_float =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var_a_float->set_constructor(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.14)));
|
||||
auto var_a_float = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var_a_float->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.14)));
|
||||
|
||||
auto outer_body = std::make_unique<ast::BlockStatement>();
|
||||
auto outer_body = create<ast::BlockStatement>();
|
||||
outer_body->append(
|
||||
std::make_unique<ast::IfStatement>(std::move(cond), std::move(body)));
|
||||
outer_body->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
create<ast::IfStatement>(std::move(cond), std::move(body)));
|
||||
outer_body->append(create<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(var_a_float)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(outer_body.get())) << td()->error();
|
||||
|
@ -613,29 +591,26 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
|
|||
// if (true) { var a : f32 = 2.0; }
|
||||
// }
|
||||
ast::type::F32Type f32;
|
||||
auto var_a_float =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var_a_float->set_constructor(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.14)));
|
||||
auto var_a_float = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var_a_float->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.14)));
|
||||
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0)));
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0)));
|
||||
|
||||
ast::type::BoolType bool_type;
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(var)));
|
||||
|
||||
auto outer_body = std::make_unique<ast::BlockStatement>();
|
||||
auto outer_body = create<ast::BlockStatement>();
|
||||
outer_body->append(
|
||||
std::make_unique<ast::VariableDeclStatement>(std::move(var_a_float)));
|
||||
create<ast::VariableDeclStatement>(std::move(var_a_float)));
|
||||
outer_body->append(
|
||||
std::make_unique<ast::IfStatement>(std::move(cond), std::move(body)));
|
||||
create<ast::IfStatement>(std::move(cond), std::move(body)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(outer_body.get())) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(outer_body.get()));
|
||||
|
@ -647,35 +622,31 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
|
|||
// func1 { var a : f32 = 3.0; return; }
|
||||
ast::type::F32Type f32;
|
||||
ast::type::VoidType void_type;
|
||||
auto var0 =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var0->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0)));
|
||||
auto var0 = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var0->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0)));
|
||||
|
||||
auto var1 = std::make_unique<ast::Variable>("a", ast::StorageClass::kNone,
|
||||
&void_type);
|
||||
var1->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0)));
|
||||
auto var1 = create<ast::Variable>("a", ast::StorageClass::kNone, &void_type);
|
||||
var1->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0)));
|
||||
|
||||
ast::VariableList params0;
|
||||
auto func0 =
|
||||
std::make_unique<ast::Function>("func0", std::move(params0), &void_type);
|
||||
auto body0 = std::make_unique<ast::BlockStatement>();
|
||||
body0->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
auto func0 = create<ast::Function>("func0", std::move(params0), &void_type);
|
||||
auto body0 = create<ast::BlockStatement>();
|
||||
body0->append(create<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(var0)));
|
||||
body0->append(std::make_unique<ast::ReturnStatement>());
|
||||
body0->append(create<ast::ReturnStatement>());
|
||||
func0->set_body(std::move(body0));
|
||||
|
||||
ast::VariableList params1;
|
||||
auto func1 =
|
||||
std::make_unique<ast::Function>("func1", std::move(params1), &void_type);
|
||||
auto body1 = std::make_unique<ast::BlockStatement>();
|
||||
body1->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
auto func1 = create<ast::Function>("func1", std::move(params1), &void_type);
|
||||
auto body1 = create<ast::BlockStatement>();
|
||||
body1->append(create<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{13, 34}}, std::move(var1)));
|
||||
body1->append(std::make_unique<ast::ReturnStatement>());
|
||||
body1->append(create<ast::ReturnStatement>());
|
||||
func1->set_body(std::move(body1));
|
||||
func1->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
func1->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
|
||||
mod()->AddFunction(std::move(func0));
|
||||
mod()->AddFunction(std::move(func1));
|
||||
|
@ -690,19 +661,18 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
|
|||
// a = 2;
|
||||
// }
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
|
||||
td()->RegisterVariableForTesting(var.get());
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto lhs = create<ast::IdentifierExpression>("a");
|
||||
auto* lhs_ptr = lhs.get();
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2));
|
||||
auto* rhs_ptr = rhs.get();
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(body.get())) << td()->error();
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define SRC_VALIDATOR_VALIDATOR_TEST_HELPER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "src/ast/type/void_type.h"
|
||||
#include "src/type_determiner.h"
|
||||
|
@ -40,6 +41,13 @@ class ValidatorTestHelper {
|
|||
/// @return a pointer to the test module
|
||||
ast::Module* mod() { return &mod_; }
|
||||
|
||||
/// @return a `std::unique_ptr` to a new `T` constructed with `args`
|
||||
/// @param args the arguments to forward to the constructor for `T`
|
||||
template <typename T, typename... ARGS>
|
||||
std::unique_ptr<T> create(ARGS&&... args) {
|
||||
return std::make_unique<T>(std::forward<ARGS>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<ValidatorImpl> v_;
|
||||
Context ctx_;
|
||||
|
|
Loading…
Reference in New Issue