mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-08 13:14:56 +00:00
Constify Type* constructor args for ast/sem classes
To avoid breaking things, functions that return the type cast away the constness for now. This, however, makes it easier to use typ::Type with these classes, as typ::Type stores pointers to const types. This also brings us one step closer to constifying types everywhere. Bug: tint:724 Change-Id: Ia3f4b76f375184dd09b8041c1f60bf1afaefe629 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48740 Commit-Queue: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
e204f27f86
commit
26fa9927e8
@@ -21,7 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::AccessControl);
|
||||
namespace tint {
|
||||
namespace sem {
|
||||
|
||||
AccessControl::AccessControl(ast::AccessControl::Access access, Type* subtype)
|
||||
AccessControl::AccessControl(ast::AccessControl::Access access,
|
||||
const Type* subtype)
|
||||
: access_(access), subtype_(subtype) {
|
||||
TINT_ASSERT(subtype_);
|
||||
TINT_ASSERT(!subtype_->Is<AccessControl>());
|
||||
|
||||
@@ -29,7 +29,7 @@ class AccessControl : public Castable<AccessControl, Type> {
|
||||
/// Constructor
|
||||
/// @param access the access control setting
|
||||
/// @param subtype the access controlled type
|
||||
AccessControl(ast::AccessControl::Access access, Type* subtype);
|
||||
AccessControl(ast::AccessControl::Access access, const Type* subtype);
|
||||
/// Move constructor
|
||||
AccessControl(AccessControl&&);
|
||||
~AccessControl() override;
|
||||
@@ -44,7 +44,7 @@ class AccessControl : public Castable<AccessControl, Type> {
|
||||
/// @returns the access control value
|
||||
ast::AccessControl::Access access_control() const { return access_; }
|
||||
/// @returns the subtype type
|
||||
Type* type() const { return subtype_; }
|
||||
Type* type() const { return const_cast<Type*>(subtype_); }
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
@@ -61,7 +61,7 @@ class AccessControl : public Castable<AccessControl, Type> {
|
||||
|
||||
private:
|
||||
ast::AccessControl::Access const access_;
|
||||
Type* const subtype_;
|
||||
const Type* const subtype_;
|
||||
};
|
||||
|
||||
} // namespace sem
|
||||
|
||||
@@ -21,7 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::Alias);
|
||||
namespace tint {
|
||||
namespace sem {
|
||||
|
||||
Alias::Alias(const Symbol& sym, Type* subtype)
|
||||
Alias::Alias(const Symbol& sym, const Type* subtype)
|
||||
: symbol_(sym), subtype_(subtype) {
|
||||
TINT_ASSERT(subtype_);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class Alias : public Castable<Alias, Type> {
|
||||
/// Constructor
|
||||
/// @param sym the symbol for the alias
|
||||
/// @param subtype the alias'd type
|
||||
Alias(const Symbol& sym, Type* subtype);
|
||||
Alias(const Symbol& sym, const Type* subtype);
|
||||
/// Move constructor
|
||||
Alias(Alias&&);
|
||||
/// Destructor
|
||||
@@ -37,7 +37,7 @@ class Alias : public Castable<Alias, Type> {
|
||||
/// @returns the alias symbol
|
||||
Symbol symbol() const { return symbol_; }
|
||||
/// @returns the alias type
|
||||
Type* type() const { return subtype_; }
|
||||
Type* type() const { return const_cast<Type*>(subtype_); }
|
||||
|
||||
/// @returns the type_name for this type
|
||||
std::string type_name() const override;
|
||||
@@ -54,7 +54,7 @@ class Alias : public Castable<Alias, Type> {
|
||||
|
||||
private:
|
||||
Symbol const symbol_;
|
||||
Type* const subtype_;
|
||||
const Type* const subtype_;
|
||||
};
|
||||
|
||||
} // namespace sem
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace tint {
|
||||
namespace sem {
|
||||
|
||||
Expression::Expression(ast::Expression* declaration,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
Statement* statement)
|
||||
: declaration_(declaration),
|
||||
type_(type->UnwrapIfNeeded()),
|
||||
|
||||
@@ -32,11 +32,11 @@ class Expression : public Castable<Expression, Node> {
|
||||
/// @param type the resolved type of the expression
|
||||
/// @param statement the statement that owns this expression
|
||||
Expression(ast::Expression* declaration,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
Statement* statement);
|
||||
|
||||
/// @return the resolved type of the expression
|
||||
sem::Type* Type() const { return type_; }
|
||||
sem::Type* Type() const { return const_cast<sem::Type*>(type_); }
|
||||
|
||||
/// @return the statement that owns this expression
|
||||
Statement* Stmt() const { return statement_; }
|
||||
@@ -46,7 +46,7 @@ class Expression : public Castable<Expression, Node> {
|
||||
|
||||
private:
|
||||
ast::Expression* declaration_;
|
||||
sem::Type* const type_;
|
||||
const sem::Type* const type_;
|
||||
Statement* const statement_;
|
||||
};
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace sem {
|
||||
|
||||
MemberAccessorExpression::MemberAccessorExpression(
|
||||
ast::MemberAccessorExpression* declaration,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
Statement* statement)
|
||||
: Base(declaration, type, statement) {}
|
||||
|
||||
@@ -34,7 +34,7 @@ MemberAccessorExpression::~MemberAccessorExpression() = default;
|
||||
|
||||
StructMemberAccess::StructMemberAccess(
|
||||
ast::MemberAccessorExpression* declaration,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
Statement* statement,
|
||||
const StructMember* member)
|
||||
: Base(declaration, type, statement), member_(member) {}
|
||||
@@ -42,7 +42,7 @@ StructMemberAccess::StructMemberAccess(
|
||||
StructMemberAccess::~StructMemberAccess() = default;
|
||||
|
||||
Swizzle::Swizzle(ast::MemberAccessorExpression* declaration,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
Statement* statement,
|
||||
std::vector<uint32_t> indices)
|
||||
: Base(declaration, type, statement), indices_(std::move(indices)) {}
|
||||
|
||||
@@ -42,7 +42,7 @@ class MemberAccessorExpression
|
||||
/// @param type the resolved type of the expression
|
||||
/// @param statement the statement that owns this expression
|
||||
MemberAccessorExpression(ast::MemberAccessorExpression* declaration,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
Statement* statement);
|
||||
|
||||
/// Destructor
|
||||
@@ -61,7 +61,7 @@ class StructMemberAccess
|
||||
/// @param statement the statement that owns this expression
|
||||
/// @param member the structure member
|
||||
StructMemberAccess(ast::MemberAccessorExpression* declaration,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
Statement* statement,
|
||||
const StructMember* member);
|
||||
|
||||
@@ -85,7 +85,7 @@ class Swizzle : public Castable<Swizzle, MemberAccessorExpression> {
|
||||
/// @param statement the statement that
|
||||
/// @param indices the swizzle indices
|
||||
Swizzle(ast::MemberAccessorExpression* declaration,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
Statement* statement,
|
||||
std::vector<uint32_t> indices);
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::MultisampledTexture);
|
||||
namespace tint {
|
||||
namespace sem {
|
||||
|
||||
MultisampledTexture::MultisampledTexture(ast::TextureDimension dim, Type* type)
|
||||
MultisampledTexture::MultisampledTexture(ast::TextureDimension dim,
|
||||
const Type* type)
|
||||
: Base(dim), type_(type) {
|
||||
TINT_ASSERT(type_);
|
||||
}
|
||||
|
||||
@@ -28,13 +28,13 @@ class MultisampledTexture : public Castable<MultisampledTexture, Texture> {
|
||||
/// Constructor
|
||||
/// @param dim the dimensionality of the texture
|
||||
/// @param type the data type of the multisampled texture
|
||||
MultisampledTexture(ast::TextureDimension dim, Type* type);
|
||||
MultisampledTexture(ast::TextureDimension dim, const Type* type);
|
||||
/// Move constructor
|
||||
MultisampledTexture(MultisampledTexture&&);
|
||||
~MultisampledTexture() override;
|
||||
|
||||
/// @returns the subtype of the sampled texture
|
||||
Type* type() const { return type_; }
|
||||
Type* type() const { return const_cast<Type*>(type_); }
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
@@ -50,7 +50,7 @@ class MultisampledTexture : public Castable<MultisampledTexture, Texture> {
|
||||
MultisampledTexture* Clone(CloneContext* ctx) const override;
|
||||
|
||||
private:
|
||||
Type* const type_;
|
||||
const Type* const type_;
|
||||
};
|
||||
|
||||
} // namespace sem
|
||||
|
||||
@@ -21,7 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::SampledTexture);
|
||||
namespace tint {
|
||||
namespace sem {
|
||||
|
||||
SampledTexture::SampledTexture(ast::TextureDimension dim, Type* type)
|
||||
SampledTexture::SampledTexture(ast::TextureDimension dim, const Type* type)
|
||||
: Base(dim), type_(type) {
|
||||
TINT_ASSERT(type_);
|
||||
}
|
||||
|
||||
@@ -28,13 +28,13 @@ class SampledTexture : public Castable<SampledTexture, Texture> {
|
||||
/// Constructor
|
||||
/// @param dim the dimensionality of the texture
|
||||
/// @param type the data type of the sampled texture
|
||||
SampledTexture(ast::TextureDimension dim, Type* type);
|
||||
SampledTexture(ast::TextureDimension dim, const Type* type);
|
||||
/// Move constructor
|
||||
SampledTexture(SampledTexture&&);
|
||||
~SampledTexture() override;
|
||||
|
||||
/// @returns the subtype of the sampled texture
|
||||
Type* type() const { return type_; }
|
||||
Type* type() const { return const_cast<Type*>(type_); }
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
@@ -50,7 +50,7 @@ class SampledTexture : public Castable<SampledTexture, Texture> {
|
||||
SampledTexture* Clone(CloneContext* ctx) const override;
|
||||
|
||||
private:
|
||||
Type* const type_;
|
||||
const Type* const type_;
|
||||
};
|
||||
|
||||
} // namespace sem
|
||||
|
||||
@@ -48,10 +48,21 @@ class Type : public Castable<Type, ShareableCloneable> {
|
||||
/// @returns the pointee type if this is a pointer, `this` otherwise
|
||||
Type* UnwrapPtrIfNeeded();
|
||||
|
||||
/// @returns the pointee type if this is a pointer, `this` otherwise
|
||||
const Type* UnwrapPtrIfNeeded() const {
|
||||
return const_cast<Type*>(this)->UnwrapPtrIfNeeded();
|
||||
}
|
||||
|
||||
/// @returns the most deeply nested aliased type if this is an alias, `this`
|
||||
/// otherwise
|
||||
Type* UnwrapAliasIfNeeded();
|
||||
|
||||
/// @returns the most deeply nested aliased type if this is an alias, `this`
|
||||
/// otherwise
|
||||
const Type* UnwrapAliasIfNeeded() const {
|
||||
return const_cast<Type*>(this)->UnwrapAliasIfNeeded();
|
||||
}
|
||||
|
||||
/// Removes all levels of aliasing and access control.
|
||||
/// This is just enough to assist with WGSL translation
|
||||
/// in that you want see through one level of pointer to get from an
|
||||
@@ -60,6 +71,16 @@ class Type : public Castable<Type, ShareableCloneable> {
|
||||
/// @returns the completely unaliased type.
|
||||
Type* UnwrapIfNeeded();
|
||||
|
||||
/// Removes all levels of aliasing and access control.
|
||||
/// This is just enough to assist with WGSL translation
|
||||
/// in that you want see through one level of pointer to get from an
|
||||
/// identifier-like expression as an l-value to its corresponding r-value,
|
||||
/// plus see through the wrappers on either side.
|
||||
/// @returns the completely unaliased type.
|
||||
const Type* UnwrapIfNeeded() const {
|
||||
return const_cast<Type*>(this)->UnwrapIfNeeded();
|
||||
}
|
||||
|
||||
/// Returns the type found after:
|
||||
/// - removing all layers of aliasing and access control if they exist, then
|
||||
/// - removing the pointer, if it exists, then
|
||||
@@ -67,6 +88,13 @@ class Type : public Castable<Type, ShareableCloneable> {
|
||||
/// @returns the unwrapped type
|
||||
Type* UnwrapAll();
|
||||
|
||||
/// Returns the type found after:
|
||||
/// - removing all layers of aliasing and access control if they exist, then
|
||||
/// - removing the pointer, if it exists, then
|
||||
/// - removing all further layers of aliasing or access control, if they exist
|
||||
/// @returns the unwrapped type
|
||||
const Type* UnwrapAll() const { return const_cast<Type*>(this)->UnwrapAll(); }
|
||||
|
||||
/// @returns true if this type is a scalar
|
||||
bool is_scalar() const;
|
||||
/// @returns true if this type is a numeric scalar
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace tint {
|
||||
namespace sem {
|
||||
|
||||
Variable::Variable(const ast::Variable* declaration,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
ast::StorageClass storage_class)
|
||||
: declaration_(declaration), type_(type), storage_class_(storage_class) {}
|
||||
|
||||
@@ -35,7 +35,7 @@ sem::Type* Variable::DeclaredType() const {
|
||||
}
|
||||
|
||||
VariableUser::VariableUser(ast::IdentifierExpression* declaration,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
Statement* statement,
|
||||
sem::Variable* variable)
|
||||
: Base(declaration, type, statement), variable_(variable) {}
|
||||
|
||||
@@ -42,7 +42,7 @@ class Variable : public Castable<Variable, Node> {
|
||||
/// @param type the variable type
|
||||
/// @param storage_class the variable storage class
|
||||
Variable(const ast::Variable* declaration,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
ast::StorageClass storage_class);
|
||||
|
||||
/// Destructor
|
||||
@@ -52,7 +52,7 @@ class Variable : public Castable<Variable, Node> {
|
||||
const ast::Variable* Declaration() const { return declaration_; }
|
||||
|
||||
/// @returns the canonical type for the variable
|
||||
sem::Type* Type() const { return type_; }
|
||||
sem::Type* Type() const { return const_cast<sem::Type*>(type_); }
|
||||
|
||||
/// @returns the AST node's type. May be nullptr.
|
||||
sem::Type* DeclaredType() const;
|
||||
@@ -68,7 +68,7 @@ class Variable : public Castable<Variable, Node> {
|
||||
|
||||
private:
|
||||
const ast::Variable* const declaration_;
|
||||
sem::Type* const type_;
|
||||
const sem::Type* const type_;
|
||||
ast::StorageClass const storage_class_;
|
||||
std::vector<const VariableUser*> users_;
|
||||
};
|
||||
@@ -83,7 +83,7 @@ class VariableUser : public Castable<VariableUser, Expression> {
|
||||
/// @param statement the statement that owns this expression
|
||||
/// @param variable the semantic variable
|
||||
VariableUser(ast::IdentifierExpression* declaration,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
Statement* statement,
|
||||
sem::Variable* variable);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user