Derive all ast::types from Castable

The hand-rolled `AsBlah()`, `IsBlah()` methods will be migrated in future changes.

Change-Id: I46a350a560f9eda8ca15f8ba8c95b17b9b6010b7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34261
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2020-11-30 23:30:58 +00:00
parent 21e9204e14
commit 69aabb51a9
31 changed files with 51 additions and 32 deletions

View File

@ -26,6 +26,8 @@ AccessControlType::AccessControlType(AccessControl access, Type* subtype)
assert(!subtype_->IsAccessControl()); assert(!subtype_->IsAccessControl());
} }
AccessControlType::AccessControlType(AccessControlType&&) = default;
AccessControlType::~AccessControlType() = default; AccessControlType::~AccessControlType() = default;
bool AccessControlType::IsAccessControl() const { bool AccessControlType::IsAccessControl() const {

View File

@ -25,14 +25,14 @@ namespace ast {
namespace type { namespace type {
/// An access control type. Holds an access setting and pointer to another type. /// An access control type. Holds an access setting and pointer to another type.
class AccessControlType : public Type { class AccessControlType : public Castable<AccessControlType, Type> {
public: public:
/// Constructor /// Constructor
/// @param access the access control setting /// @param access the access control setting
/// @param subtype the access controlled type /// @param subtype the access controlled type
AccessControlType(AccessControl access, Type* subtype); AccessControlType(AccessControl access, Type* subtype);
/// Move constructor /// Move constructor
AccessControlType(AccessControlType&&) = default; AccessControlType(AccessControlType&&);
~AccessControlType() override; ~AccessControlType() override;
/// @returns true if the type is an access control type /// @returns true if the type is an access control type

View File

@ -25,6 +25,8 @@ AliasType::AliasType(const std::string& name, Type* subtype)
assert(subtype_); assert(subtype_);
} }
AliasType::AliasType(AliasType&&) = default;
AliasType::~AliasType() = default; AliasType::~AliasType() = default;
bool AliasType::IsAlias() const { bool AliasType::IsAlias() const {

View File

@ -24,14 +24,14 @@ namespace ast {
namespace type { namespace type {
/// A type alias type. Holds a name and pointer to another type. /// A type alias type. Holds a name and pointer to another type.
class AliasType : public Type { class AliasType : public Castable<AliasType, Type> {
public: public:
/// Constructor /// Constructor
/// @param name the alias name /// @param name the alias name
/// @param subtype the alias'd type /// @param subtype the alias'd type
AliasType(const std::string& name, Type* subtype); AliasType(const std::string& name, Type* subtype);
/// Move constructor /// Move constructor
AliasType(AliasType&&) = default; AliasType(AliasType&&);
~AliasType() override; ~AliasType() override;
/// @returns true if the type is an alias type /// @returns true if the type is an alias type

View File

@ -28,7 +28,7 @@ namespace ast {
namespace type { namespace type {
/// An array type. If size is zero then it is a runtime array. /// An array type. If size is zero then it is a runtime array.
class ArrayType : public Type { class ArrayType : public Castable<ArrayType, Type> {
public: public:
/// Constructor for runtime array /// Constructor for runtime array
/// @param subtype the type of the array elements /// @param subtype the type of the array elements

View File

@ -20,6 +20,8 @@ namespace type {
BoolType::BoolType() = default; BoolType::BoolType() = default;
BoolType::BoolType(BoolType&&) = default;
BoolType::~BoolType() = default; BoolType::~BoolType() = default;
bool BoolType::IsBool() const { bool BoolType::IsBool() const {

View File

@ -24,12 +24,12 @@ namespace ast {
namespace type { namespace type {
/// A boolean type /// A boolean type
class BoolType : public Type { class BoolType : public Castable<BoolType, Type> {
public: public:
/// Constructor /// Constructor
BoolType(); BoolType();
/// Move constructor /// Move constructor
BoolType(BoolType&&) = default; BoolType(BoolType&&);
~BoolType() override; ~BoolType() override;
/// @returns true if the type is a bool type /// @returns true if the type is a bool type

View File

@ -33,7 +33,7 @@ bool IsValidDepthDimension(TextureDimension dim) {
} // namespace } // namespace
DepthTextureType::DepthTextureType(TextureDimension dim) : TextureType(dim) { DepthTextureType::DepthTextureType(TextureDimension dim) : Base(dim) {
assert(IsValidDepthDimension(dim)); assert(IsValidDepthDimension(dim));
} }

View File

@ -24,7 +24,7 @@ namespace ast {
namespace type { namespace type {
/// A depth texture type. /// A depth texture type.
class DepthTextureType : public TextureType { class DepthTextureType : public Castable<DepthTextureType, TextureType> {
public: public:
/// Constructor /// Constructor
/// @param dim the dimensionality of the texture /// @param dim the dimensionality of the texture

View File

@ -20,6 +20,8 @@ namespace type {
F32Type::F32Type() = default; F32Type::F32Type() = default;
F32Type::F32Type(F32Type&&) = default;
F32Type::~F32Type() = default; F32Type::~F32Type() = default;
bool F32Type::IsF32() const { bool F32Type::IsF32() const {

View File

@ -24,12 +24,12 @@ namespace ast {
namespace type { namespace type {
/// A float 32 type /// A float 32 type
class F32Type : public Type { class F32Type : public Castable<F32Type, Type> {
public: public:
/// Constructor /// Constructor
F32Type(); F32Type();
/// Move constructor /// Move constructor
F32Type(F32Type&&) = default; F32Type(F32Type&&);
~F32Type() override; ~F32Type() override;
/// @returns true if the type is an f32 type /// @returns true if the type is an f32 type

View File

@ -20,6 +20,8 @@ namespace type {
I32Type::I32Type() = default; I32Type::I32Type() = default;
I32Type::I32Type(I32Type&&) = default;
I32Type::~I32Type() = default; I32Type::~I32Type() = default;
bool I32Type::IsI32() const { bool I32Type::IsI32() const {

View File

@ -24,12 +24,12 @@ namespace ast {
namespace type { namespace type {
/// A signed int 32 type. /// A signed int 32 type.
class I32Type : public Type { class I32Type : public Castable<I32Type, Type> {
public: public:
/// Constructor /// Constructor
I32Type(); I32Type();
/// Move constructor /// Move constructor
I32Type(I32Type&&) = default; I32Type(I32Type&&);
~I32Type() override; ~I32Type() override;
/// @returns true if the type is an i32 type /// @returns true if the type is an i32 type

View File

@ -31,6 +31,8 @@ MatrixType::MatrixType(Type* subtype, uint32_t rows, uint32_t columns)
assert(columns < 5); assert(columns < 5);
} }
MatrixType::MatrixType(MatrixType&&) = default;
MatrixType::~MatrixType() = default; MatrixType::~MatrixType() = default;
bool MatrixType::IsMatrix() const { bool MatrixType::IsMatrix() const {

View File

@ -24,7 +24,7 @@ namespace ast {
namespace type { namespace type {
/// A matrix type /// A matrix type
class MatrixType : public Type { class MatrixType : public Castable<MatrixType, Type> {
public: public:
/// Constructor /// Constructor
/// @param subtype type matrix type /// @param subtype type matrix type
@ -32,7 +32,7 @@ class MatrixType : public Type {
/// @param columns the number of columns in the matrix /// @param columns the number of columns in the matrix
MatrixType(Type* subtype, uint32_t rows, uint32_t columns); MatrixType(Type* subtype, uint32_t rows, uint32_t columns);
/// Move constructor /// Move constructor
MatrixType(MatrixType&&) = default; MatrixType(MatrixType&&);
~MatrixType() override; ~MatrixType() override;
/// @returns true if the type is a matrix type /// @returns true if the type is a matrix type

View File

@ -23,7 +23,7 @@ namespace type {
MultisampledTextureType::MultisampledTextureType(TextureDimension dim, MultisampledTextureType::MultisampledTextureType(TextureDimension dim,
Type* type) Type* type)
: TextureType(dim), type_(type) { : Base(dim), type_(type) {
assert(type_); assert(type_);
} }

View File

@ -24,7 +24,8 @@ namespace ast {
namespace type { namespace type {
/// A multisampled texture type. /// A multisampled texture type.
class MultisampledTextureType : public TextureType { class MultisampledTextureType
: public Castable<MultisampledTextureType, TextureType> {
public: public:
/// Constructor /// Constructor
/// @param dim the dimensionality of the texture /// @param dim the dimensionality of the texture

View File

@ -31,6 +31,8 @@ std::string PointerType::type_name() const {
return out.str(); return out.str();
} }
PointerType::PointerType(PointerType&&) = default;
PointerType::~PointerType() = default; PointerType::~PointerType() = default;
} // namespace type } // namespace type

View File

@ -26,14 +26,14 @@ namespace ast {
namespace type { namespace type {
/// A pointer type. /// A pointer type.
class PointerType : public Type { class PointerType : public Castable<PointerType, Type> {
public: public:
/// Construtor /// Construtor
/// @param subtype the pointee type /// @param subtype the pointee type
/// @param storage_class the storage class of the pointer /// @param storage_class the storage class of the pointer
explicit PointerType(Type* subtype, StorageClass storage_class); explicit PointerType(Type* subtype, StorageClass storage_class);
/// Move constructor /// Move constructor
PointerType(PointerType&&) = default; PointerType(PointerType&&);
~PointerType() override; ~PointerType() override;
/// @returns true if the type is a pointer type /// @returns true if the type is a pointer type

View File

@ -22,7 +22,7 @@ namespace ast {
namespace type { namespace type {
SampledTextureType::SampledTextureType(TextureDimension dim, Type* type) SampledTextureType::SampledTextureType(TextureDimension dim, Type* type)
: TextureType(dim), type_(type) { : Base(dim), type_(type) {
assert(type_); assert(type_);
} }

View File

@ -24,7 +24,7 @@ namespace ast {
namespace type { namespace type {
/// A sampled texture type. /// A sampled texture type.
class SampledTextureType : public TextureType { class SampledTextureType : public Castable<SampledTextureType, TextureType> {
public: public:
/// Constructor /// Constructor
/// @param dim the dimensionality of the texture /// @param dim the dimensionality of the texture

View File

@ -34,7 +34,7 @@ enum class SamplerKind {
std::ostream& operator<<(std::ostream& out, SamplerKind kind); std::ostream& operator<<(std::ostream& out, SamplerKind kind);
/// A sampler type. /// A sampler type.
class SamplerType : public Type { class SamplerType : public Castable<SamplerType, Type> {
public: public:
/// Constructor /// Constructor
/// @param kind the kind of sampler /// @param kind the kind of sampler

View File

@ -153,7 +153,7 @@ std::ostream& operator<<(std::ostream& out, ImageFormat format) {
StorageTextureType::StorageTextureType(TextureDimension dim, StorageTextureType::StorageTextureType(TextureDimension dim,
AccessControl access, AccessControl access,
ImageFormat format) ImageFormat format)
: TextureType(dim), access_(access), image_format_(format) { : Base(dim), access_(access), image_format_(format) {
assert(IsValidStorageDimension(dim)); assert(IsValidStorageDimension(dim));
} }

View File

@ -66,7 +66,7 @@ enum class ImageFormat {
std::ostream& operator<<(std::ostream& out, ImageFormat dim); std::ostream& operator<<(std::ostream& out, ImageFormat dim);
/// A storage texture type. /// A storage texture type.
class StorageTextureType : public TextureType { class StorageTextureType : public Castable<StorageTextureType, TextureType> {
public: public:
/// Constructor /// Constructor
/// @param dim the dimensionality of the texture /// @param dim the dimensionality of the texture

View File

@ -26,7 +26,7 @@ namespace ast {
namespace type { namespace type {
/// A structure type /// A structure type
class StructType : public Type { class StructType : public Castable<StructType, Type> {
public: public:
/// Constructor /// Constructor
/// @param name the name of the struct /// @param name the name of the struct

View File

@ -51,7 +51,7 @@ enum class TextureDimension {
std::ostream& operator<<(std::ostream& out, TextureDimension dim); std::ostream& operator<<(std::ostream& out, TextureDimension dim);
/// A texture type. /// A texture type.
class TextureType : public Type { class TextureType : public Castable<TextureType, Type> {
public: public:
/// Constructor /// Constructor
/// @param dim the dimensionality of the texture /// @param dim the dimensionality of the texture

View File

@ -37,6 +37,8 @@ namespace type {
Type::Type() = default; Type::Type() = default;
Type:: Type(Type&&) = default;
Type::~Type() = default; Type::~Type() = default;
Type* Type::UnwrapPtrIfNeeded() { Type* Type::UnwrapPtrIfNeeded() {

View File

@ -17,6 +17,8 @@
#include <string> #include <string>
#include "src/castable.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
@ -40,11 +42,11 @@ class VoidType;
enum class MemoryLayout { kUniformBuffer, kStorageBuffer }; enum class MemoryLayout { kUniformBuffer, kStorageBuffer };
/// Base class for a type in the system /// Base class for a type in the system
class Type { class Type : public Castable<Type> {
public: public:
/// Move constructor /// Move constructor
Type(Type&&) = default; Type(Type&&);
virtual ~Type(); ~Type() override;
/// @returns true if the type is an access control type /// @returns true if the type is an access control type
virtual bool IsAccessControl() const; virtual bool IsAccessControl() const;

View File

@ -24,7 +24,7 @@ namespace ast {
namespace type { namespace type {
/// A unsigned int 32 type. /// A unsigned int 32 type.
class U32Type : public Type { class U32Type : public Castable<U32Type, Type> {
public: public:
/// Constructor /// Constructor
U32Type(); U32Type();

View File

@ -24,7 +24,7 @@ namespace ast {
namespace type { namespace type {
/// A vector type. /// A vector type.
class VectorType : public Type { class VectorType : public Castable<VectorType, Type> {
public: public:
/// Constructor /// Constructor
/// @param subtype the vector element type /// @param subtype the vector element type

View File

@ -24,7 +24,7 @@ namespace ast {
namespace type { namespace type {
/// A void type /// A void type
class VoidType : public Type { class VoidType : public Castable<VoidType, Type> {
public: public:
/// Constructor /// Constructor
VoidType(); VoidType();