tint: Add sem::IndexAccessorExpression
Also store expression object in MemberAccessorExpression, as well as the struct on sem::StructMember. These are used to implement spir-v reader atomics in a follow-up CL. Bug: tint:1441 Change-Id: Iea49cfb7f9d2e7898d89d2dac6a16a14022c546f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94523 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
90ec3d1368
commit
dfeaf29055
|
@ -428,6 +428,7 @@ libtint_source_set("libtint_core_all_src") {
|
||||||
"sem/for_loop_statement.h",
|
"sem/for_loop_statement.h",
|
||||||
"sem/i32.h",
|
"sem/i32.h",
|
||||||
"sem/if_statement.h",
|
"sem/if_statement.h",
|
||||||
|
"sem/index_accessor_expression.h",
|
||||||
"sem/info.h",
|
"sem/info.h",
|
||||||
"sem/loop_statement.h",
|
"sem/loop_statement.h",
|
||||||
"sem/materialize.h",
|
"sem/materialize.h",
|
||||||
|
@ -634,6 +635,8 @@ libtint_source_set("libtint_sem_src") {
|
||||||
"sem/i32.h",
|
"sem/i32.h",
|
||||||
"sem/if_statement.cc",
|
"sem/if_statement.cc",
|
||||||
"sem/if_statement.h",
|
"sem/if_statement.h",
|
||||||
|
"sem/index_accessor_expression.cc",
|
||||||
|
"sem/index_accessor_expression.h",
|
||||||
"sem/info.cc",
|
"sem/info.cc",
|
||||||
"sem/info.h",
|
"sem/info.h",
|
||||||
"sem/loop_statement.cc",
|
"sem/loop_statement.cc",
|
||||||
|
|
|
@ -326,6 +326,8 @@ set(TINT_LIB_SRCS
|
||||||
sem/i32.h
|
sem/i32.h
|
||||||
sem/if_statement.cc
|
sem/if_statement.cc
|
||||||
sem/if_statement.h
|
sem/if_statement.h
|
||||||
|
sem/index_accessor_expression.cc
|
||||||
|
sem/index_accessor_expression.h
|
||||||
sem/info.cc
|
sem/info.cc
|
||||||
sem/info.h
|
sem/info.h
|
||||||
sem/loop_statement.cc
|
sem/loop_statement.cc
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
#include "src/tint/resolver/resolver_test_helper.h"
|
#include "src/tint/resolver/resolver_test_helper.h"
|
||||||
|
#include "src/tint/sem/index_accessor_expression.h"
|
||||||
#include "src/tint/sem/reference.h"
|
#include "src/tint/sem/reference.h"
|
||||||
|
|
||||||
using namespace tint::number_suffixes; // NOLINT
|
using namespace tint::number_suffixes; // NOLINT
|
||||||
|
@ -41,6 +42,11 @@ TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic_Ref) {
|
||||||
WrapInFunction(Decl(idx), acc);
|
WrapInFunction(Decl(idx), acc);
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions_Dynamic_Ref) {
|
TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions_Dynamic_Ref) {
|
||||||
|
@ -51,6 +57,11 @@ TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions_Dynamic_Ref) {
|
||||||
WrapInFunction(Decl(idx), Decl(idy), acc);
|
WrapInFunction(Decl(idx), Decl(idy), acc);
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic) {
|
TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic) {
|
||||||
|
@ -61,6 +72,11 @@ TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic) {
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve());
|
EXPECT_TRUE(r()->Resolve());
|
||||||
EXPECT_EQ(r()->error(), "");
|
EXPECT_EQ(r()->error(), "");
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Matrix_XDimension_Dynamic) {
|
TEST_F(ResolverIndexAccessorTest, Matrix_XDimension_Dynamic) {
|
||||||
|
@ -71,6 +87,11 @@ TEST_F(ResolverIndexAccessorTest, Matrix_XDimension_Dynamic) {
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve());
|
EXPECT_TRUE(r()->Resolve());
|
||||||
EXPECT_EQ(r()->error(), "");
|
EXPECT_EQ(r()->error(), "");
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Matrix_BothDimension_Dynamic) {
|
TEST_F(ResolverIndexAccessorTest, Matrix_BothDimension_Dynamic) {
|
||||||
|
@ -81,6 +102,11 @@ TEST_F(ResolverIndexAccessorTest, Matrix_BothDimension_Dynamic) {
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve());
|
EXPECT_TRUE(r()->Resolve());
|
||||||
EXPECT_EQ(r()->error(), "");
|
EXPECT_EQ(r()->error(), "");
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Matrix) {
|
TEST_F(ResolverIndexAccessorTest, Matrix) {
|
||||||
|
@ -97,6 +123,11 @@ TEST_F(ResolverIndexAccessorTest, Matrix) {
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
ASSERT_TRUE(ref->StoreType()->Is<sem::Vector>());
|
ASSERT_TRUE(ref->StoreType()->Is<sem::Vector>());
|
||||||
EXPECT_EQ(ref->StoreType()->As<sem::Vector>()->Width(), 3u);
|
EXPECT_EQ(ref->StoreType()->As<sem::Vector>()->Width(), 3u);
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions) {
|
TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions) {
|
||||||
|
@ -112,6 +143,11 @@ TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions) {
|
||||||
|
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Vector_F32) {
|
TEST_F(ResolverIndexAccessorTest, Vector_F32) {
|
||||||
|
@ -130,6 +166,11 @@ TEST_F(ResolverIndexAccessorTest, Vector_Dynamic_Ref) {
|
||||||
WrapInFunction(Decl(idx), acc);
|
WrapInFunction(Decl(idx), acc);
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve());
|
EXPECT_TRUE(r()->Resolve());
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Vector_Dynamic) {
|
TEST_F(ResolverIndexAccessorTest, Vector_Dynamic) {
|
||||||
|
@ -139,6 +180,11 @@ TEST_F(ResolverIndexAccessorTest, Vector_Dynamic) {
|
||||||
WrapInFunction(Decl(idx), acc);
|
WrapInFunction(Decl(idx), acc);
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve());
|
EXPECT_TRUE(r()->Resolve());
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Vector) {
|
TEST_F(ResolverIndexAccessorTest, Vector) {
|
||||||
|
@ -154,6 +200,11 @@ TEST_F(ResolverIndexAccessorTest, Vector) {
|
||||||
|
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Array_Literal_i32) {
|
TEST_F(ResolverIndexAccessorTest, Array_Literal_i32) {
|
||||||
|
@ -165,6 +216,11 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_i32) {
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
ASSERT_NE(ref, nullptr);
|
ASSERT_NE(ref, nullptr);
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Array_Literal_u32) {
|
TEST_F(ResolverIndexAccessorTest, Array_Literal_u32) {
|
||||||
|
@ -176,6 +232,11 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_u32) {
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
ASSERT_NE(ref, nullptr);
|
ASSERT_NE(ref, nullptr);
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Array_Literal_AInt) {
|
TEST_F(ResolverIndexAccessorTest, Array_Literal_AInt) {
|
||||||
|
@ -187,6 +248,11 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_AInt) {
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
ASSERT_NE(ref, nullptr);
|
ASSERT_NE(ref, nullptr);
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Alias_Array) {
|
TEST_F(ResolverIndexAccessorTest, Alias_Array) {
|
||||||
|
@ -204,6 +270,11 @@ TEST_F(ResolverIndexAccessorTest, Alias_Array) {
|
||||||
|
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Array_Constant) {
|
TEST_F(ResolverIndexAccessorTest, Array_Constant) {
|
||||||
|
@ -216,6 +287,11 @@ TEST_F(ResolverIndexAccessorTest, Array_Constant) {
|
||||||
|
|
||||||
ASSERT_NE(TypeOf(acc), nullptr);
|
ASSERT_NE(TypeOf(acc), nullptr);
|
||||||
EXPECT_TRUE(TypeOf(acc)->Is<sem::F32>());
|
EXPECT_TRUE(TypeOf(acc)->Is<sem::F32>());
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Array_Dynamic_I32) {
|
TEST_F(ResolverIndexAccessorTest, Array_Dynamic_I32) {
|
||||||
|
@ -224,7 +300,8 @@ TEST_F(ResolverIndexAccessorTest, Array_Dynamic_I32) {
|
||||||
// var f : f32 = a[idx];
|
// var f : f32 = a[idx];
|
||||||
auto* a = Let("a", ty.array<f32, 3>(), array<f32, 3>());
|
auto* a = Let("a", ty.array<f32, 3>(), array<f32, 3>());
|
||||||
auto* idx = Var("idx", ty.i32(), Construct(ty.i32()));
|
auto* idx = Var("idx", ty.i32(), Construct(ty.i32()));
|
||||||
auto* f = Var("f", ty.f32(), IndexAccessor("a", Expr(Source{{12, 34}}, idx)));
|
auto* acc = IndexAccessor("a", Expr(Source{{12, 34}}, idx));
|
||||||
|
auto* f = Var("f", ty.f32(), acc);
|
||||||
Func("my_func", {}, ty.void_(),
|
Func("my_func", {}, ty.void_(),
|
||||||
{
|
{
|
||||||
Decl(a),
|
Decl(a),
|
||||||
|
@ -234,6 +311,11 @@ TEST_F(ResolverIndexAccessorTest, Array_Dynamic_I32) {
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve());
|
EXPECT_TRUE(r()->Resolve());
|
||||||
EXPECT_EQ(r()->error(), "");
|
EXPECT_EQ(r()->error(), "");
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Array_Literal_F32) {
|
TEST_F(ResolverIndexAccessorTest, Array_Literal_F32) {
|
||||||
|
@ -254,13 +336,19 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_I32) {
|
||||||
// let a : array<f32, 3>;
|
// let a : array<f32, 3>;
|
||||||
// var f : f32 = a[2i];
|
// var f : f32 = a[2i];
|
||||||
auto* a = Let("a", ty.array<f32, 3>(), array<f32, 3>());
|
auto* a = Let("a", ty.array<f32, 3>(), array<f32, 3>());
|
||||||
auto* f = Var("a_2", ty.f32(), IndexAccessor("a", 2_i));
|
auto* acc = IndexAccessor("a", 2_i);
|
||||||
|
auto* f = Var("a_2", ty.f32(), acc);
|
||||||
Func("my_func", {}, ty.void_(),
|
Func("my_func", {}, ty.void_(),
|
||||||
{
|
{
|
||||||
Decl(a),
|
Decl(a),
|
||||||
Decl(f),
|
Decl(f),
|
||||||
});
|
});
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Expr_Deref_FuncGoodParent) {
|
TEST_F(ResolverIndexAccessorTest, Expr_Deref_FuncGoodParent) {
|
||||||
|
@ -272,11 +360,16 @@ TEST_F(ResolverIndexAccessorTest, Expr_Deref_FuncGoodParent) {
|
||||||
auto* p = Param("p", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction));
|
auto* p = Param("p", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction));
|
||||||
auto* idx = Let("idx", ty.u32(), Construct(ty.u32()));
|
auto* idx = Let("idx", ty.u32(), Construct(ty.u32()));
|
||||||
auto* star_p = Deref(p);
|
auto* star_p = Deref(p);
|
||||||
auto* accessor_expr = IndexAccessor(Source{{12, 34}}, star_p, idx);
|
auto* acc = IndexAccessor(Source{{12, 34}}, star_p, idx);
|
||||||
auto* x = Var("x", ty.f32(), accessor_expr);
|
auto* x = Var("x", ty.f32(), acc);
|
||||||
Func("func", {p}, ty.f32(), {Decl(idx), Decl(x), Return(x)});
|
Func("func", {p}, ty.f32(), {Decl(idx), Decl(x), Return(x)});
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
|
||||||
|
auto idx_sem = Sem().Get(acc);
|
||||||
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverIndexAccessorTest, Expr_Deref_FuncBadParent) {
|
TEST_F(ResolverIndexAccessorTest, Expr_Deref_FuncBadParent) {
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
#include "src/tint/sem/for_loop_statement.h"
|
#include "src/tint/sem/for_loop_statement.h"
|
||||||
#include "src/tint/sem/function.h"
|
#include "src/tint/sem/function.h"
|
||||||
#include "src/tint/sem/if_statement.h"
|
#include "src/tint/sem/if_statement.h"
|
||||||
|
#include "src/tint/sem/index_accessor_expression.h"
|
||||||
#include "src/tint/sem/loop_statement.h"
|
#include "src/tint/sem/loop_statement.h"
|
||||||
#include "src/tint/sem/materialize.h"
|
#include "src/tint/sem/materialize.h"
|
||||||
#include "src/tint/sem/member_accessor_expression.h"
|
#include "src/tint/sem/member_accessor_expression.h"
|
||||||
|
@ -1359,8 +1360,9 @@ sem::Expression* Resolver::IndexAccessor(const ast::IndexAccessorExpression* exp
|
||||||
|
|
||||||
auto val = EvaluateConstantValue(expr, ty);
|
auto val = EvaluateConstantValue(expr, ty);
|
||||||
bool has_side_effects = idx->HasSideEffects() || obj->HasSideEffects();
|
bool has_side_effects = idx->HasSideEffects() || obj->HasSideEffects();
|
||||||
auto* sem = builder_->create<sem::Expression>(expr, ty, current_statement_, std::move(val),
|
auto* sem = builder_->create<sem::IndexAccessorExpression>(
|
||||||
has_side_effects, obj->SourceVariable());
|
expr, ty, obj, idx, current_statement_, std::move(val), has_side_effects,
|
||||||
|
obj->SourceVariable());
|
||||||
sem->Behaviors() = idx->Behaviors() + obj->Behaviors();
|
sem->Behaviors() = idx->Behaviors() + obj->Behaviors();
|
||||||
return sem;
|
return sem;
|
||||||
}
|
}
|
||||||
|
@ -1872,9 +1874,9 @@ sem::Expression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* e
|
||||||
const sem::Type* ret = nullptr;
|
const sem::Type* ret = nullptr;
|
||||||
std::vector<uint32_t> swizzle;
|
std::vector<uint32_t> swizzle;
|
||||||
|
|
||||||
// Structure may be a side-effecting expression (e.g. function call).
|
// Object may be a side-effecting expression (e.g. function call).
|
||||||
auto* sem_structure = sem_.Get(expr->structure);
|
auto* object = sem_.Get(expr->structure);
|
||||||
bool has_side_effects = sem_structure && sem_structure->HasSideEffects();
|
bool has_side_effects = object && object->HasSideEffects();
|
||||||
|
|
||||||
if (auto* str = storage_ty->As<sem::Struct>()) {
|
if (auto* str = storage_ty->As<sem::Struct>()) {
|
||||||
Mark(expr->member);
|
Mark(expr->member);
|
||||||
|
@ -1900,8 +1902,8 @@ sem::Expression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* e
|
||||||
ret = builder_->create<sem::Reference>(ret, ref->StorageClass(), ref->Access());
|
ret = builder_->create<sem::Reference>(ret, ref->StorageClass(), ref->Access());
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder_->create<sem::StructMemberAccess>(expr, ret, current_statement_, member,
|
return builder_->create<sem::StructMemberAccess>(expr, ret, current_statement_, object,
|
||||||
has_side_effects, source_var);
|
member, has_side_effects, source_var);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto* vec = storage_ty->As<sem::Vector>()) {
|
if (auto* vec = storage_ty->As<sem::Vector>()) {
|
||||||
|
@ -1967,8 +1969,8 @@ sem::Expression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* e
|
||||||
// the swizzle.
|
// the swizzle.
|
||||||
ret = builder_->create<sem::Vector>(vec->type(), static_cast<uint32_t>(size));
|
ret = builder_->create<sem::Vector>(vec->type(), static_cast<uint32_t>(size));
|
||||||
}
|
}
|
||||||
return builder_->create<sem::Swizzle>(expr, ret, current_statement_, std::move(swizzle),
|
return builder_->create<sem::Swizzle>(expr, ret, current_statement_, object,
|
||||||
has_side_effects, source_var);
|
std::move(swizzle), has_side_effects, source_var);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddError("invalid member accessor expression. Expected vector or struct, got '" +
|
AddError("invalid member accessor expression. Expected vector or struct, got '" +
|
||||||
|
@ -2384,6 +2386,8 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const_cast<sem::StructMember*>(sem_members[i])->SetStruct(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto stage = current_function_ ? current_function_->Declaration()->PipelineStage()
|
auto stage = current_function_ ? current_function_->Declaration()->PipelineStage()
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/tint/resolver/resolver_test_helper.h"
|
#include "src/tint/resolver/resolver_test_helper.h"
|
||||||
#include "src/tint/sem/expression.h"
|
#include "src/tint/sem/expression.h"
|
||||||
|
#include "src/tint/sem/index_accessor_expression.h"
|
||||||
|
|
||||||
using namespace tint::number_suffixes; // NOLINT
|
using namespace tint::number_suffixes; // NOLINT
|
||||||
|
|
||||||
|
|
|
@ -1101,6 +1101,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {
|
||||||
auto* sma = Sem().Get(mem)->As<sem::StructMemberAccess>();
|
auto* sma = Sem().Get(mem)->As<sem::StructMemberAccess>();
|
||||||
ASSERT_NE(sma, nullptr);
|
ASSERT_NE(sma, nullptr);
|
||||||
EXPECT_TRUE(sma->Member()->Type()->Is<sem::F32>());
|
EXPECT_TRUE(sma->Member()->Type()->Is<sem::F32>());
|
||||||
|
EXPECT_EQ(sma->Object()->Declaration(), mem->structure);
|
||||||
EXPECT_EQ(sma->Member()->Index(), 1u);
|
EXPECT_EQ(sma->Member()->Index(), 1u);
|
||||||
EXPECT_EQ(sma->Member()->Declaration()->symbol, Symbols().Get("second_member"));
|
EXPECT_EQ(sma->Member()->Declaration()->symbol, Symbols().Get("second_member"));
|
||||||
}
|
}
|
||||||
|
@ -1123,6 +1124,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) {
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
||||||
auto* sma = Sem().Get(mem)->As<sem::StructMemberAccess>();
|
auto* sma = Sem().Get(mem)->As<sem::StructMemberAccess>();
|
||||||
ASSERT_NE(sma, nullptr);
|
ASSERT_NE(sma, nullptr);
|
||||||
|
EXPECT_EQ(sma->Object()->Declaration(), mem->structure);
|
||||||
EXPECT_TRUE(sma->Member()->Type()->Is<sem::F32>());
|
EXPECT_TRUE(sma->Member()->Type()->Is<sem::F32>());
|
||||||
EXPECT_EQ(sma->Member()->Index(), 1u);
|
EXPECT_EQ(sma->Member()->Index(), 1u);
|
||||||
}
|
}
|
||||||
|
@ -1139,8 +1141,10 @@ TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle) {
|
||||||
ASSERT_TRUE(TypeOf(mem)->Is<sem::Vector>());
|
ASSERT_TRUE(TypeOf(mem)->Is<sem::Vector>());
|
||||||
EXPECT_TRUE(TypeOf(mem)->As<sem::Vector>()->type()->Is<sem::F32>());
|
EXPECT_TRUE(TypeOf(mem)->As<sem::Vector>()->type()->Is<sem::F32>());
|
||||||
EXPECT_EQ(TypeOf(mem)->As<sem::Vector>()->Width(), 4u);
|
EXPECT_EQ(TypeOf(mem)->As<sem::Vector>()->Width(), 4u);
|
||||||
ASSERT_TRUE(Sem().Get(mem)->Is<sem::Swizzle>());
|
auto* sma = Sem().Get(mem)->As<sem::Swizzle>();
|
||||||
EXPECT_THAT(Sem().Get(mem)->As<sem::Swizzle>()->Indices(), ElementsAre(0, 2, 1, 3));
|
ASSERT_NE(sma, nullptr);
|
||||||
|
EXPECT_EQ(sma->Object()->Declaration(), mem->structure);
|
||||||
|
EXPECT_THAT(sma->As<sem::Swizzle>()->Indices(), ElementsAre(0, 2, 1, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle_SingleElement) {
|
TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle_SingleElement) {
|
||||||
|
@ -1156,7 +1160,9 @@ TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle_SingleElement) {
|
||||||
|
|
||||||
auto* ref = TypeOf(mem)->As<sem::Reference>();
|
auto* ref = TypeOf(mem)->As<sem::Reference>();
|
||||||
ASSERT_TRUE(ref->StoreType()->Is<sem::F32>());
|
ASSERT_TRUE(ref->StoreType()->Is<sem::F32>());
|
||||||
ASSERT_TRUE(Sem().Get(mem)->Is<sem::Swizzle>());
|
auto* sma = Sem().Get(mem)->As<sem::Swizzle>();
|
||||||
|
ASSERT_NE(sma, nullptr);
|
||||||
|
EXPECT_EQ(sma->Object()->Declaration(), mem->structure);
|
||||||
EXPECT_THAT(Sem().Get(mem)->As<sem::Swizzle>()->Indices(), ElementsAre(2));
|
EXPECT_THAT(Sem().Get(mem)->As<sem::Swizzle>()->Indices(), ElementsAre(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/tint/resolver/resolver_test_helper.h"
|
#include "src/tint/resolver/resolver_test_helper.h"
|
||||||
#include "src/tint/sem/expression.h"
|
#include "src/tint/sem/expression.h"
|
||||||
|
#include "src/tint/sem/index_accessor_expression.h"
|
||||||
#include "src/tint/sem/member_accessor_expression.h"
|
#include "src/tint/sem/member_accessor_expression.h"
|
||||||
|
|
||||||
using namespace tint::number_suffixes; // NOLINT
|
using namespace tint::number_suffixes; // NOLINT
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "src/tint/resolver/resolver.h"
|
#include "src/tint/resolver/resolver.h"
|
||||||
|
|
||||||
#include "src/tint/resolver/resolver_test_helper.h"
|
#include "src/tint/resolver/resolver_test_helper.h"
|
||||||
|
#include "src/tint/sem/index_accessor_expression.h"
|
||||||
#include "src/tint/sem/member_accessor_expression.h"
|
#include "src/tint/sem/member_accessor_expression.h"
|
||||||
|
|
||||||
using namespace tint::number_suffixes; // NOLINT
|
using namespace tint::number_suffixes; // NOLINT
|
||||||
|
|
|
@ -49,6 +49,9 @@ TEST_F(ResolverStructLayoutTest, Scalars) {
|
||||||
EXPECT_EQ(sem->Members()[2]->Offset(), 8u);
|
EXPECT_EQ(sem->Members()[2]->Offset(), 8u);
|
||||||
EXPECT_EQ(sem->Members()[2]->Align(), 4u);
|
EXPECT_EQ(sem->Members()[2]->Align(), 4u);
|
||||||
EXPECT_EQ(sem->Members()[2]->Size(), 4u);
|
EXPECT_EQ(sem->Members()[2]->Size(), 4u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, Alias) {
|
TEST_F(ResolverStructLayoutTest, Alias) {
|
||||||
|
@ -74,6 +77,9 @@ TEST_F(ResolverStructLayoutTest, Alias) {
|
||||||
EXPECT_EQ(sem->Members()[1]->Offset(), 4u);
|
EXPECT_EQ(sem->Members()[1]->Offset(), 4u);
|
||||||
EXPECT_EQ(sem->Members()[1]->Align(), 4u);
|
EXPECT_EQ(sem->Members()[1]->Align(), 4u);
|
||||||
EXPECT_EQ(sem->Members()[1]->Size(), 4u);
|
EXPECT_EQ(sem->Members()[1]->Size(), 4u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayStaticSize) {
|
TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayStaticSize) {
|
||||||
|
@ -100,6 +106,9 @@ TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayStaticSize) {
|
||||||
EXPECT_EQ(sem->Members()[2]->Offset(), 32u);
|
EXPECT_EQ(sem->Members()[2]->Offset(), 32u);
|
||||||
EXPECT_EQ(sem->Members()[2]->Align(), 4u);
|
EXPECT_EQ(sem->Members()[2]->Align(), 4u);
|
||||||
EXPECT_EQ(sem->Members()[2]->Size(), 4u);
|
EXPECT_EQ(sem->Members()[2]->Size(), 4u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, ExplicitStrideArrayStaticSize) {
|
TEST_F(ResolverStructLayoutTest, ExplicitStrideArrayStaticSize) {
|
||||||
|
@ -126,6 +135,9 @@ TEST_F(ResolverStructLayoutTest, ExplicitStrideArrayStaticSize) {
|
||||||
EXPECT_EQ(sem->Members()[2]->Offset(), 104u);
|
EXPECT_EQ(sem->Members()[2]->Offset(), 104u);
|
||||||
EXPECT_EQ(sem->Members()[2]->Align(), 4u);
|
EXPECT_EQ(sem->Members()[2]->Align(), 4u);
|
||||||
EXPECT_EQ(sem->Members()[2]->Size(), 32u);
|
EXPECT_EQ(sem->Members()[2]->Size(), 32u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayRuntimeSized) {
|
TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayRuntimeSized) {
|
||||||
|
@ -144,6 +156,9 @@ TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayRuntimeSized) {
|
||||||
EXPECT_EQ(sem->Members()[0]->Offset(), 0u);
|
EXPECT_EQ(sem->Members()[0]->Offset(), 0u);
|
||||||
EXPECT_EQ(sem->Members()[0]->Align(), 4u);
|
EXPECT_EQ(sem->Members()[0]->Align(), 4u);
|
||||||
EXPECT_EQ(sem->Members()[0]->Size(), 4u);
|
EXPECT_EQ(sem->Members()[0]->Size(), 4u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, ExplicitStrideArrayRuntimeSized) {
|
TEST_F(ResolverStructLayoutTest, ExplicitStrideArrayRuntimeSized) {
|
||||||
|
@ -162,6 +177,9 @@ TEST_F(ResolverStructLayoutTest, ExplicitStrideArrayRuntimeSized) {
|
||||||
EXPECT_EQ(sem->Members()[0]->Offset(), 0u);
|
EXPECT_EQ(sem->Members()[0]->Offset(), 0u);
|
||||||
EXPECT_EQ(sem->Members()[0]->Align(), 4u);
|
EXPECT_EQ(sem->Members()[0]->Align(), 4u);
|
||||||
EXPECT_EQ(sem->Members()[0]->Size(), 32u);
|
EXPECT_EQ(sem->Members()[0]->Size(), 32u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayOfExplicitStrideArray) {
|
TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayOfExplicitStrideArray) {
|
||||||
|
@ -182,6 +200,9 @@ TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayOfExplicitStrideArray) {
|
||||||
EXPECT_EQ(sem->Members()[0]->Offset(), 0u);
|
EXPECT_EQ(sem->Members()[0]->Offset(), 0u);
|
||||||
EXPECT_EQ(sem->Members()[0]->Align(), 4u);
|
EXPECT_EQ(sem->Members()[0]->Align(), 4u);
|
||||||
EXPECT_EQ(sem->Members()[0]->Size(), 384u);
|
EXPECT_EQ(sem->Members()[0]->Size(), 384u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayOfStructure) {
|
TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayOfStructure) {
|
||||||
|
@ -206,6 +227,9 @@ TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayOfStructure) {
|
||||||
EXPECT_EQ(sem->Members()[0]->Offset(), 0u);
|
EXPECT_EQ(sem->Members()[0]->Offset(), 0u);
|
||||||
EXPECT_EQ(sem->Members()[0]->Align(), 16u);
|
EXPECT_EQ(sem->Members()[0]->Align(), 16u);
|
||||||
EXPECT_EQ(sem->Members()[0]->Size(), 576u);
|
EXPECT_EQ(sem->Members()[0]->Size(), 576u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, Vector) {
|
TEST_F(ResolverStructLayoutTest, Vector) {
|
||||||
|
@ -232,6 +256,9 @@ TEST_F(ResolverStructLayoutTest, Vector) {
|
||||||
EXPECT_EQ(sem->Members()[2]->Offset(), 32u); // vec4
|
EXPECT_EQ(sem->Members()[2]->Offset(), 32u); // vec4
|
||||||
EXPECT_EQ(sem->Members()[2]->Align(), 16u);
|
EXPECT_EQ(sem->Members()[2]->Align(), 16u);
|
||||||
EXPECT_EQ(sem->Members()[2]->Size(), 16u);
|
EXPECT_EQ(sem->Members()[2]->Size(), 16u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, Matrix) {
|
TEST_F(ResolverStructLayoutTest, Matrix) {
|
||||||
|
@ -282,6 +309,9 @@ TEST_F(ResolverStructLayoutTest, Matrix) {
|
||||||
EXPECT_EQ(sem->Members()[8]->Offset(), 304u); // mat4x4
|
EXPECT_EQ(sem->Members()[8]->Offset(), 304u); // mat4x4
|
||||||
EXPECT_EQ(sem->Members()[8]->Align(), 16u);
|
EXPECT_EQ(sem->Members()[8]->Align(), 16u);
|
||||||
EXPECT_EQ(sem->Members()[8]->Size(), 64u);
|
EXPECT_EQ(sem->Members()[8]->Size(), 64u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, NestedStruct) {
|
TEST_F(ResolverStructLayoutTest, NestedStruct) {
|
||||||
|
@ -311,6 +341,9 @@ TEST_F(ResolverStructLayoutTest, NestedStruct) {
|
||||||
EXPECT_EQ(sem->Members()[2]->Offset(), 64u);
|
EXPECT_EQ(sem->Members()[2]->Offset(), 64u);
|
||||||
EXPECT_EQ(sem->Members()[2]->Align(), 4u);
|
EXPECT_EQ(sem->Members()[2]->Align(), 4u);
|
||||||
EXPECT_EQ(sem->Members()[2]->Size(), 4u);
|
EXPECT_EQ(sem->Members()[2]->Size(), 4u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, SizeAttributes) {
|
TEST_F(ResolverStructLayoutTest, SizeAttributes) {
|
||||||
|
@ -346,6 +379,9 @@ TEST_F(ResolverStructLayoutTest, SizeAttributes) {
|
||||||
EXPECT_EQ(sem->Members()[3]->Offset(), 44u);
|
EXPECT_EQ(sem->Members()[3]->Offset(), 44u);
|
||||||
EXPECT_EQ(sem->Members()[3]->Align(), 4u);
|
EXPECT_EQ(sem->Members()[3]->Align(), 4u);
|
||||||
EXPECT_EQ(sem->Members()[3]->Size(), 32u);
|
EXPECT_EQ(sem->Members()[3]->Size(), 32u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, AlignAttributes) {
|
TEST_F(ResolverStructLayoutTest, AlignAttributes) {
|
||||||
|
@ -381,6 +417,9 @@ TEST_F(ResolverStructLayoutTest, AlignAttributes) {
|
||||||
EXPECT_EQ(sem->Members()[3]->Offset(), 64u);
|
EXPECT_EQ(sem->Members()[3]->Offset(), 64u);
|
||||||
EXPECT_EQ(sem->Members()[3]->Align(), 32u);
|
EXPECT_EQ(sem->Members()[3]->Align(), 32u);
|
||||||
EXPECT_EQ(sem->Members()[3]->Size(), 4u);
|
EXPECT_EQ(sem->Members()[3]->Size(), 4u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverStructLayoutTest, StructWithLotsOfPadding) {
|
TEST_F(ResolverStructLayoutTest, StructWithLotsOfPadding) {
|
||||||
|
@ -399,6 +438,9 @@ TEST_F(ResolverStructLayoutTest, StructWithLotsOfPadding) {
|
||||||
EXPECT_EQ(sem->Members()[0]->Offset(), 0u);
|
EXPECT_EQ(sem->Members()[0]->Offset(), 0u);
|
||||||
EXPECT_EQ(sem->Members()[0]->Align(), 1024u);
|
EXPECT_EQ(sem->Members()[0]->Align(), 1024u);
|
||||||
EXPECT_EQ(sem->Members()[0]->Size(), 4u);
|
EXPECT_EQ(sem->Members()[0]->Size(), 4u);
|
||||||
|
for (auto& m : sem->Members()) {
|
||||||
|
EXPECT_EQ(m->Struct()->Declaration(), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
// 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/tint/sem/index_accessor_expression.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
TINT_INSTANTIATE_TYPEINFO(tint::sem::IndexAccessorExpression);
|
||||||
|
|
||||||
|
namespace tint::sem {
|
||||||
|
|
||||||
|
IndexAccessorExpression::IndexAccessorExpression(const ast::IndexAccessorExpression* declaration,
|
||||||
|
const sem::Type* type,
|
||||||
|
const Expression* object,
|
||||||
|
const Expression* index,
|
||||||
|
const Statement* statement,
|
||||||
|
Constant constant,
|
||||||
|
bool has_side_effects,
|
||||||
|
const Variable* source_var /* = nullptr */)
|
||||||
|
: Base(declaration, type, statement, constant, has_side_effects, source_var),
|
||||||
|
object_(object),
|
||||||
|
index_(index) {}
|
||||||
|
|
||||||
|
IndexAccessorExpression::~IndexAccessorExpression() = default;
|
||||||
|
|
||||||
|
} // namespace tint::sem
|
|
@ -0,0 +1,66 @@
|
||||||
|
// Copyright 2022 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.
|
||||||
|
|
||||||
|
#ifndef SRC_TINT_SEM_INDEX_ACCESSOR_EXPRESSION_H_
|
||||||
|
#define SRC_TINT_SEM_INDEX_ACCESSOR_EXPRESSION_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "src/tint/sem/expression.h"
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
namespace tint::ast {
|
||||||
|
class IndexAccessorExpression;
|
||||||
|
} // namespace tint::ast
|
||||||
|
|
||||||
|
namespace tint::sem {
|
||||||
|
|
||||||
|
/// IndexAccessorExpression holds the semantic information for a ast::IndexAccessorExpression node.
|
||||||
|
class IndexAccessorExpression final : public Castable<IndexAccessorExpression, Expression> {
|
||||||
|
public:
|
||||||
|
/// Constructor
|
||||||
|
/// @param declaration the AST node
|
||||||
|
/// @param type the resolved type of the expression
|
||||||
|
/// @param object the object expression that is being indexed
|
||||||
|
/// @param index the index expression
|
||||||
|
/// @param statement the statement that owns this expression
|
||||||
|
/// @param constant the constant value of the expression. May be invalid
|
||||||
|
/// @param has_side_effects whether this expression may have side effects
|
||||||
|
/// @param source_var the (optional) source variable for this expression
|
||||||
|
IndexAccessorExpression(const ast::IndexAccessorExpression* declaration,
|
||||||
|
const sem::Type* type,
|
||||||
|
const Expression* object,
|
||||||
|
const Expression* index,
|
||||||
|
const Statement* statement,
|
||||||
|
Constant constant,
|
||||||
|
bool has_side_effects,
|
||||||
|
const Variable* source_var = nullptr);
|
||||||
|
|
||||||
|
/// Destructor
|
||||||
|
~IndexAccessorExpression() override;
|
||||||
|
|
||||||
|
/// @returns the object expression that is being indexed
|
||||||
|
Expression const* Object() const { return object_; }
|
||||||
|
|
||||||
|
/// @returns the index expression
|
||||||
|
Expression const* Index() const { return index_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Expression const* const object_;
|
||||||
|
Expression const* const index_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace tint::sem
|
||||||
|
|
||||||
|
#endif // SRC_TINT_SEM_INDEX_ACCESSOR_EXPRESSION_H_
|
|
@ -26,29 +26,33 @@ namespace tint::sem {
|
||||||
MemberAccessorExpression::MemberAccessorExpression(const ast::MemberAccessorExpression* declaration,
|
MemberAccessorExpression::MemberAccessorExpression(const ast::MemberAccessorExpression* declaration,
|
||||||
const sem::Type* type,
|
const sem::Type* type,
|
||||||
const Statement* statement,
|
const Statement* statement,
|
||||||
|
const Expression* object,
|
||||||
bool has_side_effects,
|
bool has_side_effects,
|
||||||
const Variable* source_var /* = nullptr */)
|
const Variable* source_var /* = nullptr */)
|
||||||
: Base(declaration, type, statement, Constant{}, has_side_effects, source_var) {}
|
: Base(declaration, type, statement, Constant{}, has_side_effects, source_var),
|
||||||
|
object_(object) {}
|
||||||
|
|
||||||
MemberAccessorExpression::~MemberAccessorExpression() = default;
|
MemberAccessorExpression::~MemberAccessorExpression() = default;
|
||||||
|
|
||||||
StructMemberAccess::StructMemberAccess(const ast::MemberAccessorExpression* declaration,
|
StructMemberAccess::StructMemberAccess(const ast::MemberAccessorExpression* declaration,
|
||||||
const sem::Type* type,
|
const sem::Type* type,
|
||||||
const Statement* statement,
|
const Statement* statement,
|
||||||
|
const Expression* object,
|
||||||
const StructMember* member,
|
const StructMember* member,
|
||||||
bool has_side_effects,
|
bool has_side_effects,
|
||||||
const Variable* source_var /* = nullptr */)
|
const Variable* source_var /* = nullptr */)
|
||||||
: Base(declaration, type, statement, has_side_effects, source_var), member_(member) {}
|
: Base(declaration, type, statement, object, has_side_effects, source_var), member_(member) {}
|
||||||
|
|
||||||
StructMemberAccess::~StructMemberAccess() = default;
|
StructMemberAccess::~StructMemberAccess() = default;
|
||||||
|
|
||||||
Swizzle::Swizzle(const ast::MemberAccessorExpression* declaration,
|
Swizzle::Swizzle(const ast::MemberAccessorExpression* declaration,
|
||||||
const sem::Type* type,
|
const sem::Type* type,
|
||||||
const Statement* statement,
|
const Statement* statement,
|
||||||
|
const Expression* object,
|
||||||
std::vector<uint32_t> indices,
|
std::vector<uint32_t> indices,
|
||||||
bool has_side_effects,
|
bool has_side_effects,
|
||||||
const Variable* source_var /* = nullptr */)
|
const Variable* source_var /* = nullptr */)
|
||||||
: Base(declaration, type, statement, has_side_effects, source_var),
|
: Base(declaration, type, statement, object, has_side_effects, source_var),
|
||||||
indices_(std::move(indices)) {}
|
indices_(std::move(indices)) {}
|
||||||
|
|
||||||
Swizzle::~Swizzle() = default;
|
Swizzle::~Swizzle() = default;
|
||||||
|
|
|
@ -38,16 +38,24 @@ class MemberAccessorExpression : public Castable<MemberAccessorExpression, Expre
|
||||||
/// @param declaration the AST node
|
/// @param declaration the AST node
|
||||||
/// @param type the resolved type of the expression
|
/// @param type the resolved type of the expression
|
||||||
/// @param statement the statement that owns this expression
|
/// @param statement the statement that owns this expression
|
||||||
|
/// @param object the object that holds the member being accessed
|
||||||
/// @param has_side_effects whether this expression may have side effects
|
/// @param has_side_effects whether this expression may have side effects
|
||||||
/// @param source_var the (optional) source variable for this expression
|
/// @param source_var the (optional) source variable for this expression
|
||||||
MemberAccessorExpression(const ast::MemberAccessorExpression* declaration,
|
MemberAccessorExpression(const ast::MemberAccessorExpression* declaration,
|
||||||
const sem::Type* type,
|
const sem::Type* type,
|
||||||
const Statement* statement,
|
const Statement* statement,
|
||||||
|
const Expression* object,
|
||||||
bool has_side_effects,
|
bool has_side_effects,
|
||||||
const Variable* source_var = nullptr);
|
const Variable* source_var = nullptr);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~MemberAccessorExpression() override;
|
~MemberAccessorExpression() override;
|
||||||
|
|
||||||
|
/// @returns the object that holds the member being accessed
|
||||||
|
const Expression* Object() const { return object_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Expression const* const object_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// StructMemberAccess holds the semantic information for a
|
/// StructMemberAccess holds the semantic information for a
|
||||||
|
@ -59,12 +67,14 @@ class StructMemberAccess final : public Castable<StructMemberAccess, MemberAcces
|
||||||
/// @param declaration the AST node
|
/// @param declaration the AST node
|
||||||
/// @param type the resolved type of the expression
|
/// @param type the resolved type of the expression
|
||||||
/// @param statement the statement that owns this expression
|
/// @param statement the statement that owns this expression
|
||||||
|
/// @param object the object that holds the member being accessed
|
||||||
/// @param member the structure member
|
/// @param member the structure member
|
||||||
/// @param has_side_effects whether this expression may have side effects
|
/// @param has_side_effects whether this expression may have side effects
|
||||||
/// @param source_var the (optional) source variable for this expression
|
/// @param source_var the (optional) source variable for this expression
|
||||||
StructMemberAccess(const ast::MemberAccessorExpression* declaration,
|
StructMemberAccess(const ast::MemberAccessorExpression* declaration,
|
||||||
const sem::Type* type,
|
const sem::Type* type,
|
||||||
const Statement* statement,
|
const Statement* statement,
|
||||||
|
const Expression* object,
|
||||||
const StructMember* member,
|
const StructMember* member,
|
||||||
bool has_side_effects,
|
bool has_side_effects,
|
||||||
const Variable* source_var = nullptr);
|
const Variable* source_var = nullptr);
|
||||||
|
@ -87,12 +97,14 @@ class Swizzle final : public Castable<Swizzle, MemberAccessorExpression> {
|
||||||
/// @param declaration the AST node
|
/// @param declaration the AST node
|
||||||
/// @param type the resolved type of the expression
|
/// @param type the resolved type of the expression
|
||||||
/// @param statement the statement that owns this expression
|
/// @param statement the statement that owns this expression
|
||||||
|
/// @param object the object that holds the member being accessed
|
||||||
/// @param indices the swizzle indices
|
/// @param indices the swizzle indices
|
||||||
/// @param has_side_effects whether this expression may have side effects
|
/// @param has_side_effects whether this expression may have side effects
|
||||||
/// @param source_var the (optional) source variable for this expression
|
/// @param source_var the (optional) source variable for this expression
|
||||||
Swizzle(const ast::MemberAccessorExpression* declaration,
|
Swizzle(const ast::MemberAccessorExpression* declaration,
|
||||||
const sem::Type* type,
|
const sem::Type* type,
|
||||||
const Statement* statement,
|
const Statement* statement,
|
||||||
|
const Expression* object,
|
||||||
std::vector<uint32_t> indices,
|
std::vector<uint32_t> indices,
|
||||||
bool has_side_effects,
|
bool has_side_effects,
|
||||||
const Variable* source_var = nullptr);
|
const Variable* source_var = nullptr);
|
||||||
|
|
|
@ -194,9 +194,16 @@ class StructMember : public Castable<StructMember, Node> {
|
||||||
/// @returns the AST declaration node
|
/// @returns the AST declaration node
|
||||||
const ast::StructMember* Declaration() const { return declaration_; }
|
const ast::StructMember* Declaration() const { return declaration_; }
|
||||||
|
|
||||||
/// @returns the name of the structure
|
/// @returns the name of the structure member
|
||||||
Symbol Name() const { return name_; }
|
Symbol Name() const { return name_; }
|
||||||
|
|
||||||
|
/// Sets the owning structure to `s`
|
||||||
|
/// @param s the new structure owner
|
||||||
|
void SetStruct(const sem::Struct* s) { struct_ = s; }
|
||||||
|
|
||||||
|
/// @returns the structure that owns this member
|
||||||
|
const sem::Struct* Struct() const { return struct_; }
|
||||||
|
|
||||||
/// @returns the type of the member
|
/// @returns the type of the member
|
||||||
sem::Type* Type() const { return type_; }
|
sem::Type* Type() const { return type_; }
|
||||||
|
|
||||||
|
@ -215,6 +222,7 @@ class StructMember : public Castable<StructMember, Node> {
|
||||||
private:
|
private:
|
||||||
const ast::StructMember* const declaration_;
|
const ast::StructMember* const declaration_;
|
||||||
const Symbol name_;
|
const Symbol name_;
|
||||||
|
const sem::Struct* struct_;
|
||||||
sem::Type* const type_;
|
sem::Type* const type_;
|
||||||
const uint32_t index_;
|
const uint32_t index_;
|
||||||
const uint32_t offset_;
|
const uint32_t offset_;
|
||||||
|
|
|
@ -25,6 +25,7 @@ class Expression;
|
||||||
class ForLoopStatement;
|
class ForLoopStatement;
|
||||||
class Function;
|
class Function;
|
||||||
class IfStatement;
|
class IfStatement;
|
||||||
|
class IndexAccessorExpression;
|
||||||
class MemberAccessorExpression;
|
class MemberAccessorExpression;
|
||||||
class Node;
|
class Node;
|
||||||
class Override;
|
class Override;
|
||||||
|
@ -44,6 +45,7 @@ class Expression;
|
||||||
class ForLoopStatement;
|
class ForLoopStatement;
|
||||||
class Function;
|
class Function;
|
||||||
class IfStatement;
|
class IfStatement;
|
||||||
|
class IndexAccessorExpression;
|
||||||
class MemberAccessorExpression;
|
class MemberAccessorExpression;
|
||||||
class Node;
|
class Node;
|
||||||
class GlobalVariable;
|
class GlobalVariable;
|
||||||
|
@ -69,6 +71,7 @@ struct TypeMappings {
|
||||||
ForLoopStatement* operator()(ast::ForLoopStatement*);
|
ForLoopStatement* operator()(ast::ForLoopStatement*);
|
||||||
Function* operator()(ast::Function*);
|
Function* operator()(ast::Function*);
|
||||||
IfStatement* operator()(ast::IfStatement*);
|
IfStatement* operator()(ast::IfStatement*);
|
||||||
|
IndexAccessorExpression* operator()(ast::IndexAccessorExpression*);
|
||||||
MemberAccessorExpression* operator()(ast::MemberAccessorExpression*);
|
MemberAccessorExpression* operator()(ast::MemberAccessorExpression*);
|
||||||
Node* operator()(ast::Node*);
|
Node* operator()(ast::Node*);
|
||||||
GlobalVariable* operator()(ast::Override*);
|
GlobalVariable* operator()(ast::Override*);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "gtest/gtest-spi.h"
|
#include "gtest/gtest-spi.h"
|
||||||
#include "src/tint/program_builder.h"
|
#include "src/tint/program_builder.h"
|
||||||
#include "src/tint/sem/if_statement.h"
|
#include "src/tint/sem/if_statement.h"
|
||||||
|
#include "src/tint/sem/index_accessor_expression.h"
|
||||||
#include "src/tint/sem/statement.h"
|
#include "src/tint/sem/statement.h"
|
||||||
#include "src/tint/transform/test_helper.h"
|
#include "src/tint/transform/test_helper.h"
|
||||||
#include "src/tint/transform/utils/hoist_to_decl_before.h"
|
#include "src/tint/transform/utils/hoist_to_decl_before.h"
|
||||||
|
|
Loading…
Reference in New Issue