From 81a29fe5558289f8b6898c704190f860c0cfb67a Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 17 Feb 2021 00:26:52 +0000 Subject: [PATCH] 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 Reviewed-by: dan sinclair Reviewed-by: David Neto --- src/ast/variable_test.cc | 9 +- src/inspector/inspector_test.cc | 12 +- src/program_builder.h | 24 ++-- src/transform/hlsl.cc | 3 +- src/type_determiner_test.cc | 35 ++--- src/validator/validator_builtins_test.cc | 14 +- src/validator/validator_control_block_test.cc | 30 ++--- src/validator/validator_function_test.cc | 12 +- src/validator/validator_test.cc | 127 +++++++----------- src/validator/validator_type_test.cc | 5 +- src/writer/hlsl/generator_impl_binary_test.cc | 3 +- .../hlsl/generator_impl_function_test.cc | 21 ++- src/writer/hlsl/generator_impl_loop_test.cc | 3 +- .../generator_impl_module_constant_test.cc | 8 +- ...rator_impl_variable_decl_statement_test.cc | 14 +- .../msl/generator_impl_function_test.cc | 22 +-- src/writer/msl/generator_impl_loop_test.cc | 3 +- .../generator_impl_module_constant_test.cc | 6 +- ...rator_impl_variable_decl_statement_test.cc | 9 +- .../spirv/builder_accessor_expression_test.cc | 8 +- .../spirv/builder_binary_expression_test.cc | 16 +-- src/writer/spirv/builder_function_test.cc | 4 +- .../spirv/builder_function_variable_test.cc | 21 +-- .../spirv/builder_global_variable_test.cc | 12 +- .../spirv/builder_ident_expression_test.cc | 9 +- .../wgsl/generator_impl_function_test.cc | 6 +- .../wgsl/generator_impl_global_decl_test.cc | 3 +- .../wgsl/generator_impl_variable_test.cc | 7 +- 28 files changed, 175 insertions(+), 271 deletions(-) diff --git a/src/ast/variable_test.cc b/src/ast/variable_test.cc index 48a4c1981e..6f4369af7d 100644 --- a/src/ast/variable_test.cc +++ b/src/ast/variable_test.cc @@ -73,8 +73,7 @@ TEST_F(VariableTest, IsValid) { } TEST_F(VariableTest, IsValid_WithConstructor) { - auto* v = Var("my_var", ty.i32(), StorageClass::kNone, Expr("ident"), - ast::VariableDecorationList{}); + auto* v = Var("my_var", ty.i32(), StorageClass::kNone, Expr("ident")); EXPECT_TRUE(v->IsValid()); } @@ -94,14 +93,12 @@ TEST_F(VariableTest, IsValid_MissingBoth) { } TEST_F(VariableTest, IsValid_InvalidConstructor) { - auto* v = Var("my_var", ty.i32(), StorageClass::kNone, Expr(""), - ast::VariableDecorationList{}); + auto* v = Var("my_var", ty.i32(), StorageClass::kNone, Expr("")); EXPECT_FALSE(v->IsValid()); } TEST_F(VariableTest, to_str) { - auto* v = Var("my_var", ty.f32(), StorageClass::kFunction, nullptr, - ast::VariableDecorationList{}); + auto* v = Var("my_var", ty.f32(), StorageClass::kFunction); EXPECT_EQ(str(v), R"(Variable{ my_var function diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index 6fc37cb1b5..ca6b110385 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -175,7 +175,7 @@ class InspectorHelper : public ProgramBuilder { constructor = create(MakeLiteral(type, val)); } - GlobalConst(name, type, ast::StorageClass::kNone, constructor, + GlobalConst(name, type, constructor, ast::VariableDecorationList{ create(id), }); @@ -319,11 +319,11 @@ class InspectorHelper : public ProgramBuilder { ast::StorageClass storage_class, uint32_t group, uint32_t binding) { - GlobalConst(name, type, storage_class, nullptr, - ast::VariableDecorationList{ - create(binding), - create(group), - }); + Global(name, type, storage_class, nullptr, + ast::VariableDecorationList{ + create(binding), + create(group), + }); } /// Adds an uniform buffer variable to the program diff --git a/src/program_builder.h b/src/program_builder.h index 7f78baefd3..f0ecfb3471 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -815,56 +815,51 @@ class ProgramBuilder { /// @param name the variable name /// @param type the variable type - /// @param storage the variable storage class /// @param constructor optional constructor expression /// @param decorations optional variable decorations /// @returns a constant `ast::Variable` with the given name, storage and type ast::Variable* Const(const std::string& name, type::Type* type, - ast::StorageClass storage, ast::Expression* constructor = nullptr, ast::VariableDecorationList decorations = {}) { - return create(Symbols().Register(name), storage, type, true, + return create(Symbols().Register(name), + ast::StorageClass::kNone, type, true, constructor, decorations); } /// @param source the variable source /// @param name the variable name /// @param type the variable type - /// @param storage the variable storage class /// @param constructor optional constructor expression /// @param decorations optional variable decorations /// @returns a constant `ast::Variable` with the given name, storage and type ast::Variable* Const(const Source& source, const std::string& name, type::Type* type, - ast::StorageClass storage, ast::Expression* constructor = nullptr, ast::VariableDecorationList decorations = {}) { - return create(source, Symbols().Register(name), storage, - type, true, constructor, decorations); + return create(source, Symbols().Register(name), + ast::StorageClass::kNone, type, true, + constructor, decorations); } /// @param symbol the variable symbol /// @param type the variable type - /// @param storage the variable storage class /// @param constructor optional constructor expression /// @param decorations optional variable decorations /// @returns a constant `ast::Variable` with the given symbol, storage and /// type ast::Variable* Const(Symbol symbol, type::Type* type, - ast::StorageClass storage, ast::Expression* constructor = nullptr, ast::VariableDecorationList decorations = {}) { - return create(symbol, storage, type, true, constructor, - decorations); + return create(symbol, ast::StorageClass::kNone, type, true, + constructor, decorations); } /// @param source the variable source /// @param symbol the variable symbol /// @param type the variable type - /// @param storage the variable storage class /// @param constructor optional constructor expression /// @param decorations optional variable decorations /// @returns a constant `ast::Variable` with the given symbol, storage and @@ -872,11 +867,10 @@ class ProgramBuilder { ast::Variable* Const(const Source& source, Symbol symbol, type::Type* type, - ast::StorageClass storage, ast::Expression* constructor = nullptr, ast::VariableDecorationList decorations = {}) { - return create(source, symbol, storage, type, true, - constructor, decorations); + return create(source, symbol, ast::StorageClass::kNone, type, + true, constructor, decorations); } /// @param args the arguments to pass to Var() diff --git a/src/transform/hlsl.cc b/src/transform/hlsl.cc index da2fe0c065..67651e6bfb 100644 --- a/src/transform/hlsl.cc +++ b/src/transform/hlsl.cc @@ -83,8 +83,7 @@ void Hlsl::PromoteArrayInitializerToConstVar(CloneContext& ctx) const { // Clone the array initializer auto* dst_init = ctx.Clone(src_init); // Construct the constant that holds the array - auto* dst_var = ctx.dst->Const( - dst_symbol, dst_array_ty, ast::StorageClass::kFunction, dst_init); + auto* dst_var = ctx.dst->Const(dst_symbol, dst_array_ty, dst_init); // Construct the variable declaration statement auto* dst_var_decl = ctx.dst->create(dst_var); diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 906ded1e47..243d1720b6 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -401,8 +401,7 @@ TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) { } TEST_F(TypeDeterminerTest, Stmt_VariableDecl) { - 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)); auto* init = var->constructor(); auto* decl = create(var); @@ -416,8 +415,7 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl) { TEST_F(TypeDeterminerTest, Stmt_VariableDecl_ModuleScope) { auto* init = Expr(2); - Global("my_var", ty.i32(), ast::StorageClass::kNone, init, - ast::VariableDecorationList{}); + Global("my_var", ty.i32(), ast::StorageClass::kNone, init); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -439,14 +437,12 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) { ast::VariableList params; // Declare i32 "foo" inside a block - auto* foo_i32 = Var("foo", ty.i32(), ast::StorageClass::kNone, Expr(2), - ast::VariableDecorationList{}); + auto* foo_i32 = Var("foo", ty.i32(), ast::StorageClass::kNone, Expr(2)); auto* foo_i32_init = foo_i32->constructor(); auto* foo_i32_decl = create(foo_i32); // Reference "foo" inside the block - auto* bar_i32 = Var("bar", ty.i32(), ast::StorageClass::kNone, Expr("foo"), - ast::VariableDecorationList{}); + auto* bar_i32 = Var("bar", ty.i32(), ast::StorageClass::kNone, Expr("foo")); auto* bar_i32_init = bar_i32->constructor(); auto* bar_i32_decl = create(bar_i32); @@ -454,14 +450,12 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) { ast::StatementList{foo_i32_decl, bar_i32_decl}); // Declare f32 "foo" at function scope - auto* foo_f32 = Var("foo", ty.f32(), ast::StorageClass::kNone, Expr(2.f), - ast::VariableDecorationList{}); + auto* foo_f32 = Var("foo", ty.f32(), ast::StorageClass::kNone, Expr(2.f)); auto* foo_f32_init = foo_f32->constructor(); auto* foo_f32_decl = create(foo_f32); // Reference "foo" at function scope - auto* bar_f32 = Var("bar", ty.f32(), ast::StorageClass::kNone, Expr("foo"), - ast::VariableDecorationList{}); + auto* bar_f32 = Var("bar", ty.f32(), ast::StorageClass::kNone, Expr("foo")); auto* bar_f32_init = bar_f32->constructor(); auto* bar_f32_decl = create(bar_f32); @@ -498,22 +492,19 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) { ast::VariableList params; // Declare i32 "foo" inside a function - auto* fn_i32 = Var("foo", ty.i32(), ast::StorageClass::kNone, Expr(2), - ast::VariableDecorationList{}); + auto* fn_i32 = Var("foo", ty.i32(), ast::StorageClass::kNone, Expr(2)); auto* fn_i32_init = fn_i32->constructor(); auto* fn_i32_decl = create(fn_i32); Func("func_i32", params, ty.i32(), ast::StatementList{fn_i32_decl}, ast::FunctionDecorationList{}); // Declare f32 "foo" at module scope - auto* mod_f32 = Var("foo", ty.f32(), ast::StorageClass::kNone, Expr(2.f), - ast::VariableDecorationList{}); + auto* mod_f32 = Var("foo", ty.f32(), ast::StorageClass::kNone, Expr(2.f)); auto* mod_init = mod_f32->constructor(); AST().AddGlobalVariable(mod_f32); // Reference "foo" in another function - auto* fn_f32 = Var("bar", ty.f32(), ast::StorageClass::kNone, Expr("foo"), - ast::VariableDecorationList{}); + auto* fn_f32 = Var("bar", ty.f32(), ast::StorageClass::kNone, Expr("foo")); auto* fn_f32_init = fn_f32->constructor(); auto* fn_f32_decl = create(fn_f32); Func("func_f32", params, ty.f32(), ast::StatementList{fn_f32_decl}, @@ -576,7 +567,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Alias_Array) { } TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array_Constant) { - GlobalConst("my_var", ty.array(), ast::StorageClass::kFunction); + GlobalConst("my_var", ty.array()); auto* acc = IndexAccessor("my_var", 2); WrapInFunction(acc); @@ -748,7 +739,7 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalVariable) { } TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalConstant) { - auto* my_var = GlobalConst("my_var", ty.f32(), ast::StorageClass::kNone); + auto* my_var = GlobalConst("my_var", ty.f32()); auto* ident = Expr("my_var"); WrapInFunction(ident); @@ -763,7 +754,7 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalConstant) { TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable_Const) { auto* my_var_a = Expr("my_var"); auto* my_var_b = Expr("my_var"); - auto* var = Const("my_var", ty.f32(), ast::StorageClass::kNone); + auto* var = Const("my_var", ty.f32()); auto* assign = create(my_var_a, my_var_b); Func("my_func", ast::VariableList{}, ty.f32(), @@ -1845,7 +1836,7 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) { } TEST_F(TypeDeterminerTest, StorageClass_DoesNotSetOnConst) { - auto* var = Const("var", ty.i32(), ast::StorageClass::kNone); + auto* var = Const("var", ty.i32()); auto* stmt = create(var); Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt}, ast::FunctionDecorationList{}); diff --git a/src/validator/validator_builtins_test.cc b/src/validator/validator_builtins_test.cc index dee228b049..b4e5e0e8ce 100644 --- a/src/validator/validator_builtins_test.cc +++ b/src/validator/validator_builtins_test.cc @@ -161,7 +161,7 @@ TEST_F(ValidatorBuiltinsTest, Frexp_Vec2) { auto* b = Const("b", create(create(ty.i32(), 2), ast::StorageClass::kWorkgroup), - ast::StorageClass::kWorkgroup, Expr("a"), {}); + Expr("a"), {}); RegisterVariable(a); RegisterVariable(b); auto* builtin = Call("frexp", vec2(1.0f, 1.0f), Expr("b")); @@ -180,7 +180,7 @@ TEST_F(ValidatorBuiltinsTest, Frexp_Vec3) { auto* b = Const("b", create(create(ty.i32(), 3), ast::StorageClass::kWorkgroup), - ast::StorageClass::kWorkgroup, Expr("a"), {}); + Expr("a"), {}); RegisterVariable(a); RegisterVariable(b); auto* builtin = Call("frexp", vec3(1.0f, 1.0f, 1.0f), Expr("b")); @@ -198,7 +198,7 @@ TEST_F(ValidatorBuiltinsTest, Frexp_Vec4) { auto* b = Const("b", create(create(ty.i32(), 4), ast::StorageClass::kWorkgroup), - ast::StorageClass::kWorkgroup, Expr("a"), {}); + Expr("a"), {}); RegisterVariable(a); RegisterVariable(b); auto* builtin = Call("frexp", vec4(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(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(create(ty.f32(), 2), ast::StorageClass::kWorkgroup), - ast::StorageClass::kWorkgroup, Expr("a"), {}); + Expr("a"), {}); RegisterVariable(a); RegisterVariable(b); auto* builtin = Call("modf", vec2(1.0f, 1.0f), Expr("b")); @@ -250,7 +250,7 @@ TEST_F(ValidatorBuiltinsTest, Modf_Vec3) { auto* b = Const("b", create(create(ty.f32(), 3), ast::StorageClass::kWorkgroup), - ast::StorageClass::kWorkgroup, Expr("a"), {}); + Expr("a"), {}); RegisterVariable(a); RegisterVariable(b); auto* builtin = Call("modf", vec3(1.0f, 1.0f, 1.0f), Expr("b")); @@ -268,7 +268,7 @@ TEST_F(ValidatorBuiltinsTest, Modf_Vec4) { auto* b = Const("b", create(create(ty.f32(), 4), ast::StorageClass::kWorkgroup), - ast::StorageClass::kWorkgroup, Expr("a"), {}); + Expr("a"), {}); RegisterVariable(a); RegisterVariable(b); auto* builtin = Call("modf", vec4(1.0f, 1.0f, 1.0f, 1.0f), Expr("b")); diff --git a/src/validator/validator_control_block_test.cc b/src/validator/validator_control_block_test.cc index 5852ad850c..26fc50647f 100644 --- a/src/validator/validator_control_block_test.cc +++ b/src/validator/validator_control_block_test.cc @@ -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::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( @@ -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::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::StatementList{}); diff --git a/src/validator/validator_function_test.cc b/src/validator/validator_function_test.cc index 74e4bb2c35..de6a1462e1 100644 --- a/src/validator/validator_function_test.cc +++ b/src/validator/validator_function_test.cc @@ -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( 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(), diff --git a/src/validator/validator_test.cc b/src/validator/validator_test.cc index 6ca6e6e821..d74b1f4de3 100644 --- a/src/validator/validator_test.cc +++ b/src/validator/validator_test.cc @@ -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(func), ast::StorageClass::kNone, - Expr("a"), {}); + auto* var_b = Const("b", ty.pointer(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(priv), ast::StorageClass::kNone, - Expr("a"), {}); + auto* var_b = Const("b", ty.pointer(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 gloabl_var: f32; - auto* var = - Global(Source{Source::Location{12, 34}}, "global_var", ty.f32(), - ast::StorageClass::kInput, nullptr, ast::VariableDecorationList{}); + // var 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 gloabl_var: f32; - GlobalConst(Source{Source::Location{12, 34}}, "global_var", ty.f32(), - ast::StorageClass::kInput, nullptr, - ast::VariableDecorationList{}); + // const global_var: f32; + AST().AddGlobalVariable(create( + 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::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::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::StatementList{ create(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::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::StatementList{ create(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::StatementList{ create(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::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); diff --git a/src/validator/validator_type_test.cc b/src/validator/validator_type_test.cc index 18fa10d064..d61934ced0 100644 --- a/src/validator/validator_type_test.cc +++ b/src/validator/validator_type_test.cc @@ -185,9 +185,8 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) { // fn func(a : array) {} // [[stage(vertex)]] fn main() {} - auto* param = - Var(Source{Source::Location{12, 34}}, "a", ty.array(), - ast::StorageClass::kNone, nullptr, ast::VariableDecorationList{}); + auto* param = Var(Source{Source::Location{12, 34}}, "a", ty.array(), + ast::StorageClass::kNone); Func("func", ast::VariableList{param}, ty.void_(), ast::StatementList{ diff --git a/src/writer/hlsl/generator_impl_binary_test.cc b/src/writer/hlsl/generator_impl_binary_test.cc index 425d308a10..d0137da747 100644 --- a/src/writer/hlsl/generator_impl_binary_test.cc +++ b/src/writer/hlsl/generator_impl_binary_test.cc @@ -430,8 +430,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) { "a", ty.bool_(), ast::StorageClass::kFunction, create( ast::BinaryOp::kLogicalOr, - create(ast::BinaryOp::kLogicalAnd, b, c), d), - ast::VariableDecorationList{}); + create(ast::BinaryOp::kLogicalAnd, b, c), d)); auto* expr = create(var); diff --git a/src/writer/hlsl/generator_impl_function_test.cc b/src/writer/hlsl/generator_impl_function_test.cc index dceacf9285..f60289c635 100644 --- a/src/writer/hlsl/generator_impl_function_test.cc +++ b/src/writer/hlsl/generator_impl_function_test.cc @@ -262,7 +262,7 @@ TEST_F(HlslGeneratorImplTest_Function, }); auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - MemberAccessor("coord", "x"), ast::VariableDecorationList{}); + MemberAccessor("coord", "x")); Func("frag_main", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -306,8 +306,7 @@ TEST_F(HlslGeneratorImplTest_Function, auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, create( - MemberAccessor("uniforms", "coord"), Expr("x")), - ast::VariableDecorationList{}); + MemberAccessor("uniforms", "coord"), Expr("x"))); Func("frag_main", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -352,7 +351,7 @@ TEST_F(HlslGeneratorImplTest_Function, }); auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - MemberAccessor("coord", "b"), ast::VariableDecorationList{}); + MemberAccessor("coord", "b")); Func("frag_main", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -393,7 +392,7 @@ TEST_F(HlslGeneratorImplTest_Function, }); auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - MemberAccessor("coord", "b"), ast::VariableDecorationList{}); + MemberAccessor("coord", "b")); Func("frag_main", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -679,8 +678,8 @@ TEST_F(HlslGeneratorImplTest_Function, }, ast::FunctionDecorationList{}); - auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - Call("sub_func", 1.0f), ast::VariableDecorationList{}); + auto* var = + Var("v", ty.f32(), ast::StorageClass::kFunction, Call("sub_func", 1.0f)); Func("frag_main", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -727,8 +726,8 @@ TEST_F(HlslGeneratorImplTest_Function, }, ast::FunctionDecorationList{}); - auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - Call("sub_func", 1.0f), ast::VariableDecorationList{}); + auto* var = + Var("v", ty.f32(), ast::StorageClass::kFunction, Call("sub_func", 1.0f)); Func("frag_main", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -916,7 +915,7 @@ TEST_F(HlslGeneratorImplTest_Function, { auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - MemberAccessor("data", "d"), ast::VariableDecorationList{}); + MemberAccessor("data", "d")); Func("a", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -930,7 +929,7 @@ TEST_F(HlslGeneratorImplTest_Function, { auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - MemberAccessor("data", "d"), ast::VariableDecorationList{}); + MemberAccessor("data", "d")); Func("b", ast::VariableList{}, ty.void_(), ast::StatementList{ diff --git a/src/writer/hlsl/generator_impl_loop_test.cc b/src/writer/hlsl/generator_impl_loop_test.cc index c4ab5c48ae..1313f17ab2 100644 --- a/src/writer/hlsl/generator_impl_loop_test.cc +++ b/src/writer/hlsl/generator_impl_loop_test.cc @@ -162,8 +162,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) { Global("rhs", ty.f32(), ast::StorageClass::kNone); - auto* var = Var("lhs", ty.f32(), ast::StorageClass::kFunction, Expr(2.4f), - ast::VariableDecorationList{}); + auto* var = Var("lhs", ty.f32(), ast::StorageClass::kFunction, Expr(2.4f)); auto* body = create(ast::StatementList{ create(var), diff --git a/src/writer/hlsl/generator_impl_module_constant_test.cc b/src/writer/hlsl/generator_impl_module_constant_test.cc index 0cc4430686..ca988df24d 100644 --- a/src/writer/hlsl/generator_impl_module_constant_test.cc +++ b/src/writer/hlsl/generator_impl_module_constant_test.cc @@ -33,9 +33,7 @@ namespace { using HlslGeneratorImplTest_ModuleConstant = TestHelper; TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) { - auto* var = - Const("pos", ty.array(), ast::StorageClass::kNone, - array(1.f, 2.f, 3.f), ast::VariableDecorationList{}); + auto* var = Const("pos", ty.array(), array(1.f, 2.f, 3.f)); GeneratorImpl& gen = Build(); @@ -44,7 +42,7 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) { } TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant) { - auto* var = Const("pos", ty.f32(), ast::StorageClass::kNone, Expr(3.0f), + auto* var = Const("pos", ty.f32(), Expr(3.0f), ast::VariableDecorationList{ create(23), }); @@ -61,7 +59,7 @@ static const float pos = WGSL_SPEC_CONSTANT_23; } TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant_NoConstructor) { - auto* var = Const("pos", ty.f32(), ast::StorageClass::kNone, nullptr, + auto* var = Const("pos", ty.f32(), nullptr, ast::VariableDecorationList{ create(23), }); diff --git a/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc b/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc index d784fa9c3b..20ec539104 100644 --- a/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc @@ -46,7 +46,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) { } TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) { - auto* var = Const("a", ty.f32(), ast::StorageClass::kNone); + auto* var = Const("a", ty.f32()); auto* stmt = create(var); @@ -101,8 +101,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) { TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Initializer_Private) { Global("initializer", ty.f32(), ast::StorageClass::kNone); - auto* var = Global("a", ty.f32(), ast::StorageClass::kPrivate, - Expr("initializer"), ast::VariableDecorationList{}); + auto* var = + Global("a", ty.f32(), ast::StorageClass::kPrivate, Expr("initializer")); auto* stmt = create(var); @@ -115,8 +115,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Initializer_ZeroVec) { - auto* var = Var("a", ty.vec3(), ast::StorageClass::kFunction, - vec3(), ast::VariableDecorationList{}); + auto* var = + Var("a", ty.vec3(), ast::StorageClass::kFunction, vec3()); auto* stmt = create(var); WrapInFunction(stmt); @@ -130,8 +130,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Initializer_ZeroMat) { - auto* var = Var("a", ty.mat2x3(), ast::StorageClass::kFunction, - mat2x3(), ast::VariableDecorationList{}); + auto* var = + Var("a", ty.mat2x3(), ast::StorageClass::kFunction, mat2x3()); auto* stmt = create(var); WrapInFunction(stmt); diff --git a/src/writer/msl/generator_impl_function_test.cc b/src/writer/msl/generator_impl_function_test.cc index 05d51ccf00..69f2ced1e9 100644 --- a/src/writer/msl/generator_impl_function_test.cc +++ b/src/writer/msl/generator_impl_function_test.cc @@ -259,7 +259,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) { create(1)}); auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - MemberAccessor("coord", "x"), ast::VariableDecorationList{}); + MemberAccessor("coord", "x")); Func("frag_main", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -300,7 +300,7 @@ TEST_F(MslGeneratorImplTest, create(1)}); auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - MemberAccessor("coord", "b"), ast::VariableDecorationList{}); + MemberAccessor("coord", "b")); Func("frag_main", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -345,7 +345,7 @@ TEST_F(MslGeneratorImplTest, create(1)}); auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - MemberAccessor("coord", "b"), ast::VariableDecorationList{}); + MemberAccessor("coord", "b")); Func("frag_main", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -555,8 +555,8 @@ TEST_F(MslGeneratorImplTest, ast::ExpressionList expr; expr.push_back(Expr(1.0f)); - auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - Call("sub_func", 1.0f), ast::VariableDecorationList{}); + auto* var = + Var("v", ty.f32(), ast::StorageClass::kFunction, Call("sub_func", 1.0f)); Func("frag_main", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -607,8 +607,8 @@ TEST_F(MslGeneratorImplTest, Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); - auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - Call("sub_func", 1.0f), ast::VariableDecorationList{}); + auto* var = + Var("v", ty.f32(), ast::StorageClass::kFunction, Call("sub_func", 1.0f)); Func("frag_main", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -667,8 +667,8 @@ TEST_F(MslGeneratorImplTest, ast::ExpressionList expr; expr.push_back(Expr(1.0f)); - auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - Call("sub_func", 1.0f), ast::VariableDecorationList{}); + auto* var = + Var("v", ty.f32(), ast::StorageClass::kFunction, Call("sub_func", 1.0f)); Func("frag_main", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -822,7 +822,7 @@ TEST_F(MslGeneratorImplTest, { auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - MemberAccessor("data", "d"), ast::VariableDecorationList{}); + MemberAccessor("data", "d")); Func("a", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -836,7 +836,7 @@ TEST_F(MslGeneratorImplTest, { auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - MemberAccessor("data", "d"), ast::VariableDecorationList{}); + MemberAccessor("data", "d")); Func("b", ast::VariableList{}, ty.void_(), ast::StatementList{create(var), diff --git a/src/writer/msl/generator_impl_loop_test.cc b/src/writer/msl/generator_impl_loop_test.cc index 53da280502..b21c1def55 100644 --- a/src/writer/msl/generator_impl_loop_test.cc +++ b/src/writer/msl/generator_impl_loop_test.cc @@ -159,8 +159,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) { Global("rhs", ty.f32(), ast::StorageClass::kNone); - auto* var = Var("lhs", ty.f32(), ast::StorageClass::kFunction, Expr(2.4f), - ast::VariableDecorationList{}); + auto* var = Var("lhs", ty.f32(), ast::StorageClass::kFunction, Expr(2.4f)); auto* body = create(ast::StatementList{ create(var), diff --git a/src/writer/msl/generator_impl_module_constant_test.cc b/src/writer/msl/generator_impl_module_constant_test.cc index 5ad0da7f78..c59527bb11 100644 --- a/src/writer/msl/generator_impl_module_constant_test.cc +++ b/src/writer/msl/generator_impl_module_constant_test.cc @@ -35,9 +35,7 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) { - auto* var = - Const("pos", ty.array(), ast::StorageClass::kNone, - array(1.f, 2.f, 3.f), ast::VariableDecorationList{}); + auto* var = Const("pos", ty.array(), array(1.f, 2.f, 3.f)); GeneratorImpl& gen = Build(); @@ -46,7 +44,7 @@ TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) { } TEST_F(MslGeneratorImplTest, Emit_SpecConstant) { - auto* var = Const("pos", ty.f32(), ast::StorageClass::kNone, Expr(3.f), + auto* var = Const("pos", ty.f32(), Expr(3.f), ast::VariableDecorationList{ create(23), }); diff --git a/src/writer/msl/generator_impl_variable_decl_statement_test.cc b/src/writer/msl/generator_impl_variable_decl_statement_test.cc index 0931495797..22d202bd49 100644 --- a/src/writer/msl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/msl/generator_impl_variable_decl_statement_test.cc @@ -54,7 +54,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) { } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) { - auto* var = Const("a", ty.f32(), ast::StorageClass::kNone); + auto* var = Const("a", ty.f32()); auto* stmt = create(var); WrapInFunction(stmt); @@ -142,8 +142,8 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) { TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) { Global("initializer", ty.f32(), ast::StorageClass::kNone); - auto* var = Global("a", ty.f32(), ast::StorageClass::kPrivate, - Expr("initializer"), ast::VariableDecorationList{}); + auto* var = + Global("a", ty.f32(), ast::StorageClass::kPrivate, Expr("initializer")); auto* stmt = create(var); GeneratorImpl& gen = Build(); @@ -156,8 +156,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) { TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) { auto* zero_vec = vec3(); - auto* var = Var("a", ty.vec3(), ast::StorageClass::kFunction, zero_vec, - ast::VariableDecorationList{}); + auto* var = Var("a", ty.vec3(), ast::StorageClass::kFunction, zero_vec); auto* stmt = create(var); WrapInFunction(stmt); diff --git a/src/writer/spirv/builder_accessor_expression_test.cc b/src/writer/spirv/builder_accessor_expression_test.cc index 40d5b5f87b..066afd1934 100644 --- a/src/writer/spirv/builder_accessor_expression_test.cc +++ b/src/writer/spirv/builder_accessor_expression_test.cc @@ -719,10 +719,9 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) { type::Array arr(ty.vec2(), 3, ast::ArrayDecorationList{}); auto* var = - GlobalConst("pos", &arr, ast::StorageClass::kPrivate, + GlobalConst("pos", &arr, Construct(&arr, vec2(0.0f, 0.5f), - vec2(-0.5f, -0.5f), vec2(0.5f, -0.5f)), - ast::VariableDecorationList{}); + vec2(-0.5f, -0.5f), vec2(0.5f, -0.5f))); auto* expr = IndexAccessor("pos", 1u); WrapInFunction(expr); @@ -763,8 +762,7 @@ TEST_F(BuilderTest, Accessor_Const_Vec) { // const pos : vec2 = vec2(0.0, 0.5); // pos[1] - auto* var = GlobalConst("pos", ty.vec2(), ast::StorageClass::kPrivate, - vec2(0.0f, 0.5f), ast::VariableDecorationList{}); + auto* var = GlobalConst("pos", ty.vec2(), vec2(0.0f, 0.5f)); auto* expr = IndexAccessor("pos", 1u); WrapInFunction(expr); diff --git a/src/writer/spirv/builder_binary_expression_test.cc b/src/writer/spirv/builder_binary_expression_test.cc index 7009de60a5..4414838e1d 100644 --- a/src/writer/spirv/builder_binary_expression_test.cc +++ b/src/writer/spirv/builder_binary_expression_test.cc @@ -674,10 +674,10 @@ OpBranch %7 } TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) { - auto* a_var = Global("a", ty.bool_(), ast::StorageClass::kFunction, - Expr(true), ast::VariableDecorationList{}); - auto* b_var = Global("b", ty.bool_(), ast::StorageClass::kFunction, - Expr(false), ast::VariableDecorationList{}); + auto* a_var = + Global("a", ty.bool_(), ast::StorageClass::kFunction, Expr(true)); + auto* b_var = + Global("b", ty.bool_(), ast::StorageClass::kFunction, Expr(false)); auto* expr = create(ast::BinaryOp::kLogicalAnd, Expr("a"), Expr("b")); @@ -833,10 +833,10 @@ OpBranch %7 } TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) { - auto* a_var = Global("a", ty.bool_(), ast::StorageClass::kFunction, - Expr(true), ast::VariableDecorationList{}); - auto* b_var = Global("b", ty.bool_(), ast::StorageClass::kFunction, - Expr(false), ast::VariableDecorationList{}); + auto* a_var = + Global("a", ty.bool_(), ast::StorageClass::kFunction, Expr(true)); + auto* b_var = + Global("b", ty.bool_(), ast::StorageClass::kFunction, Expr(false)); auto* expr = create(ast::BinaryOp::kLogicalOr, Expr("a"), Expr("b")); diff --git a/src/writer/spirv/builder_function_test.cc b/src/writer/spirv/builder_function_test.cc index 807dba3c91..3e5803ae81 100644 --- a/src/writer/spirv/builder_function_test.cc +++ b/src/writer/spirv/builder_function_test.cc @@ -248,7 +248,7 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) { { auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - MemberAccessor("data", "d"), ast::VariableDecorationList{}); + MemberAccessor("data", "d")); Func("a", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -262,7 +262,7 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) { { auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - MemberAccessor("data", "d"), ast::VariableDecorationList{}); + MemberAccessor("data", "d")); Func("b", ast::VariableList{}, ty.void_(), ast::StatementList{ diff --git a/src/writer/spirv/builder_function_variable_test.cc b/src/writer/spirv/builder_function_variable_test.cc index 88c9260a01..8d716d164d 100644 --- a/src/writer/spirv/builder_function_variable_test.cc +++ b/src/writer/spirv/builder_function_variable_test.cc @@ -67,8 +67,7 @@ TEST_F(BuilderTest, FunctionVar_NoStorageClass) { TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) { auto* init = vec3(1.f, 1.f, 3.f); - auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput, init, - ast::VariableDecorationList{}); + auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput, init); spirv::Builder& b = Build(); @@ -97,8 +96,7 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) { TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) { auto* init = vec2(1.f, Add(3.f, 3.f)); - auto* v = Global("var", ty.vec2(), ast::StorageClass::kFunction, init, - ast::VariableDecorationList{}); + auto* v = Global("var", ty.vec2(), ast::StorageClass::kFunction, init); spirv::Builder& b = Build(); @@ -129,11 +127,9 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructorLoadedFromVar) { // var v : f32 = 1.0; // var v2 : f32 = v; // Should generate the load and store automatically. - auto* v = Global("v", ty.f32(), ast::StorageClass::kFunction, Expr(1.f), - ast::VariableDecorationList{}); + auto* v = Global("v", ty.f32(), ast::StorageClass::kFunction, Expr(1.f)); - auto* v2 = Global("v2", ty.f32(), ast::StorageClass::kFunction, Expr("v"), - ast::VariableDecorationList{}); + auto* v2 = Global("v2", ty.f32(), ast::StorageClass::kFunction, Expr("v")); spirv::Builder& b = Build(); @@ -165,11 +161,9 @@ TEST_F(BuilderTest, FunctionVar_ConstWithVarInitializer) { // var v : f32 = 1.0; // const v2 : f32 = v; // Should generate the load - auto* v = Global("v", ty.f32(), ast::StorageClass::kFunction, Expr(1.f), - ast::VariableDecorationList{}); + auto* v = Global("v", ty.f32(), ast::StorageClass::kFunction, Expr(1.f)); - auto* v2 = Global("v2", ty.f32(), ast::StorageClass::kFunction, Expr("v"), - ast::VariableDecorationList{}); + auto* v2 = Global("v2", ty.f32(), ast::StorageClass::kFunction, Expr("v")); spirv::Builder& b = Build(); @@ -200,8 +194,7 @@ OpStore %7 %6 TEST_F(BuilderTest, FunctionVar_Const) { auto* init = vec3(1.f, 1.f, 3.f); - auto* v = Const("var", ty.f32(), ast::StorageClass::kOutput, init, - ast::VariableDecorationList{}); + auto* v = Const("var", ty.f32(), init); WrapInFunction(v); diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index 46c606f01a..f1833dd1e7 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -97,8 +97,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) { TEST_F(BuilderTest, GlobalVar_WithConstructor) { auto* init = vec3(1.f, 1.f, 3.f); - auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput, init, - ast::VariableDecorationList{}); + auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput, init); spirv::Builder& b = Build(); @@ -120,8 +119,7 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) { TEST_F(BuilderTest, GlobalVar_Const) { auto* init = vec3(1.f, 1.f, 3.f); - auto* v = GlobalConst("var", ty.f32(), ast::StorageClass::kOutput, init, - ast::VariableDecorationList{}); + auto* v = GlobalConst("var", ty.f32(), init); spirv::Builder& b = Build(); @@ -141,8 +139,7 @@ TEST_F(BuilderTest, GlobalVar_Const) { TEST_F(BuilderTest, GlobalVar_Complex_Constructor) { auto* init = vec3(ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)}); - auto* v = GlobalConst("var", ty.f32(), ast::StorageClass::kOutput, init, - ast::VariableDecorationList{}); + auto* v = GlobalConst("var", ty.f32(), init); spirv::Builder& b = Build(); @@ -161,8 +158,7 @@ TEST_F(BuilderTest, GlobalVar_Complex_Constructor) { TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) { auto* init = vec3(vec2(1.f, 2.f), 3.f); - auto* v = GlobalConst("var", ty.f32(), ast::StorageClass::kOutput, init, - ast::VariableDecorationList{}); + auto* v = GlobalConst("var", ty.f32(), init); spirv::Builder& b = Build(); diff --git a/src/writer/spirv/builder_ident_expression_test.cc b/src/writer/spirv/builder_ident_expression_test.cc index 89ae49a195..eb1fd1394d 100644 --- a/src/writer/spirv/builder_ident_expression_test.cc +++ b/src/writer/spirv/builder_ident_expression_test.cc @@ -40,8 +40,7 @@ using BuilderTest = TestHelper; TEST_F(BuilderTest, IdentifierExpression_GlobalConst) { auto* init = vec3(1.f, 1.f, 3.f); - auto* v = GlobalConst("var", ty.f32(), ast::StorageClass::kOutput, init, - ast::VariableDecorationList{}); + auto* v = GlobalConst("var", ty.f32(), init); auto* expr = Expr("var"); WrapInFunction(expr); @@ -85,8 +84,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) { TEST_F(BuilderTest, IdentifierExpression_FunctionConst) { auto* init = vec3(1.f, 1.f, 3.f); - auto* v = Const("var", ty.f32(), ast::StorageClass::kOutput, init, - ast::VariableDecorationList{}); + auto* v = Const("var", ty.f32(), init); auto* expr = Expr("var"); WrapInFunction(v, expr); @@ -156,8 +154,7 @@ TEST_F(BuilderTest, IdentifierExpression_Load) { } TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) { - auto* var = GlobalConst("var", ty.i32(), ast::StorageClass::kNone, Expr(2), - ast::VariableDecorationList{}); + auto* var = GlobalConst("var", ty.i32(), Expr(2)); auto* expr = Add("var", "var"); WrapInFunction(expr); diff --git a/src/writer/wgsl/generator_impl_function_test.cc b/src/writer/wgsl/generator_impl_function_test.cc index f99f512d74..0feacc8156 100644 --- a/src/writer/wgsl/generator_impl_function_test.cc +++ b/src/writer/wgsl/generator_impl_function_test.cc @@ -194,8 +194,7 @@ TEST_F(WgslGeneratorImplTest, { auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - create(Expr("data"), Expr("d")), - ast::VariableDecorationList{}); + create(Expr("data"), Expr("d"))); Func("a", ast::VariableList{}, ty.void_(), ast::StatementList{ @@ -210,8 +209,7 @@ TEST_F(WgslGeneratorImplTest, { auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, - create(Expr("data"), Expr("d")), - ast::VariableDecorationList{}); + create(Expr("data"), Expr("d"))); Func("b", ast::VariableList{}, ty.void_(), ast::StatementList{ diff --git a/src/writer/wgsl/generator_impl_global_decl_test.cc b/src/writer/wgsl/generator_impl_global_decl_test.cc index 9f72bc241c..37030f510f 100644 --- a/src/writer/wgsl/generator_impl_global_decl_test.cc +++ b/src/writer/wgsl/generator_impl_global_decl_test.cc @@ -30,8 +30,7 @@ namespace { using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, Emit_GlobalDeclAfterFunction) { - auto* func_var = Var("a", ty.f32(), ast::StorageClass::kFunction, nullptr, - ast::VariableDecorationList{}); + auto* func_var = Var("a", ty.f32(), ast::StorageClass::kFunction); WrapInFunction(create(func_var)); auto* global_var = Global("a", ty.f32(), ast::StorageClass::kInput); diff --git a/src/writer/wgsl/generator_impl_variable_test.cc b/src/writer/wgsl/generator_impl_variable_test.cc index 09c3b40155..e410195ff2 100644 --- a/src/writer/wgsl/generator_impl_variable_test.cc +++ b/src/writer/wgsl/generator_impl_variable_test.cc @@ -86,8 +86,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) { } TEST_F(WgslGeneratorImplTest, EmitVariable_Constructor) { - auto* v = Global("a", ty.f32(), ast::StorageClass::kNone, Expr("initializer"), - ast::VariableDecorationList{}); + auto* v = + Global("a", ty.f32(), ast::StorageClass::kNone, Expr("initializer")); GeneratorImpl& gen = Build(); @@ -97,8 +97,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Constructor) { } TEST_F(WgslGeneratorImplTest, EmitVariable_Const) { - auto* v = Const("a", ty.f32(), ast::StorageClass::kNone, Expr("initializer"), - ast::VariableDecorationList{}); + auto* v = Const("a", ty.f32(), Expr("initializer")); GeneratorImpl& gen = Build();