mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
tint/ast: Migrate to utils::Vector
Change-Id: I10dd2feeaeb86a1ee7769d2bfd172e49c2805cb3 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97843 Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
34d46731bb
commit
783b169bf4
@@ -15,6 +15,7 @@
|
||||
#include "src/tint/ast/array.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
@@ -42,8 +43,8 @@ Array::Array(ProgramID pid,
|
||||
const Source& src,
|
||||
const Type* subtype,
|
||||
const Expression* cnt,
|
||||
AttributeList attrs)
|
||||
: Base(pid, nid, src), type(subtype), count(cnt), attributes(attrs) {}
|
||||
utils::VectorRef<const Attribute*> attrs)
|
||||
: Base(pid, nid, src), type(subtype), count(cnt), attributes(std::move(attrs)) {}
|
||||
|
||||
Array::Array(Array&&) = default;
|
||||
|
||||
@@ -73,7 +74,7 @@ const Array* Array::Clone(CloneContext* ctx) const {
|
||||
auto* ty = ctx->Clone(type);
|
||||
auto* cnt = ctx->Clone(count);
|
||||
auto attrs = ctx->Clone(attributes);
|
||||
return ctx->dst->create<Array>(src, ty, cnt, attrs);
|
||||
return ctx->dst->create<Array>(src, ty, cnt, std::move(attrs));
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -43,7 +43,7 @@ class Array final : public Castable<Array, Type> {
|
||||
const Source& src,
|
||||
const Type* subtype,
|
||||
const Expression* count,
|
||||
AttributeList attributes);
|
||||
utils::VectorRef<const Attribute*> attributes);
|
||||
/// Move constructor
|
||||
Array(Array&&);
|
||||
~Array() override;
|
||||
@@ -69,7 +69,7 @@ class Array final : public Castable<Array, Type> {
|
||||
const Expression* const count;
|
||||
|
||||
/// the array attributes
|
||||
const AttributeList attributes;
|
||||
const utils::Vector<const Attribute*, 1> attributes;
|
||||
};
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -26,7 +26,7 @@ using AstArrayTest = TestHelper;
|
||||
TEST_F(AstArrayTest, CreateSizedArray) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* count = Expr(3_u);
|
||||
auto* arr = create<Array>(u32, count, AttributeList{});
|
||||
auto* arr = create<Array>(u32, count, utils::Empty);
|
||||
EXPECT_EQ(arr->type, u32);
|
||||
EXPECT_EQ(arr->count, count);
|
||||
EXPECT_TRUE(arr->Is<Array>());
|
||||
@@ -35,7 +35,7 @@ TEST_F(AstArrayTest, CreateSizedArray) {
|
||||
|
||||
TEST_F(AstArrayTest, CreateRuntimeArray) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* arr = create<Array>(u32, nullptr, AttributeList{});
|
||||
auto* arr = create<Array>(u32, nullptr, utils::Empty);
|
||||
EXPECT_EQ(arr->type, u32);
|
||||
EXPECT_EQ(arr->count, nullptr);
|
||||
EXPECT_TRUE(arr->Is<Array>());
|
||||
@@ -43,7 +43,7 @@ TEST_F(AstArrayTest, CreateRuntimeArray) {
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, CreateInferredTypeArray) {
|
||||
auto* arr = create<Array>(nullptr, nullptr, AttributeList{});
|
||||
auto* arr = create<Array>(nullptr, nullptr, utils::Empty);
|
||||
EXPECT_EQ(arr->type, nullptr);
|
||||
EXPECT_EQ(arr->count, nullptr);
|
||||
EXPECT_TRUE(arr->Is<Array>());
|
||||
@@ -52,35 +52,35 @@ TEST_F(AstArrayTest, CreateInferredTypeArray) {
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_RuntimeSized) {
|
||||
auto* i32 = create<I32>();
|
||||
auto* arr = create<Array>(i32, nullptr, AttributeList{});
|
||||
auto* arr = create<Array>(i32, nullptr, utils::Empty);
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "array<i32>");
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_LiteralSized) {
|
||||
auto* i32 = create<I32>();
|
||||
auto* arr = create<Array>(i32, Expr(5_u), AttributeList{});
|
||||
auto* arr = create<Array>(i32, Expr(5_u), utils::Empty);
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "array<i32, 5>");
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_ConstantSized) {
|
||||
auto* i32 = create<I32>();
|
||||
auto* arr = create<Array>(i32, Expr("size"), AttributeList{});
|
||||
auto* arr = create<Array>(i32, Expr("size"), utils::Empty);
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "array<i32, size>");
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_WithStride) {
|
||||
auto* i32 = create<I32>();
|
||||
auto* arr = create<Array>(i32, Expr(5_u), AttributeList{create<StrideAttribute>(32u)});
|
||||
auto* arr = create<Array>(i32, Expr(5_u), utils::Vector{create<StrideAttribute>(32u)});
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(32) array<i32, 5>");
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_InferredTypeAndCount) {
|
||||
auto* arr = create<Array>(nullptr, nullptr, AttributeList{});
|
||||
auto* arr = create<Array>(nullptr, nullptr, utils::Empty);
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "array");
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_InferredTypeAndCount_WithStrize) {
|
||||
auto* arr = create<Array>(nullptr, nullptr, AttributeList{create<StrideAttribute>(32u)});
|
||||
auto* arr = create<Array>(nullptr, nullptr, utils::Vector{create<StrideAttribute>(32u)});
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(32) array");
|
||||
}
|
||||
|
||||
|
||||
@@ -38,13 +38,10 @@ class Attribute : public Castable<Attribute, Node> {
|
||||
Attribute(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {}
|
||||
};
|
||||
|
||||
/// A list of attributes
|
||||
using AttributeList = std::vector<const Attribute*>;
|
||||
|
||||
/// @param attributes the list of attributes to search
|
||||
/// @returns true if `attributes` includes a attribute of type `T`
|
||||
template <typename... Ts>
|
||||
bool HasAttribute(const AttributeList& attributes) {
|
||||
bool HasAttribute(utils::VectorRef<const Attribute*> attributes) {
|
||||
for (auto* attr : attributes) {
|
||||
if (attr->IsAnyOf<Ts...>()) {
|
||||
return true;
|
||||
@@ -56,7 +53,7 @@ bool HasAttribute(const AttributeList& attributes) {
|
||||
/// @param attributes the list of attributes to search
|
||||
/// @returns a pointer to `T` from `attributes` if found, otherwise nullptr.
|
||||
template <typename T>
|
||||
const T* GetAttribute(const AttributeList& attributes) {
|
||||
const T* GetAttribute(utils::VectorRef<const Attribute*> attributes) {
|
||||
for (auto* attr : attributes) {
|
||||
if (attr->Is<T>()) {
|
||||
return attr->As<T>();
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace tint::ast {
|
||||
BlockStatement::BlockStatement(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
const StatementList& stmts)
|
||||
utils::VectorRef<const Statement*> stmts)
|
||||
: Base(pid, nid, src), statements(std::move(stmts)) {
|
||||
for (auto* stmt : statements) {
|
||||
TINT_ASSERT(AST, stmt);
|
||||
@@ -39,7 +39,7 @@ const BlockStatement* BlockStatement::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto stmts = ctx->Clone(statements);
|
||||
return ctx->dst->create<BlockStatement>(src, stmts);
|
||||
return ctx->dst->create<BlockStatement>(src, std::move(stmts));
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -32,16 +32,16 @@ class BlockStatement final : public Castable<BlockStatement, Statement> {
|
||||
BlockStatement(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& source,
|
||||
const StatementList& statements);
|
||||
utils::VectorRef<const Statement*> statements);
|
||||
/// Move constructor
|
||||
BlockStatement(BlockStatement&&);
|
||||
~BlockStatement() override;
|
||||
|
||||
/// @returns true if the block has no statements
|
||||
bool Empty() const { return statements.empty(); }
|
||||
bool Empty() const { return statements.IsEmpty(); }
|
||||
|
||||
/// @returns the last statement in the block or nullptr if block empty
|
||||
const Statement* Last() const { return statements.empty() ? nullptr : statements.back(); }
|
||||
const Statement* Last() const { return statements.IsEmpty() ? nullptr : statements.Back(); }
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
@@ -50,7 +50,7 @@ class BlockStatement final : public Castable<BlockStatement, Statement> {
|
||||
const BlockStatement* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// the statement list
|
||||
const StatementList statements;
|
||||
const utils::Vector<const Statement*, 8> statements;
|
||||
};
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -26,21 +26,21 @@ TEST_F(BlockStatementTest, Creation) {
|
||||
auto* d = create<DiscardStatement>();
|
||||
auto* ptr = d;
|
||||
|
||||
auto* b = create<BlockStatement>(StatementList{d});
|
||||
auto* b = create<BlockStatement>(utils::Vector{d});
|
||||
|
||||
ASSERT_EQ(b->statements.size(), 1u);
|
||||
ASSERT_EQ(b->statements.Length(), 1u);
|
||||
EXPECT_EQ(b->statements[0], ptr);
|
||||
}
|
||||
|
||||
TEST_F(BlockStatementTest, Creation_WithSource) {
|
||||
auto* b = create<BlockStatement>(Source{Source::Location{20, 2}}, ast::StatementList{});
|
||||
auto* b = create<BlockStatement>(Source{Source::Location{20, 2}}, utils::Empty);
|
||||
auto src = b->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(BlockStatementTest, IsBlock) {
|
||||
auto* b = create<BlockStatement>(ast::StatementList{});
|
||||
auto* b = create<BlockStatement>(utils::Empty);
|
||||
EXPECT_TRUE(b->Is<BlockStatement>());
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ TEST_F(BlockStatementTest, Assert_Null_Statement) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<BlockStatement>(ast::StatementList{nullptr});
|
||||
b.create<BlockStatement>(utils::Vector<const ast::Statement*, 1>{nullptr});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -58,7 +58,7 @@ TEST_F(BlockStatementTest, Assert_DifferentProgramID_Statement) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<BlockStatement>(ast::StatementList{b2.create<DiscardStatement>()});
|
||||
b1.create<BlockStatement>(utils::Vector{b2.create<DiscardStatement>()});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ TextureOverloadCase::TextureOverloadCase(ValidTextureOverload o,
|
||||
ast::TextureDimension dims,
|
||||
TextureDataType datatype,
|
||||
const char* f,
|
||||
std::function<ExpressionList(ProgramBuilder*)> a)
|
||||
std::function<Args(ProgramBuilder*)> a)
|
||||
: overload(o),
|
||||
description(desc),
|
||||
texture_kind(tk),
|
||||
@@ -44,7 +44,7 @@ TextureOverloadCase::TextureOverloadCase(ValidTextureOverload o,
|
||||
ast::TextureDimension dims,
|
||||
TextureDataType datatype,
|
||||
const char* f,
|
||||
std::function<ExpressionList(ProgramBuilder*)> a)
|
||||
std::function<Args(ProgramBuilder*)> a)
|
||||
: overload(o),
|
||||
description(desc),
|
||||
texture_kind(tk),
|
||||
@@ -59,7 +59,7 @@ TextureOverloadCase::TextureOverloadCase(ValidTextureOverload o,
|
||||
ast::TextureDimension dims,
|
||||
TextureDataType datatype,
|
||||
const char* f,
|
||||
std::function<ExpressionList(ProgramBuilder*)> a)
|
||||
std::function<Args(ProgramBuilder*)> a)
|
||||
: overload(o),
|
||||
description(d),
|
||||
texture_kind(TextureKind::kStorage),
|
||||
@@ -141,7 +141,7 @@ const ast::Type* TextureOverloadCase::BuildResultVectorComponentType(ProgramBuil
|
||||
}
|
||||
|
||||
const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b) const {
|
||||
AttributeList attrs = {
|
||||
utils::Vector attrs{
|
||||
b->create<ast::GroupAttribute>(0u),
|
||||
b->create<ast::BindingAttribute>(0u),
|
||||
};
|
||||
@@ -175,7 +175,7 @@ const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b
|
||||
}
|
||||
|
||||
const ast::Variable* TextureOverloadCase::BuildSamplerVariable(ProgramBuilder* b) const {
|
||||
AttributeList attrs = {
|
||||
utils::Vector attrs = {
|
||||
b->create<ast::GroupAttribute>(0u),
|
||||
b->create<ast::BindingAttribute>(1u),
|
||||
};
|
||||
|
||||
@@ -177,6 +177,9 @@ bool ReturnsVoid(ValidTextureOverload texture_overload);
|
||||
|
||||
/// Describes a texture builtin overload
|
||||
struct TextureOverloadCase {
|
||||
/// Args is a list of ast::Expression used as arguments to the texture overload case.
|
||||
using Args = utils::Vector<const ast::Expression*, 8>;
|
||||
|
||||
/// Constructor for textureSample...() functions
|
||||
TextureOverloadCase(ValidTextureOverload,
|
||||
const char*,
|
||||
@@ -185,7 +188,7 @@ struct TextureOverloadCase {
|
||||
ast::TextureDimension,
|
||||
TextureDataType,
|
||||
const char*,
|
||||
std::function<ExpressionList(ProgramBuilder*)>);
|
||||
std::function<Args(ProgramBuilder*)>);
|
||||
/// Constructor for textureLoad() functions with non-storage textures
|
||||
TextureOverloadCase(ValidTextureOverload,
|
||||
const char*,
|
||||
@@ -193,7 +196,7 @@ struct TextureOverloadCase {
|
||||
ast::TextureDimension,
|
||||
TextureDataType,
|
||||
const char*,
|
||||
std::function<ExpressionList(ProgramBuilder*)>);
|
||||
std::function<Args(ProgramBuilder*)>);
|
||||
/// Constructor for textureLoad() with storage textures
|
||||
TextureOverloadCase(ValidTextureOverload,
|
||||
const char*,
|
||||
@@ -202,7 +205,7 @@ struct TextureOverloadCase {
|
||||
ast::TextureDimension,
|
||||
TextureDataType,
|
||||
const char*,
|
||||
std::function<ExpressionList(ProgramBuilder*)>);
|
||||
std::function<Args(ProgramBuilder*)>);
|
||||
/// Copy constructor
|
||||
TextureOverloadCase(const TextureOverloadCase&);
|
||||
/// Destructor
|
||||
@@ -246,7 +249,7 @@ struct TextureOverloadCase {
|
||||
/// Name of the function. e.g. `textureSample`, `textureSampleGrad`, etc
|
||||
const char* const function;
|
||||
/// A function that builds the AST arguments for the overload
|
||||
std::function<ExpressionList(ProgramBuilder*)> const args;
|
||||
std::function<Args(ProgramBuilder*)> const args;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const TextureOverloadCase& data);
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "src/tint/ast/call_expression.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::CallExpression);
|
||||
@@ -37,8 +39,8 @@ CallExpression::CallExpression(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
const IdentifierExpression* name,
|
||||
ExpressionList a)
|
||||
: Base(pid, nid, src), target(ToTarget(name)), args(a) {
|
||||
utils::VectorRef<const Expression*> a)
|
||||
: Base(pid, nid, src), target(ToTarget(name)), args(std::move(a)) {
|
||||
TINT_ASSERT(AST, name);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, name, program_id);
|
||||
for (auto* arg : args) {
|
||||
@@ -51,8 +53,8 @@ CallExpression::CallExpression(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
const Type* type,
|
||||
ExpressionList a)
|
||||
: Base(pid, nid, src), target(ToTarget(type)), args(a) {
|
||||
utils::VectorRef<const Expression*> a)
|
||||
: Base(pid, nid, src), target(ToTarget(type)), args(std::move(a)) {
|
||||
TINT_ASSERT(AST, type);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id);
|
||||
for (auto* arg : args) {
|
||||
@@ -69,8 +71,9 @@ const CallExpression* CallExpression::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto p = ctx->Clone(args);
|
||||
return target.name ? ctx->dst->create<CallExpression>(src, ctx->Clone(target.name), p)
|
||||
: ctx->dst->create<CallExpression>(src, ctx->Clone(target.type), p);
|
||||
return target.name
|
||||
? ctx->dst->create<CallExpression>(src, ctx->Clone(target.name), std::move(p))
|
||||
: ctx->dst->create<CallExpression>(src, ctx->Clone(target.type), std::move(p));
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -42,7 +42,7 @@ class CallExpression final : public Castable<CallExpression, Expression> {
|
||||
NodeID nid,
|
||||
const Source& source,
|
||||
const IdentifierExpression* name,
|
||||
ExpressionList args);
|
||||
utils::VectorRef<const Expression*> args);
|
||||
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
@@ -54,7 +54,7 @@ class CallExpression final : public Castable<CallExpression, Expression> {
|
||||
NodeID nid,
|
||||
const Source& source,
|
||||
const Type* type,
|
||||
ExpressionList args);
|
||||
utils::VectorRef<const Expression*> args);
|
||||
|
||||
/// Move constructor
|
||||
CallExpression(CallExpression&&);
|
||||
@@ -80,7 +80,7 @@ class CallExpression final : public Castable<CallExpression, Expression> {
|
||||
const Target target;
|
||||
|
||||
/// The arguments
|
||||
const ExpressionList args;
|
||||
const utils::Vector<const Expression*, 8> args;
|
||||
};
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -22,23 +22,24 @@ using CallExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(CallExpressionTest, CreationIdentifier) {
|
||||
auto* func = Expr("func");
|
||||
ExpressionList params;
|
||||
params.push_back(Expr("param1"));
|
||||
params.push_back(Expr("param2"));
|
||||
utils::Vector params{
|
||||
Expr("param1"),
|
||||
Expr("param2"),
|
||||
};
|
||||
|
||||
auto* stmt = create<CallExpression>(func, params);
|
||||
EXPECT_EQ(stmt->target.name, func);
|
||||
EXPECT_EQ(stmt->target.type, nullptr);
|
||||
|
||||
const auto& vec = stmt->args;
|
||||
ASSERT_EQ(vec.size(), 2u);
|
||||
ASSERT_EQ(vec.Length(), 2u);
|
||||
EXPECT_EQ(vec[0], params[0]);
|
||||
EXPECT_EQ(vec[1], params[1]);
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, CreationIdentifier_WithSource) {
|
||||
auto* func = Expr("func");
|
||||
auto* stmt = create<CallExpression>(Source{{20, 2}}, func, ExpressionList{});
|
||||
auto* stmt = create<CallExpression>(Source{{20, 2}}, func, utils::Empty);
|
||||
EXPECT_EQ(stmt->target.name, func);
|
||||
EXPECT_EQ(stmt->target.type, nullptr);
|
||||
|
||||
@@ -49,23 +50,24 @@ TEST_F(CallExpressionTest, CreationIdentifier_WithSource) {
|
||||
|
||||
TEST_F(CallExpressionTest, CreationType) {
|
||||
auto* type = ty.f32();
|
||||
ExpressionList params;
|
||||
params.push_back(Expr("param1"));
|
||||
params.push_back(Expr("param2"));
|
||||
utils::Vector params{
|
||||
Expr("param1"),
|
||||
Expr("param2"),
|
||||
};
|
||||
|
||||
auto* stmt = create<CallExpression>(type, params);
|
||||
EXPECT_EQ(stmt->target.name, nullptr);
|
||||
EXPECT_EQ(stmt->target.type, type);
|
||||
|
||||
const auto& vec = stmt->args;
|
||||
ASSERT_EQ(vec.size(), 2u);
|
||||
ASSERT_EQ(vec.Length(), 2u);
|
||||
EXPECT_EQ(vec[0], params[0]);
|
||||
EXPECT_EQ(vec[1], params[1]);
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, CreationType_WithSource) {
|
||||
auto* type = ty.f32();
|
||||
auto* stmt = create<CallExpression>(Source{{20, 2}}, type, ExpressionList{});
|
||||
auto* stmt = create<CallExpression>(Source{{20, 2}}, type, utils::Empty);
|
||||
EXPECT_EQ(stmt->target.name, nullptr);
|
||||
EXPECT_EQ(stmt->target.type, type);
|
||||
|
||||
@@ -76,7 +78,7 @@ TEST_F(CallExpressionTest, CreationType_WithSource) {
|
||||
|
||||
TEST_F(CallExpressionTest, IsCall) {
|
||||
auto* func = Expr("func");
|
||||
auto* stmt = create<CallExpression>(func, ExpressionList{});
|
||||
auto* stmt = create<CallExpression>(func, utils::Empty);
|
||||
EXPECT_TRUE(stmt->Is<CallExpression>());
|
||||
}
|
||||
|
||||
@@ -84,7 +86,7 @@ TEST_F(CallExpressionTest, Assert_Null_Identifier) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<CallExpression>(static_cast<IdentifierExpression*>(nullptr), ExpressionList{});
|
||||
b.create<CallExpression>(static_cast<IdentifierExpression*>(nullptr), utils::Empty);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -93,7 +95,7 @@ TEST_F(CallExpressionTest, Assert_Null_Type) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<CallExpression>(static_cast<Type*>(nullptr), ExpressionList{});
|
||||
b.create<CallExpression>(static_cast<Type*>(nullptr), utils::Empty);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -102,11 +104,11 @@ TEST_F(CallExpressionTest, Assert_Null_Param) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
ExpressionList params;
|
||||
params.push_back(b.Expr("param1"));
|
||||
params.push_back(nullptr);
|
||||
params.push_back(b.Expr("param2"));
|
||||
b.create<CallExpression>(b.Expr("func"), params);
|
||||
b.create<CallExpression>(b.Expr("func"), utils::Vector{
|
||||
b.Expr("param1"),
|
||||
nullptr,
|
||||
b.Expr("param2"),
|
||||
});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -116,7 +118,7 @@ TEST_F(CallExpressionTest, Assert_DifferentProgramID_Identifier) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CallExpression>(b2.Expr("func"), ExpressionList{});
|
||||
b1.create<CallExpression>(b2.Expr("func"), utils::Empty);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -126,7 +128,7 @@ TEST_F(CallExpressionTest, Assert_DifferentProgramID_Type) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CallExpression>(b2.ty.f32(), ExpressionList{});
|
||||
b1.create<CallExpression>(b2.ty.f32(), utils::Empty);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -136,7 +138,7 @@ TEST_F(CallExpressionTest, Assert_DifferentProgramID_Param) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CallExpression>(b1.Expr("func"), ExpressionList{b2.Expr("param1")});
|
||||
b1.create<CallExpression>(b1.Expr("func"), utils::Vector{b2.Expr("param1")});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace {
|
||||
using CallStatementTest = TestHelper;
|
||||
|
||||
TEST_F(CallStatementTest, Creation) {
|
||||
auto* expr = create<CallExpression>(Expr("func"), ExpressionList{});
|
||||
auto* expr = create<CallExpression>(Expr("func"), utils::Empty);
|
||||
|
||||
auto* c = create<CallStatement>(expr);
|
||||
EXPECT_EQ(c->expr, expr);
|
||||
@@ -48,7 +48,7 @@ TEST_F(CallStatementTest, Assert_DifferentProgramID_Call) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CallStatement>(b2.create<CallExpression>(b2.Expr("func"), ExpressionList{}));
|
||||
b1.create<CallStatement>(b2.create<CallExpression>(b2.Expr("func"), utils::Empty));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "src/tint/ast/case_statement.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::CaseStatement);
|
||||
@@ -23,9 +25,9 @@ namespace tint::ast {
|
||||
CaseStatement::CaseStatement(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
CaseSelectorList s,
|
||||
utils::VectorRef<const IntLiteralExpression*> s,
|
||||
const BlockStatement* b)
|
||||
: Base(pid, nid, src), selectors(s), body(b) {
|
||||
: Base(pid, nid, src), selectors(std::move(s)), body(b) {
|
||||
TINT_ASSERT(AST, body);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
|
||||
for (auto* selector : selectors) {
|
||||
@@ -43,7 +45,7 @@ const CaseStatement* CaseStatement::Clone(CloneContext* ctx) const {
|
||||
auto src = ctx->Clone(source);
|
||||
auto sel = ctx->Clone(selectors);
|
||||
auto* b = ctx->Clone(body);
|
||||
return ctx->dst->create<CaseStatement>(src, sel, b);
|
||||
return ctx->dst->create<CaseStatement>(src, std::move(sel), b);
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
|
||||
namespace tint::ast {
|
||||
|
||||
/// A list of case literals
|
||||
using CaseSelectorList = std::vector<const IntLiteralExpression*>;
|
||||
|
||||
/// A case statement
|
||||
class CaseStatement final : public Castable<CaseStatement, Statement> {
|
||||
public:
|
||||
@@ -37,14 +34,14 @@ class CaseStatement final : public Castable<CaseStatement, Statement> {
|
||||
CaseStatement(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
CaseSelectorList selectors,
|
||||
utils::VectorRef<const IntLiteralExpression*> selectors,
|
||||
const BlockStatement* body);
|
||||
/// Move constructor
|
||||
CaseStatement(CaseStatement&&);
|
||||
~CaseStatement() override;
|
||||
|
||||
/// @returns true if this is a default statement
|
||||
bool IsDefault() const { return selectors.empty(); }
|
||||
bool IsDefault() const { return selectors.IsEmpty(); }
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
@@ -53,15 +50,12 @@ class CaseStatement final : public Castable<CaseStatement, Statement> {
|
||||
const CaseStatement* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The case selectors, empty if none set
|
||||
const CaseSelectorList selectors;
|
||||
const utils::Vector<const IntLiteralExpression*, 4> selectors;
|
||||
|
||||
/// The case body
|
||||
const BlockStatement* const body;
|
||||
};
|
||||
|
||||
/// A list of case statements
|
||||
using CaseStatementList = std::vector<const CaseStatement*>;
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
#endif // SRC_TINT_AST_CASE_STATEMENT_H_
|
||||
|
||||
@@ -27,40 +27,37 @@ namespace {
|
||||
using CaseStatementTest = TestHelper;
|
||||
|
||||
TEST_F(CaseStatementTest, Creation_i32) {
|
||||
CaseSelectorList b;
|
||||
auto* selector = Expr(2_i);
|
||||
b.push_back(selector);
|
||||
utils::Vector b{selector};
|
||||
|
||||
auto* discard = create<DiscardStatement>();
|
||||
auto* body = create<BlockStatement>(StatementList{discard});
|
||||
auto* body = create<BlockStatement>(utils::Vector{discard});
|
||||
|
||||
auto* c = create<CaseStatement>(b, body);
|
||||
ASSERT_EQ(c->selectors.size(), 1u);
|
||||
ASSERT_EQ(c->selectors.Length(), 1u);
|
||||
EXPECT_EQ(c->selectors[0], selector);
|
||||
ASSERT_EQ(c->body->statements.size(), 1u);
|
||||
ASSERT_EQ(c->body->statements.Length(), 1u);
|
||||
EXPECT_EQ(c->body->statements[0], discard);
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, Creation_u32) {
|
||||
CaseSelectorList b;
|
||||
auto* selector = Expr(2_u);
|
||||
b.push_back(selector);
|
||||
utils::Vector b{selector};
|
||||
|
||||
auto* discard = create<DiscardStatement>();
|
||||
auto* body = create<BlockStatement>(StatementList{discard});
|
||||
auto* body = create<BlockStatement>(utils::Vector{discard});
|
||||
|
||||
auto* c = create<CaseStatement>(b, body);
|
||||
ASSERT_EQ(c->selectors.size(), 1u);
|
||||
ASSERT_EQ(c->selectors.Length(), 1u);
|
||||
EXPECT_EQ(c->selectors[0], selector);
|
||||
ASSERT_EQ(c->body->statements.size(), 1u);
|
||||
ASSERT_EQ(c->body->statements.Length(), 1u);
|
||||
EXPECT_EQ(c->body->statements[0], discard);
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, Creation_WithSource) {
|
||||
CaseSelectorList b;
|
||||
b.push_back(Expr(2_i));
|
||||
utils::Vector b{Expr(2_i)};
|
||||
|
||||
auto* body = create<BlockStatement>(StatementList{
|
||||
auto* body = create<BlockStatement>(utils::Vector{
|
||||
create<DiscardStatement>(),
|
||||
});
|
||||
auto* c = create<CaseStatement>(Source{Source::Location{20, 2}}, b, body);
|
||||
@@ -70,23 +67,21 @@ TEST_F(CaseStatementTest, Creation_WithSource) {
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
|
||||
auto* body = create<BlockStatement>(StatementList{
|
||||
auto* body = create<BlockStatement>(utils::Vector{
|
||||
create<DiscardStatement>(),
|
||||
});
|
||||
auto* c = create<CaseStatement>(CaseSelectorList{}, body);
|
||||
auto* c = create<CaseStatement>(utils::Empty, body);
|
||||
EXPECT_TRUE(c->IsDefault());
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
|
||||
CaseSelectorList b;
|
||||
b.push_back(Expr(2_i));
|
||||
|
||||
auto* c = create<CaseStatement>(b, create<BlockStatement>(StatementList{}));
|
||||
utils::Vector b{Expr(2_i)};
|
||||
auto* c = create<CaseStatement>(b, create<BlockStatement>(utils::Empty));
|
||||
EXPECT_FALSE(c->IsDefault());
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, IsCase) {
|
||||
auto* c = create<CaseStatement>(CaseSelectorList{}, create<BlockStatement>(StatementList{}));
|
||||
auto* c = create<CaseStatement>(utils::Empty, create<BlockStatement>(utils::Empty));
|
||||
EXPECT_TRUE(c->Is<CaseStatement>());
|
||||
}
|
||||
|
||||
@@ -94,7 +89,7 @@ TEST_F(CaseStatementTest, Assert_Null_Body) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<CaseStatement>(CaseSelectorList{}, nullptr);
|
||||
b.create<CaseStatement>(utils::Empty, nullptr);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -103,8 +98,8 @@ TEST_F(CaseStatementTest, Assert_Null_Selector) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<CaseStatement>(CaseSelectorList{nullptr},
|
||||
b.create<BlockStatement>(StatementList{}));
|
||||
b.create<CaseStatement>(utils::Vector<const ast::IntLiteralExpression*, 1>{nullptr},
|
||||
b.create<BlockStatement>(utils::Empty));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -114,8 +109,7 @@ TEST_F(CaseStatementTest, Assert_DifferentProgramID_Call) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CaseStatement>(CaseSelectorList{},
|
||||
b2.create<BlockStatement>(StatementList{}));
|
||||
b1.create<CaseStatement>(utils::Empty, b2.create<BlockStatement>(utils::Empty));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -125,8 +119,8 @@ TEST_F(CaseStatementTest, Assert_DifferentProgramID_Selector) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CaseStatement>(CaseSelectorList{b2.Expr(2_i)},
|
||||
b1.create<BlockStatement>(StatementList{}));
|
||||
b1.create<CaseStatement>(utils::Vector{b2.Expr(2_i)},
|
||||
b1.create<BlockStatement>(utils::Empty));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "src/tint/ast/const.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::Const);
|
||||
@@ -26,8 +28,8 @@ Const::Const(ProgramID pid,
|
||||
const Symbol& sym,
|
||||
const ast::Type* ty,
|
||||
const Expression* ctor,
|
||||
AttributeList attrs)
|
||||
: Base(pid, nid, src, sym, ty, ctor, attrs) {
|
||||
utils::VectorRef<const Attribute*> attrs)
|
||||
: Base(pid, nid, src, sym, ty, ctor, std::move(attrs)) {
|
||||
TINT_ASSERT(AST, ctor != nullptr);
|
||||
}
|
||||
|
||||
@@ -45,7 +47,7 @@ const Const* Const::Clone(CloneContext* ctx) const {
|
||||
auto* ty = ctx->Clone(type);
|
||||
auto* ctor = ctx->Clone(constructor);
|
||||
auto attrs = ctx->Clone(attributes);
|
||||
return ctx->dst->create<Const>(src, sym, ty, ctor, attrs);
|
||||
return ctx->dst->create<Const>(src, sym, ty, ctor, std::move(attrs));
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -46,7 +46,7 @@ class Const final : public Castable<Const, Variable> {
|
||||
const Symbol& sym,
|
||||
const ast::Type* type,
|
||||
const Expression* constructor,
|
||||
AttributeList attributes);
|
||||
utils::VectorRef<const Attribute*> attributes);
|
||||
|
||||
/// Move constructor
|
||||
Const(Const&&);
|
||||
|
||||
@@ -52,9 +52,6 @@ class Enable final : public Castable<Enable, Node> {
|
||||
const Extension extension;
|
||||
};
|
||||
|
||||
/// A list of enables
|
||||
using EnableList = std::vector<const Enable*>;
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
#endif // SRC_TINT_AST_ENABLE_H_
|
||||
|
||||
@@ -38,9 +38,6 @@ class Expression : public Castable<Expression, Node> {
|
||||
Expression(Expression&&);
|
||||
};
|
||||
|
||||
/// A list of expressions
|
||||
using ExpressionList = std::vector<const Expression*>;
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
#endif // SRC_TINT_AST_EXPRESSION_H_
|
||||
|
||||
@@ -26,11 +26,11 @@ Function::Function(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
Symbol sym,
|
||||
ParameterList parameters,
|
||||
utils::VectorRef<const Parameter*> parameters,
|
||||
const Type* return_ty,
|
||||
const BlockStatement* b,
|
||||
AttributeList attrs,
|
||||
AttributeList return_type_attrs)
|
||||
utils::VectorRef<const Attribute*> attrs,
|
||||
utils::VectorRef<const Attribute*> return_type_attrs)
|
||||
: Base(pid, nid, src),
|
||||
symbol(sym),
|
||||
params(std::move(parameters)),
|
||||
|
||||
@@ -48,11 +48,11 @@ class Function final : public Castable<Function, Node> {
|
||||
NodeID nid,
|
||||
const Source& source,
|
||||
Symbol symbol,
|
||||
ParameterList params,
|
||||
utils::VectorRef<const Parameter*> params,
|
||||
const Type* return_type,
|
||||
const BlockStatement* body,
|
||||
AttributeList attributes,
|
||||
AttributeList return_type_attributes);
|
||||
utils::VectorRef<const Attribute*> attributes,
|
||||
utils::VectorRef<const Attribute*> return_type_attributes);
|
||||
/// Move constructor
|
||||
Function(Function&&);
|
||||
|
||||
@@ -74,7 +74,7 @@ class Function final : public Castable<Function, Node> {
|
||||
const Symbol symbol;
|
||||
|
||||
/// The function params
|
||||
const ParameterList params;
|
||||
const utils::Vector<const Parameter*, 8> params;
|
||||
|
||||
/// The function return type
|
||||
const Type* const return_type;
|
||||
@@ -83,18 +83,18 @@ class Function final : public Castable<Function, Node> {
|
||||
const BlockStatement* const body;
|
||||
|
||||
/// The attributes attached to this function
|
||||
const AttributeList attributes;
|
||||
const utils::Vector<const Attribute*, 2> attributes;
|
||||
|
||||
/// The attributes attached to the function return type.
|
||||
const AttributeList return_type_attributes;
|
||||
const utils::Vector<const Attribute*, 2> return_type_attributes;
|
||||
};
|
||||
|
||||
/// A list of functions
|
||||
class FunctionList : public std::vector<const Function*> {
|
||||
class FunctionList : public utils::Vector<const Function*, 8> {
|
||||
public:
|
||||
/// Appends f to the end of the list
|
||||
/// @param f the function to append to this list
|
||||
void Add(const Function* f) { this->emplace_back(f); }
|
||||
void Add(const Function* f) { this->Push(f); }
|
||||
|
||||
/// Returns the function with the given name
|
||||
/// @param sym the function symbol to search for
|
||||
|
||||
@@ -26,20 +26,20 @@ namespace {
|
||||
using FunctionTest = TestHelper;
|
||||
|
||||
TEST_F(FunctionTest, Creation) {
|
||||
ParameterList params{Param("var", ty.i32())};
|
||||
utils::Vector params{Param("var", ty.i32())};
|
||||
auto* var = params[0];
|
||||
|
||||
auto* f = Func("func", params, ty.void_(), {});
|
||||
auto* f = Func("func", params, ty.void_(), utils::Empty);
|
||||
EXPECT_EQ(f->symbol, Symbols().Get("func"));
|
||||
ASSERT_EQ(f->params.size(), 1u);
|
||||
ASSERT_EQ(f->params.Length(), 1u);
|
||||
EXPECT_TRUE(f->return_type->Is<ast::Void>());
|
||||
EXPECT_EQ(f->params[0], var);
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Creation_WithSource) {
|
||||
ParameterList params{Param("var", ty.i32())};
|
||||
utils::Vector params{Param("var", ty.i32())};
|
||||
|
||||
auto* f = Func(Source{Source::Location{20, 2}}, "func", params, ty.void_(), {});
|
||||
auto* f = Func(Source{Source::Location{20, 2}}, "func", params, ty.void_(), utils::Empty);
|
||||
auto src = f->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
@@ -49,7 +49,7 @@ TEST_F(FunctionTest, Assert_InvalidName) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.Func("", {}, b.ty.void_(), {});
|
||||
b.Func("", utils::Empty, b.ty.void_(), utils::Empty);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -58,20 +58,20 @@ TEST_F(FunctionTest, Assert_Null_ReturnType) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.Func("f", {}, nullptr, {});
|
||||
b.Func("f", utils::Empty, nullptr, utils::Empty);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Assert_Null_Param) {
|
||||
using ParamList = utils::Vector<const ast::Parameter*, 2>;
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
ParameterList params;
|
||||
params.push_back(b.Param("var", b.ty.i32()));
|
||||
params.push_back(nullptr);
|
||||
|
||||
b.Func("f", params, b.ty.void_(), {});
|
||||
ParamList params;
|
||||
params.Push(b.Param("var", b.ty.i32()));
|
||||
params.Push(nullptr);
|
||||
b.Func("f", params, b.ty.void_(), utils::Empty);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -81,7 +81,7 @@ TEST_F(FunctionTest, Assert_DifferentProgramID_Symbol) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Func(b2.Sym("func"), {}, b1.ty.void_(), {});
|
||||
b1.Func(b2.Sym("func"), utils::Empty, b1.ty.void_(), utils::Empty);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -91,7 +91,11 @@ TEST_F(FunctionTest, Assert_DifferentProgramID_Param) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Func("func", {b2.Param("var", b2.ty.i32())}, b1.ty.void_(), {});
|
||||
b1.Func("func",
|
||||
utils::Vector{
|
||||
b2.Param("var", b2.ty.i32()),
|
||||
},
|
||||
b1.ty.void_(), utils::Empty);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -101,8 +105,8 @@ TEST_F(FunctionTest, Assert_DifferentProgramID_Attr) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Func("func", {}, b1.ty.void_(), {},
|
||||
{
|
||||
b1.Func("func", utils::Empty, b1.ty.void_(), utils::Empty,
|
||||
utils::Vector{
|
||||
b2.WorkgroupSize(2_i, 4_i, 6_i),
|
||||
});
|
||||
},
|
||||
@@ -114,8 +118,8 @@ TEST_F(FunctionTest, Assert_DifferentProgramID_ReturnAttr) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Func("func", {}, b1.ty.void_(), {}, {},
|
||||
{
|
||||
b1.Func("func", utils::Empty, b1.ty.void_(), utils::Empty, utils::Empty,
|
||||
utils::Vector{
|
||||
b2.WorkgroupSize(2_i, 4_i, 6_i),
|
||||
});
|
||||
},
|
||||
@@ -125,7 +129,7 @@ TEST_F(FunctionTest, Assert_DifferentProgramID_ReturnAttr) {
|
||||
using FunctionListTest = TestHelper;
|
||||
|
||||
TEST_F(FunctionListTest, FindSymbol) {
|
||||
auto* func = Func("main", {}, ty.f32(), {});
|
||||
auto* func = Func("main", utils::Empty, ty.f32(), utils::Empty);
|
||||
FunctionList list;
|
||||
list.Add(func);
|
||||
EXPECT_EQ(func, list.Find(Symbols().Register("main")));
|
||||
@@ -137,12 +141,12 @@ TEST_F(FunctionListTest, FindSymbolMissing) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionListTest, FindSymbolStage) {
|
||||
auto* fs = Func("main", {}, ty.f32(), {},
|
||||
{
|
||||
auto* fs = Func("main", utils::Empty, ty.f32(), utils::Empty,
|
||||
utils::Vector{
|
||||
Stage(PipelineStage::kFragment),
|
||||
});
|
||||
auto* vs = Func("main", {}, ty.f32(), {},
|
||||
{
|
||||
auto* vs = Func("main", utils::Empty, ty.f32(), utils::Empty,
|
||||
utils::Vector{
|
||||
Stage(PipelineStage::kVertex),
|
||||
});
|
||||
FunctionList list;
|
||||
@@ -154,8 +158,8 @@ TEST_F(FunctionListTest, FindSymbolStage) {
|
||||
|
||||
TEST_F(FunctionListTest, FindSymbolStageMissing) {
|
||||
FunctionList list;
|
||||
list.Add(Func("main", {}, ty.f32(), {},
|
||||
{
|
||||
list.Add(Func("main", utils::Empty, ty.f32(), utils::Empty,
|
||||
utils::Vector{
|
||||
Stage(PipelineStage::kFragment),
|
||||
}));
|
||||
EXPECT_EQ(nullptr, list.Find(Symbols().Register("main"), PipelineStage::kVertex));
|
||||
@@ -163,8 +167,8 @@ TEST_F(FunctionListTest, FindSymbolStageMissing) {
|
||||
|
||||
TEST_F(FunctionListTest, HasStage) {
|
||||
FunctionList list;
|
||||
list.Add(Func("main", {}, ty.f32(), {},
|
||||
{
|
||||
list.Add(Func("main", utils::Empty, ty.f32(), utils::Empty,
|
||||
utils::Vector{
|
||||
Stage(PipelineStage::kFragment),
|
||||
}));
|
||||
EXPECT_TRUE(list.HasStage(PipelineStage::kFragment));
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "src/tint/ast/let.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::Let);
|
||||
@@ -26,8 +28,8 @@ Let::Let(ProgramID pid,
|
||||
const Symbol& sym,
|
||||
const ast::Type* ty,
|
||||
const Expression* ctor,
|
||||
AttributeList attrs)
|
||||
: Base(pid, nid, src, sym, ty, ctor, attrs) {
|
||||
utils::VectorRef<const Attribute*> attrs)
|
||||
: Base(pid, nid, src, sym, ty, ctor, std::move(attrs)) {
|
||||
TINT_ASSERT(AST, ctor != nullptr);
|
||||
}
|
||||
|
||||
@@ -45,7 +47,7 @@ const Let* Let::Clone(CloneContext* ctx) const {
|
||||
auto* ty = ctx->Clone(type);
|
||||
auto* ctor = ctx->Clone(constructor);
|
||||
auto attrs = ctx->Clone(attributes);
|
||||
return ctx->dst->create<Let>(src, sym, ty, ctor, attrs);
|
||||
return ctx->dst->create<Let>(src, sym, ty, ctor, std::move(attrs));
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -43,7 +43,7 @@ class Let final : public Castable<Let, Variable> {
|
||||
const Symbol& sym,
|
||||
const ast::Type* type,
|
||||
const Expression* constructor,
|
||||
AttributeList attributes);
|
||||
utils::VectorRef<const Attribute*> attributes);
|
||||
|
||||
/// Move constructor
|
||||
Let(Let&&);
|
||||
|
||||
@@ -31,9 +31,9 @@ TEST_F(LoopStatementTest, Creation) {
|
||||
auto* continuing = Block(create<DiscardStatement>());
|
||||
|
||||
auto* l = create<LoopStatement>(body, continuing);
|
||||
ASSERT_EQ(l->body->statements.size(), 1u);
|
||||
ASSERT_EQ(l->body->statements.Length(), 1u);
|
||||
EXPECT_EQ(l->body->statements[0], b);
|
||||
ASSERT_EQ(l->continuing->statements.size(), 1u);
|
||||
ASSERT_EQ(l->continuing->statements.Length(), 1u);
|
||||
EXPECT_EQ(l->continuing->statements[0], continuing->Last());
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ Module::Module(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, sr
|
||||
Module::Module(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
std::vector<const ast::Node*> global_decls)
|
||||
utils::VectorRef<const ast::Node*> global_decls)
|
||||
: Base(pid, nid, src), global_declarations_(std::move(global_decls)) {
|
||||
for (auto* decl : global_declarations_) {
|
||||
if (decl == nullptr) {
|
||||
@@ -53,7 +53,7 @@ const ast::TypeDecl* Module::LookupType(Symbol name) const {
|
||||
void Module::AddGlobalDeclaration(const tint::ast::Node* decl) {
|
||||
diag::List diags;
|
||||
BinGlobalDeclaration(decl, diags);
|
||||
global_declarations_.emplace_back(decl);
|
||||
global_declarations_.Push(decl);
|
||||
}
|
||||
|
||||
void Module::BinGlobalDeclaration(const tint::ast::Node* decl, diag::List& diags) {
|
||||
@@ -61,19 +61,19 @@ void Module::BinGlobalDeclaration(const tint::ast::Node* decl, diag::List& diags
|
||||
decl, //
|
||||
[&](const ast::TypeDecl* type) {
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id);
|
||||
type_decls_.push_back(type);
|
||||
type_decls_.Push(type);
|
||||
},
|
||||
[&](const Function* func) {
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id);
|
||||
functions_.push_back(func);
|
||||
functions_.Push(func);
|
||||
},
|
||||
[&](const Variable* var) {
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, var, program_id);
|
||||
global_variables_.push_back(var);
|
||||
global_variables_.Push(var);
|
||||
},
|
||||
[&](const Enable* enable) {
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, enable, program_id);
|
||||
enables_.push_back(enable);
|
||||
enables_.Push(enable);
|
||||
},
|
||||
[&](Default) { TINT_ICE(AST, diags) << "Unknown global declaration type"; });
|
||||
}
|
||||
@@ -81,29 +81,29 @@ void Module::BinGlobalDeclaration(const tint::ast::Node* decl, diag::List& diags
|
||||
void Module::AddEnable(const ast::Enable* enable) {
|
||||
TINT_ASSERT(AST, enable);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, enable, program_id);
|
||||
global_declarations_.push_back(enable);
|
||||
enables_.push_back(enable);
|
||||
global_declarations_.Push(enable);
|
||||
enables_.Push(enable);
|
||||
}
|
||||
|
||||
void Module::AddGlobalVariable(const ast::Variable* var) {
|
||||
TINT_ASSERT(AST, var);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, var, program_id);
|
||||
global_variables_.push_back(var);
|
||||
global_declarations_.push_back(var);
|
||||
global_variables_.Push(var);
|
||||
global_declarations_.Push(var);
|
||||
}
|
||||
|
||||
void Module::AddTypeDecl(const ast::TypeDecl* type) {
|
||||
TINT_ASSERT(AST, type);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id);
|
||||
type_decls_.push_back(type);
|
||||
global_declarations_.push_back(type);
|
||||
type_decls_.Push(type);
|
||||
global_declarations_.Push(type);
|
||||
}
|
||||
|
||||
void Module::AddFunction(const ast::Function* func) {
|
||||
TINT_ASSERT(AST, func);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id);
|
||||
functions_.push_back(func);
|
||||
global_declarations_.push_back(func);
|
||||
functions_.Push(func);
|
||||
global_declarations_.Push(func);
|
||||
}
|
||||
|
||||
const Module* Module::Clone(CloneContext* ctx) const {
|
||||
@@ -117,10 +117,10 @@ void Module::Copy(CloneContext* ctx, const Module* src) {
|
||||
|
||||
// During the clone, declarations may have been placed into the module.
|
||||
// Clear everything out, as we're about to re-bin the declarations.
|
||||
type_decls_.clear();
|
||||
functions_.clear();
|
||||
global_variables_.clear();
|
||||
enables_.clear();
|
||||
type_decls_.Clear();
|
||||
functions_.Clear();
|
||||
global_variables_.Clear();
|
||||
enables_.Clear();
|
||||
|
||||
for (auto* decl : global_declarations_) {
|
||||
if (!decl) {
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
#define SRC_TINT_AST_MODULE_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "src/tint/ast/enable.h"
|
||||
#include "src/tint/ast/function.h"
|
||||
#include "src/tint/ast/type.h"
|
||||
#include "src/tint/utils/vector.h"
|
||||
|
||||
namespace tint::ast {
|
||||
|
||||
@@ -42,13 +42,16 @@ class Module final : public Castable<Module, Node> {
|
||||
/// @param src the source of this node
|
||||
/// @param global_decls the list of global types, functions, and variables, in
|
||||
/// the order they were declared in the source program
|
||||
Module(ProgramID pid, NodeID nid, const Source& src, std::vector<const Node*> global_decls);
|
||||
Module(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
utils::VectorRef<const ast::Node*> global_decls);
|
||||
|
||||
/// Destructor
|
||||
~Module() override;
|
||||
|
||||
/// @returns the declaration-ordered global declarations for the module
|
||||
const std::vector<const Node*>& GlobalDeclarations() const { return global_declarations_; }
|
||||
const auto& GlobalDeclarations() const { return global_declarations_; }
|
||||
|
||||
/// Add a enable directive to the Builder
|
||||
/// @param ext the enable directive to add
|
||||
@@ -74,26 +77,26 @@ class Module final : public Castable<Module, Node> {
|
||||
void AddGlobalDeclaration(const tint::ast::Node* decl);
|
||||
|
||||
/// @returns the global variables for the module
|
||||
const VariableList& GlobalVariables() const { return global_variables_; }
|
||||
const auto& GlobalVariables() const { return global_variables_; }
|
||||
|
||||
/// @returns the global variables for the module
|
||||
VariableList& GlobalVariables() { return global_variables_; }
|
||||
auto& GlobalVariables() { return global_variables_; }
|
||||
|
||||
/// @returns the global variable declarations of kind 'T' for the module
|
||||
template <typename T, typename = traits::EnableIfIsType<T, ast::Variable>>
|
||||
std::vector<const T*> Globals() const {
|
||||
std::vector<const T*> out;
|
||||
out.reserve(global_variables_.size());
|
||||
auto Globals() const {
|
||||
utils::Vector<const T*, 32> out;
|
||||
out.Reserve(global_variables_.Length());
|
||||
for (auto* global : global_variables_) {
|
||||
if (auto* var = global->As<T>()) {
|
||||
out.emplace_back(var);
|
||||
out.Push(var);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// @returns the extension set for the module
|
||||
const EnableList& Enables() const { return enables_; }
|
||||
const auto& Enables() const { return enables_; }
|
||||
|
||||
/// Adds a type declaration to the Builder.
|
||||
/// @param decl the type declaration to add
|
||||
@@ -104,7 +107,7 @@ class Module final : public Castable<Module, Node> {
|
||||
const TypeDecl* LookupType(Symbol name) const;
|
||||
|
||||
/// @returns the declared types in the module
|
||||
const std::vector<const TypeDecl*>& TypeDecls() const { return type_decls_; }
|
||||
const auto& TypeDecls() const { return type_decls_; }
|
||||
|
||||
/// Add a function to the Builder
|
||||
/// @param func the function to add
|
||||
@@ -131,11 +134,11 @@ class Module final : public Castable<Module, Node> {
|
||||
/// * #functions_
|
||||
void BinGlobalDeclaration(const tint::ast::Node* decl, diag::List& diags);
|
||||
|
||||
std::vector<const Node*> global_declarations_;
|
||||
std::vector<const TypeDecl*> type_decls_;
|
||||
utils::Vector<const Node*, 64> global_declarations_;
|
||||
utils::Vector<const TypeDecl*, 16> type_decls_;
|
||||
FunctionList functions_;
|
||||
VariableList global_variables_;
|
||||
EnableList enables_;
|
||||
utils::Vector<const Variable*, 32> global_variables_;
|
||||
utils::Vector<const Enable*, 8> enables_;
|
||||
};
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace {
|
||||
using ModuleTest = TestHelper;
|
||||
|
||||
TEST_F(ModuleTest, Creation) {
|
||||
EXPECT_EQ(Program(std::move(*this)).AST().Functions().size(), 0u);
|
||||
EXPECT_EQ(Program(std::move(*this)).AST().Functions().Length(), 0u);
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, LookupFunction) {
|
||||
@@ -61,8 +61,8 @@ TEST_F(ModuleTest, Assert_DifferentProgramID_Function) {
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.AST().AddFunction(b2.create<ast::Function>(b2.Symbols().Register("func"),
|
||||
ParameterList{}, b2.ty.f32(), b2.Block(),
|
||||
AttributeList{}, AttributeList{}));
|
||||
utils::Empty, b2.ty.f32(), b2.Block(),
|
||||
utils::Empty, utils::Empty));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -116,7 +116,7 @@ TEST_F(ModuleTest, CloneOrder) {
|
||||
ctx.Clone();
|
||||
|
||||
auto& decls = cloned.AST().GlobalDeclarations();
|
||||
ASSERT_EQ(decls.size(), 6u);
|
||||
ASSERT_EQ(decls.Length(), 6u);
|
||||
EXPECT_TRUE(decls[1]->Is<ast::Function>());
|
||||
EXPECT_TRUE(decls[3]->Is<ast::Alias>());
|
||||
EXPECT_TRUE(decls[5]->Is<ast::Variable>());
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "src/tint/ast/override.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::Override);
|
||||
@@ -26,8 +28,8 @@ Override::Override(ProgramID pid,
|
||||
const Symbol& sym,
|
||||
const ast::Type* ty,
|
||||
const Expression* ctor,
|
||||
AttributeList attrs)
|
||||
: Base(pid, nid, src, sym, ty, ctor, attrs) {}
|
||||
utils::VectorRef<const Attribute*> attrs)
|
||||
: Base(pid, nid, src, sym, ty, ctor, std::move(attrs)) {}
|
||||
|
||||
Override::Override(Override&&) = default;
|
||||
|
||||
@@ -43,7 +45,7 @@ const Override* Override::Clone(CloneContext* ctx) const {
|
||||
auto* ty = ctx->Clone(type);
|
||||
auto* ctor = ctx->Clone(constructor);
|
||||
auto attrs = ctx->Clone(attributes);
|
||||
return ctx->dst->create<Override>(src, sym, ty, ctor, attrs);
|
||||
return ctx->dst->create<Override>(src, sym, ty, ctor, std::move(attrs));
|
||||
}
|
||||
|
||||
std::string Override::Identifier(const SymbolTable& symbols) const {
|
||||
|
||||
@@ -46,7 +46,7 @@ class Override final : public Castable<Override, Variable> {
|
||||
const Symbol& sym,
|
||||
const ast::Type* type,
|
||||
const Expression* constructor,
|
||||
AttributeList attributes);
|
||||
utils::VectorRef<const Attribute*> attributes);
|
||||
|
||||
/// Move constructor
|
||||
Override(Override&&);
|
||||
|
||||
@@ -27,7 +27,7 @@ TEST_F(OverrideTest, Identifier_NoId) {
|
||||
}
|
||||
|
||||
TEST_F(OverrideTest, Identifier_WithId) {
|
||||
auto* o = Override("o", nullptr, Expr(f32(1.0)), {Id(4u)});
|
||||
auto* o = Override("o", nullptr, Expr(f32(1.0)), utils::Vector{Id(4u)});
|
||||
EXPECT_EQ(std::string("4"), o->Identifier(Symbols()));
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "src/tint/ast/parameter.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::Parameter);
|
||||
@@ -25,8 +27,8 @@ Parameter::Parameter(ProgramID pid,
|
||||
const Source& src,
|
||||
const Symbol& sym,
|
||||
const ast::Type* ty,
|
||||
AttributeList attrs)
|
||||
: Base(pid, nid, src, sym, ty, nullptr, attrs) {}
|
||||
utils::VectorRef<const Attribute*> attrs)
|
||||
: Base(pid, nid, src, sym, ty, nullptr, std::move(attrs)) {}
|
||||
|
||||
Parameter::Parameter(Parameter&&) = default;
|
||||
|
||||
@@ -41,7 +43,7 @@ const Parameter* Parameter::Clone(CloneContext* ctx) const {
|
||||
auto sym = ctx->Clone(symbol);
|
||||
auto* ty = ctx->Clone(type);
|
||||
auto attrs = ctx->Clone(attributes);
|
||||
return ctx->dst->create<Parameter>(src, sym, ty, attrs);
|
||||
return ctx->dst->create<Parameter>(src, sym, ty, std::move(attrs));
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -45,7 +45,7 @@ class Parameter final : public Castable<Parameter, Variable> {
|
||||
const Source& source,
|
||||
const Symbol& sym,
|
||||
const ast::Type* type,
|
||||
AttributeList attributes);
|
||||
utils::VectorRef<const Attribute*> attributes);
|
||||
|
||||
/// Move constructor
|
||||
Parameter(Parameter&&);
|
||||
@@ -63,9 +63,6 @@ class Parameter final : public Castable<Parameter, Variable> {
|
||||
const Parameter* Clone(CloneContext* ctx) const override;
|
||||
};
|
||||
|
||||
/// A list of parameters
|
||||
using ParameterList = std::vector<const Parameter*>;
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
#endif // SRC_TINT_AST_PARAMETER_H_
|
||||
|
||||
@@ -39,9 +39,6 @@ class Statement : public Castable<Statement, Node> {
|
||||
Statement(Statement&&);
|
||||
};
|
||||
|
||||
/// A list of statements
|
||||
using StatementList = std::vector<const Statement*>;
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
#endif // SRC_TINT_AST_STATEMENT_H_
|
||||
|
||||
@@ -26,8 +26,8 @@ Struct::Struct(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
Symbol n,
|
||||
StructMemberList m,
|
||||
AttributeList attrs)
|
||||
utils::VectorRef<const ast::StructMember*> m,
|
||||
utils::VectorRef<const ast::Attribute*> attrs)
|
||||
: Base(pid, nid, src, n), members(std::move(m)), attributes(std::move(attrs)) {
|
||||
for (auto* mem : members) {
|
||||
TINT_ASSERT(AST, mem);
|
||||
@@ -49,7 +49,7 @@ const Struct* Struct::Clone(CloneContext* ctx) const {
|
||||
auto n = ctx->Clone(name);
|
||||
auto mem = ctx->Clone(members);
|
||||
auto attrs = ctx->Clone(attributes);
|
||||
return ctx->dst->create<Struct>(src, n, mem, attrs);
|
||||
return ctx->dst->create<Struct>(src, n, std::move(mem), std::move(attrs));
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "src/tint/ast/attribute.h"
|
||||
#include "src/tint/ast/struct_member.h"
|
||||
#include "src/tint/ast/type_decl.h"
|
||||
#include "src/tint/utils/vector.h"
|
||||
|
||||
namespace tint::ast {
|
||||
|
||||
@@ -38,8 +39,8 @@ class Struct final : public Castable<Struct, TypeDecl> {
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
Symbol name,
|
||||
StructMemberList members,
|
||||
AttributeList attributes);
|
||||
utils::VectorRef<const ast::StructMember*> members,
|
||||
utils::VectorRef<const ast::Attribute*> attributes);
|
||||
/// Move constructor
|
||||
Struct(Struct&&);
|
||||
|
||||
@@ -52,10 +53,10 @@ class Struct final : public Castable<Struct, TypeDecl> {
|
||||
const Struct* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The members
|
||||
const StructMemberList members;
|
||||
const utils::Vector<const ast::StructMember*, 8> members;
|
||||
|
||||
/// The struct attributes
|
||||
const AttributeList attributes;
|
||||
const utils::Vector<const ast::Attribute*, 4> attributes;
|
||||
};
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -25,7 +25,7 @@ StructMember::StructMember(ProgramID pid,
|
||||
const Source& src,
|
||||
const Symbol& sym,
|
||||
const ast::Type* ty,
|
||||
AttributeList attrs)
|
||||
utils::VectorRef<const Attribute*> attrs)
|
||||
: Base(pid, nid, src), symbol(sym), type(ty), attributes(std::move(attrs)) {
|
||||
TINT_ASSERT(AST, type);
|
||||
TINT_ASSERT(AST, symbol.IsValid());
|
||||
@@ -46,7 +46,7 @@ const StructMember* StructMember::Clone(CloneContext* ctx) const {
|
||||
auto sym = ctx->Clone(symbol);
|
||||
auto* ty = ctx->Clone(type);
|
||||
auto attrs = ctx->Clone(attributes);
|
||||
return ctx->dst->create<StructMember>(src, sym, ty, attrs);
|
||||
return ctx->dst->create<StructMember>(src, sym, ty, std::move(attrs));
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#define SRC_TINT_AST_STRUCT_MEMBER_H_
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "src/tint/ast/attribute.h"
|
||||
|
||||
@@ -42,7 +41,7 @@ class StructMember final : public Castable<StructMember, Node> {
|
||||
const Source& src,
|
||||
const Symbol& sym,
|
||||
const ast::Type* type,
|
||||
AttributeList attributes);
|
||||
utils::VectorRef<const Attribute*> attributes);
|
||||
/// Move constructor
|
||||
StructMember(StructMember&&);
|
||||
|
||||
@@ -61,12 +60,9 @@ class StructMember final : public Castable<StructMember, Node> {
|
||||
const ast::Type* const type;
|
||||
|
||||
/// The attributes
|
||||
const AttributeList attributes;
|
||||
const utils::Vector<const Attribute*, 4> attributes;
|
||||
};
|
||||
|
||||
/// A list of struct members
|
||||
using StructMemberList = std::vector<const StructMember*>;
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
#endif // SRC_TINT_AST_STRUCT_MEMBER_H_
|
||||
|
||||
@@ -21,10 +21,10 @@ namespace {
|
||||
using StructMemberTest = TestHelper;
|
||||
|
||||
TEST_F(StructMemberTest, Creation) {
|
||||
auto* st = Member("a", ty.i32(), {MemberSize(4)});
|
||||
auto* st = Member("a", ty.i32(), utils::Vector{MemberSize(4)});
|
||||
EXPECT_EQ(st->symbol, Symbol(1, ID()));
|
||||
EXPECT_TRUE(st->type->Is<ast::I32>());
|
||||
EXPECT_EQ(st->attributes.size(), 1u);
|
||||
EXPECT_EQ(st->attributes.Length(), 1u);
|
||||
EXPECT_TRUE(st->attributes[0]->Is<StructMemberSizeAttribute>());
|
||||
EXPECT_EQ(st->source.range.begin.line, 0u);
|
||||
EXPECT_EQ(st->source.range.begin.column, 0u);
|
||||
@@ -37,7 +37,7 @@ TEST_F(StructMemberTest, CreationWithSource) {
|
||||
ty.i32());
|
||||
EXPECT_EQ(st->symbol, Symbol(1, ID()));
|
||||
EXPECT_TRUE(st->type->Is<ast::I32>());
|
||||
EXPECT_EQ(st->attributes.size(), 0u);
|
||||
EXPECT_EQ(st->attributes.Length(), 0u);
|
||||
EXPECT_EQ(st->source.range.begin.line, 27u);
|
||||
EXPECT_EQ(st->source.range.begin.column, 4u);
|
||||
EXPECT_EQ(st->source.range.end.line, 27u);
|
||||
@@ -66,7 +66,7 @@ TEST_F(StructMemberTest, Assert_Null_Attribute) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.Member("a", b.ty.i32(), {b.MemberSize(4), nullptr});
|
||||
b.Member("a", b.ty.i32(), utils::Vector{b.MemberSize(4), nullptr});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -76,7 +76,7 @@ TEST_F(StructMemberTest, Assert_DifferentProgramID_Symbol) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Member(b2.Sym("a"), b1.ty.i32(), {b1.MemberSize(4)});
|
||||
b1.Member(b2.Sym("a"), b1.ty.i32(), utils::Vector{b1.MemberSize(4)});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -86,7 +86,7 @@ TEST_F(StructMemberTest, Assert_DifferentProgramID_Attribute) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Member("a", b1.ty.i32(), {b2.MemberSize(4)});
|
||||
b1.Member("a", b1.ty.i32(), utils::Vector{b2.MemberSize(4)});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ using SpirvBlockAttribute = transform::AddSpirvBlockAttribute::SpirvBlockAttribu
|
||||
|
||||
TEST_F(AstStructTest, Creation) {
|
||||
auto name = Sym("s");
|
||||
auto* s = create<Struct>(name, StructMemberList{Member("a", ty.i32())}, AttributeList{});
|
||||
auto* s = create<Struct>(name, utils::Vector{Member("a", ty.i32())}, utils::Empty);
|
||||
EXPECT_EQ(s->name, name);
|
||||
EXPECT_EQ(s->members.size(), 1u);
|
||||
EXPECT_TRUE(s->attributes.empty());
|
||||
EXPECT_EQ(s->members.Length(), 1u);
|
||||
EXPECT_TRUE(s->attributes.IsEmpty());
|
||||
EXPECT_EQ(s->source.range.begin.line, 0u);
|
||||
EXPECT_EQ(s->source.range.begin.column, 0u);
|
||||
EXPECT_EQ(s->source.range.end.line, 0u);
|
||||
@@ -48,13 +48,14 @@ TEST_F(AstStructTest, Creation) {
|
||||
|
||||
TEST_F(AstStructTest, Creation_WithAttributes) {
|
||||
auto name = Sym("s");
|
||||
AttributeList attrs;
|
||||
attrs.push_back(ASTNodes().Create<SpirvBlockAttribute>(ID(), AllocateNodeID()));
|
||||
|
||||
auto* s = create<Struct>(name, StructMemberList{Member("a", ty.i32())}, attrs);
|
||||
auto* s = create<Struct>(name, utils::Vector{Member("a", ty.i32())},
|
||||
utils::Vector{
|
||||
ASTNodes().Create<SpirvBlockAttribute>(ID(), AllocateNodeID()),
|
||||
});
|
||||
EXPECT_EQ(s->name, name);
|
||||
EXPECT_EQ(s->members.size(), 1u);
|
||||
ASSERT_EQ(s->attributes.size(), 1u);
|
||||
EXPECT_EQ(s->members.Length(), 1u);
|
||||
ASSERT_EQ(s->attributes.Length(), 1u);
|
||||
EXPECT_TRUE(s->attributes[0]->Is<SpirvBlockAttribute>());
|
||||
EXPECT_EQ(s->source.range.begin.line, 0u);
|
||||
EXPECT_EQ(s->source.range.begin.column, 0u);
|
||||
@@ -66,11 +67,11 @@ TEST_F(AstStructTest, CreationWithSourceAndAttributes) {
|
||||
auto name = Sym("s");
|
||||
auto* s = create<Struct>(
|
||||
Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, name,
|
||||
StructMemberList{Member("a", ty.i32())},
|
||||
AttributeList{ASTNodes().Create<SpirvBlockAttribute>(ID(), AllocateNodeID())});
|
||||
utils::Vector{Member("a", ty.i32())},
|
||||
utils::Vector{ASTNodes().Create<SpirvBlockAttribute>(ID(), AllocateNodeID())});
|
||||
EXPECT_EQ(s->name, name);
|
||||
EXPECT_EQ(s->members.size(), 1u);
|
||||
ASSERT_EQ(s->attributes.size(), 1u);
|
||||
EXPECT_EQ(s->members.Length(), 1u);
|
||||
ASSERT_EQ(s->attributes.Length(), 1u);
|
||||
EXPECT_TRUE(s->attributes[0]->Is<SpirvBlockAttribute>());
|
||||
EXPECT_EQ(s->source.range.begin.line, 27u);
|
||||
EXPECT_EQ(s->source.range.begin.column, 4u);
|
||||
@@ -82,8 +83,8 @@ TEST_F(AstStructTest, Assert_Null_StructMember) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<Struct>(b.Sym("S"), StructMemberList{b.Member("a", b.ty.i32()), nullptr},
|
||||
AttributeList{});
|
||||
b.create<Struct>(b.Sym("S"), utils::Vector{b.Member("a", b.ty.i32()), nullptr},
|
||||
utils::Empty);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -92,8 +93,8 @@ TEST_F(AstStructTest, Assert_Null_Attribute) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<Struct>(b.Sym("S"), StructMemberList{b.Member("a", b.ty.i32())},
|
||||
AttributeList{nullptr});
|
||||
b.create<Struct>(b.Sym("S"), utils::Vector{b.Member("a", b.ty.i32())},
|
||||
utils::Vector<const ast::Attribute*, 1>{nullptr});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -103,8 +104,8 @@ TEST_F(AstStructTest, Assert_DifferentProgramID_StructMember) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<Struct>(b1.Sym("S"), StructMemberList{b2.Member("a", b2.ty.i32())},
|
||||
AttributeList{});
|
||||
b1.create<Struct>(b1.Sym("S"), utils::Vector{b2.Member("a", b2.ty.i32())},
|
||||
utils::Empty);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -114,8 +115,8 @@ TEST_F(AstStructTest, Assert_DifferentProgramID_Attribute) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<Struct>(b1.Sym("S"), StructMemberList{b1.Member("a", b1.ty.i32())},
|
||||
AttributeList{b2.ASTNodes().Create<SpirvBlockAttribute>(
|
||||
b1.create<Struct>(b1.Sym("S"), utils::Vector{b1.Member("a", b1.ty.i32())},
|
||||
utils::Vector{b2.ASTNodes().Create<SpirvBlockAttribute>(
|
||||
b2.ID(), b2.AllocateNodeID())});
|
||||
},
|
||||
"internal compiler error");
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "src/tint/ast/switch_statement.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::SwitchStatement);
|
||||
@@ -24,8 +26,8 @@ SwitchStatement::SwitchStatement(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
const Expression* cond,
|
||||
CaseStatementList b)
|
||||
: Base(pid, nid, src), condition(cond), body(b) {
|
||||
utils::VectorRef<const CaseStatement*> b)
|
||||
: Base(pid, nid, src), condition(cond), body(std::move(b)) {
|
||||
TINT_ASSERT(AST, condition);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id);
|
||||
for (auto* stmt : body) {
|
||||
@@ -43,7 +45,7 @@ const SwitchStatement* SwitchStatement::Clone(CloneContext* ctx) const {
|
||||
auto src = ctx->Clone(source);
|
||||
auto* cond = ctx->Clone(condition);
|
||||
auto b = ctx->Clone(body);
|
||||
return ctx->dst->create<SwitchStatement>(src, cond, b);
|
||||
return ctx->dst->create<SwitchStatement>(src, cond, std::move(b));
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -33,7 +33,7 @@ class SwitchStatement final : public Castable<SwitchStatement, Statement> {
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
const Expression* condition,
|
||||
CaseStatementList body);
|
||||
utils::VectorRef<const CaseStatement*> body);
|
||||
/// Move constructor
|
||||
SwitchStatement(SwitchStatement&&);
|
||||
~SwitchStatement() override;
|
||||
@@ -51,7 +51,7 @@ class SwitchStatement final : public Castable<SwitchStatement, Statement> {
|
||||
const Expression* const condition;
|
||||
|
||||
/// The Switch body
|
||||
const CaseStatementList body;
|
||||
const utils::Vector<const CaseStatement*, 4> body;
|
||||
SwitchStatement(const SwitchStatement&) = delete;
|
||||
};
|
||||
|
||||
|
||||
@@ -25,54 +25,47 @@ namespace {
|
||||
using SwitchStatementTest = TestHelper;
|
||||
|
||||
TEST_F(SwitchStatementTest, Creation) {
|
||||
CaseSelectorList lit;
|
||||
lit.push_back(Expr(1_u));
|
||||
|
||||
auto* case_stmt = create<CaseStatement>(utils::Vector{Expr(1_u)}, Block());
|
||||
auto* ident = Expr("ident");
|
||||
CaseStatementList body;
|
||||
auto* case_stmt = create<CaseStatement>(lit, Block());
|
||||
body.push_back(case_stmt);
|
||||
utils::Vector body{case_stmt};
|
||||
|
||||
auto* stmt = create<SwitchStatement>(ident, body);
|
||||
EXPECT_EQ(stmt->condition, ident);
|
||||
ASSERT_EQ(stmt->body.size(), 1u);
|
||||
ASSERT_EQ(stmt->body.Length(), 1u);
|
||||
EXPECT_EQ(stmt->body[0], case_stmt);
|
||||
}
|
||||
|
||||
TEST_F(SwitchStatementTest, Creation_WithSource) {
|
||||
auto* ident = Expr("ident");
|
||||
|
||||
auto* stmt =
|
||||
create<SwitchStatement>(Source{Source::Location{20, 2}}, ident, CaseStatementList());
|
||||
auto* stmt = create<SwitchStatement>(Source{Source::Location{20, 2}}, ident, utils::Empty);
|
||||
auto src = stmt->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(SwitchStatementTest, IsSwitch) {
|
||||
CaseSelectorList lit;
|
||||
lit.push_back(Expr(2_i));
|
||||
|
||||
utils::Vector lit{Expr(2_i)};
|
||||
auto* ident = Expr("ident");
|
||||
CaseStatementList body;
|
||||
body.push_back(create<CaseStatement>(lit, Block()));
|
||||
utils::Vector body{create<CaseStatement>(lit, Block())};
|
||||
|
||||
auto* stmt = create<SwitchStatement>(ident, body);
|
||||
EXPECT_TRUE(stmt->Is<SwitchStatement>());
|
||||
}
|
||||
|
||||
TEST_F(SwitchStatementTest, Assert_Null_Condition) {
|
||||
using CaseStatementList = utils::Vector<const ast::CaseStatement*, 2>;
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
CaseStatementList cases;
|
||||
cases.push_back(b.create<CaseStatement>(CaseSelectorList{b.Expr(1_i)}, b.Block()));
|
||||
cases.Push(b.create<CaseStatement>(utils::Vector{b.Expr(1_i)}, b.Block()));
|
||||
b.create<SwitchStatement>(nullptr, cases);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(SwitchStatementTest, Assert_Null_CaseStatement) {
|
||||
using CaseStatementList = utils::Vector<const ast::CaseStatement*, 2>;
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
@@ -86,9 +79,9 @@ TEST_F(SwitchStatementTest, Assert_DifferentProgramID_Condition) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<SwitchStatement>(b2.Expr(true), CaseStatementList{
|
||||
b1.create<SwitchStatement>(b2.Expr(true), utils::Vector{
|
||||
b1.create<CaseStatement>(
|
||||
CaseSelectorList{
|
||||
utils::Vector{
|
||||
b1.Expr(1_i),
|
||||
},
|
||||
b1.Block()),
|
||||
@@ -102,9 +95,9 @@ TEST_F(SwitchStatementTest, Assert_DifferentProgramID_CaseStatement) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<SwitchStatement>(b1.Expr(true), CaseStatementList{
|
||||
b1.create<SwitchStatement>(b1.Expr(true), utils::Vector{
|
||||
b2.create<CaseStatement>(
|
||||
CaseSelectorList{
|
||||
utils::Vector{
|
||||
b2.Expr(1_i),
|
||||
},
|
||||
b2.Block()),
|
||||
|
||||
@@ -82,7 +82,7 @@ bool TraverseExpressions(const ast::Expression* root, diag::List& diags, CALLBAC
|
||||
to_visit.Push({right, depth});
|
||||
}
|
||||
};
|
||||
auto push_list = [&](const std::vector<const ast::Expression*>& exprs, size_t depth) {
|
||||
auto push_list = [&](utils::VectorRef<const ast::Expression*> exprs, size_t depth) {
|
||||
if (ORDER == TraverseOrder::LeftToRight) {
|
||||
for (auto* expr : utils::Reverse(exprs)) {
|
||||
to_visit.Push({expr, depth});
|
||||
|
||||
@@ -97,19 +97,19 @@ TEST_F(TraverseExpressionsTest, DescendBitcastExpression) {
|
||||
auto* b2 = Bitcast<i32>(b1);
|
||||
auto* root = Bitcast<i32>(b2);
|
||||
{
|
||||
std::vector<const ast::Expression*> l2r;
|
||||
utils::Vector<const ast::Expression*, 8> l2r;
|
||||
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
||||
[&](const ast::Expression* expr) {
|
||||
l2r.push_back(expr);
|
||||
l2r.Push(expr);
|
||||
return ast::TraverseAction::Descend;
|
||||
});
|
||||
EXPECT_THAT(l2r, ElementsAre(root, b2, b1, b0, e));
|
||||
}
|
||||
{
|
||||
std::vector<const ast::Expression*> r2l;
|
||||
utils::Vector<const ast::Expression*, 8> r2l;
|
||||
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
||||
[&](const ast::Expression* expr) {
|
||||
r2l.push_back(expr);
|
||||
r2l.Push(expr);
|
||||
return ast::TraverseAction::Descend;
|
||||
});
|
||||
EXPECT_THAT(r2l, ElementsAre(root, b2, b1, b0, e));
|
||||
@@ -117,23 +117,23 @@ TEST_F(TraverseExpressionsTest, DescendBitcastExpression) {
|
||||
}
|
||||
|
||||
TEST_F(TraverseExpressionsTest, DescendCallExpression) {
|
||||
std::vector<const ast::Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
|
||||
std::vector<const ast::Expression*> c = {Call("a", e[0], e[1]), Call("b", e[2], e[3])};
|
||||
utils::Vector e{Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
|
||||
utils::Vector c{Call("a", e[0], e[1]), Call("b", e[2], e[3])};
|
||||
auto* root = Call("c", c[0], c[1]);
|
||||
{
|
||||
std::vector<const ast::Expression*> l2r;
|
||||
utils::Vector<const ast::Expression*, 8> l2r;
|
||||
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
||||
[&](const ast::Expression* expr) {
|
||||
l2r.push_back(expr);
|
||||
l2r.Push(expr);
|
||||
return ast::TraverseAction::Descend;
|
||||
});
|
||||
EXPECT_THAT(l2r, ElementsAre(root, c[0], e[0], e[1], c[1], e[2], e[3]));
|
||||
}
|
||||
{
|
||||
std::vector<const ast::Expression*> r2l;
|
||||
utils::Vector<const ast::Expression*, 8> r2l;
|
||||
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
||||
[&](const ast::Expression* expr) {
|
||||
r2l.push_back(expr);
|
||||
r2l.Push(expr);
|
||||
return ast::TraverseAction::Descend;
|
||||
});
|
||||
EXPECT_THAT(r2l, ElementsAre(root, c[1], e[3], e[2], c[0], e[1], e[0]));
|
||||
|
||||
@@ -28,8 +28,8 @@ Var::Var(ProgramID pid,
|
||||
StorageClass storage_class,
|
||||
Access access,
|
||||
const Expression* ctor,
|
||||
AttributeList attrs)
|
||||
: Base(pid, nid, src, sym, ty, ctor, attrs),
|
||||
utils::VectorRef<const Attribute*> attrs)
|
||||
: Base(pid, nid, src, sym, ty, ctor, std::move(attrs)),
|
||||
declared_storage_class(storage_class),
|
||||
declared_access(access) {}
|
||||
|
||||
@@ -48,7 +48,7 @@ const Var* Var::Clone(CloneContext* ctx) const {
|
||||
auto* ctor = ctx->Clone(constructor);
|
||||
auto attrs = ctx->Clone(attributes);
|
||||
return ctx->dst->create<Var>(src, sym, ty, declared_storage_class, declared_access, ctor,
|
||||
attrs);
|
||||
std::move(attrs));
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -59,7 +59,7 @@ class Var final : public Castable<Var, Variable> {
|
||||
StorageClass declared_storage_class,
|
||||
Access declared_access,
|
||||
const Expression* constructor,
|
||||
AttributeList attributes);
|
||||
utils::VectorRef<const Attribute*> attributes);
|
||||
|
||||
/// Move constructor
|
||||
Var(Var&&);
|
||||
|
||||
@@ -26,7 +26,7 @@ Variable::Variable(ProgramID pid,
|
||||
const Symbol& sym,
|
||||
const ast::Type* ty,
|
||||
const Expression* ctor,
|
||||
AttributeList attrs)
|
||||
utils::VectorRef<const Attribute*> attrs)
|
||||
: Base(pid, nid, src), symbol(sym), type(ty), constructor(ctor), attributes(std::move(attrs)) {
|
||||
TINT_ASSERT(AST, symbol.IsValid());
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id);
|
||||
|
||||
@@ -67,7 +67,7 @@ class Variable : public Castable<Variable, Node> {
|
||||
const Symbol& sym,
|
||||
const ast::Type* type,
|
||||
const Expression* constructor,
|
||||
AttributeList attributes);
|
||||
utils::VectorRef<const Attribute*> attributes);
|
||||
|
||||
/// Move constructor
|
||||
Variable(Variable&&);
|
||||
@@ -95,12 +95,9 @@ class Variable : public Castable<Variable, Node> {
|
||||
const Expression* const constructor;
|
||||
|
||||
/// The attributes attached to this variable
|
||||
const AttributeList attributes;
|
||||
const utils::Vector<const Attribute*, 2> attributes;
|
||||
};
|
||||
|
||||
/// A list of variables
|
||||
using VariableList = std::vector<const Variable*>;
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
#endif // SRC_TINT_AST_VARIABLE_H_
|
||||
|
||||
@@ -38,7 +38,7 @@ TEST_F(VariableTest, Creation) {
|
||||
|
||||
TEST_F(VariableTest, CreationWithSource) {
|
||||
auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, "i",
|
||||
ty.f32(), StorageClass::kPrivate, nullptr, AttributeList{});
|
||||
ty.f32(), StorageClass::kPrivate, nullptr, utils::Empty);
|
||||
|
||||
EXPECT_EQ(v->symbol, Symbol(1, ID()));
|
||||
EXPECT_EQ(v->declared_storage_class, StorageClass::kPrivate);
|
||||
@@ -51,7 +51,7 @@ TEST_F(VariableTest, CreationWithSource) {
|
||||
|
||||
TEST_F(VariableTest, CreationEmpty) {
|
||||
auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, "a_var",
|
||||
ty.i32(), StorageClass::kWorkgroup, nullptr, AttributeList{});
|
||||
ty.i32(), StorageClass::kWorkgroup, nullptr, utils::Empty);
|
||||
|
||||
EXPECT_EQ(v->symbol, Symbol(1, ID()));
|
||||
EXPECT_EQ(v->declared_storage_class, StorageClass::kWorkgroup);
|
||||
@@ -93,7 +93,7 @@ TEST_F(VariableTest, Assert_DifferentProgramID_Constructor) {
|
||||
|
||||
TEST_F(VariableTest, WithAttributes) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr,
|
||||
AttributeList{
|
||||
utils::Vector{
|
||||
create<LocationAttribute>(1u),
|
||||
create<BuiltinAttribute>(BuiltinValue::kPosition),
|
||||
create<IdAttribute>(1200u),
|
||||
@@ -111,7 +111,7 @@ TEST_F(VariableTest, WithAttributes) {
|
||||
|
||||
TEST_F(VariableTest, BindingPoint) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr,
|
||||
AttributeList{
|
||||
utils::Vector{
|
||||
create<BindingAttribute>(2u),
|
||||
create<GroupAttribute>(1u),
|
||||
});
|
||||
@@ -123,7 +123,7 @@ TEST_F(VariableTest, BindingPoint) {
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, BindingPointAttributes) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr, AttributeList{});
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr, utils::Empty);
|
||||
EXPECT_FALSE(var->BindingPoint());
|
||||
EXPECT_EQ(var->BindingPoint().group, nullptr);
|
||||
EXPECT_EQ(var->BindingPoint().binding, nullptr);
|
||||
@@ -131,7 +131,7 @@ TEST_F(VariableTest, BindingPointAttributes) {
|
||||
|
||||
TEST_F(VariableTest, BindingPointMissingGroupAttribute) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr,
|
||||
AttributeList{
|
||||
utils::Vector{
|
||||
create<BindingAttribute>(2u),
|
||||
});
|
||||
EXPECT_FALSE(var->BindingPoint());
|
||||
@@ -142,7 +142,7 @@ TEST_F(VariableTest, BindingPointMissingGroupAttribute) {
|
||||
|
||||
TEST_F(VariableTest, BindingPointMissingBindingAttribute) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr,
|
||||
AttributeList{create<GroupAttribute>(1u)});
|
||||
utils::Vector{create<GroupAttribute>(1u)});
|
||||
EXPECT_FALSE(var->BindingPoint());
|
||||
ASSERT_NE(var->BindingPoint().group, nullptr);
|
||||
EXPECT_EQ(var->BindingPoint().group->value, 1u);
|
||||
|
||||
Reference in New Issue
Block a user