mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-12 06:45:16 +00:00
Rename all type UnwrapXXX() methods
Give them sensible names. Make them act consistently. Remove those that were not used. Change-Id: Ib043a4093cfae9f81630643e1a0e4eae7bca2440 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50305 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: James Price <jrprice@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
fcda15ef67
commit
f14e0e1c8c
@@ -80,41 +80,6 @@ TEST_F(AstAliasTest, FriendlyName) {
|
||||
EXPECT_EQ(at->FriendlyName(Symbols()), "Particle");
|
||||
}
|
||||
|
||||
TEST_F(AstAliasTest, UnwrapIfNeeded_Alias) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* a = create<Alias>(Sym("a_type"), u32);
|
||||
EXPECT_EQ(a->symbol(), Symbol(1, ID()));
|
||||
EXPECT_EQ(a->type(), u32);
|
||||
EXPECT_EQ(a->UnwrapIfNeeded(), u32);
|
||||
EXPECT_EQ(u32->UnwrapIfNeeded(), u32);
|
||||
}
|
||||
|
||||
TEST_F(AstAliasTest, UnwrapIfNeeded_AccessControl) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* ac = create<AccessControl>(AccessControl::kReadOnly, u32);
|
||||
EXPECT_EQ(ac->type(), u32);
|
||||
EXPECT_EQ(ac->UnwrapIfNeeded(), u32);
|
||||
}
|
||||
|
||||
TEST_F(AstAliasTest, UnwrapIfNeeded_MultiLevel) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* a = create<Alias>(Sym("a_type"), u32);
|
||||
auto* aa = create<Alias>(Sym("aa_type"), a);
|
||||
|
||||
EXPECT_EQ(aa->symbol(), Symbol(2, ID()));
|
||||
EXPECT_EQ(aa->type(), a);
|
||||
EXPECT_EQ(aa->UnwrapIfNeeded(), u32);
|
||||
}
|
||||
|
||||
TEST_F(AstAliasTest, UnwrapIfNeeded_MultiLevel_AliasAccessControl) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* a = create<Alias>(Sym("a_type"), u32);
|
||||
|
||||
auto* ac = create<AccessControl>(AccessControl::kReadWrite, a);
|
||||
EXPECT_EQ(ac->type(), a);
|
||||
EXPECT_EQ(ac->UnwrapIfNeeded(), u32);
|
||||
}
|
||||
|
||||
TEST_F(AstAliasTest, UnwrapAll_TwiceAliasPointerTwiceAlias) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* a = create<Alias>(Sym("a_type"), u32);
|
||||
@@ -128,31 +93,6 @@ TEST_F(AstAliasTest, UnwrapAll_TwiceAliasPointerTwiceAlias) {
|
||||
EXPECT_EQ(aapaa->UnwrapAll(), u32);
|
||||
}
|
||||
|
||||
TEST_F(AstAliasTest, UnwrapAll_SecondConsecutivePointerBlocksUnrapping) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* a = create<Alias>(Sym("a_type"), u32);
|
||||
auto* aa = create<Alias>(Sym("aa_type"), a);
|
||||
|
||||
auto* paa = create<Pointer>(aa, StorageClass::kUniform);
|
||||
auto* ppaa = create<Pointer>(paa, StorageClass::kUniform);
|
||||
auto* appaa = create<Alias>(Sym("appaa_type"), ppaa);
|
||||
EXPECT_EQ(appaa->UnwrapAll(), paa);
|
||||
}
|
||||
|
||||
TEST_F(AstAliasTest, UnwrapAll_SecondNonConsecutivePointerBlocksUnrapping) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* a = create<Alias>(Sym("a_type"), u32);
|
||||
auto* aa = create<Alias>(Sym("aa_type"), a);
|
||||
auto* paa = create<Pointer>(aa, StorageClass::kUniform);
|
||||
|
||||
auto* apaa = create<Alias>(Sym("apaa_type"), paa);
|
||||
auto* aapaa = create<Alias>(Sym("aapaa_type"), apaa);
|
||||
auto* paapaa = create<Pointer>(aapaa, StorageClass::kUniform);
|
||||
auto* apaapaa = create<Alias>(Sym("apaapaa_type"), paapaa);
|
||||
|
||||
EXPECT_EQ(apaapaa->UnwrapAll(), paa);
|
||||
}
|
||||
|
||||
TEST_F(AstAliasTest, UnwrapAll_AccessControlPointer) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* a = create<AccessControl>(AccessControl::kReadOnly, u32);
|
||||
@@ -170,14 +110,6 @@ TEST_F(AstAliasTest, UnwrapAll_PointerAccessControl) {
|
||||
EXPECT_EQ(a->UnwrapAll(), u32);
|
||||
}
|
||||
|
||||
TEST_F(AstAliasTest, UnwrapAliasIfNeeded) {
|
||||
auto* f32 = create<F32>();
|
||||
auto* alias1 = create<Alias>(Sym("alias1"), f32);
|
||||
auto* alias2 = create<Alias>(Sym("alias2"), alias1);
|
||||
auto* alias3 = create<Alias>(Sym("alias3"), alias2);
|
||||
EXPECT_EQ(alias3->UnwrapAliasIfNeeded(), f32);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
@@ -38,37 +38,20 @@ Type::Type(Type&&) = default;
|
||||
|
||||
Type::~Type() = default;
|
||||
|
||||
Type* Type::UnwrapPtrIfNeeded() {
|
||||
if (auto* ptr = As<Pointer>()) {
|
||||
return ptr->type();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
Type* Type::UnwrapAliasIfNeeded() {
|
||||
Type* unwrapped = this;
|
||||
while (auto* ptr = unwrapped->As<Alias>()) {
|
||||
unwrapped = ptr->type();
|
||||
}
|
||||
return unwrapped;
|
||||
}
|
||||
|
||||
Type* Type::UnwrapIfNeeded() {
|
||||
auto* where = this;
|
||||
Type* Type::UnwrapAll() {
|
||||
auto* type = this;
|
||||
while (true) {
|
||||
if (auto* alias = where->As<Alias>()) {
|
||||
where = alias->type();
|
||||
} else if (auto* access = where->As<AccessControl>()) {
|
||||
where = access->type();
|
||||
if (auto* alias = type->As<Alias>()) {
|
||||
type = alias->type();
|
||||
} else if (auto* access = type->As<AccessControl>()) {
|
||||
type = access->type();
|
||||
} else if (auto* ptr = type->As<Pointer>()) {
|
||||
type = ptr->type();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return where;
|
||||
}
|
||||
|
||||
Type* Type::UnwrapAll() {
|
||||
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
|
||||
return type;
|
||||
}
|
||||
|
||||
bool Type::is_scalar() const {
|
||||
|
||||
@@ -43,49 +43,10 @@ class Type : public Castable<Type, Node> {
|
||||
/// declared in WGSL.
|
||||
virtual std::string FriendlyName(const SymbolTable& symbols) const = 0;
|
||||
|
||||
/// @returns the pointee type if this is a pointer, `this` otherwise
|
||||
Type* UnwrapPtrIfNeeded();
|
||||
|
||||
/// @returns the most deeply nested aliased type if this is an alias, `this`
|
||||
/// otherwise
|
||||
const Type* UnwrapAliasIfNeeded() const {
|
||||
return const_cast<Type*>(this)->UnwrapAliasIfNeeded();
|
||||
}
|
||||
|
||||
/// @returns the most deeply nested aliased type if this is an alias, `this`
|
||||
/// otherwise
|
||||
Type* UnwrapAliasIfNeeded();
|
||||
|
||||
/// Removes all levels of aliasing and access control.
|
||||
/// This is just enough to assist with WGSL translation
|
||||
/// in that you want see through one level of pointer to get from an
|
||||
/// identifier-like expression as an l-value to its corresponding r-value,
|
||||
/// plus see through the wrappers on either side.
|
||||
/// @returns the completely unaliased type.
|
||||
Type* UnwrapIfNeeded();
|
||||
|
||||
/// Removes all levels of aliasing and access control.
|
||||
/// This is just enough to assist with WGSL translation
|
||||
/// in that you want see through one level of pointer to get from an
|
||||
/// identifier-like expression as an l-value to its corresponding r-value,
|
||||
/// plus see through the wrappers on either side.
|
||||
/// @returns the completely unaliased type.
|
||||
const Type* UnwrapIfNeeded() const {
|
||||
return const_cast<Type*>(this)->UnwrapIfNeeded();
|
||||
}
|
||||
|
||||
/// Returns the type found after:
|
||||
/// - removing all layers of aliasing and access control if they exist, then
|
||||
/// - removing the pointer, if it exists, then
|
||||
/// - removing all further layers of aliasing or access control, if they exist
|
||||
/// @returns the unwrapped type
|
||||
/// @returns the type with all aliasing, access control and pointers removed
|
||||
Type* UnwrapAll();
|
||||
|
||||
/// Returns the type found after:
|
||||
/// - removing all layers of aliasing and access control if they exist, then
|
||||
/// - removing the pointer, if it exists, then
|
||||
/// - removing all further layers of aliasing or access control, if they exist
|
||||
/// @returns the unwrapped type
|
||||
/// @returns the type with all aliasing, access control and pointers removed
|
||||
const Type* UnwrapAll() const { return const_cast<Type*>(this)->UnwrapAll(); }
|
||||
|
||||
/// @returns true if this type is a scalar
|
||||
|
||||
Reference in New Issue
Block a user