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:
Antonio Maiorano 2021-04-22 15:34:13 +00:00 committed by Commit Bot service account
parent e204f27f86
commit 26fa9927e8
35 changed files with 100 additions and 63 deletions

View File

@ -24,7 +24,7 @@ namespace ast {
AccessControl::AccessControl(ProgramID program_id, AccessControl::AccessControl(ProgramID program_id,
const Source& source, const Source& source,
Access access, Access access,
Type* subtype) const Type* subtype)
: Base(program_id, source), access_(access), subtype_(subtype) { : Base(program_id, source), access_(access), subtype_(subtype) {
TINT_ASSERT(subtype_); TINT_ASSERT(subtype_);
TINT_ASSERT(!subtype_->Is<AccessControl>()); TINT_ASSERT(!subtype_->Is<AccessControl>());

View File

@ -44,7 +44,7 @@ class AccessControl : public Castable<AccessControl, Type> {
AccessControl(ProgramID program_id, AccessControl(ProgramID program_id,
const Source& source, const Source& source,
Access access, Access access,
Type* subtype); const Type* subtype);
/// Move constructor /// Move constructor
AccessControl(AccessControl&&); AccessControl(AccessControl&&);
~AccessControl() override; ~AccessControl() override;
@ -59,7 +59,7 @@ class AccessControl : public Castable<AccessControl, Type> {
/// @returns the access control value /// @returns the access control value
Access access_control() const { return access_; } Access access_control() const { return access_; }
/// @returns the subtype type /// @returns the subtype type
Type* type() const { return subtype_; } Type* type() const { return const_cast<Type*>(subtype_); }
/// @returns the name for this type /// @returns the name for this type
std::string type_name() const override; std::string type_name() const override;
@ -76,7 +76,7 @@ class AccessControl : public Castable<AccessControl, Type> {
private: private:
Access const access_; Access const access_;
Type* const subtype_; const Type* const subtype_;
}; };
/// @param out the std::ostream to write to /// @param out the std::ostream to write to

View File

@ -23,7 +23,7 @@ namespace ast {
BitcastExpression::BitcastExpression(ProgramID program_id, BitcastExpression::BitcastExpression(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
Expression* expr) Expression* expr)
: Base(program_id, source), type_(type), expr_(expr) { : Base(program_id, source), type_(type), expr_(expr) {
TINT_ASSERT(type_); TINT_ASSERT(type_);
@ -37,7 +37,7 @@ BitcastExpression::~BitcastExpression() = default;
BitcastExpression* BitcastExpression::Clone(CloneContext* ctx) const { BitcastExpression* BitcastExpression::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering // Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source()); auto src = ctx->Clone(source());
auto* ty = ctx->Clone(type_); auto* ty = ctx->Clone(type());
auto* e = ctx->Clone(expr_); auto* e = ctx->Clone(expr_);
return ctx->dst->create<BitcastExpression>(src, ty, e); return ctx->dst->create<BitcastExpression>(src, ty, e);
} }

View File

@ -30,14 +30,14 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
/// @param expr the expr /// @param expr the expr
BitcastExpression(ProgramID program_id, BitcastExpression(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
Expression* expr); Expression* expr);
/// Move constructor /// Move constructor
BitcastExpression(BitcastExpression&&); BitcastExpression(BitcastExpression&&);
~BitcastExpression() override; ~BitcastExpression() override;
/// @returns the left side expression /// @returns the left side expression
sem::Type* type() const { return type_; } sem::Type* type() const { return const_cast<sem::Type*>(type_); }
/// @returns the expression /// @returns the expression
Expression* expr() const { return expr_; } Expression* expr() const { return expr_; }
@ -58,7 +58,7 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
private: private:
BitcastExpression(const BitcastExpression&) = delete; BitcastExpression(const BitcastExpression&) = delete;
sem::Type* const type_; const sem::Type* const type_;
Expression* const expr_; Expression* const expr_;
}; };

View File

@ -23,7 +23,7 @@ namespace ast {
BoolLiteral::BoolLiteral(ProgramID program_id, BoolLiteral::BoolLiteral(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
bool value) bool value)
: Base(program_id, source, type), value_(value) {} : Base(program_id, source, type), value_(value) {}

View File

@ -32,7 +32,7 @@ class BoolLiteral : public Castable<BoolLiteral, Literal> {
/// @param value the bool literals value /// @param value the bool literals value
BoolLiteral(ProgramID program_id, BoolLiteral(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
bool value); bool value);
~BoolLiteral() override; ~BoolLiteral() override;

View File

@ -25,7 +25,7 @@ namespace ast {
FloatLiteral::FloatLiteral(ProgramID program_id, FloatLiteral::FloatLiteral(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
float value) float value)
: Base(program_id, source, type), value_(value) {} : Base(program_id, source, type), value_(value) {}

View File

@ -32,7 +32,7 @@ class FloatLiteral : public Castable<FloatLiteral, Literal> {
/// @param value the float literals value /// @param value the float literals value
FloatLiteral(ProgramID program_id, FloatLiteral(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
float value); float value);
~FloatLiteral() override; ~FloatLiteral() override;

View File

@ -21,7 +21,7 @@ namespace ast {
IntLiteral::IntLiteral(ProgramID program_id, IntLiteral::IntLiteral(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
uint32_t value) uint32_t value)
: Base(program_id, source, type), value_(value) {} : Base(program_id, source, type), value_(value) {}

View File

@ -36,7 +36,7 @@ class IntLiteral : public Castable<IntLiteral, Literal> {
/// @param value value of the literal /// @param value value of the literal
IntLiteral(ProgramID program_id, IntLiteral(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
uint32_t value); uint32_t value);
private: private:

View File

@ -19,7 +19,9 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Literal);
namespace tint { namespace tint {
namespace ast { namespace ast {
Literal::Literal(ProgramID program_id, const Source& source, sem::Type* type) Literal::Literal(ProgramID program_id,
const Source& source,
const sem::Type* type)
: Base(program_id, source), type_(type) {} : Base(program_id, source), type_(type) {}
Literal::~Literal() = default; Literal::~Literal() = default;

View File

@ -28,7 +28,7 @@ class Literal : public Castable<Literal, Node> {
~Literal() override; ~Literal() override;
/// @returns the type of the literal /// @returns the type of the literal
sem::Type* type() const { return type_; } sem::Type* type() const { return const_cast<sem::Type*>(type_); }
/// Writes a representation of the node to the output stream /// Writes a representation of the node to the output stream
/// @param sem the semantic info for the program /// @param sem the semantic info for the program
@ -50,10 +50,12 @@ class Literal : public Castable<Literal, Node> {
/// @param program_id the identifier of the program that owns this node /// @param program_id the identifier of the program that owns this node
/// @param source the input source /// @param source the input source
/// @param type the type of the literal /// @param type the type of the literal
explicit Literal(ProgramID program_id, const Source& source, sem::Type* type); explicit Literal(ProgramID program_id,
const Source& source,
const sem::Type* type);
private: private:
sem::Type* const type_; const sem::Type* const type_;
}; };
} // namespace ast } // namespace ast

View File

@ -23,7 +23,7 @@ namespace ast {
SintLiteral::SintLiteral(ProgramID program_id, SintLiteral::SintLiteral(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
int32_t value) int32_t value)
: Base(program_id, source, type, static_cast<uint32_t>(value)) {} : Base(program_id, source, type, static_cast<uint32_t>(value)) {}

View File

@ -32,7 +32,7 @@ class SintLiteral : public Castable<SintLiteral, IntLiteral> {
/// @param value the signed int literals value /// @param value the signed int literals value
SintLiteral(ProgramID program_id, SintLiteral(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
int32_t value); int32_t value);
~SintLiteral() override; ~SintLiteral() override;

View File

@ -23,7 +23,7 @@ namespace ast {
TypeConstructorExpression::TypeConstructorExpression(ProgramID program_id, TypeConstructorExpression::TypeConstructorExpression(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
ExpressionList values) ExpressionList values)
: Base(program_id, source), type_(type), values_(std::move(values)) { : Base(program_id, source), type_(type), values_(std::move(values)) {
TINT_ASSERT(type_); TINT_ASSERT(type_);

View File

@ -33,14 +33,15 @@ class TypeConstructorExpression
/// @param values the constructor values /// @param values the constructor values
TypeConstructorExpression(ProgramID program_id, TypeConstructorExpression(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
ExpressionList values); ExpressionList values);
/// Move constructor /// Move constructor
TypeConstructorExpression(TypeConstructorExpression&&); TypeConstructorExpression(TypeConstructorExpression&&);
~TypeConstructorExpression() override; ~TypeConstructorExpression() override;
/// @returns the type /// @returns the type
sem::Type* type() const { return type_; } sem::Type* type() const { return const_cast<sem::Type*>(type_); }
/// @returns the values /// @returns the values
const ExpressionList& values() const { return values_; } const ExpressionList& values() const { return values_; }
@ -61,7 +62,7 @@ class TypeConstructorExpression
private: private:
TypeConstructorExpression(const TypeConstructorExpression&) = delete; TypeConstructorExpression(const TypeConstructorExpression&) = delete;
sem::Type* const type_; const sem::Type* const type_;
ExpressionList const values_; ExpressionList const values_;
}; };

View File

@ -23,7 +23,7 @@ namespace ast {
UintLiteral::UintLiteral(ProgramID program_id, UintLiteral::UintLiteral(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
uint32_t value) uint32_t value)
: Base(program_id, source, type, value) {} : Base(program_id, source, type, value) {}

View File

@ -32,7 +32,7 @@ class UintLiteral : public Castable<UintLiteral, IntLiteral> {
/// @param value the uint literals value /// @param value the uint literals value
UintLiteral(ProgramID program_id, UintLiteral(ProgramID program_id,
const Source& source, const Source& source,
sem::Type* type, const sem::Type* type,
uint32_t value); uint32_t value);
~UintLiteral() override; ~UintLiteral() override;

View File

@ -27,7 +27,7 @@ Variable::Variable(ProgramID program_id,
const Source& source, const Source& source,
const Symbol& sym, const Symbol& sym,
StorageClass declared_storage_class, StorageClass declared_storage_class,
sem::Type* declared_type, const sem::Type* declared_type,
bool is_const, bool is_const,
Expression* constructor, Expression* constructor,
DecorationList decorations) DecorationList decorations)

View File

@ -103,7 +103,7 @@ class Variable : public Castable<Variable, Node> {
const Source& source, const Source& source,
const Symbol& sym, const Symbol& sym,
StorageClass declared_storage_class, StorageClass declared_storage_class,
sem::Type* declared_type, const sem::Type* declared_type,
bool is_const, bool is_const,
Expression* constructor, Expression* constructor,
DecorationList decorations); DecorationList decorations);
@ -116,7 +116,9 @@ class Variable : public Castable<Variable, Node> {
const Symbol& symbol() const { return symbol_; } const Symbol& symbol() const { return symbol_; }
/// @returns the declared type /// @returns the declared type
sem::Type* declared_type() const { return declared_type_; } sem::Type* declared_type() const {
return const_cast<sem::Type*>(declared_type_);
}
/// @returns the declared storage class /// @returns the declared storage class
StorageClass declared_storage_class() const { StorageClass declared_storage_class() const {
@ -175,7 +177,7 @@ class Variable : public Castable<Variable, Node> {
Symbol const symbol_; Symbol const symbol_;
// The value type if a const or formal paramter, and the store type if a var // The value type if a const or formal paramter, and the store type if a var
sem::Type* const declared_type_; const sem::Type* const declared_type_;
bool const is_const_; bool const is_const_;
Expression* const constructor_; Expression* const constructor_;
DecorationList const decorations_; DecorationList const decorations_;

View File

@ -21,7 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::AccessControl);
namespace tint { namespace tint {
namespace sem { namespace sem {
AccessControl::AccessControl(ast::AccessControl::Access access, Type* subtype) AccessControl::AccessControl(ast::AccessControl::Access access,
const Type* subtype)
: access_(access), subtype_(subtype) { : access_(access), subtype_(subtype) {
TINT_ASSERT(subtype_); TINT_ASSERT(subtype_);
TINT_ASSERT(!subtype_->Is<AccessControl>()); TINT_ASSERT(!subtype_->Is<AccessControl>());

View File

@ -29,7 +29,7 @@ class AccessControl : public Castable<AccessControl, Type> {
/// 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
AccessControl(ast::AccessControl::Access access, Type* subtype); AccessControl(ast::AccessControl::Access access, const Type* subtype);
/// Move constructor /// Move constructor
AccessControl(AccessControl&&); AccessControl(AccessControl&&);
~AccessControl() override; ~AccessControl() override;
@ -44,7 +44,7 @@ class AccessControl : public Castable<AccessControl, Type> {
/// @returns the access control value /// @returns the access control value
ast::AccessControl::Access access_control() const { return access_; } ast::AccessControl::Access access_control() const { return access_; }
/// @returns the subtype type /// @returns the subtype type
Type* type() const { return subtype_; } Type* type() const { return const_cast<Type*>(subtype_); }
/// @returns the name for this type /// @returns the name for this type
std::string type_name() const override; std::string type_name() const override;
@ -61,7 +61,7 @@ class AccessControl : public Castable<AccessControl, Type> {
private: private:
ast::AccessControl::Access const access_; ast::AccessControl::Access const access_;
Type* const subtype_; const Type* const subtype_;
}; };
} // namespace sem } // namespace sem

View File

@ -21,7 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::Alias);
namespace tint { namespace tint {
namespace sem { namespace sem {
Alias::Alias(const Symbol& sym, Type* subtype) Alias::Alias(const Symbol& sym, const Type* subtype)
: symbol_(sym), subtype_(subtype) { : symbol_(sym), subtype_(subtype) {
TINT_ASSERT(subtype_); TINT_ASSERT(subtype_);
} }

View File

@ -28,7 +28,7 @@ class Alias : public Castable<Alias, Type> {
/// Constructor /// Constructor
/// @param sym the symbol for the alias /// @param sym the symbol for the alias
/// @param subtype the alias'd type /// @param subtype the alias'd type
Alias(const Symbol& sym, Type* subtype); Alias(const Symbol& sym, const Type* subtype);
/// Move constructor /// Move constructor
Alias(Alias&&); Alias(Alias&&);
/// Destructor /// Destructor
@ -37,7 +37,7 @@ class Alias : public Castable<Alias, Type> {
/// @returns the alias symbol /// @returns the alias symbol
Symbol symbol() const { return symbol_; } Symbol symbol() const { return symbol_; }
/// @returns the alias type /// @returns the alias type
Type* type() const { return subtype_; } Type* type() const { return const_cast<Type*>(subtype_); }
/// @returns the type_name for this type /// @returns the type_name for this type
std::string type_name() const override; std::string type_name() const override;
@ -54,7 +54,7 @@ class Alias : public Castable<Alias, Type> {
private: private:
Symbol const symbol_; Symbol const symbol_;
Type* const subtype_; const Type* const subtype_;
}; };
} // namespace sem } // namespace sem

View File

@ -20,7 +20,7 @@ namespace tint {
namespace sem { namespace sem {
Expression::Expression(ast::Expression* declaration, Expression::Expression(ast::Expression* declaration,
sem::Type* type, const sem::Type* type,
Statement* statement) Statement* statement)
: declaration_(declaration), : declaration_(declaration),
type_(type->UnwrapIfNeeded()), type_(type->UnwrapIfNeeded()),

View File

@ -32,11 +32,11 @@ class Expression : public Castable<Expression, Node> {
/// @param type the resolved type of the expression /// @param type the resolved type of the expression
/// @param statement the statement that owns this expression /// @param statement the statement that owns this expression
Expression(ast::Expression* declaration, Expression(ast::Expression* declaration,
sem::Type* type, const sem::Type* type,
Statement* statement); Statement* statement);
/// @return the resolved type of the expression /// @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 /// @return the statement that owns this expression
Statement* Stmt() const { return statement_; } Statement* Stmt() const { return statement_; }
@ -46,7 +46,7 @@ class Expression : public Castable<Expression, Node> {
private: private:
ast::Expression* declaration_; ast::Expression* declaration_;
sem::Type* const type_; const sem::Type* const type_;
Statement* const statement_; Statement* const statement_;
}; };

View File

@ -26,7 +26,7 @@ namespace sem {
MemberAccessorExpression::MemberAccessorExpression( MemberAccessorExpression::MemberAccessorExpression(
ast::MemberAccessorExpression* declaration, ast::MemberAccessorExpression* declaration,
sem::Type* type, const sem::Type* type,
Statement* statement) Statement* statement)
: Base(declaration, type, statement) {} : Base(declaration, type, statement) {}
@ -34,7 +34,7 @@ MemberAccessorExpression::~MemberAccessorExpression() = default;
StructMemberAccess::StructMemberAccess( StructMemberAccess::StructMemberAccess(
ast::MemberAccessorExpression* declaration, ast::MemberAccessorExpression* declaration,
sem::Type* type, const sem::Type* type,
Statement* statement, Statement* statement,
const StructMember* member) const StructMember* member)
: Base(declaration, type, statement), member_(member) {} : Base(declaration, type, statement), member_(member) {}
@ -42,7 +42,7 @@ StructMemberAccess::StructMemberAccess(
StructMemberAccess::~StructMemberAccess() = default; StructMemberAccess::~StructMemberAccess() = default;
Swizzle::Swizzle(ast::MemberAccessorExpression* declaration, Swizzle::Swizzle(ast::MemberAccessorExpression* declaration,
sem::Type* type, const sem::Type* type,
Statement* statement, Statement* statement,
std::vector<uint32_t> indices) std::vector<uint32_t> indices)
: Base(declaration, type, statement), indices_(std::move(indices)) {} : Base(declaration, type, statement), indices_(std::move(indices)) {}

View File

@ -42,7 +42,7 @@ class MemberAccessorExpression
/// @param type the resolved type of the expression /// @param type the resolved type of the expression
/// @param statement the statement that owns this expression /// @param statement the statement that owns this expression
MemberAccessorExpression(ast::MemberAccessorExpression* declaration, MemberAccessorExpression(ast::MemberAccessorExpression* declaration,
sem::Type* type, const sem::Type* type,
Statement* statement); Statement* statement);
/// Destructor /// Destructor
@ -61,7 +61,7 @@ class StructMemberAccess
/// @param statement the statement that owns this expression /// @param statement the statement that owns this expression
/// @param member the structure member /// @param member the structure member
StructMemberAccess(ast::MemberAccessorExpression* declaration, StructMemberAccess(ast::MemberAccessorExpression* declaration,
sem::Type* type, const sem::Type* type,
Statement* statement, Statement* statement,
const StructMember* member); const StructMember* member);
@ -85,7 +85,7 @@ class Swizzle : public Castable<Swizzle, MemberAccessorExpression> {
/// @param statement the statement that /// @param statement the statement that
/// @param indices the swizzle indices /// @param indices the swizzle indices
Swizzle(ast::MemberAccessorExpression* declaration, Swizzle(ast::MemberAccessorExpression* declaration,
sem::Type* type, const sem::Type* type,
Statement* statement, Statement* statement,
std::vector<uint32_t> indices); std::vector<uint32_t> indices);

View File

@ -21,7 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::MultisampledTexture);
namespace tint { namespace tint {
namespace sem { namespace sem {
MultisampledTexture::MultisampledTexture(ast::TextureDimension dim, Type* type) MultisampledTexture::MultisampledTexture(ast::TextureDimension dim,
const Type* type)
: Base(dim), type_(type) { : Base(dim), type_(type) {
TINT_ASSERT(type_); TINT_ASSERT(type_);
} }

View File

@ -28,13 +28,13 @@ class MultisampledTexture : public Castable<MultisampledTexture, Texture> {
/// Constructor /// Constructor
/// @param dim the dimensionality of the texture /// @param dim the dimensionality of the texture
/// @param type the data type of the multisampled 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 /// Move constructor
MultisampledTexture(MultisampledTexture&&); MultisampledTexture(MultisampledTexture&&);
~MultisampledTexture() override; ~MultisampledTexture() override;
/// @returns the subtype of the sampled texture /// @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 /// @returns the name for this type
std::string type_name() const override; std::string type_name() const override;
@ -50,7 +50,7 @@ class MultisampledTexture : public Castable<MultisampledTexture, Texture> {
MultisampledTexture* Clone(CloneContext* ctx) const override; MultisampledTexture* Clone(CloneContext* ctx) const override;
private: private:
Type* const type_; const Type* const type_;
}; };
} // namespace sem } // namespace sem

View File

@ -21,7 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::SampledTexture);
namespace tint { namespace tint {
namespace sem { namespace sem {
SampledTexture::SampledTexture(ast::TextureDimension dim, Type* type) SampledTexture::SampledTexture(ast::TextureDimension dim, const Type* type)
: Base(dim), type_(type) { : Base(dim), type_(type) {
TINT_ASSERT(type_); TINT_ASSERT(type_);
} }

View File

@ -28,13 +28,13 @@ class SampledTexture : public Castable<SampledTexture, Texture> {
/// Constructor /// Constructor
/// @param dim the dimensionality of the texture /// @param dim the dimensionality of the texture
/// @param type the data type of the sampled 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 /// Move constructor
SampledTexture(SampledTexture&&); SampledTexture(SampledTexture&&);
~SampledTexture() override; ~SampledTexture() override;
/// @returns the subtype of the sampled texture /// @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 /// @returns the name for this type
std::string type_name() const override; std::string type_name() const override;
@ -50,7 +50,7 @@ class SampledTexture : public Castable<SampledTexture, Texture> {
SampledTexture* Clone(CloneContext* ctx) const override; SampledTexture* Clone(CloneContext* ctx) const override;
private: private:
Type* const type_; const Type* const type_;
}; };
} // namespace sem } // namespace sem

View File

@ -48,10 +48,21 @@ class Type : public Castable<Type, ShareableCloneable> {
/// @returns the pointee type if this is a pointer, `this` otherwise /// @returns the pointee type if this is a pointer, `this` otherwise
Type* UnwrapPtrIfNeeded(); 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` /// @returns the most deeply nested aliased type if this is an alias, `this`
/// otherwise /// otherwise
Type* UnwrapAliasIfNeeded(); 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. /// Removes all levels of aliasing and access control.
/// This is just enough to assist with WGSL translation /// This is just enough to assist with WGSL translation
/// in that you want see through one level of pointer to get from an /// 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. /// @returns the completely unaliased type.
Type* UnwrapIfNeeded(); 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: /// Returns the type found after:
/// - removing all layers of aliasing and access control if they exist, then /// - removing all layers of aliasing and access control if they exist, then
/// - removing the pointer, if it exists, then /// - removing the pointer, if it exists, then
@ -67,6 +88,13 @@ class Type : public Castable<Type, ShareableCloneable> {
/// @returns the unwrapped type /// @returns the unwrapped type
Type* UnwrapAll(); 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 /// @returns true if this type is a scalar
bool is_scalar() const; bool is_scalar() const;
/// @returns true if this type is a numeric scalar /// @returns true if this type is a numeric scalar

View File

@ -24,7 +24,7 @@ namespace tint {
namespace sem { namespace sem {
Variable::Variable(const ast::Variable* declaration, Variable::Variable(const ast::Variable* declaration,
sem::Type* type, const sem::Type* type,
ast::StorageClass storage_class) ast::StorageClass storage_class)
: declaration_(declaration), type_(type), storage_class_(storage_class) {} : declaration_(declaration), type_(type), storage_class_(storage_class) {}
@ -35,7 +35,7 @@ sem::Type* Variable::DeclaredType() const {
} }
VariableUser::VariableUser(ast::IdentifierExpression* declaration, VariableUser::VariableUser(ast::IdentifierExpression* declaration,
sem::Type* type, const sem::Type* type,
Statement* statement, Statement* statement,
sem::Variable* variable) sem::Variable* variable)
: Base(declaration, type, statement), variable_(variable) {} : Base(declaration, type, statement), variable_(variable) {}

View File

@ -42,7 +42,7 @@ class Variable : public Castable<Variable, Node> {
/// @param type the variable type /// @param type the variable type
/// @param storage_class the variable storage class /// @param storage_class the variable storage class
Variable(const ast::Variable* declaration, Variable(const ast::Variable* declaration,
sem::Type* type, const sem::Type* type,
ast::StorageClass storage_class); ast::StorageClass storage_class);
/// Destructor /// Destructor
@ -52,7 +52,7 @@ class Variable : public Castable<Variable, Node> {
const ast::Variable* Declaration() const { return declaration_; } const ast::Variable* Declaration() const { return declaration_; }
/// @returns the canonical type for the variable /// @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. /// @returns the AST node's type. May be nullptr.
sem::Type* DeclaredType() const; sem::Type* DeclaredType() const;
@ -68,7 +68,7 @@ class Variable : public Castable<Variable, Node> {
private: private:
const ast::Variable* const declaration_; const ast::Variable* const declaration_;
sem::Type* const type_; const sem::Type* const type_;
ast::StorageClass const storage_class_; ast::StorageClass const storage_class_;
std::vector<const VariableUser*> users_; std::vector<const VariableUser*> users_;
}; };
@ -83,7 +83,7 @@ class VariableUser : public Castable<VariableUser, Expression> {
/// @param statement the statement that owns this expression /// @param statement the statement that owns this expression
/// @param variable the semantic variable /// @param variable the semantic variable
VariableUser(ast::IdentifierExpression* declaration, VariableUser(ast::IdentifierExpression* declaration,
sem::Type* type, const sem::Type* type,
Statement* statement, Statement* statement,
sem::Variable* variable); sem::Variable* variable);