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:
parent
ac146b1a48
commit
28a7827981
|
@ -497,7 +497,7 @@ class ProgramBuilder {
|
||||||
/// @returns the de-aliased array count pointer
|
/// @returns the de-aliased array count pointer
|
||||||
template <typename T, typename... ARGS>
|
template <typename T, typename... ARGS>
|
||||||
traits::EnableIf<traits::IsTypeOrDerived<T, type::ArrayCount> ||
|
traits::EnableIf<traits::IsTypeOrDerived<T, type::ArrayCount> ||
|
||||||
traits::IsTypeOrDerived<T, type::StructMemberBase>,
|
traits::IsTypeOrDerived<T, type::StructMember>,
|
||||||
T>*
|
T>*
|
||||||
create(ARGS&&... args) {
|
create(ARGS&&... args) {
|
||||||
AssertNotMoved();
|
AssertNotMoved();
|
||||||
|
|
|
@ -416,7 +416,7 @@ struct Composite : ImplConstant {
|
||||||
utils::Vector<const sem::Constant*, 4> conv_els;
|
utils::Vector<const sem::Constant*, 4> conv_els;
|
||||||
conv_els.Reserve(elements.Length());
|
conv_els.Reserve(elements.Length());
|
||||||
std::function<const type::Type*(size_t idx)> target_el_ty;
|
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()) {
|
if (str->Members().Length() != elements.Length()) {
|
||||||
TINT_ICE(Resolver, builder.Diagnostics())
|
TINT_ICE(Resolver, builder.Diagnostics())
|
||||||
<< "const-eval conversion of structure has mismatched element counts";
|
<< "const-eval conversion of structure has mismatched element counts";
|
||||||
|
@ -494,7 +494,7 @@ const ImplConstant* ZeroValue(ProgramBuilder& builder, const type::Type* type) {
|
||||||
}
|
}
|
||||||
return nullptr;
|
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::Hashmap<const type::Type*, const ImplConstant*, 8> zero_by_type;
|
||||||
utils::Vector<const sem::Constant*, 4> zeros;
|
utils::Vector<const sem::Constant*, 4> zeros;
|
||||||
zeros.Reserve(s->Members().Length());
|
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,
|
ConstEval::Result ConstEval::MemberAccess(const sem::Expression* obj_expr,
|
||||||
const type::StructMemberBase* member) {
|
const type::StructMember* member) {
|
||||||
auto obj_val = obj_expr->ConstantValue();
|
auto obj_val = obj_expr->ConstantValue();
|
||||||
if (!obj_val) {
|
if (!obj_val) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Constant;
|
||||||
class Expression;
|
class Expression;
|
||||||
} // namespace tint::sem
|
} // namespace tint::sem
|
||||||
namespace tint::type {
|
namespace tint::type {
|
||||||
class StructMemberBase;
|
class StructMember;
|
||||||
} // namespace tint::type
|
} // namespace tint::type
|
||||||
|
|
||||||
namespace tint::resolver {
|
namespace tint::resolver {
|
||||||
|
@ -94,7 +94,7 @@ class ConstEval {
|
||||||
/// @param obj the object being accessed
|
/// @param obj the object being accessed
|
||||||
/// @param member the member
|
/// @param member the member
|
||||||
/// @return the result of the member access, or null if the value cannot be calculated
|
/// @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 ty the result type
|
||||||
/// @param vector the vector being swizzled
|
/// @param vector the vector being swizzled
|
||||||
|
|
|
@ -32,13 +32,13 @@ namespace tint::sem {
|
||||||
class StructMember;
|
class StructMember;
|
||||||
} // namespace tint::sem
|
} // namespace tint::sem
|
||||||
namespace tint::type {
|
namespace tint::type {
|
||||||
class StructMemberBase;
|
class StructMember;
|
||||||
} // namespace tint::type
|
} // namespace tint::type
|
||||||
|
|
||||||
namespace tint::sem {
|
namespace tint::sem {
|
||||||
|
|
||||||
/// Struct holds the semantic information for structures.
|
/// Struct holds the semantic information for structures.
|
||||||
class Struct final : public Castable<Struct, type::StructBase> {
|
class Struct final : public Castable<Struct, type::Struct> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param declaration the AST structure declaration
|
/// @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.
|
/// 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:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param declaration the AST declaration node
|
/// @param declaration the AST declaration node
|
||||||
|
|
|
@ -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
|
// Returns true if the expression should be hoisted to a new let statement before the
|
||||||
// expression's statement.
|
// expression's statement.
|
||||||
auto should_hoist = [&](const sem::Expression* expr) {
|
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
|
// We only care about array and struct initializers
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ class Manager final {
|
||||||
/// pointer is returned.
|
/// pointer is returned.
|
||||||
template <typename TYPE,
|
template <typename TYPE,
|
||||||
typename _ = std::enable_if<traits::IsTypeOrDerived<TYPE, ArrayCount> ||
|
typename _ = std::enable_if<traits::IsTypeOrDerived<TYPE, ArrayCount> ||
|
||||||
traits::IsTypeOrDerived<TYPE, StructMemberBase>>,
|
traits::IsTypeOrDerived<TYPE, StructMember>>,
|
||||||
typename... ARGS>
|
typename... ARGS>
|
||||||
TYPE* GetNode(ARGS&&... args) {
|
TYPE* GetNode(ARGS&&... args) {
|
||||||
return nodes_.Get<TYPE>(std::forward<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 {
|
size_t operator()(const tint::type::Node& type) const {
|
||||||
if (const auto* ac = type.As<tint::type::ArrayCount>()) {
|
if (const auto* ac = type.As<tint::type::ArrayCount>()) {
|
||||||
return ac->Hash();
|
return ac->Hash();
|
||||||
} else if (type.Is<tint::type::StructMemberBase>()) {
|
} else if (type.Is<tint::type::StructMember>()) {
|
||||||
return tint::TypeInfo::Of<tint::type::StructMemberBase>().full_hashcode;
|
return tint::TypeInfo::Of<tint::type::StructMember>().full_hashcode;
|
||||||
}
|
}
|
||||||
TINT_ASSERT(Type, false && "Unreachable");
|
TINT_ASSERT(Type, false && "Unreachable");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -139,7 +139,7 @@ struct equal_to<tint::type::Node> {
|
||||||
return ac->Equals(*bc);
|
return ac->Equals(*bc);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (a.Is<tint::type::StructMemberBase>()) {
|
} else if (a.Is<tint::type::StructMember>()) {
|
||||||
return &a == &b;
|
return &a == &b;
|
||||||
}
|
}
|
||||||
TINT_ASSERT(Type, false && "Unreachable");
|
TINT_ASSERT(Type, false && "Unreachable");
|
||||||
|
|
|
@ -22,13 +22,13 @@
|
||||||
#include "src/tint/symbol_table.h"
|
#include "src/tint/symbol_table.h"
|
||||||
#include "src/tint/utils/hash.h"
|
#include "src/tint/utils/hash.h"
|
||||||
|
|
||||||
TINT_INSTANTIATE_TYPEINFO(tint::type::StructBase);
|
TINT_INSTANTIATE_TYPEINFO(tint::type::Struct);
|
||||||
TINT_INSTANTIATE_TYPEINFO(tint::type::StructMemberBase);
|
TINT_INSTANTIATE_TYPEINFO(tint::type::StructMember);
|
||||||
|
|
||||||
namespace tint::type {
|
namespace tint::type {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TypeFlags FlagsFrom(utils::VectorRef<const StructMemberBase*> members) {
|
TypeFlags FlagsFrom(utils::VectorRef<const StructMember*> members) {
|
||||||
TypeFlags flags{
|
TypeFlags flags{
|
||||||
TypeFlag::kConstructable,
|
TypeFlag::kConstructable,
|
||||||
TypeFlag::kCreationFixedFootprint,
|
TypeFlag::kCreationFixedFootprint,
|
||||||
|
@ -50,12 +50,12 @@ TypeFlags FlagsFrom(utils::VectorRef<const StructMemberBase*> members) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
StructBase::StructBase(tint::Source source,
|
Struct::Struct(tint::Source source,
|
||||||
Symbol name,
|
Symbol name,
|
||||||
utils::VectorRef<const StructMemberBase*> members,
|
utils::VectorRef<const StructMember*> members,
|
||||||
uint32_t align,
|
uint32_t align,
|
||||||
uint32_t size,
|
uint32_t size,
|
||||||
uint32_t size_no_padding)
|
uint32_t size_no_padding)
|
||||||
: Base(FlagsFrom(members)),
|
: Base(FlagsFrom(members)),
|
||||||
source_(source),
|
source_(source),
|
||||||
name_(name),
|
name_(name),
|
||||||
|
@ -64,20 +64,20 @@ StructBase::StructBase(tint::Source source,
|
||||||
size_(size),
|
size_(size),
|
||||||
size_no_padding_(size_no_padding) {}
|
size_no_padding_(size_no_padding) {}
|
||||||
|
|
||||||
StructBase::~StructBase() = default;
|
Struct::~Struct() = default;
|
||||||
|
|
||||||
size_t StructBase::Hash() const {
|
size_t Struct::Hash() const {
|
||||||
return utils::Hash(TypeInfo::Of<StructBase>().full_hashcode, name_);
|
return utils::Hash(TypeInfo::Of<Struct>().full_hashcode, name_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StructBase::Equals(const Type& other) const {
|
bool Struct::Equals(const Type& other) const {
|
||||||
if (auto* o = other.As<StructBase>()) {
|
if (auto* o = other.As<Struct>()) {
|
||||||
return o->name_ == name_;
|
return o->name_ == name_;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const StructMemberBase* StructBase::FindMember(Symbol name) const {
|
const StructMember* Struct::FindMember(Symbol name) const {
|
||||||
for (auto* member : members_) {
|
for (auto* member : members_) {
|
||||||
if (member->Name() == name) {
|
if (member->Name() == name) {
|
||||||
return member;
|
return member;
|
||||||
|
@ -86,22 +86,22 @@ const StructMemberBase* StructBase::FindMember(Symbol name) const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t StructBase::Align() const {
|
uint32_t Struct::Align() const {
|
||||||
return align_;
|
return align_;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t StructBase::Size() const {
|
uint32_t Struct::Size() const {
|
||||||
return size_;
|
return size_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string StructBase::FriendlyName(const SymbolTable& symbols) const {
|
std::string Struct::FriendlyName(const SymbolTable& symbols) const {
|
||||||
return symbols.NameFor(name_);
|
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;
|
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()) {
|
if (Members().IsEmpty()) {
|
||||||
return {};
|
return {};
|
||||||
|
@ -164,14 +164,14 @@ std::string StructBase::Layout(const tint::SymbolTable& symbols) const {
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
StructMemberBase::StructMemberBase(tint::Source source,
|
StructMember::StructMember(tint::Source source,
|
||||||
Symbol name,
|
Symbol name,
|
||||||
const type::Type* type,
|
const type::Type* type,
|
||||||
uint32_t index,
|
uint32_t index,
|
||||||
uint32_t offset,
|
uint32_t offset,
|
||||||
uint32_t align,
|
uint32_t align,
|
||||||
uint32_t size,
|
uint32_t size,
|
||||||
std::optional<uint32_t> location)
|
std::optional<uint32_t> location)
|
||||||
: source_(source),
|
: source_(source),
|
||||||
name_(name),
|
name_(name),
|
||||||
type_(type),
|
type_(type),
|
||||||
|
@ -181,6 +181,6 @@ StructMemberBase::StructMemberBase(tint::Source source,
|
||||||
size_(size),
|
size_(size),
|
||||||
location_(location) {}
|
location_(location) {}
|
||||||
|
|
||||||
StructMemberBase::~StructMemberBase() = default;
|
StructMember::~StructMember() = default;
|
||||||
|
|
||||||
} // namespace tint::type
|
} // namespace tint::type
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
namespace tint::type {
|
namespace tint::type {
|
||||||
class StructMemberBase;
|
class StructMember;
|
||||||
} // namespace tint::type
|
} // namespace tint::type
|
||||||
|
|
||||||
namespace tint::type {
|
namespace tint::type {
|
||||||
|
@ -44,8 +44,8 @@ enum class PipelineStageUsage {
|
||||||
kComputeOutput,
|
kComputeOutput,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// StructBase holds the Type information for structures.
|
/// Struct holds the Type information for structures.
|
||||||
class StructBase : public Castable<StructBase, Type> {
|
class Struct : public Castable<Struct, Type> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the source of the structure
|
/// @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 the byte size of the structure
|
||||||
/// @param size_no_padding size of the members without the end of structure
|
/// @param size_no_padding size of the members without the end of structure
|
||||||
/// alignment padding
|
/// alignment padding
|
||||||
StructBase(tint::Source source,
|
Struct(tint::Source source,
|
||||||
Symbol name,
|
Symbol name,
|
||||||
utils::VectorRef<const StructMemberBase*> members,
|
utils::VectorRef<const StructMember*> members,
|
||||||
uint32_t align,
|
uint32_t align,
|
||||||
uint32_t size,
|
uint32_t size,
|
||||||
uint32_t size_no_padding);
|
uint32_t size_no_padding);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~StructBase() override;
|
~Struct() override;
|
||||||
|
|
||||||
/// @returns a hash of the type.
|
/// @returns a hash of the type.
|
||||||
size_t Hash() const override;
|
size_t Hash() const override;
|
||||||
|
@ -79,11 +79,11 @@ class StructBase : public Castable<StructBase, Type> {
|
||||||
Symbol Name() const { return name_; }
|
Symbol Name() const { return name_; }
|
||||||
|
|
||||||
/// @returns the members of the structure
|
/// @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
|
/// @param name the member name to look for
|
||||||
/// @returns the member with the given name, or nullptr if it was not found.
|
/// @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
|
/// @returns the byte alignment of the structure
|
||||||
/// @note this may differ from the alignment of a structure member of this
|
/// @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;
|
std::string Layout(const tint::SymbolTable& symbols) const;
|
||||||
|
|
||||||
/// @param concrete the conversion-rank ordered concrete versions of this abstract structure.
|
/// @param concrete the conversion-rank ordered concrete versions of this abstract structure.
|
||||||
void SetConcreteTypes(utils::VectorRef<const StructBase*> concrete) {
|
void SetConcreteTypes(utils::VectorRef<const Struct*> concrete) { concrete_types_ = concrete; }
|
||||||
concrete_types_ = concrete;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @returns the conversion-rank ordered concrete versions of this abstract structure, or an
|
/// @returns the conversion-rank ordered concrete versions of this abstract structure, or an
|
||||||
/// empty vector if this structure is not abstract.
|
/// empty vector if this structure is not abstract.
|
||||||
/// @note only structures returned by builtins may be abstract (e.g. modf, frexp)
|
/// @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:
|
private:
|
||||||
const tint::Source source_;
|
const tint::Source source_;
|
||||||
const Symbol name_;
|
const Symbol name_;
|
||||||
const utils::Vector<const StructMemberBase*, 4> members_;
|
const utils::Vector<const StructMember*, 4> members_;
|
||||||
const uint32_t align_;
|
const uint32_t align_;
|
||||||
const uint32_t size_;
|
const uint32_t size_;
|
||||||
const uint32_t size_no_padding_;
|
const uint32_t size_no_padding_;
|
||||||
std::unordered_set<ast::AddressSpace> address_space_usage_;
|
std::unordered_set<ast::AddressSpace> address_space_usage_;
|
||||||
std::unordered_set<PipelineStageUsage> pipeline_stage_uses_;
|
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.
|
/// StructMember holds the type information for structure members.
|
||||||
class StructMemberBase : public Castable<StructMemberBase, Node> {
|
class StructMember : public Castable<StructMember, Node> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the source of the struct member
|
/// @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 align the byte alignment of the member
|
||||||
/// @param size the byte size of the member
|
/// @param size the byte size of the member
|
||||||
/// @param location the location attribute, if present
|
/// @param location the location attribute, if present
|
||||||
StructMemberBase(tint::Source source,
|
StructMember(tint::Source source,
|
||||||
Symbol name,
|
Symbol name,
|
||||||
const type::Type* type,
|
const type::Type* type,
|
||||||
uint32_t index,
|
uint32_t index,
|
||||||
uint32_t offset,
|
uint32_t offset,
|
||||||
uint32_t align,
|
uint32_t align,
|
||||||
uint32_t size,
|
uint32_t size,
|
||||||
std::optional<uint32_t> location);
|
std::optional<uint32_t> location);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~StructMemberBase() override;
|
~StructMember() override;
|
||||||
|
|
||||||
/// @returns the source the struct member
|
/// @returns the source the struct member
|
||||||
const tint::Source& Source() const { return source_; }
|
const tint::Source& Source() const { return source_; }
|
||||||
|
@ -198,10 +196,10 @@ class StructMemberBase : public Castable<StructMemberBase, Node> {
|
||||||
|
|
||||||
/// Sets the owning structure to `s`
|
/// Sets the owning structure to `s`
|
||||||
/// @param s the new structure owner
|
/// @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
|
/// @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
|
/// @returns the type of the member
|
||||||
const type::Type* Type() const { return type_; }
|
const type::Type* Type() const { return type_; }
|
||||||
|
@ -224,7 +222,7 @@ class StructMemberBase : public Castable<StructMemberBase, Node> {
|
||||||
private:
|
private:
|
||||||
const tint::Source source_;
|
const tint::Source source_;
|
||||||
const Symbol name_;
|
const Symbol name_;
|
||||||
const StructBase* struct_;
|
const type::Struct* struct_;
|
||||||
const type::Type* type_;
|
const type::Type* type_;
|
||||||
const uint32_t index_;
|
const uint32_t index_;
|
||||||
const uint32_t offset_;
|
const uint32_t offset_;
|
||||||
|
|
|
@ -24,27 +24,27 @@ using TypeStructTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(TypeStructTest, Creation) {
|
TEST_F(TypeStructTest, Creation) {
|
||||||
auto name = Sym("S");
|
auto name = Sym("S");
|
||||||
auto* s = create<StructBase>(Source{}, name, utils::Empty, 4u /* align */, 8u /* size */,
|
auto* s = create<Struct>(Source{}, name, utils::Empty, 4u /* align */, 8u /* size */,
|
||||||
16u /* size_no_padding */);
|
16u /* size_no_padding */);
|
||||||
EXPECT_EQ(s->Align(), 4u);
|
EXPECT_EQ(s->Align(), 4u);
|
||||||
EXPECT_EQ(s->Size(), 8u);
|
EXPECT_EQ(s->Size(), 8u);
|
||||||
EXPECT_EQ(s->SizeNoPadding(), 16u);
|
EXPECT_EQ(s->SizeNoPadding(), 16u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TypeStructTest, Hash) {
|
TEST_F(TypeStructTest, Hash) {
|
||||||
auto* a = create<StructBase>(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */,
|
auto* a = create<Struct>(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */,
|
||||||
4u /* size_no_padding */);
|
4u /* size_no_padding */);
|
||||||
auto* b = create<StructBase>(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */,
|
auto* b = create<Struct>(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */,
|
||||||
4u /* size_no_padding */);
|
4u /* size_no_padding */);
|
||||||
|
|
||||||
EXPECT_NE(a->Hash(), b->Hash());
|
EXPECT_NE(a->Hash(), b->Hash());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TypeStructTest, Equals) {
|
TEST_F(TypeStructTest, Equals) {
|
||||||
auto* a = create<StructBase>(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */,
|
auto* a = create<Struct>(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */,
|
||||||
4u /* size_no_padding */);
|
4u /* size_no_padding */);
|
||||||
auto* b = create<StructBase>(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */,
|
auto* b = create<Struct>(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */,
|
||||||
4u /* size_no_padding */);
|
4u /* size_no_padding */);
|
||||||
|
|
||||||
EXPECT_TRUE(a->Equals(*a));
|
EXPECT_TRUE(a->Equals(*a));
|
||||||
EXPECT_FALSE(a->Equals(*b));
|
EXPECT_FALSE(a->Equals(*b));
|
||||||
|
@ -53,8 +53,8 @@ TEST_F(TypeStructTest, Equals) {
|
||||||
|
|
||||||
TEST_F(TypeStructTest, FriendlyName) {
|
TEST_F(TypeStructTest, FriendlyName) {
|
||||||
auto name = Sym("my_struct");
|
auto name = Sym("my_struct");
|
||||||
auto* s = create<StructBase>(Source{}, name, utils::Empty, 4u /* align */, 4u /* size */,
|
auto* s = create<Struct>(Source{}, name, utils::Empty, 4u /* align */, 4u /* size */,
|
||||||
4u /* size_no_padding */);
|
4u /* size_no_padding */);
|
||||||
EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct");
|
EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ bool Type::HoldsAbstract() const {
|
||||||
[&](const Vector* v) { return v->type()->HoldsAbstract(); },
|
[&](const Vector* v) { return v->type()->HoldsAbstract(); },
|
||||||
[&](const Matrix* m) { return m->type()->HoldsAbstract(); },
|
[&](const Matrix* m) { return m->type()->HoldsAbstract(); },
|
||||||
[&](const Array* a) { return a->ElemType()->HoldsAbstract(); },
|
[&](const Array* a) { return a->ElemType()->HoldsAbstract(); },
|
||||||
[&](const StructBase* s) {
|
[&](const Struct* s) {
|
||||||
for (auto* m : s->Members()) {
|
for (auto* m : s->Members()) {
|
||||||
if (m->Type()->HoldsAbstract()) {
|
if (m->Type()->HoldsAbstract()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -238,7 +238,7 @@ uint32_t Type::ConversionRank(const Type* from, const Type* to) {
|
||||||
}
|
}
|
||||||
return kNoConversion;
|
return kNoConversion;
|
||||||
},
|
},
|
||||||
[&](const StructBase* from_str) {
|
[&](const Struct* from_str) {
|
||||||
auto concrete_tys = from_str->ConcreteTypes();
|
auto concrete_tys = from_str->ConcreteTypes();
|
||||||
for (size_t i = 0; i < concrete_tys.Length(); i++) {
|
for (size_t i = 0; i < concrete_tys.Length(); i++) {
|
||||||
if (concrete_tys[i] == to) {
|
if (concrete_tys[i] == to) {
|
||||||
|
|
|
@ -45,54 +45,54 @@ struct TypeTest : public TestHelper {
|
||||||
const Matrix* mat4x3_af = create<Matrix>(vec3_af, 4u);
|
const Matrix* mat4x3_af = create<Matrix>(vec3_af, 4u);
|
||||||
const Reference* ref_u32 =
|
const Reference* ref_u32 =
|
||||||
create<Reference>(u32, ast::AddressSpace::kPrivate, ast::Access::kReadWrite);
|
create<Reference>(u32, ast::AddressSpace::kPrivate, ast::Access::kReadWrite);
|
||||||
const StructBase* str_f32 = create<StructBase>(Source{},
|
const Struct* str_f32 = create<Struct>(Source{},
|
||||||
Sym("str_f32"),
|
Sym("str_f32"),
|
||||||
utils::Vector{
|
utils::Vector{
|
||||||
create<StructMemberBase>(
|
create<StructMember>(
|
||||||
/* source */ Source{},
|
/* source */ Source{},
|
||||||
/* name */ Sym("x"),
|
/* name */ Sym("x"),
|
||||||
/* type */ f32,
|
/* type */ f32,
|
||||||
/* index */ 0u,
|
/* index */ 0u,
|
||||||
/* offset */ 0u,
|
/* offset */ 0u,
|
||||||
/* align */ 4u,
|
/* align */ 4u,
|
||||||
/* size */ 4u,
|
/* size */ 4u,
|
||||||
/* location */ std::nullopt),
|
/* location */ std::nullopt),
|
||||||
},
|
},
|
||||||
/* align*/ 4u,
|
/* align*/ 4u,
|
||||||
/* size*/ 4u,
|
/* size*/ 4u,
|
||||||
/* size_no_padding*/ 4u);
|
/* size_no_padding*/ 4u);
|
||||||
const StructBase* str_f16 = create<StructBase>(Source{},
|
const Struct* str_f16 = create<Struct>(Source{},
|
||||||
Sym("str_f16"),
|
Sym("str_f16"),
|
||||||
utils::Vector{
|
utils::Vector{
|
||||||
create<StructMemberBase>(
|
create<StructMember>(
|
||||||
/* source */ Source{},
|
/* source */ Source{},
|
||||||
/* name */ Sym("x"),
|
/* name */ Sym("x"),
|
||||||
/* type */ f16,
|
/* type */ f16,
|
||||||
/* index */ 0u,
|
/* index */ 0u,
|
||||||
/* offset */ 0u,
|
/* offset */ 0u,
|
||||||
/* align */ 4u,
|
/* align */ 4u,
|
||||||
/* size */ 4u,
|
/* size */ 4u,
|
||||||
/* location */ std::nullopt),
|
/* location */ std::nullopt),
|
||||||
},
|
},
|
||||||
/* align*/ 4u,
|
/* align*/ 4u,
|
||||||
/* size*/ 4u,
|
/* size*/ 4u,
|
||||||
/* size_no_padding*/ 4u);
|
/* size_no_padding*/ 4u);
|
||||||
StructBase* str_af = create<StructBase>(Source{},
|
Struct* str_af = create<Struct>(Source{},
|
||||||
Sym("str_af"),
|
Sym("str_af"),
|
||||||
utils::Vector{
|
utils::Vector{
|
||||||
create<StructMemberBase>(
|
create<StructMember>(
|
||||||
/* source */ Source{},
|
/* source */ Source{},
|
||||||
/* name */ Sym("x"),
|
/* name */ Sym("x"),
|
||||||
/* type */ af,
|
/* type */ af,
|
||||||
/* index */ 0u,
|
/* index */ 0u,
|
||||||
/* offset */ 0u,
|
/* offset */ 0u,
|
||||||
/* align */ 4u,
|
/* align */ 4u,
|
||||||
/* size */ 4u,
|
/* size */ 4u,
|
||||||
/* location */ std::nullopt),
|
/* location */ std::nullopt),
|
||||||
},
|
},
|
||||||
/* align*/ 4u,
|
/* align*/ 4u,
|
||||||
/* size*/ 4u,
|
/* size*/ 4u,
|
||||||
/* size_no_padding*/ 4u);
|
/* size_no_padding*/ 4u);
|
||||||
const Array* arr_i32 = create<Array>(
|
const Array* arr_i32 = create<Array>(
|
||||||
/* element */ i32,
|
/* element */ i32,
|
||||||
/* count */ create<ConstantArrayCount>(5u),
|
/* count */ create<ConstantArrayCount>(5u),
|
||||||
|
|
Loading…
Reference in New Issue