Move array accessor tests to their own file
No new tests or any changes, just moving to a separate file in preparation for adding lots more of these tests soon. Change-Id: Iaa7eef52384e702c395a6db312fef19e22507644 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/63580 Kokoro: Kokoro <noreply+kokoro@google.com> Auto-Submit: James Price <jrprice@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
parent
ed18f2f8c3
commit
c77214d52d
|
@ -641,6 +641,7 @@ if(${TINT_BUILD_TESTS})
|
||||||
diagnostic/printer_test.cc
|
diagnostic/printer_test.cc
|
||||||
intrinsic_table_test.cc
|
intrinsic_table_test.cc
|
||||||
program_test.cc
|
program_test.cc
|
||||||
|
resolver/array_accessor_test.cc
|
||||||
resolver/assignment_validation_test.cc
|
resolver/assignment_validation_test.cc
|
||||||
resolver/atomics_test.cc
|
resolver/atomics_test.cc
|
||||||
resolver/atomics_validation_test.cc
|
resolver/atomics_validation_test.cc
|
||||||
|
|
|
@ -0,0 +1,262 @@
|
||||||
|
// Copyright 2021 The Tint Authors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "src/resolver/resolver.h"
|
||||||
|
|
||||||
|
#include "gmock/gmock.h"
|
||||||
|
#include "src/resolver/resolver_test_helper.h"
|
||||||
|
#include "src/sem/reference_type.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace resolver {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using ResolverArrayAccessorTest = ResolverTest;
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Matrix_Dynamic_F32) {
|
||||||
|
Global("my_var", ty.mat2x3<f32>(), ast::StorageClass::kPrivate);
|
||||||
|
auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, 1.0f));
|
||||||
|
WrapInFunction(acc);
|
||||||
|
|
||||||
|
EXPECT_FALSE(r()->Resolve());
|
||||||
|
EXPECT_EQ(r()->error(),
|
||||||
|
"12:34 error: index must be of type 'i32' or 'u32', found: 'f32'");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Matrix_Dynamic_Ref) {
|
||||||
|
Global("my_var", ty.mat2x3<f32>(), ast::StorageClass::kPrivate);
|
||||||
|
auto* idx = Var("idx", ty.i32(), Construct(ty.i32()));
|
||||||
|
auto* acc = IndexAccessor("my_var", idx);
|
||||||
|
WrapInFunction(Decl(idx), acc);
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Matrix_BothDimensions_Dynamic_Ref) {
|
||||||
|
Global("my_var", ty.mat4x4<f32>(), ast::StorageClass::kPrivate);
|
||||||
|
auto* idx = Var("idx", ty.u32(), Expr(3u));
|
||||||
|
auto* idy = Var("idy", ty.u32(), Expr(2u));
|
||||||
|
auto* acc = IndexAccessor(IndexAccessor("my_var", idx), idy);
|
||||||
|
WrapInFunction(Decl(idx), Decl(idy), acc);
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Matrix_Dynamic) {
|
||||||
|
GlobalConst("my_const", ty.mat2x3<f32>(), Construct(ty.mat2x3<f32>()));
|
||||||
|
auto* idx = Var("idx", ty.i32(), Construct(ty.i32()));
|
||||||
|
auto* acc = IndexAccessor("my_const", Expr(Source{{12, 34}}, idx));
|
||||||
|
WrapInFunction(Decl(idx), acc);
|
||||||
|
|
||||||
|
EXPECT_FALSE(r()->Resolve());
|
||||||
|
EXPECT_EQ(r()->error(),
|
||||||
|
"12:34 error: index must be signed or unsigned integer literal");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Matrix_XDimension_Dynamic) {
|
||||||
|
GlobalConst("my_var", ty.mat4x4<f32>(), Construct(ty.mat4x4<f32>()));
|
||||||
|
auto* idx = Var("idx", ty.u32(), Expr(3u));
|
||||||
|
auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, idx));
|
||||||
|
WrapInFunction(Decl(idx), acc);
|
||||||
|
|
||||||
|
EXPECT_FALSE(r()->Resolve());
|
||||||
|
EXPECT_EQ(r()->error(),
|
||||||
|
"12:34 error: index must be signed or unsigned integer literal");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Matrix_BothDimension_Dynamic) {
|
||||||
|
GlobalConst("my_var", ty.mat4x4<f32>(), Construct(ty.mat4x4<f32>()));
|
||||||
|
auto* idx = Var("idy", ty.u32(), Expr(2u));
|
||||||
|
auto* acc =
|
||||||
|
IndexAccessor(IndexAccessor("my_var", Expr(Source{{12, 34}}, idx)), 1);
|
||||||
|
WrapInFunction(Decl(idx), acc);
|
||||||
|
|
||||||
|
EXPECT_FALSE(r()->Resolve());
|
||||||
|
EXPECT_EQ(r()->error(),
|
||||||
|
"12:34 error: index must be signed or unsigned integer literal");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Matrix) {
|
||||||
|
Global("my_var", ty.mat2x3<f32>(), ast::StorageClass::kPrivate);
|
||||||
|
|
||||||
|
auto* acc = IndexAccessor("my_var", 2);
|
||||||
|
WrapInFunction(acc);
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(acc), nullptr);
|
||||||
|
ASSERT_TRUE(TypeOf(acc)->Is<sem::Reference>());
|
||||||
|
|
||||||
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
|
ASSERT_TRUE(ref->StoreType()->Is<sem::Vector>());
|
||||||
|
EXPECT_EQ(ref->StoreType()->As<sem::Vector>()->Width(), 3u);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Matrix_BothDimensions) {
|
||||||
|
Global("my_var", ty.mat2x3<f32>(), ast::StorageClass::kPrivate);
|
||||||
|
|
||||||
|
auto* acc = IndexAccessor(IndexAccessor("my_var", 2), 1);
|
||||||
|
WrapInFunction(acc);
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(acc), nullptr);
|
||||||
|
ASSERT_TRUE(TypeOf(acc)->Is<sem::Reference>());
|
||||||
|
|
||||||
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
|
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Vector_F32) {
|
||||||
|
Global("my_var", ty.vec3<f32>(), ast::StorageClass::kPrivate);
|
||||||
|
auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, 2.0f));
|
||||||
|
WrapInFunction(acc);
|
||||||
|
|
||||||
|
EXPECT_FALSE(r()->Resolve());
|
||||||
|
EXPECT_EQ(r()->error(),
|
||||||
|
"12:34 error: index must be of type 'i32' or 'u32', found: 'f32'");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Vector_Dynamic_Ref) {
|
||||||
|
Global("my_var", ty.vec3<f32>(), ast::StorageClass::kPrivate);
|
||||||
|
auto* idx = Var("idx", ty.i32(), Expr(2));
|
||||||
|
auto* acc = IndexAccessor("my_var", idx);
|
||||||
|
WrapInFunction(Decl(idx), acc);
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Vector_Dynamic) {
|
||||||
|
GlobalConst("my_var", ty.vec3<f32>(), Construct(ty.vec3<f32>()));
|
||||||
|
auto* idx = Var("idx", ty.i32(), Expr(2));
|
||||||
|
auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, idx));
|
||||||
|
WrapInFunction(Decl(idx), acc);
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Vector) {
|
||||||
|
Global("my_var", ty.vec3<f32>(), ast::StorageClass::kPrivate);
|
||||||
|
|
||||||
|
auto* acc = IndexAccessor("my_var", 2);
|
||||||
|
WrapInFunction(acc);
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(acc), nullptr);
|
||||||
|
ASSERT_TRUE(TypeOf(acc)->Is<sem::Reference>());
|
||||||
|
|
||||||
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
|
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Array) {
|
||||||
|
auto* idx = Expr(2);
|
||||||
|
Global("my_var", ty.array<f32, 3>(), ast::StorageClass::kPrivate);
|
||||||
|
|
||||||
|
auto* acc = IndexAccessor("my_var", idx);
|
||||||
|
WrapInFunction(acc);
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(acc), nullptr);
|
||||||
|
ASSERT_TRUE(TypeOf(acc)->Is<sem::Reference>());
|
||||||
|
|
||||||
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
|
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Alias_Array) {
|
||||||
|
auto* aary = Alias("myarrty", ty.array<f32, 3>());
|
||||||
|
|
||||||
|
Global("my_var", ty.Of(aary), ast::StorageClass::kPrivate);
|
||||||
|
|
||||||
|
auto* acc = IndexAccessor("my_var", 2);
|
||||||
|
WrapInFunction(acc);
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(acc), nullptr);
|
||||||
|
ASSERT_TRUE(TypeOf(acc)->Is<sem::Reference>());
|
||||||
|
|
||||||
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
|
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Array_Constant) {
|
||||||
|
GlobalConst("my_var", ty.array<f32, 3>(), array<f32, 3>());
|
||||||
|
|
||||||
|
auto* acc = IndexAccessor("my_var", 2);
|
||||||
|
WrapInFunction(acc);
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(acc), nullptr);
|
||||||
|
EXPECT_TRUE(TypeOf(acc)->Is<sem::F32>()) << TypeOf(acc)->type_name();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Array_Dynamic_I32) {
|
||||||
|
// let a : array<f32, 3> = 0;
|
||||||
|
// var idx : i32 = 0;
|
||||||
|
// var f : f32 = a[idx];
|
||||||
|
auto* a = Const("a", ty.array<f32, 3>(), array<f32, 3>());
|
||||||
|
auto* idx = Var("idx", ty.i32(), Construct(ty.i32()));
|
||||||
|
auto* f = Var("f", ty.f32(), IndexAccessor("a", Expr(Source{{12, 34}}, idx)));
|
||||||
|
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||||
|
{
|
||||||
|
Decl(a),
|
||||||
|
Decl(idx),
|
||||||
|
Decl(f),
|
||||||
|
},
|
||||||
|
ast::DecorationList{});
|
||||||
|
|
||||||
|
EXPECT_FALSE(r()->Resolve());
|
||||||
|
EXPECT_EQ(r()->error(),
|
||||||
|
"12:34 error: index must be signed or unsigned integer literal");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Array_Literal_F32) {
|
||||||
|
// let a : array<f32, 3>;
|
||||||
|
// var f : f32 = a[2.0f];
|
||||||
|
auto* a = Const("a", ty.array<f32, 3>(), array<f32, 3>());
|
||||||
|
auto* f =
|
||||||
|
Var("a_2", ty.f32(), IndexAccessor("a", Expr(Source{{12, 34}}, 2.0f)));
|
||||||
|
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||||
|
{
|
||||||
|
Decl(a),
|
||||||
|
Decl(f),
|
||||||
|
},
|
||||||
|
ast::DecorationList{});
|
||||||
|
EXPECT_FALSE(r()->Resolve());
|
||||||
|
EXPECT_EQ(r()->error(),
|
||||||
|
"12:34 error: index must be of type 'i32' or 'u32', found: 'f32'");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverArrayAccessorTest, Array_Literal_I32) {
|
||||||
|
// let a : array<f32, 3>;
|
||||||
|
// var f : f32 = a[2];
|
||||||
|
auto* a = Const("a", ty.array<f32, 3>(), array<f32, 3>());
|
||||||
|
auto* f = Var("a_2", ty.f32(), IndexAccessor("a", 2));
|
||||||
|
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||||
|
{
|
||||||
|
Decl(a),
|
||||||
|
Decl(f),
|
||||||
|
},
|
||||||
|
ast::DecorationList{});
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace resolver
|
||||||
|
} // namespace tint
|
|
@ -491,188 +491,6 @@ TEST_F(ResolverTest, ArraySize_SignedConstant) {
|
||||||
EXPECT_EQ(ary->Count(), 10u);
|
EXPECT_EQ(ary->Count(), 10u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_ArrayAccessor_Array) {
|
|
||||||
auto* idx = Expr(2);
|
|
||||||
Global("my_var", ty.array<f32, 3>(), ast::StorageClass::kPrivate);
|
|
||||||
|
|
||||||
auto* acc = IndexAccessor("my_var", idx);
|
|
||||||
WrapInFunction(acc);
|
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
|
||||||
|
|
||||||
ASSERT_NE(TypeOf(acc), nullptr);
|
|
||||||
ASSERT_TRUE(TypeOf(acc)->Is<sem::Reference>());
|
|
||||||
|
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_ArrayAccessor_Alias_Array) {
|
|
||||||
auto* aary = Alias("myarrty", ty.array<f32, 3>());
|
|
||||||
|
|
||||||
Global("my_var", ty.Of(aary), ast::StorageClass::kPrivate);
|
|
||||||
|
|
||||||
auto* acc = IndexAccessor("my_var", 2);
|
|
||||||
WrapInFunction(acc);
|
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
|
||||||
|
|
||||||
ASSERT_NE(TypeOf(acc), nullptr);
|
|
||||||
ASSERT_TRUE(TypeOf(acc)->Is<sem::Reference>());
|
|
||||||
|
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_ArrayAccessor_Array_Constant) {
|
|
||||||
GlobalConst("my_var", ty.array<f32, 3>(), array<f32, 3>());
|
|
||||||
|
|
||||||
auto* acc = IndexAccessor("my_var", 2);
|
|
||||||
WrapInFunction(acc);
|
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
|
||||||
|
|
||||||
ASSERT_NE(TypeOf(acc), nullptr);
|
|
||||||
EXPECT_TRUE(TypeOf(acc)->Is<sem::F32>()) << TypeOf(acc)->type_name();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, ArrayAccessor_Matrix_Dynamic_F32) {
|
|
||||||
Global("my_var", ty.mat2x3<f32>(), ast::StorageClass::kPrivate);
|
|
||||||
auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, 1.0f));
|
|
||||||
WrapInFunction(acc);
|
|
||||||
|
|
||||||
EXPECT_FALSE(r()->Resolve());
|
|
||||||
EXPECT_EQ(r()->error(),
|
|
||||||
"12:34 error: index must be of type 'i32' or 'u32', found: 'f32'");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, ArrayAccessor_Matrix_Dynamic_Ref) {
|
|
||||||
Global("my_var", ty.mat2x3<f32>(), ast::StorageClass::kPrivate);
|
|
||||||
auto* idx = Var("idx", ty.i32(), Construct(ty.i32()));
|
|
||||||
auto* acc = IndexAccessor("my_var", idx);
|
|
||||||
WrapInFunction(Decl(idx), acc);
|
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, ArrayAccessor_Matrix_BothDimensions_Dynamic_Ref) {
|
|
||||||
Global("my_var", ty.mat4x4<f32>(), ast::StorageClass::kPrivate);
|
|
||||||
auto* idx = Var("idx", ty.u32(), Expr(3u));
|
|
||||||
auto* idy = Var("idy", ty.u32(), Expr(2u));
|
|
||||||
auto* acc = IndexAccessor(IndexAccessor("my_var", idx), idy);
|
|
||||||
WrapInFunction(Decl(idx), Decl(idy), acc);
|
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, ArrayAccessor_Matrix_Dynamic) {
|
|
||||||
GlobalConst("my_const", ty.mat2x3<f32>(), Construct(ty.mat2x3<f32>()));
|
|
||||||
auto* idx = Var("idx", ty.i32(), Construct(ty.i32()));
|
|
||||||
auto* acc = IndexAccessor("my_const", Expr(Source{{12, 34}}, idx));
|
|
||||||
WrapInFunction(Decl(idx), acc);
|
|
||||||
|
|
||||||
EXPECT_FALSE(r()->Resolve());
|
|
||||||
EXPECT_EQ(r()->error(),
|
|
||||||
"12:34 error: index must be signed or unsigned integer literal");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, ArrayAccessor_Matrix_XDimension_Dynamic) {
|
|
||||||
GlobalConst("my_var", ty.mat4x4<f32>(), Construct(ty.mat4x4<f32>()));
|
|
||||||
auto* idx = Var("idx", ty.u32(), Expr(3u));
|
|
||||||
auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, idx));
|
|
||||||
WrapInFunction(Decl(idx), acc);
|
|
||||||
|
|
||||||
EXPECT_FALSE(r()->Resolve());
|
|
||||||
EXPECT_EQ(r()->error(),
|
|
||||||
"12:34 error: index must be signed or unsigned integer literal");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, ArrayAccessor_Matrix_BothDimension_Dynamic) {
|
|
||||||
GlobalConst("my_var", ty.mat4x4<f32>(), Construct(ty.mat4x4<f32>()));
|
|
||||||
auto* idx = Var("idy", ty.u32(), Expr(2u));
|
|
||||||
auto* acc =
|
|
||||||
IndexAccessor(IndexAccessor("my_var", Expr(Source{{12, 34}}, idx)), 1);
|
|
||||||
WrapInFunction(Decl(idx), acc);
|
|
||||||
|
|
||||||
EXPECT_FALSE(r()->Resolve());
|
|
||||||
EXPECT_EQ(r()->error(),
|
|
||||||
"12:34 error: index must be signed or unsigned integer literal");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_ArrayAccessor_Matrix) {
|
|
||||||
Global("my_var", ty.mat2x3<f32>(), ast::StorageClass::kPrivate);
|
|
||||||
|
|
||||||
auto* acc = IndexAccessor("my_var", 2);
|
|
||||||
WrapInFunction(acc);
|
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
|
||||||
|
|
||||||
ASSERT_NE(TypeOf(acc), nullptr);
|
|
||||||
ASSERT_TRUE(TypeOf(acc)->Is<sem::Reference>());
|
|
||||||
|
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
|
||||||
ASSERT_TRUE(ref->StoreType()->Is<sem::Vector>());
|
|
||||||
EXPECT_EQ(ref->StoreType()->As<sem::Vector>()->Width(), 3u);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_ArrayAccessor_Matrix_BothDimensions) {
|
|
||||||
Global("my_var", ty.mat2x3<f32>(), ast::StorageClass::kPrivate);
|
|
||||||
|
|
||||||
auto* acc = IndexAccessor(IndexAccessor("my_var", 2), 1);
|
|
||||||
WrapInFunction(acc);
|
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
|
||||||
|
|
||||||
ASSERT_NE(TypeOf(acc), nullptr);
|
|
||||||
ASSERT_TRUE(TypeOf(acc)->Is<sem::Reference>());
|
|
||||||
|
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_ArrayAccessor_Vector_F32) {
|
|
||||||
Global("my_var", ty.vec3<f32>(), ast::StorageClass::kPrivate);
|
|
||||||
auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, 2.0f));
|
|
||||||
WrapInFunction(acc);
|
|
||||||
|
|
||||||
EXPECT_FALSE(r()->Resolve());
|
|
||||||
EXPECT_EQ(r()->error(),
|
|
||||||
"12:34 error: index must be of type 'i32' or 'u32', found: 'f32'");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_ArrayAccessor_Vector_Dynamic_Ref) {
|
|
||||||
Global("my_var", ty.vec3<f32>(), ast::StorageClass::kPrivate);
|
|
||||||
auto* idx = Var("idx", ty.i32(), Expr(2));
|
|
||||||
auto* acc = IndexAccessor("my_var", idx);
|
|
||||||
WrapInFunction(Decl(idx), acc);
|
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_ArrayAccessor_Vector_Dynamic) {
|
|
||||||
GlobalConst("my_var", ty.vec3<f32>(), Construct(ty.vec3<f32>()));
|
|
||||||
auto* idx = Var("idx", ty.i32(), Expr(2));
|
|
||||||
auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, idx));
|
|
||||||
WrapInFunction(Decl(idx), acc);
|
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_ArrayAccessor_Vector) {
|
|
||||||
Global("my_var", ty.vec3<f32>(), ast::StorageClass::kPrivate);
|
|
||||||
|
|
||||||
auto* acc = IndexAccessor("my_var", 2);
|
|
||||||
WrapInFunction(acc);
|
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
|
||||||
|
|
||||||
ASSERT_NE(TypeOf(acc), nullptr);
|
|
||||||
ASSERT_TRUE(TypeOf(acc)->Is<sem::Reference>());
|
|
||||||
|
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_Bitcast) {
|
TEST_F(ResolverTest, Expr_Bitcast) {
|
||||||
Global("name", ty.f32(), ast::StorageClass::kPrivate);
|
Global("name", ty.f32(), ast::StorageClass::kPrivate);
|
||||||
|
|
||||||
|
@ -869,56 +687,6 @@ TEST_F(ResolverTest, ArrayAccessor_Dynamic_Ref_F32) {
|
||||||
"12:34 error: index must be of type 'i32' or 'u32', found: 'f32'");
|
"12:34 error: index must be of type 'i32' or 'u32', found: 'f32'");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverTest, ArrayAccessor_Dynamic_I32) {
|
|
||||||
// let a : array<f32, 3> = 0;
|
|
||||||
// var idx : i32 = 0;
|
|
||||||
// var f : f32 = a[idx];
|
|
||||||
auto* a = Const("a", ty.array<f32, 3>(), array<f32, 3>());
|
|
||||||
auto* idx = Var("idx", ty.i32(), Construct(ty.i32()));
|
|
||||||
auto* f = Var("f", ty.f32(), IndexAccessor("a", Expr(Source{{12, 34}}, idx)));
|
|
||||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
|
||||||
{
|
|
||||||
Decl(a),
|
|
||||||
Decl(idx),
|
|
||||||
Decl(f),
|
|
||||||
},
|
|
||||||
ast::DecorationList{});
|
|
||||||
|
|
||||||
EXPECT_FALSE(r()->Resolve());
|
|
||||||
EXPECT_EQ(r()->error(),
|
|
||||||
"12:34 error: index must be signed or unsigned integer literal");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, ArrayAccessor_Literal_F32) {
|
|
||||||
// let a : array<f32, 3>;
|
|
||||||
// var f : f32 = a[2.0f];
|
|
||||||
auto* a = Const("a", ty.array<f32, 3>(), array<f32, 3>());
|
|
||||||
auto* f =
|
|
||||||
Var("a_2", ty.f32(), IndexAccessor("a", Expr(Source{{12, 34}}, 2.0f)));
|
|
||||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
|
||||||
{
|
|
||||||
Decl(a),
|
|
||||||
Decl(f),
|
|
||||||
},
|
|
||||||
ast::DecorationList{});
|
|
||||||
EXPECT_FALSE(r()->Resolve());
|
|
||||||
EXPECT_EQ(r()->error(),
|
|
||||||
"12:34 error: index must be of type 'i32' or 'u32', found: 'f32'");
|
|
||||||
}
|
|
||||||
TEST_F(ResolverTest, ArrayAccessor_Literal_I32) {
|
|
||||||
// let a : array<f32, 3>;
|
|
||||||
// var f : f32 = a[2];
|
|
||||||
auto* a = Const("a", ty.array<f32, 3>(), array<f32, 3>());
|
|
||||||
auto* f = Var("a_2", ty.f32(), IndexAccessor("a", 2));
|
|
||||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
|
||||||
{
|
|
||||||
Decl(a),
|
|
||||||
Decl(f),
|
|
||||||
},
|
|
||||||
ast::DecorationList{});
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_Identifier_FunctionVariable) {
|
TEST_F(ResolverTest, Expr_Identifier_FunctionVariable) {
|
||||||
auto* my_var_a = Expr("my_var");
|
auto* my_var_a = Expr("my_var");
|
||||||
auto* my_var_b = Expr("my_var");
|
auto* my_var_b = Expr("my_var");
|
||||||
|
|
|
@ -229,6 +229,7 @@ tint_unittests_source_set("tint_unittests_core_src") {
|
||||||
"../src/intrinsic_table_test.cc",
|
"../src/intrinsic_table_test.cc",
|
||||||
"../src/program_builder_test.cc",
|
"../src/program_builder_test.cc",
|
||||||
"../src/program_test.cc",
|
"../src/program_test.cc",
|
||||||
|
"../src/resolver/array_accessor_test.cc",
|
||||||
"../src/resolver/assignment_validation_test.cc",
|
"../src/resolver/assignment_validation_test.cc",
|
||||||
"../src/resolver/atomics_test.cc",
|
"../src/resolver/atomics_test.cc",
|
||||||
"../src/resolver/atomics_validation_test.cc",
|
"../src/resolver/atomics_validation_test.cc",
|
||||||
|
|
Loading…
Reference in New Issue