mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
Replace StructMemberDecoration::(Is|As) with Castable
Change-Id: I158194c60a9fe0ea2126ca31a92ad536c92a6388 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34314 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -41,7 +41,7 @@ StructMember::~StructMember() = default;
|
||||
|
||||
bool StructMember::has_offset_decoration() const {
|
||||
for (auto* deco : decorations_) {
|
||||
if (deco->IsOffset()) {
|
||||
if (deco->Is<ast::StructMemberOffsetDecoration>()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -50,8 +50,8 @@ bool StructMember::has_offset_decoration() const {
|
||||
|
||||
uint32_t StructMember::offset() const {
|
||||
for (auto* deco : decorations_) {
|
||||
if (deco->IsOffset()) {
|
||||
return deco->AsOffset()->offset();
|
||||
if (auto* offset = deco->As<ast::StructMemberOffsetDecoration>()) {
|
||||
return offset->offset();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -32,14 +32,5 @@ DecorationKind StructMemberDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool StructMemberDecoration::IsOffset() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
StructMemberOffsetDecoration* StructMemberDecoration::AsOffset() {
|
||||
assert(IsOffset());
|
||||
return static_cast<StructMemberOffsetDecoration*>(this);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
class StructMemberOffsetDecoration;
|
||||
|
||||
/// A decoration attached to a struct member
|
||||
class StructMemberDecoration
|
||||
: public Castable<StructMemberDecoration, Decoration> {
|
||||
@@ -38,12 +36,6 @@ class StructMemberDecoration
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @returns true if this is an offset decoration
|
||||
virtual bool IsOffset() const;
|
||||
|
||||
/// @returns the decoration as an offset decoration
|
||||
StructMemberOffsetDecoration* AsOffset();
|
||||
|
||||
protected:
|
||||
/// Constructor
|
||||
/// @param source the source of this decoration
|
||||
|
||||
@@ -21,10 +21,6 @@ StructMemberOffsetDecoration::StructMemberOffsetDecoration(uint32_t offset,
|
||||
const Source& source)
|
||||
: Base(source), offset_(offset) {}
|
||||
|
||||
bool StructMemberOffsetDecoration::IsOffset() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
StructMemberOffsetDecoration::~StructMemberOffsetDecoration() = default;
|
||||
|
||||
void StructMemberOffsetDecoration::to_str(std::ostream& out,
|
||||
|
||||
@@ -34,9 +34,6 @@ class StructMemberOffsetDecoration
|
||||
StructMemberOffsetDecoration(uint32_t offset, const Source& source);
|
||||
~StructMemberOffsetDecoration() override;
|
||||
|
||||
/// @returns true if this is an offset decoration
|
||||
bool IsOffset() const override;
|
||||
|
||||
/// @returns the offset value
|
||||
uint32_t offset() const { return offset_; }
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ TEST_F(StructMemberOffsetDecorationTest, Creation) {
|
||||
|
||||
TEST_F(StructMemberOffsetDecorationTest, Is) {
|
||||
StructMemberOffsetDecoration d{2, Source{}};
|
||||
EXPECT_TRUE(d.IsOffset());
|
||||
EXPECT_TRUE(d.Is<ast::StructMemberOffsetDecoration>());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -36,7 +36,7 @@ TEST_F(StructMemberTest, Creation) {
|
||||
EXPECT_EQ(st.name(), "a");
|
||||
EXPECT_EQ(st.type(), &i32);
|
||||
EXPECT_EQ(st.decorations().size(), 1u);
|
||||
EXPECT_TRUE(st.decorations()[0]->IsOffset());
|
||||
EXPECT_TRUE(st.decorations()[0]->Is<ast::StructMemberOffsetDecoration>());
|
||||
EXPECT_EQ(st.source().range.begin.line, 0u);
|
||||
EXPECT_EQ(st.source().range.begin.column, 0u);
|
||||
EXPECT_EQ(st.source().range.end.line, 0u);
|
||||
|
||||
Reference in New Issue
Block a user