Make all ast and sem pointers const

And remove a whole load of const_cast hackery.

Semantic nodes may contain internally mutable fields (although only ever modified during resolving), so these are always passed by `const` pointer.

While all AST nodes are internally immutable, we have decided that pointers to AST nodes should also be marked `const`, for consistency.

There's still a collection of const_cast calls in the Resolver. These will be fixed up in a later change.

Bug: tint:745
Change-Id: I046309b8e586772605fc0fe6b2d27f28806d40ef
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66606
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton 2021-10-19 18:38:54 +00:00 committed by Tint LUCI CQ
parent 7d0fc07b20
commit 8648120bbe
261 changed files with 2441 additions and 2258 deletions

View File

@ -71,7 +71,7 @@ bool MaybeApplyMutation(const tint::Program& program,
tint::CloneContext clone_context(&mutated, &program); tint::CloneContext clone_context(&mutated, &program);
NodeIdMap new_node_id_map; NodeIdMap new_node_id_map;
clone_context.ReplaceAll( clone_context.ReplaceAll(
[&node_id_map, &new_node_id_map, &clone_context](ast::Node* node) { [&node_id_map, &new_node_id_map, &clone_context](const ast::Node* node) {
// Make sure all `tint::ast::` nodes' ids are preserved. // Make sure all `tint::ast::` nodes' ids are preserved.
auto* cloned = tint::As<ast::Node>(node->Clone(&clone_context)); auto* cloned = tint::As<ast::Node>(node->Clone(&clone_context));
new_node_id_map.Add(cloned, node_id_map.GetId(node)); new_node_id_map.Add(cloned, node_id_map.GetId(node));

View File

@ -22,33 +22,29 @@ namespace ast_fuzzer {
NodeIdMap::NodeIdMap() = default; NodeIdMap::NodeIdMap() = default;
NodeIdMap::NodeIdMap(const tint::Program& program) : NodeIdMap() { NodeIdMap::NodeIdMap(const Program& program) : NodeIdMap() {
for (const auto* node : program.ASTNodes().Objects()) { for (const auto* node : program.ASTNodes().Objects()) {
Add(node, TakeFreshId()); Add(node, TakeFreshId());
} }
} }
NodeIdMap::IdType NodeIdMap::GetId(const ast::Node* node) const { NodeIdMap::IdType NodeIdMap::GetId(const ast::Node* node) const {
// Since node is immutable by default, const_cast won't auto it = node_to_id_.find(node);
// modify the node structure.
auto it = node_to_id_.find(const_cast<ast::Node*>(node));
return it == node_to_id_.end() ? 0 : it->second; return it == node_to_id_.end() ? 0 : it->second;
} }
ast::Node* NodeIdMap::GetNode(IdType id) const { const ast::Node* NodeIdMap::GetNode(IdType id) const {
auto it = id_to_node_.find(id); auto it = id_to_node_.find(id);
return it == id_to_node_.end() ? nullptr : it->second; return it == id_to_node_.end() ? nullptr : it->second;
} }
void NodeIdMap::Add(const ast::Node* node, IdType id) { void NodeIdMap::Add(const ast::Node* node, IdType id) {
auto* casted_node = const_cast<ast::Node*>(node); assert(!node_to_id_.count(node) && "The node already exists in the map");
assert(!node_to_id_.count(casted_node) &&
"The node already exists in the map");
assert(IdIsFreshAndValid(id) && "Id already exists in the map or Id is zero"); assert(IdIsFreshAndValid(id) && "Id already exists in the map or Id is zero");
assert(node && "`node` can't be a nullptr"); assert(node && "`node` can't be a nullptr");
node_to_id_[casted_node] = id; node_to_id_[node] = id;
id_to_node_[id] = casted_node; id_to_node_[id] = node;
if (id >= fresh_id_) { if (id >= fresh_id_) {
fresh_id_ = id + 1; fresh_id_ = id + 1;

View File

@ -48,13 +48,13 @@ class NodeIdMap {
/// @brief Initializes this instance with all the nodes in the `program`. /// @brief Initializes this instance with all the nodes in the `program`.
/// @param program - must be valid. /// @param program - must be valid.
explicit NodeIdMap(const tint::Program& program); explicit NodeIdMap(const Program& program);
/// @brief Returns a node for the given `id`. /// @brief Returns a node for the given `id`.
/// @param id - any value is accepted. /// @param id - any value is accepted.
/// @return a pointer to some node if `id` exists in this map. /// @return a pointer to some node if `id` exists in this map.
/// @return `nullptr` otherwise. /// @return `nullptr` otherwise.
ast::Node* GetNode(IdType id) const; const ast::Node* GetNode(IdType id) const;
/// @brief Returns an id of the given `node`. /// @brief Returns an id of the given `node`.
/// @param node - can be a `nullptr`. /// @param node - can be a `nullptr`.
@ -85,8 +85,8 @@ class NodeIdMap {
private: private:
IdType fresh_id_ = 1; IdType fresh_id_ = 1;
std::unordered_map<ast::Node*, IdType> node_to_id_; std::unordered_map<const ast::Node*, IdType> node_to_id_;
std::unordered_map<IdType, ast::Node*> id_to_node_; std::unordered_map<IdType, const ast::Node*> id_to_node_;
}; };
} // namespace ast_fuzzer } // namespace ast_fuzzer

View File

@ -21,7 +21,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Alias);
namespace tint { namespace tint {
namespace ast { namespace ast {
Alias::Alias(ProgramID pid, const Source& src, const Symbol& n, Type* subtype) Alias::Alias(ProgramID pid,
const Source& src,
const Symbol& n,
const Type* subtype)
: Base(pid, src, n), type(subtype) { : Base(pid, src, n), type(subtype) {
TINT_ASSERT(AST, type); TINT_ASSERT(AST, type);
} }
@ -30,7 +33,7 @@ Alias::Alias(Alias&&) = default;
Alias::~Alias() = default; Alias::~Alias() = default;
Alias* Alias::Clone(CloneContext* ctx) const { const Alias* Alias::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 sym = ctx->Clone(name); auto sym = ctx->Clone(name);

View File

@ -30,7 +30,10 @@ class Alias : public Castable<Alias, TypeDecl> {
/// @param src the source of this node /// @param src the source of this node
/// @param name the symbol for the alias /// @param name the symbol for the alias
/// @param subtype the alias'd type /// @param subtype the alias'd type
Alias(ProgramID pid, const Source& src, const Symbol& name, Type* subtype); Alias(ProgramID pid,
const Source& src,
const Symbol& name,
const Type* subtype);
/// Move constructor /// Move constructor
Alias(Alias&&); Alias(Alias&&);
/// Destructor /// Destructor
@ -39,10 +42,10 @@ class Alias : public Castable<Alias, TypeDecl> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
Alias* Clone(CloneContext* ctx) const override; const Alias* Clone(CloneContext* ctx) const override;
/// the alias type /// the alias type
Type* const type; const Type* const type;
}; };
} // namespace ast } // namespace ast

View File

@ -25,13 +25,13 @@ namespace ast {
namespace { namespace {
// Returns the string representation of an array size expression. // Returns the string representation of an array size expression.
std::string SizeExprToString(const ast::Expression* size, std::string SizeExprToString(const Expression* size,
const SymbolTable& symbols) { const SymbolTable& symbols) {
if (auto* ident = size->As<ast::IdentifierExpression>()) { if (auto* ident = size->As<IdentifierExpression>()) {
return symbols.NameFor(ident->symbol); return symbols.NameFor(ident->symbol);
} }
if (auto* scalar = size->As<ast::ScalarConstructorExpression>()) { if (auto* scalar = size->As<ScalarConstructorExpression>()) {
auto* literal = scalar->literal->As<ast::IntLiteral>(); auto* literal = scalar->literal->As<IntLiteral>();
if (literal) { if (literal) {
return std::to_string(literal->ValueAsU32()); return std::to_string(literal->ValueAsU32());
} }
@ -44,9 +44,9 @@ std::string SizeExprToString(const ast::Expression* size,
Array::Array(ProgramID pid, Array::Array(ProgramID pid,
const Source& src, const Source& src,
Type* subtype, const Type* subtype,
ast::Expression* cnt, const Expression* cnt,
ast::DecorationList decos) DecorationList decos)
: Base(pid, src), type(subtype), count(cnt), decorations(decos) {} : Base(pid, src), type(subtype), count(cnt), decorations(decos) {}
Array::Array(Array&&) = default; Array::Array(Array&&) = default;
@ -68,7 +68,7 @@ std::string Array::FriendlyName(const SymbolTable& symbols) const {
return out.str(); return out.str();
} }
Array* Array::Clone(CloneContext* ctx) const { const Array* Array::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);

View File

@ -38,9 +38,9 @@ class Array : public Castable<Array, Type> {
/// @param decorations the array decorations /// @param decorations the array decorations
Array(ProgramID pid, Array(ProgramID pid,
const Source& src, const Source& src,
Type* subtype, const Type* subtype,
ast::Expression* count, const Expression* count,
ast::DecorationList decorations); DecorationList decorations);
/// Move constructor /// Move constructor
Array(Array&&); Array(Array&&);
~Array() override; ~Array() override;
@ -57,16 +57,16 @@ class Array : public Castable<Array, Type> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
Array* Clone(CloneContext* ctx) const override; const Array* Clone(CloneContext* ctx) const override;
/// the array element type /// the array element type
Type* const type; const Type* const type;
/// the array size in elements, or nullptr for a runtime array /// the array size in elements, or nullptr for a runtime array
ast::Expression* const count; const Expression* const count;
/// the array decorations /// the array decorations
ast::DecorationList const decorations; const DecorationList decorations;
}; };
} // namespace ast } // namespace ast

View File

@ -23,8 +23,8 @@ namespace ast {
ArrayAccessorExpression::ArrayAccessorExpression(ProgramID pid, ArrayAccessorExpression::ArrayAccessorExpression(ProgramID pid,
const Source& src, const Source& src,
Expression* arr, const Expression* arr,
Expression* idx) const Expression* idx)
: Base(pid, src), array(arr), index(idx) { : Base(pid, src), array(arr), index(idx) {
TINT_ASSERT(AST, array); TINT_ASSERT(AST, array);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, array, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, array, program_id);
@ -37,7 +37,7 @@ ArrayAccessorExpression::ArrayAccessorExpression(ArrayAccessorExpression&&) =
ArrayAccessorExpression::~ArrayAccessorExpression() = default; ArrayAccessorExpression::~ArrayAccessorExpression() = default;
ArrayAccessorExpression* ArrayAccessorExpression::Clone( const ArrayAccessorExpression* ArrayAccessorExpression::Clone(
CloneContext* ctx) const { 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);

View File

@ -31,8 +31,8 @@ class ArrayAccessorExpression
/// @param idx the index expression /// @param idx the index expression
ArrayAccessorExpression(ProgramID program_id, ArrayAccessorExpression(ProgramID program_id,
const Source& source, const Source& source,
Expression* arr, const Expression* arr,
Expression* idx); const Expression* idx);
/// Move constructor /// Move constructor
ArrayAccessorExpression(ArrayAccessorExpression&&); ArrayAccessorExpression(ArrayAccessorExpression&&);
~ArrayAccessorExpression() override; ~ArrayAccessorExpression() override;
@ -41,13 +41,13 @@ class ArrayAccessorExpression
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
ArrayAccessorExpression* Clone(CloneContext* ctx) const override; const ArrayAccessorExpression* Clone(CloneContext* ctx) const override;
/// the array /// the array
Expression* const array; const Expression* const array;
/// the index expression /// the index expression
Expression* const index; const Expression* const index;
}; };
} // namespace ast } // namespace ast

View File

@ -23,8 +23,8 @@ namespace ast {
AssignmentStatement::AssignmentStatement(ProgramID pid, AssignmentStatement::AssignmentStatement(ProgramID pid,
const Source& src, const Source& src,
Expression* l, const Expression* l,
Expression* r) const Expression* r)
: Base(pid, src), lhs(l), rhs(r) { : Base(pid, src), lhs(l), rhs(r) {
TINT_ASSERT(AST, lhs); TINT_ASSERT(AST, lhs);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id);
@ -36,7 +36,7 @@ AssignmentStatement::AssignmentStatement(AssignmentStatement&&) = default;
AssignmentStatement::~AssignmentStatement() = default; AssignmentStatement::~AssignmentStatement() = default;
AssignmentStatement* AssignmentStatement::Clone(CloneContext* ctx) const { const AssignmentStatement* AssignmentStatement::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* l = ctx->Clone(lhs); auto* l = ctx->Clone(lhs);

View File

@ -31,8 +31,8 @@ class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
/// @param rhs the right side of the expression /// @param rhs the right side of the expression
AssignmentStatement(ProgramID program_id, AssignmentStatement(ProgramID program_id,
const Source& source, const Source& source,
Expression* lhs, const Expression* lhs,
Expression* rhs); const Expression* rhs);
/// Move constructor /// Move constructor
AssignmentStatement(AssignmentStatement&&); AssignmentStatement(AssignmentStatement&&);
~AssignmentStatement() override; ~AssignmentStatement() override;
@ -41,13 +41,13 @@ class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
AssignmentStatement* Clone(CloneContext* ctx) const override; const AssignmentStatement* Clone(CloneContext* ctx) const override;
/// left side expression /// left side expression
Expression* const lhs; const Expression* const lhs;
/// right side expression /// right side expression
Expression* const rhs; const Expression* const rhs;
}; };
} // namespace ast } // namespace ast

View File

@ -21,7 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Atomic);
namespace tint { namespace tint {
namespace ast { namespace ast {
Atomic::Atomic(ProgramID pid, const Source& src, Type* const subtype) Atomic::Atomic(ProgramID pid, const Source& src, const Type* const subtype)
: Base(pid, src), type(subtype) {} : Base(pid, src), type(subtype) {}
std::string Atomic::FriendlyName(const SymbolTable& symbols) const { std::string Atomic::FriendlyName(const SymbolTable& symbols) const {
@ -34,10 +34,10 @@ Atomic::Atomic(Atomic&&) = default;
Atomic::~Atomic() = default; Atomic::~Atomic() = default;
Atomic* Atomic::Clone(CloneContext* ctx) const { const Atomic* Atomic::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(const_cast<Type*>(type)); auto* ty = ctx->Clone(type);
return ctx->dst->create<Atomic>(src, ty); return ctx->dst->create<Atomic>(src, ty);
} }

View File

@ -29,7 +29,7 @@ class Atomic : public Castable<Atomic, Type> {
/// @param pid the identifier of the program that owns this node /// @param pid the identifier of the program that owns this node
/// @param src the source of this node /// @param src the source of this node
/// @param subtype the pointee type /// @param subtype the pointee type
Atomic(ProgramID pid, const Source& src, Type* const subtype); Atomic(ProgramID pid, const Source& src, const Type* const subtype);
/// Move constructor /// Move constructor
Atomic(Atomic&&); Atomic(Atomic&&);
~Atomic() override; ~Atomic() override;
@ -42,10 +42,10 @@ class Atomic : public Castable<Atomic, Type> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
Atomic* Clone(CloneContext* ctx) const override; const Atomic* Clone(CloneContext* ctx) const override;
/// the pointee type /// the pointee type
Type const* const type; const Type* const type;
}; };
} // namespace ast } // namespace ast

View File

@ -24,8 +24,8 @@ namespace ast {
BinaryExpression::BinaryExpression(ProgramID pid, BinaryExpression::BinaryExpression(ProgramID pid,
const Source& src, const Source& src,
BinaryOp o, BinaryOp o,
Expression* l, const Expression* l,
Expression* r) const Expression* r)
: Base(pid, src), op(o), lhs(l), rhs(r) { : Base(pid, src), op(o), lhs(l), rhs(r) {
TINT_ASSERT(AST, lhs); TINT_ASSERT(AST, lhs);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id);
@ -38,7 +38,7 @@ BinaryExpression::BinaryExpression(BinaryExpression&&) = default;
BinaryExpression::~BinaryExpression() = default; BinaryExpression::~BinaryExpression() = default;
BinaryExpression* BinaryExpression::Clone(CloneContext* ctx) const { const BinaryExpression* BinaryExpression::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* l = ctx->Clone(lhs); auto* l = ctx->Clone(lhs);

View File

@ -55,8 +55,8 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
BinaryExpression(ProgramID program_id, BinaryExpression(ProgramID program_id,
const Source& source, const Source& source,
BinaryOp op, BinaryOp op,
Expression* lhs, const Expression* lhs,
Expression* rhs); const Expression* rhs);
/// Move constructor /// Move constructor
BinaryExpression(BinaryExpression&&); BinaryExpression(BinaryExpression&&);
~BinaryExpression() override; ~BinaryExpression() override;
@ -110,14 +110,14 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
BinaryExpression* Clone(CloneContext* ctx) const override; const BinaryExpression* Clone(CloneContext* ctx) const override;
/// the binary op type /// the binary op type
BinaryOp const op; const BinaryOp op;
/// the left side expression /// the left side expression
Expression* const lhs; const Expression* const lhs;
/// the right side expression /// the right side expression
Expression* const rhs; const Expression* const rhs;
}; };
inline bool BinaryExpression::IsArithmetic() const { inline bool BinaryExpression::IsArithmetic() const {

View File

@ -34,7 +34,7 @@ std::string BindingDecoration::Name() const {
return "binding"; return "binding";
} }
BindingDecoration* BindingDecoration::Clone(CloneContext* ctx) const { const BindingDecoration* BindingDecoration::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);
return ctx->dst->create<BindingDecoration>(src, value); return ctx->dst->create<BindingDecoration>(src, value);

View File

@ -39,10 +39,10 @@ class BindingDecoration : public Castable<BindingDecoration, Decoration> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
BindingDecoration* Clone(CloneContext* ctx) const override; const BindingDecoration* Clone(CloneContext* ctx) const override;
/// the binding value /// the binding value
uint32_t const value; const uint32_t value;
}; };
} // namespace ast } // namespace ast

View File

@ -23,8 +23,8 @@ namespace ast {
BitcastExpression::BitcastExpression(ProgramID pid, BitcastExpression::BitcastExpression(ProgramID pid,
const Source& src, const Source& src,
ast::Type* t, const Type* t,
Expression* e) const Expression* e)
: Base(pid, src), type(t), expr(e) { : Base(pid, src), type(t), expr(e) {
TINT_ASSERT(AST, type); TINT_ASSERT(AST, type);
TINT_ASSERT(AST, expr); TINT_ASSERT(AST, expr);
@ -34,7 +34,7 @@ BitcastExpression::BitcastExpression(ProgramID pid,
BitcastExpression::BitcastExpression(BitcastExpression&&) = default; BitcastExpression::BitcastExpression(BitcastExpression&&) = default;
BitcastExpression::~BitcastExpression() = default; BitcastExpression::~BitcastExpression() = default;
BitcastExpression* BitcastExpression::Clone(CloneContext* ctx) const { 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* t = ctx->Clone(type); auto* t = ctx->Clone(type);

View File

@ -33,8 +33,8 @@ 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,
ast::Type* type, const Type* type,
Expression* expr); const Expression* expr);
/// Move constructor /// Move constructor
BitcastExpression(BitcastExpression&&); BitcastExpression(BitcastExpression&&);
~BitcastExpression() override; ~BitcastExpression() override;
@ -43,12 +43,12 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
BitcastExpression* Clone(CloneContext* ctx) const override; const BitcastExpression* Clone(CloneContext* ctx) const override;
/// the target cast type /// the target cast type
ast::Type* const type; const Type* const type;
/// the expression /// the expression
Expression* const expr; const Expression* const expr;
}; };
} // namespace ast } // namespace ast

View File

@ -35,7 +35,7 @@ BlockStatement::BlockStatement(BlockStatement&&) = default;
BlockStatement::~BlockStatement() = default; BlockStatement::~BlockStatement() = default;
BlockStatement* BlockStatement::Clone(CloneContext* ctx) const { const BlockStatement* BlockStatement::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 stmts = ctx->Clone(statements); auto stmts = ctx->Clone(statements);

View File

@ -40,7 +40,7 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
bool Empty() const { return statements.empty(); } bool Empty() const { return statements.empty(); }
/// @returns the last statement in the block or nullptr if block empty /// @returns the last statement in the block or nullptr if block empty
Statement* Last() const { const Statement* Last() const {
return statements.empty() ? nullptr : statements.back(); return statements.empty() ? nullptr : statements.back();
} }
@ -48,10 +48,10 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
BlockStatement* Clone(CloneContext* ctx) const override; const BlockStatement* Clone(CloneContext* ctx) const override;
/// the statement list /// the statement list
StatementList const statements; const StatementList statements;
}; };
} // namespace ast } // namespace ast

View File

@ -31,7 +31,7 @@ std::string Bool::FriendlyName(const SymbolTable&) const {
return "bool"; return "bool";
} }
Bool* Bool::Clone(CloneContext* ctx) const { const Bool* Bool::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source); auto src = ctx->Clone(source);
return ctx->dst->create<Bool>(src); return ctx->dst->create<Bool>(src);
} }

View File

@ -47,7 +47,7 @@ class Bool : public Castable<Bool, Type> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
Bool* Clone(CloneContext* ctx) const override; const Bool* Clone(CloneContext* ctx) const override;
}; };
} // namespace ast } // namespace ast

View File

@ -26,7 +26,7 @@ BoolLiteral::BoolLiteral(ProgramID pid, const Source& src, bool val)
BoolLiteral::~BoolLiteral() = default; BoolLiteral::~BoolLiteral() = default;
BoolLiteral* BoolLiteral::Clone(CloneContext* ctx) const { const BoolLiteral* BoolLiteral::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);
return ctx->dst->create<BoolLiteral>(src, value); return ctx->dst->create<BoolLiteral>(src, value);

View File

@ -32,15 +32,14 @@ class BoolLiteral : public Castable<BoolLiteral, Literal> {
BoolLiteral(ProgramID pid, const Source& src, bool value); BoolLiteral(ProgramID pid, const Source& src, bool value);
~BoolLiteral() override; ~BoolLiteral() override;
/// Clones this node and all transitive child nodes using the `CloneContext` /// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
BoolLiteral* Clone(CloneContext* ctx) const override; const BoolLiteral* Clone(CloneContext* ctx) const override;
/// The boolean literal value /// The boolean literal value
bool const value; const bool value;
}; };
} // namespace ast } // namespace ast

View File

@ -28,7 +28,7 @@ BreakStatement::BreakStatement(BreakStatement&&) = default;
BreakStatement::~BreakStatement() = default; BreakStatement::~BreakStatement() = default;
BreakStatement* BreakStatement::Clone(CloneContext* ctx) const { const BreakStatement* BreakStatement::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);
return ctx->dst->create<BreakStatement>(src); return ctx->dst->create<BreakStatement>(src);

View File

@ -35,7 +35,7 @@ class BreakStatement : public Castable<BreakStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
BreakStatement* Clone(CloneContext* ctx) const override; const BreakStatement* Clone(CloneContext* ctx) const override;
}; };
} // namespace ast } // namespace ast

View File

@ -34,7 +34,7 @@ std::string BuiltinDecoration::Name() const {
return "builtin"; return "builtin";
} }
BuiltinDecoration* BuiltinDecoration::Clone(CloneContext* ctx) const { const BuiltinDecoration* BuiltinDecoration::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);
return ctx->dst->create<BuiltinDecoration>(src, builtin); return ctx->dst->create<BuiltinDecoration>(src, builtin);

View File

@ -40,10 +40,10 @@ class BuiltinDecoration : public Castable<BuiltinDecoration, Decoration> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
BuiltinDecoration* Clone(CloneContext* ctx) const override; const BuiltinDecoration* Clone(CloneContext* ctx) const override;
/// The builtin value /// The builtin value
Builtin const builtin; const Builtin builtin;
}; };
} // namespace ast } // namespace ast

