mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
ast: Remove the now unused Decoration::IsKind() method
And replace the use of`ast::As(Decoration* deco)` with `Castable::As<T>()`. These were used for dynamic casting, but is now replaced with Castable. Change-Id: Ie5fe19ad4db4bc4d19f5386d2cfddaaf84b215d0 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34302 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -28,10 +28,6 @@ DecorationKind AccessDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool AccessDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || Base::IsKind(kind);
|
||||
}
|
||||
|
||||
bool AccessDecoration::IsAccess() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,11 +38,6 @@ class AccessDecoration : public Castable<AccessDecoration, TypeDecoration> {
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is an access decoration
|
||||
bool IsAccess() const override;
|
||||
|
||||
|
||||
@@ -31,10 +31,6 @@ DecorationKind ArrayDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool ArrayDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind;
|
||||
}
|
||||
|
||||
bool ArrayDecoration::IsStride() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -37,11 +37,6 @@ class ArrayDecoration : public Castable<ArrayDecoration, Decoration> {
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is a stride decoration
|
||||
virtual bool IsStride() const;
|
||||
|
||||
|
||||
@@ -28,10 +28,6 @@ DecorationKind BindingDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool BindingDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || Base::IsKind(kind);
|
||||
}
|
||||
|
||||
bool BindingDecoration::IsBinding() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,11 +38,6 @@ class BindingDecoration
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is a binding decoration
|
||||
bool IsBinding() const override;
|
||||
|
||||
|
||||
@@ -28,10 +28,6 @@ DecorationKind BuiltinDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool BuiltinDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || Base::IsKind(kind);
|
||||
}
|
||||
|
||||
bool BuiltinDecoration::IsBuiltin() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -37,11 +37,6 @@ class BuiltinDecoration
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is a builtin decoration
|
||||
bool IsBuiltin() const override;
|
||||
|
||||
|
||||
@@ -28,10 +28,6 @@ DecorationKind ConstantIdDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool ConstantIdDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || Base::IsKind(kind);
|
||||
}
|
||||
|
||||
bool ConstantIdDecoration::IsConstantId() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -37,11 +37,6 @@ class ConstantIdDecoration
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is a constant_id decoration
|
||||
bool IsConstantId() const override;
|
||||
|
||||
|
||||
@@ -54,11 +54,6 @@ class Decoration : public Castable<Decoration, Node> {
|
||||
/// @return the decoration kind
|
||||
virtual DecorationKind GetKind() const = 0;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
virtual bool IsKind(DecorationKind kind) const = 0;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
@@ -68,19 +63,6 @@ class Decoration : public Castable<Decoration, Node> {
|
||||
explicit Decoration(const Source& source) : Base(source) {}
|
||||
};
|
||||
|
||||
/// As dynamically casts |deco| to the target type |TO|.
|
||||
/// @return the cast decoration, or nullptr if |deco| is not of the type |TO|.
|
||||
template <typename TO>
|
||||
TO* As(Decoration* deco) {
|
||||
if (deco == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (deco->Is<TO>()) {
|
||||
return static_cast<TO*>(deco);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/// A list of decorations
|
||||
using DecorationList = std::vector<Decoration*>;
|
||||
|
||||
|
||||
@@ -81,112 +81,6 @@ TEST_F(DecorationTest, Kinds) {
|
||||
EXPECT_EQ(LocationDecoration::Kind, DecorationKind::kLocation);
|
||||
}
|
||||
|
||||
TEST_F(DecorationTest, IsKind) {
|
||||
std::vector<DecorationKind> all_kinds{
|
||||
DecorationKind::kArray, DecorationKind::kStride,
|
||||
DecorationKind::kFunction, DecorationKind::kStage,
|
||||
DecorationKind::kWorkgroup, DecorationKind::kStruct,
|
||||
DecorationKind::kStructMember, DecorationKind::kStructMemberOffset,
|
||||
DecorationKind::kType, DecorationKind::kAccess,
|
||||
DecorationKind::kVariable, DecorationKind::kBinding,
|
||||
DecorationKind::kBuiltin, DecorationKind::kConstantId,
|
||||
DecorationKind::kLocation,
|
||||
};
|
||||
|
||||
struct ExpectedKinds {
|
||||
DecorationKind kind;
|
||||
std::unordered_set<DecorationKind> expect_true;
|
||||
};
|
||||
|
||||
// kArray
|
||||
// | kStride
|
||||
// kFunction
|
||||
// | kStage
|
||||
// | kWorkgroup
|
||||
// kStruct
|
||||
// kStructMember
|
||||
// | kStructMemberOffset
|
||||
// kType
|
||||
// | kAccess
|
||||
// kVariable
|
||||
// | kBinding
|
||||
// | kBuiltin
|
||||
// | kConstantId
|
||||
// | kLocation
|
||||
std::unordered_map<DecorationKind, std::unordered_set<DecorationKind>>
|
||||
kind_is{
|
||||
{
|
||||
DecorationKind::kStride,
|
||||
{DecorationKind::kArray, DecorationKind::kStride},
|
||||
},
|
||||
{
|
||||
DecorationKind::kStage,
|
||||
{DecorationKind::kFunction, DecorationKind::kStage},
|
||||
},
|
||||
{
|
||||
DecorationKind::kWorkgroup,
|
||||
{DecorationKind::kFunction, DecorationKind::kWorkgroup},
|
||||
},
|
||||
{
|
||||
DecorationKind::kStruct,
|
||||
{DecorationKind::kStruct},
|
||||
},
|
||||
{
|
||||
DecorationKind::kStructMemberOffset,
|
||||
{DecorationKind::kStructMember,
|
||||
DecorationKind::kStructMemberOffset},
|
||||
},
|
||||
{
|
||||
DecorationKind::kAccess,
|
||||
{DecorationKind::kType, DecorationKind::kAccess},
|
||||
},
|
||||
{
|
||||
DecorationKind::kBinding,
|
||||
{DecorationKind::kVariable, DecorationKind::kBinding},
|
||||
},
|
||||
{
|
||||
DecorationKind::kBuiltin,
|
||||
{DecorationKind::kVariable, DecorationKind::kBuiltin},
|
||||
},
|
||||
{
|
||||
DecorationKind::kConstantId,
|
||||
{DecorationKind::kVariable, DecorationKind::kConstantId},
|
||||
},
|
||||
{
|
||||
DecorationKind::kLocation,
|
||||
{DecorationKind::kVariable, DecorationKind::kLocation},
|
||||
},
|
||||
};
|
||||
|
||||
auto check = [&](Decoration* d) {
|
||||
auto& is_set = kind_is[d->GetKind()];
|
||||
for (auto test : all_kinds) {
|
||||
bool is_kind = is_set.find(test) != is_set.end();
|
||||
EXPECT_EQ(d->IsKind(test), is_kind)
|
||||
<< "decoration: " << d->GetKind() << " IsKind(" << test << ")";
|
||||
}
|
||||
};
|
||||
StrideDecoration stride(0, {});
|
||||
StageDecoration stage(PipelineStage::kNone, {});
|
||||
WorkgroupDecoration workgroup(0, {});
|
||||
StructMemberOffsetDecoration struct_member_offset(0, {});
|
||||
AccessDecoration access(AccessControl::kReadOnly, {});
|
||||
BindingDecoration binding(0, {});
|
||||
BuiltinDecoration builtin(Builtin::kNone, {});
|
||||
ConstantIdDecoration constant_id(0, {});
|
||||
LocationDecoration location(0, {});
|
||||
|
||||
check(&stride);
|
||||
check(&stage);
|
||||
check(&workgroup);
|
||||
check(&struct_member_offset);
|
||||
check(&access);
|
||||
check(&binding);
|
||||
check(&builtin);
|
||||
check(&constant_id);
|
||||
check(&location);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
@@ -32,10 +32,6 @@ DecorationKind FunctionDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool FunctionDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind;
|
||||
}
|
||||
|
||||
bool FunctionDecoration::IsStage() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -38,11 +38,6 @@ class FunctionDecoration : public Castable<FunctionDecoration, Decoration> {
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is a stage decoration
|
||||
virtual bool IsStage() const;
|
||||
/// @returns true if this is a workgroup decoration
|
||||
|
||||
@@ -28,10 +28,6 @@ DecorationKind LocationDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool LocationDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || Base::IsKind(kind);
|
||||
}
|
||||
|
||||
bool LocationDecoration::IsLocation() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,11 +38,6 @@ class LocationDecoration
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is a location decoration
|
||||
bool IsLocation() const override;
|
||||
|
||||
|
||||
@@ -28,10 +28,6 @@ DecorationKind StageDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool StageDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || Base::IsKind(kind);
|
||||
}
|
||||
|
||||
bool StageDecoration::IsStage() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -36,11 +36,6 @@ class StageDecoration : public Castable<StageDecoration, FunctionDecoration> {
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is a stage decoration
|
||||
bool IsStage() const override;
|
||||
|
||||
|
||||
@@ -26,10 +26,6 @@ DecorationKind StrideDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool StrideDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || Base::IsKind(kind);
|
||||
}
|
||||
|
||||
bool StrideDecoration::IsStride() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -39,11 +39,6 @@ class StrideDecoration : public Castable<StrideDecoration, ArrayDecoration> {
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is a stride decoration
|
||||
bool IsStride() const override;
|
||||
|
||||
|
||||
@@ -27,9 +27,5 @@ DecorationKind StructDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool StructDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind;
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
@@ -35,11 +35,6 @@ class StructDecoration : public Castable<StructDecoration, Decoration> {
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is a block struct
|
||||
virtual bool IsBlock() const = 0;
|
||||
|
||||
|
||||
@@ -32,10 +32,6 @@ DecorationKind StructMemberDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool StructMemberDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind;
|
||||
}
|
||||
|
||||
bool StructMemberDecoration::IsOffset() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -38,11 +38,6 @@ class StructMemberDecoration
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is an offset decoration
|
||||
virtual bool IsOffset() const;
|
||||
|
||||
|
||||
@@ -27,10 +27,6 @@ DecorationKind StructMemberOffsetDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool StructMemberOffsetDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || Base::IsKind(kind);
|
||||
}
|
||||
|
||||
bool StructMemberOffsetDecoration::IsOffset() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -41,11 +41,6 @@ class StructMemberOffsetDecoration
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is an offset decoration
|
||||
bool IsOffset() const override;
|
||||
|
||||
|
||||
@@ -31,10 +31,6 @@ DecorationKind TypeDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool TypeDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind;
|
||||
}
|
||||
|
||||
bool TypeDecoration::IsAccess() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -38,11 +38,6 @@ class TypeDecoration : public Castable<TypeDecoration, Decoration> {
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is an access decoration
|
||||
virtual bool IsAccess() const;
|
||||
|
||||
|
||||
@@ -35,10 +35,6 @@ DecorationKind VariableDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool VariableDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind;
|
||||
}
|
||||
|
||||
bool VariableDecoration::IsBinding() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -42,11 +42,6 @@ class VariableDecoration : public Castable<VariableDecoration, Decoration> {
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is a binding decoration
|
||||
virtual bool IsBinding() const;
|
||||
/// @returns true if this is a builtin decoration
|
||||
|
||||
@@ -39,10 +39,6 @@ DecorationKind WorkgroupDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool WorkgroupDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || Base::IsKind(kind);
|
||||
}
|
||||
|
||||
bool WorkgroupDecoration::IsWorkgroup() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,11 +51,6 @@ class WorkgroupDecoration
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
bool IsKind(DecorationKind kind) const override;
|
||||
|
||||
/// @returns true if this is a workgroup decoration
|
||||
bool IsWorkgroup() const override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user