mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
Convert @id to an expression.
This CL updates the @id AST nodes to store an expression instead of a literal value. This is in anticipation of the parser updates for ID expressions. Bug: tint:1633 Change-Id: I4dd626007dd1f9093999a0236e220ffdbc9e62db Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100760 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
969692ccf8
commit
5361d9e778
@@ -22,7 +22,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IdAttribute);
|
||||
|
||||
namespace tint::ast {
|
||||
|
||||
IdAttribute::IdAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t val)
|
||||
IdAttribute::IdAttribute(ProgramID pid, NodeID nid, const Source& src, const ast::Expression* val)
|
||||
: Base(pid, nid, src), value(val) {}
|
||||
|
||||
IdAttribute::~IdAttribute() = default;
|
||||
@@ -34,7 +34,8 @@ std::string IdAttribute::Name() const {
|
||||
const IdAttribute* IdAttribute::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<IdAttribute>(src, value);
|
||||
auto* value_ = ctx->Clone(value);
|
||||
return ctx->dst->create<IdAttribute>(src, value_);
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -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 IdAttribute final : public Castable<IdAttribute, 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 val the numeric id value
|
||||
IdAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t val);
|
||||
/// @param val the numeric id value expression
|
||||
IdAttribute(ProgramID pid, NodeID nid, const Source& src, const ast::Expression* val);
|
||||
~IdAttribute() override;
|
||||
|
||||
/// @returns the WGSL name for the attribute
|
||||
@@ -41,8 +42,8 @@ class IdAttribute final : public Castable<IdAttribute, Attribute> {
|
||||
/// @return the newly cloned node
|
||||
const IdAttribute* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The id value
|
||||
const uint32_t value;
|
||||
/// The id value expression
|
||||
const ast::Expression* const value;
|
||||
};
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -19,11 +19,12 @@
|
||||
namespace tint::ast {
|
||||
namespace {
|
||||
|
||||
using namespace tint::number_suffixes; // NOLINT
|
||||
using IdAttributeTest = TestHelper;
|
||||
|
||||
TEST_F(IdAttributeTest, Creation) {
|
||||
auto* d = create<IdAttribute>(12u);
|
||||
EXPECT_EQ(12u, d->value);
|
||||
auto* d = Id(12_a);
|
||||
EXPECT_TRUE(d->value->Is<ast::IntLiteralExpression>());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -48,11 +48,4 @@ const Override* Override::Clone(CloneContext* ctx) const {
|
||||
return ctx->dst->create<Override>(src, sym, ty, ctor, std::move(attrs));
|
||||
}
|
||||
|
||||
std::string Override::Identifier(const SymbolTable& symbols) const {
|
||||
if (auto* id = ast::GetAttribute<ast::IdAttribute>(attributes)) {
|
||||
return std::to_string(id->value);
|
||||
}
|
||||
return symbols.NameFor(symbol);
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -62,12 +62,6 @@ class Override final : public Castable<Override, Variable> {
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const Override* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// @param symbols the symbol table to retrieve the name from
|
||||
/// @returns the identifier string for the override. If the override has
|
||||
/// an ID attribute, the string is the id-stringified. Otherwise, the ID
|
||||
/// is the symbol.
|
||||
std::string Identifier(const SymbolTable& symbols) const;
|
||||
};
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright 2022 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/override.h"
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint::ast {
|
||||
namespace {
|
||||
|
||||
using OverrideTest = TestHelper;
|
||||
|
||||
TEST_F(OverrideTest, Identifier_NoId) {
|
||||
auto* o = Override("o", Expr(f32(1.0)));
|
||||
EXPECT_EQ(std::string("o"), o->Identifier(Symbols()));
|
||||
}
|
||||
|
||||
TEST_F(OverrideTest, Identifier_WithId) {
|
||||
auto* o = Override("o", Expr(f32(1.0)), Id(4u));
|
||||
EXPECT_EQ(std::string("4"), o->Identifier(Symbols()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::ast
|
||||
@@ -93,7 +93,7 @@ TEST_F(VariableTest, Assert_DifferentProgramID_Constructor) {
|
||||
|
||||
TEST_F(VariableTest, WithAttributes) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Location(1u),
|
||||
Builtin(BuiltinValue::kPosition), Id(1200u));
|
||||
Builtin(BuiltinValue::kPosition), Id(1200_u));
|
||||
|
||||
auto& attributes = var->attributes;
|
||||
EXPECT_TRUE(ast::HasAttribute<ast::LocationAttribute>(attributes));
|
||||
|
||||
Reference in New Issue
Block a user