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());
}
AccessControlType::AccessControlType(AccessControlType&&) = default;
AccessControlType::~AccessControlType() = default;
bool AccessControlType::IsAccessControl() const {

View File

@ -25,14 +25,14 @@ namespace ast {
namespace 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:
/// Constructor
/// @param access the access control setting
/// @param subtype the access controlled type
AccessControlType(AccessControl access, Type* subtype);
/// Move constructor
AccessControlType(AccessControlType&&) = default;
AccessControlType(AccessControlType&&);
~AccessControlType() override;
/// @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_);
}
AliasType::AliasType(AliasType&&) = default;
AliasType::~AliasType() = default;
bool AliasType::IsAlias() const {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,12 +24,12 @@ namespace ast {
namespace type {
/// A signed int 32 type.
class I32Type : public Type {
class I32Type : public Castable<I32Type, Type> {
public:
/// Constructor
I32Type();
/// Move constructor
I32Type(I32Type&&) = default;
I32Type(I32Type&&);
~I32Type() override;
/// @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);
}
MatrixType::MatrixType(MatrixType&&) = default;
MatrixType::~MatrixType() = default;
bool MatrixType::IsMatrix() const {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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