mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 08:57:26 +00:00
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:
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include "src/ast/struct.h"
|
#include "src/ast/struct.h"
|
||||||
|
|
||||||
|
#include "src/ast/struct_block_decoration.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
@@ -52,7 +54,7 @@ StructMember* Struct::get_member(const std::string& name) const {
|
|||||||
|
|
||||||
bool Struct::IsBlockDecorated() const {
|
bool Struct::IsBlockDecorated() const {
|
||||||
for (auto* deco : decorations_) {
|
for (auto* deco : decorations_) {
|
||||||
if (deco->IsBlock()) {
|
if (deco->Is<StructBlockDecoration>()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ StructBlockDecoration::StructBlockDecoration(const Source& source)
|
|||||||
|
|
||||||
StructBlockDecoration::~StructBlockDecoration() = default;
|
StructBlockDecoration::~StructBlockDecoration() = default;
|
||||||
|
|
||||||
bool StructBlockDecoration::IsBlock() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void StructBlockDecoration::to_str(std::ostream& out, size_t indent) const {
|
void StructBlockDecoration::to_str(std::ostream& out, size_t indent) const {
|
||||||
make_indent(out, indent);
|
make_indent(out, indent);
|
||||||
out << "block";
|
out << "block";
|
||||||
|
|||||||
@@ -33,9 +33,6 @@ class StructBlockDecoration
|
|||||||
explicit StructBlockDecoration(const Source& source);
|
explicit StructBlockDecoration(const Source& source);
|
||||||
~StructBlockDecoration() override;
|
~StructBlockDecoration() override;
|
||||||
|
|
||||||
/// @returns true if this is a block struct
|
|
||||||
bool IsBlock() const override;
|
|
||||||
|
|
||||||
/// Outputs the decoration to the given stream
|
/// Outputs the decoration to the given stream
|
||||||
/// @param out the stream to write to
|
/// @param out the stream to write to
|
||||||
/// @param indent number of spaces to indent the node when writing
|
/// @param indent number of spaces to indent the node when writing
|
||||||
|
|||||||
@@ -35,9 +35,6 @@ class StructDecoration : public Castable<StructDecoration, Decoration> {
|
|||||||
/// @return the decoration kind
|
/// @return the decoration kind
|
||||||
DecorationKind GetKind() const override;
|
DecorationKind GetKind() const override;
|
||||||
|
|
||||||
/// @returns true if this is a block struct
|
|
||||||
virtual bool IsBlock() const = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the source of this decoration
|
/// @param source the source of this decoration
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ TEST_F(StructTest, Creation_WithDecorations) {
|
|||||||
Struct s{decos, members};
|
Struct s{decos, members};
|
||||||
EXPECT_EQ(s.members().size(), 1u);
|
EXPECT_EQ(s.members().size(), 1u);
|
||||||
ASSERT_EQ(s.decorations().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.line, 0u);
|
||||||
EXPECT_EQ(s.source().range.begin.column, 0u);
|
EXPECT_EQ(s.source().range.begin.column, 0u);
|
||||||
EXPECT_EQ(s.source().range.end.line, 0u);
|
EXPECT_EQ(s.source().range.end.line, 0u);
|
||||||
@@ -79,7 +79,7 @@ TEST_F(StructTest, CreationWithSourceAndDecorations) {
|
|||||||
decos, members};
|
decos, members};
|
||||||
EXPECT_EQ(s.members().size(), 1u);
|
EXPECT_EQ(s.members().size(), 1u);
|
||||||
ASSERT_EQ(s.decorations().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.line, 27u);
|
||||||
EXPECT_EQ(s.source().range.begin.column, 4u);
|
EXPECT_EQ(s.source().range.begin.column, 4u);
|
||||||
EXPECT_EQ(s.source().range.end.line, 27u);
|
EXPECT_EQ(s.source().range.end.line, 27u);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "src/ast/struct_block_decoration.h"
|
||||||
#include "src/ast/type/struct_type.h"
|
#include "src/ast/type/struct_type.h"
|
||||||
#include "src/reader/wgsl/parser_impl.h"
|
#include "src/reader/wgsl/parser_impl.h"
|
||||||
#include "src/reader/wgsl/parser_impl_test_helper.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()[0]->name(), "a");
|
||||||
EXPECT_EQ(s->impl()->members()[1]->name(), "b");
|
EXPECT_EQ(s->impl()->members()[1]->name(), "b");
|
||||||
ASSERT_EQ(s->impl()->decorations().size(), 1u);
|
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) {
|
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()[0]->name(), "a");
|
||||||
EXPECT_EQ(s->impl()->members()[1]->name(), "b");
|
EXPECT_EQ(s->impl()->members()[1]->name(), "b");
|
||||||
ASSERT_EQ(s->impl()->decorations().size(), 2u);
|
ASSERT_EQ(s->impl()->decorations().size(), 2u);
|
||||||
EXPECT_TRUE(s->impl()->decorations()[0]->IsBlock());
|
EXPECT_TRUE(s->impl()->decorations()[0]->Is<ast::StructBlockDecoration>());
|
||||||
EXPECT_TRUE(s->impl()->decorations()[1]->IsBlock());
|
EXPECT_TRUE(s->impl()->decorations()[1]->Is<ast::StructBlockDecoration>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, StructDecl_EmptyMembers) {
|
TEST_F(ParserImplTest, StructDecl_EmptyMembers) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "src/ast/struct_block_decoration.h"
|
||||||
#include "src/reader/wgsl/parser_impl.h"
|
#include "src/reader/wgsl/parser_impl.h"
|
||||||
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
||||||
|
|
||||||
@@ -29,7 +30,7 @@ TEST_F(ParserImplTest, StructDecorationDecl_Parses) {
|
|||||||
EXPECT_TRUE(decos.matched);
|
EXPECT_TRUE(decos.matched);
|
||||||
ASSERT_EQ(decos.value.size(), 1u);
|
ASSERT_EQ(decos.value.size(), 1u);
|
||||||
auto* struct_deco = decos.value[0]->As<ast::StructDecoration>();
|
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) {
|
TEST_F(ParserImplTest, StructDecorationDecl_MissingAttrRight) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "src/ast/struct_block_decoration.h"
|
||||||
#include "src/ast/struct_decoration.h"
|
#include "src/ast/struct_decoration.h"
|
||||||
#include "src/reader/wgsl/parser_impl.h"
|
#include "src/reader/wgsl/parser_impl.h"
|
||||||
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
||||||
@@ -45,7 +46,7 @@ TEST_P(StructDecorationTest, Parses) {
|
|||||||
ASSERT_NE(deco.value, nullptr);
|
ASSERT_NE(deco.value, nullptr);
|
||||||
auto* struct_deco = deco.value->As<ast::StructDecoration>();
|
auto* struct_deco = deco.value->As<ast::StructDecoration>();
|
||||||
ASSERT_NE(struct_deco, nullptr);
|
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,
|
INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||||
StructDecorationTest,
|
StructDecorationTest,
|
||||||
|
|||||||
Reference in New Issue
Block a user