Replace Type::(Is|As)Struct with Castable
Change-Id: I0bc5645d65d7b53058bda7b343a991a9614741be Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34271 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
351128a41e
commit
d734dd0c10
|
@ -61,12 +61,12 @@ bool Module::IsValid() const {
|
|||
if (alias->type() == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (alias->type()->IsStruct() &&
|
||||
alias->type()->AsStruct()->name().empty()) {
|
||||
if (alias->type()->Is<ast::type::StructType>() &&
|
||||
alias->type()->As<ast::type::StructType>()->name().empty()) {
|
||||
return false;
|
||||
}
|
||||
} else if (ty->IsStruct()) {
|
||||
auto* str = ty->AsStruct();
|
||||
} else if (ty->Is<ast::type::StructType>()) {
|
||||
auto* str = ty->As<ast::type::StructType>();
|
||||
if (str->name().empty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -94,11 +94,11 @@ std::string Module::to_str() const {
|
|||
if (ty->Is<ast::type::AliasType>()) {
|
||||
auto* alias = ty->As<ast::type::AliasType>();
|
||||
out << alias->name() << " -> " << alias->type()->type_name() << std::endl;
|
||||
if (alias->type()->IsStruct()) {
|
||||
alias->type()->AsStruct()->impl()->to_str(out, indent);
|
||||
if (alias->type()->Is<ast::type::StructType>()) {
|
||||
alias->type()->As<ast::type::StructType>()->impl()->to_str(out, indent);
|
||||
}
|
||||
} else if (ty->IsStruct()) {
|
||||
auto* str = ty->AsStruct();
|
||||
} else if (ty->Is<ast::type::StructType>()) {
|
||||
auto* str = ty->As<ast::type::StructType>();
|
||||
out << str->name() << " ";
|
||||
str->impl()->to_str(out, indent);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ TEST_F(AccessControlTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -61,7 +61,7 @@ TEST_F(AliasTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/type/u32_type.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -66,7 +67,7 @@ TEST_F(ArrayTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -41,7 +42,7 @@ TEST_F(BoolTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -43,7 +44,7 @@ TEST_F(DepthTextureTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_TRUE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -41,7 +42,7 @@ TEST_F(F32TypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -41,7 +42,7 @@ TEST_F(I32TypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -50,7 +51,7 @@ TEST_F(MatrixTypeTest, Is) {
|
|||
EXPECT_TRUE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -43,7 +44,7 @@ TEST_F(MultisampledTextureTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_TRUE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -49,7 +50,7 @@ TEST_F(PointerTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_TRUE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -43,7 +44,7 @@ TEST_F(SampledTextureTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_TRUE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -53,7 +54,7 @@ TEST_F(SamplerTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_TRUE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/type_determiner.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -47,7 +48,7 @@ TEST_F(StorageTextureTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_TRUE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -33,10 +33,6 @@ StructType::StructType(StructType&&) = default;
|
|||
|
||||
StructType::~StructType() = default;
|
||||
|
||||
bool StructType::IsStruct() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string StructType::type_name() const {
|
||||
return "__struct_" + name_;
|
||||
}
|
||||
|
|
|
@ -42,9 +42,6 @@ class StructType : public Castable<StructType, Type> {
|
|||
/// @returns true if the struct has a block decoration
|
||||
bool IsBlockDecorated() const { return struct_->IsBlockDecorated(); }
|
||||
|
||||
/// @returns true if the type is a struct type
|
||||
bool IsStruct() const override;
|
||||
|
||||
/// @returns the struct name
|
||||
Struct* impl() const { return struct_; }
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ TEST_F(StructTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_TRUE(ty->IsStruct());
|
||||
EXPECT_TRUE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -66,10 +66,6 @@ Type* Type::UnwrapAll() {
|
|||
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
|
||||
}
|
||||
|
||||
bool Type::IsStruct() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Type::IsTexture() const {
|
||||
return false;
|
||||
}
|
||||
|
@ -138,11 +134,6 @@ bool Type::is_integer_scalar_or_vector() {
|
|||
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
|
||||
}
|
||||
|
||||
const StructType* Type::AsStruct() const {
|
||||
assert(IsStruct());
|
||||
return static_cast<const StructType*>(this);
|
||||
}
|
||||
|
||||
const TextureType* Type::AsTexture() const {
|
||||
assert(IsTexture());
|
||||
return static_cast<const TextureType*>(this);
|
||||
|
@ -163,11 +154,6 @@ const VoidType* Type::AsVoid() const {
|
|||
return static_cast<const VoidType*>(this);
|
||||
}
|
||||
|
||||
StructType* Type::AsStruct() {
|
||||
assert(IsStruct());
|
||||
return static_cast<StructType*>(this);
|
||||
}
|
||||
|
||||
TextureType* Type::AsTexture() {
|
||||
assert(IsTexture());
|
||||
return static_cast<TextureType*>(this);
|
||||
|
|
|
@ -23,7 +23,6 @@ namespace tint {
|
|||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
class StructType;
|
||||
class TextureType;
|
||||
class U32Type;
|
||||
class VectorType;
|
||||
|
@ -39,8 +38,6 @@ class Type : public Castable<Type> {
|
|||
Type(Type&&);
|
||||
~Type() override;
|
||||
|
||||
/// @returns true if the type is a struct type
|
||||
virtual bool IsStruct() const;
|
||||
/// @returns true if the type is a texture type
|
||||
virtual bool IsTexture() const;
|
||||
/// @returns true if the type is a u32 type
|
||||
|
@ -104,8 +101,6 @@ class Type : public Castable<Type> {
|
|||
/// @returns true if this type is an integer scalar or vector
|
||||
bool is_integer_scalar_or_vector();
|
||||
|
||||
/// @returns the type as a struct type
|
||||
const StructType* AsStruct() const;
|
||||
/// @returns the type as a texture type
|
||||
const TextureType* AsTexture() const;
|
||||
/// @returns the type as a u32 type
|
||||
|
@ -115,8 +110,6 @@ class Type : public Castable<Type> {
|
|||
/// @returns the type as a void type
|
||||
const VoidType* AsVoid() const;
|
||||
|
||||
/// @returns the type as a struct type
|
||||
StructType* AsStruct();
|
||||
/// @returns the type as a texture type
|
||||
TextureType* AsTexture();
|
||||
/// @returns the type as a u32 type
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/sampler_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -43,7 +44,7 @@ TEST_F(U32TypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
EXPECT_TRUE(ty->IsU32());
|
||||
EXPECT_FALSE(ty->IsVector());
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -50,7 +51,7 @@ TEST_F(VectorTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
EXPECT_FALSE(ty->IsU32());
|
||||
EXPECT_TRUE(ty->IsVector());
|
||||
|
|
|
@ -188,11 +188,11 @@ std::vector<ResourceBinding> Inspector::GetUniformBufferResourceBindings(
|
|||
}
|
||||
auto* unwrapped_type = var->type()->UnwrapIfNeeded();
|
||||
|
||||
if (!unwrapped_type->IsStruct()) {
|
||||
if (!unwrapped_type->Is<ast::type::StructType>()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!unwrapped_type->AsStruct()->IsBlockDecorated()) {
|
||||
if (!unwrapped_type->As<ast::type::StructType>()->IsBlockDecorated()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -314,7 +314,7 @@ std::vector<ResourceBinding> Inspector::GetStorageBufferResourceBindingsImpl(
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!var->type()->UnwrapIfNeeded()->IsStruct()) {
|
||||
if (!var->type()->UnwrapIfNeeded()->Is<ast::type::StructType>()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1381,8 +1381,8 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
|
|||
return create<ast::TypeConstructorExpression>(original_type,
|
||||
std::move(ast_components));
|
||||
}
|
||||
if (type->IsStruct()) {
|
||||
auto* struct_ty = type->AsStruct();
|
||||
if (type->Is<ast::type::StructType>()) {
|
||||
auto* struct_ty = type->As<ast::type::StructType>();
|
||||
ast::ExpressionList ast_components;
|
||||
for (auto* member : struct_ty->impl()->members()) {
|
||||
ast_components.emplace_back(MakeNullValue(member->type()));
|
||||
|
|
|
@ -570,9 +570,9 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) {
|
|||
|
||||
auto* type = p->ConvertType(10);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->IsStruct());
|
||||
EXPECT_TRUE(type->Is<ast::type::StructType>());
|
||||
std::stringstream ss;
|
||||
type->AsStruct()->impl()->to_str(ss, 0);
|
||||
type->As<ast::type::StructType>()->impl()->to_str(ss, 0);
|
||||
EXPECT_THAT(ss.str(), Eq(R"(Struct{
|
||||
StructMember{field0: __u32}
|
||||
StructMember{field1: __f32}
|
||||
|
@ -591,9 +591,9 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) {
|
|||
|
||||
auto* type = p->ConvertType(10);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->IsStruct());
|
||||
EXPECT_TRUE(type->Is<ast::type::StructType>());
|
||||
std::stringstream ss;
|
||||
type->AsStruct()->impl()->to_str(ss, 0);
|
||||
type->As<ast::type::StructType>()->impl()->to_str(ss, 0);
|
||||
EXPECT_THAT(ss.str(), Eq(R"(Struct{
|
||||
[[block]]
|
||||
StructMember{field0: __u32}
|
||||
|
@ -616,9 +616,9 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) {
|
|||
|
||||
auto* type = p->ConvertType(10);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->IsStruct());
|
||||
EXPECT_TRUE(type->Is<ast::type::StructType>());
|
||||
std::stringstream ss;
|
||||
type->AsStruct()->impl()->to_str(ss, 0);
|
||||
type->As<ast::type::StructType>()->impl()->to_str(ss, 0);
|
||||
EXPECT_THAT(ss.str(), Eq(R"(Struct{
|
||||
StructMember{[[ offset 0 ]] field0: __f32}
|
||||
StructMember{[[ offset 8 ]] field1: __vec_2__f32}
|
||||
|
|
|
@ -318,7 +318,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
|
|||
return Failure::kErrored;
|
||||
|
||||
auto* type = module_.unique_type(std::move(str.value));
|
||||
register_constructed(type->AsStruct()->name(), type);
|
||||
register_constructed(type->As<ast::type::StructType>()->name(), type);
|
||||
module_.AddConstructedType(type);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "src/ast/type/storage_texture_type.h"
|
||||
#include "src/ast/type/texture_type.h"
|
||||
#include "src/ast/type/type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/ast/variable_decoration.h"
|
||||
#include "src/context.h"
|
||||
|
|
|
@ -103,8 +103,8 @@ type B = A;)");
|
|||
|
||||
auto& m = p->get_module();
|
||||
ASSERT_EQ(m.constructed_types().size(), 2u);
|
||||
ASSERT_TRUE(m.constructed_types()[0]->IsStruct());
|
||||
auto* str = m.constructed_types()[0]->AsStruct();
|
||||
ASSERT_TRUE(m.constructed_types()[0]->Is<ast::type::StructType>());
|
||||
auto* str = m.constructed_types()[0]->As<ast::type::StructType>();
|
||||
EXPECT_EQ(str->name(), "A");
|
||||
|
||||
ASSERT_TRUE(m.constructed_types()[1]->Is<ast::type::AliasType>());
|
||||
|
@ -164,9 +164,9 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) {
|
|||
|
||||
auto* t = m.constructed_types()[0];
|
||||
ASSERT_NE(t, nullptr);
|
||||
ASSERT_TRUE(t->IsStruct());
|
||||
ASSERT_TRUE(t->Is<ast::type::StructType>());
|
||||
|
||||
auto* str = t->AsStruct();
|
||||
auto* str = t->As<ast::type::StructType>();
|
||||
EXPECT_EQ(str->name(), "A");
|
||||
EXPECT_EQ(str->impl()->members().size(), 2u);
|
||||
}
|
||||
|
@ -183,9 +183,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) {
|
|||
|
||||
auto* t = m.constructed_types()[0];
|
||||
ASSERT_NE(t, nullptr);
|
||||
ASSERT_TRUE(t->IsStruct());
|
||||
ASSERT_TRUE(t->Is<ast::type::StructType>());
|
||||
|
||||
auto* str = t->AsStruct();
|
||||
auto* str = t->As<ast::type::StructType>();
|
||||
EXPECT_EQ(str->name(), "A");
|
||||
EXPECT_EQ(str->impl()->members().size(), 1u);
|
||||
EXPECT_FALSE(str->IsBlockDecorated());
|
||||
|
@ -207,9 +207,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) {
|
|||
|
||||
auto* t = m.constructed_types()[0];
|
||||
ASSERT_NE(t, nullptr);
|
||||
ASSERT_TRUE(t->IsStruct());
|
||||
ASSERT_TRUE(t->Is<ast::type::StructType>());
|
||||
|
||||
auto* str = t->AsStruct();
|
||||
auto* str = t->As<ast::type::StructType>();
|
||||
EXPECT_EQ(str->name(), "A");
|
||||
EXPECT_EQ(str->impl()->members().size(), 1u);
|
||||
EXPECT_TRUE(str->IsBlockDecorated());
|
||||
|
|
|
@ -56,9 +56,9 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
|
|||
ASSERT_TRUE(t->Is<ast::type::AliasType>());
|
||||
auto* alias = t->As<ast::type::AliasType>();
|
||||
EXPECT_EQ(alias->name(), "a");
|
||||
ASSERT_TRUE(alias->type()->IsStruct());
|
||||
ASSERT_TRUE(alias->type()->Is<ast::type::StructType>());
|
||||
|
||||
auto* s = alias->type()->AsStruct();
|
||||
auto* s = alias->type()->As<ast::type::StructType>();
|
||||
EXPECT_EQ(s->name(), "B");
|
||||
}
|
||||
|
||||
|
|
|
@ -1028,8 +1028,8 @@ bool TypeDeterminer::DetermineMemberAccessor(
|
|||
auto* data_type = res->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
|
||||
|
||||
ast::type::Type* ret = nullptr;
|
||||
if (data_type->IsStruct()) {
|
||||
auto* strct = data_type->AsStruct()->impl();
|
||||
if (data_type->Is<ast::type::StructType>()) {
|
||||
auto* strct = data_type->As<ast::type::StructType>()->impl();
|
||||
auto name = expr->member()->name();
|
||||
|
||||
for (auto* member : strct->members()) {
|
||||
|
|
|
@ -83,8 +83,8 @@ bool ValidatorImpl::Validate(const ast::Module* module) {
|
|||
bool ValidatorImpl::ValidateConstructedTypes(
|
||||
const std::vector<ast::type::Type*>& constructed_types) {
|
||||
for (auto* const ct : constructed_types) {
|
||||
if (ct->IsStruct()) {
|
||||
auto* st = ct->AsStruct();
|
||||
if (ct->Is<ast::type::StructType>()) {
|
||||
auto* st = ct->As<ast::type::StructType>();
|
||||
for (auto* member : st->impl()->members()) {
|
||||
if (member->type()->UnwrapAll()->Is<ast::type::ArrayType>()) {
|
||||
auto* r = member->type()->UnwrapAll()->As<ast::type::ArrayType>();
|
||||
|
|
|
@ -218,8 +218,9 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out,
|
|||
auto* alias = ty->As<ast::type::AliasType>();
|
||||
// HLSL typedef is for intrinsic types only. For an alias'd struct,
|
||||
// generate a secondary struct with the new name.
|
||||
if (alias->type()->IsStruct()) {
|
||||
if (!EmitStructType(out, alias->type()->AsStruct(), alias->name())) {
|
||||
if (alias->type()->Is<ast::type::StructType>()) {
|
||||
if (!EmitStructType(out, alias->type()->As<ast::type::StructType>(),
|
||||
alias->name())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -229,8 +230,8 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out,
|
|||
return false;
|
||||
}
|
||||
out << " " << namer_.NameFor(alias->name()) << ";" << std::endl;
|
||||
} else if (ty->IsStruct()) {
|
||||
auto* str = ty->AsStruct();
|
||||
} else if (ty->Is<ast::type::StructType>()) {
|
||||
auto* str = ty->As<ast::type::StructType>();
|
||||
if (!EmitStructType(out, str, str->name())) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1289,8 +1290,8 @@ bool GeneratorImpl::EmitEntryPointData(
|
|||
emitted_globals.insert(var->name());
|
||||
|
||||
auto* type = var->type()->UnwrapIfNeeded();
|
||||
if (type->IsStruct()) {
|
||||
auto* strct = type->AsStruct();
|
||||
if (type->Is<ast::type::StructType>()) {
|
||||
auto* strct = type->As<ast::type::StructType>();
|
||||
|
||||
out << "ConstantBuffer<" << strct->name() << "> " << var->name()
|
||||
<< " : register(b" << binding->value() << ");" << std::endl;
|
||||
|
@ -1684,8 +1685,8 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression(
|
|||
if (expr->IsMemberAccessor()) {
|
||||
auto* mem = expr->AsMemberAccessor();
|
||||
auto* res_type = mem->structure()->result_type()->UnwrapAll();
|
||||
if (res_type->IsStruct()) {
|
||||
auto* str_type = res_type->AsStruct()->impl();
|
||||
if (res_type->Is<ast::type::StructType>()) {
|
||||
auto* str_type = res_type->As<ast::type::StructType>()->impl();
|
||||
auto* str_member = str_type->get_member(mem->member()->name());
|
||||
|
||||
if (!str_member->has_offset_decoration()) {
|
||||
|
@ -2086,8 +2087,8 @@ bool GeneratorImpl::EmitType(std::ostream& out,
|
|||
out << "Comparison";
|
||||
}
|
||||
out << "State";
|
||||
} else if (type->IsStruct()) {
|
||||
out << type->AsStruct()->name();
|
||||
} else if (type->Is<ast::type::StructType>()) {
|
||||
out << type->As<ast::type::StructType>()->name();
|
||||
} else if (type->IsTexture()) {
|
||||
auto* tex = type->AsTexture();
|
||||
if (tex->IsStorage()) {
|
||||
|
|
|
@ -166,19 +166,19 @@ bool GeneratorImpl::Generate() {
|
|||
|
||||
uint32_t GeneratorImpl::calculate_largest_alignment(
|
||||
ast::type::StructType* type) {
|
||||
auto* stct = type->AsStruct()->impl();
|
||||
auto* stct = type->As<ast::type::StructType>()->impl();
|
||||
uint32_t largest_alignment = 0;
|
||||
for (auto* mem : stct->members()) {
|
||||
auto align = calculate_alignment_size(mem->type());
|
||||
if (align == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (!mem->type()->IsStruct()) {
|
||||
if (!mem->type()->Is<ast::type::StructType>()) {
|
||||
largest_alignment = std::max(largest_alignment, align);
|
||||
} else {
|
||||
largest_alignment =
|
||||
std::max(largest_alignment,
|
||||
calculate_largest_alignment(mem->type()->AsStruct()));
|
||||
largest_alignment = std::max(
|
||||
largest_alignment, calculate_largest_alignment(
|
||||
mem->type()->As<ast::type::StructType>()));
|
||||
}
|
||||
}
|
||||
return largest_alignment;
|
||||
|
@ -211,8 +211,8 @@ uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) {
|
|||
uint32_t type_size = calculate_alignment_size(mat->type());
|
||||
return mat->rows() * mat->columns() * type_size;
|
||||
}
|
||||
if (type->IsStruct()) {
|
||||
auto* stct = type->AsStruct()->impl();
|
||||
if (type->Is<ast::type::StructType>()) {
|
||||
auto* stct = type->As<ast::type::StructType>()->impl();
|
||||
uint32_t count = 0;
|
||||
uint32_t largest_alignment = 0;
|
||||
// Offset decorations in WGSL must be in increasing order.
|
||||
|
@ -226,12 +226,12 @@ uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) {
|
|||
if (align == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (!mem->type()->IsStruct()) {
|
||||
if (!mem->type()->Is<ast::type::StructType>()) {
|
||||
largest_alignment = std::max(largest_alignment, align);
|
||||
} else {
|
||||
largest_alignment =
|
||||
std::max(largest_alignment,
|
||||
calculate_largest_alignment(mem->type()->AsStruct()));
|
||||
largest_alignment = std::max(
|
||||
largest_alignment, calculate_largest_alignment(
|
||||
mem->type()->As<ast::type::StructType>()));
|
||||
}
|
||||
|
||||
// Round up to the alignment size
|
||||
|
@ -264,8 +264,8 @@ bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) {
|
|||
return false;
|
||||
}
|
||||
out_ << " " << namer_.NameFor(alias->name()) << ";" << std::endl;
|
||||
} else if (ty->IsStruct()) {
|
||||
if (!EmitStructType(ty->AsStruct())) {
|
||||
} else if (ty->Is<ast::type::StructType>()) {
|
||||
if (!EmitStructType(ty->As<ast::type::StructType>())) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
@ -947,7 +947,7 @@ bool GeneratorImpl::EmitZeroValue(ast::type::Type* type) {
|
|||
return false;
|
||||
}
|
||||
out_ << "}";
|
||||
} else if (type->IsStruct()) {
|
||||
} else if (type->Is<ast::type::StructType>()) {
|
||||
out_ << "{}";
|
||||
} else {
|
||||
error_ = "Invalid type for zero emission: " + type->type_name();
|
||||
|
@ -1834,10 +1834,10 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
|
|||
out_ << "*";
|
||||
} else if (type->Is<ast::type::SamplerType>()) {
|
||||
out_ << "sampler";
|
||||
} else if (type->IsStruct()) {
|
||||
} else if (type->Is<ast::type::StructType>()) {
|
||||
// The struct type emits as just the name. The declaration would be emitted
|
||||
// as part of emitting the constructed types.
|
||||
out_ << type->AsStruct()->name();
|
||||
out_ << type->As<ast::type::StructType>()->name();
|
||||
} else if (type->IsTexture()) {
|
||||
auto* tex = type->AsTexture();
|
||||
|
||||
|
|
|
@ -853,7 +853,7 @@ 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->IsStruct()) {
|
||||
if (data_type->Is<ast::type::StructType>()) {
|
||||
if (!info->source_type->Is<ast::type::PointerType>()) {
|
||||
error_ =
|
||||
"Attempting to access a struct member on a non-pointer. Something is "
|
||||
|
@ -861,7 +861,7 @@ bool Builder::GenerateMemberAccessor(ast::MemberAccessorExpression* expr,
|
|||
return false;
|
||||
}
|
||||
|
||||
auto* strct = data_type->AsStruct()->impl();
|
||||
auto* strct = data_type->As<ast::type::StructType>()->impl();
|
||||
auto name = expr->member()->name();
|
||||
|
||||
uint32_t i = 0;
|
||||
|
@ -1208,8 +1208,12 @@ bool Builder::is_constructor_const(ast::Expression* expr, bool is_global_init) {
|
|||
subtype = subtype->As<ast::type::MatrixType>()->type()->UnwrapAll();
|
||||
} else if (subtype->Is<ast::type::ArrayType>()) {
|
||||
subtype = subtype->As<ast::type::ArrayType>()->type()->UnwrapAll();
|
||||
} else if (subtype->IsStruct()) {
|
||||
subtype = subtype->AsStruct()->impl()->members()[i]->type()->UnwrapAll();
|
||||
} else if (subtype->Is<ast::type::StructType>()) {
|
||||
subtype = subtype->As<ast::type::StructType>()
|
||||
->impl()
|
||||
->members()[i]
|
||||
->type()
|
||||
->UnwrapAll();
|
||||
}
|
||||
if (subtype != sc->result_type()->UnwrapAll()) {
|
||||
return false;
|
||||
|
@ -1282,7 +1286,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<ast::type::MatrixType>() ||
|
||||
result_type->Is<ast::type::ArrayType>() || result_type->IsStruct()) {
|
||||
result_type->Is<ast::type::ArrayType>() ||
|
||||
result_type->Is<ast::type::StructType>()) {
|
||||
out << "_" << id;
|
||||
|
||||
ops.push_back(Operand::Int(id));
|
||||
|
@ -1823,14 +1828,14 @@ uint32_t Builder::GenerateIntrinsic(ast::IdentifierExpression* ident,
|
|||
params.push_back(Operand::Int(struct_id));
|
||||
|
||||
auto* type = accessor->structure()->result_type()->UnwrapAll();
|
||||
if (!type->IsStruct()) {
|
||||
if (!type->Is<ast::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->AsStruct()->impl()->members().size() - 1)));
|
||||
params.push_back(Operand::Int(uint32_t(
|
||||
type->As<ast::type::StructType>()->impl()->members().size() - 1)));
|
||||
|
||||
push_function_inst(spv::Op::OpArrayLength, params);
|
||||
return result_id;
|
||||
|
@ -2409,12 +2414,12 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) {
|
|||
if (type->Is<ast::type::AccessControlType>()) {
|
||||
auto* ac = type->As<ast::type::AccessControlType>();
|
||||
auto* subtype = ac->type()->UnwrapIfNeeded();
|
||||
if (!subtype->IsStruct()) {
|
||||
if (!subtype->Is<ast::type::StructType>()) {
|
||||
error_ = "Access control attached to non-struct type.";
|
||||
return 0;
|
||||
}
|
||||
if (!GenerateStructType(subtype->AsStruct(), ac->access_control(),
|
||||
result)) {
|
||||
if (!GenerateStructType(subtype->As<ast::type::StructType>(),
|
||||
ac->access_control(), result)) {
|
||||
return 0;
|
||||
}
|
||||
} else if (type->Is<ast::type::ArrayType>()) {
|
||||
|
@ -2435,9 +2440,9 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) {
|
|||
if (!GeneratePointerType(type->As<ast::type::PointerType>(), result)) {
|
||||
return 0;
|
||||
}
|
||||
} else if (type->IsStruct()) {
|
||||
if (!GenerateStructType(type->AsStruct(), ast::AccessControl::kReadWrite,
|
||||
result)) {
|
||||
} else if (type->Is<ast::type::StructType>()) {
|
||||
if (!GenerateStructType(type->As<ast::type::StructType>(),
|
||||
ast::AccessControl::kReadWrite, result)) {
|
||||
return 0;
|
||||
}
|
||||
} else if (type->IsU32()) {
|
||||
|
|
|
@ -28,10 +28,11 @@
|
|||
#include "src/ast/module.h"
|
||||
#include "src/ast/struct_member.h"
|
||||
#include "src/ast/type/access_control_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/storage_texture_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/context.h"
|
||||
#include "src/scope_stack.h"
|
||||
|
|
|
@ -178,8 +178,8 @@ bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) {
|
|||
return false;
|
||||
}
|
||||
out_ << ";" << std::endl;
|
||||
} else if (ty->IsStruct()) {
|
||||
if (!EmitStructType(ty->AsStruct())) {
|
||||
} else if (ty->Is<ast::type::StructType>()) {
|
||||
if (!EmitStructType(ty->As<ast::type::StructType>())) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
@ -460,10 +460,10 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
|||
if (sampler->IsComparison()) {
|
||||
out_ << "_comparison";
|
||||
}
|
||||
} else if (type->IsStruct()) {
|
||||
} else if (type->Is<ast::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_ << type->AsStruct()->name();
|
||||
out_ << type->As<ast::type::StructType>()->name();
|
||||
} else if (type->IsTexture()) {
|
||||
auto* texture = type->AsTexture();
|
||||
|
||||
|
|
Loading…
Reference in New Issue