Rename type::Struct to type::StructType

This is to avoid name conflicts once we move all classes from namespace
`type` to `sem`.

Bug: tint:724
Change-Id: I23cdec636cb5bcf0bbba03ee7bb7c44252ddade7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48361
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Antonio Maiorano 2021-04-19 21:31:43 +00:00 committed by Commit Bot service account
parent cf4057be01
commit 3aa226138e
47 changed files with 187 additions and 182 deletions

View File

@ -85,10 +85,10 @@ void Module::to_str(const sem::Info& sem,
if (auto* alias = ty->As<type::Alias>()) {
out << alias->symbol().to_str() << " -> " << alias->type()->type_name()
<< std::endl;
if (auto* str = alias->type()->As<type::Struct>()) {
if (auto* str = alias->type()->As<type::StructType>()) {
str->impl()->to_str(sem, out, indent);
}
} else if (auto* str = ty->As<type::Struct>()) {
} else if (auto* str = ty->As<type::StructType>()) {
out << str->symbol().to_str() << " ";
str->impl()->to_str(sem, out, indent);
}

View File

@ -386,7 +386,7 @@ std::vector<ResourceBinding> Inspector::GetUniformBufferResourceBindings(
auto binding_info = ruv.second;
auto* unwrapped_type = var->Type()->UnwrapIfNeeded();
auto* str = unwrapped_type->As<type::Struct>();
auto* str = unwrapped_type->As<type::StructType>();
if (str == nullptr) {
continue;
}
@ -551,7 +551,7 @@ void Inspector::AddEntryPointInOutVariables(
auto* unwrapped_type = type->UnwrapAll();
if (auto* struct_ty = unwrapped_type->As<type::Struct>()) {
if (auto* struct_ty = unwrapped_type->As<type::StructType>()) {
// Recurse into members.
for (auto* member : struct_ty->impl()->members()) {
AddEntryPointInOutVariables(
@ -606,7 +606,7 @@ std::vector<ResourceBinding> Inspector::GetStorageBufferResourceBindingsImpl(
continue;
}
auto* str = var->Type()->UnwrapIfNeeded()->As<type::Struct>();
auto* str = var->Type()->UnwrapIfNeeded()->As<type::StructType>();
if (!str) {
continue;
}

View File

@ -62,7 +62,7 @@ class InspectorHelper : public ProgramBuilder {
/// Generates a struct that contains user-defined IO members
/// @param name the name of the generated struct
/// @param inout_vars tuples of {name, loc} that will be the struct members
type::Struct* MakeInOutStruct(
type::StructType* MakeInOutStruct(
std::string name,
std::vector<std::tuple<std::string, uint32_t>> inout_vars) {
ast::StructMemberList members;
@ -212,9 +212,9 @@ class InspectorHelper : public ProgramBuilder {
/// @param member_types a vector of member types
/// @param is_block whether or not to decorate as a Block
/// @returns a struct type
type::Struct* MakeStructType(const std::string& name,
std::vector<type::Type*> member_types,
bool is_block) {
type::StructType* MakeStructType(const std::string& name,
std::vector<type::Type*> member_types,
bool is_block) {
ast::StructMemberList members;
for (auto* type : member_types) {
members.push_back(Member(StructMemberName(members.size(), type), type));
@ -235,8 +235,9 @@ class InspectorHelper : public ProgramBuilder {
/// @param name name for the type
/// @param member_types a vector of member types
/// @returns a struct type that has the layout for an uniform buffer.
type::Struct* MakeUniformBufferType(const std::string& name,
std::vector<type::Type*> member_types) {
type::StructType* MakeUniformBufferType(
const std::string& name,
std::vector<type::Type*> member_types) {
auto* struct_type = MakeStructType(name, member_types, true);
return struct_type;
}
@ -247,7 +248,7 @@ class InspectorHelper : public ProgramBuilder {
/// @returns a tuple {struct type, access control type}, where the struct has
/// the layout for a storage buffer, and the control type wraps the
/// struct.
std::tuple<type::Struct*, type::AccessControl*> MakeStorageBufferTypes(
std::tuple<type::StructType*, type::AccessControl*> MakeStorageBufferTypes(
const std::string& name,
std::vector<type::Type*> member_types) {
auto* struct_type = MakeStructType(name, member_types, true);
@ -262,7 +263,7 @@ class InspectorHelper : public ProgramBuilder {
/// @returns a tuple {struct type, access control type}, where the struct has
/// the layout for a read-only storage buffer, and the control type
/// wraps the struct.
std::tuple<type::Struct*, type::AccessControl*>
std::tuple<type::StructType*, type::AccessControl*>
MakeReadOnlyStorageBufferTypes(const std::string& name,
std::vector<type::Type*> member_types) {
auto* struct_type = MakeStructType(name, member_types, true);
@ -1680,18 +1681,19 @@ TEST_F(InspectorGetResourceBindingsTest, Empty) {
}
TEST_F(InspectorGetResourceBindingsTest, Simple) {
type::Struct* ub_struct_type = MakeUniformBufferType("ub_type", {ty.i32()});
type::StructType* ub_struct_type =
MakeUniformBufferType("ub_type", {ty.i32()});
AddUniformBuffer("ub_var", ub_struct_type, 0, 0);
MakeStructVariableReferenceBodyFunction("ub_func", "ub_var", {{0, ty.i32()}});
type::Struct* sb_struct_type;
type::StructType* sb_struct_type;
type::AccessControl* sb_control_type;
std::tie(sb_struct_type, sb_control_type) =
MakeStorageBufferTypes("sb_type", {ty.i32()});
AddStorageBuffer("sb_var", sb_control_type, 1, 0);
MakeStructVariableReferenceBodyFunction("sb_func", "sb_var", {{0, ty.i32()}});
type::Struct* rosb_struct_type;
type::StructType* rosb_struct_type;
type::AccessControl* rosb_control_type;
std::tie(rosb_struct_type, rosb_control_type) =
MakeReadOnlyStorageBufferTypes("rosb_type", {ty.i32()});
@ -1801,7 +1803,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingEntryPoint) {
}
TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) {
type::Struct* foo_struct_type = MakeUniformBufferType("foo_type", {ty.i32()});
type::StructType* foo_struct_type =
MakeUniformBufferType("foo_type", {ty.i32()});
AddUniformBuffer("foo_ub", foo_struct_type, 0, 0);
MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", {{0, ty.i32()}});
@ -1844,7 +1847,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) {
}
TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) {
type::Struct* foo_struct_type = MakeUniformBufferType("foo_type", {ty.i32()});
type::StructType* foo_struct_type =
MakeUniformBufferType("foo_type", {ty.i32()});
AddUniformBuffer("foo_ub", foo_struct_type, 0, 0);
MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", {{0, ty.i32()}});
@ -1870,7 +1874,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) {
}
TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) {
type::Struct* foo_struct_type =
type::StructType* foo_struct_type =
MakeUniformBufferType("foo_type", {ty.i32(), ty.u32(), ty.f32()});
AddUniformBuffer("foo_ub", foo_struct_type, 0, 0);
@ -1898,7 +1902,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) {
}
TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingPadding) {
type::Struct* foo_struct_type =
type::StructType* foo_struct_type =
MakeUniformBufferType("foo_type", {ty.vec3<f32>()});
AddUniformBuffer("foo_ub", foo_struct_type, 0, 0);
@ -1926,7 +1930,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingPadding) {
}
TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
type::Struct* ub_struct_type =
type::StructType* ub_struct_type =
MakeUniformBufferType("ub_type", {ty.i32(), ty.u32(), ty.f32()});
AddUniformBuffer("ub_foo", ub_struct_type, 0, 0);
AddUniformBuffer("ub_bar", ub_struct_type, 0, 1);
@ -1985,7 +1989,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) {
// TODO(bclayton) - This is not a legal structure layout for uniform buffer
// usage. Once crbug.com/tint/628 is implemented, this will fail validation
// and will need to be fixed.
type::Struct* foo_struct_type =
type::StructType* foo_struct_type =
MakeUniformBufferType("foo_type", {ty.i32(), u32_array_type(4)});
AddUniformBuffer("foo_ub", foo_struct_type, 0, 0);
@ -2012,7 +2016,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) {
}
TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) {
type::Struct* foo_struct_type;
type::StructType* foo_struct_type;
type::AccessControl* foo_control_type;
std::tie(foo_struct_type, foo_control_type) =
MakeStorageBufferTypes("foo_type", {ty.i32()});
@ -2041,7 +2045,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) {
}
TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) {
type::Struct* foo_struct_type;
type::StructType* foo_struct_type;
type::AccessControl* foo_control_type;
std::tie(foo_struct_type, foo_control_type) =
MakeStorageBufferTypes("foo_type", {ty.i32(), ty.u32(), ty.f32()});
@ -2071,7 +2075,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) {
}
TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
type::Struct* sb_struct_type;
type::StructType* sb_struct_type;
type::AccessControl* sb_control_type;
std::tie(sb_struct_type, sb_control_type) =
MakeStorageBufferTypes("sb_type", {ty.i32(), ty.u32(), ty.f32()});
@ -2132,7 +2136,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
}
TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) {
type::Struct* foo_struct_type;
type::StructType* foo_struct_type;
type::AccessControl* foo_control_type;
std::tie(foo_struct_type, foo_control_type) =
MakeStorageBufferTypes("foo_type", {ty.i32(), u32_array_type(4)});
@ -2161,7 +2165,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) {
}
TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) {
type::Struct* foo_struct_type;
type::StructType* foo_struct_type;
type::AccessControl* foo_control_type;
std::tie(foo_struct_type, foo_control_type) =
MakeStorageBufferTypes("foo_type", {ty.i32(), u32_array_type(0)});
@ -2190,7 +2194,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) {
}
TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingPadding) {
type::Struct* foo_struct_type;
type::StructType* foo_struct_type;
type::AccessControl* foo_control_type;
std::tie(foo_struct_type, foo_control_type) =
MakeStorageBufferTypes("foo_type", {ty.vec3<f32>()});
@ -2220,7 +2224,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingPadding) {
}
TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) {
type::Struct* foo_struct_type;
type::StructType* foo_struct_type;
type::AccessControl* foo_control_type;
std::tie(foo_struct_type, foo_control_type) =
MakeReadOnlyStorageBufferTypes("foo_type", {ty.i32()});
@ -2242,7 +2246,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) {
}
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) {
type::Struct* foo_struct_type;
type::StructType* foo_struct_type;
type::AccessControl* foo_control_type;
std::tie(foo_struct_type, foo_control_type) =
MakeReadOnlyStorageBufferTypes("foo_type", {ty.i32()});
@ -2272,7 +2276,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) {
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
MultipleStorageBuffers) {
type::Struct* sb_struct_type;
type::StructType* sb_struct_type;
type::AccessControl* sb_control_type;
std::tie(sb_struct_type, sb_control_type) =
MakeReadOnlyStorageBufferTypes("sb_type", {ty.i32(), ty.u32(), ty.f32()});
@ -2333,7 +2337,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
}
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) {
type::Struct* foo_struct_type;
type::StructType* foo_struct_type;
type::AccessControl* foo_control_type;
std::tie(foo_struct_type, foo_control_type) =
MakeReadOnlyStorageBufferTypes("foo_type", {ty.i32(), u32_array_type(4)});
@ -2363,7 +2367,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) {
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
ContainingRuntimeArray) {
type::Struct* foo_struct_type;
type::StructType* foo_struct_type;
type::AccessControl* foo_control_type;
std::tie(foo_struct_type, foo_control_type) =
MakeReadOnlyStorageBufferTypes("foo_type", {ty.i32(), u32_array_type(0)});
@ -2392,7 +2396,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
}
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) {
type::Struct* foo_struct_type;
type::StructType* foo_struct_type;
type::AccessControl* foo_control_type;
std::tie(foo_struct_type, foo_control_type) =
MakeStorageBufferTypes("foo_type", {ty.i32()});

View File

@ -561,8 +561,8 @@ class ProgramBuilder {
/// @param impl the struct implementation
/// @returns a struct pointer
template <typename NAME>
type::Struct* struct_(NAME&& name, ast::Struct* impl) const {
return builder->create<type::Struct>(
type::StructType* struct_(NAME&& name, ast::Struct* impl) const {
return builder->create<type::StructType>(
builder->Sym(std::forward<NAME>(name)), impl);
}
@ -1174,18 +1174,18 @@ class ProgramBuilder {
return create<ast::ReturnStatement>(Expr(std::forward<EXPR>(val)));
}
/// Creates a ast::Struct and type::Struct, registering the type::Struct with
/// the AST().ConstructedTypes().
/// Creates a ast::Struct and type::StructType, registering the
/// type::StructType with the AST().ConstructedTypes().
/// @param source the source information
/// @param name the struct name
/// @param members the struct members
/// @param decorations the optional struct decorations
/// @returns the struct type
template <typename NAME>
type::Struct* Structure(const Source& source,
NAME&& name,
ast::StructMemberList members,
ast::DecorationList decorations = {}) {
type::StructType* Structure(const Source& source,
NAME&& name,
ast::StructMemberList members,
ast::DecorationList decorations = {}) {
auto* impl =
create<ast::Struct>(source, std::move(members), std::move(decorations));
auto* type = ty.struct_(Sym(std::forward<NAME>(name)), impl);
@ -1193,16 +1193,16 @@ class ProgramBuilder {
return type;
}
/// Creates a ast::Struct and type::Struct, registering the type::Struct with
/// the AST().ConstructedTypes().
/// Creates a ast::Struct and type::StructType, registering the
/// type::StructType with the AST().ConstructedTypes().
/// @param name the struct name
/// @param members the struct members
/// @param decorations the optional struct decorations
/// @returns the struct type
template <typename NAME>
type::Struct* Structure(NAME&& name,
ast::StructMemberList members,
ast::DecorationList decorations = {}) {
type::StructType* Structure(NAME&& name,
ast::StructMemberList members,
ast::DecorationList decorations = {}) {
auto* impl =
create<ast::Struct>(std::move(members), std::move(decorations));
auto* type = ty.struct_(Sym(std::forward<NAME>(name)), impl);

View File

@ -947,7 +947,7 @@ type::Type* ParserImpl::ConvertType(
namer_.SuggestSanitizedName(type_id, "S");
auto name = namer_.GetName(type_id);
auto* result = builder_.create<type::Struct>(
auto* result = builder_.create<type::StructType>(
builder_.Symbols().Register(name), ast_struct);
id_to_type_[type_id] = result;
if (num_non_writable_members == members.size()) {
@ -1501,7 +1501,7 @@ ast::Expression* ParserImpl::MakeNullValue(type::Type* type) {
return create<ast::TypeConstructorExpression>(Source{}, original_type,
std::move(ast_components));
}
if (auto* struct_ty = type->As<type::Struct>()) {
if (auto* struct_ty = type->As<type::StructType>()) {
ast::ExpressionList ast_components;
for (auto* member : struct_ty->impl()->members()) {
ast_components.emplace_back(MakeNullValue(member->type()));

View File

@ -550,10 +550,10 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) {
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<type::Struct>());
EXPECT_TRUE(type->Is<type::StructType>());
Program program = p->program();
EXPECT_THAT(program.str(type->As<type::Struct>()->impl()), Eq(R"(Struct{
EXPECT_THAT(program.str(type->As<type::StructType>()->impl()), Eq(R"(Struct{
StructMember{field0: __u32}
StructMember{field1: __f32}
}
@ -571,10 +571,10 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) {
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<type::Struct>());
EXPECT_TRUE(type->Is<type::StructType>());
Program program = p->program();
EXPECT_THAT(program.str(type->As<type::Struct>()->impl()), Eq(R"(Struct{
EXPECT_THAT(program.str(type->As<type::StructType>()->impl()), Eq(R"(Struct{
[[block]]
StructMember{field0: __u32}
}
@ -596,10 +596,10 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) {
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<type::Struct>());
EXPECT_TRUE(type->Is<type::StructType>());
Program program = p->program();
EXPECT_THAT(program.str(type->As<type::Struct>()->impl()), Eq(R"(Struct{
EXPECT_THAT(program.str(type->As<type::StructType>()->impl()), Eq(R"(Struct{
StructMember{[[ offset 0 ]] field0: __f32}
StructMember{[[ offset 8 ]] field1: __vec_2__f32}
StructMember{[[ offset 16 ]] field2: __mat_2_2__f32}

View File

@ -1121,7 +1121,7 @@ Expect<ast::StorageClass> ParserImpl::expect_storage_class(
// struct_decl
// : struct_decoration_decl* STRUCT IDENT struct_body_decl
Maybe<type::Struct*> ParserImpl::struct_decl(ast::DecorationList& decos) {
Maybe<type::StructType*> ParserImpl::struct_decl(ast::DecorationList& decos) {
auto t = peek();
auto source = t.source();
@ -1136,7 +1136,7 @@ Maybe<type::Struct*> ParserImpl::struct_decl(ast::DecorationList& decos) {
if (body.errored)
return Failure::kErrored;
return create<type::Struct>(
return create<type::StructType>(
builder_.Symbols().Register(name.value),
create<ast::Struct>(source, std::move(body.value), std::move(decos)));
}

View File

@ -379,7 +379,7 @@ class ParserImpl {
/// `struct_decoration_decl*` provided as `decos`.
/// @returns the struct type or nullptr on error
/// @param decos the list of decorations for the struct declaration.
Maybe<type::Struct*> struct_decl(ast::DecorationList& decos);
Maybe<type::StructType*> struct_decl(ast::DecorationList& decos);
/// Parses a `struct_body_decl` grammar element, erroring on parse failure.
/// @returns the struct members
Expect<ast::StructMemberList> expect_struct_body_decl();

View File

@ -102,8 +102,8 @@ type B = A;)");
auto program = p->program();
ASSERT_EQ(program.AST().ConstructedTypes().size(), 2u);
ASSERT_TRUE(program.AST().ConstructedTypes()[0]->Is<type::Struct>());
auto* str = program.AST().ConstructedTypes()[0]->As<type::Struct>();
ASSERT_TRUE(program.AST().ConstructedTypes()[0]->Is<type::StructType>());
auto* str = program.AST().ConstructedTypes()[0]->As<type::StructType>();
EXPECT_EQ(str->symbol(), program.Symbols().Get("A"));
ASSERT_TRUE(program.AST().ConstructedTypes()[1]->Is<type::Alias>());
@ -165,9 +165,9 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) {
auto* t = program.AST().ConstructedTypes()[0];
ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<type::Struct>());
ASSERT_TRUE(t->Is<type::StructType>());
auto* str = t->As<type::Struct>();
auto* str = t->As<type::StructType>();
EXPECT_EQ(str->symbol(), program.Symbols().Get("A"));
EXPECT_EQ(str->impl()->members().size(), 2u);
}
@ -183,9 +183,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) {
auto* t = program.AST().ConstructedTypes()[0];
ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<type::Struct>());
ASSERT_TRUE(t->Is<type::StructType>());
auto* str = t->As<type::Struct>();
auto* str = t->As<type::StructType>();
EXPECT_EQ(str->symbol(), program.Symbols().Get("A"));
EXPECT_EQ(str->impl()->members().size(), 1u);
EXPECT_FALSE(str->IsBlockDecorated());
@ -210,9 +210,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) {
auto* t = program.AST().ConstructedTypes()[0];
ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<type::Struct>());
ASSERT_TRUE(t->Is<type::StructType>());
auto* str = t->As<type::Struct>();
auto* str = t->As<type::StructType>();
EXPECT_EQ(str->symbol(), program.Symbols().Get("A"));
EXPECT_EQ(str->impl()->members().size(), 1u);
EXPECT_TRUE(str->IsBlockDecorated());

View File

@ -38,7 +38,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) {
TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
auto p = parser("type a = B");
type::Struct str(p->builder().Symbols().Get("B"), {});
type::StructType str(p->builder().Symbols().Get("B"), {});
p->register_constructed("B", &str);
auto t = p->type_alias();
@ -49,9 +49,9 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
ASSERT_TRUE(t->Is<type::Alias>());
auto* alias = t->As<type::Alias>();
EXPECT_EQ(p->builder().Symbols().NameFor(alias->symbol()), "a");
ASSERT_TRUE(alias->type()->Is<type::Struct>());
ASSERT_TRUE(alias->type()->Is<type::StructType>());
auto* s = alias->type()->As<type::Struct>();
auto* s = alias->type()->As<type::StructType>();
EXPECT_EQ(s->symbol(), p->builder().Symbols().Get("B"));
EXPECT_EQ(s->symbol(), p->builder().Symbols().Get("B"));
}

View File

@ -126,7 +126,7 @@ bool Resolver::IsStorable(type::Type* type) {
if (type::ArrayType* arr = type->As<type::ArrayType>()) {
return IsStorable(arr->type());
}
if (type::Struct* str = type->As<type::Struct>()) {
if (type::StructType* str = type->As<type::StructType>()) {
for (const auto* member : str->impl()->members()) {
if (!IsStorable(member->type())) {
return false;
@ -152,7 +152,7 @@ bool Resolver::IsHostShareable(type::Type* type) {
if (auto* arr = type->As<type::ArrayType>()) {
return IsHostShareable(arr->type());
}
if (auto* str = type->As<type::Struct>()) {
if (auto* str = type->As<type::StructType>()) {
for (auto* member : str->impl()->members()) {
if (!IsHostShareable(member->type())) {
return false;
@ -224,7 +224,7 @@ bool Resolver::ResolveInternal() {
bool Resolver::Type(type::Type* ty) {
ty = ty->UnwrapAliasIfNeeded();
if (auto* str = ty->As<type::Struct>()) {
if (auto* str = ty->As<type::StructType>()) {
if (!Structure(str)) {
return false;
}
@ -331,7 +331,7 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) {
// satisfying the storage class constraints.
auto* access = info->type->As<type::AccessControl>();
auto* str = access ? access->type()->As<type::Struct>() : nullptr;
auto* str = access ? access->type()->As<type::StructType>() : nullptr;
if (!str) {
diagnostics_.add_error(
"variables declared in the <storage> storage class must be of an "
@ -519,7 +519,7 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func) {
}
// Check that we saw a pipeline IO attribute iff we need one.
if (Canonical(ty)->Is<type::Struct>()) {
if (Canonical(ty)->Is<type::StructType>()) {
if (pipeline_io_attribute) {
diagnostics_.add_error(
"entry point IO attributes must not be used on structure " +
@ -555,12 +555,12 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func) {
return false;
}
if (auto* struct_ty = Canonical(ty)->As<type::Struct>()) {
if (auto* struct_ty = Canonical(ty)->As<type::StructType>()) {
// Validate the decorations for each struct members, and also check for
// invalid member types.
for (auto* member : struct_ty->impl()->members()) {
auto* member_ty = Canonical(member->type());
if (member_ty->Is<type::Struct>()) {
if (member_ty->Is<type::StructType>()) {
diagnostics_.add_error(
"entry point IO types cannot contain nested structures",
member->source());
@ -646,7 +646,7 @@ bool Resolver::Function(ast::Function* func) {
return false;
}
if (auto* str = param_info->type->As<type::Struct>()) {
if (auto* str = param_info->type->As<type::StructType>()) {
auto* info = Structure(str);
if (!info) {
return false;
@ -670,7 +670,7 @@ bool Resolver::Function(ast::Function* func) {
}
}
if (auto* str = Canonical(func->return_type())->As<type::Struct>()) {
if (auto* str = Canonical(func->return_type())->As<type::StructType>()) {
if (!ApplyStorageClassUsageToType(ast::StorageClass::kNone, str,
func->source())) {
diagnostics_.add_note("while instantiating return type for " +
@ -1296,7 +1296,7 @@ bool Resolver::MemberAccessor(ast::MemberAccessorExpression* expr) {
type::Type* ret = nullptr;
std::vector<uint32_t> swizzle;
if (auto* ty = data_type->As<type::Struct>()) {
if (auto* ty = data_type->As<type::StructType>()) {
Mark(expr->member());
auto symbol = expr->member()->symbol();
auto* str = Structure(ty);
@ -1909,7 +1909,7 @@ bool Resolver::DefaultAlignAndSize(type::Type* ty,
align = vector_align[mat->rows()];
size = vector_align[mat->rows()] * mat->columns();
return true;
} else if (auto* s = cty->As<type::Struct>()) {
} else if (auto* s = cty->As<type::StructType>()) {
if (auto* si = Structure(s)) {
align = si->align;
size = si->size;
@ -1998,7 +1998,7 @@ const sem::Array* Resolver::Array(type::ArrayType* arr, const Source& source) {
return create_semantic(implicit_stride);
}
bool Resolver::ValidateStructure(const type::Struct* st) {
bool Resolver::ValidateStructure(const type::StructType* st) {
for (auto* member : st->impl()->members()) {
if (auto* r = member->type()->UnwrapAll()->As<type::ArrayType>()) {
if (r->IsRuntimeArray()) {
@ -2053,7 +2053,7 @@ bool Resolver::ValidateStructure(const type::Struct* st) {
return true;
}
Resolver::StructInfo* Resolver::Structure(type::Struct* str) {
Resolver::StructInfo* Resolver::Structure(type::StructType* str) {
auto info_it = struct_info_.find(str);
if (info_it != struct_info_.end()) {
// StructInfo already resolved for this structure type
@ -2369,7 +2369,7 @@ bool Resolver::ApplyStorageClassUsageToType(ast::StorageClass sc,
const Source& usage) {
ty = ty->UnwrapIfNeeded();
if (auto* str = ty->As<type::Struct>()) {
if (auto* str = ty->As<type::StructType>()) {
auto* info = Structure(str);
if (!info) {
return false;

View File

@ -245,7 +245,7 @@ class Resolver {
const ast::ExpressionList& values);
bool ValidateParameter(const ast::Variable* param);
bool ValidateReturn(const ast::ReturnStatement* ret);
bool ValidateStructure(const type::Struct* st);
bool ValidateStructure(const type::StructType* st);
bool ValidateSwitch(const ast::SwitchStatement* s);
bool ValidateVariable(const ast::Variable* param);
bool ValidateVectorConstructor(const type::Vector* vec_type,
@ -260,7 +260,7 @@ class Resolver {
/// @returns the StructInfo for the structure `str`, building it if it hasn't
/// been constructed already. If an error is raised, nullptr is returned.
StructInfo* Structure(type::Struct* str);
StructInfo* Structure(type::StructType* str);
/// @returns the VariableInfo for the variable `var`, building it if it hasn't
/// been constructed already. If an error is raised, nullptr is returned.
@ -330,7 +330,7 @@ class Resolver {
std::unordered_map<const ast::Variable*, VariableInfo*> variable_to_info_;
std::unordered_map<ast::CallExpression*, FunctionCallInfo> function_calls_;
std::unordered_map<ast::Expression*, ExpressionInfo> expr_info_;
std::unordered_map<type::Struct*, StructInfo*> struct_info_;
std::unordered_map<type::StructType*, StructInfo*> struct_info_;
std::unordered_map<type::Type*, type::Type*> type_to_canonical_;
std::unordered_set<ast::Node*> marked_;
FunctionInfo* current_function_ = nullptr;

View File

@ -23,7 +23,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::StructMember);
namespace tint {
namespace sem {
Struct::Struct(type::Struct* type,
Struct::Struct(type::StructType* type,
StructMemberList members,
uint32_t align,
uint32_t size,

View File

@ -31,7 +31,7 @@ namespace ast {
class StructMember;
} // namespace ast
namespace type {
class Struct;
class StructType;
} // namespace type
namespace sem {
@ -63,7 +63,7 @@ class Struct : public Castable<Struct, Node> {
/// alignment padding
/// @param storage_class_usage a set of all the storage class usages
/// @param pipeline_stage_uses a set of all the pipeline stage uses
Struct(type::Struct* type,
Struct(type::StructType* type,
StructMemberList members,
uint32_t align,
uint32_t size,
@ -75,7 +75,7 @@ class Struct : public Castable<Struct, Node> {
~Struct() override;
/// @returns the structure type
type::Struct* Type() const { return type_; }
type::StructType* Type() const { return type_; }
/// @returns the members of the structure
const StructMemberList& Members() const { return members_; }
@ -128,7 +128,7 @@ class Struct : public Castable<Struct, Node> {
}
private:
type::Struct* const type_;
type::StructType* const type_;
StructMemberList const members_;
uint32_t const align_;
uint32_t const size_;

View File

@ -31,7 +31,7 @@ class Variable;
} // namespace ast
namespace type {
class ArrayType;
class Struct;
class StructType;
} // namespace type
namespace sem {
@ -59,7 +59,7 @@ struct TypeMappings {
Function* operator()(ast::Function*);
MemberAccessorExpression* operator()(ast::MemberAccessorExpression*);
Statement* operator()(ast::Statement*);
Struct* operator()(type::Struct*);
Struct* operator()(type::StructType*);
StructMember* operator()(ast::StructMember*);
Variable* operator()(ast::Variable*);
//! @endcond

View File

@ -77,8 +77,8 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
// get_buffer_size_intrinsic() emits the function decorated with
// BufferSizeIntrinsic that is transformed by the HLSL writer into a call to
// [RW]ByteAddressBuffer.GetDimensions().
std::unordered_map<type::Struct*, Symbol> buffer_size_intrinsics;
auto get_buffer_size_intrinsic = [&](type::Struct* buffer_type) {
std::unordered_map<type::StructType*, Symbol> buffer_size_intrinsics;
auto get_buffer_size_intrinsic = [&](type::StructType* buffer_type) {
return utils::GetOrCreate(buffer_size_intrinsics, buffer_type, [&] {
auto name = ctx.dst->Symbols().New();
auto* func = ctx.dst->create<ast::Function>(
@ -138,7 +138,7 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
auto* storage_buffer_expr = accessor->structure();
auto* storage_buffer_sem = sem.Get(storage_buffer_expr);
auto* storage_buffer_type =
storage_buffer_sem->Type()->UnwrapAll()->As<type::Struct>();
storage_buffer_sem->Type()->UnwrapAll()->As<type::StructType>();
// Generate BufferSizeIntrinsic for this storage type if we haven't
// already
@ -146,7 +146,7 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
if (!storage_buffer_type) {
TINT_ICE(ctx.dst->Diagnostics())
<< "arrayLength(X.Y) expected X to be type::Struct, got "
<< "arrayLength(X.Y) expected X to be type::StructType, got "
<< storage_buffer_type->FriendlyName(ctx.src->Symbols());
break;
}

View File

@ -66,7 +66,7 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
// Strip entry point IO decorations from struct declarations.
// TODO(jrprice): This code is duplicated with the SPIR-V transform.
for (auto* ty : ctx.src->AST().ConstructedTypes()) {
if (auto* struct_ty = ty->As<type::Struct>()) {
if (auto* struct_ty = ty->As<type::StructType>()) {
// Build new list of struct members without entry point IO decorations.
ast::StructMemberList new_struct_members;
for (auto* member : struct_ty->impl()->members()) {
@ -81,7 +81,7 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
}
// Redeclare the struct.
auto* new_struct = ctx.dst->create<type::Struct>(
auto* new_struct = ctx.dst->create<type::StructType>(
ctx.Clone(struct_ty->symbol()),
ctx.dst->create<ast::Struct>(
new_struct_members, ctx.Clone(struct_ty->impl()->decorations())));
@ -107,11 +107,11 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
std::function<ast::Expression*()> func_const_initializer;
if (auto* struct_ty = param_ty->As<type::Struct>()) {
if (auto* struct_ty = param_ty->As<type::StructType>()) {
// Pull out all struct members and build initializer list.
std::vector<Symbol> member_names;
for (auto* member : struct_ty->impl()->members()) {
if (member->type()->UnwrapAll()->Is<type::Struct>()) {
if (member->type()->UnwrapAll()->Is<type::StructType>()) {
TINT_ICE(ctx.dst->Diagnostics()) << "nested pipeline IO struct";
}
@ -174,7 +174,7 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
StructMemberComparator);
// Create the new struct type.
auto* in_struct = ctx.dst->create<type::Struct>(
auto* in_struct = ctx.dst->create<type::StructType>(
ctx.dst->Symbols().New(),
ctx.dst->create<ast::Struct>(new_struct_members,
ast::DecorationList{}));
@ -193,10 +193,10 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
} else {
ast::StructMemberList new_struct_members;
if (auto* struct_ty = ret_type->As<type::Struct>()) {
if (auto* struct_ty = ret_type->As<type::StructType>()) {
// Rebuild struct with only the entry point IO attributes.
for (auto* member : struct_ty->impl()->members()) {
if (member->type()->UnwrapAll()->Is<type::Struct>()) {
if (member->type()->UnwrapAll()->Is<type::StructType>()) {
TINT_ICE(ctx.dst->Diagnostics()) << "nested pipeline IO struct";
}
@ -220,7 +220,7 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
StructMemberComparator);
// Create the new struct type.
auto* out_struct = ctx.dst->create<type::Struct>(
auto* out_struct = ctx.dst->create<type::StructType>(
ctx.dst->Symbols().New(),
ctx.dst->create<ast::Struct>(new_struct_members,
ast::DecorationList{}));
@ -237,7 +237,7 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
};
ast::ExpressionList ret_values;
if (ret_type->Is<type::Struct>()) {
if (ret_type->Is<type::StructType>()) {
if (!ret->value()->Is<ast::IdentifierExpression>()) {
// Create a const to hold the return value expression to avoid
// re-evaluating it multiple times.

View File

@ -341,7 +341,7 @@ type::Type* ConstructedTypeOf(type::Type* ty) {
if (auto* alias = ty->As<type::Alias>()) {
return alias;
}
if (auto* str = ty->As<type::Struct>()) {
if (auto* str = ty->As<type::StructType>()) {
return str;
}
// Not a constructed type
@ -438,7 +438,7 @@ struct State {
ctx.dst->Add("offset", i * MatrixColumnStride(mat_ty));
values.emplace_back(ctx.dst->Call(load, "buffer", offset));
}
} else if (auto* str_ty = el_ty->As<type::Struct>()) {
} else if (auto* str_ty = el_ty->As<type::StructType>()) {
auto& sem = ctx.src->Sem();
auto* str = sem.Get(str_ty);
for (auto* member : str->Members()) {
@ -505,7 +505,7 @@ struct State {
auto* call = ctx.dst->Call(store, "buffer", offset, access);
body.emplace_back(ctx.dst->create<ast::CallStatement>(call));
}
} else if (auto* str_ty = el_ty->As<type::Struct>()) {
} else if (auto* str_ty = el_ty->As<type::StructType>()) {
auto& sem = ctx.src->Sem();
auto* str = sem.Get(str_ty);
for (auto* member : str->Members()) {
@ -660,7 +660,7 @@ Output DecomposeStorageAccess::Run(const Program* in, const DataMap&) {
}
} else {
if (auto access = state.TakeAccess(accessor->structure())) {
auto* str_ty = access.type->As<type::Struct>();
auto* str_ty = access.type->As<type::StructType>();
auto* member =
sem.Get(str_ty)->FindMember(accessor->member()->symbol());
auto offset = member->Offset();

View File

@ -96,7 +96,7 @@ void Hlsl::PromoteInitializersToConstVar(CloneContext& ctx) const {
}
auto* src_ty = src_sem_expr->Type();
if (src_ty->IsAnyOf<type::ArrayType, type::Struct>()) {
if (src_ty->IsAnyOf<type::ArrayType, type::StructType>()) {
// Create a new symbol for the constant
auto dst_symbol = ctx.dst->Symbols().New();
// Clone the type

View File

@ -111,7 +111,7 @@ void Spirv::HandleEntryPointIOTypes(CloneContext& ctx) const {
// Strip entry point IO decorations from struct declarations.
for (auto* ty : ctx.src->AST().ConstructedTypes()) {
if (auto* struct_ty = ty->As<type::Struct>()) {
if (auto* struct_ty = ty->As<type::StructType>()) {
// Build new list of struct members without entry point IO decorations.
ast::StructMemberList new_struct_members;
for (auto* member : struct_ty->impl()->members()) {
@ -126,7 +126,7 @@ void Spirv::HandleEntryPointIOTypes(CloneContext& ctx) const {
}
// Redeclare the struct.
auto* new_struct = ctx.dst->create<type::Struct>(
auto* new_struct = ctx.dst->create<type::StructType>(
ctx.Clone(struct_ty->symbol()),
ctx.dst->create<ast::Struct>(
new_struct_members, ctx.Clone(struct_ty->impl()->decorations())));
@ -255,7 +255,7 @@ Symbol Spirv::HoistToInputVariables(
type::Type* ty,
type::Type* declared_ty,
const ast::DecorationList& decorations) const {
if (!ty->Is<type::Struct>()) {
if (!ty->Is<type::StructType>()) {
// Base case: create a global variable and return.
ast::DecorationList new_decorations =
RemoveDecorations(&ctx, decorations, [](const ast::Decoration* deco) {
@ -272,7 +272,7 @@ Symbol Spirv::HoistToInputVariables(
// Recurse into struct members and build the initializer list.
std::vector<Symbol> init_value_names;
auto* struct_ty = ty->As<type::Struct>();
auto* struct_ty = ty->As<type::StructType>();
for (auto* member : struct_ty->impl()->members()) {
auto member_var = HoistToInputVariables(
ctx, func, member->type(), member->type(), member->decorations());
@ -308,7 +308,7 @@ void Spirv::HoistToOutputVariables(CloneContext& ctx,
Symbol store_value,
ast::StatementList& stores) const {
// Base case.
if (!ty->Is<type::Struct>()) {
if (!ty->Is<type::StructType>()) {
// Create a global variable.
ast::DecorationList new_decorations =
RemoveDecorations(&ctx, decorations, [](const ast::Decoration* deco) {
@ -332,7 +332,7 @@ void Spirv::HoistToOutputVariables(CloneContext& ctx,
}
// Recurse into struct members.
auto* struct_ty = ty->As<type::Struct>();
auto* struct_ty = ty->As<type::StructType>();
for (auto* member : struct_ty->impl()->members()) {
member_accesses.push_back(ctx.Clone(member->symbol()));
HoistToOutputVariables(ctx, func, member->type(), member->type(),

View File

@ -44,7 +44,7 @@ TEST_F(AccessControlTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -40,7 +40,7 @@ TEST_F(AliasTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -54,7 +54,7 @@ TEST_F(ArrayTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -34,7 +34,7 @@ TEST_F(BoolTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -39,7 +39,7 @@ TEST_F(DepthTextureTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_TRUE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -40,7 +40,7 @@ TEST_F(ExternalTextureTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_TRUE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -34,7 +34,7 @@ TEST_F(F32Test, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -34,7 +34,7 @@ TEST_F(I32Test, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -43,7 +43,7 @@ TEST_F(MatrixTest, Is) {
EXPECT_TRUE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -40,7 +40,7 @@ TEST_F(MultisampledTextureTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_TRUE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -42,7 +42,7 @@ TEST_F(PointerTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_TRUE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -39,7 +39,7 @@ TEST_F(SampledTextureTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_TRUE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -45,7 +45,7 @@ TEST_F(SamplerTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_TRUE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -41,7 +41,7 @@ TEST_F(StorageTextureTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_TRUE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -18,31 +18,31 @@
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::Struct);
TINT_INSTANTIATE_TYPEINFO(tint::type::StructType);
namespace tint {
namespace type {
Struct::Struct(const Symbol& sym, ast::Struct* impl)
StructType::StructType(const Symbol& sym, ast::Struct* impl)
: symbol_(sym), struct_(impl) {}
Struct::Struct(Struct&&) = default;
StructType::StructType(StructType&&) = default;
Struct::~Struct() = default;
StructType::~StructType() = default;
std::string Struct::type_name() const {
std::string StructType::type_name() const {
return "__struct_" + symbol_.to_str();
}
std::string Struct::FriendlyName(const SymbolTable& symbols) const {
std::string StructType::FriendlyName(const SymbolTable& symbols) const {
return symbols.NameFor(symbol_);
}
Struct* Struct::Clone(CloneContext* ctx) const {
StructType* StructType::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto sym = ctx->Clone(symbol());
auto* str = ctx->Clone(impl());
return ctx->dst->create<Struct>(sym, str);
return ctx->dst->create<StructType>(sym, str);
}
} // namespace type

View File

@ -24,15 +24,15 @@ namespace tint {
namespace type {
/// A structure type
class Struct : public Castable<Struct, Type> {
class StructType : public Castable<StructType, Type> {
public:
/// Constructor
/// @param sym the symbol representing the struct
/// @param impl the struct data
Struct(const Symbol& sym, ast::Struct* impl);
StructType(const Symbol& sym, ast::Struct* impl);
/// Move constructor
Struct(Struct&&);
~Struct() override;
StructType(StructType&&);
~StructType() override;
/// @returns the struct symbol
const Symbol& symbol() const { return symbol_; }
@ -54,7 +54,7 @@ class Struct : public Castable<Struct, Type> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context
/// @return the newly cloned type
Struct* Clone(CloneContext* ctx) const override;
StructType* Clone(CloneContext* ctx) const override;
private:
Symbol const symbol_;

View File

@ -44,7 +44,7 @@ TEST_F(StructTypeTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_TRUE(ty->Is<Struct>());
EXPECT_TRUE(ty->Is<StructType>());
EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -34,7 +34,7 @@ TEST_F(U32Test, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_FALSE(ty->Is<Texture>());
EXPECT_TRUE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<Vector>());

View File

@ -42,7 +42,7 @@ TEST_F(VectorTest, Is) {
EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<StructType>());
EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32>());
EXPECT_TRUE(ty->Is<Vector>());

View File

@ -207,7 +207,7 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out,
if (auto* alias = ty->As<type::Alias>()) {
// HLSL typedef is for intrinsic types only. For an alias'd struct,
// generate a secondary struct with the new name.
if (auto* str = alias->type()->As<type::Struct>()) {
if (auto* str = alias->type()->As<type::StructType>()) {
if (!EmitStructType(out, str,
builder_.Symbols().NameFor(alias->symbol()))) {
return false;
@ -220,7 +220,7 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out,
}
out << " " << builder_.Symbols().NameFor(alias->symbol()) << ";"
<< std::endl;
} else if (auto* str = ty->As<type::Struct>()) {
} else if (auto* str = ty->As<type::StructType>()) {
if (!EmitStructType(out, str, builder_.Symbols().NameFor(str->symbol()))) {
return false;
}
@ -1317,7 +1317,7 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& pre,
bool brackets = expr->type()
->UnwrapAliasIfNeeded()
->IsAnyOf<type::ArrayType, type::Struct>();
->IsAnyOf<type::ArrayType, type::StructType>();
if (brackets) {
out << "{";
@ -1708,7 +1708,7 @@ bool GeneratorImpl::EmitEntryPointData(
}
auto* type = var->Type()->UnwrapIfNeeded();
if (auto* strct = type->As<type::Struct>()) {
if (auto* strct = type->As<type::StructType>()) {
out << "ConstantBuffer<" << builder_.Symbols().NameFor(strct->symbol())
<< "> " << builder_.Symbols().NameFor(decl->symbol())
<< RegisterAndSpace('b', binding_point) << ";" << std::endl;
@ -2030,7 +2030,7 @@ bool GeneratorImpl::EmitEntryPointFunction(std::ostream& out,
for (auto* var : func->params()) {
auto* sem = builder_.Sem().Get(var);
auto* type = sem->Type();
if (!type->Is<type::Struct>()) {
if (!type->Is<type::StructType>()) {
TINT_ICE(diagnostics_) << "Unsupported non-struct entry point parameter";
}
@ -2132,7 +2132,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, type::Type* type) {
return false;
}
}
} else if (auto* str = type->As<type::Struct>()) {
} else if (auto* str = type->As<type::StructType>()) {
out << "{";
bool first = true;
for (auto* member : str->impl()->members()) {
@ -2449,7 +2449,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
out << "Comparison";
}
out << "State";
} else if (auto* str = type->As<type::Struct>()) {
} else if (auto* str = type->As<type::StructType>()) {
out << builder_.Symbols().NameFor(str->symbol());
} else if (auto* tex = type->As<type::Texture>()) {
auto* storage = tex->As<type::StorageTexture>();
@ -2539,7 +2539,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
}
bool GeneratorImpl::EmitStructType(std::ostream& out,
const type::Struct* str,
const type::StructType* str,
const std::string& name) {
auto* sem_str = builder_.Sem().Get(str);

View File

@ -299,7 +299,7 @@ class GeneratorImpl : public TextGenerator {
/// @param name the struct name
/// @returns true if the struct is emitted
bool EmitStructType(std::ostream& out,
const type::Struct* ty,
const type::StructType* ty,
const std::string& name);
/// Handles a unary op expression
/// @param pre the preamble for the expression stream

View File

@ -155,7 +155,7 @@ bool GeneratorImpl::EmitConstructedType(const type::Type* ty) {
}
out_ << " " << program_->Symbols().NameFor(alias->symbol()) << ";"
<< std::endl;
} else if (auto* str = ty->As<type::Struct>()) {
} else if (auto* str = ty->As<type::StructType>()) {
if (!EmitStructType(str)) {
return false;
}
@ -886,7 +886,7 @@ bool GeneratorImpl::EmitContinue(ast::ContinueStatement*) {
}
bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) {
if (expr->type()->IsAnyOf<type::ArrayType, type::Struct>()) {
if (expr->type()->IsAnyOf<type::ArrayType, type::StructType>()) {
out_ << "{";
} else {
if (!EmitType(expr->type(), "")) {
@ -915,7 +915,7 @@ bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) {
}
}
if (expr->type()->IsAnyOf<type::ArrayType, type::Struct>()) {
if (expr->type()->IsAnyOf<type::ArrayType, type::StructType>()) {
out_ << "}";
} else {
out_ << ")";
@ -942,7 +942,7 @@ bool GeneratorImpl::EmitZeroValue(type::Type* type) {
return false;
}
out_ << "}";
} else if (type->As<type::Struct>()) {
} else if (type->As<type::StructType>()) {
out_ << "{}";
} else {
diagnostics_.add_error("Invalid type for zero emission: " +
@ -1429,7 +1429,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) {
out_ << " " << program_->Symbols().NameFor(var->symbol());
if (type->Is<type::Struct>()) {
if (type->Is<type::StructType>()) {
out_ << " [[stage_in]]";
} else {
auto& decos = var->decorations();
@ -1947,7 +1947,7 @@ bool GeneratorImpl::EmitType(type::Type* type, const std::string& name) {
out_ << "*";
} else if (type->Is<type::Sampler>()) {
out_ << "sampler";
} else if (auto* str = type->As<type::Struct>()) {
} else if (auto* str = type->As<type::StructType>()) {
// The struct type emits as just the name. The declaration would be emitted
// as part of emitting the constructed types.
out_ << program_->Symbols().NameFor(str->symbol());
@ -2042,7 +2042,7 @@ bool GeneratorImpl::EmitPackedType(type::Type* type, const std::string& name) {
return EmitType(type, name);
}
bool GeneratorImpl::EmitStructType(const type::Struct* str) {
bool GeneratorImpl::EmitStructType(const type::StructType* str) {
// TODO(dsinclair): Block decoration?
// if (str->impl()->decoration() != ast::Decoration::kNone) {
// }
@ -2345,7 +2345,7 @@ GeneratorImpl::SizeAndAlign GeneratorImpl::MslPackedTypeSizeAndAlign(
return SizeAndAlign{el_size_align.size * num_els, el_size_align.align};
}
if (auto* str = ty->As<type::Struct>()) {
if (auto* str = ty->As<type::StructType>()) {
// TODO(crbug.com/tint/650): There's an assumption here that MSL's default
// structure size and alignment matches WGSL's. We need to confirm this.
auto* sem = program_->Sem().Get(str);

View File

@ -206,7 +206,7 @@ class GeneratorImpl : public TextGenerator {
/// Handles generating a struct declaration
/// @param str the struct to generate
/// @returns true if the struct is emitted
bool EmitStructType(const type::Struct* str);
bool EmitStructType(const type::StructType* str);
/// Handles emitting a type constructor
/// @param expr the type constructor expression
/// @returns true if the constructor is emitted

View File

@ -864,8 +864,8 @@ bool Builder::GenerateMemberAccessor(ast::MemberAccessorExpression* expr,
// If the data_type is a structure we're accessing a member, if it's a
// vector we're accessing a swizzle.
if (data_type->Is<type::Struct>()) {
auto* strct = data_type->As<type::Struct>()->impl();
if (data_type->Is<type::StructType>()) {
auto* strct = data_type->As<type::StructType>()->impl();
auto symbol = expr->member()->symbol();
uint32_t idx = 0;
@ -1252,7 +1252,7 @@ bool Builder::is_constructor_const(ast::Expression* expr, bool is_global_init) {
subtype = mat->type()->UnwrapAll();
} else if (auto* arr = subtype->As<type::ArrayType>()) {
subtype = arr->type()->UnwrapAll();
} else if (auto* str = subtype->As<type::Struct>()) {
} else if (auto* str = subtype->As<type::StructType>()) {
subtype = str->impl()->members()[i]->type()->UnwrapAll();
}
if (subtype != TypeOf(sc)->UnwrapAll()) {
@ -1329,7 +1329,8 @@ uint32_t Builder::GenerateTypeConstructorExpression(
// If the result is not a vector then we should have validated that the
// value type is a correctly sized vector so we can just use it directly.
if (result_type == value_type || result_type->Is<type::Matrix>() ||
result_type->Is<type::ArrayType>() || result_type->Is<type::Struct>()) {
result_type->Is<type::ArrayType>() ||
result_type->Is<type::StructType>()) {
out << "_" << id;
ops.push_back(Operand::Int(id));
@ -1980,14 +1981,14 @@ uint32_t Builder::GenerateIntrinsic(ast::CallExpression* call,
params.push_back(Operand::Int(struct_id));
auto* type = TypeOf(accessor->structure())->UnwrapAll();
if (!type->Is<type::Struct>()) {
if (!type->Is<type::StructType>()) {
error_ =
"invalid type (" + type->type_name() + ") for runtime array length";
return 0;
}
// Runtime array must be the last member in the structure
params.push_back(Operand::Int(
uint32_t(type->As<type::Struct>()->impl()->members().size() - 1)));
params.push_back(Operand::Int(uint32_t(
type->As<type::StructType>()->impl()->members().size() - 1)));
if (!push_function_inst(spv::Op::OpArrayLength, params)) {
return 0;
@ -2934,7 +2935,7 @@ uint32_t Builder::GenerateTypeIfNeeded(type::Type* type) {
return GenerateTypeIfNeeded(alias->type());
}
if (auto* ac = type->As<type::AccessControl>()) {
if (!ac->type()->UnwrapIfNeeded()->Is<type::Struct>()) {
if (!ac->type()->UnwrapIfNeeded()->Is<type::StructType>()) {
return GenerateTypeIfNeeded(ac->type());
}
}
@ -2949,8 +2950,8 @@ uint32_t Builder::GenerateTypeIfNeeded(type::Type* type) {
if (auto* ac = type->As<type::AccessControl>()) {
// The non-struct case was handled above.
auto* subtype = ac->type()->UnwrapIfNeeded();
if (!GenerateStructType(subtype->As<type::Struct>(), ac->access_control(),
result)) {
if (!GenerateStructType(subtype->As<type::StructType>(),
ac->access_control(), result)) {
return 0;
}
} else if (auto* arr = type->As<type::ArrayType>()) {
@ -2971,7 +2972,7 @@ uint32_t Builder::GenerateTypeIfNeeded(type::Type* type) {
if (!GeneratePointerType(ptr, result)) {
return 0;
}
} else if (auto* str = type->As<type::Struct>()) {
} else if (auto* str = type->As<type::StructType>()) {
if (!GenerateStructType(str, ast::AccessControl::kReadWrite, result)) {
return 0;
}
@ -3144,7 +3145,7 @@ bool Builder::GeneratePointerType(type::Pointer* ptr, const Operand& result) {
return true;
}
bool Builder::GenerateStructType(type::Struct* struct_type,
bool Builder::GenerateStructType(type::StructType* struct_type,
ast::AccessControl access_control,
const Operand& result) {
auto struct_id = result.to_i();

View File

@ -449,7 +449,7 @@ class Builder {
/// @param access_control the access controls to assign to the struct
/// @param result the result operand
/// @returns true if the vector was successfully generated
bool GenerateStructType(type::Struct* struct_type,
bool GenerateStructType(type::StructType* struct_type,
ast::AccessControl access_control,
const Operand& result);
/// Generates a struct member

View File

@ -123,7 +123,7 @@ bool GeneratorImpl::EmitConstructedType(const type::Type* ty) {
return false;
}
out_ << ";" << std::endl;
} else if (auto* str = ty->As<type::Struct>()) {
} else if (auto* str = ty->As<type::StructType>()) {
if (!EmitStructType(str)) {
return false;
}
@ -430,7 +430,7 @@ bool GeneratorImpl::EmitType(type::Type* type) {
if (sampler->IsComparison()) {
out_ << "_comparison";
}
} else if (auto* str = type->As<type::Struct>()) {
} else if (auto* str = type->As<type::StructType>()) {
// The struct, as a type, is just the name. We should have already emitted
// the declaration through a call to |EmitStructType| earlier.
out_ << program_->Symbols().NameFor(str->symbol());
@ -511,7 +511,7 @@ bool GeneratorImpl::EmitType(type::Type* type) {
return true;
}
bool GeneratorImpl::EmitStructType(const type::Struct* str) {
bool GeneratorImpl::EmitStructType(const type::StructType* str) {
auto* impl = str->impl();
for (auto* deco : impl->decorations()) {
out_ << "[[";

View File

@ -176,7 +176,7 @@ class GeneratorImpl : public TextGenerator {
/// Handles generating a struct declaration
/// @param str the struct
/// @returns true if the struct is emitted
bool EmitStructType(const type::Struct* str);
bool EmitStructType(const type::StructType* str);
/// Handles emitting an image format
/// @param fmt the format to generate
/// @returns true if the format is emitted