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>
This commit is contained in:
parent
3958f81fd7
commit
864579db3d
|
@ -31,14 +31,5 @@ DecorationKind ArrayDecoration::GetKind() const {
|
|||
return Kind;
|
||||
}
|
||||
|
||||
bool ArrayDecoration::IsStride() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
StrideDecoration* ArrayDecoration::AsStride() {
|
||||
assert(IsStride());
|
||||
return static_cast<StrideDecoration*>(this);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
|
|
@ -37,12 +37,6 @@ class ArrayDecoration : public Castable<ArrayDecoration, Decoration> {
|
|||
/// @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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -33,9 +33,6 @@ class StrideDecoration : public Castable<StrideDecoration, ArrayDecoration> {
|
|||
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_; }
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ TEST_F(StrideDecorationTest, Creation) {
|
|||
|
||||
TEST_F(StrideDecorationTest, Is) {
|
||||
StrideDecoration d{2, Source{}};
|
||||
EXPECT_TRUE(d.IsStride());
|
||||
EXPECT_TRUE(d.Is<StrideDecoration>());
|
||||
}
|
||||
|
||||
TEST_F(StrideDecorationTest, Source) {
|
||||
|
|
|
@ -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<ast::StrideDecoration>()) {
|
||||
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<ast::StrideDecoration>()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<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 @@ 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<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) {
|
||||
|
|
|
@ -421,8 +421,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
|||
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() << ")]] ";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue