Cleanup code using RegisterSymbol

This CL goes through and converts things which call RegisterSymbol to
use the helper builders. Several variables are also updated to use the
helper as it will need RegisterSymbol in the near future.

Change-Id: Ib5a8e8be54c1eaad123384fab09f6625421d9fcd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35880
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair
2020-12-16 21:38:40 +00:00
committed by Commit Bot service account
parent e5d288be5e
commit b5839939e1
66 changed files with 1912 additions and 4889 deletions

View File

@@ -45,16 +45,15 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(3.14f),
ast::VariableDecorationList{});
auto* cond = create<ast::IdentifierExpression>(
Source{Source::Location{12, 34}}, mod->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
body.push_back(
create<ast::CaseStatement>(ast::CaseSelectorList{}, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(cond, body),
create<ast::SwitchStatement>(Expr(Source{Source::Location{12, 34}}, "a"),
body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
@@ -72,16 +71,16 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
ast::VariableDecorationList{});
auto* cond = Expr("a");
ast::CaseSelectorList csl;
csl.push_back(Literal(1));
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(
csl, create<ast::BlockStatement>(ast::StatementList{})));
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Source{Source::Location{12, 34}}, cond,
create<ast::SwitchStatement>(Source{Source::Location{12, 34}}, Expr("a"),
body),
});
@@ -103,8 +102,6 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
ast::VariableDecorationList{});
ast::CaseStatementList switch_body;
auto* cond = Expr("a");
ast::CaseSelectorList default_csl_1;
auto* block_default_1 = create<ast::BlockStatement>(ast::StatementList{});
switch_body.push_back(
@@ -122,7 +119,7 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Source{Source::Location{12, 34}}, cond,
create<ast::SwitchStatement>(Source{Source::Location{12, 34}}, Expr("a"),
switch_body),
});
@@ -144,8 +141,6 @@ TEST_F(ValidateControlBlockTest,
ast::VariableDecorationList{});
ast::CaseStatementList switch_body;
auto* cond = Expr("a");
ast::CaseSelectorList csl;
csl.push_back(create<ast::UintLiteral>(ty.u32, 1));
switch_body.push_back(create<ast::CaseStatement>(
@@ -158,7 +153,7 @@ TEST_F(ValidateControlBlockTest,
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(cond, switch_body),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -180,8 +175,6 @@ TEST_F(ValidateControlBlockTest,
ast::VariableDecorationList{});
ast::CaseStatementList switch_body;
auto* cond = Expr("a");
ast::CaseSelectorList csl;
csl.push_back(Literal(-1));
switch_body.push_back(create<ast::CaseStatement>(
@@ -194,7 +187,7 @@ TEST_F(ValidateControlBlockTest,
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(cond, switch_body),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -216,8 +209,6 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
ast::VariableDecorationList{});
ast::CaseStatementList switch_body;
auto* cond = Expr("a");
ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::UintLiteral>(ty.u32, 0));
switch_body.push_back(create<ast::CaseStatement>(
@@ -236,7 +227,7 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(cond, switch_body),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -256,8 +247,6 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
ast::VariableDecorationList{});
ast::CaseStatementList switch_body;
auto* cond = Expr("a");
ast::CaseSelectorList csl_1;
csl_1.push_back(Literal(10));
switch_body.push_back(create<ast::CaseStatement>(
@@ -278,7 +267,7 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(cond, switch_body),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -295,7 +284,6 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
ast::VariableDecorationList{});
auto* cond = Expr("a");
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(
@@ -307,7 +295,7 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(cond, body),
create<ast::SwitchStatement>(Expr("a"), body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -325,7 +313,6 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
ast::VariableDecorationList{});
auto* cond = Expr("a");
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
ast::CaseStatementList body;
@@ -338,7 +325,7 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(cond, body),
create<ast::SwitchStatement>(Expr("a"), body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_TRUE(v()->ValidateStatements(block)) << v()->error();
@@ -351,12 +338,10 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
// default: {}
// }
ast::type::Alias my_int{mod->RegisterSymbol("MyInt"), "MyInt", ty.u32};
auto* var = Var("a", ast::StorageClass::kNone, &my_int, Expr(2u),
auto* my_int = ty.alias("MyInt", ty.u32);
auto* var = Var("a", ast::StorageClass::kNone, my_int, Expr(2u),
ast::VariableDecorationList{});
auto* cond = Expr("a");
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
ast::CaseStatementList body;
@@ -365,9 +350,9 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
auto* block = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(cond, body),
create<ast::SwitchStatement>(Expr("a"), body),
});
mod->AddConstructedType(&my_int);
mod->AddConstructedType(my_int);
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_TRUE(v()->ValidateStatements(block)) << v()->error();

View File

@@ -277,20 +277,16 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
mod->AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate, ty.f32,
Expr(2.1f), ast::VariableDecorationList{}));
auto* lhs = create<ast::IdentifierExpression>(
mod->RegisterSymbol("global_var"), "global_var");
auto* rhs = Expr(3.14f);
auto* func =
Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs),
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
auto* func = Func(
"my_func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}},
Expr("global_var"), Expr(3.14f)),
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
mod->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();

View File

@@ -49,9 +49,9 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsLast_Pass) {
Member("rt", ty.array<f32>())},
decos);
ast::type::Struct struct_type(mod->RegisterSymbol("Foo"), "Foo", st);
auto* struct_type = ty.struct_("Foo", st);
mod->AddConstructedType(&struct_type);
mod->AddConstructedType(struct_type);
EXPECT_TRUE(v()->ValidateConstructedTypes(mod->constructed_types()));
}
@@ -67,9 +67,8 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsLastNoBlock_Fail) {
Member("rt", ty.array<f32>())},
decos);
ast::type::Struct struct_type(mod->RegisterSymbol("Foo"), "Foo", st);
mod->AddConstructedType(&struct_type);
auto* struct_type = ty.struct_("Foo", st);
mod->AddConstructedType(struct_type);
EXPECT_FALSE(v()->ValidateConstructedTypes(mod->constructed_types()));
EXPECT_EQ(v()->error(),
"v-0031: a struct containing a runtime-sized array must be "
@@ -90,9 +89,9 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsNotLast_Fail) {
Member("vf", ty.f32)},
decos);
ast::type::Struct struct_type(mod->RegisterSymbol("Foo"), "Foo", st);
auto* struct_type = ty.struct_("Foo", st);
mod->AddConstructedType(&struct_type);
mod->AddConstructedType(struct_type);
EXPECT_FALSE(v()->ValidateConstructedTypes(mod->constructed_types()));
EXPECT_EQ(v()->error(),
"v-0015: runtime arrays may only appear as the last member "
@@ -107,16 +106,15 @@ TEST_F(ValidatorTypeTest, AliasRuntimeArrayIsNotLast_Fail) {
// a: u32;
//}
ast::type::Alias alias{mod->RegisterSymbol("RTArr"), "RTArr",
ty.array<u32>()};
auto* alias = ty.alias("RTArr", ty.array<u32>());
ast::StructDecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>());
auto* st = create<ast::Struct>(
ast::StructMemberList{Member("b", &alias), Member("a", ty.u32)}, decos);
ast::StructMemberList{Member("b", alias), Member("a", ty.u32)}, decos);
ast::type::Struct struct_type(mod->RegisterSymbol("s"), "s", st);
mod->AddConstructedType(&struct_type);
auto* struct_type = ty.struct_("s", st);
mod->AddConstructedType(struct_type);
EXPECT_FALSE(v()->ValidateConstructedTypes(mod->constructed_types()));
EXPECT_EQ(v()->error(),
"v-0015: runtime arrays may only appear as the last member "
@@ -131,16 +129,15 @@ TEST_F(ValidatorTypeTest, AliasRuntimeArrayIsLast_Pass) {
// b: RTArr;
//}
ast::type::Alias alias{mod->RegisterSymbol("RTArr"), "RTArr",
ty.array<u32>()};
auto* alias = ty.alias("RTArr", ty.array<u32>());
ast::StructDecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>());
auto* st = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.u32), Member("b", &alias)}, decos);
ast::StructMemberList{Member("a", ty.u32), Member("b", alias)}, decos);
ast::type::Struct struct_type(mod->RegisterSymbol("s"), "s", st);
mod->AddConstructedType(&struct_type);
auto* struct_type = ty.struct_("s", st);
mod->AddConstructedType(struct_type);
EXPECT_TRUE(v()->ValidateConstructedTypes(mod->constructed_types()));
}