Replace VariableDecoration::(Is|As)Set with Castable
Change-Id: I9808e31f3842b70b3df9ed0398583e09e4f2ca42
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34310
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/ast/binding_decoration_test.cc b/src/ast/binding_decoration_test.cc
index 4111653..54e6f74 100644
--- a/src/ast/binding_decoration_test.cc
+++ b/src/ast/binding_decoration_test.cc
@@ -35,7 +35,7 @@
EXPECT_FALSE(d->Is<BuiltinDecoration>());
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
EXPECT_FALSE(d->Is<LocationDecoration>());
- EXPECT_FALSE(bd.IsSet());
+ EXPECT_FALSE(d->Is<SetDecoration>());
}
TEST_F(BindingDecorationTest, ToStr) {
diff --git a/src/ast/builtin_decoration_test.cc b/src/ast/builtin_decoration_test.cc
index 11e1b2d..3122651 100644
--- a/src/ast/builtin_decoration_test.cc
+++ b/src/ast/builtin_decoration_test.cc
@@ -35,7 +35,7 @@
EXPECT_TRUE(d->Is<BuiltinDecoration>());
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
EXPECT_FALSE(d->Is<LocationDecoration>());
- EXPECT_FALSE(bd.IsSet());
+ EXPECT_FALSE(d->Is<SetDecoration>());
}
TEST_F(BuiltinDecorationTest, ToStr) {
diff --git a/src/ast/constant_id_decoration_test.cc b/src/ast/constant_id_decoration_test.cc
index ece2385..28f77ee 100644
--- a/src/ast/constant_id_decoration_test.cc
+++ b/src/ast/constant_id_decoration_test.cc
@@ -34,7 +34,7 @@
EXPECT_FALSE(d->Is<BuiltinDecoration>());
EXPECT_TRUE(d->Is<ConstantIdDecoration>());
EXPECT_FALSE(d->Is<LocationDecoration>());
- EXPECT_FALSE(cd.IsSet());
+ EXPECT_FALSE(d->Is<SetDecoration>());
}
TEST_F(ConstantIdDecorationTest, ToStr) {
diff --git a/src/ast/location_decoration_test.cc b/src/ast/location_decoration_test.cc
index f8ffff8..f402abe 100644
--- a/src/ast/location_decoration_test.cc
+++ b/src/ast/location_decoration_test.cc
@@ -37,7 +37,7 @@
EXPECT_FALSE(d->Is<BuiltinDecoration>());
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
EXPECT_TRUE(d->Is<LocationDecoration>());
- EXPECT_FALSE(ld.IsSet());
+ EXPECT_FALSE(d->Is<SetDecoration>());
}
TEST_F(LocationDecorationTest, ToStr) {
diff --git a/src/ast/set_decoration.cc b/src/ast/set_decoration.cc
index 4178e4d..4d6a776 100644
--- a/src/ast/set_decoration.cc
+++ b/src/ast/set_decoration.cc
@@ -22,10 +22,6 @@
SetDecoration::~SetDecoration() = default;
-bool SetDecoration::IsSet() const {
- return true;
-}
-
void SetDecoration::to_str(std::ostream& out, size_t indent) const {
make_indent(out, indent);
out << "SetDecoration{" << value_ << "}" << std::endl;
diff --git a/src/ast/set_decoration.h b/src/ast/set_decoration.h
index 73469c4..9706f86 100644
--- a/src/ast/set_decoration.h
+++ b/src/ast/set_decoration.h
@@ -31,9 +31,6 @@
SetDecoration(uint32_t value, const Source& source);
~SetDecoration() override;
- /// @returns true if this is a set decoration
- bool IsSet() const override;
-
/// @returns the set value
uint32_t value() const { return value_; }
diff --git a/src/ast/set_decoration_test.cc b/src/ast/set_decoration_test.cc
index d9b9e79..088f3f0 100644
--- a/src/ast/set_decoration_test.cc
+++ b/src/ast/set_decoration_test.cc
@@ -35,7 +35,7 @@
EXPECT_FALSE(d->Is<BuiltinDecoration>());
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
EXPECT_FALSE(d->Is<LocationDecoration>());
- EXPECT_TRUE(sd.IsSet());
+ EXPECT_TRUE(d->Is<SetDecoration>());
}
TEST_F(SetDecorationTest, ToStr) {
diff --git a/src/ast/variable_decoration.cc b/src/ast/variable_decoration.cc
index 287300c..ea8d268 100644
--- a/src/ast/variable_decoration.cc
+++ b/src/ast/variable_decoration.cc
@@ -16,8 +16,6 @@
#include <assert.h>
-#include "src/ast/set_decoration.h"
-
namespace tint {
namespace ast {
@@ -31,14 +29,5 @@
return Kind;
}
-bool VariableDecoration::IsSet() const {
- return false;
-}
-
-SetDecoration* VariableDecoration::AsSet() {
- assert(IsSet());
- return static_cast<SetDecoration*>(this);
-}
-
} // namespace ast
} // namespace tint
diff --git a/src/ast/variable_decoration.h b/src/ast/variable_decoration.h
index 39206fb..72e18ad 100644
--- a/src/ast/variable_decoration.h
+++ b/src/ast/variable_decoration.h
@@ -25,8 +25,6 @@
namespace tint {
namespace ast {
-class SetDecoration;
-
/// A decoration attached to a variable
class VariableDecoration : public Castable<VariableDecoration, Decoration> {
public:
@@ -38,12 +36,6 @@
/// @return the decoration kind
DecorationKind GetKind() const override;
- /// @returns true if this is a set decoration
- virtual bool IsSet() const;
-
- /// @returns the decoration as a set decoration
- SetDecoration* AsSet();
-
protected:
/// Constructor
/// @param source the source of this decoration
diff --git a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc
index 8e8ddc3..80a5d30 100644
--- a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc
+++ b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc
@@ -105,7 +105,7 @@
auto& decorations = v->decorations();
ASSERT_EQ(decorations.size(), 2u);
ASSERT_TRUE(decorations[0]->Is<ast::BindingDecoration>());
- ASSERT_TRUE(decorations[1]->IsSet());
+ ASSERT_TRUE(decorations[1]->Is<ast::SetDecoration>());
}
TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration_MulitpleGroups) {
@@ -139,7 +139,7 @@
auto& decorations = v->decorations();
ASSERT_EQ(decorations.size(), 2u);
ASSERT_TRUE(decorations[0]->Is<ast::BindingDecoration>());
- ASSERT_TRUE(decorations[1]->IsSet());
+ ASSERT_TRUE(decorations[1]->Is<ast::SetDecoration>());
}
TEST_F(ParserImplTest, GlobalVariableDecl_InvalidDecoration) {
diff --git a/src/reader/wgsl/parser_impl_variable_decoration_test.cc b/src/reader/wgsl/parser_impl_variable_decoration_test.cc
index 60f1977..d6b9ac5 100644
--- a/src/reader/wgsl/parser_impl_variable_decoration_test.cc
+++ b/src/reader/wgsl/parser_impl_variable_decoration_test.cc
@@ -240,9 +240,9 @@
auto* var_deco = deco.value->As<ast::VariableDecoration>();
ASSERT_FALSE(p->has_error());
ASSERT_NE(var_deco, nullptr);
- ASSERT_TRUE(var_deco->IsSet());
+ ASSERT_TRUE(var_deco->Is<ast::SetDecoration>());
- auto* set = var_deco->AsSet();
+ auto* set = var_deco->As<ast::SetDecoration>();
EXPECT_EQ(set->value(), 4u);
}
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index 5b800a4..0c1c1d5 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -792,11 +792,11 @@
push_annot(spv::Op::OpDecorate,
{Operand::Int(var_id), Operand::Int(SpvDecorationBinding),
Operand::Int(binding->value())});
- } else if (deco->IsSet()) {
+ } else if (auto* set = deco->As<ast::SetDecoration>()) {
push_annot(
spv::Op::OpDecorate,
{Operand::Int(var_id), Operand::Int(SpvDecorationDescriptorSet),
- Operand::Int(deco->AsSet()->value())});
+ Operand::Int(set->value())});
} else if (deco->Is<ast::ConstantIdDecoration>()) {
// Spec constants are handled elsewhere
} else {
diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc
index 95a227f..e713aa6 100644
--- a/src/writer/wgsl/generator_impl.cc
+++ b/src/writer/wgsl/generator_impl.cc
@@ -643,8 +643,8 @@
if (auto* binding = deco->As<ast::BindingDecoration>()) {
out_ << "binding(" << binding->value() << ")";
- } else if (deco->IsSet()) {
- out_ << "set(" << deco->AsSet()->value() << ")";
+ } else if (auto* set = deco->As<ast::SetDecoration>()) {
+ out_ << "set(" << set->value() << ")";
} else if (auto* location = deco->As<ast::LocationDecoration>()) {
out_ << "location(" << location->value() << ")";
} else if (auto* builtin = deco->As<ast::BuiltinDecoration>()) {