Rename Index and Member builder helpers.
This CL renames Index to IndexAccessor and Member to MemberAccessor. This keeps the naming consistent and makes room to use Member for StructMember. Change-Id: Icbba3a39ed5e079cd83d8f512fff69494dfac10d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35824 Auto-Submit: dan sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
523b2193e3
commit
8b40a67cf7
|
@ -557,7 +557,7 @@ class Builder {
|
||||||
/// @param idx the index argument for the array accessor expression
|
/// @param idx the index argument for the array accessor expression
|
||||||
/// @returns a `ArrayAccessorExpression` that indexes `arr` with `idx`
|
/// @returns a `ArrayAccessorExpression` that indexes `arr` with `idx`
|
||||||
template <typename ARR, typename IDX>
|
template <typename ARR, typename IDX>
|
||||||
Expression* Index(ARR&& arr, IDX&& idx) {
|
Expression* IndexAccessor(ARR&& arr, IDX&& idx) {
|
||||||
return create<ArrayAccessorExpression>(Expr(std::forward<ARR>(arr)),
|
return create<ArrayAccessorExpression>(Expr(std::forward<ARR>(arr)),
|
||||||
Expr(std::forward<IDX>(idx)));
|
Expr(std::forward<IDX>(idx)));
|
||||||
}
|
}
|
||||||
|
@ -566,7 +566,7 @@ class Builder {
|
||||||
/// @param idx the index argument for the array accessor expression
|
/// @param idx the index argument for the array accessor expression
|
||||||
/// @returns a `MemberAccessorExpression` that indexes `obj` with `idx`
|
/// @returns a `MemberAccessorExpression` that indexes `obj` with `idx`
|
||||||
template <typename OBJ, typename IDX>
|
template <typename OBJ, typename IDX>
|
||||||
Expression* Member(OBJ&& obj, IDX&& idx) {
|
Expression* MemberAccessor(OBJ&& obj, IDX&& idx) {
|
||||||
return create<MemberAccessorExpression>(Expr(std::forward<OBJ>(obj)),
|
return create<MemberAccessorExpression>(Expr(std::forward<OBJ>(obj)),
|
||||||
Expr(std::forward<IDX>(idx)));
|
Expr(std::forward<IDX>(idx)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,8 @@ TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.array<f32, 3>());
|
Var("a", ast::StorageClass::kFunction, ty.array<f32, 3>());
|
||||||
Const("c", ast::StorageClass::kFunction, ty.u32);
|
Const("c", ast::StorageClass::kFunction, ty.u32);
|
||||||
Const("b", ast::StorageClass::kFunction,
|
Const("b", ast::StorageClass::kFunction,
|
||||||
ty.pointer<f32>(ast::StorageClass::kFunction), Index("a", "c"), {});
|
ty.pointer<f32>(ast::StorageClass::kFunction),
|
||||||
|
IndexAccessor("a", "c"), {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -168,7 +169,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Nested_Scalar) {
|
||||||
Var("b", ast::StorageClass::kFunction, ty.array<f32, 5>());
|
Var("b", ast::StorageClass::kFunction, ty.array<f32, 5>());
|
||||||
Var("i", ast::StorageClass::kFunction, ty.u32);
|
Var("i", ast::StorageClass::kFunction, ty.u32);
|
||||||
Const("c", ast::StorageClass::kFunction, ty.f32,
|
Const("c", ast::StorageClass::kFunction, ty.f32,
|
||||||
Index("a", Index("b", "i")), {});
|
IndexAccessor("a", IndexAccessor("b", "i")), {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -237,7 +238,8 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Scalar) {
|
||||||
struct Builder : ModuleBuilder {
|
struct Builder : ModuleBuilder {
|
||||||
void Build() override {
|
void Build() override {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.array(ty.f32, 3));
|
Var("a", ast::StorageClass::kFunction, ty.array(ty.f32, 3));
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32, Index("a", 1u), {});
|
Var("b", ast::StorageClass::kFunction, ty.f32, IndexAccessor("a", 1u),
|
||||||
|
{});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -270,7 +272,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Expr) {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.array<f32, 3>());
|
Var("a", ast::StorageClass::kFunction, ty.array<f32, 3>());
|
||||||
Var("c", ast::StorageClass::kFunction, ty.u32);
|
Var("c", ast::StorageClass::kFunction, ty.u32);
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32,
|
Var("b", ast::StorageClass::kFunction, ty.f32,
|
||||||
Index("a", Add("c", Sub(2u, 3u))), {});
|
IndexAccessor("a", Add("c", Sub(2u, 3u))), {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -335,7 +337,8 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Negative) {
|
||||||
struct Builder : ModuleBuilder {
|
struct Builder : ModuleBuilder {
|
||||||
void Build() override {
|
void Build() override {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.array<f32, 3>());
|
Var("a", ast::StorageClass::kFunction, ty.array<f32, 3>());
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32, Index("a", -1), {});
|
Var("b", ast::StorageClass::kFunction, ty.f32, IndexAccessor("a", -1),
|
||||||
|
{});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -365,7 +368,8 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_OutOfBounds) {
|
||||||
struct Builder : ModuleBuilder {
|
struct Builder : ModuleBuilder {
|
||||||
void Build() override {
|
void Build() override {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.array<f32, 3>());
|
Var("a", ast::StorageClass::kFunction, ty.array<f32, 3>());
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32, Index("a", 3u), {});
|
Var("b", ast::StorageClass::kFunction, ty.f32, IndexAccessor("a", 3u),
|
||||||
|
{});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -395,7 +399,8 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Scalar) {
|
||||||
struct Builder : ModuleBuilder {
|
struct Builder : ModuleBuilder {
|
||||||
void Build() override {
|
void Build() override {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.vec3<f32>());
|
Var("a", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32, Index("a", 1u), {});
|
Var("b", ast::StorageClass::kFunction, ty.f32, IndexAccessor("a", 1u),
|
||||||
|
{});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -428,7 +433,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Expr) {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.vec3<f32>());
|
Var("a", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||||
Var("c", ast::StorageClass::kFunction, ty.u32);
|
Var("c", ast::StorageClass::kFunction, ty.u32);
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32,
|
Var("b", ast::StorageClass::kFunction, ty.f32,
|
||||||
Index("a", Add("c", Sub(2u, 3u))), {});
|
IndexAccessor("a", Add("c", Sub(2u, 3u))), {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -491,7 +496,8 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Negative) {
|
||||||
struct Builder : ModuleBuilder {
|
struct Builder : ModuleBuilder {
|
||||||
void Build() override {
|
void Build() override {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.vec3<f32>());
|
Var("a", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32, Index("a", -1), {});
|
Var("b", ast::StorageClass::kFunction, ty.f32, IndexAccessor("a", -1),
|
||||||
|
{});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -521,7 +527,8 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_OutOfBounds) {
|
||||||
struct Builder : ModuleBuilder {
|
struct Builder : ModuleBuilder {
|
||||||
void Build() override {
|
void Build() override {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.vec3<f32>());
|
Var("a", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32, Index("a", 3u), {});
|
Var("b", ast::StorageClass::kFunction, ty.f32, IndexAccessor("a", 3u),
|
||||||
|
{});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -551,8 +558,8 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Scalar) {
|
||||||
struct Builder : ModuleBuilder {
|
struct Builder : ModuleBuilder {
|
||||||
void Build() override {
|
void Build() override {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32, Index(Index("a", 2u), 1u),
|
Var("b", ast::StorageClass::kFunction, ty.f32,
|
||||||
{});
|
IndexAccessor(IndexAccessor("a", 2u), 1u), {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -598,7 +605,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Column) {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
||||||
Var("c", ast::StorageClass::kFunction, ty.u32);
|
Var("c", ast::StorageClass::kFunction, ty.u32);
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32,
|
Var("b", ast::StorageClass::kFunction, ty.f32,
|
||||||
Index(Index("a", Add("c", Sub(2u, 3u))), 1u), {});
|
IndexAccessor(IndexAccessor("a", Add("c", Sub(2u, 3u))), 1u), {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -678,7 +685,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Row) {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
||||||
Var("c", ast::StorageClass::kFunction, ty.u32);
|
Var("c", ast::StorageClass::kFunction, ty.u32);
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32,
|
Var("b", ast::StorageClass::kFunction, ty.f32,
|
||||||
Index(Index("a", 1u), Add("c", Sub(2u, 3u))), {});
|
IndexAccessor(IndexAccessor("a", 1u), Add("c", Sub(2u, 3u))), {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -755,8 +762,8 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Column) {
|
||||||
struct Builder : ModuleBuilder {
|
struct Builder : ModuleBuilder {
|
||||||
void Build() override {
|
void Build() override {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32, Index(Index("a", -1), 1),
|
Var("b", ast::StorageClass::kFunction, ty.f32,
|
||||||
{});
|
IndexAccessor(IndexAccessor("a", -1), 1), {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -799,8 +806,8 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Row) {
|
||||||
struct Builder : ModuleBuilder {
|
struct Builder : ModuleBuilder {
|
||||||
void Build() override {
|
void Build() override {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32, Index(Index("a", 2), -1),
|
Var("b", ast::StorageClass::kFunction, ty.f32,
|
||||||
{});
|
IndexAccessor(IndexAccessor("a", 2), -1), {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -843,8 +850,8 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Column) {
|
||||||
struct Builder : ModuleBuilder {
|
struct Builder : ModuleBuilder {
|
||||||
void Build() override {
|
void Build() override {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32, Index(Index("a", 5u), 1u),
|
Var("b", ast::StorageClass::kFunction, ty.f32,
|
||||||
{});
|
IndexAccessor(IndexAccessor("a", 5u), 1u), {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -887,8 +894,8 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Row) {
|
||||||
struct Builder : ModuleBuilder {
|
struct Builder : ModuleBuilder {
|
||||||
void Build() override {
|
void Build() override {
|
||||||
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
||||||
Var("b", ast::StorageClass::kFunction, ty.f32, Index(Index("a", 2u), 5u),
|
Var("b", ast::StorageClass::kFunction, ty.f32,
|
||||||
{});
|
IndexAccessor(IndexAccessor("a", 2u), 5u), {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -377,7 +377,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array) {
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine());
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto* acc = Index("my_var", idx);
|
auto* acc = IndexAccessor("my_var", idx);
|
||||||
EXPECT_TRUE(td()->DetermineResultType(acc));
|
EXPECT_TRUE(td()->DetermineResultType(acc));
|
||||||
ASSERT_NE(acc->result_type(), nullptr);
|
ASSERT_NE(acc->result_type(), nullptr);
|
||||||
ASSERT_TRUE(acc->result_type()->Is<ast::type::Pointer>());
|
ASSERT_TRUE(acc->result_type()->Is<ast::type::Pointer>());
|
||||||
|
@ -395,7 +395,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Alias_Array) {
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine());
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto* acc = Index("my_var", 2);
|
auto* acc = IndexAccessor("my_var", 2);
|
||||||
EXPECT_TRUE(td()->DetermineResultType(acc));
|
EXPECT_TRUE(td()->DetermineResultType(acc));
|
||||||
ASSERT_NE(acc->result_type(), nullptr);
|
ASSERT_NE(acc->result_type(), nullptr);
|
||||||
ASSERT_TRUE(acc->result_type()->Is<ast::type::Pointer>());
|
ASSERT_TRUE(acc->result_type()->Is<ast::type::Pointer>());
|
||||||
|
@ -412,7 +412,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array_Constant) {
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine());
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto* acc = Index("my_var", 2);
|
auto* acc = IndexAccessor("my_var", 2);
|
||||||
EXPECT_TRUE(td()->DetermineResultType(acc));
|
EXPECT_TRUE(td()->DetermineResultType(acc));
|
||||||
ASSERT_NE(acc->result_type(), nullptr);
|
ASSERT_NE(acc->result_type(), nullptr);
|
||||||
EXPECT_TRUE(acc->result_type()->Is<ast::type::F32>())
|
EXPECT_TRUE(acc->result_type()->Is<ast::type::F32>())
|
||||||
|
@ -427,7 +427,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix) {
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine());
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto* acc = Index("my_var", 2);
|
auto* acc = IndexAccessor("my_var", 2);
|
||||||
EXPECT_TRUE(td()->DetermineResultType(acc));
|
EXPECT_TRUE(td()->DetermineResultType(acc));
|
||||||
ASSERT_NE(acc->result_type(), nullptr);
|
ASSERT_NE(acc->result_type(), nullptr);
|
||||||
ASSERT_TRUE(acc->result_type()->Is<ast::type::Pointer>());
|
ASSERT_TRUE(acc->result_type()->Is<ast::type::Pointer>());
|
||||||
|
@ -443,7 +443,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix_BothDimensions) {
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine());
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto* acc = Index(Index("my_var", 2), 1);
|
auto* acc = IndexAccessor(IndexAccessor("my_var", 2), 1);
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(acc));
|
EXPECT_TRUE(td()->DetermineResultType(acc));
|
||||||
ASSERT_NE(acc->result_type(), nullptr);
|
ASSERT_NE(acc->result_type(), nullptr);
|
||||||
|
@ -459,7 +459,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Vector) {
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine());
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto* acc = Index("my_var", 2);
|
auto* acc = IndexAccessor("my_var", 2);
|
||||||
EXPECT_TRUE(td()->DetermineResultType(acc));
|
EXPECT_TRUE(td()->DetermineResultType(acc));
|
||||||
ASSERT_NE(acc->result_type(), nullptr);
|
ASSERT_NE(acc->result_type(), nullptr);
|
||||||
ASSERT_TRUE(acc->result_type()->Is<ast::type::Pointer>());
|
ASSERT_TRUE(acc->result_type()->Is<ast::type::Pointer>());
|
||||||
|
@ -802,7 +802,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct) {
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine());
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto* mem = Member("my_struct", "second_member");
|
auto* mem = MemberAccessor("my_struct", "second_member");
|
||||||
EXPECT_TRUE(td()->DetermineResultType(mem));
|
EXPECT_TRUE(td()->DetermineResultType(mem));
|
||||||
ASSERT_NE(mem->result_type(), nullptr);
|
ASSERT_NE(mem->result_type(), nullptr);
|
||||||
ASSERT_TRUE(mem->result_type()->Is<ast::type::Pointer>());
|
ASSERT_TRUE(mem->result_type()->Is<ast::type::Pointer>());
|
||||||
|
@ -831,7 +831,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct_Alias) {
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine());
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto* mem = Member("my_struct", "second_member");
|
auto* mem = MemberAccessor("my_struct", "second_member");
|
||||||
EXPECT_TRUE(td()->DetermineResultType(mem));
|
EXPECT_TRUE(td()->DetermineResultType(mem));
|
||||||
ASSERT_NE(mem->result_type(), nullptr);
|
ASSERT_NE(mem->result_type(), nullptr);
|
||||||
ASSERT_TRUE(mem->result_type()->Is<ast::type::Pointer>());
|
ASSERT_TRUE(mem->result_type()->Is<ast::type::Pointer>());
|
||||||
|
@ -846,7 +846,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_VectorSwizzle) {
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine());
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto* mem = Member("my_vec", "xy");
|
auto* mem = MemberAccessor("my_vec", "xy");
|
||||||
EXPECT_TRUE(td()->DetermineResultType(mem)) << td()->error();
|
EXPECT_TRUE(td()->DetermineResultType(mem)) << td()->error();
|
||||||
ASSERT_NE(mem->result_type(), nullptr);
|
ASSERT_NE(mem->result_type(), nullptr);
|
||||||
ASSERT_TRUE(mem->result_type()->Is<ast::type::Vector>());
|
ASSERT_TRUE(mem->result_type()->Is<ast::type::Vector>());
|
||||||
|
@ -863,7 +863,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_VectorSwizzle_SingleElement) {
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine());
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto* mem = Member("my_vec", "x");
|
auto* mem = MemberAccessor("my_vec", "x");
|
||||||
EXPECT_TRUE(td()->DetermineResultType(mem)) << td()->error();
|
EXPECT_TRUE(td()->DetermineResultType(mem)) << td()->error();
|
||||||
ASSERT_NE(mem->result_type(), nullptr);
|
ASSERT_NE(mem->result_type(), nullptr);
|
||||||
ASSERT_TRUE(mem->result_type()->Is<ast::type::Pointer>());
|
ASSERT_TRUE(mem->result_type()->Is<ast::type::Pointer>());
|
||||||
|
@ -922,7 +922,9 @@ TEST_F(TypeDeterminerTest, Expr_Accessor_MultiLevel) {
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine());
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto* mem = Member(Member(Index(Member("c", "mem"), 0), "foo"), "yx");
|
auto* mem = MemberAccessor(
|
||||||
|
MemberAccessor(IndexAccessor(MemberAccessor("c", "mem"), 0), "foo"),
|
||||||
|
"yx");
|
||||||
EXPECT_TRUE(td()->DetermineResultType(mem)) << td()->error();
|
EXPECT_TRUE(td()->DetermineResultType(mem)) << td()->error();
|
||||||
|
|
||||||
ASSERT_NE(mem->result_type(), nullptr);
|
ASSERT_NE(mem->result_type(), nullptr);
|
||||||
|
|
|
@ -30,14 +30,14 @@ namespace {
|
||||||
using HlslGeneratorImplTest_Expression = TestHelper;
|
using HlslGeneratorImplTest_Expression = TestHelper;
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) {
|
TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) {
|
||||||
auto* expr = Index("ary", 5);
|
auto* expr = IndexAccessor("ary", 5);
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
||||||
EXPECT_EQ(result(), "ary[5]");
|
EXPECT_EQ(result(), "ary[5]");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) {
|
TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) {
|
||||||
auto* expr = Index("ary", "idx");
|
auto* expr = IndexAccessor("ary", "idx");
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
||||||
EXPECT_EQ(result(), "ary[idx]");
|
EXPECT_EQ(result(), "ary[idx]");
|
||||||
|
|
|
@ -359,7 +359,8 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("depth"), Member("coord", "x")),
|
create<ast::AssignmentStatement>(Expr("depth"),
|
||||||
|
MemberAccessor("coord", "x")),
|
||||||
});
|
});
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
mod->RegisterSymbol("main"), "main", params, ty.void_, body,
|
mod->RegisterSymbol("main"), "main", params, ty.void_, body,
|
||||||
|
|
|
@ -185,7 +185,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("depth"), Member("coord", "x")),
|
create<ast::AssignmentStatement>(Expr("depth"),
|
||||||
|
MemberAccessor("coord", "x")),
|
||||||
create<ast::ReturnStatement>(),
|
create<ast::ReturnStatement>(),
|
||||||
});
|
});
|
||||||
auto* func = create<ast::Function>(
|
auto* func = create<ast::Function>(
|
||||||
|
@ -229,7 +230,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
||||||
Member("coord", "x"), ast::VariableDecorationList{});
|
MemberAccessor("coord", "x"), ast::VariableDecorationList{});
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::VariableDeclStatement>(var),
|
create<ast::VariableDeclStatement>(var),
|
||||||
|
@ -282,7 +283,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
||||||
create<ast::MemberAccessorExpression>(
|
create<ast::MemberAccessorExpression>(
|
||||||
Member("uniforms", "coord"), Expr("x")),
|
MemberAccessor("uniforms", "coord"), Expr("x")),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
|
@ -343,7 +344,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
||||||
Member("coord", "b"), ast::VariableDecorationList{});
|
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::VariableDeclStatement>(var),
|
create<ast::VariableDeclStatement>(var),
|
||||||
|
@ -400,7 +401,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
||||||
Member("coord", "b"), ast::VariableDecorationList{});
|
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::VariableDeclStatement>(var),
|
create<ast::VariableDeclStatement>(var),
|
||||||
|
@ -456,7 +457,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
mod->AddGlobalVariable(coord_var);
|
mod->AddGlobalVariable(coord_var);
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Member("coord", "b"), Expr(2.0f)),
|
create<ast::AssignmentStatement>(MemberAccessor("coord", "b"),
|
||||||
|
Expr(2.0f)),
|
||||||
create<ast::ReturnStatement>(),
|
create<ast::ReturnStatement>(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -641,7 +643,8 @@ TEST_F(
|
||||||
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32));
|
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("depth"), Member("coord", "x")),
|
create<ast::AssignmentStatement>(Expr("depth"),
|
||||||
|
MemberAccessor("coord", "x")),
|
||||||
create<ast::ReturnStatement>(Expr("param")),
|
create<ast::ReturnStatement>(Expr("param")),
|
||||||
});
|
});
|
||||||
auto* sub_func =
|
auto* sub_func =
|
||||||
|
@ -703,7 +706,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32));
|
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::ReturnStatement>(Member("coord", "x")),
|
create<ast::ReturnStatement>(MemberAccessor("coord", "x")),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* sub_func =
|
auto* sub_func =
|
||||||
|
@ -764,7 +767,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32));
|
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32));
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::ReturnStatement>(Member("coord", "x")),
|
create<ast::ReturnStatement>(MemberAccessor("coord", "x")),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* sub_func =
|
auto* sub_func =
|
||||||
|
@ -993,7 +996,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
{
|
{
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
||||||
Member("data", "d"), ast::VariableDecorationList{});
|
MemberAccessor("data", "d"), ast::VariableDecorationList{});
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::VariableDeclStatement>(var),
|
create<ast::VariableDeclStatement>(var),
|
||||||
|
@ -1012,7 +1015,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
{
|
{
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
||||||
Member("data", "d"), ast::VariableDecorationList{});
|
MemberAccessor("data", "d"), ast::VariableDecorationList{});
|
||||||
|
|
||||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::VariableDeclStatement>(var),
|
create<ast::VariableDeclStatement>(var),
|
||||||
|
|
|
@ -52,7 +52,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
|
||||||
|
|
||||||
auto* str_var = Var("str", ast::StorageClass::kPrivate, &s);
|
auto* str_var = Var("str", ast::StorageClass::kPrivate, &s);
|
||||||
|
|
||||||
auto* expr = Member("str", "mem");
|
auto* expr = MemberAccessor("str", "mem");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(str_var);
|
td.RegisterVariableForTesting(str_var);
|
||||||
gen.register_global(str_var);
|
gen.register_global(str_var);
|
||||||
|
@ -88,7 +88,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
||||||
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
||||||
auto* expr = Member("data", "b");
|
auto* expr = MemberAccessor("data", "b");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
td.RegisterVariableForTesting(coord_var);
|
||||||
gen.register_global(coord_var);
|
gen.register_global(coord_var);
|
||||||
|
@ -126,7 +126,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
||||||
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
||||||
auto* expr = Member("data", "a");
|
auto* expr = MemberAccessor("data", "a");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
td.RegisterVariableForTesting(coord_var);
|
||||||
gen.register_global(coord_var);
|
gen.register_global(coord_var);
|
||||||
|
@ -171,7 +171,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
||||||
|
|
||||||
auto* lhs = Member("data", "a");
|
auto* lhs = MemberAccessor("data", "a");
|
||||||
auto* rhs = Expr("b");
|
auto* rhs = Expr("b");
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
@ -224,7 +224,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
||||||
|
|
||||||
auto* lhs = Member("data", "a");
|
auto* lhs = MemberAccessor("data", "a");
|
||||||
auto* rhs = Construct(ty.mat2x3<f32>(), ast::ExpressionList{});
|
auto* rhs = Construct(ty.mat2x3<f32>(), ast::ExpressionList{});
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
@ -274,7 +274,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
||||||
|
|
||||||
auto* expr = Member("data", "a");
|
auto* expr = MemberAccessor("data", "a");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
td.RegisterVariableForTesting(coord_var);
|
||||||
gen.register_global(coord_var);
|
gen.register_global(coord_var);
|
||||||
|
@ -318,7 +318,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
||||||
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
||||||
auto* expr = Member("data", "a");
|
auto* expr = MemberAccessor("data", "a");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
td.RegisterVariableForTesting(coord_var);
|
||||||
gen.register_global(coord_var);
|
gen.register_global(coord_var);
|
||||||
|
@ -353,7 +353,7 @@ TEST_F(
|
||||||
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
||||||
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
||||||
auto* expr = Member("data", "a");
|
auto* expr = MemberAccessor("data", "a");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
td.RegisterVariableForTesting(coord_var);
|
||||||
gen.register_global(coord_var);
|
gen.register_global(coord_var);
|
||||||
|
@ -393,7 +393,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
||||||
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
||||||
auto* expr = Index(Index(Member("data", "a"), Expr(2)), Expr(1));
|
auto* expr = IndexAccessor(
|
||||||
|
IndexAccessor(MemberAccessor("data", "a"), Expr(2)), Expr(1));
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
td.RegisterVariableForTesting(coord_var);
|
||||||
gen.register_global(coord_var);
|
gen.register_global(coord_var);
|
||||||
|
@ -429,7 +430,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
||||||
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
||||||
auto* expr = Index(Member("data", "a"), Expr(2));
|
auto* expr = IndexAccessor(MemberAccessor("data", "a"), Expr(2));
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
td.RegisterVariableForTesting(coord_var);
|
||||||
gen.register_global(coord_var);
|
gen.register_global(coord_var);
|
||||||
|
@ -465,7 +466,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
|
||||||
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
ast::type::Struct s(mod->RegisterSymbol("Data"), "Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
auto* coord_var = Var("data", ast::StorageClass::kStorageBuffer, &s);
|
||||||
auto* expr = Index(Member("data", "a"), Sub(Add(Expr(2), Expr(4)), Expr(3)));
|
auto* expr = IndexAccessor(MemberAccessor("data", "a"),
|
||||||
|
Sub(Add(Expr(2), Expr(4)), Expr(3)));
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
td.RegisterVariableForTesting(coord_var);
|
||||||
gen.register_global(coord_var);
|
gen.register_global(coord_var);
|
||||||
|
@ -510,7 +512,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
|
|
||||||
auto* lhs = Member("data", "b");
|
auto* lhs = MemberAccessor("data", "b");
|
||||||
auto* rhs = Expr(2.0f);
|
auto* rhs = Expr(2.0f);
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
|
||||||
|
@ -553,7 +555,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
|
|
||||||
auto* lhs = Index(Member("data", "a"), Expr(2));
|
auto* lhs = IndexAccessor(MemberAccessor("data", "a"), Expr(2));
|
||||||
auto* rhs = Expr(2);
|
auto* rhs = Expr(2);
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
|
||||||
|
@ -595,7 +597,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
|
|
||||||
auto* lhs = Member("data", "a");
|
auto* lhs = MemberAccessor("data", "a");
|
||||||
auto* rhs = Expr(2);
|
auto* rhs = Expr(2);
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
|
||||||
|
@ -637,7 +639,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
|
|
||||||
auto* expr = Member("data", "b");
|
auto* expr = MemberAccessor("data", "b");
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
ASSERT_TRUE(td.DetermineResultType(expr));
|
||||||
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
||||||
|
@ -678,7 +680,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
|
|
||||||
auto* lhs = Member("data", "b");
|
auto* lhs = MemberAccessor("data", "b");
|
||||||
auto* rhs = vec3<f32>(1.f, 2.f, 3.f);
|
auto* rhs = vec3<f32>(1.f, 2.f, 3.f);
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
@ -744,7 +746,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
|
|
||||||
auto* expr = Member(Index(Member("data", "c"), Expr(2)), "b");
|
auto* expr =
|
||||||
|
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b");
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
ASSERT_TRUE(td.DetermineResultType(expr));
|
||||||
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
||||||
|
@ -804,7 +807,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
|
|
||||||
auto* expr = Member(Member(Index(Member("data", "c"), Expr(2)), "b"), "xy");
|
auto* expr = MemberAccessor(
|
||||||
|
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
|
||||||
|
"xy");
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
ASSERT_TRUE(td.DetermineResultType(expr));
|
||||||
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
||||||
|
@ -864,7 +869,9 @@ TEST_F(
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
|
|
||||||
auto* expr = Member(Member(Index(Member("data", "c"), Expr(2)), "b"), "g");
|
auto* expr = MemberAccessor(
|
||||||
|
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
|
||||||
|
"g");
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
ASSERT_TRUE(td.DetermineResultType(expr));
|
||||||
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
||||||
|
@ -923,7 +930,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
|
|
||||||
auto* expr = Index(Member(Index(Member("data", "c"), Expr(2)), "b"), Expr(1));
|
auto* expr = IndexAccessor(
|
||||||
|
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
|
||||||
|
Expr(1));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
ASSERT_TRUE(td.DetermineResultType(expr));
|
||||||
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
||||||
|
@ -982,7 +991,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
|
|
||||||
auto* lhs = Member(Index(Member("data", "c"), Expr(2)), "b");
|
auto* lhs =
|
||||||
|
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b");
|
||||||
|
|
||||||
auto* assign =
|
auto* assign =
|
||||||
create<ast::AssignmentStatement>(lhs, vec3<f32>(1.f, 2.f, 3.f));
|
create<ast::AssignmentStatement>(lhs, vec3<f32>(1.f, 2.f, 3.f));
|
||||||
|
@ -1046,7 +1056,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
|
|
||||||
auto* lhs = Member(Member(Index(Member("data", "c"), Expr(2)), "b"), "y");
|
auto* lhs = MemberAccessor(
|
||||||
|
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
|
||||||
|
"y");
|
||||||
auto* rhs = Expr(1.f);
|
auto* rhs = Expr(1.f);
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
|
|
@ -54,7 +54,7 @@ TEST_F(BuilderTest, ArrayAccessor) {
|
||||||
auto* ary = Expr("ary");
|
auto* ary = Expr("ary");
|
||||||
auto* idx_expr = Expr(1);
|
auto* idx_expr = Expr(1);
|
||||||
|
|
||||||
auto* expr = Index(ary, idx_expr);
|
auto* expr = IndexAccessor(ary, idx_expr);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||||
|
@ -91,7 +91,7 @@ TEST_F(BuilderTest, Accessor_Array_LoadIndex) {
|
||||||
auto* ary = Expr("ary");
|
auto* ary = Expr("ary");
|
||||||
auto* idx_expr = Expr("idx");
|
auto* idx_expr = Expr("idx");
|
||||||
|
|
||||||
auto* expr = Index(ary, idx_expr);
|
auto* expr = IndexAccessor(ary, idx_expr);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
td.RegisterVariableForTesting(idx);
|
td.RegisterVariableForTesting(idx);
|
||||||
|
@ -130,7 +130,7 @@ TEST_F(BuilderTest, ArrayAccessor_Dynamic) {
|
||||||
|
|
||||||
auto* ary = Expr("ary");
|
auto* ary = Expr("ary");
|
||||||
|
|
||||||
auto* expr = Index(ary, Add(1, 2));
|
auto* expr = IndexAccessor(ary, Add(1, 2));
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||||
|
@ -166,7 +166,7 @@ TEST_F(BuilderTest, ArrayAccessor_MultiLevel) {
|
||||||
|
|
||||||
auto* var = Var("ary", ast::StorageClass::kFunction, &ary4);
|
auto* var = Var("ary", ast::StorageClass::kFunction, &ary4);
|
||||||
|
|
||||||
auto* expr = Index(Index("ary", 3), 2);
|
auto* expr = IndexAccessor(IndexAccessor("ary", 3), 2);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||||
|
@ -204,7 +204,7 @@ TEST_F(BuilderTest, Accessor_ArrayWithSwizzle) {
|
||||||
|
|
||||||
auto* var = Var("ary", ast::StorageClass::kFunction, &ary4);
|
auto* var = Var("ary", ast::StorageClass::kFunction, &ary4);
|
||||||
|
|
||||||
auto* expr = Member(Index("ary", 2), "xy");
|
auto* expr = MemberAccessor(IndexAccessor("ary", 2), "xy");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||||
|
@ -255,7 +255,7 @@ TEST_F(BuilderTest, MemberAccessor) {
|
||||||
|
|
||||||
auto* var = Var("ident", ast::StorageClass::kFunction, &s_type);
|
auto* var = Var("ident", ast::StorageClass::kFunction, &s_type);
|
||||||
|
|
||||||
auto* expr = Member("ident", "b");
|
auto* expr = MemberAccessor("ident", "b");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||||
|
@ -312,7 +312,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
|
||||||
|
|
||||||
auto* var = Var("ident", ast::StorageClass::kFunction, &s_type);
|
auto* var = Var("ident", ast::StorageClass::kFunction, &s_type);
|
||||||
|
|
||||||
auto* expr = Member(Member("ident", "inner"), "a");
|
auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "a");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||||
|
@ -373,7 +373,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
|
||||||
|
|
||||||
auto* var = Var("ident", ast::StorageClass::kFunction, &s_type);
|
auto* var = Var("ident", ast::StorageClass::kFunction, &s_type);
|
||||||
|
|
||||||
auto* expr = Member(Member("ident", "inner"), "a");
|
auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "a");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||||
|
@ -432,7 +432,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
|
||||||
|
|
||||||
auto* var = Var("ident", ast::StorageClass::kFunction, &s_type);
|
auto* var = Var("ident", ast::StorageClass::kFunction, &s_type);
|
||||||
|
|
||||||
auto* lhs = Member(Member("ident", "inner"), "a");
|
auto* lhs = MemberAccessor(MemberAccessor("ident", "inner"), "a");
|
||||||
|
|
||||||
auto* rhs = Expr(2.0f);
|
auto* rhs = Expr(2.0f);
|
||||||
|
|
||||||
|
@ -499,7 +499,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
|
||||||
auto* store = Var("store", ast::StorageClass::kFunction, ty.f32);
|
auto* store = Var("store", ast::StorageClass::kFunction, ty.f32);
|
||||||
|
|
||||||
auto* lhs = Expr("store");
|
auto* lhs = Expr("store");
|
||||||
auto* rhs = Member(Member("ident", "inner"), "a");
|
auto* rhs = MemberAccessor(MemberAccessor("ident", "inner"), "a");
|
||||||
|
|
||||||
auto* expr = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* expr = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
|
||||||
|
@ -539,7 +539,7 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
|
||||||
|
|
||||||
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
|
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||||
|
|
||||||
auto* expr = Member("ident", "y");
|
auto* expr = MemberAccessor("ident", "y");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||||
|
@ -570,7 +570,7 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
|
||||||
|
|
||||||
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
|
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||||
|
|
||||||
auto* expr = Member("ident", "yx");
|
auto* expr = MemberAccessor("ident", "yx");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||||
|
@ -600,7 +600,7 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
|
||||||
|
|
||||||
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
|
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||||
|
|
||||||
auto* expr = Member(Member("ident", "yxz"), "xz");
|
auto* expr = MemberAccessor(MemberAccessor("ident", "yxz"), "xz");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||||
|
@ -631,7 +631,7 @@ TEST_F(BuilderTest, MemberAccessor_Member_of_Swizzle) {
|
||||||
|
|
||||||
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
|
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||||
|
|
||||||
auto* expr = Member(Member("ident", "yxz"), "x");
|
auto* expr = MemberAccessor(MemberAccessor("ident", "yxz"), "x");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||||
|
@ -661,7 +661,7 @@ TEST_F(BuilderTest, MemberAccessor_Array_of_Swizzle) {
|
||||||
|
|
||||||
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
|
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||||
|
|
||||||
auto* expr = Index(Member("ident", "yxz"), 1);
|
auto* expr = IndexAccessor(MemberAccessor("ident", "yxz"), 1);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||||
|
@ -727,8 +727,13 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
|
||||||
|
|
||||||
auto* var = Var("index", ast::StorageClass::kFunction, &a_ary_type);
|
auto* var = Var("index", ast::StorageClass::kFunction, &a_ary_type);
|
||||||
|
|
||||||
auto* expr = Member(
|
auto* expr = MemberAccessor(
|
||||||
Member(Member(Index(Member(Index("index", 0), "foo"), 2), "bar"), "baz"),
|
MemberAccessor(
|
||||||
|
MemberAccessor(
|
||||||
|
IndexAccessor(MemberAccessor(IndexAccessor("index", 0), "foo"),
|
||||||
|
2),
|
||||||
|
"bar"),
|
||||||
|
"baz"),
|
||||||
"yx");
|
"yx");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
|
@ -783,7 +788,7 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) {
|
||||||
vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)),
|
vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)),
|
||||||
{});
|
{});
|
||||||
|
|
||||||
auto* expr = Index("pos", 1u);
|
auto* expr = IndexAccessor("pos", 1u);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(var->constructor())) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(var->constructor())) << td.error();
|
||||||
|
@ -826,7 +831,7 @@ TEST_F(BuilderTest, Accessor_Const_Vec) {
|
||||||
auto* var = Const("pos", ast::StorageClass::kPrivate, ty.vec2<f32>(),
|
auto* var = Const("pos", ast::StorageClass::kPrivate, ty.vec2<f32>(),
|
||||||
vec2<f32>(0.0f, 0.5f), {});
|
vec2<f32>(0.0f, 0.5f), {});
|
||||||
|
|
||||||
auto* expr = Index("pos", 1u);
|
auto* expr = IndexAccessor("pos", 1u);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
td.RegisterVariableForTesting(var);
|
||||||
ASSERT_TRUE(td.DetermineResultType(var->constructor())) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(var->constructor())) << td.error();
|
||||||
|
|
Loading…
Reference in New Issue