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