mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-11 14:41:50 +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
@@ -24,7 +24,7 @@ namespace ast {
|
||||
AccessControl::AccessControl(ProgramID program_id,
|
||||
const Source& source,
|
||||
Access access,
|
||||
Type* subtype)
|
||||
const Type* subtype)
|
||||
: Base(program_id, source), access_(access), subtype_(subtype) {
|
||||
TINT_ASSERT(subtype_);
|
||||
TINT_ASSERT(!subtype_->Is<AccessControl>());
|
||||
|
||||
@@ -44,7 +44,7 @@ class AccessControl : public Castable<AccessControl, Type> {
|
||||
AccessControl(ProgramID program_id,
|
||||
const Source& source,
|
||||
Access access,
|
||||
Type* subtype);
|
||||
const Type* subtype);
|
||||
/// Move constructor
|
||||
AccessControl(AccessControl&&);
|
||||
~AccessControl() override;
|
||||
@@ -59,7 +59,7 @@ class AccessControl : public Castable<AccessControl, Type> {
|
||||
/// @returns the access control value
|
||||
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;
|
||||
@@ -76,7 +76,7 @@ class AccessControl : public Castable<AccessControl, Type> {
|
||||
|
||||
private:
|
||||
Access const access_;
|
||||
Type* const subtype_;
|
||||
const Type* const subtype_;
|
||||
};
|
||||
|
||||
/// @param out the std::ostream to write to
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ast {
|
||||
|
||||
BitcastExpression::BitcastExpression(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
Expression* expr)
|
||||
: Base(program_id, source), type_(type), expr_(expr) {
|
||||
TINT_ASSERT(type_);
|
||||
@@ -37,7 +37,7 @@ BitcastExpression::~BitcastExpression() = default;
|
||||
BitcastExpression* BitcastExpression::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source());
|
||||
auto* ty = ctx->Clone(type_);
|
||||
auto* ty = ctx->Clone(type());
|
||||
auto* e = ctx->Clone(expr_);
|
||||
return ctx->dst->create<BitcastExpression>(src, ty, e);
|
||||
}
|
||||
|
||||
@@ -30,14 +30,14 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
|
||||
/// @param expr the expr
|
||||
BitcastExpression(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
Expression* expr);
|
||||
/// Move constructor
|
||||
BitcastExpression(BitcastExpression&&);
|
||||
~BitcastExpression() override;
|
||||
|
||||
/// @returns the left side expression
|
||||
sem::Type* type() const { return type_; }
|
||||
sem::Type* type() const { return const_cast<sem::Type*>(type_); }
|
||||
/// @returns the expression
|
||||
Expression* expr() const { return expr_; }
|
||||
|
||||
@@ -58,7 +58,7 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
|
||||
private:
|
||||
BitcastExpression(const BitcastExpression&) = delete;
|
||||
|
||||
sem::Type* const type_;
|
||||
const sem::Type* const type_;
|
||||
Expression* const expr_;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ast {
|
||||
|
||||
BoolLiteral::BoolLiteral(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
bool value)
|
||||
: Base(program_id, source, type), value_(value) {}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class BoolLiteral : public Castable<BoolLiteral, Literal> {
|
||||
/// @param value the bool literals value
|
||||
BoolLiteral(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
bool value);
|
||||
~BoolLiteral() override;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace ast {
|
||||
|
||||
FloatLiteral::FloatLiteral(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
float value)
|
||||
: Base(program_id, source, type), value_(value) {}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class FloatLiteral : public Castable<FloatLiteral, Literal> {
|
||||
/// @param value the float literals value
|
||||
FloatLiteral(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
float value);
|
||||
~FloatLiteral() override;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace ast {
|
||||
|
||||
IntLiteral::IntLiteral(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
uint32_t value)
|
||||
: Base(program_id, source, type), value_(value) {}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class IntLiteral : public Castable<IntLiteral, Literal> {
|
||||
/// @param value value of the literal
|
||||
IntLiteral(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
uint32_t value);
|
||||
|
||||
private:
|
||||
|
||||
@@ -19,7 +19,9 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Literal);
|
||||
namespace tint {
|
||||
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) {}
|
||||
|
||||
Literal::~Literal() = default;
|
||||
|
||||
@@ -28,7 +28,7 @@ class Literal : public Castable<Literal, Node> {
|
||||
~Literal() override;
|
||||
|
||||
/// @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
|
||||
/// @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 source the input source
|
||||
/// @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:
|
||||
sem::Type* const type_;
|
||||
const sem::Type* const type_;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ast {
|
||||
|
||||
SintLiteral::SintLiteral(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
int32_t value)
|
||||
: Base(program_id, source, type, static_cast<uint32_t>(value)) {}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class SintLiteral : public Castable<SintLiteral, IntLiteral> {
|
||||
/// @param value the signed int literals value
|
||||
SintLiteral(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
int32_t value);
|
||||
~SintLiteral() override;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ast {
|
||||
|
||||
TypeConstructorExpression::TypeConstructorExpression(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
ExpressionList values)
|
||||
: Base(program_id, source), type_(type), values_(std::move(values)) {
|
||||
TINT_ASSERT(type_);
|
||||
|
||||
@@ -33,14 +33,15 @@ class TypeConstructorExpression
|
||||
/// @param values the constructor values
|
||||
TypeConstructorExpression(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
ExpressionList values);
|
||||
/// Move constructor
|
||||
TypeConstructorExpression(TypeConstructorExpression&&);
|
||||
~TypeConstructorExpression() override;
|
||||
|
||||
/// @returns the type
|
||||
sem::Type* type() const { return type_; }
|
||||
sem::Type* type() const { return const_cast<sem::Type*>(type_); }
|
||||
|
||||
/// @returns the values
|
||||
const ExpressionList& values() const { return values_; }
|
||||
|
||||
@@ -61,7 +62,7 @@ class TypeConstructorExpression
|
||||
private:
|
||||
TypeConstructorExpression(const TypeConstructorExpression&) = delete;
|
||||
|
||||
sem::Type* const type_;
|
||||
const sem::Type* const type_;
|
||||
ExpressionList const values_;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ast {
|
||||
|
||||
UintLiteral::UintLiteral(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
uint32_t value)
|
||||
: Base(program_id, source, type, value) {}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class UintLiteral : public Castable<UintLiteral, IntLiteral> {
|
||||
/// @param value the uint literals value
|
||||
UintLiteral(ProgramID program_id,
|
||||
const Source& source,
|
||||
sem::Type* type,
|
||||
const sem::Type* type,
|
||||
uint32_t value);
|
||||
~UintLiteral() override;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ Variable::Variable(ProgramID program_id,
|
||||
const Source& source,
|
||||
const Symbol& sym,
|
||||
StorageClass declared_storage_class,
|
||||
sem::Type* declared_type,
|
||||
const sem::Type* declared_type,
|
||||
bool is_const,
|
||||
Expression* constructor,
|
||||
DecorationList decorations)
|
||||
|
||||
@@ -103,7 +103,7 @@ class Variable : public Castable<Variable, Node> {
|
||||
const Source& source,
|
||||
const Symbol& sym,
|
||||
StorageClass declared_storage_class,
|
||||
sem::Type* declared_type,
|
||||
const sem::Type* declared_type,
|
||||
bool is_const,
|
||||
Expression* constructor,
|
||||
DecorationList decorations);
|
||||
@@ -116,7 +116,9 @@ class Variable : public Castable<Variable, Node> {
|
||||
const Symbol& symbol() const { return symbol_; }
|
||||
|
||||
/// @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
|
||||
StorageClass declared_storage_class() const {
|
||||
@@ -175,7 +177,7 @@ class Variable : public Castable<Variable, Node> {
|
||||
|
||||
Symbol const symbol_;
|
||||
// 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_;
|
||||
Expression* const constructor_;
|
||||
DecorationList const decorations_;
|
||||
|
||||
Reference in New Issue
Block a user