mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
Replace Variable::(Is|As)* with Castable
Change-Id: I7a49287af079d53cee095fa2243dd21757546b56 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34318 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -69,10 +69,6 @@ uint32_t DecoratedVariable::constant_id() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool DecoratedVariable::IsDecorated() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DecoratedVariable::IsValid() const {
|
||||
return Variable::IsValid();
|
||||
}
|
||||
|
||||
@@ -56,9 +56,6 @@ class DecoratedVariable : public Castable<DecoratedVariable, Variable> {
|
||||
/// |HasConstantIdDecoration| has been called first.
|
||||
uint32_t constant_id() const;
|
||||
|
||||
/// @returns true if this is a decorated variable
|
||||
bool IsDecorated() const override;
|
||||
|
||||
/// @returns true if the name and path are both present
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ TEST_F(DecoratedVariableTest, IsValid) {
|
||||
|
||||
TEST_F(DecoratedVariableTest, IsDecorated) {
|
||||
DecoratedVariable dv;
|
||||
EXPECT_TRUE(dv.IsDecorated());
|
||||
EXPECT_TRUE(dv.Is<ast::DecoratedVariable>());
|
||||
}
|
||||
|
||||
TEST_F(DecoratedVariableTest, to_str) {
|
||||
|
||||
@@ -85,13 +85,12 @@ Function::referenced_location_variables() const {
|
||||
std::vector<std::pair<Variable*, LocationDecoration*>> ret;
|
||||
|
||||
for (auto* var : referenced_module_variables()) {
|
||||
if (!var->IsDecorated()) {
|
||||
continue;
|
||||
}
|
||||
for (auto* deco : var->AsDecorated()->decorations()) {
|
||||
if (auto* location = deco->As<LocationDecoration>()) {
|
||||
ret.push_back({var, location});
|
||||
break;
|
||||
if (auto* decos = var->As<ast::DecoratedVariable>()) {
|
||||
for (auto* deco : decos->decorations()) {
|
||||
if (auto* location = deco->As<LocationDecoration>()) {
|
||||
ret.push_back({var, location});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,14 +102,14 @@ Function::referenced_uniform_variables() const {
|
||||
std::vector<std::pair<Variable*, Function::BindingInfo>> ret;
|
||||
|
||||
for (auto* var : referenced_module_variables()) {
|
||||
if (!var->IsDecorated() ||
|
||||
if (!var->Is<ast::DecoratedVariable>() ||
|
||||
var->storage_class() != ast::StorageClass::kUniform) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BindingDecoration* binding = nullptr;
|
||||
SetDecoration* set = nullptr;
|
||||
for (auto* deco : var->AsDecorated()->decorations()) {
|
||||
for (auto* deco : var->As<ast::DecoratedVariable>()->decorations()) {
|
||||
if (auto* b = deco->As<ast::BindingDecoration>()) {
|
||||
binding = b;
|
||||
} else if (auto* s = deco->As<ast::SetDecoration>()) {
|
||||
@@ -131,14 +130,14 @@ Function::referenced_storagebuffer_variables() const {
|
||||
std::vector<std::pair<Variable*, Function::BindingInfo>> ret;
|
||||
|
||||
for (auto* var : referenced_module_variables()) {
|
||||
if (!var->IsDecorated() ||
|
||||
if (!var->Is<ast::DecoratedVariable>() ||
|
||||
var->storage_class() != ast::StorageClass::kStorageBuffer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BindingDecoration* binding = nullptr;
|
||||
SetDecoration* set = nullptr;
|
||||
for (auto* deco : var->AsDecorated()->decorations()) {
|
||||
for (auto* deco : var->As<ast::DecoratedVariable>()->decorations()) {
|
||||
if (auto* b = deco->As<ast::BindingDecoration>()) {
|
||||
binding = b;
|
||||
} else if (auto* s = deco->As<ast::SetDecoration>()) {
|
||||
@@ -159,10 +158,10 @@ Function::referenced_builtin_variables() const {
|
||||
std::vector<std::pair<Variable*, BuiltinDecoration*>> ret;
|
||||
|
||||
for (auto* var : referenced_module_variables()) {
|
||||
if (!var->IsDecorated()) {
|
||||
if (!var->Is<ast::DecoratedVariable>()) {
|
||||
continue;
|
||||
}
|
||||
for (auto* deco : var->AsDecorated()->decorations()) {
|
||||
for (auto* deco : var->As<ast::DecoratedVariable>()->decorations()) {
|
||||
if (auto* builtin = deco->As<BuiltinDecoration>()) {
|
||||
ret.push_back({var, builtin});
|
||||
break;
|
||||
@@ -283,14 +282,15 @@ Function::ReferencedSamplerVariablesImpl(type::SamplerKind kind) const {
|
||||
|
||||
for (auto* var : referenced_module_variables()) {
|
||||
auto* unwrapped_type = var->type()->UnwrapIfNeeded();
|
||||
if (!var->IsDecorated() || !unwrapped_type->Is<ast::type::SamplerType>() ||
|
||||
if (!var->Is<ast::DecoratedVariable>() ||
|
||||
!unwrapped_type->Is<ast::type::SamplerType>() ||
|
||||
unwrapped_type->As<ast::type::SamplerType>()->kind() != kind) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BindingDecoration* binding = nullptr;
|
||||
SetDecoration* set = nullptr;
|
||||
for (auto* deco : var->AsDecorated()->decorations()) {
|
||||
for (auto* deco : var->As<ast::DecoratedVariable>()->decorations()) {
|
||||
if (auto* b = deco->As<ast::BindingDecoration>()) {
|
||||
binding = b;
|
||||
} else if (auto* s = deco->As<ast::SetDecoration>()) {
|
||||
@@ -312,7 +312,8 @@ Function::ReferencedSampledTextureVariablesImpl(bool multisampled) const {
|
||||
|
||||
for (auto* var : referenced_module_variables()) {
|
||||
auto* unwrapped_type = var->type()->UnwrapIfNeeded();
|
||||
if (!var->IsDecorated() || !unwrapped_type->Is<ast::type::TextureType>()) {
|
||||
if (!var->Is<ast::DecoratedVariable>() ||
|
||||
!unwrapped_type->Is<ast::type::TextureType>()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -325,7 +326,7 @@ Function::ReferencedSampledTextureVariablesImpl(bool multisampled) const {
|
||||
|
||||
BindingDecoration* binding = nullptr;
|
||||
SetDecoration* set = nullptr;
|
||||
for (auto* deco : var->AsDecorated()->decorations()) {
|
||||
for (auto* deco : var->As<ast::DecoratedVariable>()->decorations()) {
|
||||
if (auto* b = deco->As<ast::BindingDecoration>()) {
|
||||
binding = b;
|
||||
} else if (auto* s = deco->As<ast::SetDecoration>()) {
|
||||
|
||||
@@ -36,20 +36,6 @@ Variable::Variable(Variable&&) = default;
|
||||
|
||||
Variable::~Variable() = default;
|
||||
|
||||
DecoratedVariable* Variable::AsDecorated() {
|
||||
assert(IsDecorated());
|
||||
return static_cast<DecoratedVariable*>(this);
|
||||
}
|
||||
|
||||
const DecoratedVariable* Variable::AsDecorated() const {
|
||||
assert(IsDecorated());
|
||||
return static_cast<const DecoratedVariable*>(this);
|
||||
}
|
||||
|
||||
bool Variable::IsDecorated() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Variable::IsValid() const {
|
||||
if (name_.length() == 0) {
|
||||
return false;
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
class DecoratedVariable;
|
||||
|
||||
/// A Variable statement.
|
||||
///
|
||||
/// An instance of this class represents one of three constructs in WGSL: "var"
|
||||
@@ -134,14 +132,6 @@ class Variable : public Castable<Variable, Node> {
|
||||
/// @returns true if this is a constant, false otherwise
|
||||
bool is_const() const { return is_const_; }
|
||||
|
||||
/// @returns true if this is a decorated variable
|
||||
virtual bool IsDecorated() const;
|
||||
|
||||
/// @returns the expression as a decorated variable
|
||||
DecoratedVariable* AsDecorated();
|
||||
/// @returns the expression as a decorated variable
|
||||
const DecoratedVariable* AsDecorated() const;
|
||||
|
||||
/// @returns true if the name and path are both present
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user