View File

@ -23,7 +23,7 @@ namespace ast {
CallExpression::CallExpression(ProgramID pid, CallExpression::CallExpression(ProgramID pid,
const Source& src, const Source& src,
IdentifierExpression* fn, const IdentifierExpression* fn,
ExpressionList a) ExpressionList a)
: Base(pid, src), func(fn), args(a) { : Base(pid, src), func(fn), args(a) {
TINT_ASSERT(AST, func); TINT_ASSERT(AST, func);
@ -38,7 +38,7 @@ CallExpression::CallExpression(CallExpression&&) = default;
CallExpression::~CallExpression() = default; CallExpression::~CallExpression() = default;
CallExpression* CallExpression::Clone(CloneContext* ctx) const { const CallExpression* CallExpression::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* fn = ctx->Clone(func); auto* fn = ctx->Clone(func);

View File

@ -33,7 +33,7 @@ class CallExpression : public Castable<CallExpression, Expression> {
/// @param args the arguments /// @param args the arguments
CallExpression(ProgramID program_id, CallExpression(ProgramID program_id,
const Source& source, const Source& source,
IdentifierExpression* func, const IdentifierExpression* func,
ExpressionList args); ExpressionList args);
/// Move constructor /// Move constructor
CallExpression(CallExpression&&); CallExpression(CallExpression&&);
@ -43,12 +43,12 @@ class CallExpression : public Castable<CallExpression, Expression> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
CallExpression* Clone(CloneContext* ctx) const override; const CallExpression* Clone(CloneContext* ctx) const override;
/// The target function /// The target function
IdentifierExpression* const func; const IdentifierExpression* const func;
/// The arguments /// The arguments
ExpressionList const args; const ExpressionList args;
}; };
} // namespace ast } // namespace ast

View File

@ -23,7 +23,7 @@ namespace ast {
CallStatement::CallStatement(ProgramID pid, CallStatement::CallStatement(ProgramID pid,
const Source& src, const Source& src,
CallExpression* call) const CallExpression* call)
: Base(pid, src), expr(call) { : Base(pid, src), expr(call) {
TINT_ASSERT(AST, expr); TINT_ASSERT(AST, expr);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id);
@ -33,7 +33,7 @@ CallStatement::CallStatement(CallStatement&&) = default;
CallStatement::~CallStatement() = default; CallStatement::~CallStatement() = default;
CallStatement* CallStatement::Clone(CloneContext* ctx) const { const CallStatement* CallStatement::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* call = ctx->Clone(expr); auto* call = ctx->Clone(expr);

View File

@ -28,7 +28,7 @@ class CallStatement : public Castable<CallStatement, Statement> {
/// @param pid the identifier of the program that owns this node /// @param pid the identifier of the program that owns this node
/// @param src the source of this node for the statement /// @param src the source of this node for the statement
/// @param call the function /// @param call the function
CallStatement(ProgramID pid, const Source& src, CallExpression* call); CallStatement(ProgramID pid, const Source& src, const CallExpression* call);
/// Move constructor /// Move constructor
CallStatement(CallStatement&&); CallStatement(CallStatement&&);
~CallStatement() override; ~CallStatement() override;
@ -37,10 +37,10 @@ class CallStatement : public Castable<CallStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
CallStatement* Clone(CloneContext* ctx) const override; const CallStatement* Clone(CloneContext* ctx) const override;
/// The call expression /// The call expression
CallExpression* const expr; const CallExpression* const expr;
}; };
} // namespace ast } // namespace ast

View File

@ -24,7 +24,7 @@ namespace ast {
CaseStatement::CaseStatement(ProgramID pid, CaseStatement::CaseStatement(ProgramID pid,
const Source& src, const Source& src,
CaseSelectorList s, CaseSelectorList s,
BlockStatement* b) const BlockStatement* b)
: Base(pid, src), selectors(s), body(b) { : Base(pid, src), selectors(s), body(b) {
TINT_ASSERT(AST, body); TINT_ASSERT(AST, body);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
@ -38,7 +38,7 @@ CaseStatement::CaseStatement(CaseStatement&&) = default;
CaseStatement::~CaseStatement() = default; CaseStatement::~CaseStatement() = default;
CaseStatement* CaseStatement::Clone(CloneContext* ctx) const { const CaseStatement* CaseStatement::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 sel = ctx->Clone(selectors); auto sel = ctx->Clone(selectors);

View File

@ -24,7 +24,7 @@ namespace tint {
namespace ast { namespace ast {
/// A list of case literals /// A list of case literals
using CaseSelectorList = std::vector<IntLiteral*>; using CaseSelectorList = std::vector<const IntLiteral*>;
/// A case statement /// A case statement
class CaseStatement : public Castable<CaseStatement, Statement> { class CaseStatement : public Castable<CaseStatement, Statement> {
@ -37,7 +37,7 @@ class CaseStatement : public Castable<CaseStatement, Statement> {
CaseStatement(ProgramID pid, CaseStatement(ProgramID pid,
const Source& src, const Source& src,
CaseSelectorList selectors, CaseSelectorList selectors,
BlockStatement* body); const BlockStatement* body);
/// Move constructor /// Move constructor
CaseStatement(CaseStatement&&); CaseStatement(CaseStatement&&);
~CaseStatement() override; ~CaseStatement() override;
@ -49,17 +49,17 @@ class CaseStatement : public Castable<CaseStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
CaseStatement* Clone(CloneContext* ctx) const override; const CaseStatement* Clone(CloneContext* ctx) const override;
/// The case selectors, empty if none set /// The case selectors, empty if none set
CaseSelectorList const selectors; const CaseSelectorList selectors;
/// The case body /// The case body
BlockStatement* const body; const BlockStatement* const body;
}; };
/// A list of case statements /// A list of case statements
using CaseStatementList = std::vector<CaseStatement*>; using CaseStatementList = std::vector<const CaseStatement*>;
} // namespace ast } // namespace ast
} // namespace tint } // namespace tint

View File

@ -28,7 +28,7 @@ ContinueStatement::ContinueStatement(ContinueStatement&&) = default;
ContinueStatement::~ContinueStatement() = default; ContinueStatement::~ContinueStatement() = default;
ContinueStatement* ContinueStatement::Clone(CloneContext* ctx) const { const ContinueStatement* ContinueStatement::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);
return ctx->dst->create<ContinueStatement>(src); return ctx->dst->create<ContinueStatement>(src);

View File

@ -35,7 +35,7 @@ class ContinueStatement : public Castable<ContinueStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
ContinueStatement* Clone(CloneContext* ctx) const override; const ContinueStatement* Clone(CloneContext* ctx) const override;
}; };
} // namespace ast } // namespace ast

View File

@ -39,7 +39,7 @@ class Decoration : public Castable<Decoration, Node> {
}; };
/// A list of decorations /// A list of decorations
using DecorationList = std::vector<Decoration*>; using DecorationList = std::vector<const Decoration*>;
/// @param decorations the list of decorations to search /// @param decorations the list of decorations to search
/// @returns true if `decorations` includes a decoration of type `T` /// @returns true if `decorations` includes a decoration of type `T`
@ -56,7 +56,7 @@ bool HasDecoration(const DecorationList& decorations) {
/// @param decorations the list of decorations to search /// @param decorations the list of decorations to search
/// @returns a pointer to `T` from `decorations` if found, otherwise nullptr. /// @returns a pointer to `T` from `decorations` if found, otherwise nullptr.
template <typename T> template <typename T>
T* GetDecoration(const DecorationList& decorations) { const T* GetDecoration(const DecorationList& decorations) {
for (auto* deco : decorations) { for (auto* deco : decorations) {
if (deco->Is<T>()) { if (deco->Is<T>()) {
return deco->As<T>(); return deco->As<T>();

View File

@ -46,7 +46,7 @@ std::string DepthMultisampledTexture::FriendlyName(const SymbolTable&) const {
return out.str(); return out.str();
} }
DepthMultisampledTexture* DepthMultisampledTexture::Clone( const DepthMultisampledTexture* DepthMultisampledTexture::Clone(
CloneContext* ctx) const { CloneContext* ctx) const {
auto src = ctx->Clone(source); auto src = ctx->Clone(source);
return ctx->dst->create<DepthMultisampledTexture>(src, dim); return ctx->dst->create<DepthMultisampledTexture>(src, dim);

View File

@ -45,7 +45,7 @@ class DepthMultisampledTexture
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
DepthMultisampledTexture* Clone(CloneContext* ctx) const override; const DepthMultisampledTexture* Clone(CloneContext* ctx) const override;
}; };
} // namespace ast } // namespace ast

View File

@ -44,7 +44,7 @@ std::string DepthTexture::FriendlyName(const SymbolTable&) const {
return out.str(); return out.str();
} }
DepthTexture* DepthTexture::Clone(CloneContext* ctx) const { const DepthTexture* DepthTexture::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source); auto src = ctx->Clone(source);
return ctx->dst->create<DepthTexture>(src, dim); return ctx->dst->create<DepthTexture>(src, dim);
} }

View File

@ -42,7 +42,7 @@ class DepthTexture : public Castable<DepthTexture, Texture> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
DepthTexture* Clone(CloneContext* ctx) const override; const DepthTexture* Clone(CloneContext* ctx) const override;
}; };
} // namespace ast } // namespace ast

View File

@ -47,7 +47,7 @@ std::string DisableValidationDecoration::InternalName() const {
return "<invalid>"; return "<invalid>";
} }
DisableValidationDecoration* DisableValidationDecoration::Clone( const DisableValidationDecoration* DisableValidationDecoration::Clone(
CloneContext* ctx) const { CloneContext* ctx) const {
return ctx->dst->ASTNodes().Create<DisableValidationDecoration>( return ctx->dst->ASTNodes().Create<DisableValidationDecoration>(
ctx->dst->ID(), validation); ctx->dst->ID(), validation);

View File

@ -71,10 +71,10 @@ class DisableValidationDecoration
/// Performs a deep clone of this object using the CloneContext `ctx`. /// Performs a deep clone of this object using the CloneContext `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned object /// @return the newly cloned object
DisableValidationDecoration* Clone(CloneContext* ctx) const override; const DisableValidationDecoration* Clone(CloneContext* ctx) const override;
/// The validation that this decoration disables /// The validation that this decoration disables
DisabledValidation const validation; const DisabledValidation validation;
}; };
} // namespace ast } // namespace ast

View File

@ -28,7 +28,7 @@ DiscardStatement::DiscardStatement(DiscardStatement&&) = default;
DiscardStatement::~DiscardStatement() = default; DiscardStatement::~DiscardStatement() = default;
DiscardStatement* DiscardStatement::Clone(CloneContext* ctx) const { const DiscardStatement* DiscardStatement::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);
return ctx->dst->create<DiscardStatement>(src); return ctx->dst->create<DiscardStatement>(src);

View File

@ -35,7 +35,7 @@ class DiscardStatement : public Castable<DiscardStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
DiscardStatement* Clone(CloneContext* ctx) const override; const DiscardStatement* Clone(CloneContext* ctx) const override;
}; };
} // namespace ast } // namespace ast

