Convert @location to store expression internally.

This CL updates the internal storage for a `@location` attribute
to store the `Expression` instead of a raw `uint32_t`. The current
parser is updated to generate an `IntLiteralExpression` so we still
parse as a `uint32_t` at the moment.

Bug: tint:1633
Change-Id: I2b9684754a657b39554160c81727cf1541bee96c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/101461
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair
2022-09-07 22:25:24 +00:00
committed by Dawn LUCI CQ
parent 145337f309
commit f9eeed6106
41 changed files with 387 additions and 249 deletions

View File

@@ -22,7 +22,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::LocationAttribute);
namespace tint::ast {
LocationAttribute::LocationAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t val)
LocationAttribute::LocationAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* val)
: Base(pid, nid, src), value(val) {}
LocationAttribute::~LocationAttribute() = default;
@@ -34,7 +37,8 @@ std::string LocationAttribute::Name() const {
const LocationAttribute* LocationAttribute::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);
return ctx->dst->create<LocationAttribute>(src, value);
auto value_ = ctx->Clone(value);
return ctx->dst->create<LocationAttribute>(src, value_);
}
} // namespace tint::ast

View File

@@ -18,6 +18,7 @@
#include <string>
#include "src/tint/ast/attribute.h"
#include "src/tint/ast/expression.h"
namespace tint::ast {
@@ -28,8 +29,8 @@ class LocationAttribute final : public Castable<LocationAttribute, Attribute> {
/// @param pid the identifier of the program that owns this node
/// @param nid the unique node identifier
/// @param src the source of this node
/// @param value the location value
LocationAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t value);
/// @param value the location value expression
LocationAttribute(ProgramID pid, NodeID nid, const Source& src, const ast::Expression* value);
~LocationAttribute() override;
/// @returns the WGSL name for the attribute
@@ -42,7 +43,7 @@ class LocationAttribute final : public Castable<LocationAttribute, Attribute> {
const LocationAttribute* Clone(CloneContext* ctx) const override;
/// The location value
const uint32_t value;
const ast::Expression* const value;
};
} // namespace tint::ast

View File

@@ -17,11 +17,12 @@
namespace tint::ast {
namespace {
using namespace tint::number_suffixes; // NOLINT
using LocationAttributeTest = TestHelper;
TEST_F(LocationAttributeTest, Creation) {
auto* d = create<LocationAttribute>(2u);
EXPECT_EQ(2u, d->value);
auto* d = Location(2_a);
EXPECT_TRUE(d->value->Is<IntLiteralExpression>());
}
} // namespace

View File

@@ -92,7 +92,7 @@ TEST_F(VariableTest, Assert_DifferentProgramID_Constructor) {
}
TEST_F(VariableTest, WithAttributes) {
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Location(1u),
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Location(1_u),
Builtin(BuiltinValue::kPosition), Id(1200_u));
auto& attributes = var->attributes;
@@ -102,7 +102,8 @@ TEST_F(VariableTest, WithAttributes) {
auto* location = ast::GetAttribute<ast::LocationAttribute>(attributes);
ASSERT_NE(nullptr, location);
EXPECT_EQ(1u, location->value);
ASSERT_NE(nullptr, location->value);
EXPECT_TRUE(location->value->Is<ast::IntLiteralExpression>());
}
TEST_F(VariableTest, HasBindingPoint_BothProvided) {