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:
parent
37571bc32d
commit
81a29fe555
|
@ -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
|
||||
|
|
|
@ -175,7 +175,7 @@ class InspectorHelper : public ProgramBuilder {
|
|||
constructor =
|
||||
create<ast::ScalarConstructorExpression>(MakeLiteral(type, val));
|
||||
}
|
||||
GlobalConst(name, type, ast::StorageClass::kNone, constructor,
|
||||
GlobalConst(name, type, constructor,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::ConstantIdDecoration>(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<ast::BindingDecoration>(binding),
|
||||
create<ast::GroupDecoration>(group),
|
||||
});
|
||||
Global(name, type, storage_class, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::BindingDecoration>(binding),
|
||||
create<ast::GroupDecoration>(group),
|
||||
});
|
||||
}
|
||||
|
||||
/// Adds an uniform buffer variable to the program
|
||||
|
|
|
@ -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<ast::Variable>(Symbols().Register(name), storage, type, true,
|
||||
return create<ast::Variable>(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<ast::Variable>(source, Symbols().Register(name), storage,
|
||||
type, true, constructor, decorations);
|
||||
return create<ast::Variable>(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<ast::Variable>(symbol, storage, type, true, constructor,
|
||||
decorations);
|
||||
return create<ast::Variable>(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<ast::Variable>(source, symbol, storage, type, true,
|
||||
constructor, decorations);
|
||||
return create<ast::Variable>(source, symbol, ast::StorageClass::kNone, type,
|
||||
true, constructor, decorations);
|
||||
}
|
||||
|
||||
/// @param args the arguments to pass to Var()
|
||||
|
|
|
@ -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<ast::VariableDeclStatement>(dst_var);
|
||||
|
|
|
@ -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<ast::VariableDeclStatement>(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<ast::VariableDeclStatement>(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<ast::VariableDeclStatement>(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<ast::VariableDeclStatement>(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<ast::VariableDeclStatement>(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<ast::VariableDeclStatement>(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<ast::VariableDeclStatement>(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<f32, 3>(), ast::StorageClass::kFunction);
|
||||
GlobalConst("my_var", ty.array<f32, 3>());
|
||||
|
||||
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<ast::AssignmentStatement>(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<ast::VariableDeclStatement>(var);
|
||||
Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt},
|
||||
ast::FunctionDecorationList{});
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -430,8 +430,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) {
|
|||
"a", ty.bool_(), ast::StorageClass::kFunction,
|
||||
create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kLogicalOr,
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, b, c), d),
|
||||
ast::VariableDecorationList{});
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, b, c), d));
|
||||
|
||||
auto* expr = create<ast::VariableDeclStatement>(var);
|
||||
|
||||
|
|
|
@ -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<ast::MemberAccessorExpression>(
|
||||
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{
|
||||
|
|
|
@ -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::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
|
|
|
@ -33,9 +33,7 @@ namespace {
|
|||
using HlslGeneratorImplTest_ModuleConstant = TestHelper;
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
|
||||
auto* var =
|
||||
Const("pos", ty.array<f32, 3>(), ast::StorageClass::kNone,
|
||||
array<f32, 3>(1.f, 2.f, 3.f), ast::VariableDecorationList{});
|
||||
auto* var = Const("pos", ty.array<f32, 3>(), array<f32, 3>(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<ast::ConstantIdDecoration>(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<ast::ConstantIdDecoration>(23),
|
||||
});
|
||||
|
|
|
@ -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<ast::VariableDeclStatement>(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<ast::VariableDeclStatement>(var);
|
||||
|
||||
|
@ -115,8 +115,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
|
|||
|
||||
TEST_F(HlslGeneratorImplTest_VariableDecl,
|
||||
Emit_VariableDeclStatement_Initializer_ZeroVec) {
|
||||
auto* var = Var("a", ty.vec3<f32>(), ast::StorageClass::kFunction,
|
||||
vec3<f32>(), ast::VariableDecorationList{});
|
||||
auto* var =
|
||||
Var("a", ty.vec3<f32>(), ast::StorageClass::kFunction, vec3<f32>());
|
||||
|
||||
auto* stmt = create<ast::VariableDeclStatement>(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<f32>(), ast::StorageClass::kFunction,
|
||||
mat2x3<f32>(), ast::VariableDecorationList{});
|
||||
auto* var =
|
||||
Var("a", ty.mat2x3<f32>(), ast::StorageClass::kFunction, mat2x3<f32>());
|
||||
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
WrapInFunction(stmt);
|
||||
|
|
|
@ -259,7 +259,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
|
|||
create<ast::GroupDecoration>(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<ast::GroupDecoration>(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<ast::GroupDecoration>(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<ast::VariableDeclStatement>(var),
|
||||
|
|
|
@ -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::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
|
|
|
@ -35,9 +35,7 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) {
|
||||
auto* var =
|
||||
Const("pos", ty.array<f32, 3>(), ast::StorageClass::kNone,
|
||||
array<f32, 3>(1.f, 2.f, 3.f), ast::VariableDecorationList{});
|
||||
auto* var = Const("pos", ty.array<f32, 3>(), array<f32, 3>(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<ast::ConstantIdDecoration>(23),
|
||||
});
|
||||
|
|
|
@ -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<ast::VariableDeclStatement>(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<ast::VariableDeclStatement>(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<f32>();
|
||||
|
||||
auto* var = Var("a", ty.vec3<f32>(), ast::StorageClass::kFunction, zero_vec,
|
||||
ast::VariableDecorationList{});
|
||||
auto* var = Var("a", ty.vec3<f32>(), ast::StorageClass::kFunction, zero_vec);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
|
|
|
@ -719,10 +719,9 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) {
|
|||
type::Array arr(ty.vec2<f32>(), 3, ast::ArrayDecorationList{});
|
||||
|
||||
auto* var =
|
||||
GlobalConst("pos", &arr, ast::StorageClass::kPrivate,
|
||||
GlobalConst("pos", &arr,
|
||||
Construct(&arr, vec2<f32>(0.0f, 0.5f),
|
||||
vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)),
|
||||
ast::VariableDecorationList{});
|
||||
vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)));
|
||||
|
||||
auto* expr = IndexAccessor("pos", 1u);
|
||||
WrapInFunction(expr);
|
||||
|
@ -763,8 +762,7 @@ TEST_F(BuilderTest, Accessor_Const_Vec) {
|
|||
// const pos : vec2<f32> = vec2<f32>(0.0, 0.5);
|
||||
// pos[1]
|
||||
|
||||
auto* var = GlobalConst("pos", ty.vec2<f32>(), ast::StorageClass::kPrivate,
|
||||
vec2<f32>(0.0f, 0.5f), ast::VariableDecorationList{});
|
||||
auto* var = GlobalConst("pos", ty.vec2<f32>(), vec2<f32>(0.0f, 0.5f));
|
||||
|
||||
auto* expr = IndexAccessor("pos", 1u);
|
||||
WrapInFunction(expr);
|
||||
|
|
|
@ -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::BinaryExpression>(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::BinaryExpression>(ast::BinaryOp::kLogicalOr,
|
||||
Expr("a"), Expr("b"));
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -67,8 +67,7 @@ TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
|
|||
TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
||||
auto* init = vec3<f32>(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<f32>(1.f, Add(3.f, 3.f));
|
||||
|
||||
auto* v = Global("var", ty.vec2<f32>(), ast::StorageClass::kFunction, init,
|
||||
ast::VariableDecorationList{});
|
||||
auto* v = Global("var", ty.vec2<f32>(), 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<f32>(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);
|
||||
|
||||
|
|
|
@ -97,8 +97,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) {
|
|||
TEST_F(BuilderTest, GlobalVar_WithConstructor) {
|
||||
auto* init = vec3<f32>(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<f32>(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<f32>(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<f32>(vec2<f32>(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();
|
||||
|
||||
|
|
|
@ -40,8 +40,7 @@ using BuilderTest = TestHelper;
|
|||
TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
|
||||
auto* init = vec3<f32>(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<f32>(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);
|
||||
|
|
|
@ -194,8 +194,7 @@ TEST_F(WgslGeneratorImplTest,
|
|||
{
|
||||
auto* var =
|
||||
Var("v", ty.f32(), ast::StorageClass::kFunction,
|
||||
create<ast::MemberAccessorExpression>(Expr("data"), Expr("d")),
|
||||
ast::VariableDecorationList{});
|
||||
create<ast::MemberAccessorExpression>(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<ast::MemberAccessorExpression>(Expr("data"), Expr("d")),
|
||||
ast::VariableDecorationList{});
|
||||
create<ast::MemberAccessorExpression>(Expr("data"), Expr("d")));
|
||||
|
||||
Func("b", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
|
|
|
@ -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<ast::VariableDeclStatement>(func_var));
|
||||
|
||||
auto* global_var = Global("a", ty.f32(), ast::StorageClass::kInput);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue