Rename type Base methods

This CL renames StructBase and StructMemberBase to drop the Base suffix
now that the move is complete.

Bug: tint:1718
Change-Id: If8126e4993c58bb2de475c2b18695705082a0a92
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113800
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2022-12-12 20:51:44 +00:00 committed by Dawn LUCI CQ
parent ac146b1a48
commit 28a7827981
11 changed files with 135 additions and 137 deletions

View File

@ -497,7 +497,7 @@ class ProgramBuilder {
/// @returns the de-aliased array count pointer
template <typename T, typename... ARGS>
traits::EnableIf<traits::IsTypeOrDerived<T, type::ArrayCount> ||
traits::IsTypeOrDerived<T, type::StructMemberBase>,
traits::IsTypeOrDerived<T, type::StructMember>,
T>*
create(ARGS&&... args) {
AssertNotMoved();

View File

@ -416,7 +416,7 @@ struct Composite : ImplConstant {
utils::Vector<const sem::Constant*, 4> conv_els;
conv_els.Reserve(elements.Length());
std::function<const type::Type*(size_t idx)> target_el_ty;
if (auto* str = target_ty->As<type::StructBase>()) {
if (auto* str = target_ty->As<type::Struct>()) {
if (str->Members().Length() != elements.Length()) {
TINT_ICE(Resolver, builder.Diagnostics())
<< "const-eval conversion of structure has mismatched element counts";
@ -494,7 +494,7 @@ const ImplConstant* ZeroValue(ProgramBuilder& builder, const type::Type* type) {
}
return nullptr;
},
[&](const type::StructBase* s) -> const ImplConstant* {
[&](const type::Struct* s) -> const ImplConstant* {
utils::Hashmap<const type::Type*, const ImplConstant*, 8> zero_by_type;
utils::Vector<const sem::Constant*, 4> zeros;
zeros.Reserve(s->Members().Length());
@ -1449,7 +1449,7 @@ ConstEval::Result ConstEval::Index(const sem::Expression* obj_expr,
}
ConstEval::Result ConstEval::MemberAccess(const sem::Expression* obj_expr,
const type::StructMemberBase* member) {
const type::StructMember* member) {
auto obj_val = obj_expr->ConstantValue();
if (!obj_val) {
return nullptr;

View File

@ -35,7 +35,7 @@ class Constant;
class Expression;
} // namespace tint::sem
namespace tint::type {
class StructMemberBase;
class StructMember;
} // namespace tint::type
namespace tint::resolver {
@ -94,7 +94,7 @@ class ConstEval {
/// @param obj the object being accessed
/// @param member the member
/// @return the result of the member access, or null if the value cannot be calculated
Result MemberAccess(const sem::Expression* obj, const type::StructMemberBase* member);
Result MemberAccess(const sem::Expression* obj, const type::StructMember* member);
/// @param ty the result type
/// @param vector the vector being swizzled

View File

@ -32,13 +32,13 @@ namespace tint::sem {
class StructMember;
} // namespace tint::sem
namespace tint::type {
class StructMemberBase;
class StructMember;
} // namespace tint::type
namespace tint::sem {
/// Struct holds the semantic information for structures.
class Struct final : public Castable<Struct, type::StructBase> {
class Struct final : public Castable<Struct, type::Struct> {
public:
/// Constructor
/// @param declaration the AST structure declaration
@ -73,7 +73,7 @@ class Struct final : public Castable<Struct, type::StructBase> {
};
/// StructMember holds the semantic information for structure members.
class StructMember final : public Castable<StructMember, type::StructMemberBase> {
class StructMember final : public Castable<StructMember, type::StructMember> {
public:
/// Constructor
/// @param declaration the AST declaration node

View File

@ -42,7 +42,7 @@ Transform::ApplyResult PromoteInitializersToLet::Apply(const Program* src,
// Returns true if the expression should be hoisted to a new let statement before the
// expression's statement.
auto should_hoist = [&](const sem::Expression* expr) {
if (!expr->Type()->IsAnyOf<type::Array, type::StructBase>()) {
if (!expr->Type()->IsAnyOf<type::Array, type::Struct>()) {
// We only care about array and struct initializers
return false;
}

View File

@ -91,7 +91,7 @@ class Manager final {
/// pointer is returned.
template <typename TYPE,
typename _ = std::enable_if<traits::IsTypeOrDerived<TYPE, ArrayCount> ||
traits::IsTypeOrDerived<TYPE, StructMemberBase>>,
traits::IsTypeOrDerived<TYPE, StructMember>>,
typename... ARGS>
TYPE* GetNode(ARGS&&... args) {
return nodes_.Get<TYPE>(std::forward<ARGS>(args)...);
@ -119,8 +119,8 @@ struct hash<tint::type::Node> {
size_t operator()(const tint::type::Node& type) const {
if (const auto* ac = type.As<tint::type::ArrayCount>()) {
return ac->Hash();
} else if (type.Is<tint::type::StructMemberBase>()) {
return tint::TypeInfo::Of<tint::type::StructMemberBase>().full_hashcode;
} else if (type.Is<tint::type::StructMember>()) {
return tint::TypeInfo::Of<tint::type::StructMember>().full_hashcode;
}
TINT_ASSERT(Type, false && "Unreachable");
return 0;
@ -139,7 +139,7 @@ struct equal_to<tint::type::Node> {
return ac->Equals(*bc);
}
return false;
} else if (a.Is<tint::type::StructMemberBase>()) {
} else if (a.Is<tint::type::StructMember>()) {
return &a == &b;
}
TINT_ASSERT(Type, false && "Unreachable");

View File

@ -22,13 +22,13 @@
#include "src/tint/symbol_table.h"
#include "src/tint/utils/hash.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::StructBase);
TINT_INSTANTIATE_TYPEINFO(tint::type::StructMemberBase);
TINT_INSTANTIATE_TYPEINFO(tint::type::Struct);
TINT_INSTANTIATE_TYPEINFO(tint::type::StructMember);
namespace tint::type {
namespace {
TypeFlags FlagsFrom(utils::VectorRef<const StructMemberBase*> members) {
TypeFlags FlagsFrom(utils::VectorRef<const StructMember*> members) {
TypeFlags flags{
TypeFlag::kConstructable,
TypeFlag::kCreationFixedFootprint,
@ -50,12 +50,12 @@ TypeFlags FlagsFrom(utils::VectorRef<const StructMemberBase*> members) {
} // namespace
StructBase::StructBase(tint::Source source,
Symbol name,
utils::VectorRef<const StructMemberBase*> members,
uint32_t align,
uint32_t size,
uint32_t size_no_padding)
Struct::Struct(tint::Source source,
Symbol name,
utils::VectorRef<const StructMember*> members,
uint32_t align,
uint32_t size,
uint32_t size_no_padding)
: Base(FlagsFrom(members)),
source_(source),
name_(name),
@ -64,20 +64,20 @@ StructBase::StructBase(tint::Source source,
size_(size),
size_no_padding_(size_no_padding) {}
StructBase::~StructBase() = default;
Struct::~Struct() = default;
size_t StructBase::Hash() const {
return utils::Hash(TypeInfo::Of<StructBase>().full_hashcode, name_);
size_t Struct::Hash() const {
return utils::Hash(TypeInfo::Of<Struct>().full_hashcode, name_);
}
bool StructBase::Equals(const Type& other) const {
if (auto* o = other.As<StructBase>()) {
bool Struct::Equals(const Type& other) const {
if (auto* o = other.As<Struct>()) {
return o->name_ == name_;
}
return false;
}
const StructMemberBase* StructBase::FindMember(Symbol name) const {
const StructMember* Struct::FindMember(Symbol name) const {
for (auto* member : members_) {
if (member->Name() == name) {
return member;
@ -86,22 +86,22 @@ const StructMemberBase* StructBase::FindMember(Symbol name) const {
return nullptr;
}
uint32_t StructBase::Align() const {
uint32_t Struct::Align() const {
return align_;
}
uint32_t StructBase::Size() const {
uint32_t Struct::Size() const {
return size_;
}
std::string StructBase::FriendlyName(const SymbolTable& symbols) const {
std::string Struct::FriendlyName(const SymbolTable& symbols) const {
return symbols.NameFor(name_);
}
std::string StructBase::Layout(const tint::SymbolTable& symbols) const {
std::string Struct::Layout(const tint::SymbolTable& symbols) const {
std::stringstream ss;
auto member_name_of = [&](const StructMemberBase* sm) { return symbols.NameFor(sm->Name()); };
auto member_name_of = [&](const StructMember* sm) { return symbols.NameFor(sm->Name()); };
if (Members().IsEmpty()) {
return {};
@ -164,14 +164,14 @@ std::string StructBase::Layout(const tint::SymbolTable& symbols) const {
return ss.str();
}
StructMemberBase::StructMemberBase(tint::Source source,
Symbol name,
const type::Type* type,
uint32_t index,
uint32_t offset,
uint32_t align,
uint32_t size,
std::optional<uint32_t> location)
StructMember::StructMember(tint::Source source,
Symbol name,
const type::Type* type,
uint32_t index,
uint32_t offset,
uint32_t align,
uint32_t size,
std::optional<uint32_t> location)
: source_(source),
name_(name),
type_(type),
@ -181,6 +181,6 @@ StructMemberBase::StructMemberBase(tint::Source source,
size_(size),
location_(location) {}
StructMemberBase::~StructMemberBase() = default;
StructMember::~StructMember() = default;
} // namespace tint::type

View File

@ -29,7 +29,7 @@
// Forward declarations
namespace tint::type {
class StructMemberBase;
class StructMember;
} // namespace tint::type
namespace tint::type {
@ -44,8 +44,8 @@ enum class PipelineStageUsage {
kComputeOutput,
};
/// StructBase holds the Type information for structures.
class StructBase : public Castable<StructBase, Type> {
/// Struct holds the Type information for structures.
class Struct : public Castable<Struct, Type> {
public:
/// Constructor
/// @param source the source of the structure
@ -55,15 +55,15 @@ class StructBase : public Castable<StructBase, Type> {
/// @param size the byte size of the structure
/// @param size_no_padding size of the members without the end of structure
/// alignment padding
StructBase(tint::Source source,
Symbol name,
utils::VectorRef<const StructMemberBase*> members,
uint32_t align,
uint32_t size,
uint32_t size_no_padding);
Struct(tint::Source source,
Symbol name,
utils::VectorRef<const StructMember*> members,
uint32_t align,
uint32_t size,
uint32_t size_no_padding);
/// Destructor
~StructBase() override;
~Struct() override;
/// @returns a hash of the type.
size_t Hash() const override;
@ -79,11 +79,11 @@ class StructBase : public Castable<StructBase, Type> {
Symbol Name() const { return name_; }
/// @returns the members of the structure
utils::VectorRef<const StructMemberBase*> Members() const { return members_; }
utils::VectorRef<const StructMember*> Members() const { return members_; }
/// @param name the member name to look for
/// @returns the member with the given name, or nullptr if it was not found.
const StructMemberBase* FindMember(Symbol name) const;
const StructMember* FindMember(Symbol name) const;
/// @returns the byte alignment of the structure
/// @note this may differ from the alignment of a structure member of this
@ -145,29 +145,27 @@ class StructBase : public Castable<StructBase, Type> {
std::string Layout(const tint::SymbolTable& symbols) const;
/// @param concrete the conversion-rank ordered concrete versions of this abstract structure.
void SetConcreteTypes(utils::VectorRef<const StructBase*> concrete) {
concrete_types_ = concrete;
}
void SetConcreteTypes(utils::VectorRef<const Struct*> concrete) { concrete_types_ = concrete; }
/// @returns the conversion-rank ordered concrete versions of this abstract structure, or an
/// empty vector if this structure is not abstract.
/// @note only structures returned by builtins may be abstract (e.g. modf, frexp)
utils::VectorRef<const StructBase*> ConcreteTypes() const { return concrete_types_; }
utils::VectorRef<const Struct*> ConcreteTypes() const { return concrete_types_; }
private:
const tint::Source source_;
const Symbol name_;
const utils::Vector<const StructMemberBase*, 4> members_;
const utils::Vector<const StructMember*, 4> members_;
const uint32_t align_;
const uint32_t size_;
const uint32_t size_no_padding_;
std::unordered_set<ast::AddressSpace> address_space_usage_;
std::unordered_set<PipelineStageUsage> pipeline_stage_uses_;
utils::Vector<const StructBase*, 2> concrete_types_;
utils::Vector<const Struct*, 2> concrete_types_;
};
/// StructMemberBase holds the type information for structure members.
class StructMemberBase : public Castable<StructMemberBase, Node> {
/// StructMember holds the type information for structure members.
class StructMember : public Castable<StructMember, Node> {
public:
/// Constructor
/// @param source the source of the struct member
@ -178,17 +176,17 @@ class StructMemberBase : public Castable<StructMemberBase, Node> {
/// @param align the byte alignment of the member
/// @param size the byte size of the member
/// @param location the location attribute, if present
StructMemberBase(tint::Source source,
Symbol name,
const type::Type* type,
uint32_t index,
uint32_t offset,
uint32_t align,
uint32_t size,
std::optional<uint32_t> location);
StructMember(tint::Source source,
Symbol name,
const type::Type* type,
uint32_t index,
uint32_t offset,
uint32_t align,
uint32_t size,
std::optional<uint32_t> location);
/// Destructor
~StructMemberBase() override;
~StructMember() override;
/// @returns the source the struct member
const tint::Source& Source() const { return source_; }
@ -198,10 +196,10 @@ class StructMemberBase : public Castable<StructMemberBase, Node> {
/// Sets the owning structure to `s`
/// @param s the new structure owner
void SetStruct(const StructBase* s) { struct_ = s; }
void SetStruct(const Struct* s) { struct_ = s; }
/// @returns the structure that owns this member
const StructBase* Struct() const { return struct_; }
const type::Struct* Struct() const { return struct_; }
/// @returns the type of the member
const type::Type* Type() const { return type_; }
@ -224,7 +222,7 @@ class StructMemberBase : public Castable<StructMemberBase, Node> {
private:
const tint::Source source_;
const Symbol name_;
const StructBase* struct_;
const type::Struct* struct_;
const type::Type* type_;
const uint32_t index_;
const uint32_t offset_;

View File

@ -24,27 +24,27 @@ using TypeStructTest = TestHelper;
TEST_F(TypeStructTest, Creation) {
auto name = Sym("S");
auto* s = create<StructBase>(Source{}, name, utils::Empty, 4u /* align */, 8u /* size */,
16u /* size_no_padding */);
auto* s = create<Struct>(Source{}, name, utils::Empty, 4u /* align */, 8u /* size */,
16u /* size_no_padding */);
EXPECT_EQ(s->Align(), 4u);
EXPECT_EQ(s->Size(), 8u);
EXPECT_EQ(s->SizeNoPadding(), 16u);
}
TEST_F(TypeStructTest, Hash) {
auto* a = create<StructBase>(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */);
auto* b = create<StructBase>(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */);
auto* a = create<Struct>(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */);
auto* b = create<Struct>(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */);
EXPECT_NE(a->Hash(), b->Hash());
}
TEST_F(TypeStructTest, Equals) {
auto* a = create<StructBase>(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */);
auto* b = create<StructBase>(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */);
auto* a = create<Struct>(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */);
auto* b = create<Struct>(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */);
EXPECT_TRUE(a->Equals(*a));
EXPECT_FALSE(a->Equals(*b));
@ -53,8 +53,8 @@ TEST_F(TypeStructTest, Equals) {
TEST_F(TypeStructTest, FriendlyName) {
auto name = Sym("my_struct");
auto* s = create<StructBase>(Source{}, name, utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */);
auto* s = create<Struct>(Source{}, name, utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */);
EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct");
}

View File

@ -180,7 +180,7 @@ bool Type::HoldsAbstract() const {
[&](const Vector* v) { return v->type()->HoldsAbstract(); },
[&](const Matrix* m) { return m->type()->HoldsAbstract(); },
[&](const Array* a) { return a->ElemType()->HoldsAbstract(); },
[&](const StructBase* s) {
[&](const Struct* s) {
for (auto* m : s->Members()) {
if (m->Type()->HoldsAbstract()) {
return true;
@ -238,7 +238,7 @@ uint32_t Type::ConversionRank(const Type* from, const Type* to) {
}
return kNoConversion;
},
[&](const StructBase* from_str) {
[&](const Struct* from_str) {
auto concrete_tys = from_str->ConcreteTypes();
for (size_t i = 0; i < concrete_tys.Length(); i++) {
if (concrete_tys[i] == to) {

View File

@ -45,54 +45,54 @@ struct TypeTest : public TestHelper {
const Matrix* mat4x3_af = create<Matrix>(vec3_af, 4u);
const Reference* ref_u32 =
create<Reference>(u32, ast::AddressSpace::kPrivate, ast::Access::kReadWrite);
const StructBase* str_f32 = create<StructBase>(Source{},
Sym("str_f32"),
utils::Vector{
create<StructMemberBase>(
/* source */ Source{},
/* name */ Sym("x"),
/* type */ f32,
/* index */ 0u,
/* offset */ 0u,
/* align */ 4u,
/* size */ 4u,
/* location */ std::nullopt),
},
/* align*/ 4u,
/* size*/ 4u,
/* size_no_padding*/ 4u);
const StructBase* str_f16 = create<StructBase>(Source{},
Sym("str_f16"),
utils::Vector{
create<StructMemberBase>(
/* source */ Source{},
/* name */ Sym("x"),
/* type */ f16,
/* index */ 0u,
/* offset */ 0u,
/* align */ 4u,
/* size */ 4u,
/* location */ std::nullopt),
},
/* align*/ 4u,
/* size*/ 4u,
/* size_no_padding*/ 4u);
StructBase* str_af = create<StructBase>(Source{},
Sym("str_af"),
utils::Vector{
create<StructMemberBase>(
/* source */ Source{},
/* name */ Sym("x"),
/* type */ af,
/* index */ 0u,
/* offset */ 0u,
/* align */ 4u,
/* size */ 4u,
/* location */ std::nullopt),
},
/* align*/ 4u,
/* size*/ 4u,
/* size_no_padding*/ 4u);
const Struct* str_f32 = create<Struct>(Source{},
Sym("str_f32"),
utils::Vector{
create<StructMember>(
/* source */ Source{},
/* name */ Sym("x"),
/* type */ f32,
/* index */ 0u,
/* offset */ 0u,
/* align */ 4u,
/* size */ 4u,
/* location */ std::nullopt),
},
/* align*/ 4u,
/* size*/ 4u,
/* size_no_padding*/ 4u);
const Struct* str_f16 = create<Struct>(Source{},
Sym("str_f16"),
utils::Vector{
create<StructMember>(
/* source */ Source{},
/* name */ Sym("x"),
/* type */ f16,
/* index */ 0u,
/* offset */ 0u,
/* align */ 4u,
/* size */ 4u,
/* location */ std::nullopt),
},
/* align*/ 4u,
/* size*/ 4u,
/* size_no_padding*/ 4u);
Struct* str_af = create<Struct>(Source{},
Sym("str_af"),
utils::Vector{
create<StructMember>(
/* source */ Source{},
/* name */ Sym("x"),
/* type */ af,
/* index */ 0u,
/* offset */ 0u,
/* align */ 4u,
/* size */ 4u,
/* location */ std::nullopt),
},
/* align*/ 4u,
/* size*/ 4u,
/* size_no_padding*/ 4u);
const Array* arr_i32 = create<Array>(
/* element */ i32,
/* count */ create<ConstantArrayCount>(5u),