mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
Replace VariableDecoration::(Is|As)Builtin with Castable
Change-Id: I49d970301c46cfe29d7b22e18abb443daa0c8073 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34307 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -28,12 +28,13 @@ TEST_F(BindingDecorationTest, Creation) {
|
||||
}
|
||||
|
||||
TEST_F(BindingDecorationTest, Is) {
|
||||
BindingDecoration d{2, Source{}};
|
||||
EXPECT_TRUE(d.Is<BindingDecoration>());
|
||||
EXPECT_FALSE(d.IsBuiltin());
|
||||
EXPECT_FALSE(d.IsConstantId());
|
||||
EXPECT_FALSE(d.IsLocation());
|
||||
EXPECT_FALSE(d.IsSet());
|
||||
BindingDecoration bd{2, Source{}};
|
||||
Decoration* d = &bd;
|
||||
EXPECT_TRUE(d->Is<BindingDecoration>());
|
||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_FALSE(bd.IsConstantId());
|
||||
EXPECT_FALSE(bd.IsLocation());
|
||||
EXPECT_FALSE(bd.IsSet());
|
||||
}
|
||||
|
||||
TEST_F(BindingDecorationTest, ToStr) {
|
||||
|
||||
@@ -22,10 +22,6 @@ BuiltinDecoration::BuiltinDecoration(Builtin builtin, const Source& source)
|
||||
|
||||
BuiltinDecoration::~BuiltinDecoration() = default;
|
||||
|
||||
bool BuiltinDecoration::IsBuiltin() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void BuiltinDecoration::to_str(std::ostream& out, size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "BuiltinDecoration{" << builtin_ << "}" << std::endl;
|
||||
|
||||
@@ -31,9 +31,6 @@ class BuiltinDecoration
|
||||
BuiltinDecoration(Builtin builtin, const Source& source);
|
||||
~BuiltinDecoration() override;
|
||||
|
||||
/// @returns true if this is a builtin decoration
|
||||
bool IsBuiltin() const override;
|
||||
|
||||
/// @returns the builtin value
|
||||
Builtin value() const { return builtin_; }
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ TEST_F(BuiltinDecorationTest, Is) {
|
||||
BuiltinDecoration bd{Builtin::kFragDepth, Source{}};
|
||||
Decoration* d = &bd;
|
||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||
EXPECT_TRUE(bd.IsBuiltin());
|
||||
EXPECT_TRUE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_FALSE(bd.IsConstantId());
|
||||
EXPECT_FALSE(bd.IsLocation());
|
||||
EXPECT_FALSE(bd.IsSet());
|
||||
|
||||
@@ -31,7 +31,7 @@ TEST_F(ConstantIdDecorationTest, Is) {
|
||||
ConstantIdDecoration cd{27, Source{}};
|
||||
Decoration* d = &cd;
|
||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||
EXPECT_FALSE(cd.IsBuiltin());
|
||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_TRUE(cd.IsConstantId());
|
||||
EXPECT_FALSE(cd.IsLocation());
|
||||
EXPECT_FALSE(cd.IsSet());
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "src/ast/builtin_decoration.h"
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
|
||||
namespace tint {
|
||||
@@ -41,7 +42,7 @@ bool DecoratedVariable::HasLocationDecoration() const {
|
||||
|
||||
bool DecoratedVariable::HasBuiltinDecoration() const {
|
||||
for (auto* deco : decorations_) {
|
||||
if (deco->IsBuiltin()) {
|
||||
if (deco->Is<BuiltinDecoration>()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,8 +163,8 @@ Function::referenced_builtin_variables() const {
|
||||
continue;
|
||||
}
|
||||
for (auto* deco : var->AsDecorated()->decorations()) {
|
||||
if (deco->IsBuiltin()) {
|
||||
ret.push_back({var, deco->AsBuiltin()});
|
||||
if (auto* builtin = deco->As<BuiltinDecoration>()) {
|
||||
ret.push_back({var, builtin});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ TEST_F(LocationDecorationTest, Is) {
|
||||
LocationDecoration ld{2, Source{}};
|
||||
Decoration* d = &ld;
|
||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||
EXPECT_FALSE(ld.IsBuiltin());
|
||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_FALSE(ld.IsConstantId());
|
||||
EXPECT_TRUE(ld.IsLocation());
|
||||
EXPECT_FALSE(ld.IsSet());
|
||||
|
||||
@@ -31,7 +31,7 @@ TEST_F(SetDecorationTest, Is) {
|
||||
SetDecoration sd{2, Source{}};
|
||||
Decoration* d = &sd;
|
||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||
EXPECT_FALSE(sd.IsBuiltin());
|
||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_FALSE(sd.IsConstantId());
|
||||
EXPECT_FALSE(sd.IsLocation());
|
||||
EXPECT_TRUE(sd.IsSet());
|
||||
|
||||
@@ -35,10 +35,6 @@ DecorationKind VariableDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool VariableDecoration::IsBuiltin() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VariableDecoration::IsLocation() const {
|
||||
return false;
|
||||
}
|
||||
@@ -51,11 +47,6 @@ bool VariableDecoration::IsSet() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
BuiltinDecoration* VariableDecoration::AsBuiltin() {
|
||||
assert(IsBuiltin());
|
||||
return static_cast<BuiltinDecoration*>(this);
|
||||
}
|
||||
|
||||
ConstantIdDecoration* VariableDecoration::AsConstantId() {
|
||||
assert(IsConstantId());
|
||||
return static_cast<ConstantIdDecoration*>(this);
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
class BuiltinDecoration;
|
||||
class ConstantIdDecoration;
|
||||
class LocationDecoration;
|
||||
class SetDecoration;
|
||||
@@ -41,8 +40,6 @@ class VariableDecoration : public Castable<VariableDecoration, Decoration> {
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @returns true if this is a builtin decoration
|
||||
virtual bool IsBuiltin() const;
|
||||
/// @returns true if this is a constant id decoration
|
||||
virtual bool IsConstantId() const;
|
||||
/// @returns true if this is a location decoration
|
||||
@@ -50,8 +47,6 @@ class VariableDecoration : public Castable<VariableDecoration, Decoration> {
|
||||
/// @returns true if this is a set decoration
|
||||
virtual bool IsSet() const;
|
||||
|
||||
/// @returns the decoration as a builtin decoration
|
||||
BuiltinDecoration* AsBuiltin();
|
||||
/// @returns the decoration as a constant id decoration
|
||||
ConstantIdDecoration* AsConstantId();
|
||||
/// @returns the decoration as a location decoration
|
||||
|
||||
Reference in New Issue
Block a user