Remove BlockStatement::append()

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

View File

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

View File

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

View File

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

View File

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