[ast] Require StructType to have a name

This CL moves the StructType name into the constructor of the struct
type instead of receiving through an accessor. The |set_name| accessor
is removed as it should not be needed anymore. All call sites have been
updated.

The vertex pulling transform was fixed to correctly register an alias
for the structure being created so it will be emitted.

Bug: tint:175
Change-Id: I8802931d9bdbc6c2f12982eea9032931939d195c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30280
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2020-10-15 17:54:13 +00:00 committed by Commit Bot service account
parent 53380f9ed7
commit 481ecff293
27 changed files with 190 additions and 174 deletions

View File

@ -56,6 +56,10 @@ bool Module::IsValid() const {
if (alias == nullptr) { if (alias == nullptr) {
return false; return false;
} }
if (alias->type()->IsStruct() &&
alias->type()->AsStruct()->name().empty()) {
return false;
}
} }
for (const auto& func : functions_) { for (const auto& func : functions_) {
if (func == nullptr || !func->IsValid()) { if (func == nullptr || !func->IsValid()) {

View File

@ -19,7 +19,9 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "src/ast/function.h" #include "src/ast/function.h"
#include "src/ast/type/alias_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/struct_type.h"
#include "src/ast/variable.h" #include "src/ast/variable.h"
namespace tint { namespace tint {
@ -99,6 +101,26 @@ TEST_F(ModuleTest, IsValid_Null_Alias) {
EXPECT_FALSE(m.IsValid()); EXPECT_FALSE(m.IsValid());
} }
TEST_F(ModuleTest, IsValid_Struct) {
type::F32Type f32;
type::StructType st("name", {});
type::AliasType alias("name", &st);
Module m;
m.AddAliasType(&alias);
EXPECT_TRUE(m.IsValid());
}
TEST_F(ModuleTest, IsValid_Struct_EmptyName) {
type::F32Type f32;
type::StructType st("", {});
type::AliasType alias("name", &st);
Module m;
m.AddAliasType(&alias);
EXPECT_FALSE(m.IsValid());
}
TEST_F(ModuleTest, IsValid_Function) { TEST_F(ModuleTest, IsValid_Function) {
type::F32Type f32; type::F32Type f32;
auto func = std::make_unique<Function>("main", VariableList(), &f32); auto func = std::make_unique<Function>("main", VariableList(), &f32);

View File

@ -20,8 +20,8 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
StructType::StructType(std::unique_ptr<Struct> impl) StructType::StructType(const std::string& name, std::unique_ptr<Struct> impl)
: struct_(std::move(impl)) {} : name_(name), struct_(std::move(impl)) {}
StructType::StructType(StructType&&) = default; StructType::StructType(StructType&&) = default;

View File

@ -29,15 +29,13 @@ namespace type {
class StructType : public Type { class StructType : public Type {
public: public:
/// Constructor /// Constructor
/// @param name the name of the struct
/// @param impl the struct data /// @param impl the struct data
explicit StructType(std::unique_ptr<Struct> impl); StructType(const std::string& name, std::unique_ptr<Struct> impl);
/// Move constructor /// Move constructor
StructType(StructType&&); StructType(StructType&&);
~StructType() override; ~StructType() override;
/// Sets the name of the struct
/// @param name the name to set
void set_name(const std::string& name) { name_ = name; }
/// @returns the struct name /// @returns the struct name
const std::string& name() const { return name_; } const std::string& name() const { return name_; }

View File

@ -29,13 +29,13 @@ using StructTypeTest = testing::Test;
TEST_F(StructTypeTest, Creation) { TEST_F(StructTypeTest, Creation) {
auto impl = std::make_unique<Struct>(); auto impl = std::make_unique<Struct>();
auto* ptr = impl.get(); auto* ptr = impl.get();
StructType s{std::move(impl)}; StructType s{"S", std::move(impl)};
EXPECT_EQ(s.impl(), ptr); EXPECT_EQ(s.impl(), ptr);
} }
TEST_F(StructTypeTest, Is) { TEST_F(StructTypeTest, Is) {
auto impl = std::make_unique<Struct>(); auto impl = std::make_unique<Struct>();
StructType s{std::move(impl)}; StructType s{"S", std::move(impl)};
EXPECT_FALSE(s.IsAlias()); EXPECT_FALSE(s.IsAlias());
EXPECT_FALSE(s.IsArray()); EXPECT_FALSE(s.IsArray());
EXPECT_FALSE(s.IsBool()); EXPECT_FALSE(s.IsBool());
@ -52,8 +52,7 @@ TEST_F(StructTypeTest, Is) {
TEST_F(StructTypeTest, TypeName) { TEST_F(StructTypeTest, TypeName) {
auto impl = std::make_unique<Struct>(); auto impl = std::make_unique<Struct>();
StructType s{std::move(impl)}; StructType s{"my_struct", std::move(impl)};
s.set_name("my_struct");
EXPECT_EQ(s.type_name(), "__struct_my_struct"); EXPECT_EQ(s.type_name(), "__struct_my_struct");
} }

View File

@ -864,12 +864,11 @@ ast::type::Type* ParserImpl::ConvertType(
// Now make the struct. // Now make the struct.
auto ast_struct = std::make_unique<ast::Struct>( auto ast_struct = std::make_unique<ast::Struct>(
std::move(ast_struct_decorations), std::move(ast_members)); std::move(ast_struct_decorations), std::move(ast_members));
// The struct type will be assigned a name during EmitAliasTypes.
auto ast_struct_type =
std::make_unique<ast::type::StructType>(std::move(ast_struct));
// Set the struct name before registering it.
namer_.SuggestSanitizedName(type_id, "S"); namer_.SuggestSanitizedName(type_id, "S");
ast_struct_type->set_name(namer_.GetName(type_id)); auto ast_struct_type = std::make_unique<ast::type::StructType>(
namer_.GetName(type_id), std::move(ast_struct));
auto* result = ctx_.type_mgr().Get(std::move(ast_struct_type)); auto* result = ctx_.type_mgr().Get(std::move(ast_struct_type));
return result; return result;
} }

View File

@ -1083,7 +1083,7 @@ ast::type::AliasType* ParserImpl::type_alias() {
if (has_error()) if (has_error())
return nullptr; return nullptr;
if (type == nullptr) { if (type == nullptr) {
auto str = struct_decl(); auto str = struct_decl(name);
if (has_error()) if (has_error())
return nullptr; return nullptr;
if (str == nullptr) { if (str == nullptr) {
@ -1091,7 +1091,6 @@ ast::type::AliasType* ParserImpl::type_alias() {
return nullptr; return nullptr;
} }
str->set_name(name);
type = ctx_.type_mgr().Get(std::move(str)); type = ctx_.type_mgr().Get(std::move(str));
} }
if (type == nullptr) { if (type == nullptr) {
@ -1479,7 +1478,8 @@ ast::StorageClass ParserImpl::storage_class() {
// struct_decl // struct_decl
// : struct_decoration_decl* STRUCT struct_body_decl // : struct_decoration_decl* STRUCT struct_body_decl
std::unique_ptr<ast::type::StructType> ParserImpl::struct_decl() { std::unique_ptr<ast::type::StructType> ParserImpl::struct_decl(
const std::string& name) {
auto t = peek(); auto t = peek();
auto source = t.source(); auto source = t.source();
@ -1506,6 +1506,7 @@ std::unique_ptr<ast::type::StructType> ParserImpl::struct_decl() {
} }
return std::make_unique<ast::type::StructType>( return std::make_unique<ast::type::StructType>(
name,
std::make_unique<ast::Struct>(source, std::move(decos), std::move(body))); std::make_unique<ast::Struct>(source, std::move(decos), std::move(body)));
} }

View File

@ -156,8 +156,9 @@ class ParserImpl {
/// @returns the storage class or StorageClass::kNone if none matched /// @returns the storage class or StorageClass::kNone if none matched
ast::StorageClass storage_class(); ast::StorageClass storage_class();
/// Parses a `struct_decl` grammar element /// Parses a `struct_decl` grammar element
/// @param name the name of the struct
/// @returns the struct type or nullptr on error /// @returns the struct type or nullptr on error
std::unique_ptr<ast::type::StructType> struct_decl(); std::unique_ptr<ast::type::StructType> struct_decl(const std::string& name);
/// Parses a `struct_decoration_decl` grammar element, appending newly /// Parses a `struct_decoration_decl` grammar element, appending newly
/// parsed decorations to the end of |decos|. /// parsed decorations to the end of |decos|.
/// @param decos list to store the parsed decorations /// @param decos list to store the parsed decorations

View File

@ -28,9 +28,10 @@ struct {
a : i32; a : i32;
[[offset(4)]] b : f32; [[offset(4)]] b : f32;
})"); })");
auto s = p->struct_decl(); auto s = p->struct_decl("S");
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ASSERT_NE(s, nullptr); ASSERT_NE(s, nullptr);
ASSERT_EQ(s->name(), "S");
ASSERT_EQ(s->impl()->members().size(), 2u); ASSERT_EQ(s->impl()->members().size(), 2u);
EXPECT_EQ(s->impl()->members()[0]->name(), "a"); EXPECT_EQ(s->impl()->members()[0]->name(), "a");
EXPECT_EQ(s->impl()->members()[1]->name(), "b"); EXPECT_EQ(s->impl()->members()[1]->name(), "b");
@ -42,9 +43,10 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) {
a : f32; a : f32;
b : f32; b : f32;
})"); })");
auto s = p->struct_decl(); auto s = p->struct_decl("B");
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ASSERT_NE(s, nullptr); ASSERT_NE(s, nullptr);
ASSERT_EQ(s->name(), "B");
ASSERT_EQ(s->impl()->members().size(), 2u); ASSERT_EQ(s->impl()->members().size(), 2u);
EXPECT_EQ(s->impl()->members()[0]->name(), "a"); EXPECT_EQ(s->impl()->members()[0]->name(), "a");
EXPECT_EQ(s->impl()->members()[1]->name(), "b"); EXPECT_EQ(s->impl()->members()[1]->name(), "b");
@ -59,9 +61,10 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) {
a : f32; a : f32;
b : f32; b : f32;
})"); })");
auto s = p->struct_decl(); auto s = p->struct_decl("S");
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ASSERT_NE(s, nullptr); ASSERT_NE(s, nullptr);
ASSERT_EQ(s->name(), "S");
ASSERT_EQ(s->impl()->members().size(), 2u); ASSERT_EQ(s->impl()->members().size(), 2u);
EXPECT_EQ(s->impl()->members()[0]->name(), "a"); EXPECT_EQ(s->impl()->members()[0]->name(), "a");
EXPECT_EQ(s->impl()->members()[1]->name(), "b"); EXPECT_EQ(s->impl()->members()[1]->name(), "b");
@ -72,7 +75,7 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) {
TEST_F(ParserImplTest, StructDecl_EmptyMembers) { TEST_F(ParserImplTest, StructDecl_EmptyMembers) {
auto* p = parser("struct {}"); auto* p = parser("struct {}");
auto s = p->struct_decl(); auto s = p->struct_decl("S");
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ASSERT_NE(s, nullptr); ASSERT_NE(s, nullptr);
ASSERT_EQ(s->impl()->members().size(), 0u); ASSERT_EQ(s->impl()->members().size(), 0u);
@ -80,7 +83,7 @@ TEST_F(ParserImplTest, StructDecl_EmptyMembers) {
TEST_F(ParserImplTest, StructDecl_MissingBracketLeft) { TEST_F(ParserImplTest, StructDecl_MissingBracketLeft) {
auto* p = parser("struct }"); auto* p = parser("struct }");
auto s = p->struct_decl(); auto s = p->struct_decl("S");
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(s, nullptr); ASSERT_EQ(s, nullptr);
EXPECT_EQ(p->error(), "1:8: missing { for struct declaration"); EXPECT_EQ(p->error(), "1:8: missing { for struct declaration");
@ -88,7 +91,7 @@ TEST_F(ParserImplTest, StructDecl_MissingBracketLeft) {
TEST_F(ParserImplTest, StructDecl_InvalidStructBody) { TEST_F(ParserImplTest, StructDecl_InvalidStructBody) {
auto* p = parser("struct { a : B; }"); auto* p = parser("struct { a : B; }");
auto s = p->struct_decl(); auto s = p->struct_decl("S");
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(s, nullptr); ASSERT_EQ(s, nullptr);
EXPECT_EQ(p->error(), "1:14: unknown type alias 'B'"); EXPECT_EQ(p->error(), "1:14: unknown type alias 'B'");
@ -96,7 +99,7 @@ TEST_F(ParserImplTest, StructDecl_InvalidStructBody) {
TEST_F(ParserImplTest, StructDecl_InvalidStructDecorationDecl) { TEST_F(ParserImplTest, StructDecl_InvalidStructDecorationDecl) {
auto* p = parser("[[block struct { a : i32; }"); auto* p = parser("[[block struct { a : i32; }");
auto s = p->struct_decl(); auto s = p->struct_decl("S");
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(s, nullptr); ASSERT_EQ(s, nullptr);
EXPECT_EQ(p->error(), "1:9: missing ]] for struct decoration"); EXPECT_EQ(p->error(), "1:9: missing ]] for struct decoration");
@ -104,7 +107,7 @@ TEST_F(ParserImplTest, StructDecl_InvalidStructDecorationDecl) {
TEST_F(ParserImplTest, StructDecl_MissingStruct) { TEST_F(ParserImplTest, StructDecl_MissingStruct) {
auto* p = parser("[[block]] {}"); auto* p = parser("[[block]] {}");
auto s = p->struct_decl(); auto s = p->struct_decl("S");
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(s, nullptr); ASSERT_EQ(s, nullptr);
EXPECT_EQ(p->error(), "1:11: missing struct declaration"); EXPECT_EQ(p->error(), "1:11: missing struct declaration");

View File

@ -26,6 +26,7 @@
#include "src/ast/struct_decoration.h" #include "src/ast/struct_decoration.h"
#include "src/ast/struct_member.h" #include "src/ast/struct_member.h"
#include "src/ast/struct_member_offset_decoration.h" #include "src/ast/struct_member_offset_decoration.h"
#include "src/ast/type/alias_type.h"
#include "src/ast/type/array_type.h" #include "src/ast/type/array_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
@ -42,6 +43,7 @@ namespace {
static const char kVertexBufferNamePrefix[] = "_tint_pulling_vertex_buffer_"; static const char kVertexBufferNamePrefix[] = "_tint_pulling_vertex_buffer_";
static const char kStructBufferName[] = "_tint_vertex_data"; static const char kStructBufferName[] = "_tint_vertex_data";
static const char kStructName[] = "TintVertexData";
static const char kPullingPosVarName[] = "_tint_pulling_pos"; static const char kPullingPosVarName[] = "_tint_pulling_pos";
static const char kDefaultVertexIndexName[] = "_tint_pulling_vertex_index"; static const char kDefaultVertexIndexName[] = "_tint_pulling_vertex_index";
static const char kDefaultInstanceIndexName[] = "_tint_pulling_instance_index"; static const char kDefaultInstanceIndexName[] = "_tint_pulling_instance_index";
@ -235,14 +237,16 @@ void VertexPullingTransform::AddVertexStorageBuffers() {
auto* struct_type = auto* struct_type =
ctx_->type_mgr().Get(std::make_unique<ast::type::StructType>( ctx_->type_mgr().Get(std::make_unique<ast::type::StructType>(
kStructName,
std::make_unique<ast::Struct>(std::move(decos), std::move(members)))); std::make_unique<ast::Struct>(std::move(decos), std::move(members))));
auto* alias = ctx_->type_mgr().Get(
std::make_unique<ast::type::AliasType>(kStructName, struct_type));
for (uint32_t i = 0; i < vertex_state_->vertex_buffers.size(); ++i) { for (uint32_t i = 0; i < vertex_state_->vertex_buffers.size(); ++i) {
// The decorated variable with struct type // The decorated variable with struct type
auto var = std::make_unique<ast::DecoratedVariable>( auto var = std::make_unique<ast::DecoratedVariable>(
std::make_unique<ast::Variable>(GetVertexBufferName(i), std::make_unique<ast::Variable>(
ast::StorageClass::kStorageBuffer, GetVertexBufferName(i), ast::StorageClass::kStorageBuffer, alias));
struct_type));
// Add decorations // Add decorations
ast::VariableDecorationList decorations; ast::VariableDecorationList decorations;
@ -252,6 +256,7 @@ void VertexPullingTransform::AddVertexStorageBuffers() {
mod_->AddGlobalVariable(std::move(var)); mod_->AddGlobalVariable(std::move(var));
} }
mod_->AddAliasType(alias->AsAlias());
} }
void VertexPullingTransform::AddVertexPullingPreamble( void VertexPullingTransform::AddVertexPullingPreamble(

View File

@ -156,7 +156,12 @@ TEST_F(VertexPullingTransformTest, OneAttribute) {
} }
_tint_pulling_vertex_buffer_0 _tint_pulling_vertex_buffer_0
storage_buffer storage_buffer
__struct_ __alias_TintVertexData__struct_TintVertexData
}
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
} }
Function main -> __void Function main -> __void
StageDecoration{vertex} StageDecoration{vertex}
@ -237,7 +242,12 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) {
} }
_tint_pulling_vertex_buffer_0 _tint_pulling_vertex_buffer_0
storage_buffer storage_buffer
__struct_ __alias_TintVertexData__struct_TintVertexData
}
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
} }
Function main -> __void Function main -> __void
StageDecoration{vertex} StageDecoration{vertex}
@ -318,7 +328,12 @@ TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) {
} }
_tint_pulling_vertex_buffer_0 _tint_pulling_vertex_buffer_0
storage_buffer storage_buffer
__struct_ __alias_TintVertexData__struct_TintVertexData
}
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
} }
Function main -> __void Function main -> __void
StageDecoration{vertex} StageDecoration{vertex}
@ -442,7 +457,7 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
} }
_tint_pulling_vertex_buffer_0 _tint_pulling_vertex_buffer_0
storage_buffer storage_buffer
__struct_ __alias_TintVertexData__struct_TintVertexData
} }
DecoratedVariable{ DecoratedVariable{
Decorations{ Decorations{
@ -451,7 +466,12 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
} }
_tint_pulling_vertex_buffer_1 _tint_pulling_vertex_buffer_1
storage_buffer storage_buffer
__struct_ __alias_TintVertexData__struct_TintVertexData
}
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
} }
Function main -> __void Function main -> __void
StageDecoration{vertex} StageDecoration{vertex}
@ -570,7 +590,12 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) {
} }
_tint_pulling_vertex_buffer_0 _tint_pulling_vertex_buffer_0
storage_buffer storage_buffer
__struct_ __alias_TintVertexData__struct_TintVertexData
}
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
} }
Function main -> __void Function main -> __void
StageDecoration{vertex} StageDecoration{vertex}
@ -756,7 +781,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
} }
_tint_pulling_vertex_buffer_0 _tint_pulling_vertex_buffer_0
storage_buffer storage_buffer
__struct_ __alias_TintVertexData__struct_TintVertexData
} }
DecoratedVariable{ DecoratedVariable{
Decorations{ Decorations{
@ -765,7 +790,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
} }
_tint_pulling_vertex_buffer_1 _tint_pulling_vertex_buffer_1
storage_buffer storage_buffer
__struct_ __alias_TintVertexData__struct_TintVertexData
} }
DecoratedVariable{ DecoratedVariable{
Decorations{ Decorations{
@ -774,7 +799,12 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
} }
_tint_pulling_vertex_buffer_2 _tint_pulling_vertex_buffer_2
storage_buffer storage_buffer
__struct_ __alias_TintVertexData__struct_TintVertexData
}
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
} }
Function main -> __void Function main -> __void
StageDecoration{vertex} StageDecoration{vertex}

