sem::StructType remove symbol()

The name now lives on the ast::Struct. Use that instead.

Bug: tint:724
Change-Id: I4ee5e9b29973e468edd8df8c5448816b36f0fca6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48384
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton
2021-04-20 15:21:21 +00:00
committed by Commit Bot service account
parent 8a8d26bbd9
commit 913a2f4b2a
22 changed files with 87 additions and 100 deletions

View File

@@ -23,26 +23,24 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::StructType);
namespace tint {
namespace sem {
StructType::StructType(const Symbol& sym, ast::Struct* impl)
: symbol_(sym), struct_(impl) {}
StructType::StructType(ast::Struct* impl) : struct_(impl) {}
StructType::StructType(StructType&&) = default;
StructType::~StructType() = default;
std::string StructType::type_name() const {
return "__struct_" + symbol_.to_str();
return impl()->type_name();
}
std::string StructType::FriendlyName(const SymbolTable& symbols) const {
return symbols.NameFor(symbol_);
return impl()->FriendlyName(symbols);
}
StructType* StructType::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto sym = ctx->Clone(symbol());
auto* str = ctx->Clone(impl());
return ctx->dst->create<StructType>(sym, str);
return ctx->dst->create<StructType>(str);
}
} // namespace sem

View File

@@ -27,16 +27,12 @@ namespace sem {
class StructType : public Castable<StructType, Type> {
public:
/// Constructor
/// @param sym the symbol representing the struct
/// @param impl the struct data
StructType(const Symbol& sym, ast::Struct* impl);
explicit StructType(ast::Struct* impl);
/// Move constructor
StructType(StructType&&);
~StructType() override;
/// @returns the struct symbol
const Symbol& symbol() const { return symbol_; }
/// @returns true if the struct has a block decoration
bool IsBlockDecorated() const { return struct_->IsBlockDecorated(); }
@@ -57,7 +53,6 @@ class StructType : public Castable<StructType, Type> {
StructType* Clone(CloneContext* ctx) const override;
private:
Symbol const symbol_;
ast::Struct* const struct_;
uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const;

View File

@@ -27,7 +27,7 @@ TEST_F(StructTypeTest, Creation) {
auto* impl =
create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
auto* ptr = impl;
auto* s = ty.struct_(name, impl);
auto* s = ty.struct_(impl);
EXPECT_EQ(s->impl(), ptr);
}
@@ -35,7 +35,7 @@ TEST_F(StructTypeTest, Is) {
auto name = Sym("S");
auto* impl =
create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
auto* s = ty.struct_(name, impl);
auto* s = ty.struct_(impl);
sem::Type* ty = s;
EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<Alias>());
@@ -56,7 +56,7 @@ TEST_F(StructTypeTest, TypeName) {
auto name = Sym("my_struct");
auto* impl =
create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
auto* s = ty.struct_(name, impl);
auto* s = ty.struct_(impl);
EXPECT_EQ(s->type_name(), "__struct_$1");
}
@@ -64,7 +64,7 @@ TEST_F(StructTypeTest, FriendlyName) {
auto name = Sym("my_struct");
auto* impl =
create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
auto* s = ty.struct_(name, impl);
auto* s = ty.struct_(impl);
EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct");
}