From 864579db3dd4077df4e698e621e767354bb75ad3 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 30 Nov 2020 23:30:58 +0000 Subject: [PATCH] Replace ArrayDecoration::(Is|As)Stride with Castable Change-Id: I0a346226996c86a6f976b51f69ae4df32806a797 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34305 Reviewed-by: dan sinclair --- src/ast/array_decoration.cc | 9 --------- src/ast/array_decoration.h | 6 ------ src/ast/stride_decoration.cc | 4 ---- src/ast/stride_decoration.h | 3 --- src/ast/stride_decoration_test.cc | 2 +- src/ast/type/array_type.cc | 6 +++--- src/reader/wgsl/parser_impl_type_decl_test.cc | 16 ++++++++-------- src/writer/wgsl/generator_impl.cc | 4 ++-- 8 files changed, 14 insertions(+), 36 deletions(-) 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() << ")]] "; } }