View File

@ -1037,7 +1037,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct) {
auto strct = std::make_unique<ast::Struct>(std::move(members)); auto strct = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType st(std::move(strct)); ast::type::StructType st("S", std::move(strct));
auto var = std::make_unique<ast::Variable>("my_struct", auto var = std::make_unique<ast::Variable>("my_struct",
ast::StorageClass::kNone, &st); ast::StorageClass::kNone, &st);
@ -1072,7 +1072,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct_Alias) {
auto strct = std::make_unique<ast::Struct>(std::move(members)); auto strct = std::make_unique<ast::Struct>(std::move(members));
auto st = std::make_unique<ast::type::StructType>(std::move(strct)); auto st = std::make_unique<ast::type::StructType>("alias", std::move(strct));
ast::type::AliasType alias("alias", st.get()); ast::type::AliasType alias("alias", st.get());
auto var = std::make_unique<ast::Variable>("my_struct", auto var = std::make_unique<ast::Variable>("my_struct",
@ -1176,8 +1176,7 @@ TEST_F(TypeDeterminerTest, Expr_Accessor_MultiLevel) {
std::make_unique<ast::StructMember>("foo", &vec4, std::move(decos))); std::make_unique<ast::StructMember>("foo", &vec4, std::move(decos)));
auto strctB = std::make_unique<ast::Struct>(std::move(b_members)); auto strctB = std::make_unique<ast::Struct>(std::move(b_members));
ast::type::StructType stB(std::move(strctB)); ast::type::StructType stB("B", std::move(strctB));
stB.set_name("B");
ast::type::VectorType vecB(&stB, 3); ast::type::VectorType vecB(&stB, 3);
@ -1187,8 +1186,7 @@ TEST_F(TypeDeterminerTest, Expr_Accessor_MultiLevel) {
auto strctA = std::make_unique<ast::Struct>(std::move(a_members)); auto strctA = std::make_unique<ast::Struct>(std::move(a_members));
ast::type::StructType stA(std::move(strctA)); ast::type::StructType stA("A", std::move(strctA));
stA.set_name("A");
auto var = auto var =
std::make_unique<ast::Variable>("c", ast::StorageClass::kNone, &stA); std::make_unique<ast::Variable>("c", ast::StorageClass::kNone, &stA);

View File

@ -63,7 +63,7 @@ TEST_F(HlslGeneratorImplTest_AliasType, EmitAliasType_Struct) {
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("a", std::move(str));
ast::type::AliasType alias("a", &s); ast::type::AliasType alias("a", &s);
ast::Module m; ast::Module m;

View File

@ -309,8 +309,7 @@ TEST_F(HlslGeneratorImplTest_Function,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Uniforms", std::move(str));
s.set_name("Uniforms");
auto alias = std::make_unique<ast::type::AliasType>("Uniforms", &s); auto alias = std::make_unique<ast::type::AliasType>("Uniforms", &s);
auto coord_var = auto coord_var =
@ -384,8 +383,7 @@ TEST_F(HlslGeneratorImplTest_Function,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -450,8 +448,7 @@ TEST_F(HlslGeneratorImplTest_Function,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(

View File

@ -58,8 +58,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
auto strct = std::make_unique<ast::Struct>(); auto strct = std::make_unique<ast::Struct>();
strct->set_members(std::move(members)); strct->set_members(std::move(members));
ast::type::StructType s(std::move(strct)); ast::type::StructType s("Str", std::move(strct));
s.set_name("Str");
auto str_var = std::make_unique<ast::DecoratedVariable>( auto str_var = std::make_unique<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("str", ast::StorageClass::kPrivate, &s)); std::make_unique<ast::Variable>("str", ast::StorageClass::kPrivate, &s));
@ -105,8 +104,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -154,8 +152,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -206,8 +203,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto b_var = auto b_var =
std::make_unique<ast::Variable>("b", ast::StorageClass::kPrivate, &mat); std::make_unique<ast::Variable>("b", ast::StorageClass::kPrivate, &mat);
@ -270,8 +266,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -330,8 +325,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -386,8 +380,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -434,8 +427,7 @@ TEST_F(
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -486,8 +478,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -539,8 +530,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -589,8 +579,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -650,8 +639,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -702,8 +690,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -759,8 +746,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -815,8 +801,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -867,8 +852,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("Data", std::move(str));
s.set_name("Data");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -940,8 +924,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto data_str = std::make_unique<ast::Struct>(); auto data_str = std::make_unique<ast::Struct>();
data_str->set_members(std::move(members)); data_str->set_members(std::move(members));
ast::type::StructType data(std::move(data_str)); ast::type::StructType data("Data", std::move(data_str));
data.set_name("Data");
ast::type::ArrayType ary(&data, 4); ast::type::ArrayType ary(&data, 4);
ast::ArrayDecorationList decos; ast::ArrayDecorationList decos;
@ -955,8 +938,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto pre_str = std::make_unique<ast::Struct>(); auto pre_str = std::make_unique<ast::Struct>();
pre_str->set_members(std::move(members)); pre_str->set_members(std::move(members));
ast::type::StructType pre_struct(std::move(pre_str)); ast::type::StructType pre_struct("Pre", std::move(pre_str));
pre_struct.set_name("Pre");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -1015,8 +997,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto data_str = std::make_unique<ast::Struct>(); auto data_str = std::make_unique<ast::Struct>();
data_str->set_members(std::move(members)); data_str->set_members(std::move(members));
ast::type::StructType data(std::move(data_str)); ast::type::StructType data("Data", std::move(data_str));
data.set_name("Data");
ast::type::ArrayType ary(&data, 4); ast::type::ArrayType ary(&data, 4);
ast::ArrayDecorationList decos; ast::ArrayDecorationList decos;
@ -1030,8 +1011,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto pre_str = std::make_unique<ast::Struct>(); auto pre_str = std::make_unique<ast::Struct>();
pre_str->set_members(std::move(members)); pre_str->set_members(std::move(members));
ast::type::StructType pre_struct(std::move(pre_str)); ast::type::StructType pre_struct("Pre", std::move(pre_str));
pre_struct.set_name("Pre");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -1093,8 +1073,7 @@ TEST_F(
auto data_str = std::make_unique<ast::Struct>(); auto data_str = std::make_unique<ast::Struct>();
data_str->set_members(std::move(members)); data_str->set_members(std::move(members));
ast::type::StructType data(std::move(data_str)); ast::type::StructType data("Data", std::move(data_str));
data.set_name("Data");
ast::type::ArrayType ary(&data, 4); ast::type::ArrayType ary(&data, 4);
ast::ArrayDecorationList decos; ast::ArrayDecorationList decos;
@ -1108,8 +1087,7 @@ TEST_F(
auto pre_str = std::make_unique<ast::Struct>(); auto pre_str = std::make_unique<ast::Struct>();
pre_str->set_members(std::move(members)); pre_str->set_members(std::move(members));
ast::type::StructType pre_struct(std::move(pre_str)); ast::type::StructType pre_struct("Pre", std::move(pre_str));
pre_struct.set_name("Pre");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -1170,8 +1148,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto data_str = std::make_unique<ast::Struct>(); auto data_str = std::make_unique<ast::Struct>();
data_str->set_members(std::move(members)); data_str->set_members(std::move(members));
ast::type::StructType data(std::move(data_str)); ast::type::StructType data("Data", std::move(data_str));
data.set_name("Data");
ast::type::ArrayType ary(&data, 4); ast::type::ArrayType ary(&data, 4);
ast::ArrayDecorationList decos; ast::ArrayDecorationList decos;
@ -1185,8 +1162,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto pre_str = std::make_unique<ast::Struct>(); auto pre_str = std::make_unique<ast::Struct>();
pre_str->set_members(std::move(members)); pre_str->set_members(std::move(members));
ast::type::StructType pre_struct(std::move(pre_str)); ast::type::StructType pre_struct("Pre", std::move(pre_str));
pre_struct.set_name("Pre");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -1248,8 +1224,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto data_str = std::make_unique<ast::Struct>(); auto data_str = std::make_unique<ast::Struct>();
data_str->set_members(std::move(members)); data_str->set_members(std::move(members));
ast::type::StructType data(std::move(data_str)); ast::type::StructType data("Data", std::move(data_str));
data.set_name("Data");
ast::type::ArrayType ary(&data, 4); ast::type::ArrayType ary(&data, 4);
ast::ArrayDecorationList decos; ast::ArrayDecorationList decos;
@ -1263,8 +1238,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto pre_str = std::make_unique<ast::Struct>(); auto pre_str = std::make_unique<ast::Struct>();
pre_str->set_members(std::move(members)); pre_str->set_members(std::move(members));
ast::type::StructType pre_struct(std::move(pre_str)); ast::type::StructType pre_struct("Pre", std::move(pre_str));
pre_struct.set_name("Pre");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -1342,8 +1316,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto data_str = std::make_unique<ast::Struct>(); auto data_str = std::make_unique<ast::Struct>();
data_str->set_members(std::move(members)); data_str->set_members(std::move(members));
ast::type::StructType data(std::move(data_str)); ast::type::StructType data("Data", std::move(data_str));
data.set_name("Data");
ast::type::ArrayType ary(&data, 4); ast::type::ArrayType ary(&data, 4);
ast::ArrayDecorationList decos; ast::ArrayDecorationList decos;
@ -1357,8 +1330,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto pre_str = std::make_unique<ast::Struct>(); auto pre_str = std::make_unique<ast::Struct>();
pre_str->set_members(std::move(members)); pre_str->set_members(std::move(members));
ast::type::StructType pre_struct(std::move(pre_str)); ast::type::StructType pre_struct("Pre", std::move(pre_str));
pre_struct.set_name("Pre");
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(

View File

@ -179,7 +179,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) {
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("S", std::move(str));
ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error(); ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error();
EXPECT_EQ(result(), R"(struct { EXPECT_EQ(result(), R"(struct {
@ -210,7 +210,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_InjectPadding) {
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("S", std::move(str));
ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error(); ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error();
EXPECT_EQ(result(), R"(struct { EXPECT_EQ(result(), R"(struct {
@ -238,7 +238,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("S", std::move(str));
ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error(); ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error();
EXPECT_EQ(result(), R"(struct { EXPECT_EQ(result(), R"(struct {
@ -267,7 +267,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) {
auto str = auto str =
std::make_unique<ast::Struct>(std::move(decos), std::move(members)); std::make_unique<ast::Struct>(std::move(decos), std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("S", std::move(str));
ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error(); ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error();
EXPECT_EQ(result(), R"(struct { EXPECT_EQ(result(), R"(struct {

View File

@ -68,7 +68,7 @@ TEST_F(MslGeneratorImplTest, EmitAliasType_Struct) {
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("a", std::move(str));
ast::type::AliasType alias("a", &s); ast::type::AliasType alias("a", &s);
ast::Module m; ast::Module m;

View File

@ -201,7 +201,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct) {
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("S", std::move(str));
ast::Module m; ast::Module m;
GeneratorImpl g(&m); GeneratorImpl g(&m);
@ -231,7 +231,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) {
auto inner_str = std::make_unique<ast::Struct>(); auto inner_str = std::make_unique<ast::Struct>();
inner_str->set_members(std::move(members)); inner_str->set_members(std::move(members));
ast::type::StructType inner_s(std::move(inner_str)); ast::type::StructType inner_s("Inner", std::move(inner_str));
decos.push_back(std::make_unique<ast::StructMemberOffsetDecoration>(0)); decos.push_back(std::make_unique<ast::StructMemberOffsetDecoration>(0));
members.push_back( members.push_back(
@ -248,7 +248,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) {
auto outer_str = std::make_unique<ast::Struct>(); auto outer_str = std::make_unique<ast::Struct>();
outer_str->set_members(std::move(members)); outer_str->set_members(std::move(members));
ast::type::StructType outer_s(std::move(outer_str)); ast::type::StructType outer_s("Outer", std::move(outer_str));
ast::Module m; ast::Module m;
GeneratorImpl g(&m); GeneratorImpl g(&m);

View File

@ -208,7 +208,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct) {
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("S", std::move(str));
ast::Module m; ast::Module m;
GeneratorImpl g(&m); GeneratorImpl g(&m);
@ -241,7 +241,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_InjectPadding) {
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("S", std::move(str));
ast::Module m; ast::Module m;
GeneratorImpl g(&m); GeneratorImpl g(&m);
@ -271,7 +271,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_NameCollision) {
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("S", std::move(str));
ast::Module m; ast::Module m;
GeneratorImpl g(&m); GeneratorImpl g(&m);
@ -301,7 +301,7 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) {
auto str = auto str =
std::make_unique<ast::Struct>(std::move(decos), std::move(members)); std::make_unique<ast::Struct>(std::move(decos), std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("S", std::move(str));
ast::Module m; ast::Module m;
GeneratorImpl g(&m); GeneratorImpl g(&m);

View File

@ -102,7 +102,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("S", std::move(str));
auto var = std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &s); auto var = std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &s);

View File

@ -309,8 +309,7 @@ TEST_F(BuilderTest, MemberAccessor) {
std::make_unique<ast::StructMember>("b", &f32, std::move(decos))); std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
s_type.set_name("my_struct");
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
@ -366,15 +365,14 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
std::make_unique<ast::StructMember>("b", &f32, std::move(decos))); std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
ast::type::StructType inner_struct( ast::type::StructType inner_struct(
std::make_unique<ast::Struct>(std::move(inner_members))); "Inner", std::make_unique<ast::Struct>(std::move(inner_members)));
ast::StructMemberList outer_members; ast::StructMemberList outer_members;
outer_members.push_back(std::make_unique<ast::StructMember>( outer_members.push_back(std::make_unique<ast::StructMember>(
"inner", &inner_struct, std::move(decos))); "inner", &inner_struct, std::move(decos)));
ast::type::StructType s_type( ast::type::StructType s_type(
std::make_unique<ast::Struct>(std::move(outer_members))); "my_struct", std::make_unique<ast::Struct>(std::move(outer_members)));
s_type.set_name("my_struct");
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
@ -434,7 +432,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
std::make_unique<ast::StructMember>("b", &f32, std::move(decos))); std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
ast::type::StructType inner_struct( ast::type::StructType inner_struct(
std::make_unique<ast::Struct>(std::move(inner_members))); "Inner", std::make_unique<ast::Struct>(std::move(inner_members)));
ast::type::AliasType alias("Inner", &inner_struct); ast::type::AliasType alias("Inner", &inner_struct);
@ -443,8 +441,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
std::make_unique<ast::StructMember>("inner", &alias, std::move(decos))); std::make_unique<ast::StructMember>("inner", &alias, std::move(decos)));
ast::type::StructType s_type( ast::type::StructType s_type(
std::make_unique<ast::Struct>(std::move(outer_members))); "Outer", std::make_unique<ast::Struct>(std::move(outer_members)));
s_type.set_name("my_struct");
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
@ -504,15 +501,14 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
std::make_unique<ast::StructMember>("b", &f32, std::move(decos))); std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
ast::type::StructType inner_struct( ast::type::StructType inner_struct(
std::make_unique<ast::Struct>(std::move(inner_members))); "Inner", std::make_unique<ast::Struct>(std::move(inner_members)));
ast::StructMemberList outer_members; ast::StructMemberList outer_members;
outer_members.push_back(std::make_unique<ast::StructMember>( outer_members.push_back(std::make_unique<ast::StructMember>(
"inner", &inner_struct, std::move(decos))); "inner", &inner_struct, std::move(decos)));
ast::type::StructType s_type( ast::type::StructType s_type(
std::make_unique<ast::Struct>(std::move(outer_members))); "my_struct", std::make_unique<ast::Struct>(std::move(outer_members)));
s_type.set_name("my_struct");
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
@ -579,15 +575,14 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
std::make_unique<ast::StructMember>("b", &f32, std::move(decos))); std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
ast::type::StructType inner_struct( ast::type::StructType inner_struct(
std::make_unique<ast::Struct>(std::move(inner_members))); "Inner", std::make_unique<ast::Struct>(std::move(inner_members)));
ast::StructMemberList outer_members; ast::StructMemberList outer_members;
outer_members.push_back(std::make_unique<ast::StructMember>( outer_members.push_back(std::make_unique<ast::StructMember>(
"inner", &inner_struct, std::move(decos))); "inner", &inner_struct, std::move(decos)));
ast::type::StructType s_type( ast::type::StructType s_type(
std::make_unique<ast::Struct>(std::move(outer_members))); "my_struct", std::make_unique<ast::Struct>(std::move(outer_members)));
s_type.set_name("my_struct");
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
ast::Variable store("store", ast::StorageClass::kFunction, &f32); ast::Variable store("store", ast::StorageClass::kFunction, &f32);
@ -866,22 +861,19 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
members.push_back( members.push_back(
std::make_unique<ast::StructMember>("baz", &vec3, std::move(decos))); std::make_unique<ast::StructMember>("baz", &vec3, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType c_type(std::move(s)); ast::type::StructType c_type("C", std::move(s));
c_type.set_name("C");
members.push_back( members.push_back(
std::make_unique<ast::StructMember>("bar", &c_type, std::move(decos))); std::make_unique<ast::StructMember>("bar", &c_type, std::move(decos)));
s = std::make_unique<ast::Struct>(std::move(members)); s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType b_type(std::move(s)); ast::type::StructType b_type("B", std::move(s));
b_type.set_name("B");
ast::type::ArrayType b_ary_type(&b_type, 3); ast::type::ArrayType b_ary_type(&b_type, 3);
members.push_back(std::make_unique<ast::StructMember>("foo", &b_ary_type, members.push_back(std::make_unique<ast::StructMember>("foo", &b_ary_type,
std::move(decos))); std::move(decos)));
s = std::make_unique<ast::Struct>(std::move(members)); s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType a_type(std::move(s)); ast::type::StructType a_type("A", std::move(s));
a_type.set_name("A");
ast::type::ArrayType a_ary_type(&a_type, 2); ast::type::ArrayType a_ary_type(&a_type, 2);

View File

@ -241,8 +241,7 @@ TEST_F(BuilderTest, Assign_StructMember) {
std::make_unique<ast::StructMember>("b", &f32, std::move(decos))); std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
s_type.set_name("my_struct");
ast::Variable v("ident", ast::StorageClass::kFunction, &s_type); ast::Variable v("ident", ast::StorageClass::kFunction, &s_type);

View File

@ -1791,8 +1791,7 @@ TEST_F(BuilderTest, Constructor_Type_Struct) {
std::make_unique<ast::StructMember>("b", &vec, std::move(decos))); std::make_unique<ast::StructMember>("b", &vec, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
s_type.set_name("my_struct");
ast::ExpressionList vec_vals; ast::ExpressionList vec_vals;
vec_vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vec_vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
@ -2002,8 +2001,7 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_Struct) {
std::make_unique<ast::StructMember>("a", &f32, std::move(decos))); std::make_unique<ast::StructMember>("a", &f32, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
s_type.set_name("my_struct");
ast::ExpressionList vals; ast::ExpressionList vals;
ast::TypeConstructorExpression t(&s_type, std::move(vals)); ast::TypeConstructorExpression t(&s_type, std::move(vals));
@ -2775,8 +2773,7 @@ TEST_F(BuilderTest, IsConstructorConst_Struct) {
std::make_unique<ast::StructMember>("b", &vec, std::move(decos))); std::make_unique<ast::StructMember>("b", &vec, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
s_type.set_name("my_struct");
ast::ExpressionList vec_vals; ast::ExpressionList vec_vals;
vec_vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vec_vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
@ -2816,8 +2813,7 @@ TEST_F(BuilderTest, IsConstructorConst_Struct_WithIdentSubExpression) {
std::make_unique<ast::StructMember>("b", &vec, std::move(decos))); std::make_unique<ast::StructMember>("b", &vec, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
s_type.set_name("my_struct");
ast::ExpressionList vec_vals; ast::ExpressionList vec_vals;
vec_vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vec_vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(

View File

@ -2733,8 +2733,7 @@ TEST_F(BuilderTest, Call_ArrayLength) {
std::make_unique<ast::StructMember>("a", &ary, std::move(decos))); std::make_unique<ast::StructMember>("a", &ary, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
s_type.set_name("my_struct");
auto var = std::make_unique<ast::Variable>("b", ast::StorageClass::kPrivate, auto var = std::make_unique<ast::Variable>("b", ast::StorageClass::kPrivate,
&s_type); &s_type);
@ -2792,8 +2791,7 @@ TEST_F(BuilderTest, Call_ArrayLength_OtherMembersInStruct) {
std::make_unique<ast::StructMember>("a", &ary, std::move(decos))); std::make_unique<ast::StructMember>("a", &ary, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
s_type.set_name("my_struct");
auto var = std::make_unique<ast::Variable>("b", ast::StorageClass::kPrivate, auto var = std::make_unique<ast::Variable>("b", ast::StorageClass::kPrivate,
&s_type); &s_type);
@ -2853,8 +2851,7 @@ TEST_F(BuilderTest, DISABLED_Call_ArrayLength_Ptr) {
std::make_unique<ast::StructMember>("a", &ary, std::move(decos))); std::make_unique<ast::StructMember>("a", &ary, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
s_type.set_name("my_struct");
auto var = std::make_unique<ast::Variable>("b", ast::StorageClass::kPrivate, auto var = std::make_unique<ast::Variable>("b", ast::StorageClass::kPrivate,
&s_type); &s_type);

View File

@ -311,7 +311,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedPtr) {
TEST_F(BuilderTest_Type, GenerateStruct_Empty) { TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
auto s = std::make_unique<ast::Struct>(); auto s = std::make_unique<ast::Struct>();
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("S", std::move(s));
ast::Module mod; ast::Module mod;
Builder b(&mod); Builder b(&mod);
@ -320,7 +320,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
EXPECT_EQ(id, 1u); EXPECT_EQ(id, 1u);
EXPECT_EQ(b.types().size(), 1u); EXPECT_EQ(b.types().size(), 1u);
EXPECT_EQ(DumpInstructions(b.debug()), ""); EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeStruct EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeStruct
)"); )");
} }
@ -334,8 +335,7 @@ TEST_F(BuilderTest_Type, GenerateStruct) {
std::make_unique<ast::StructMember>("a", &f32, std::move(decos))); std::make_unique<ast::StructMember>("a", &f32, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
s_type.set_name("my_struct");
ast::Module mod; ast::Module mod;
Builder b(&mod); Builder b(&mod);
@ -364,8 +364,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_Decorated) {
auto s = std::make_unique<ast::Struct>(std::move(struct_decos), auto s = std::make_unique<ast::Struct>(std::move(struct_decos),
std::move(members)); std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
s_type.set_name("my_struct");
ast::Module mod; ast::Module mod;
Builder b(&mod); Builder b(&mod);
@ -398,7 +397,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers) {
std::make_unique<ast::StructMember>("b", &f32, std::move(b_decos))); std::make_unique<ast::StructMember>("b", &f32, std::move(b_decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("S", std::move(s));
ast::Module mod; ast::Module mod;
Builder b(&mod); Builder b(&mod);
@ -409,7 +408,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers) {
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeStruct %2 %2 %1 = OpTypeStruct %2 %2
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpMemberName %1 0 "a" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
OpMemberName %1 0 "a"
OpMemberName %1 1 "b" OpMemberName %1 1 "b"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
@ -436,7 +436,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_NonLayout_Matrix) {
std::move(empty_c))); std::move(empty_c)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("S", std::move(s));
ast::Module mod; ast::Module mod;
Builder b(&mod); Builder b(&mod);
@ -453,7 +453,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_NonLayout_Matrix) {
%7 = OpTypeMatrix %8 4 %7 = OpTypeMatrix %8 4
%1 = OpTypeStruct %2 %5 %7 %1 = OpTypeStruct %2 %5 %7
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpMemberName %1 0 "a" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
OpMemberName %1 0 "a"
OpMemberName %1 1 "b" OpMemberName %1 1 "b"
OpMemberName %1 2 "c" OpMemberName %1 2 "c"
)"); )");
@ -483,7 +484,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutMatrix) {
std::move(c_decos))); std::move(c_decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("S", std::move(s));
ast::Module mod; ast::Module mod;
Builder b(&mod); Builder b(&mod);
@ -500,7 +501,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutMatrix) {
%7 = OpTypeMatrix %8 4 %7 = OpTypeMatrix %8 4
%1 = OpTypeStruct %2 %5 %7 %1 = OpTypeStruct %2 %5 %7
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpMemberName %1 0 "a" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
OpMemberName %1 0 "a"
OpMemberName %1 1 "b" OpMemberName %1 1 "b"
OpMemberName %1 2 "c" OpMemberName %1 2 "c"
)"); )");
@ -548,7 +550,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutArraysOfMatrix) {
std::move(c_decos))); std::move(c_decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType s_type(std::move(s)); ast::type::StructType s_type("S", std::move(s));
ast::Module mod; ast::Module mod;
Builder b(&mod); Builder b(&mod);
@ -565,7 +567,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutArraysOfMatrix) {
%7 = OpTypeMatrix %8 4 %7 = OpTypeMatrix %8 4
%1 = OpTypeStruct %2 %5 %7 %1 = OpTypeStruct %2 %5 %7
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpMemberName %1 0 "a" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
OpMemberName %1 0 "a"
OpMemberName %1 1 "b" OpMemberName %1 1 "b"
OpMemberName %1 2 "c" OpMemberName %1 2 "c"
)"); )");

View File

@ -55,7 +55,7 @@ TEST_F(WgslGeneratorImplTest, EmitAliasType_Struct) {
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("a", std::move(str));
ast::type::AliasType alias("a", &s); ast::type::AliasType alias("a", &s);
GeneratorImpl g; GeneratorImpl g;

View File

@ -155,7 +155,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct) {
auto str = std::make_unique<ast::Struct>(); auto str = std::make_unique<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("S", std::move(str));
GeneratorImpl g; GeneratorImpl g;
ASSERT_TRUE(g.EmitType(&s)) << g.error(); ASSERT_TRUE(g.EmitType(&s)) << g.error();
@ -185,7 +185,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithDecoration) {
auto str = auto str =
std::make_unique<ast::Struct>(std::move(decos), std::move(members)); std::make_unique<ast::Struct>(std::move(decos), std::move(members));
ast::type::StructType s(std::move(str)); ast::type::StructType s("S", std::move(str));
GeneratorImpl g; GeneratorImpl g;
ASSERT_TRUE(g.EmitType(&s)) << g.error(); ASSERT_TRUE(g.EmitType(&s)) << g.error();