View File

@ -23,8 +23,8 @@ namespace ast {
ElseStatement::ElseStatement(ProgramID pid, ElseStatement::ElseStatement(ProgramID pid,
const Source& src, const Source& src,
Expression* cond, const Expression* cond,
BlockStatement* b) const BlockStatement* b)
: Base(pid, src), condition(cond), body(b) { : Base(pid, src), condition(cond), body(b) {
TINT_ASSERT(AST, body); TINT_ASSERT(AST, body);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
@ -35,7 +35,7 @@ ElseStatement::ElseStatement(ElseStatement&&) = default;
ElseStatement::~ElseStatement() = default; ElseStatement::~ElseStatement() = default;
ElseStatement* ElseStatement::Clone(CloneContext* ctx) const { const ElseStatement* ElseStatement::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* cond = ctx->Clone(condition); auto* cond = ctx->Clone(condition);

View File

@ -33,8 +33,8 @@ class ElseStatement : public Castable<ElseStatement, Statement> {
/// @param body the else body /// @param body the else body
ElseStatement(ProgramID pid, ElseStatement(ProgramID pid,
const Source& src, const Source& src,
Expression* condition, const Expression* condition,
BlockStatement* body); const BlockStatement* body);
/// Move constructor /// Move constructor
ElseStatement(ElseStatement&&); ElseStatement(ElseStatement&&);
~ElseStatement() override; ~ElseStatement() override;
@ -43,17 +43,17 @@ class ElseStatement : public Castable<ElseStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
ElseStatement* Clone(CloneContext* ctx) const override; const ElseStatement* Clone(CloneContext* ctx) const override;
/// The else condition or nullptr if none set /// The else condition or nullptr if none set
Expression* const condition; const Expression* const condition;
/// The else body /// The else body
BlockStatement* const body; const BlockStatement* const body;
}; };
/// A list of else statements /// A list of else statements
using ElseStatementList = std::vector<ElseStatement*>; using ElseStatementList = std::vector<const ElseStatement*>;
} // namespace ast } // namespace ast
} // namespace tint } // namespace tint

View File

@ -39,7 +39,7 @@ class Expression : public Castable<Expression, Node> {
}; };
/// A list of expressions /// A list of expressions
using ExpressionList = std::vector<Expression*>; using ExpressionList = std::vector<const Expression*>;
} // namespace ast } // namespace ast
} // namespace tint } // namespace tint

