sem::StructMember: Add Type()
Once the AST switches to pure ast::Type nodes, we need a way to fetch the semantic type for a structure member. Bug: tint:724 Change-Id: I4b55c1ec0220e29ca4ff3131cf2d41409821a538 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49347 Commit-Queue: Ben Clayton <bclayton@chromium.org> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
109b18f504
commit
2ac55febf5
|
@ -2392,10 +2392,12 @@ Resolver::StructInfo* Resolver::Structure(const sem::StructType* str) {
|
||||||
for (auto* member : str->impl()->members()) {
|
for (auto* member : str->impl()->members()) {
|
||||||
Mark(member);
|
Mark(member);
|
||||||
|
|
||||||
|
auto type = member->type();
|
||||||
|
|
||||||
// First check the member type is legal
|
// First check the member type is legal
|
||||||
if (!IsStorable(member->type())) {
|
if (!IsStorable(type)) {
|
||||||
builder_->Diagnostics().add_error(
|
builder_->Diagnostics().add_error(
|
||||||
std::string(member->type()->FriendlyName(builder_->Symbols())) +
|
std::string(type->FriendlyName(builder_->Symbols())) +
|
||||||
" cannot be used as the type of a structure member");
|
" cannot be used as the type of a structure member");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -2403,7 +2405,7 @@ Resolver::StructInfo* Resolver::Structure(const sem::StructType* str) {
|
||||||
uint32_t offset = struct_size;
|
uint32_t offset = struct_size;
|
||||||
uint32_t align = 0;
|
uint32_t align = 0;
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
if (!DefaultAlignAndSize(member->type(), align, size, member->source())) {
|
if (!DefaultAlignAndSize(type, align, size, member->source())) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2455,7 +2457,7 @@ Resolver::StructInfo* Resolver::Structure(const sem::StructType* str) {
|
||||||
offset = utils::RoundUp(align, offset);
|
offset = utils::RoundUp(align, offset);
|
||||||
|
|
||||||
auto* sem_member =
|
auto* sem_member =
|
||||||
builder_->create<sem::StructMember>(member, offset, align, size);
|
builder_->create<sem::StructMember>(member, type, offset, align, size);
|
||||||
builder_->Sem().Add(member, sem_member);
|
builder_->Sem().Add(member, sem_member);
|
||||||
sem_members.emplace_back(sem_member);
|
sem_members.emplace_back(sem_member);
|
||||||
|
|
||||||
|
|
|
@ -892,13 +892,10 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {
|
||||||
|
|
||||||
auto* ptr = TypeOf(mem)->As<sem::Pointer>();
|
auto* ptr = TypeOf(mem)->As<sem::Pointer>();
|
||||||
EXPECT_TRUE(ptr->type()->Is<sem::F32>());
|
EXPECT_TRUE(ptr->type()->Is<sem::F32>());
|
||||||
ASSERT_TRUE(Sem().Get(mem)->Is<sem::StructMemberAccess>());
|
auto* sma = Sem().Get(mem)->As<sem::StructMemberAccess>();
|
||||||
EXPECT_EQ(Sem()
|
ASSERT_NE(sma, nullptr);
|
||||||
.Get(mem)
|
EXPECT_EQ(sma->Member()->Type(), ty.f32());
|
||||||
->As<sem::StructMemberAccess>()
|
EXPECT_EQ(sma->Member()->Declaration()->symbol(),
|
||||||
->Member()
|
|
||||||
->Declaration()
|
|
||||||
->symbol(),
|
|
||||||
Symbols().Get("second_member"));
|
Symbols().Get("second_member"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -918,7 +915,9 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) {
|
||||||
|
|
||||||
auto* ptr = TypeOf(mem)->As<sem::Pointer>();
|
auto* ptr = TypeOf(mem)->As<sem::Pointer>();
|
||||||
EXPECT_TRUE(ptr->type()->Is<sem::F32>());
|
EXPECT_TRUE(ptr->type()->Is<sem::F32>());
|
||||||
ASSERT_TRUE(Sem().Get(mem)->Is<sem::StructMemberAccess>());
|
auto* sma = Sem().Get(mem)->As<sem::StructMemberAccess>();
|
||||||
|
ASSERT_NE(sma, nullptr);
|
||||||
|
EXPECT_EQ(sma->Member()->Type(), ty.f32());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle) {
|
TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle) {
|
||||||
|
|
|
@ -50,10 +50,15 @@ const StructMember* Struct::FindMember(Symbol name) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
StructMember::StructMember(ast::StructMember* declaration,
|
StructMember::StructMember(ast::StructMember* declaration,
|
||||||
|
sem::Type* type,
|
||||||
uint32_t offset,
|
uint32_t offset,
|
||||||
uint32_t align,
|
uint32_t align,
|
||||||
uint32_t size)
|
uint32_t size)
|
||||||
: declaration_(declaration), offset_(offset), align_(align), size_(size) {}
|
: declaration_(declaration),
|
||||||
|
type_(type),
|
||||||
|
offset_(offset),
|
||||||
|
align_(align),
|
||||||
|
size_(size) {}
|
||||||
|
|
||||||
StructMember::~StructMember() = default;
|
StructMember::~StructMember() = default;
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ namespace sem {
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
class StructType;
|
class StructType;
|
||||||
class StructMember;
|
class StructMember;
|
||||||
|
class Type;
|
||||||
|
|
||||||
/// A vector of StructMember pointers.
|
/// A vector of StructMember pointers.
|
||||||
using StructMemberList = std::vector<const StructMember*>;
|
using StructMemberList = std::vector<const StructMember*>;
|
||||||
|
@ -141,10 +142,12 @@ class StructMember : public Castable<StructMember, Node> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param declaration the AST declaration node
|
/// @param declaration the AST declaration node
|
||||||
|
/// @param type the type of the member
|
||||||
/// @param offset the byte offset from the base of the structure
|
/// @param offset the byte offset from the base of the structure
|
||||||
/// @param align the byte alignment of the member
|
/// @param align the byte alignment of the member
|
||||||
/// @param size the byte size of the member
|
/// @param size the byte size of the member
|
||||||
StructMember(ast::StructMember* declaration,
|
StructMember(ast::StructMember* declaration,
|
||||||
|
sem::Type* type,
|
||||||
uint32_t offset,
|
uint32_t offset,
|
||||||
uint32_t align,
|
uint32_t align,
|
||||||
uint32_t size);
|
uint32_t size);
|
||||||
|
@ -155,6 +158,9 @@ class StructMember : public Castable<StructMember, Node> {
|
||||||
/// @returns the AST declaration node
|
/// @returns the AST declaration node
|
||||||
ast::StructMember* Declaration() const { return declaration_; }
|
ast::StructMember* Declaration() const { return declaration_; }
|
||||||
|
|
||||||
|
/// @returns the type of the member
|
||||||
|
sem::Type* Type() const { return type_; }
|
||||||
|
|
||||||
/// @returns byte offset from base of structure
|
/// @returns byte offset from base of structure
|
||||||
uint32_t Offset() const { return offset_; }
|
uint32_t Offset() const { return offset_; }
|
||||||
|
|
||||||
|
@ -166,6 +172,7 @@ class StructMember : public Castable<StructMember, Node> {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ast::StructMember* const declaration_;
|
ast::StructMember* const declaration_;
|
||||||
|
sem::Type* const type_;
|
||||||
uint32_t const offset_; // Byte offset from base of structure
|
uint32_t const offset_; // Byte offset from base of structure
|
||||||
uint32_t const align_; // Byte alignment of the member
|
uint32_t const align_; // Byte alignment of the member
|
||||||
uint32_t const size_; // Byte size of the member
|
uint32_t const size_; // Byte size of the member
|
||||||
|
|
Loading…
Reference in New Issue