Replace ArrayDecoration::(Is|As)Stride with Castable
Change-Id: I0a346226996c86a6f976b51f69ae4df32806a797
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34305
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/ast/array_decoration.cc b/src/ast/array_decoration.cc
index 62338b2..2bdefd4 100644
--- a/src/ast/array_decoration.cc
+++ b/src/ast/array_decoration.cc
@@ -31,14 +31,5 @@
return Kind;
}
-bool ArrayDecoration::IsStride() const {
- return false;
-}
-
-StrideDecoration* ArrayDecoration::AsStride() {
- assert(IsStride());
- return static_cast<StrideDecoration*>(this);
-}
-
} // namespace ast
} // namespace tint
diff --git a/src/ast/array_decoration.h b/src/ast/array_decoration.h
index 43141a0..5473385 100644
--- a/src/ast/array_decoration.h
+++ b/src/ast/array_decoration.h
@@ -37,12 +37,6 @@
/// @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 eea3053..6de4550 100644
--- a/src/ast/stride_decoration.cc
+++ b/src/ast/stride_decoration.cc
@@ -20,10 +20,6 @@
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 ac4fd37..e3abd4b 100644
--- a/src/ast/stride_decoration.h
+++ b/src/ast/stride_decoration.h
@@ -33,9 +33,6 @@
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 4a1088c..6b97255 100644
--- a/src/ast/stride_decoration_test.cc
+++ b/src/ast/stride_decoration_test.cc
@@ -29,7 +29,7 @@
TEST_F(StrideDecorationTest, Is) {
StrideDecoration d{2, Source{}};
- EXPECT_TRUE(d.IsStride());
+ EXPECT_TRUE(d.Is<StrideDecoration>());
}
TEST_F(StrideDecorationTest, Source) {
diff --git a/src/ast/type/array_type.cc b/src/ast/type/array_type.cc
index 4bdaf1b..d46fcc5 100644
--- a/src/ast/type/array_type.cc
+++ b/src/ast/type/array_type.cc
@@ -65,8 +65,8 @@
uint32_t ArrayType::array_stride() const {
for (auto* deco : decos_) {
- if (deco->IsStride()) {
- return deco->AsStride()->stride();
+ if (auto* stride = deco->As<ast::StrideDecoration>()) {
+ return stride->stride();
}
}
return 0;
@@ -74,7 +74,7 @@
bool ArrayType::has_array_stride() const {
for (auto* deco : decos_) {
- if (deco->IsStride()) {
+ if (deco->Is<ast::StrideDecoration>()) {
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 29c509c..e8a85f8 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 @@
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<ast::StrideDecoration>());
+ EXPECT_EQ(decos[0]->As<ast::StrideDecoration>()->stride(), 16u);
+ EXPECT_TRUE(decos[1]->Is<ast::StrideDecoration>());
+ EXPECT_EQ(decos[1]->As<ast::StrideDecoration>()->stride(), 32u);
}
TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_MultipleBlocks) {
@@ -429,10 +429,10 @@
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<ast::StrideDecoration>());
+ EXPECT_EQ(decos[0]->As<ast::StrideDecoration>()->stride(), 16u);
+ EXPECT_TRUE(decos[1]->Is<ast::StrideDecoration>());
+ EXPECT_EQ(decos[1]->As<ast::StrideDecoration>()->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 2428187..f8cd1fc 100644
--- a/src/writer/wgsl/generator_impl.cc
+++ b/src/writer/wgsl/generator_impl.cc
@@ -421,8 +421,8 @@
auto* ary = type->As<ast::type::ArrayType>();
for (auto* deco : ary->decorations()) {
- if (deco->IsStride()) {
- out_ << "[[stride(" << deco->AsStride()->stride() << ")]] ";
+ if (auto* stride = deco->As<ast::StrideDecoration>()) {
+ out_ << "[[stride(" << stride->stride() << ")]] ";
}
}