View File

@ -33,7 +33,7 @@ std::string ExternalTexture::FriendlyName(const SymbolTable&) const {
return "texture_external"; return "texture_external";
} }
ExternalTexture* ExternalTexture::Clone(CloneContext* ctx) const { const ExternalTexture* ExternalTexture::Clone(CloneContext* ctx) const {
return ctx->dst->create<ExternalTexture>(); return ctx->dst->create<ExternalTexture>();
} }

View File

@ -42,7 +42,7 @@ class ExternalTexture : public Castable<ExternalTexture, Texture> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
ExternalTexture* Clone(CloneContext* ctx) const override; const ExternalTexture* Clone(CloneContext* ctx) const override;
}; };
} // namespace ast } // namespace ast

View File

@ -31,7 +31,7 @@ std::string F32::FriendlyName(const SymbolTable&) const {
return "f32"; return "f32";
} }
F32* F32::Clone(CloneContext* ctx) const { const F32* F32::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source); auto src = ctx->Clone(source);
return ctx->dst->create<F32>(src); return ctx->dst->create<F32>(src);
} }

View File

@ -41,7 +41,7 @@ class F32 : public Castable<F32, Type> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
F32* Clone(CloneContext* ctx) const override; const F32* Clone(CloneContext* ctx) const override;
}; };
} // namespace ast } // namespace ast

View File

@ -28,7 +28,8 @@ FallthroughStatement::FallthroughStatement(FallthroughStatement&&) = default;
FallthroughStatement::~FallthroughStatement() = default; FallthroughStatement::~FallthroughStatement() = default;
FallthroughStatement* FallthroughStatement::Clone(CloneContext* ctx) const { const FallthroughStatement* FallthroughStatement::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);
return ctx->dst->create<FallthroughStatement>(src); return ctx->dst->create<FallthroughStatement>(src);

View File

