Replace VariableDecoration::(Is|As)ConstantId with Castable
Change-Id: I3f402fe8925ef7d5c9b3d5b21f2556d7af59a0cd Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34308 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
c0eb9aeafb
commit
0482b54782
|
@ -15,6 +15,7 @@
|
|||
#include "src/ast/binding_decoration.h"
|
||||
|
||||
#include "src/ast/test_helper.h"
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -32,7 +33,7 @@ TEST_F(BindingDecorationTest, Is) {
|
|||
Decoration* d = &bd;
|
||||
EXPECT_TRUE(d->Is<BindingDecoration>());
|
||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_FALSE(bd.IsConstantId());
|
||||
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
||||
EXPECT_FALSE(bd.IsLocation());
|
||||
EXPECT_FALSE(bd.IsSet());
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "src/ast/builtin_decoration.h"
|
||||
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
#include "src/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -32,7 +33,7 @@ TEST_F(BuiltinDecorationTest, Is) {
|
|||
Decoration* d = &bd;
|
||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||
EXPECT_TRUE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_FALSE(bd.IsConstantId());
|
||||
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
||||
EXPECT_FALSE(bd.IsLocation());
|
||||
EXPECT_FALSE(bd.IsSet());
|
||||
}
|
||||
|
|
|
@ -22,10 +22,6 @@ ConstantIdDecoration::ConstantIdDecoration(uint32_t val, const Source& source)
|
|||
|
||||
ConstantIdDecoration::~ConstantIdDecoration() = default;
|
||||
|
||||
bool ConstantIdDecoration::IsConstantId() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConstantIdDecoration::to_str(std::ostream& out, size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "ConstantIdDecoration{" << value_ << "}" << std::endl;
|
||||
|
|
|
@ -31,9 +31,6 @@ class ConstantIdDecoration
|
|||
ConstantIdDecoration(uint32_t val, const Source& source);
|
||||
~ConstantIdDecoration() override;
|
||||
|
||||
/// @returns true if this is a constant_id decoration
|
||||
bool IsConstantId() const override;
|
||||
|
||||
/// @returns the constant id value
|
||||
uint32_t value() const { return value_; }
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ TEST_F(ConstantIdDecorationTest, Is) {
|
|||
Decoration* d = &cd;
|
||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_TRUE(cd.IsConstantId());
|
||||
EXPECT_TRUE(d->Is<ConstantIdDecoration>());
|
||||
EXPECT_FALSE(cd.IsLocation());
|
||||
EXPECT_FALSE(cd.IsSet());
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ bool DecoratedVariable::HasBuiltinDecoration() const {
|
|||
|
||||
bool DecoratedVariable::HasConstantIdDecoration() const {
|
||||
for (auto* deco : decorations_) {
|
||||
if (deco->IsConstantId()) {
|
||||
if (deco->Is<ConstantIdDecoration>()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -61,8 +61,8 @@ bool DecoratedVariable::HasConstantIdDecoration() const {
|
|||
uint32_t DecoratedVariable::constant_id() const {
|
||||
assert(HasConstantIdDecoration());
|
||||
for (auto* deco : decorations_) {
|
||||
if (deco->IsConstantId()) {
|
||||
return deco->AsConstantId()->value();
|
||||
if (auto* cid = deco->As<ConstantIdDecoration>()) {
|
||||
return cid->value();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <sstream>
|
||||
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
#include "src/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -34,7 +35,7 @@ TEST_F(LocationDecorationTest, Is) {
|
|||
Decoration* d = &ld;
|
||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_FALSE(ld.IsConstantId());
|
||||
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
||||
EXPECT_TRUE(ld.IsLocation());
|
||||
EXPECT_FALSE(ld.IsSet());
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "src/ast/set_decoration.h"
|
||||
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
#include "src/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -32,7 +33,7 @@ TEST_F(SetDecorationTest, Is) {
|
|||
Decoration* d = &sd;
|
||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||
EXPECT_FALSE(sd.IsConstantId());
|
||||
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
||||
EXPECT_FALSE(sd.IsLocation());
|
||||
EXPECT_TRUE(sd.IsSet());
|
||||
}
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
|
||||
#include <assert.h>
|
||||
|
||||
#include "src/ast/binding_decoration.h"
|
||||
#include "src/ast/builtin_decoration.h"
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
#include "src/ast/location_decoration.h"
|
||||
#include "src/ast/set_decoration.h"
|
||||
|
||||
|
@ -39,19 +36,10 @@ bool VariableDecoration::IsLocation() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool VariableDecoration::IsConstantId() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VariableDecoration::IsSet() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
ConstantIdDecoration* VariableDecoration::AsConstantId() {
|
||||
assert(IsConstantId());
|
||||
return static_cast<ConstantIdDecoration*>(this);
|
||||
}
|
||||
|
||||
LocationDecoration* VariableDecoration::AsLocation() {
|
||||
assert(IsLocation());
|
||||
return static_cast<LocationDecoration*>(this);
|
||||
|
|
|
@ -40,15 +40,11 @@ class VariableDecoration : public Castable<VariableDecoration, Decoration> {
|
|||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @returns true if this is a constant id decoration
|
||||
virtual bool IsConstantId() const;
|
||||
/// @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 constant id decoration
|
||||
ConstantIdDecoration* AsConstantId();
|
||||
/// @returns the decoration as a location decoration
|
||||
LocationDecoration* AsLocation();
|
||||
/// @returns the decoration as a set decoration
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "src/ast/call_expression.h"
|
||||
#include "src/ast/call_statement.h"
|
||||
#include "src/ast/case_statement.h"
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
#include "src/ast/constructor_expression.h"
|
||||
#include "src/ast/decorated_variable.h"
|
||||
#include "src/ast/else_statement.h"
|
||||
|
@ -796,7 +797,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
|
|||
spv::Op::OpDecorate,
|
||||
{Operand::Int(var_id), Operand::Int(SpvDecorationDescriptorSet),
|
||||
Operand::Int(deco->AsSet()->value())});
|
||||
} else if (deco->IsConstantId()) {
|
||||
} else if (deco->Is<ast::ConstantIdDecoration>()) {
|
||||
// Spec constants are handled elsewhere
|
||||
} else {
|
||||
error_ = "unknown decoration";
|
||||
|
|
|
@ -649,8 +649,8 @@ bool GeneratorImpl::EmitVariableDecorations(ast::DecoratedVariable* var) {
|
|||
out_ << "location(" << deco->AsLocation()->value() << ")";
|
||||
} else if (auto* builtin = deco->As<ast::BuiltinDecoration>()) {
|
||||
out_ << "builtin(" << builtin->value() << ")";
|
||||
} else if (deco->IsConstantId()) {
|
||||
out_ << "constant_id(" << deco->AsConstantId()->value() << ")";
|
||||
} else if (auto* cid = deco->As<ast::ConstantIdDecoration>()) {
|
||||
out_ << "constant_id(" << cid->value() << ")";
|
||||
} else {
|
||||
error_ = "unknown variable decoration";
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue