ast: Rename 'array accessor' to 'index accessor'
This cleans up the remnants of ArrayAccessorExpression which was renamed
in a838bb718
.
Change-Id: Ie2c67a49e63774d8b153ec17c3185652708a91e5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68942
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
parent
8bc1a3045d
commit
6595b386b5
|
@ -488,7 +488,7 @@ fn f() {
|
|||
->body->statements[2]
|
||||
->As<ast::AssignmentStatement>()
|
||||
->lhs->As<ast::IndexAccessorExpression>()
|
||||
->array->As<ast::UnaryOpExpression>()
|
||||
->object->As<ast::UnaryOpExpression>()
|
||||
->expr->As<ast::UnaryOpExpression>()
|
||||
->expr);
|
||||
ASSERT_NE(use_id, 0);
|
||||
|
@ -538,7 +538,7 @@ fn f(b: ptr<function, vec2<u32>>) {
|
|||
->body->statements[2]
|
||||
->As<ast::AssignmentStatement>()
|
||||
->lhs->As<ast::IndexAccessorExpression>()
|
||||
->array->As<ast::UnaryOpExpression>()
|
||||
->object->As<ast::UnaryOpExpression>()
|
||||
->expr);
|
||||
ASSERT_NE(use_id, 0);
|
||||
|
||||
|
@ -585,7 +585,7 @@ fn f() {
|
|||
->body->statements[1]
|
||||
->As<ast::AssignmentStatement>()
|
||||
->lhs->As<ast::IndexAccessorExpression>()
|
||||
->array->As<ast::UnaryOpExpression>()
|
||||
->object->As<ast::UnaryOpExpression>()
|
||||
->expr->As<ast::UnaryOpExpression>()
|
||||
->expr);
|
||||
ASSERT_NE(use_id, 0);
|
||||
|
@ -613,15 +613,15 @@ fn f() {
|
|||
|
||||
NodeIdMap node_id_map(program);
|
||||
|
||||
auto use_id =
|
||||
node_id_map.GetId(program.AST()
|
||||
.Functions()[0]
|
||||
->body->statements[1]
|
||||
->As<ast::VariableDeclStatement>()
|
||||
->variable->constructor->As<ast::IndexAccessorExpression>()
|
||||
->array->As<ast::UnaryOpExpression>()
|
||||
->expr->As<ast::UnaryOpExpression>()
|
||||
->expr);
|
||||
auto use_id = node_id_map.GetId(
|
||||
program.AST()
|
||||
.Functions()[0]
|
||||
->body->statements[1]
|
||||
->As<ast::VariableDeclStatement>()
|
||||
->variable->constructor->As<ast::IndexAccessorExpression>()
|
||||
->object->As<ast::UnaryOpExpression>()
|
||||
->expr->As<ast::UnaryOpExpression>()
|
||||
->expr);
|
||||
ASSERT_NE(use_id, 0);
|
||||
|
||||
auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[0]);
|
||||
|
@ -649,14 +649,14 @@ fn f() {
|
|||
|
||||
NodeIdMap node_id_map(program);
|
||||
|
||||
auto use_id =
|
||||
node_id_map.GetId(program.AST()
|
||||
.Functions()[0]
|
||||
->body->statements[3]
|
||||
->As<ast::VariableDeclStatement>()
|
||||
->variable->constructor->As<ast::IndexAccessorExpression>()
|
||||
->array->As<ast::UnaryOpExpression>()
|
||||
->expr);
|
||||
auto use_id = node_id_map.GetId(
|
||||
program.AST()
|
||||
.Functions()[0]
|
||||
->body->statements[3]
|
||||
->As<ast::VariableDeclStatement>()
|
||||
->variable->constructor->As<ast::IndexAccessorExpression>()
|
||||
->object->As<ast::UnaryOpExpression>()
|
||||
->expr);
|
||||
ASSERT_NE(use_id, 0);
|
||||
|
||||
auto replacement_id = node_id_map.GetId(program.AST()
|
||||
|
|
|
@ -23,11 +23,11 @@ namespace ast {
|
|||
|
||||
IndexAccessorExpression::IndexAccessorExpression(ProgramID pid,
|
||||
const Source& src,
|
||||
const Expression* arr,
|
||||
const Expression* obj,
|
||||
const Expression* idx)
|
||||
: Base(pid, src), array(arr), index(idx) {
|
||||
TINT_ASSERT(AST, array);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, array, program_id);
|
||||
: Base(pid, src), object(obj), index(idx) {
|
||||
TINT_ASSERT(AST, object);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, object, program_id);
|
||||
TINT_ASSERT(AST, idx);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, idx, program_id);
|
||||
}
|
||||
|
@ -41,9 +41,9 @@ const IndexAccessorExpression* IndexAccessorExpression::Clone(
|
|||
CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto* arr = ctx->Clone(array);
|
||||
auto* obj = ctx->Clone(object);
|
||||
auto* idx = ctx->Clone(index);
|
||||
return ctx->dst->create<IndexAccessorExpression>(src, arr, idx);
|
||||
return ctx->dst->create<IndexAccessorExpression>(src, obj, idx);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
|
|
|
@ -20,18 +20,18 @@
|
|||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// An array accessor expression
|
||||
/// An index accessor expression
|
||||
class IndexAccessorExpression
|
||||
: public Castable<IndexAccessorExpression, Expression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param program_id the identifier of the program that owns this node
|
||||
/// @param source the array accessor source
|
||||
/// @param arr the array
|
||||
/// @param source the index accessor source
|
||||
/// @param obj the object
|
||||
/// @param idx the index expression
|
||||
IndexAccessorExpression(ProgramID program_id,
|
||||
const Source& source,
|
||||
const Expression* arr,
|
||||
const Expression* obj,
|
||||
const Expression* idx);
|
||||
/// Move constructor
|
||||
IndexAccessorExpression(IndexAccessorExpression&&);
|
||||
|
@ -43,8 +43,8 @@ class IndexAccessorExpression
|
|||
/// @return the newly cloned node
|
||||
const IndexAccessorExpression* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// the array
|
||||
const Expression* const array;
|
||||
/// the array, vector or matrix
|
||||
const Expression* const object;
|
||||
|
||||
/// the index expression
|
||||
const Expression* const index;
|
||||
|
|
|
@ -22,29 +22,29 @@ namespace {
|
|||
using IndexAccessorExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(IndexAccessorExpressionTest, Create) {
|
||||
auto* ary = Expr("ary");
|
||||
auto* obj = Expr("obj");
|
||||
auto* idx = Expr("idx");
|
||||
|
||||
auto* exp = IndexAccessor(ary, idx);
|
||||
ASSERT_EQ(exp->array, ary);
|
||||
auto* exp = IndexAccessor(obj, idx);
|
||||
ASSERT_EQ(exp->object, obj);
|
||||
ASSERT_EQ(exp->index, idx);
|
||||
}
|
||||
|
||||
TEST_F(IndexAccessorExpressionTest, CreateWithSource) {
|
||||
auto* ary = Expr("ary");
|
||||
auto* obj = Expr("obj");
|
||||
auto* idx = Expr("idx");
|
||||
|
||||
auto* exp = IndexAccessor(Source{{20, 2}}, ary, idx);
|
||||
auto* exp = IndexAccessor(Source{{20, 2}}, obj, idx);
|
||||
auto src = exp->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(IndexAccessorExpressionTest, IsIndexAccessor) {
|
||||
auto* ary = Expr("ary");
|
||||
auto* obj = Expr("obj");
|
||||
auto* idx = Expr("idx");
|
||||
|
||||
auto* exp = IndexAccessor(ary, idx);
|
||||
auto* exp = IndexAccessor(obj, idx);
|
||||
EXPECT_TRUE(exp->Is<IndexAccessorExpression>());
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ bool TraverseExpressions(const ast::Expression* root,
|
|||
}
|
||||
|
||||
if (auto* idx = expr->As<IndexAccessorExpression>()) {
|
||||
push_pair(idx->array, idx->index);
|
||||
push_pair(idx->object, idx->index);
|
||||
} else if (auto* bin_op = expr->As<BinaryExpression>()) {
|
||||
push_pair(bin_op->lhs, bin_op->rhs);
|
||||
} else if (auto* bitcast = expr->As<BitcastExpression>()) {
|
||||
|
|
|
@ -1748,29 +1748,29 @@ class ProgramBuilder {
|
|||
}
|
||||
|
||||
/// @param source the source information
|
||||
/// @param arr the array argument for the array accessor expression
|
||||
/// @param idx the index argument for the array accessor expression
|
||||
/// @param obj the object for the index accessor expression
|
||||
/// @param idx the index argument for the index accessor expression
|
||||
/// @returns a `ast::IndexAccessorExpression` that indexes `arr` with `idx`
|
||||
template <typename ARR, typename IDX>
|
||||
template <typename OBJ, typename IDX>
|
||||
const ast::IndexAccessorExpression* IndexAccessor(const Source& source,
|
||||
ARR&& arr,
|
||||
OBJ&& obj,
|
||||
IDX&& idx) {
|
||||
return create<ast::IndexAccessorExpression>(
|
||||
source, Expr(std::forward<ARR>(arr)), Expr(std::forward<IDX>(idx)));
|
||||
source, Expr(std::forward<OBJ>(obj)), Expr(std::forward<IDX>(idx)));
|
||||
}
|
||||
|
||||
/// @param arr the array argument for the array accessor expression
|
||||
/// @param idx the index argument for the array accessor expression
|
||||
/// @param obj the object for the index accessor expression
|
||||
/// @param idx the index argument for the index accessor expression
|
||||
/// @returns a `ast::IndexAccessorExpression` that indexes `arr` with `idx`
|
||||
template <typename ARR, typename IDX>
|
||||
const ast::IndexAccessorExpression* IndexAccessor(ARR&& arr, IDX&& idx) {
|
||||
return create<ast::IndexAccessorExpression>(Expr(std::forward<ARR>(arr)),
|
||||
template <typename OBJ, typename IDX>
|
||||
const ast::IndexAccessorExpression* IndexAccessor(OBJ&& obj, IDX&& idx) {
|
||||
return create<ast::IndexAccessorExpression>(Expr(std::forward<OBJ>(obj)),
|
||||
Expr(std::forward<IDX>(idx)));
|
||||
}
|
||||
|
||||
/// @param source the source information
|
||||
/// @param obj the object for the member accessor expression
|
||||
/// @param idx the index argument for the array accessor expression
|
||||
/// @param idx the index argument for the member accessor expression
|
||||
/// @returns a `ast::MemberAccessorExpression` that indexes `obj` with `idx`
|
||||
template <typename OBJ, typename IDX>
|
||||
const ast::MemberAccessorExpression* MemberAccessor(const Source& source,
|
||||
|
@ -1781,7 +1781,7 @@ class ProgramBuilder {
|
|||
}
|
||||
|
||||
/// @param obj the object for the member accessor expression
|
||||
/// @param idx the index argument for the array accessor expression
|
||||
/// @param idx the index argument for the member accessor expression
|
||||
/// @returns a `ast::MemberAccessorExpression` that indexes `obj` with `idx`
|
||||
template <typename OBJ, typename IDX>
|
||||
const ast::MemberAccessorExpression* MemberAccessor(OBJ&& obj, IDX&& idx) {
|
||||
|
|
|
@ -2266,7 +2266,7 @@ Maybe<const ast::Expression*> ParserImpl::postfix_expression(
|
|||
return add_error(peek(), "unable to parse expression inside []");
|
||||
}
|
||||
|
||||
if (!expect("array accessor", Token::Type::kBracketRight)) {
|
||||
if (!expect("index accessor", Token::Type::kBracketRight)) {
|
||||
return Failure::kErrored;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,14 +64,14 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
|
|||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("d"));
|
||||
|
||||
ASSERT_TRUE(mem->structure->Is<ast::IndexAccessorExpression>());
|
||||
auto* ary = mem->structure->As<ast::IndexAccessorExpression>();
|
||||
auto* idx = mem->structure->As<ast::IndexAccessorExpression>();
|
||||
|
||||
ASSERT_NE(ary->index, nullptr);
|
||||
ASSERT_TRUE(ary->index->Is<ast::SintLiteral>());
|
||||
EXPECT_EQ(ary->index->As<ast::SintLiteral>()->value, 2);
|
||||
ASSERT_NE(idx->index, nullptr);
|
||||
ASSERT_TRUE(idx->index->Is<ast::SintLiteral>());
|
||||
EXPECT_EQ(idx->index->As<ast::SintLiteral>()->value, 2);
|
||||
|
||||
ASSERT_TRUE(ary->array->Is<ast::MemberAccessorExpression>());
|
||||
mem = ary->array->As<ast::MemberAccessorExpression>();
|
||||
ASSERT_TRUE(idx->object->Is<ast::MemberAccessorExpression>());
|
||||
mem = idx->object->As<ast::MemberAccessorExpression>();
|
||||
ASSERT_TRUE(mem->member->Is<ast::IdentifierExpression>());
|
||||
ident = mem->member->As<ast::IdentifierExpression>();
|
||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("c"));
|
||||
|
|
|
@ -58,16 +58,16 @@ TEST_F(ParserImplErrorTest, AliasDeclInvalidDeco) {
|
|||
" ^^^^^\n");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplErrorTest, ArrayIndexExprInvalidExpr) {
|
||||
TEST_F(ParserImplErrorTest, IndexExprInvalidExpr) {
|
||||
EXPECT("fn f() { x = y[^]; }",
|
||||
"test.wgsl:1:16 error: unable to parse expression inside []\n"
|
||||
"fn f() { x = y[^]; }\n"
|
||||
" ^\n");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplErrorTest, ArrayIndexExprMissingRBracket) {
|
||||
TEST_F(ParserImplErrorTest, IndexExprMissingRBracket) {
|
||||
EXPECT("fn f() { x = y[1; }",
|
||||
"test.wgsl:1:17 error: expected ']' for array accessor\n"
|
||||
"test.wgsl:1:17 error: expected ']' for index accessor\n"
|
||||
"fn f() { x = y[1; }\n"
|
||||
" ^\n");
|
||||
}
|
||||
|
|
|
@ -28,14 +28,14 @@ TEST_F(ParserImplTest, SingularExpression_Array_ConstantIndex) {
|
|||
ASSERT_NE(e.value, nullptr);
|
||||
|
||||
ASSERT_TRUE(e->Is<ast::IndexAccessorExpression>());
|
||||
auto* ary = e->As<ast::IndexAccessorExpression>();
|
||||
auto* idx = e->As<ast::IndexAccessorExpression>();
|
||||
|
||||
ASSERT_TRUE(ary->array->Is<ast::IdentifierExpression>());
|
||||
auto* ident = ary->array->As<ast::IdentifierExpression>();
|
||||
ASSERT_TRUE(idx->object->Is<ast::IdentifierExpression>());
|
||||
auto* ident = idx->object->As<ast::IdentifierExpression>();
|
||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
||||
|
||||
ASSERT_TRUE(ary->index->Is<ast::SintLiteral>());
|
||||
EXPECT_EQ(ary->index->As<ast::SintLiteral>()->value, 1);
|
||||
ASSERT_TRUE(idx->index->Is<ast::SintLiteral>());
|
||||
EXPECT_EQ(idx->index->As<ast::SintLiteral>()->value, 1);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SingularExpression_Array_ExpressionIndex) {
|
||||
|
@ -47,13 +47,13 @@ TEST_F(ParserImplTest, SingularExpression_Array_ExpressionIndex) {
|
|||
ASSERT_NE(e.value, nullptr);
|
||||
|
||||
ASSERT_TRUE(e->Is<ast::IndexAccessorExpression>());
|
||||
auto* ary = e->As<ast::IndexAccessorExpression>();
|
||||
auto* idx = e->As<ast::IndexAccessorExpression>();
|
||||
|
||||
ASSERT_TRUE(ary->array->Is<ast::IdentifierExpression>());
|
||||
auto* ident = ary->array->As<ast::IdentifierExpression>();
|
||||
ASSERT_TRUE(idx->object->Is<ast::IdentifierExpression>());
|
||||
auto* ident = idx->object->As<ast::IdentifierExpression>();
|
||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
||||
|
||||
ASSERT_TRUE(ary->index->Is<ast::BinaryExpression>());
|
||||
ASSERT_TRUE(idx->index->Is<ast::BinaryExpression>());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SingularExpression_Array_MissingIndex) {
|
||||
|
@ -73,7 +73,7 @@ TEST_F(ParserImplTest, SingularExpression_Array_MissingRightBrace) {
|
|||
EXPECT_TRUE(e.errored);
|
||||
EXPECT_EQ(e.value, nullptr);
|
||||
EXPECT_TRUE(p->has_error());
|
||||
EXPECT_EQ(p->error(), "1:4: expected ']' for array accessor");
|
||||
EXPECT_EQ(p->error(), "1:4: expected ']' for index accessor");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SingularExpression_Array_InvalidIndex) {
|
||||
|
@ -213,19 +213,19 @@ TEST_F(ParserImplTest, SingularExpression_Array_NestedIndexAccessor) {
|
|||
const auto* outer_accessor = e->As<ast::IndexAccessorExpression>();
|
||||
ASSERT_TRUE(outer_accessor);
|
||||
|
||||
const auto* outer_array =
|
||||
outer_accessor->array->As<ast::IdentifierExpression>();
|
||||
ASSERT_TRUE(outer_array);
|
||||
EXPECT_EQ(outer_array->symbol, p->builder().Symbols().Get("a"));
|
||||
const auto* outer_object =
|
||||
outer_accessor->object->As<ast::IdentifierExpression>();
|
||||
ASSERT_TRUE(outer_object);
|
||||
EXPECT_EQ(outer_object->symbol, p->builder().Symbols().Get("a"));
|
||||
|
||||
const auto* inner_accessor =
|
||||
outer_accessor->index->As<ast::IndexAccessorExpression>();
|
||||
ASSERT_TRUE(inner_accessor);
|
||||
|
||||
const auto* inner_array =
|
||||
inner_accessor->array->As<ast::IdentifierExpression>();
|
||||
ASSERT_TRUE(inner_array);
|
||||
EXPECT_EQ(inner_array->symbol, p->builder().Symbols().Get("b"));
|
||||
const auto* inner_object =
|
||||
inner_accessor->object->As<ast::IdentifierExpression>();
|
||||
ASSERT_TRUE(inner_object);
|
||||
EXPECT_EQ(inner_object->symbol, p->builder().Symbols().Get("b"));
|
||||
|
||||
const auto* index_expr =
|
||||
inner_accessor->index->As<ast::IdentifierExpression>();
|
||||
|
|
|
@ -29,13 +29,13 @@ TEST_F(ParserImplTest, UnaryExpression_Postix) {
|
|||
ASSERT_NE(e.value, nullptr);
|
||||
|
||||
ASSERT_TRUE(e->Is<ast::IndexAccessorExpression>());
|
||||
auto* ary = e->As<ast::IndexAccessorExpression>();
|
||||
ASSERT_TRUE(ary->array->Is<ast::IdentifierExpression>());
|
||||
auto* ident = ary->array->As<ast::IdentifierExpression>();
|
||||
auto* idx = e->As<ast::IndexAccessorExpression>();
|
||||
ASSERT_TRUE(idx->object->Is<ast::IdentifierExpression>());
|
||||
auto* ident = idx->object->As<ast::IdentifierExpression>();
|
||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
||||
|
||||
ASSERT_TRUE(ary->index->Is<ast::SintLiteral>());
|
||||
ASSERT_EQ(ary->index->As<ast::SintLiteral>()->value, 2);
|
||||
ASSERT_TRUE(idx->index->Is<ast::SintLiteral>());
|
||||
ASSERT_EQ(idx->index->As<ast::SintLiteral>()->value, 2);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, UnaryExpression_Minus) {
|
||||
|
|
|
@ -2398,7 +2398,7 @@ sem::Expression* Resolver::Expression(const ast::Expression* root) {
|
|||
sem::Expression* Resolver::IndexAccessor(
|
||||
const ast::IndexAccessorExpression* expr) {
|
||||
auto* idx = expr->index;
|
||||
auto* parent_raw_ty = TypeOf(expr->array);
|
||||
auto* parent_raw_ty = TypeOf(expr->object);
|
||||
auto* parent_ty = parent_raw_ty->UnwrapRef();
|
||||
const sem::Type* ty = nullptr;
|
||||
if (auto* arr = parent_ty->As<sem::Array>()) {
|
||||
|
@ -3454,7 +3454,7 @@ sem::Expression* Resolver::UnaryOp(const ast::UnaryOpExpression* unary) {
|
|||
|
||||
auto* array = unary->expr->As<ast::IndexAccessorExpression>();
|
||||
auto* member = unary->expr->As<ast::MemberAccessorExpression>();
|
||||
if ((array && TypeOf(array->array)->UnwrapRef()->Is<sem::Vector>()) ||
|
||||
if ((array && TypeOf(array->object)->UnwrapRef()->Is<sem::Vector>()) ||
|
||||
(member &&
|
||||
TypeOf(member->structure)->UnwrapRef()->Is<sem::Vector>())) {
|
||||
AddError("cannot take the address of a vector component",
|
||||
|
|
|
@ -852,7 +852,7 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) {
|
|||
}
|
||||
|
||||
if (auto* accessor = node->As<ast::IndexAccessorExpression>()) {
|
||||
if (auto access = state.TakeAccess(accessor->array)) {
|
||||
if (auto access = state.TakeAccess(accessor->object)) {
|
||||
// X[Y]
|
||||
if (auto* arr = access.type->As<sem::Array>()) {
|
||||
auto* offset = state.Mul(arr->Stride(), accessor->index);
|
||||
|
|
|
@ -147,10 +147,10 @@ void DecomposeStridedMatrix::Run(CloneContext& ctx, const DataMap&, DataMap&) {
|
|||
ctx.ReplaceAll([&](const ast::IndexAccessorExpression* expr)
|
||||
-> const ast::IndexAccessorExpression* {
|
||||
if (auto* access =
|
||||
ctx.src->Sem().Get<sem::StructMemberAccess>(expr->array)) {
|
||||
ctx.src->Sem().Get<sem::StructMemberAccess>(expr->object)) {
|
||||
auto it = decomposed.find(access->Member()->Declaration());
|
||||
if (it != decomposed.end()) {
|
||||
auto* obj = ctx.CloneWithoutTransform(expr->array);
|
||||
auto* obj = ctx.CloneWithoutTransform(expr->object);
|
||||
auto* idx = ctx.Clone(expr->index);
|
||||
return ctx.dst->IndexAccessor(obj, idx);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ void CollectSavedArrayIndices(const Program* program,
|
|||
const ast::Expression* expr,
|
||||
F&& cb) {
|
||||
if (auto* a = expr->As<ast::IndexAccessorExpression>()) {
|
||||
CollectSavedArrayIndices(program, a->array, cb);
|
||||
CollectSavedArrayIndices(program, a->object, cb);
|
||||
|
||||
if (!a->index->Is<ast::Literal>()) {
|
||||
cb(a->index);
|
||||
|
@ -160,7 +160,7 @@ void InlinePointerLets::Run(CloneContext& ctx, const DataMap&, DataMap&) {
|
|||
ctx.dst->Const(saved_name, nullptr, ctx.Clone(idx_expr)));
|
||||
// Place this variable after the pointer typed let. Order here is
|
||||
// important as order-of-operations needs to be preserved.
|
||||
// CollectSavedArrayIndices() visits the LHS of an array accessor
|
||||
// CollectSavedArrayIndices() visits the LHS of an index accessor
|
||||
// before the index expression.
|
||||
// Note that repeated calls to InsertAfter() with the same `after`
|
||||
// argument will result in nodes to inserted in the order the calls
|
||||
|
|
|
@ -114,11 +114,11 @@ void PadArrayElements::Run(CloneContext& ctx, const DataMap&, DataMap&) {
|
|||
return nullptr;
|
||||
});
|
||||
|
||||
// Fix up array accessors so `a[1]` becomes `a[1].el`
|
||||
// Fix up index accessors so `a[1]` becomes `a[1].el`
|
||||
ctx.ReplaceAll([&](const ast::IndexAccessorExpression* accessor)
|
||||
-> const ast::Expression* {
|
||||
if (auto* array = tint::As<sem::Array>(
|
||||
sem.Get(accessor->array)->Type()->UnwrapRef())) {
|
||||
sem.Get(accessor->object)->Type()->UnwrapRef())) {
|
||||
if (pad(array)) {
|
||||
// Array element is wrapped in a structure. Emit a member accessor
|
||||
// to get to the actual array element.
|
||||
|
|
|
@ -54,7 +54,7 @@ struct Robustness::State {
|
|||
/// cloned without changes.
|
||||
const ast::IndexAccessorExpression* Transform(
|
||||
const ast::IndexAccessorExpression* expr) {
|
||||
auto* ret_type = ctx.src->Sem().Get(expr->array)->Type();
|
||||
auto* ret_type = ctx.src->Sem().Get(expr->object)->Type();
|
||||
|
||||
auto* ref = ret_type->As<sem::Reference>();
|
||||
if (ref && omitted_classes.count(ref->StorageClass()) != 0) {
|
||||
|
@ -83,7 +83,7 @@ struct Robustness::State {
|
|||
} else if (auto* arr = ret_unwrapped->As<sem::Array>()) {
|
||||
size.u32 = arr->Count();
|
||||
} else if (auto* mat = ret_unwrapped->As<sem::Matrix>()) {
|
||||
// The row accessor would have been an embedded array accessor and already
|
||||
// The row accessor would have been an embedded index accessor and already
|
||||
// handled, so we just need to do columns here.
|
||||
size.u32 = mat->columns();
|
||||
} else {
|
||||
|
@ -97,7 +97,7 @@ struct Robustness::State {
|
|||
return nullptr;
|
||||
}
|
||||
// Runtime sized array
|
||||
auto* arr = ctx.Clone(expr->array);
|
||||
auto* arr = ctx.Clone(expr->object);
|
||||
size.expr = b.Call("arrayLength", b.AddressOf(arr));
|
||||
}
|
||||
|
||||
|
@ -196,8 +196,8 @@ struct Robustness::State {
|
|||
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx.Clone(expr->source);
|
||||
auto* arr = ctx.Clone(expr->array);
|
||||
return b.IndexAccessor(src, arr, idx.expr);
|
||||
auto* obj = ctx.Clone(expr->object);
|
||||
return b.IndexAccessor(src, obj, idx.expr);
|
||||
}
|
||||
|
||||
/// @param type intrinsic type
|
||||
|
|
|
@ -56,15 +56,15 @@ void WrapArraysInStructs::Run(CloneContext& ctx, const DataMap&, DataMap&) {
|
|||
return nullptr;
|
||||
});
|
||||
|
||||
// Fix up array accessors so `a[1]` becomes `a.arr[1]`
|
||||
// Fix up index accessors so `a[1]` becomes `a.arr[1]`
|
||||
ctx.ReplaceAll([&](const ast::IndexAccessorExpression* accessor)
|
||||
-> const ast::IndexAccessorExpression* {
|
||||
if (auto* array = ::tint::As<sem::Array>(
|
||||
sem.Get(accessor->array)->Type()->UnwrapRef())) {
|
||||
sem.Get(accessor->object)->Type()->UnwrapRef())) {
|
||||
if (wrapper(array)) {
|
||||
// Array is wrapped in a structure. Emit a member accessor to get
|
||||
// to the actual array.
|
||||
auto* arr = ctx.Clone(accessor->array);
|
||||
auto* arr = ctx.Clone(accessor->object);
|
||||
auto* idx = ctx.Clone(accessor->index);
|
||||
auto* unwrapped = ctx.dst->MemberAccessor(arr, "arr");
|
||||
return ctx.dst->IndexAccessor(accessor->source, unwrapped, idx);
|
||||
|
|
|
@ -167,7 +167,7 @@ bool GeneratorImpl::Generate() {
|
|||
bool GeneratorImpl::EmitIndexAccessor(
|
||||
std::ostream& out,
|
||||
const ast::IndexAccessorExpression* expr) {
|
||||
if (!EmitExpression(out, expr->array)) {
|
||||
if (!EmitExpression(out, expr->object)) {
|
||||
return false;
|
||||
}
|
||||
out << "[";
|
||||
|
|
|
@ -59,10 +59,10 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// @returns true on successful generation; false otherwise
|
||||
bool Generate();
|
||||
|
||||
/// Handles an array accessor expression
|
||||
/// Handles an index accessor expression
|
||||
/// @param out the output of the expression stream
|
||||
/// @param expr the expression to emit
|
||||
/// @returns true if the array accessor was emitted
|
||||
/// @returns true if the index accessor was emitted
|
||||
bool EmitIndexAccessor(std::ostream& out,
|
||||
const ast::IndexAccessorExpression* expr);
|
||||
/// Handles an assignment statement
|
||||
|
|
|
@ -295,7 +295,7 @@ bool GeneratorImpl::EmitDynamicVectorAssignment(
|
|||
|
||||
auto out = line();
|
||||
out << name << "(";
|
||||
if (!EmitExpression(out, ast_access_expr->array)) {
|
||||
if (!EmitExpression(out, ast_access_expr->object)) {
|
||||
return false;
|
||||
}
|
||||
out << ", ";
|
||||
|
@ -314,7 +314,7 @@ bool GeneratorImpl::EmitDynamicVectorAssignment(
|
|||
bool GeneratorImpl::EmitIndexAccessor(
|
||||
std::ostream& out,
|
||||
const ast::IndexAccessorExpression* expr) {
|
||||
if (!EmitExpression(out, expr->array)) {
|
||||
if (!EmitExpression(out, expr->object)) {
|
||||
return false;
|
||||
}
|
||||
out << "[";
|
||||
|
@ -355,7 +355,7 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out,
|
|||
|
||||
bool GeneratorImpl::EmitAssign(const ast::AssignmentStatement* stmt) {
|
||||
if (auto* idx = stmt->lhs->As<ast::IndexAccessorExpression>()) {
|
||||
if (auto* vec = TypeOf(idx->array)->UnwrapRef()->As<sem::Vector>()) {
|
||||
if (auto* vec = TypeOf(idx->object)->UnwrapRef()->As<sem::Vector>()) {
|
||||
auto* rhs_sem = builder_.Sem().Get(idx->index);
|
||||
if (!rhs_sem->ConstantValue().IsValid()) {
|
||||
return EmitDynamicVectorAssignment(stmt, vec);
|
||||
|
|
|
@ -75,10 +75,10 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// @returns true on successful generation; false otherwise
|
||||
bool Generate();
|
||||
|
||||
/// Handles an array accessor expression
|
||||
/// Handles an index accessor expression
|
||||
/// @param out the output of the expression stream
|
||||
/// @param expr the expression to emit
|
||||
/// @returns true if the array accessor was emitted
|
||||
/// @returns true if the index accessor was emitted
|
||||
bool EmitIndexAccessor(std::ostream& out,
|
||||
const ast::IndexAccessorExpression* expr);
|
||||
/// Handles an assignment statement
|
||||
|
|
|
@ -242,7 +242,7 @@ bool GeneratorImpl::EmitIndexAccessor(
|
|||
std::ostream& out,
|
||||
const ast::IndexAccessorExpression* expr) {
|
||||
bool paren_lhs =
|
||||
!expr->array
|
||||
!expr->object
|
||||
->IsAnyOf<ast::IndexAccessorExpression, ast::CallExpression,
|
||||
ast::IdentifierExpression, ast::MemberAccessorExpression,
|
||||
ast::TypeConstructorExpression>();
|
||||
|
@ -250,7 +250,7 @@ bool GeneratorImpl::EmitIndexAccessor(
|
|||
if (paren_lhs) {
|
||||
out << "(";
|
||||
}
|
||||
if (!EmitExpression(out, expr->array)) {
|
||||
if (!EmitExpression(out, expr->object)) {
|
||||
return false;
|
||||
}
|
||||
if (paren_lhs) {
|
||||
|
|
|
@ -95,10 +95,10 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// @param ty the declared type to generate
|
||||
/// @returns true if the declared type was emitted
|
||||
bool EmitTypeDecl(const sem::Type* ty);
|
||||
/// Handles an array accessor expression
|
||||
/// Handles an index accessor expression
|
||||
/// @param out the output of the expression stream
|
||||
/// @param expr the expression to emit
|
||||
/// @returns true if the array accessor was emitted
|
||||
/// @returns true if the index accessor was emitted
|
||||
bool EmitIndexAccessor(std::ostream& out,
|
||||
const ast::IndexAccessorExpression* expr);
|
||||
/// Handles an assignment statement
|
||||
|
|
|
@ -958,7 +958,7 @@ bool Builder::GenerateIndexAccessor(const ast::IndexAccessorExpression* expr,
|
|||
}
|
||||
|
||||
TINT_ICE(Writer, builder_.Diagnostics())
|
||||
<< "unsupported array accessor expression";
|
||||
<< "unsupported index accessor expression";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1095,7 +1095,7 @@ uint32_t Builder::GenerateAccessorExpression(const ast::Expression* expr) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Gather a list of all the member and array accessors that are in this chain.
|
||||
// Gather a list of all the member and index accessors that are in this chain.
|
||||
// The list is built in reverse order as that's the order we need to access
|
||||
// the chain.
|
||||
std::vector<const ast::Expression*> accessors;
|
||||
|
@ -1103,7 +1103,7 @@ uint32_t Builder::GenerateAccessorExpression(const ast::Expression* expr) {
|
|||
while (true) {
|
||||
if (auto* array = source->As<ast::IndexAccessorExpression>()) {
|
||||
accessors.insert(accessors.begin(), source);
|
||||
source = array->array;
|
||||
source = array->object;
|
||||
} else if (auto* member = source->As<ast::MemberAccessorExpression>()) {
|
||||
accessors.insert(accessors.begin(), source);
|
||||
source = member->structure;
|
||||
|
|
|
@ -299,7 +299,7 @@ class Builder {
|
|||
/// @param var the variable to generate
|
||||
/// @returns true if the variable is emited.
|
||||
bool GenerateGlobalVariable(const ast::Variable* var);
|
||||
/// Generates an array accessor expression.
|
||||
/// Generates an index accessor expression.
|
||||
///
|
||||
/// For more information on accessors see the "Pointer evaluation" section of
|
||||
/// the WGSL specification.
|
||||
|
@ -307,7 +307,7 @@ class Builder {
|
|||
/// @param expr the expresssion to generate
|
||||
/// @returns the id of the expression or 0 on failure
|
||||
uint32_t GenerateAccessorExpression(const ast::Expression* expr);
|
||||
/// Generates an array accessor
|
||||
/// Generates an index accessor
|
||||
/// @param expr the accessor to generate
|
||||
/// @param info the current accessor information
|
||||
/// @returns true if the accessor was generated successfully
|
||||
|
|
|
@ -156,14 +156,14 @@ bool GeneratorImpl::EmitIndexAccessor(
|
|||
std::ostream& out,
|
||||
const ast::IndexAccessorExpression* expr) {
|
||||
bool paren_lhs =
|
||||
!expr->array
|
||||
!expr->object
|
||||
->IsAnyOf<ast::IndexAccessorExpression, ast::CallExpression,
|
||||
ast::IdentifierExpression, ast::MemberAccessorExpression,
|
||||
ast::TypeConstructorExpression>();
|
||||
if (paren_lhs) {
|
||||
out << "(";
|
||||
}
|
||||
if (!EmitExpression(out, expr->array)) {
|
||||
if (!EmitExpression(out, expr->object)) {
|
||||
return false;
|
||||
}
|
||||
if (paren_lhs) {
|
||||
|
|
|
@ -58,10 +58,10 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// @param ty the declared type to generate
|
||||
/// @returns true if the declared type was emitted
|
||||
bool EmitTypeDecl(const ast::TypeDecl* ty);
|
||||
/// Handles an array accessor expression
|
||||
/// Handles an index accessor expression
|
||||
/// @param out the output of the expression stream
|
||||
/// @param expr the expression to emit
|
||||
/// @returns true if the array accessor was emitted
|
||||
/// @returns true if the index accessor was emitted
|
||||
bool EmitIndexAccessor(std::ostream& out,
|
||||
const ast::IndexAccessorExpression* expr);
|
||||
/// Handles an assignment statement
|
||||
|
|
Loading…
Reference in New Issue