@ -35,7 +35,7 @@ class FallthroughStatement : public Castable<FallthroughStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
FallthroughStatement* Clone(CloneContext* ctx) const override; const FallthroughStatement* Clone(CloneContext* ctx) const override;
}; };
} // namespace ast } // namespace ast

View File

@ -28,7 +28,7 @@ FloatLiteral::FloatLiteral(ProgramID pid, const Source& src, float val)
FloatLiteral::~FloatLiteral() = default; FloatLiteral::~FloatLiteral() = default;
FloatLiteral* FloatLiteral::Clone(CloneContext* ctx) const { const FloatLiteral* FloatLiteral::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);
return ctx->dst->create<FloatLiteral>(src, value); return ctx->dst->create<FloatLiteral>(src, value);

View File

@ -36,10 +36,10 @@ class FloatLiteral : public Castable<FloatLiteral, Literal> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
FloatLiteral* Clone(CloneContext* ctx) const override; const FloatLiteral* Clone(CloneContext* ctx) const override;
/// The float literal value /// The float literal value
float const value; const float value;
}; };
} // namespace ast } // namespace ast

View File

@ -23,10 +23,10 @@ namespace ast {
ForLoopStatement::ForLoopStatement(ProgramID pid, ForLoopStatement::ForLoopStatement(ProgramID pid,
const Source& src, const Source& src,
Statement* init, const Statement* init,
Expression* cond, const Expression* cond,
Statement* cont, const Statement* cont,
BlockStatement* b) const BlockStatement* b)
: Base(pid, src), : Base(pid, src),
initializer(init), initializer(init),
condition(cond), condition(cond),
@ -44,7 +44,7 @@ ForLoopStatement::ForLoopStatement(ForLoopStatement&&) = default;
ForLoopStatement::~ForLoopStatement() = default; ForLoopStatement::~ForLoopStatement() = default;
ForLoopStatement* ForLoopStatement::Clone(CloneContext* ctx) const { const ForLoopStatement* ForLoopStatement::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);

View File

@ -33,11 +33,11 @@ class ForLoopStatement : public Castable<ForLoopStatement, Statement> {
/// @param continuing the optional continuing statement /// @param continuing the optional continuing statement
/// @param body the loop body /// @param body the loop body
ForLoopStatement(ProgramID program_id, ForLoopStatement(ProgramID program_id,
const Source& source, Source const& source,
Statement* initializer, const Statement* initializer,
Expression* condition, const Expression* condition,
Statement* continuing, const Statement* continuing,
BlockStatement* body); const BlockStatement* body);
/// Move constructor /// Move constructor
ForLoopStatement(ForLoopStatement&&); ForLoopStatement(ForLoopStatement&&);
~ForLoopStatement() override; ~ForLoopStatement() override;
@ -46,19 +46,19 @@ class ForLoopStatement : public Castable<ForLoopStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
ForLoopStatement* Clone(CloneContext* ctx) const override; const ForLoopStatement* Clone(CloneContext* ctx) const override;
/// The initializer statement /// The initializer statement
Statement* const initializer; const Statement* const initializer;
/// The condition expression /// The condition expression
Expression* const condition; const Expression* const condition;
/// The continuing statement /// The continuing statement
Statement* const continuing; const Statement* const continuing;
/// The loop body block /// The loop body block
BlockStatement* const body; const BlockStatement* const body;
}; };
} // namespace ast } // namespace ast

View File

@ -27,8 +27,8 @@ Function::Function(ProgramID pid,
const Source& src, const Source& src,
Symbol sym, Symbol sym,
VariableList parameters, VariableList parameters,
ast::Type* return_ty, const Type* return_ty,
BlockStatement* b, const BlockStatement* b,
DecorationList decos, DecorationList decos,
DecorationList return_type_decos) DecorationList return_type_decos)
: Base(pid, src), : Base(pid, src),
@ -65,7 +65,7 @@ PipelineStage Function::PipelineStage() const {
return PipelineStage::kNone; return PipelineStage::kNone;
} }
Function* Function::Clone(CloneContext* ctx) const { const Function* Function::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 sym = ctx->Clone(symbol); auto sym = ctx->Clone(symbol);
@ -77,7 +77,7 @@ Function* Function::Clone(CloneContext* ctx) const {
return ctx->dst->create<Function>(src, sym, p, ret, b, decos, ret_decos); return ctx->dst->create<Function>(src, sym, p, ret, b, decos, ret_decos);
} }
Function* FunctionList::Find(Symbol sym) const { const Function* FunctionList::Find(Symbol sym) const {
for (auto* func : *this) { for (auto* func : *this) {
if (func->symbol == sym) { if (func->symbol == sym) {
return func; return func;
@ -86,7 +86,7 @@ Function* FunctionList::Find(Symbol sym) const {
return nullptr; return nullptr;
} }
Function* FunctionList::Find(Symbol sym, PipelineStage stage) const { const Function* FunctionList::Find(Symbol sym, PipelineStage stage) const {
for (auto* func : *this) { for (auto* func : *this) {
if (func->symbol == sym && func->PipelineStage() == stage) { if (func->symbol == sym && func->PipelineStage() == stage) {
return func; return func;

View File

@ -48,8 +48,8 @@ class Function : public Castable<Function, Node> {
const Source& source, const Source& source,
Symbol symbol, Symbol symbol,
VariableList params, VariableList params,
ast::Type* return_type, const Type* return_type,
BlockStatement* body, const BlockStatement* body,
DecorationList decorations, DecorationList decorations,
DecorationList return_type_decorations); DecorationList return_type_decorations);
/// Move constructor /// Move constructor
@ -67,44 +67,44 @@ class Function : public Castable<Function, Node> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
Function* Clone(CloneContext* ctx) const override; const Function* Clone(CloneContext* ctx) const override;
/// The function symbol /// The function symbol
Symbol const symbol; const Symbol symbol;
/// The function params /// The function params
VariableList const params; const VariableList params;
/// The function return type /// The function return type
ast::Type* const return_type; const Type* const return_type;
/// The function body /// The function body
BlockStatement* const body; const BlockStatement* const body;
/// The decorations attached to this function /// The decorations attached to this function
DecorationList const decorations; const DecorationList decorations;
/// The decorations attached to the function return type. /// The decorations attached to the function return type.
DecorationList const return_type_decorations; const DecorationList return_type_decorations;
}; };
/// A list of functions /// A list of functions
class FunctionList : public std::vector<Function*> { class FunctionList : public std::vector<const Function*> {
public: public:
/// Appends f to the end of the list /// Appends f to the end of the list
/// @param f the function to append to this list /// @param f the function to append to this list
void Add(Function* f) { this->emplace_back(f); } void Add(const Function* f) { this->emplace_back(f); }
/// Returns the function with the given name /// Returns the function with the given name
/// @param sym the function symbol to search for /// @param sym the function symbol to search for
/// @returns the associated function or nullptr if none exists /// @returns the associated function or nullptr if none exists
Function* Find(Symbol sym) const; const Function* Find(Symbol sym) const;
/// Returns the function with the given name /// Returns the function with the given name
/// @param sym the function symbol to search for /// @param sym the function symbol to search for
/// @param stage the pipeline stage /// @param stage the pipeline stage
/// @returns the associated function or nullptr if none exists /// @returns the associated function or nullptr if none exists
Function* Find(Symbol sym, PipelineStage stage) const; const Function* Find(Symbol sym, PipelineStage stage) const;
/// @param stage the pipeline stage /// @param stage the pipeline stage
/// @returns true if the Builder contains an entrypoint function with /// @returns true if the Builder contains an entrypoint function with

View File

@ -32,7 +32,7 @@ std::string GroupDecoration::Name() const {
return "group"; return "group";
} }
GroupDecoration* GroupDecoration::Clone(CloneContext* ctx) const { const GroupDecoration* GroupDecoration::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);
return ctx->dst->create<GroupDecoration>(src, value); return ctx->dst->create<GroupDecoration>(src, value);

View File

@ -39,10 +39,10 @@ class GroupDecoration : public Castable<GroupDecoration, Decoration> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
GroupDecoration* Clone(CloneContext* ctx) const override; const GroupDecoration* Clone(CloneContext* ctx) const override;
/// The group value /// The group value
uint32_t const value; const uint32_t value;
}; };
} // namespace ast } // namespace ast

View File

@ -31,7 +31,7 @@ std::string I32::FriendlyName(const SymbolTable&) const {
return "i32"; return "i32";
} }
I32* I32::Clone(CloneContext* ctx) const { const I32* I32::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source); auto src = ctx->Clone(source);
return ctx->dst->create<I32>(src); return ctx->dst->create<I32>(src);
} }

View File

@ -41,7 +41,7 @@ class I32 : public Castable<I32, Type> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
I32* Clone(CloneContext* ctx) const override; const I32* Clone(CloneContext* ctx) const override;
}; };
} // namespace ast } // namespace ast

View File

@ -33,7 +33,8 @@ IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default;
IdentifierExpression::~IdentifierExpression() = default; IdentifierExpression::~IdentifierExpression() = default;
IdentifierExpression* IdentifierExpression::Clone(CloneContext* ctx) const { const IdentifierExpression* IdentifierExpression::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 sym = ctx->Clone(symbol); auto sym = ctx->Clone(symbol);

View File

@ -36,10 +36,10 @@ class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
IdentifierExpression* Clone(CloneContext* ctx) const override; const IdentifierExpression* Clone(CloneContext* ctx) const override;
/// The symbol for the identifier /// The symbol for the identifier
Symbol const symbol; const Symbol symbol;
}; };
} // namespace ast } // namespace ast

View File

@ -23,8 +23,8 @@ namespace ast {
IfStatement::IfStatement(ProgramID pid, IfStatement::IfStatement(ProgramID pid,
const Source& src, const Source& src,
Expression* cond, const Expression* cond,
BlockStatement* b, const BlockStatement* b,
ElseStatementList else_stmts) ElseStatementList else_stmts)
: Base(pid, src), : Base(pid, src),
condition(cond), condition(cond),
@ -44,7 +44,7 @@ IfStatement::IfStatement(IfStatement&&) = default;
IfStatement::~IfStatement() = default; IfStatement::~IfStatement() = default;
IfStatement* IfStatement::Clone(CloneContext* ctx) const { const IfStatement* IfStatement::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* cond = ctx->Clone(condition); auto* cond = ctx->Clone(condition);

View File

@ -33,8 +33,8 @@ class IfStatement : public Castable<IfStatement, Statement> {
/// @param else_stmts the else statements /// @param else_stmts the else statements
IfStatement(ProgramID pid, IfStatement(ProgramID pid,
const Source& src, const Source& src,
Expression* condition, const Expression* condition,
BlockStatement* body, const BlockStatement* body,
ElseStatementList else_stmts); ElseStatementList else_stmts);
/// Move constructor /// Move constructor
IfStatement(IfStatement&&); IfStatement(IfStatement&&);
@ -44,16 +44,16 @@ class IfStatement : public Castable<IfStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
IfStatement* Clone(CloneContext* ctx) const override; const IfStatement* Clone(CloneContext* ctx) const override;
/// The if condition or nullptr if none set /// The if condition or nullptr if none set
Expression* const condition; const Expression* const condition;
/// The if body /// The if body
BlockStatement* const body; const BlockStatement* const body;
/// The else statements /// The else statements
ElseStatementList const else_statements; const ElseStatementList else_statements;
}; };
} // namespace ast } // namespace ast

View File

@ -19,8 +19,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IntLiteral);
namespace tint { namespace tint {
namespace ast { namespace ast {
IntLiteral::IntLiteral(ProgramID pid, const Source& src) IntLiteral::IntLiteral(ProgramID pid, const Source& src) : Base(pid, src) {}
: Base(pid, src) {}
IntLiteral::~IntLiteral() = default; IntLiteral::~IntLiteral() = default;

View File

@ -35,7 +35,8 @@ std::string InterpolateDecoration::Name() const {
return "interpolate"; return "interpolate";
} }
InterpolateDecoration* InterpolateDecoration::Clone(CloneContext* ctx) const { const InterpolateDecoration* InterpolateDecoration::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);
return ctx->dst->create<InterpolateDecoration>(src, type, sampling); return ctx->dst->create<InterpolateDecoration>(src, type, sampling);

View File

@ -51,13 +51,13 @@ class InterpolateDecoration
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
InterpolateDecoration* Clone(CloneContext* ctx) const override; const InterpolateDecoration* Clone(CloneContext* ctx) const override;
/// The interpolation type /// The interpolation type
InterpolationType const type; const InterpolationType type;
/// The interpolation sampling /// The interpolation sampling
InterpolationSampling const sampling; const InterpolationSampling sampling;
}; };
/// @param out the std::ostream to write to /// @param out the std::ostream to write to

View File

@ -134,7 +134,7 @@ std::ostream& operator<<(std::ostream& out, const TextureOverloadCase& data) {
return out; return out;
} }
ast::Type* TextureOverloadCase::BuildResultVectorComponentType( const ast::Type* TextureOverloadCase::BuildResultVectorComponentType(
ProgramBuilder* b) const { ProgramBuilder* b) const {
switch (texture_data_type) { switch (texture_data_type) {
case ast::intrinsic::test::TextureDataType::kF32: case ast::intrinsic::test::TextureDataType::kF32:
@ -149,7 +149,7 @@ ast::Type* TextureOverloadCase::BuildResultVectorComponentType(
return {}; return {};
} }
ast::Variable* TextureOverloadCase::BuildTextureVariable( const ast::Variable* TextureOverloadCase::BuildTextureVariable(
ProgramBuilder* b) const { ProgramBuilder* b) const {
DecorationList decos = { DecorationList decos = {
b->create<ast::GroupDecoration>(0), b->create<ast::GroupDecoration>(0),
@ -188,7 +188,7 @@ ast::Variable* TextureOverloadCase::BuildTextureVariable(
return nullptr; return nullptr;
} }
ast::Variable* TextureOverloadCase::BuildSamplerVariable( const ast::Variable* TextureOverloadCase::BuildSamplerVariable(
ProgramBuilder* b) const { ProgramBuilder* b) const {
DecorationList decos = { DecorationList decos = {
b->create<ast::GroupDecoration>(0), b->create<ast::GroupDecoration>(0),

View File

@ -205,22 +205,23 @@ struct TextureOverloadCase {
/// @param builder the AST builder used for the test /// @param builder the AST builder used for the test
/// @returns the vector component type of the texture function return value /// @returns the vector component type of the texture function return value
ast::Type* BuildResultVectorComponentType(ProgramBuilder* builder) const; const ast::Type* BuildResultVectorComponentType(
ProgramBuilder* builder) const;
/// @param builder the AST builder used for the test /// @param builder the AST builder used for the test
/// @returns a variable holding the test texture, automatically registered as /// @returns a variable holding the test texture, automatically registered as
/// a global variable. /// a global variable.
ast::Variable* BuildTextureVariable(ProgramBuilder* builder) const; const ast::Variable* BuildTextureVariable(ProgramBuilder* builder) const;
/// @param builder the AST builder used for the test /// @param builder the AST builder used for the test
/// @returns a Variable holding the test sampler, automatically registered as /// @returns a Variable holding the test sampler, automatically registered as
/// a global variable. /// a global variable.
ast::Variable* BuildSamplerVariable(ProgramBuilder* builder) const; const ast::Variable* BuildSamplerVariable(ProgramBuilder* builder) const;
/// The enumerator for this overload /// The enumerator for this overload
ValidTextureOverload const overload; const ValidTextureOverload overload;
/// A human readable description of the overload /// A human readable description of the overload
const char* const description; const char* const description;
/// The texture kind for the texture parameter /// The texture kind for the texture parameter
TextureKind const texture_kind; const TextureKind texture_kind;
/// The sampler kind for the sampler parameter /// The sampler kind for the sampler parameter
/// Used only when texture_kind is not kStorage /// Used only when texture_kind is not kStorage
ast::SamplerKind const sampler_kind = ast::SamplerKind::kSampler; ast::SamplerKind const sampler_kind = ast::SamplerKind::kSampler;
@ -233,7 +234,7 @@ struct TextureOverloadCase {
/// The dimensions of the texture parameter /// The dimensions of the texture parameter
ast::TextureDimension const texture_dimension; ast::TextureDimension const texture_dimension;
/// The data type of the texture parameter /// The data type of the texture parameter
TextureDataType const texture_data_type; const TextureDataType texture_data_type;
/// Name of the function. e.g. `textureSample`, `textureSampleGrad`, etc /// Name of the function. e.g. `textureSample`, `textureSampleGrad`, etc
const char* const function; const char* const function;
/// A function that builds the AST arguments for the overload /// A function that builds the AST arguments for the overload

View File

@ -30,7 +30,7 @@ std::string InvariantDecoration::Name() const {
return "invariant"; return "invariant";
} }
InvariantDecoration* InvariantDecoration::Clone(CloneContext* ctx) const { const InvariantDecoration* InvariantDecoration::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);
return ctx->dst->create<InvariantDecoration>(src); return ctx->dst->create<InvariantDecoration>(src);

View File

@ -38,7 +38,7 @@ class InvariantDecoration : public Castable<InvariantDecoration, Decoration> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
InvariantDecoration* Clone(CloneContext* ctx) const override; const InvariantDecoration* Clone(CloneContext* ctx) const override;
}; };
} // namespace ast } // namespace ast

View File

@ -34,7 +34,7 @@ std::string LocationDecoration::Name() const {
return "location"; return "location";
} }
LocationDecoration* LocationDecoration::Clone(CloneContext* ctx) const { const LocationDecoration* LocationDecoration::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);
return ctx->dst->create<LocationDecoration>(src, value); return ctx->dst->create<LocationDecoration>(src, value);

View File

@ -39,10 +39,10 @@ class LocationDecoration : public Castable<LocationDecoration, Decoration> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
LocationDecoration* Clone(CloneContext* ctx) const override; const LocationDecoration* Clone(CloneContext* ctx) const override;
/// The location value /// The location value
uint32_t const value; const uint32_t value;
}; };
} // namespace ast } // namespace ast

View File

@ -23,8 +23,8 @@ namespace ast {
LoopStatement::LoopStatement(ProgramID pid, LoopStatement::LoopStatement(ProgramID pid,
const Source& src, const Source& src,
BlockStatement* b, const BlockStatement* b,
BlockStatement* cont) const BlockStatement* cont)
: Base(pid, src), body(b), continuing(cont) { : Base(pid, src), body(b), continuing(cont) {
TINT_ASSERT(AST, body); TINT_ASSERT(AST, body);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
@ -35,7 +35,7 @@ LoopStatement::LoopStatement(LoopStatement&&) = default;
LoopStatement::~LoopStatement() = default; LoopStatement::~LoopStatement() = default;
LoopStatement* LoopStatement::Clone(CloneContext* ctx) const { const LoopStatement* LoopStatement::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* b = ctx->Clone(body); auto* b = ctx->Clone(body);

View File

@ -30,8 +30,8 @@ class LoopStatement : public Castable<LoopStatement, Statement> {
/// @param continuing the continuing statements /// @param continuing the continuing statements
LoopStatement(ProgramID program_id, LoopStatement(ProgramID program_id,
const Source& source, const Source& source,
BlockStatement* body, const BlockStatement* body,
BlockStatement* continuing); const BlockStatement* continuing);
/// Move constructor /// Move constructor
LoopStatement(LoopStatement&&); LoopStatement(LoopStatement&&);
~LoopStatement() override; ~LoopStatement() override;
@ -40,13 +40,13 @@ class LoopStatement : public Castable<LoopStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
LoopStatement* Clone(CloneContext* ctx) const override; const LoopStatement* Clone(CloneContext* ctx) const override;
/// The loop body /// The loop body
BlockStatement* const body; const BlockStatement* const body;
/// The continuing statements /// The continuing statements
BlockStatement* const continuing; const BlockStatement* const continuing;
}; };
} // namespace ast } // namespace ast

View File

@ -23,7 +23,7 @@ namespace ast {
Matrix::Matrix(ProgramID pid, Matrix::Matrix(ProgramID pid,
const Source& src, const Source& src,
Type* subtype, const Type* subtype,
uint32_t r, uint32_t r,
uint32_t c) uint32_t c)
: Base(pid, src), type(subtype), rows(r), columns(c) { : Base(pid, src), type(subtype), rows(r), columns(c) {
@ -45,7 +45,7 @@ std::string Matrix::FriendlyName(const SymbolTable& symbols) const {
return out.str(); return out.str();
} }
Matrix* Matrix::Clone(CloneContext* ctx) const { const Matrix* Matrix::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);

View File

@ -33,7 +33,7 @@ class Matrix : public Castable<Matrix, Type> {
/// @param columns the number of columns in the matrix /// @param columns the number of columns in the matrix
Matrix(ProgramID pid, Matrix(ProgramID pid,
const Source& src, const Source& src,
Type* subtype, const Type* subtype,
uint32_t rows, uint32_t rows,
uint32_t columns); uint32_t columns);
/// Move constructor /// Move constructor
@ -48,16 +48,16 @@ class Matrix : public Castable<Matrix, Type> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
Matrix* Clone(CloneContext* ctx) const override; const Matrix* Clone(CloneContext* ctx) const override;
/// The type of the matrix /// The type of the matrix
Type* const type; const Type* const type;
/// The number of rows in the matrix /// The number of rows in the matrix
uint32_t const rows; const uint32_t rows;
/// The number of columns in the matrix /// The number of columns in the matrix
uint32_t const columns; const uint32_t columns;
}; };
} // namespace ast } // namespace ast

View File

@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::MemberAccessorExpression);
namespace tint { namespace tint {
namespace ast { namespace ast {
MemberAccessorExpression::MemberAccessorExpression(ProgramID pid, MemberAccessorExpression::MemberAccessorExpression(
const Source& src, ProgramID pid,
Expression* str, const Source& src,
IdentifierExpression* mem) const Expression* str,
const IdentifierExpression* mem)
: Base(pid, src), structure(str), member(mem) { : Base(pid, src), structure(str), member(mem) {
TINT_ASSERT(AST, structure); TINT_ASSERT(AST, structure);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, structure, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, structure, program_id);
@ -37,7 +38,7 @@ MemberAccessorExpression::MemberAccessorExpression(MemberAccessorExpression&&) =
MemberAccessorExpression::~MemberAccessorExpression() = default; MemberAccessorExpression::~MemberAccessorExpression() = default;
MemberAccessorExpression* MemberAccessorExpression::Clone( const MemberAccessorExpression* MemberAccessorExpression::Clone(
CloneContext* ctx) const { 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);

View File

@ -31,8 +31,8 @@ class MemberAccessorExpression
/// @param member the member /// @param member the member
MemberAccessorExpression(ProgramID program_id, MemberAccessorExpression(ProgramID program_id,
const Source& source, const Source& source,
Expression* structure, const Expression* structure,
IdentifierExpression* member); const IdentifierExpression* member);
/// Move constructor /// Move constructor
MemberAccessorExpression(MemberAccessorExpression&&); MemberAccessorExpression(MemberAccessorExpression&&);
~MemberAccessorExpression() override; ~MemberAccessorExpression() override;
@ -41,13 +41,13 @@ class MemberAccessorExpression
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
MemberAccessorExpression* Clone(CloneContext* ctx) const override; const MemberAccessorExpression* Clone(CloneContext* ctx) const override;
/// The structure /// The structure
Expression* const structure; const Expression* const structure;
/// The member expression /// The member expression
IdentifierExpression* const member; const IdentifierExpression* const member;
}; };
} // namespace ast } // namespace ast

View File

@ -28,7 +28,7 @@ Module::Module(ProgramID pid, const Source& src) : Base(pid, src) {}
Module::Module(ProgramID pid, Module::Module(ProgramID pid,
const Source& src, const Source& src,
std::vector<ast::Node*> global_decls) std::vector<const ast::Node*> global_decls)
: Base(pid, src), global_declarations_(std::move(global_decls)) { : Base(pid, src), global_declarations_(std::move(global_decls)) {
for (auto* decl : global_declarations_) { for (auto* decl : global_declarations_) {
if (decl == nullptr) { if (decl == nullptr) {
@ -59,28 +59,28 @@ const ast::TypeDecl* Module::LookupType(Symbol name) const {
return nullptr; return nullptr;
} }
void Module::AddGlobalVariable(ast::Variable* var) { void Module::AddGlobalVariable(const ast::Variable* var) {
TINT_ASSERT(AST, var); TINT_ASSERT(AST, var);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, var, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, var, program_id);
global_variables_.push_back(var); global_variables_.push_back(var);
global_declarations_.push_back(var); global_declarations_.push_back(var);
} }
void Module::AddTypeDecl(ast::TypeDecl* type) { void Module::AddTypeDecl(const ast::TypeDecl* type) {
TINT_ASSERT(AST, type); TINT_ASSERT(AST, type);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id);
type_decls_.push_back(type); type_decls_.push_back(type);
global_declarations_.push_back(type); global_declarations_.push_back(type);
} }
void Module::AddFunction(ast::Function* func) { void Module::AddFunction(const ast::Function* func) {
TINT_ASSERT(AST, func); TINT_ASSERT(AST, func);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id);
functions_.push_back(func); functions_.push_back(func);
global_declarations_.push_back(func); global_declarations_.push_back(func);
} }
Module* Module::Clone(CloneContext* ctx) const { const Module* Module::Clone(CloneContext* ctx) const {
auto* out = ctx->dst->create<Module>(); auto* out = ctx->dst->create<Module>();
out->Copy(ctx, this); out->Copy(ctx, this);
return out; return out;

View File

@ -42,23 +42,23 @@ class Module : public Castable<Module, Node> {
/// the order they were declared in the source program /// the order they were declared in the source program
Module(ProgramID pid, Module(ProgramID pid,
const Source& src, const Source& src,
std::vector<ast::Node*> global_decls); std::vector<const Node*> global_decls);
/// Destructor /// Destructor
~Module() override; ~Module() override;
/// @returns the ordered global declarations for the translation unit /// @returns the ordered global declarations for the translation unit
const std::vector<ast::Node*>& GlobalDeclarations() const { const std::vector<const Node*>& GlobalDeclarations() const {
return global_declarations_; return global_declarations_;
} }
/// Add a global variable to the Builder /// Add a global variable to the Builder
/// @param var the variable to add /// @param var the variable to add
void AddGlobalVariable(ast::Variable* var); void AddGlobalVariable(const Variable* var);
/// @returns true if the module has the global declaration `decl` /// @returns true if the module has the global declaration `decl`
/// @param decl the declaration to check /// @param decl the declaration to check
bool HasGlobalDeclaration(ast::Node* decl) const { bool HasGlobalDeclaration(Node* decl) const {
for (auto* d : global_declarations_) { for (auto* d : global_declarations_) {
if (d == decl) { if (d == decl) {
return true; return true;
@ -75,18 +75,18 @@ class Module : public Castable<Module, Node> {
/// Adds a type declaration to the Builder. /// Adds a type declaration to the Builder.
/// @param decl the type declaration to add /// @param decl the type declaration to add
void AddTypeDecl(ast::TypeDecl* decl); void AddTypeDecl(const TypeDecl* decl);
/// @returns the TypeDecl registered as a TypeDecl() /// @returns the TypeDecl registered as a TypeDecl()
/// @param name the name of the type to search for /// @param name the name of the type to search for
const ast::TypeDecl* LookupType(Symbol name) const; const TypeDecl* LookupType(Symbol name) const;
/// @returns the declared types in the translation unit /// @returns the declared types in the translation unit
const std::vector<ast::TypeDecl*>& TypeDecls() const { return type_decls_; } const std::vector<const TypeDecl*>& TypeDecls() const { return type_decls_; }
/// Add a function to the Builder /// Add a function to the Builder
/// @param func the function to add /// @param func the function to add
void AddFunction(ast::Function* func); void AddFunction(const Function* func);
/// @returns the functions declared in the translation unit /// @returns the functions declared in the translation unit
const FunctionList& Functions() const { return functions_; } const FunctionList& Functions() const { return functions_; }
@ -95,7 +95,7 @@ class Module : public Castable<Module, Node> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
Module* Clone(CloneContext* ctx) const override; const Module* Clone(CloneContext* ctx) const override;
/// Copy copies the content of the Module src into this module. /// Copy copies the content of the Module src into this module.
/// @param ctx the clone context /// @param ctx the clone context
@ -103,8 +103,8 @@ class Module : public Castable<Module, Node> {
void Copy(CloneContext* ctx, const Module* src); void Copy(CloneContext* ctx, const Module* src);
private: private:
std::vector<ast::Node*> global_declarations_; std::vector<const Node*> global_declarations_;
std::vector<ast::TypeDecl*> type_decls_; std::vector<const TypeDecl*> type_decls_;
FunctionList functions_; FunctionList functions_;
VariableList global_variables_; VariableList global_variables_;
}; };

View File

@ -106,15 +106,15 @@ TEST_F(ModuleTest, CloneOrder) {
// declaration that triggered the ReplaceAll(). // declaration that triggered the ReplaceAll().
ProgramBuilder cloned; ProgramBuilder cloned;
CloneContext ctx(&cloned, &p); CloneContext ctx(&cloned, &p);
ctx.ReplaceAll([&](ast::Function*) -> ast::Function* { ctx.ReplaceAll([&](const ast::Function*) -> const ast::Function* {
ctx.dst->Alias("inserted_before_F", cloned.ty.u32()); ctx.dst->Alias("inserted_before_F", cloned.ty.u32());
return nullptr; return nullptr;
}); });
ctx.ReplaceAll([&](ast::Alias*) -> ast::Alias* { ctx.ReplaceAll([&](const ast::Alias*) -> const ast::Alias* {
ctx.dst->Alias("inserted_before_A", cloned.ty.u32()); ctx.dst->Alias("inserted_before_A", cloned.ty.u32());
return nullptr; return nullptr;
}); });
ctx.ReplaceAll([&](ast::Variable*) -> ast::Variable* { ctx.ReplaceAll([&](const ast::Variable*) -> const ast::Variable* {
ctx.dst->Alias("inserted_before_V", cloned.ty.u32()); ctx.dst->Alias("inserted_before_V", cloned.ty.u32());
return nullptr; return nullptr;
}); });

View File

@ -24,7 +24,7 @@ namespace ast {
MultisampledTexture::MultisampledTexture(ProgramID pid, MultisampledTexture::MultisampledTexture(ProgramID pid,
const Source& src, const Source& src,
TextureDimension d, TextureDimension d,
Type* ty) const Type* ty)
: Base(pid, src, d), type(ty) { : Base(pid, src, d), type(ty) {
TINT_ASSERT(AST, type); TINT_ASSERT(AST, type);
} }
@ -41,7 +41,7 @@ std::string MultisampledTexture::FriendlyName(
return out.str(); return out.str();
} }
MultisampledTexture* MultisampledTexture::Clone(CloneContext* ctx) const { const MultisampledTexture* MultisampledTexture::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);

View File

@ -33,7 +33,7 @@ class MultisampledTexture : public Castable<MultisampledTexture, Texture> {
MultisampledTexture(ProgramID pid, MultisampledTexture(ProgramID pid,
const Source& src, const Source& src,
TextureDimension dim, TextureDimension dim,
Type* type); const Type* type);
/// Move constructor /// Move constructor
MultisampledTexture(MultisampledTexture&&); MultisampledTexture(MultisampledTexture&&);
~MultisampledTexture() override; ~MultisampledTexture() override;
@ -46,10 +46,10 @@ class MultisampledTexture : public Castable<MultisampledTexture, Texture> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
MultisampledTexture* Clone(CloneContext* ctx) const override; const MultisampledTexture* Clone(CloneContext* ctx) const override;
/// The subtype of the multisampled texture /// The subtype of the multisampled texture
Type* const type; const Type* const type;
}; };
} // namespace ast } // namespace ast

View File

@ -38,10 +38,10 @@ class Node : public Castable<Node, Cloneable> {
~Node() override; ~Node() override;
/// The identifier of the program that owns this node /// The identifier of the program that owns this node
ProgramID const program_id; const ProgramID program_id;
/// The node source data /// The node source data
Source const source; const Source source;
protected: protected:
/// Create a new node /// Create a new node

View File

@ -37,7 +37,7 @@ std::string OverrideDecoration::Name() const {
return "override"; return "override";
} }
OverrideDecoration* OverrideDecoration::Clone(CloneContext* ctx) const { const OverrideDecoration* OverrideDecoration::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);
if (has_value) { if (has_value) {

View File

@ -43,13 +43,13 @@ class OverrideDecoration : public Castable<OverrideDecoration, Decoration> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
OverrideDecoration* Clone(CloneContext* ctx) const override; const OverrideDecoration* Clone(CloneContext* ctx) const override;
/// True if an override id was specified /// True if an override id was specified
bool const has_value; const bool has_value;
/// The override id value /// The override id value
uint32_t const value; const uint32_t value;
}; };
} // namespace ast } // namespace ast

View File

@ -23,7 +23,7 @@ namespace ast {
Pointer::Pointer(ProgramID pid, Pointer::Pointer(ProgramID pid,
const Source& src, const Source& src,
Type* const subtype, const Type* const subtype,
ast::StorageClass sc, ast::StorageClass sc,
ast::Access ac) ast::Access ac)
: Base(pid, src), type(subtype), storage_class(sc), access(ac) {} : Base(pid, src), type(subtype), storage_class(sc), access(ac) {}
@ -46,7 +46,7 @@ Pointer::Pointer(Pointer&&) = default;
Pointer::~Pointer() = default; Pointer::~Pointer() = default;
Pointer* Pointer::Clone(CloneContext* ctx) const { const Pointer* Pointer::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);

View File

@ -35,7 +35,7 @@ class Pointer : public Castable<Pointer, Type> {
/// @param access the access control of the pointer /// @param access the access control of the pointer
Pointer(ProgramID pid, Pointer(ProgramID pid,
const Source& src, const Source& src,
Type* const subtype, const Type* const subtype,
ast::StorageClass storage_class, ast::StorageClass storage_class,
ast::Access access); ast::Access access);
/// Move constructor /// Move constructor
@ -50,10 +50,10 @@ class Pointer : public Castable<Pointer, Type> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
Pointer* Clone(CloneContext* ctx) const override; const Pointer* Clone(CloneContext* ctx) const override;
/// The pointee type /// The pointee type
Type* const type; const Type* const type;
/// The storage class of the pointer /// The storage class of the pointer
ast::StorageClass const storage_class; ast::StorageClass const storage_class;

View File

@ -26,7 +26,7 @@ ReturnStatement::ReturnStatement(ProgramID pid, const Source& src)
ReturnStatement::ReturnStatement(ProgramID pid, ReturnStatement::ReturnStatement(ProgramID pid,
const Source& src, const Source& src,
Expression* val) const Expression* val)
: Base(pid, src), value(val) { : Base(pid, src), value(val) {
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, value, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, value, program_id);
} }
@ -35,7 +35,7 @@ ReturnStatement::ReturnStatement(ReturnStatement&&) = default;
ReturnStatement::~ReturnStatement() = default; ReturnStatement::~ReturnStatement() = default;
ReturnStatement* ReturnStatement::Clone(CloneContext* ctx) const { const ReturnStatement* ReturnStatement::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* ret = ctx->Clone(value); auto* ret = ctx->Clone(value);

View File

@ -33,7 +33,7 @@ class ReturnStatement : public Castable<ReturnStatement, Statement> {
/// @param pid the identifier of the program that owns this node /// @param pid the identifier of the program that owns this node
/// @param src the source of this node /// @param src the source of this node
/// @param value the return value /// @param value the return value
ReturnStatement(ProgramID pid, const Source& src, Expression* value); ReturnStatement(ProgramID pid, const Source& src, const Expression* value);
/// Move constructor /// Move constructor
ReturnStatement(ReturnStatement&&); ReturnStatement(ReturnStatement&&);
~ReturnStatement() override; ~ReturnStatement() override;
@ -42,10 +42,10 @@ class ReturnStatement : public Castable<ReturnStatement, Statement> {
/// `ctx`. /// `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned node /// @return the newly cloned node
ReturnStatement* Clone(CloneContext* ctx) const override; const ReturnStatement* Clone(CloneContext* ctx) const override;
/// The value returned. May be null. /// The value returned. May be null.
Expression* const value; const Expression* const value;
}; };
} // namespace ast } // namespace ast

View File

@ -24,8 +24,8 @@ namespace ast {
SampledTexture::SampledTexture(ProgramID pid, SampledTexture::SampledTexture(ProgramID pid,
const Source& src, const Source& src,
TextureDimension d, TextureDimension d,
Type const* ty) const Type* ty)
: Base(pid, src, d), type(const_cast<Type*>(ty)) { : Base(pid, src, d), type(ty) {
TINT_ASSERT(AST, type); TINT_ASSERT(AST, type);
} }
@ -39,7 +39,7 @@ std::string SampledTexture::FriendlyName(const SymbolTable& symbols) const {
return out.str(); return out.str();
} }
SampledTexture* SampledTexture::Clone(CloneContext* ctx) const { const SampledTexture* SampledTexture::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);

View File

@ -33,7 +33,7 @@ class SampledTexture : public Castable<SampledTexture, Texture> {
SampledTexture(ProgramID pid, SampledTexture(ProgramID pid,
const Source& src, const Source& src,
TextureDimension dim, TextureDimension dim,
Type const* type); const Type* type);
/// Move constructor /// Move constructor
SampledTexture(SampledTexture&&); SampledTexture(SampledTexture&&);
~SampledTexture() override; ~SampledTexture() override;
@ -46,10 +46,10 @@ class SampledTexture : public Castable<SampledTexture, Texture> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
SampledTexture* Clone(CloneContext* ctx) const override; const SampledTexture* Clone(CloneContext* ctx) const override;
/// The subtype of the sampled texture /// The subtype of the sampled texture
Type* const type; const Type* const type;
}; };
} // namespace ast } // namespace ast

View File

@ -44,7 +44,7 @@ std::string Sampler::FriendlyName(const SymbolTable&) const {
return kind == SamplerKind::kSampler ? "sampler" : "sampler_comparison"; return kind == SamplerKind::kSampler ? "sampler" : "sampler_comparison";
} }
Sampler* Sampler::Clone(CloneContext* ctx) const { const Sampler* Sampler::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source); auto src = ctx->Clone(source);
return ctx->dst->create<Sampler>(src, kind); return ctx->dst->create<Sampler>(src, kind);
} }

View File

@ -58,10 +58,10 @@ class Sampler : public Castable<Sampler, Type> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`. /// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context /// @param ctx the clone context
/// @return the newly cloned type /// @return the newly cloned type
Sampler* Clone(CloneContext* ctx) const override; const Sampler* Clone(CloneContext* ctx) const override;
/// The sampler type /// The sampler type
SamplerKind const kind; const SamplerKind kind;
}; };
} // namespace ast } // namespace ast

Some files were not shown because too many files have changed in this diff Show More