Replace Type::(Is|As)Alias with Castable
Change-Id: I10f1d3d0757661a41b44517d55d6f159aced04ce Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34263 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
a8d87788da
commit
67864267c2
|
@ -56,8 +56,8 @@ bool Module::IsValid() const {
|
||||||
if (ty == nullptr) {
|
if (ty == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (ty->IsAlias()) {
|
if (ty->Is<ast::type::AliasType>()) {
|
||||||
auto* alias = ty->AsAlias();
|
auto* alias = ty->As<ast::type::AliasType>();
|
||||||
if (alias->type() == nullptr) {
|
if (alias->type() == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -91,8 +91,8 @@ std::string Module::to_str() const {
|
||||||
for (size_t i = 0; i < indent; ++i) {
|
for (size_t i = 0; i < indent; ++i) {
|
||||||
out << " ";
|
out << " ";
|
||||||
}
|
}
|
||||||
if (ty->IsAlias()) {
|
if (ty->Is<ast::type::AliasType>()) {
|
||||||
auto* alias = ty->AsAlias();
|
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()->IsStruct()) {
|
||||||
alias->type()->AsStruct()->impl()->to_str(out, indent);
|
alias->type()->AsStruct()->impl()->to_str(out, indent);
|
||||||
|
|
|
@ -47,19 +47,20 @@ TEST_F(AccessControlTypeTest, Is) {
|
||||||
I32Type i32;
|
I32Type i32;
|
||||||
|
|
||||||
AccessControlType at{AccessControl::kReadOnly, &i32};
|
AccessControlType at{AccessControl::kReadOnly, &i32};
|
||||||
EXPECT_TRUE(at.Is<AccessControlType>());
|
Type* ty = &at;
|
||||||
EXPECT_FALSE(at.IsAlias());
|
EXPECT_TRUE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(at.IsArray());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(at.IsBool());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(at.IsF32());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(at.IsI32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
EXPECT_FALSE(at.IsMatrix());
|
EXPECT_FALSE(ty->IsI32());
|
||||||
EXPECT_FALSE(at.IsPointer());
|
EXPECT_FALSE(ty->IsMatrix());
|
||||||
EXPECT_FALSE(at.IsSampler());
|
EXPECT_FALSE(ty->IsPointer());
|
||||||
EXPECT_FALSE(at.IsStruct());
|
EXPECT_FALSE(ty->IsSampler());
|
||||||
EXPECT_FALSE(at.IsTexture());
|
EXPECT_FALSE(ty->IsStruct());
|
||||||
EXPECT_FALSE(at.IsU32());
|
EXPECT_FALSE(ty->IsTexture());
|
||||||
EXPECT_FALSE(at.IsVector());
|
EXPECT_FALSE(ty->IsU32());
|
||||||
|
EXPECT_FALSE(ty->IsVector());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AccessControlTypeTest, AccessRead) {
|
TEST_F(AccessControlTypeTest, AccessRead) {
|
||||||
|
|
|
@ -29,10 +29,6 @@ AliasType::AliasType(AliasType&&) = default;
|
||||||
|
|
||||||
AliasType::~AliasType() = default;
|
AliasType::~AliasType() = default;
|
||||||
|
|
||||||
bool AliasType::IsAlias() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string AliasType::type_name() const {
|
std::string AliasType::type_name() const {
|
||||||
return "__alias_" + name_ + subtype_->type_name();
|
return "__alias_" + name_ + subtype_->type_name();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,6 @@ class AliasType : public Castable<AliasType, Type> {
|
||||||
AliasType(AliasType&&);
|
AliasType(AliasType&&);
|
||||||
~AliasType() override;
|
~AliasType() override;
|
||||||
|
|
||||||
/// @returns true if the type is an alias type
|
|
||||||
bool IsAlias() const override;
|
|
||||||
|
|
||||||
/// @returns the alias name
|
/// @returns the alias name
|
||||||
const std::string& name() const { return name_; }
|
const std::string& name() const { return name_; }
|
||||||
/// @returns the alias type
|
/// @returns the alias type
|
||||||
|
|
|
@ -50,7 +50,7 @@ TEST_F(AliasTypeTest, Is) {
|
||||||
AliasType at{"a", &i32};
|
AliasType at{"a", &i32};
|
||||||
Type* ty = &at;
|
Type* ty = &at;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_TRUE(ty->IsAlias());
|
EXPECT_TRUE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -54,7 +54,7 @@ TEST_F(ArrayTypeTest, Is) {
|
||||||
ArrayType arr{&i32, 3};
|
ArrayType arr{&i32, 3};
|
||||||
Type* ty = &arr;
|
Type* ty = &arr;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_TRUE(ty->IsArray());
|
EXPECT_TRUE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -28,7 +28,7 @@ TEST_F(BoolTypeTest, Is) {
|
||||||
BoolType b;
|
BoolType b;
|
||||||
Type* ty = &b;
|
Type* ty = &b;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_TRUE(ty->IsBool());
|
EXPECT_TRUE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -29,7 +29,7 @@ TEST_F(DepthTextureTypeTest, Is) {
|
||||||
DepthTextureType d(TextureDimension::kCube);
|
DepthTextureType d(TextureDimension::kCube);
|
||||||
Type* ty = &d;
|
Type* ty = &d;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -28,7 +28,7 @@ TEST_F(F32TypeTest, Is) {
|
||||||
F32Type f;
|
F32Type f;
|
||||||
Type* ty = &f;
|
Type* ty = &f;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_TRUE(ty->IsF32());
|
EXPECT_TRUE(ty->IsF32());
|
||||||
|
|
|
@ -28,7 +28,7 @@ TEST_F(I32TypeTest, Is) {
|
||||||
I32Type i;
|
I32Type i;
|
||||||
Type* ty = &i;
|
Type* ty = &i;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -38,7 +38,7 @@ TEST_F(MatrixTypeTest, Is) {
|
||||||
MatrixType m{&i32, 2, 3};
|
MatrixType m{&i32, 2, 3};
|
||||||
Type* ty = &m;
|
Type* ty = &m;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -30,7 +30,7 @@ TEST_F(MultisampledTextureTypeTest, Is) {
|
||||||
MultisampledTextureType s(TextureDimension::kCube, &f32);
|
MultisampledTextureType s(TextureDimension::kCube, &f32);
|
||||||
Type* ty = &s;
|
Type* ty = &s;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -37,7 +37,7 @@ TEST_F(PointerTypeTest, Is) {
|
||||||
PointerType p{&i32, StorageClass::kFunction};
|
PointerType p{&i32, StorageClass::kFunction};
|
||||||
Type* ty = &p;
|
Type* ty = &p;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -30,7 +30,7 @@ TEST_F(SampledTextureTypeTest, Is) {
|
||||||
SampledTextureType s(TextureDimension::kCube, &f32);
|
SampledTextureType s(TextureDimension::kCube, &f32);
|
||||||
Type* ty = &s;
|
Type* ty = &s;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -39,7 +39,7 @@ TEST_F(SamplerTypeTest, Is) {
|
||||||
SamplerType s{SamplerKind::kSampler};
|
SamplerType s{SamplerKind::kSampler};
|
||||||
Type* ty = &s;
|
Type* ty = &s;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -33,7 +33,7 @@ TEST_F(StorageTextureTypeTest, Is) {
|
||||||
ImageFormat::kRgba32Float);
|
ImageFormat::kRgba32Float);
|
||||||
Type* ty = &s;
|
Type* ty = &s;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -46,7 +46,7 @@ TEST_F(StructTypeTest, Is) {
|
||||||
StructType s{"S", impl};
|
StructType s{"S", impl};
|
||||||
Type* ty = &s;
|
Type* ty = &s;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -51,8 +51,8 @@ Type* Type::UnwrapPtrIfNeeded() {
|
||||||
Type* Type::UnwrapIfNeeded() {
|
Type* Type::UnwrapIfNeeded() {
|
||||||
auto* where = this;
|
auto* where = this;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (where->IsAlias()) {
|
if (where->Is<AliasType>()) {
|
||||||
where = where->AsAlias()->type();
|
where = where->As<AliasType>()->type();
|
||||||
} else if (where->Is<AccessControlType>()) {
|
} else if (where->Is<AccessControlType>()) {
|
||||||
where = where->As<AccessControlType>()->type();
|
where = where->As<AccessControlType>()->type();
|
||||||
} else {
|
} else {
|
||||||
|
@ -66,10 +66,6 @@ Type* Type::UnwrapAll() {
|
||||||
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
|
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Type::IsAlias() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Type::IsArray() const {
|
bool Type::IsArray() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -170,11 +166,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 AliasType* Type::AsAlias() const {
|
|
||||||
assert(IsAlias());
|
|
||||||
return static_cast<const AliasType*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const ArrayType* Type::AsArray() const {
|
const ArrayType* Type::AsArray() const {
|
||||||
assert(IsArray());
|
assert(IsArray());
|
||||||
return static_cast<const ArrayType*>(this);
|
return static_cast<const ArrayType*>(this);
|
||||||
|
@ -235,11 +226,6 @@ const VoidType* Type::AsVoid() const {
|
||||||
return static_cast<const VoidType*>(this);
|
return static_cast<const VoidType*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
AliasType* Type::AsAlias() {
|
|
||||||
assert(IsAlias());
|
|
||||||
return static_cast<AliasType*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayType* Type::AsArray() {
|
ArrayType* Type::AsArray() {
|
||||||
assert(IsArray());
|
assert(IsArray());
|
||||||
return static_cast<ArrayType*>(this);
|
return static_cast<ArrayType*>(this);
|
||||||
|
|
|
@ -23,7 +23,6 @@ namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
namespace type {
|
namespace type {
|
||||||
|
|
||||||
class AliasType;
|
|
||||||
class ArrayType;
|
class ArrayType;
|
||||||
class BoolType;
|
class BoolType;
|
||||||
class F32Type;
|
class F32Type;
|
||||||
|
@ -47,8 +46,6 @@ class Type : public Castable<Type> {
|
||||||
Type(Type&&);
|
Type(Type&&);
|
||||||
~Type() override;
|
~Type() override;
|
||||||
|
|
||||||
/// @returns true if the type is an alias type
|
|
||||||
virtual bool IsAlias() const;
|
|
||||||
/// @returns true if the type is an array type
|
/// @returns true if the type is an array type
|
||||||
virtual bool IsArray() const;
|
virtual bool IsArray() const;
|
||||||
/// @returns true if the type is a bool type
|
/// @returns true if the type is a bool type
|
||||||
|
@ -128,8 +125,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 an alias type
|
|
||||||
const AliasType* AsAlias() const;
|
|
||||||
/// @returns the type as an array type
|
/// @returns the type as an array type
|
||||||
const ArrayType* AsArray() const;
|
const ArrayType* AsArray() const;
|
||||||
/// @returns the type as a bool type
|
/// @returns the type as a bool type
|
||||||
|
@ -155,8 +150,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 an alias type
|
|
||||||
AliasType* AsAlias();
|
|
||||||
/// @returns the type as an array type
|
/// @returns the type as an array type
|
||||||
ArrayType* AsArray();
|
ArrayType* AsArray();
|
||||||
/// @returns the type as a bool type
|
/// @returns the type as a bool type
|
||||||
|
|
|
@ -28,7 +28,7 @@ TEST_F(U32TypeTest, Is) {
|
||||||
U32Type u;
|
U32Type u;
|
||||||
Type* ty = &u;
|
Type* ty = &u;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -37,7 +37,7 @@ TEST_F(VectorTypeTest, Is) {
|
||||||
VectorType v{&i32, 4};
|
VectorType v{&i32, 4};
|
||||||
Type* ty = &v;
|
Type* ty = &v;
|
||||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||||
EXPECT_FALSE(ty->IsAlias());
|
EXPECT_FALSE(ty->Is<AliasType>());
|
||||||
EXPECT_FALSE(ty->IsArray());
|
EXPECT_FALSE(ty->IsArray());
|
||||||
EXPECT_FALSE(ty->IsBool());
|
EXPECT_FALSE(ty->IsBool());
|
||||||
EXPECT_FALSE(ty->IsF32());
|
EXPECT_FALSE(ty->IsF32());
|
||||||
|
|
|
@ -903,7 +903,7 @@ Maybe<ast::type::Type*> ParserImpl::type_alias() {
|
||||||
auto* alias = module_.create<ast::type::AliasType>(name.value, type.value);
|
auto* alias = module_.create<ast::type::AliasType>(name.value, type.value);
|
||||||
register_constructed(name.value, alias);
|
register_constructed(name.value, alias);
|
||||||
|
|
||||||
return alias->AsAlias();
|
return alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
// type_decl
|
// type_decl
|
||||||
|
|
|
@ -88,8 +88,8 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) {
|
||||||
|
|
||||||
auto& m = p->get_module();
|
auto& m = p->get_module();
|
||||||
ASSERT_EQ(m.constructed_types().size(), 1u);
|
ASSERT_EQ(m.constructed_types().size(), 1u);
|
||||||
ASSERT_TRUE(m.constructed_types()[0]->IsAlias());
|
ASSERT_TRUE(m.constructed_types()[0]->Is<ast::type::AliasType>());
|
||||||
EXPECT_EQ(m.constructed_types()[0]->AsAlias()->name(), "A");
|
EXPECT_EQ(m.constructed_types()[0]->As<ast::type::AliasType>()->name(), "A");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) {
|
TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) {
|
||||||
|
@ -107,8 +107,8 @@ type B = A;)");
|
||||||
auto* str = m.constructed_types()[0]->AsStruct();
|
auto* str = m.constructed_types()[0]->AsStruct();
|
||||||
EXPECT_EQ(str->name(), "A");
|
EXPECT_EQ(str->name(), "A");
|
||||||
|
|
||||||
ASSERT_TRUE(m.constructed_types()[1]->IsAlias());
|
ASSERT_TRUE(m.constructed_types()[1]->Is<ast::type::AliasType>());
|
||||||
auto* alias = m.constructed_types()[1]->AsAlias();
|
auto* alias = m.constructed_types()[1]->As<ast::type::AliasType>();
|
||||||
EXPECT_EQ(alias->name(), "B");
|
EXPECT_EQ(alias->name(), "B");
|
||||||
EXPECT_EQ(alias->type(), str);
|
EXPECT_EQ(alias->type(), str);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,8 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) {
|
||||||
EXPECT_FALSE(t.errored);
|
EXPECT_FALSE(t.errored);
|
||||||
EXPECT_TRUE(t.matched);
|
EXPECT_TRUE(t.matched);
|
||||||
ASSERT_NE(t.value, nullptr);
|
ASSERT_NE(t.value, nullptr);
|
||||||
ASSERT_TRUE(t->IsAlias());
|
ASSERT_TRUE(t->Is<ast::type::AliasType>());
|
||||||
auto* alias = t->AsAlias();
|
auto* alias = t->As<ast::type::AliasType>();
|
||||||
ASSERT_TRUE(alias->type()->IsI32());
|
ASSERT_TRUE(alias->type()->IsI32());
|
||||||
ASSERT_EQ(alias->type(), i32);
|
ASSERT_EQ(alias->type(), i32);
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,8 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
|
||||||
EXPECT_FALSE(t.errored);
|
EXPECT_FALSE(t.errored);
|
||||||
EXPECT_TRUE(t.matched);
|
EXPECT_TRUE(t.matched);
|
||||||
ASSERT_NE(t.value, nullptr);
|
ASSERT_NE(t.value, nullptr);
|
||||||
ASSERT_TRUE(t->IsAlias());
|
ASSERT_TRUE(t->Is<ast::type::AliasType>());
|
||||||
auto* alias = t->AsAlias();
|
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()->IsStruct());
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,9 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) {
|
||||||
EXPECT_FALSE(t.errored);
|
EXPECT_FALSE(t.errored);
|
||||||
ASSERT_NE(t.value, nullptr) << p->error();
|
ASSERT_NE(t.value, nullptr) << p->error();
|
||||||
EXPECT_EQ(t.value, alias_type);
|
EXPECT_EQ(t.value, alias_type);
|
||||||
ASSERT_TRUE(t->IsAlias());
|
ASSERT_TRUE(t->Is<ast::type::AliasType>());
|
||||||
|
|
||||||
auto* alias = t->AsAlias();
|
auto* alias = t->As<ast::type::AliasType>();
|
||||||
EXPECT_EQ(alias->name(), "A");
|
EXPECT_EQ(alias->name(), "A");
|
||||||
EXPECT_EQ(alias->type(), int_type);
|
EXPECT_EQ(alias->type(), int_type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,8 +212,8 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out,
|
||||||
const ast::type::Type* ty) {
|
const ast::type::Type* ty) {
|
||||||
make_indent(out);
|
make_indent(out);
|
||||||
|
|
||||||
if (ty->IsAlias()) {
|
if (ty->Is<ast::type::AliasType>()) {
|
||||||
auto* alias = ty->AsAlias();
|
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()->IsStruct()) {
|
||||||
|
@ -2029,8 +2029,8 @@ bool GeneratorImpl::EmitSwitch(std::ostream& out, ast::SwitchStatement* stmt) {
|
||||||
bool GeneratorImpl::EmitType(std::ostream& out,
|
bool GeneratorImpl::EmitType(std::ostream& out,
|
||||||
ast::type::Type* type,
|
ast::type::Type* type,
|
||||||
const std::string& name) {
|
const std::string& name) {
|
||||||
if (type->IsAlias()) {
|
if (type->Is<ast::type::AliasType>()) {
|
||||||
auto* alias = type->AsAlias();
|
auto* alias = type->As<ast::type::AliasType>();
|
||||||
out << namer_.NameFor(alias->name());
|
out << namer_.NameFor(alias->name());
|
||||||
} else if (type->IsArray()) {
|
} else if (type->IsArray()) {
|
||||||
auto* ary = type->AsArray();
|
auto* ary = type->AsArray();
|
||||||
|
|
|
@ -185,8 +185,8 @@ uint32_t GeneratorImpl::calculate_largest_alignment(
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) {
|
uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) {
|
||||||
if (type->IsAlias()) {
|
if (type->Is<ast::type::AliasType>()) {
|
||||||
return calculate_alignment_size(type->AsAlias()->type());
|
return calculate_alignment_size(type->As<ast::type::AliasType>()->type());
|
||||||
}
|
}
|
||||||
if (type->IsArray()) {
|
if (type->IsArray()) {
|
||||||
auto* ary = type->AsArray();
|
auto* ary = type->AsArray();
|
||||||
|
@ -255,8 +255,8 @@ uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) {
|
||||||
bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) {
|
bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) {
|
||||||
make_indent();
|
make_indent();
|
||||||
|
|
||||||
if (ty->IsAlias()) {
|
if (ty->Is<ast::type::AliasType>()) {
|
||||||
auto* alias = ty->AsAlias();
|
auto* alias = ty->As<ast::type::AliasType>();
|
||||||
|
|
||||||
out_ << "typedef ";
|
out_ << "typedef ";
|
||||||
if (!EmitType(alias->type(), "")) {
|
if (!EmitType(alias->type(), "")) {
|
||||||
|
@ -1787,8 +1787,8 @@ bool GeneratorImpl::EmitSwitch(ast::SwitchStatement* stmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
|
bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
|
||||||
if (type->IsAlias()) {
|
if (type->Is<ast::type::AliasType>()) {
|
||||||
auto* alias = type->AsAlias();
|
auto* alias = type->As<ast::type::AliasType>();
|
||||||
out_ << namer_.NameFor(alias->name());
|
out_ << namer_.NameFor(alias->name());
|
||||||
} else if (type->IsArray()) {
|
} else if (type->IsArray()) {
|
||||||
auto* ary = type->AsArray();
|
auto* ary = type->AsArray();
|
||||||
|
|
|
@ -2387,8 +2387,8 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The alias is a wrapper around the subtype, so emit the subtype
|
// The alias is a wrapper around the subtype, so emit the subtype
|
||||||
if (type->IsAlias()) {
|
if (type->Is<ast::type::AliasType>()) {
|
||||||
return GenerateTypeIfNeeded(type->AsAlias()->type());
|
return GenerateTypeIfNeeded(type->As<ast::type::AliasType>()->type());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto val = type_name_to_id_.find(type->type_name());
|
auto val = type_name_to_id_.find(type->type_name());
|
||||||
|
|
|
@ -168,8 +168,8 @@ bool GeneratorImpl::GenerateEntryPoint(const ast::Module& module,
|
||||||
|
|
||||||
bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) {
|
bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) {
|
||||||
make_indent();
|
make_indent();
|
||||||
if (ty->IsAlias()) {
|
if (ty->Is<ast::type::AliasType>()) {
|
||||||
auto* alias = ty->AsAlias();
|
auto* alias = ty->As<ast::type::AliasType>();
|
||||||
out_ << "type " << alias->name() << " = ";
|
out_ << "type " << alias->name() << " = ";
|
||||||
if (!EmitType(alias->type())) {
|
if (!EmitType(alias->type())) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -410,8 +410,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
||||||
if (!EmitType(ac->type())) {
|
if (!EmitType(ac->type())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (type->IsAlias()) {
|
} else if (type->Is<ast::type::AliasType>()) {
|
||||||
out_ << type->AsAlias()->name();
|
out_ << type->As<ast::type::AliasType>()->name();
|
||||||
} else if (type->IsArray()) {
|
} else if (type->IsArray()) {
|
||||||
auto* ary = type->AsArray();
|
auto* ary = type->AsArray();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue