Replace StructDecoration::IsBlock with Castable

Change-Id: I4b053aab610b18f99b72156f92317bc8eaf430b4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34313
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-30 23:30:58 +00:00
parent 731372f0b4
commit 8a82dcd977
8 changed files with 13 additions and 18 deletions

View File

@ -14,6 +14,8 @@
#include "src/ast/struct.h"
#include "src/ast/struct_block_decoration.h"
namespace tint {
namespace ast {
@ -52,7 +54,7 @@ StructMember* Struct::get_member(const std::string& name) const {
bool Struct::IsBlockDecorated() const {
for (auto* deco : decorations_) {
if (deco->IsBlock()) {
if (deco->Is<StructBlockDecoration>()) {
return true;
}
}

View File

@ -22,10 +22,6 @@ StructBlockDecoration::StructBlockDecoration(const Source& source)
StructBlockDecoration::~StructBlockDecoration() = default;
bool StructBlockDecoration::IsBlock() const {
return true;
}
void StructBlockDecoration::to_str(std::ostream& out, size_t indent) const {
make_indent(out, indent);
out << "block";

View File

@ -33,9 +33,6 @@ class StructBlockDecoration
explicit StructBlockDecoration(const Source& source);
~StructBlockDecoration() override;
/// @returns true if this is a block struct
bool IsBlock() const override;
/// Outputs the decoration to the given stream
/// @param out the stream to write to
/// @param indent number of spaces to indent the node when writing

View File

@ -35,9 +35,6 @@ class StructDecoration : public Castable<StructDecoration, Decoration> {
/// @return the decoration kind
DecorationKind GetKind() const override;
/// @returns true if this is a block struct
virtual bool IsBlock() const = 0;
protected:
/// Constructor
/// @param source the source of this decoration

View File

@ -57,7 +57,7 @@ TEST_F(StructTest, Creation_WithDecorations) {
Struct s{decos, members};
EXPECT_EQ(s.members().size(), 1u);
ASSERT_EQ(s.decorations().size(), 1u);
EXPECT_TRUE(s.decorations()[0]->IsBlock());
EXPECT_TRUE(s.decorations()[0]->Is<StructBlockDecoration>());
EXPECT_EQ(s.source().range.begin.line, 0u);
EXPECT_EQ(s.source().range.begin.column, 0u);
EXPECT_EQ(s.source().range.end.line, 0u);
@ -79,7 +79,7 @@ TEST_F(StructTest, CreationWithSourceAndDecorations) {
decos, members};
EXPECT_EQ(s.members().size(), 1u);
ASSERT_EQ(s.decorations().size(), 1u);
EXPECT_TRUE(s.decorations()[0]->IsBlock());
EXPECT_TRUE(s.decorations()[0]->Is<StructBlockDecoration>());
EXPECT_EQ(s.source().range.begin.line, 27u);
EXPECT_EQ(s.source().range.begin.column, 4u);
EXPECT_EQ(s.source().range.end.line, 27u);

View File

@ -13,6 +13,7 @@
// limitations under the License.
#include "gtest/gtest.h"
#include "src/ast/struct_block_decoration.h"
#include "src/ast/type/struct_type.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@ -65,7 +66,7 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) {
EXPECT_EQ(s->impl()->members()[0]->name(), "a");
EXPECT_EQ(s->impl()->members()[1]->name(), "b");
ASSERT_EQ(s->impl()->decorations().size(), 1u);
EXPECT_TRUE(s->impl()->decorations()[0]->IsBlock());
EXPECT_TRUE(s->impl()->decorations()[0]->Is<ast::StructBlockDecoration>());
}
TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) {
@ -90,8 +91,8 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) {
EXPECT_EQ(s->impl()->members()[0]->name(), "a");
EXPECT_EQ(s->impl()->members()[1]->name(), "b");
ASSERT_EQ(s->impl()->decorations().size(), 2u);
EXPECT_TRUE(s->impl()->decorations()[0]->IsBlock());
EXPECT_TRUE(s->impl()->decorations()[1]->IsBlock());
EXPECT_TRUE(s->impl()->decorations()[0]->Is<ast::StructBlockDecoration>());
EXPECT_TRUE(s->impl()->decorations()[1]->Is<ast::StructBlockDecoration>());
}
TEST_F(ParserImplTest, StructDecl_EmptyMembers) {

View File

@ -13,6 +13,7 @@
// limitations under the License.
#include "gtest/gtest.h"
#include "src/ast/struct_block_decoration.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@ -29,7 +30,7 @@ TEST_F(ParserImplTest, StructDecorationDecl_Parses) {
EXPECT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 1u);
auto* struct_deco = decos.value[0]->As<ast::StructDecoration>();
EXPECT_TRUE(struct_deco->IsBlock());
EXPECT_TRUE(struct_deco->Is<ast::StructBlockDecoration>());
}
TEST_F(ParserImplTest, StructDecorationDecl_MissingAttrRight) {

View File

@ -13,6 +13,7 @@
// limitations under the License.
#include "gtest/gtest.h"
#include "src/ast/struct_block_decoration.h"
#include "src/ast/struct_decoration.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@ -45,7 +46,7 @@ TEST_P(StructDecorationTest, Parses) {
ASSERT_NE(deco.value, nullptr);
auto* struct_deco = deco.value->As<ast::StructDecoration>();
ASSERT_NE(struct_deco, nullptr);
EXPECT_EQ(struct_deco->IsBlock(), params.is_block);
EXPECT_EQ(struct_deco->Is<ast::StructBlockDecoration>(), params.is_block);
}
INSTANTIATE_TEST_SUITE_P(ParserImplTest,
StructDecorationTest,