diff --git a/src/ast/array_decoration.cc b/src/ast/array_decoration.cc index 62338b27e1..2bdefd46b1 100644 --- a/src/ast/array_decoration.cc +++ b/src/ast/array_decoration.cc @@ -31,14 +31,5 @@ DecorationKind ArrayDecoration::GetKind() const { return Kind; } -bool ArrayDecoration::IsStride() const { - return false; -} - -StrideDecoration* ArrayDecoration::AsStride() { - assert(IsStride()); - return static_cast(this); -} - } // namespace ast } // namespace tint diff --git a/src/ast/array_decoration.h b/src/ast/array_decoration.h index 43141a0034..5473385670 100644 --- a/src/ast/array_decoration.h +++ b/src/ast/array_decoration.h @@ -37,12 +37,6 @@ class ArrayDecoration : public Castable { /// @return the decoration kind DecorationKind GetKind() const override; - /// @returns true if this is a stride decoration - virtual bool IsStride() const; - - /// @returns the decoration as a stride decoration - StrideDecoration* AsStride(); - protected: /// Constructor /// @param source the source of this decoration diff --git a/src/ast/stride_decoration.cc b/src/ast/stride_decoration.cc index eea3053270..6de4550e18 100644 --- a/src/ast/stride_decoration.cc +++ b/src/ast/stride_decoration.cc @@ -20,10 +20,6 @@ namespace ast { StrideDecoration::StrideDecoration(uint32_t stride, const Source& source) : Base(source), stride_(stride) {} -bool StrideDecoration::IsStride() const { - return true; -} - StrideDecoration::~StrideDecoration() = default; void StrideDecoration::to_str(std::ostream& out, size_t indent) const { diff --git a/src/ast/stride_decoration.h b/src/ast/stride_decoration.h index ac4fd371d1..e3abd4bb09 100644 --- a/src/ast/stride_decoration.h +++ b/src/ast/stride_decoration.h @@ -33,9 +33,6 @@ class StrideDecoration : public Castable { StrideDecoration(uint32_t stride, const Source& source); ~StrideDecoration() override; - /// @returns true if this is a stride decoration - bool IsStride() const override; - /// @returns the stride value uint32_t stride() const { return stride_; } diff --git a/src/ast/stride_decoration_test.cc b/src/ast/stride_decoration_test.cc index 4a1088c4b3..6b9725585b 100644 --- a/src/ast/stride_decoration_test.cc +++ b/src/ast/stride_decoration_test.cc @@ -29,7 +29,7 @@ TEST_F(StrideDecorationTest, Creation) { TEST_F(StrideDecorationTest, Is) { StrideDecoration d{2, Source{}}; - EXPECT_TRUE(d.IsStride()); + EXPECT_TRUE(d.Is()); } TEST_F(StrideDecorationTest, Source) { diff --git a/src/ast/type/array_type.cc b/src/ast/type/array_type.cc index 4bdaf1b14d..d46fcc58c2 100644 --- a/src/ast/type/array_type.cc +++ b/src/ast/type/array_type.cc @@ -65,8 +65,8 @@ uint64_t ArrayType::BaseAlignment(MemoryLayout mem_layout) const { uint32_t ArrayType::array_stride() const { for (auto* deco : decos_) { - if (deco->IsStride()) { - return deco->AsStride()->stride(); + if (auto* stride = deco->As()) { + return stride->stride(); } } return 0; @@ -74,7 +74,7 @@ uint32_t ArrayType::array_stride() const { bool ArrayType::has_array_stride() const { for (auto* deco : decos_) { - if (deco->IsStride()) { + if (deco->Is()) { return true; } } diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc index 29c509c818..e8a85f8569 100644 --- a/src/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_type_decl_test.cc @@ -408,10 +408,10 @@ TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_OneBlock) { auto& decos = a->decorations(); ASSERT_EQ(decos.size(), 2u); - EXPECT_TRUE(decos[0]->IsStride()); - EXPECT_EQ(decos[0]->AsStride()->stride(), 16u); - EXPECT_TRUE(decos[1]->IsStride()); - EXPECT_EQ(decos[1]->AsStride()->stride(), 32u); + EXPECT_TRUE(decos[0]->Is()); + EXPECT_EQ(decos[0]->As()->stride(), 16u); + EXPECT_TRUE(decos[1]->Is()); + EXPECT_EQ(decos[1]->As()->stride(), 32u); } TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_MultipleBlocks) { @@ -429,10 +429,10 @@ TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_MultipleBlocks) { auto& decos = a->decorations(); ASSERT_EQ(decos.size(), 2u); - EXPECT_TRUE(decos[0]->IsStride()); - EXPECT_EQ(decos[0]->AsStride()->stride(), 16u); - EXPECT_TRUE(decos[1]->IsStride()); - EXPECT_EQ(decos[1]->AsStride()->stride(), 32u); + EXPECT_TRUE(decos[0]->Is()); + EXPECT_EQ(decos[0]->As()->stride(), 16u); + EXPECT_TRUE(decos[1]->Is()); + EXPECT_EQ(decos[1]->As()->stride(), 32u); } TEST_F(ParserImplTest, TypeDecl_Array_Decoration_MissingArray) { diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 2428187784..f8cd1fc74b 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -421,8 +421,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { auto* ary = type->As(); for (auto* deco : ary->decorations()) { - if (deco->IsStride()) { - out_ << "[[stride(" << deco->AsStride()->stride() << ")]] "; + if (auto* stride = deco->As()) { + out_ << "[[stride(" << stride->stride() << ")]] "; } }