mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
ProgramBuilder: Remove storage parameter from [Global]Const()
Storage classes are unused for constants. Also trim extra arguments to these variable constructor functions that are already defaulted to the same value. Change-Id: Ia0b44364de000bfb8799de15827ce08fcce5f5be Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41541 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
37571bc32d
commit
81a29fe555
@@ -161,7 +161,7 @@ TEST_F(ValidatorBuiltinsTest, Frexp_Vec2) {
|
||||
auto* b = Const("b",
|
||||
create<type::Pointer>(create<type::Vector>(ty.i32(), 2),
|
||||
ast::StorageClass::kWorkgroup),
|
||||
ast::StorageClass::kWorkgroup, Expr("a"), {});
|
||||
Expr("a"), {});
|
||||
RegisterVariable(a);
|
||||
RegisterVariable(b);
|
||||
auto* builtin = Call("frexp", vec2<float>(1.0f, 1.0f), Expr("b"));
|
||||
@@ -180,7 +180,7 @@ TEST_F(ValidatorBuiltinsTest, Frexp_Vec3) {
|
||||
auto* b = Const("b",
|
||||
create<type::Pointer>(create<type::Vector>(ty.i32(), 3),
|
||||
ast::StorageClass::kWorkgroup),
|
||||
ast::StorageClass::kWorkgroup, Expr("a"), {});
|
||||
Expr("a"), {});
|
||||
RegisterVariable(a);
|
||||
RegisterVariable(b);
|
||||
auto* builtin = Call("frexp", vec3<float>(1.0f, 1.0f, 1.0f), Expr("b"));
|
||||
@@ -198,7 +198,7 @@ TEST_F(ValidatorBuiltinsTest, Frexp_Vec4) {
|
||||
auto* b = Const("b",
|
||||
create<type::Pointer>(create<type::Vector>(ty.i32(), 4),
|
||||
ast::StorageClass::kWorkgroup),
|
||||
ast::StorageClass::kWorkgroup, Expr("a"), {});
|
||||
Expr("a"), {});
|
||||
RegisterVariable(a);
|
||||
RegisterVariable(b);
|
||||
auto* builtin = Call("frexp", vec4<float>(1.0f, 1.0f, 1.0f, 1.0f), Expr("b"));
|
||||
@@ -214,7 +214,7 @@ TEST_F(ValidatorBuiltinsTest, Frexp_Vec4) {
|
||||
TEST_F(ValidatorBuiltinsTest, Modf_Scalar) {
|
||||
auto* a = Var("a", ty.f32(), ast::StorageClass::kWorkgroup);
|
||||
auto* b = Const("b", ty.pointer<float>(ast::StorageClass::kWorkgroup),
|
||||
ast::StorageClass::kWorkgroup, Expr("a"), {});
|
||||
Expr("a"), {});
|
||||
RegisterVariable(a);
|
||||
RegisterVariable(b);
|
||||
auto* builtin = Call("modf", 1.0f, Expr("b"));
|
||||
@@ -232,7 +232,7 @@ TEST_F(ValidatorBuiltinsTest, Modf_Vec2) {
|
||||
auto* b = Const("b",
|
||||
create<type::Pointer>(create<type::Vector>(ty.f32(), 2),
|
||||
ast::StorageClass::kWorkgroup),
|
||||
ast::StorageClass::kWorkgroup, Expr("a"), {});
|
||||
Expr("a"), {});
|
||||
RegisterVariable(a);
|
||||
RegisterVariable(b);
|
||||
auto* builtin = Call("modf", vec2<float>(1.0f, 1.0f), Expr("b"));
|
||||
@@ -250,7 +250,7 @@ TEST_F(ValidatorBuiltinsTest, Modf_Vec3) {
|
||||
auto* b = Const("b",
|
||||
create<type::Pointer>(create<type::Vector>(ty.f32(), 3),
|
||||
ast::StorageClass::kWorkgroup),
|
||||
ast::StorageClass::kWorkgroup, Expr("a"), {});
|
||||
Expr("a"), {});
|
||||
RegisterVariable(a);
|
||||
RegisterVariable(b);
|
||||
auto* builtin = Call("modf", vec3<float>(1.0f, 1.0f, 1.0f), Expr("b"));
|
||||
@@ -268,7 +268,7 @@ TEST_F(ValidatorBuiltinsTest, Modf_Vec4) {
|
||||
auto* b = Const("b",
|
||||
create<type::Pointer>(create<type::Vector>(ty.f32(), 4),
|
||||
ast::StorageClass::kWorkgroup),
|
||||
ast::StorageClass::kWorkgroup, Expr("a"), {});
|
||||
Expr("a"), {});
|
||||
RegisterVariable(a);
|
||||
RegisterVariable(b);
|
||||
auto* builtin = Call("modf", vec4<float>(1.0f, 1.0f, 1.0f, 1.0f), Expr("b"));
|
||||
|
||||
@@ -42,8 +42,7 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
|
||||
// switch (a) {
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.14f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.14f));
|
||||
|
||||
ast::CaseStatementList body;
|
||||
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
|
||||
@@ -71,8 +70,7 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
|
||||
// switch (a) {
|
||||
// case 1: {}
|
||||
// }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
ast::CaseSelectorList csl;
|
||||
csl.push_back(Literal(1));
|
||||
@@ -104,8 +102,7 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
|
||||
// case 1: {}
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
ast::CaseSelectorList default_csl_1;
|
||||
@@ -146,8 +143,7 @@ TEST_F(ValidateControlBlockTest,
|
||||
// case 1: {}
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
ast::CaseSelectorList csl;
|
||||
@@ -181,8 +177,7 @@ TEST_F(ValidateControlBlockTest,
|
||||
// case -1: {}
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ty.u32(), ast::StorageClass::kNone, Expr(2u),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.u32(), ast::StorageClass::kNone, Expr(2u));
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
ast::CaseSelectorList csl;
|
||||
@@ -216,8 +211,7 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
|
||||
// case 2, 2: {}
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ty.u32(), ast::StorageClass::kNone, Expr(3u),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.u32(), ast::StorageClass::kNone, Expr(3u));
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
ast::CaseSelectorList csl_1;
|
||||
@@ -257,8 +251,7 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
|
||||
// case 0,1,2,10: {}
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
ast::CaseSelectorList csl_1;
|
||||
@@ -298,8 +291,7 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
|
||||
// switch (a) {
|
||||
// default: { fallthrough; }
|
||||
// }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto* block_default = create<ast::BlockStatement>(
|
||||
@@ -330,8 +322,7 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
|
||||
// default: {}
|
||||
// case 5: {}
|
||||
// }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
|
||||
@@ -362,8 +353,7 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
|
||||
// }
|
||||
|
||||
auto* my_int = ty.alias("MyInt", ty.u32());
|
||||
auto* var = Var("a", my_int, ast::StorageClass::kNone, Expr(2u),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", my_int, ast::StorageClass::kNone, Expr(2u));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
|
||||
|
||||
@@ -38,8 +38,7 @@ class ValidateFunctionTest : public ValidatorTestHelper,
|
||||
TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
|
||||
// [[stage(vertex)]]
|
||||
// fn func -> void { var a:i32 = 2; }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
|
||||
ty.void_(),
|
||||
@@ -74,8 +73,7 @@ TEST_F(ValidateFunctionTest,
|
||||
TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
|
||||
// fn func -> int { var a:i32 = 2; }
|
||||
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
|
||||
ast::StatementList{
|
||||
@@ -201,8 +199,7 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
|
||||
ast::ExpressionList call_params;
|
||||
auto* call_expr = create<ast::CallExpression>(
|
||||
Source{Source::Location{12, 34}}, Expr("func"), call_params);
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, call_expr,
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, call_expr);
|
||||
|
||||
Func("func", ast::VariableList{}, ty.i32(),
|
||||
ast::StatementList{
|
||||
@@ -242,8 +239,7 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
|
||||
// fn vtx_func(a : i32) -> void { return; }
|
||||
|
||||
Func(Source{Source::Location{12, 34}}, "vtx_func",
|
||||
ast::VariableList{Var("a", ty.i32(), ast::StorageClass::kNone, nullptr,
|
||||
ast::VariableDecorationList{})},
|
||||
ast::VariableList{Var("a", ty.i32(), ast::StorageClass::kNone)},
|
||||
ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
|
||||
@@ -64,8 +64,7 @@ TEST_F(ValidatorTest, AssignToScalar_Fail) {
|
||||
// var my_var : i32 = 2;
|
||||
// 1 = my_var;
|
||||
|
||||
auto* var = Var("my_var", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("my_var", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
RegisterVariable(var);
|
||||
|
||||
auto* lhs = Expr(1);
|
||||
@@ -122,8 +121,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) {
|
||||
TEST_F(ValidatorTest, AssignCompatibleTypes_Pass) {
|
||||
// var a :i32 = 2;
|
||||
// a = 2
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
RegisterVariable(var);
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
@@ -146,8 +144,7 @@ TEST_F(ValidatorTest, AssignCompatibleTypesThroughAlias_Pass) {
|
||||
// var a :myint = 2;
|
||||
// a = 2
|
||||
auto* myint = ty.alias("myint", ty.i32());
|
||||
auto* var = Var("a", myint, ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", myint, ast::StorageClass::kNone, Expr(2));
|
||||
RegisterVariable(var);
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
@@ -169,10 +166,8 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInferRHSLoad_Pass) {
|
||||
// var a :i32 = 2;
|
||||
// var b :i32 = 3;
|
||||
// a = b;
|
||||
auto* var_a = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var_b = Var("b", ty.i32(), ast::StorageClass::kNone, Expr(3),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var_a = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
auto* var_b = Var("b", ty.i32(), ast::StorageClass::kNone, Expr(3));
|
||||
RegisterVariable(var_a);
|
||||
RegisterVariable(var_b);
|
||||
|
||||
@@ -197,8 +192,7 @@ TEST_F(ValidatorTest, AssignThroughPointer_Pass) {
|
||||
// b = 2;
|
||||
const auto func = ast::StorageClass::kFunction;
|
||||
auto* var_a = Var("a", ty.i32(), func, Expr(2), {});
|
||||
auto* var_b = Const("b", ty.pointer<int>(func), ast::StorageClass::kNone,
|
||||
Expr("a"), {});
|
||||
auto* var_b = Const("b", ty.pointer<int>(func), Expr("a"), {});
|
||||
RegisterVariable(var_a);
|
||||
RegisterVariable(var_b);
|
||||
|
||||
@@ -223,8 +217,7 @@ TEST_F(ValidatorTest, AssignIncompatibleTypes_Fail) {
|
||||
// a = 2.3;
|
||||
// }
|
||||
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
RegisterVariable(var);
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
@@ -253,8 +246,7 @@ TEST_F(ValidatorTest, AssignThroughPointerWrongeStoreType_Fail) {
|
||||
// b = 2;
|
||||
const auto priv = ast::StorageClass::kFunction;
|
||||
auto* var_a = Var("a", ty.f32(), priv, Expr(2), {});
|
||||
auto* var_b = Const("b", ty.pointer<float>(priv), ast::StorageClass::kNone,
|
||||
Expr("a"), {});
|
||||
auto* var_b = Const("b", ty.pointer<float>(priv), Expr("a"), {});
|
||||
RegisterVariable(var_a);
|
||||
RegisterVariable(var_b);
|
||||
|
||||
@@ -281,8 +273,7 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
|
||||
// var a :i32 = 2;
|
||||
// a = 2
|
||||
// }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2);
|
||||
@@ -308,8 +299,7 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
|
||||
// a = 2.3;
|
||||
// }
|
||||
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2.3f);
|
||||
@@ -342,8 +332,7 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInNestedBlockStatement_Fail) {
|
||||
// }
|
||||
// }
|
||||
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2.3f);
|
||||
@@ -374,10 +363,9 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInNestedBlockStatement_Fail) {
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
|
||||
// var<in> gloabl_var: f32;
|
||||
auto* var =
|
||||
Global(Source{Source::Location{12, 34}}, "global_var", ty.f32(),
|
||||
ast::StorageClass::kInput, nullptr, ast::VariableDecorationList{});
|
||||
// var<in> global_var: f32;
|
||||
auto* var = Global(Source{Source::Location{12, 34}}, "global_var", ty.f32(),
|
||||
ast::StorageClass::kInput);
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
@@ -385,9 +373,9 @@ TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
|
||||
// var gloabl_var: f32;
|
||||
// var global_var: f32;
|
||||
Global(Source{Source::Location{12, 34}}, "global_var", ty.f32(),
|
||||
ast::StorageClass::kNone, nullptr, ast::VariableDecorationList{});
|
||||
ast::StorageClass::kNone);
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
@@ -397,10 +385,11 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
|
||||
// const<in> gloabl_var: f32;
|
||||
GlobalConst(Source{Source::Location{12, 34}}, "global_var", ty.f32(),
|
||||
ast::StorageClass::kInput, nullptr,
|
||||
ast::VariableDecorationList{});
|
||||
// const<in> global_var: f32;
|
||||
AST().AddGlobalVariable(create<ast::Variable>(
|
||||
Source{Source::Location{12, 34}}, Symbols().Register("global_var"),
|
||||
ast::StorageClass::kInput, ty.f32(), true, nullptr,
|
||||
ast::VariableDecorationList{}));
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
@@ -411,9 +400,8 @@ TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) {
|
||||
// const gloabl_var: f32;
|
||||
GlobalConst(Source{Source::Location{12, 34}}, "global_var", ty.f32(),
|
||||
ast::StorageClass::kNone, nullptr, ast::VariableDecorationList{});
|
||||
// const global_var: f32;
|
||||
GlobalConst(Source{Source::Location{12, 34}}, "global_var", ty.f32());
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
@@ -437,8 +425,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariableAfter_Fail) {
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
|
||||
|
||||
Global("global_var", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f),
|
||||
ast::VariableDecorationList{});
|
||||
Global("global_var", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f));
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
@@ -453,8 +440,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
Global("global_var", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f),
|
||||
ast::VariableDecorationList{});
|
||||
Global("global_var", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f));
|
||||
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
@@ -476,8 +462,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
|
||||
// if (true) { var a : f32 = 2.0; }
|
||||
// a = 3.14;
|
||||
// }
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
|
||||
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
@@ -510,8 +495,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
|
||||
// var a : f32 = 2.0;
|
||||
// if (true) { a = 3.14; }
|
||||
// }
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
|
||||
|
||||
SetSource(Source{Source::Location{12, 34}});
|
||||
auto* lhs = Expr("a");
|
||||
@@ -543,8 +527,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableDifferentScope_Fail) {
|
||||
// { var a : f32 = 2.0; }
|
||||
// { a = 3.14; }
|
||||
// }
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
|
||||
auto* first_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
});
|
||||
@@ -576,12 +559,11 @@ TEST_F(ValidatorTest, UsingUndefinedVariableDifferentScope_Fail) {
|
||||
TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
|
||||
// var global_var0 : f32 = 0.1;
|
||||
// var global_var1 : i32 = 0;
|
||||
auto* var0 = Global("global_var0", ty.f32(), ast::StorageClass::kPrivate,
|
||||
Expr(0.1f), ast::VariableDecorationList{});
|
||||
auto* var0 =
|
||||
Global("global_var0", ty.f32(), ast::StorageClass::kPrivate, Expr(0.1f));
|
||||
|
||||
auto* var1 = Global(Source{Source::Location{12, 34}}, "global_var1", ty.f32(),
|
||||
ast::StorageClass::kPrivate, Expr(0),
|
||||
ast::VariableDecorationList{});
|
||||
ast::StorageClass::kPrivate, Expr(0));
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
@@ -592,11 +574,10 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
|
||||
TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
|
||||
// var global_var : f32 = 0.1;
|
||||
// var global_var : i32 = 0;
|
||||
Global("global_var", ty.f32(), ast::StorageClass::kPrivate, Expr(0.1f),
|
||||
ast::VariableDecorationList{});
|
||||
Global("global_var", ty.f32(), ast::StorageClass::kPrivate, Expr(0.1f));
|
||||
|
||||
Global(Source{Source::Location{12, 34}}, "global_var", ty.i32(),
|
||||
ast::StorageClass::kPrivate, Expr(0), ast::VariableDecorationList{});
|
||||
ast::StorageClass::kPrivate, Expr(0));
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
@@ -610,8 +591,7 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
|
||||
// const a :i32 = 2;
|
||||
// a = 2
|
||||
// }
|
||||
auto* var = Const("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Const("a", ty.i32(), Expr(2));
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2);
|
||||
@@ -639,8 +619,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Pass) {
|
||||
// }
|
||||
// var a: f32 = 2.1;
|
||||
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
|
||||
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
@@ -649,8 +628,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Pass) {
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
|
||||
|
||||
Global("a", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f),
|
||||
ast::VariableDecorationList{});
|
||||
Global("a", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f));
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
@@ -664,11 +642,9 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
Global("a", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f),
|
||||
ast::VariableDecorationList{});
|
||||
Global("a", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f));
|
||||
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
|
||||
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
@@ -688,11 +664,9 @@ TEST_F(ValidatorTest, RedeclaredIdentifier_Fail) {
|
||||
// var a :i32 = 2;
|
||||
// var a :f21 = 2.0;
|
||||
// }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
auto* var_a_float = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(0.1f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var_a_float = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(0.1f));
|
||||
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
@@ -713,16 +687,14 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
|
||||
// if (true) { var a : f32 = 2.0; }
|
||||
// var a : f32 = 3.14;
|
||||
// }
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
|
||||
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
});
|
||||
|
||||
auto* var_a_float = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.1f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var_a_float = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.1f));
|
||||
|
||||
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
|
||||
@@ -744,11 +716,9 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
|
||||
// var a : f32 = 3.14;
|
||||
// if (true) { var a : f32 = 2.0; }
|
||||
// }
|
||||
auto* var_a_float = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.1f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var_a_float = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.1f));
|
||||
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
|
||||
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
@@ -820,11 +790,9 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScopeBlock_Fail) {
|
||||
TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
|
||||
// func0 { var a : f32 = 2.0; return; }
|
||||
// func1 { var a : f32 = 3.0; return; }
|
||||
auto* var0 = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var0 = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
|
||||
|
||||
auto* var1 = Var("a", ty.void_(), ast::StorageClass::kNone, Expr(1.0f),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var1 = Var("a", ty.void_(), ast::StorageClass::kNone, Expr(1.0f));
|
||||
|
||||
Func("func0", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
@@ -854,8 +822,7 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
|
||||
// var a :i32;
|
||||
// a = 2;
|
||||
// }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, nullptr,
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, nullptr);
|
||||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2);
|
||||
|
||||
|
||||
@@ -185,9 +185,8 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) {
|
||||
// fn func(a : array<u32>) {}
|
||||
// [[stage(vertex)]] fn main() {}
|
||||
|
||||
auto* param =
|
||||
Var(Source{Source::Location{12, 34}}, "a", ty.array<i32>(),
|
||||
ast::StorageClass::kNone, nullptr, ast::VariableDecorationList{});
|
||||
auto* param = Var(Source{Source::Location{12, 34}}, "a", ty.array<i32>(),
|
||||
ast::StorageClass::kNone);
|
||||
|
||||
Func("func", ast::VariableList{param}, ty.void_(),
|
||||
ast::StatementList{
|
||||
|
||||
Reference in New Issue
Block a user