mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
Replace VariableDecoration::(Is|As)Location with Castable
Change-Id: I3096045fc093f3782401ce8623a18e0bca49b22c Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34309 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
|
||||
#include "src/ast/binding_decoration.h"
|
||||
|
||||
#include "src/ast/test_helper.h"
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
#include "src/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -34,7 +34,7 @@ TEST_F(BindingDecorationTest, Is) {
|
||||
EXPECT_TRUE(d->Is<BindingDecoration>());
|
||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
||||
EXPECT_FALSE(bd.IsLocation());
|
||||
EXPECT_FALSE(d->Is<LocationDecoration>());
|
||||
EXPECT_FALSE(bd.IsSet());
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ TEST_F(BuiltinDecorationTest, Is) {
|
||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||
EXPECT_TRUE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
||||
EXPECT_FALSE(bd.IsLocation());
|
||||
EXPECT_FALSE(d->Is<LocationDecoration>());
|
||||
EXPECT_FALSE(bd.IsSet());
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ TEST_F(ConstantIdDecorationTest, Is) {
|
||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_TRUE(d->Is<ConstantIdDecoration>());
|
||||
EXPECT_FALSE(cd.IsLocation());
|
||||
EXPECT_FALSE(d->Is<LocationDecoration>());
|
||||
EXPECT_FALSE(cd.IsSet());
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "src/ast/builtin_decoration.h"
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
#include "src/ast/location_decoration.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -33,7 +34,7 @@ DecoratedVariable::~DecoratedVariable() = default;
|
||||
|
||||
bool DecoratedVariable::HasLocationDecoration() const {
|
||||
for (auto* deco : decorations_) {
|
||||
if (deco->IsLocation()) {
|
||||
if (deco->Is<LocationDecoration>()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ Function::referenced_location_variables() const {
|
||||
continue;
|
||||
}
|
||||
for (auto* deco : var->AsDecorated()->decorations()) {
|
||||
if (deco->IsLocation()) {
|
||||
ret.push_back({var, deco->AsLocation()});
|
||||
if (auto* location = deco->As<LocationDecoration>()) {
|
||||
ret.push_back({var, location});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,6 @@ LocationDecoration::LocationDecoration(uint32_t val, const Source& source)
|
||||
|
||||
LocationDecoration::~LocationDecoration() = default;
|
||||
|
||||
bool LocationDecoration::IsLocation() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void LocationDecoration::to_str(std::ostream& out, size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "LocationDecoration{" << value_ << "}" << std::endl;
|
||||
|
||||
@@ -32,9 +32,6 @@ class LocationDecoration
|
||||
explicit LocationDecoration(uint32_t value, const Source& source);
|
||||
~LocationDecoration() override;
|
||||
|
||||
/// @returns true if this is a location decoration
|
||||
bool IsLocation() const override;
|
||||
|
||||
/// @returns the location value
|
||||
uint32_t value() const { return value_; }
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ TEST_F(LocationDecorationTest, Is) {
|
||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
||||
EXPECT_TRUE(ld.IsLocation());
|
||||
EXPECT_TRUE(d->Is<LocationDecoration>());
|
||||
EXPECT_FALSE(ld.IsSet());
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ TEST_F(SetDecorationTest, Is) {
|
||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
||||
EXPECT_FALSE(sd.IsLocation());
|
||||
EXPECT_FALSE(d->Is<LocationDecoration>());
|
||||
EXPECT_TRUE(sd.IsSet());
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "src/ast/location_decoration.h"
|
||||
#include "src/ast/set_decoration.h"
|
||||
|
||||
namespace tint {
|
||||
@@ -32,19 +31,10 @@ DecorationKind VariableDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool VariableDecoration::IsLocation() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VariableDecoration::IsSet() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
LocationDecoration* VariableDecoration::AsLocation() {
|
||||
assert(IsLocation());
|
||||
return static_cast<LocationDecoration*>(this);
|
||||
}
|
||||
|
||||
SetDecoration* VariableDecoration::AsSet() {
|
||||
assert(IsSet());
|
||||
return static_cast<SetDecoration*>(this);
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
class ConstantIdDecoration;
|
||||
class LocationDecoration;
|
||||
class SetDecoration;
|
||||
|
||||
/// A decoration attached to a variable
|
||||
@@ -40,13 +38,9 @@ class VariableDecoration : public Castable<VariableDecoration, Decoration> {
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @returns true if this is a location decoration
|
||||
virtual bool IsLocation() const;
|
||||
/// @returns true if this is a set decoration
|
||||
virtual bool IsSet() const;
|
||||
|
||||
/// @returns the decoration as a location decoration
|
||||
LocationDecoration* AsLocation();
|
||||
/// @returns the decoration as a set decoration
|
||||
SetDecoration* AsSet();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user