tint/ast: Tighten AST definition of runtime-sized array
Just checking whether the count is nullptr is not sufficient to know whether the array is fixed-size: `array` represents a infered type, infered fixed-size array `array<T>` represents an explicit type, runtime-sized array `array<T, N>` represents an explicit type, explicit fixed-size array Bug: tint:1628 Change-Id: I03f547078c015d1d2a8a38308bb5e41c733715ec Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97589 Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
parent
b779b2b13d
commit
bf32bd4e96
|
@ -56,11 +56,14 @@ std::string Array::FriendlyName(const SymbolTable& symbols) const {
|
|||
out << "@stride(" << stride->stride << ") ";
|
||||
}
|
||||
}
|
||||
out << "array<" << type->FriendlyName(symbols);
|
||||
if (!IsRuntimeArray()) {
|
||||
out << ", " << SizeExprToString(count, symbols);
|
||||
out << "array";
|
||||
if (type) {
|
||||
out << "<" << type->FriendlyName(symbols);
|
||||
if (count) {
|
||||
out << ", " << SizeExprToString(count, symbols);
|
||||
}
|
||||
out << ">";
|
||||
}
|
||||
out << ">";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
|
|
@ -35,9 +35,9 @@ class Array final : public Castable<Array, Type> {
|
|||
/// @param nid the unique node identifier
|
||||
/// @param src the source of this node
|
||||
/// @param subtype the type of the array elements
|
||||
/// @param count the number of elements in the array. nullptr represents a
|
||||
/// runtime-sized array.
|
||||
/// @param count the number of elements in the array
|
||||
/// @param attributes the array attributes
|
||||
/// @note a runtime-sized array is represented by a null count and a non-null type
|
||||
Array(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
|
@ -50,7 +50,7 @@ class Array final : public Castable<Array, Type> {
|
|||
|
||||
/// @returns true if this is a runtime array.
|
||||
/// i.e. the size is determined at runtime
|
||||
bool IsRuntimeArray() const { return count == nullptr; }
|
||||
bool IsRuntimeArray() const { return type != nullptr && count == nullptr; }
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type that closely resembles how it would be
|
||||
|
|
|
@ -42,6 +42,14 @@ TEST_F(AstArrayTest, CreateRuntimeArray) {
|
|||
EXPECT_TRUE(arr->IsRuntimeArray());
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, CreateInferredTypeArray) {
|
||||
auto* arr = create<Array>(nullptr, nullptr, AttributeList{});
|
||||
EXPECT_EQ(arr->type, nullptr);
|
||||
EXPECT_EQ(arr->count, nullptr);
|
||||
EXPECT_TRUE(arr->Is<Array>());
|
||||
EXPECT_FALSE(arr->IsRuntimeArray());
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_RuntimeSized) {
|
||||
auto* i32 = create<I32>();
|
||||
auto* arr = create<Array>(i32, nullptr, AttributeList{});
|
||||
|
@ -66,5 +74,15 @@ TEST_F(AstArrayTest, FriendlyName_WithStride) {
|
|||
EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(32) array<i32, 5>");
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_InferredTypeAndCount) {
|
||||
auto* arr = create<Array>(nullptr, nullptr, AttributeList{});
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "array");
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_InferredTypeAndCount_WithStrize) {
|
||||
auto* arr = create<Array>(nullptr, nullptr, AttributeList{create<StrideAttribute>(32u)});
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(32) array");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::ast
|
||||
|
|
Loading…
Reference in New Issue