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

View File

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

View File

@ -21,7 +21,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Alias);
namespace tint {
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) {
TINT_ASSERT(AST, type);
}
@ -30,7 +33,7 @@ Alias::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
auto src = ctx->Clone(source);
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 name the symbol for the alias
/// @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
Alias(Alias&&);
/// Destructor
@ -39,10 +42,10 @@ class Alias : public Castable<Alias, TypeDecl> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context
/// @return the newly cloned type
Alias* Clone(CloneContext* ctx) const override;
const Alias* Clone(CloneContext* ctx) const override;
/// the alias type
Type* const type;
const Type* const type;
};
} // namespace ast

View File

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

View File

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

View File

@ -23,8 +23,8 @@ namespace ast {
ArrayAccessorExpression::ArrayAccessorExpression(ProgramID pid,
const Source& src,
Expression* arr,
Expression* idx)
const Expression* arr,
const Expression* idx)
: Base(pid, src), array(arr), index(idx) {
TINT_ASSERT(AST, array);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, array, program_id);
@ -37,7 +37,7 @@ ArrayAccessorExpression::ArrayAccessorExpression(ArrayAccessorExpression&&) =
ArrayAccessorExpression::~ArrayAccessorExpression() = default;
ArrayAccessorExpression* ArrayAccessorExpression::Clone(
const ArrayAccessorExpression* ArrayAccessorExpression::Clone(
CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);

View File

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

View File

@ -23,8 +23,8 @@ namespace ast {
AssignmentStatement::AssignmentStatement(ProgramID pid,
const Source& src,
Expression* l,
Expression* r)
const Expression* l,
const Expression* r)
: Base(pid, src), lhs(l), rhs(r) {
TINT_ASSERT(AST, lhs);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id);
@ -36,7 +36,7 @@ AssignmentStatement::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
auto src = ctx->Clone(source);
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
AssignmentStatement(ProgramID program_id,
const Source& source,
Expression* lhs,
Expression* rhs);
const Expression* lhs,
const Expression* rhs);
/// Move constructor
AssignmentStatement(AssignmentStatement&&);
~AssignmentStatement() override;
@ -41,13 +41,13 @@ class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
AssignmentStatement* Clone(CloneContext* ctx) const override;
const AssignmentStatement* Clone(CloneContext* ctx) const override;
/// left side expression
Expression* const lhs;
const Expression* const lhs;
/// right side expression
Expression* const rhs;
const Expression* const rhs;
};
} // namespace ast

View File

@ -21,7 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Atomic);
namespace tint {
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) {}
std::string Atomic::FriendlyName(const SymbolTable& symbols) const {
@ -34,10 +34,10 @@ Atomic::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
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);
}

View File

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

View File

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

View File

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

View File

@ -34,7 +34,7 @@ std::string BindingDecoration::Name() const {
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
auto src = ctx->Clone(source);
return ctx->dst->create<BindingDecoration>(src, value);

View File

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

View File

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

View File

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

View File

@ -35,7 +35,7 @@ BlockStatement::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
auto src = ctx->Clone(source);
auto stmts = ctx->Clone(statements);

View File

@ -40,7 +40,7 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
bool Empty() const { return statements.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();
}
@ -48,10 +48,10 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
BlockStatement* Clone(CloneContext* ctx) const override;
const BlockStatement* Clone(CloneContext* ctx) const override;
/// the statement list
StatementList const statements;
const StatementList statements;
};
} // namespace ast

View File

@ -31,7 +31,7 @@ std::string Bool::FriendlyName(const SymbolTable&) const {
return "bool";
}
Bool* Bool::Clone(CloneContext* ctx) const {
const Bool* Bool::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source);
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`.
/// @param ctx the clone context
/// @return the newly cloned type
Bool* Clone(CloneContext* ctx) const override;
const Bool* Clone(CloneContext* ctx) const override;
};
} // namespace ast

View File

@ -26,7 +26,7 @@ BoolLiteral::BoolLiteral(ProgramID pid, const Source& src, bool val)
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
auto src = ctx->Clone(source);
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() override;
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
BoolLiteral* Clone(CloneContext* ctx) const override;
const BoolLiteral* Clone(CloneContext* ctx) const override;
/// The boolean literal value
bool const value;
const bool value;
};
} // namespace ast

View File

@ -28,7 +28,7 @@ BreakStatement::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
auto src = ctx->Clone(source);
return ctx->dst->create<BreakStatement>(src);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -23,7 +23,7 @@ namespace ast {
CallStatement::CallStatement(ProgramID pid,
const Source& src,
CallExpression* call)
const CallExpression* call)
: Base(pid, src), expr(call) {
TINT_ASSERT(AST, expr);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id);
@ -33,7 +33,7 @@ CallStatement::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
auto src = ctx->Clone(source);
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 src the source of this node for the statement
/// @param call the function
CallStatement(ProgramID pid, const Source& src, CallExpression* call);
CallStatement(ProgramID pid, const Source& src, const CallExpression* call);
/// Move constructor
CallStatement(CallStatement&&);
~CallStatement() override;
@ -37,10 +37,10 @@ class CallStatement : public Castable<CallStatement, Statement> {
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
CallStatement* Clone(CloneContext* ctx) const override;
const CallStatement* Clone(CloneContext* ctx) const override;
/// The call expression
CallExpression* const expr;
const CallExpression* const expr;
};
} // namespace ast

View File

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

View File

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

View File

@ -28,7 +28,7 @@ ContinueStatement::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
auto src = ctx->Clone(source);
return ctx->dst->create<ContinueStatement>(src);

View File

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

View File

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

View File

@ -46,7 +46,7 @@ std::string DepthMultisampledTexture::FriendlyName(const SymbolTable&) const {
return out.str();
}
DepthMultisampledTexture* DepthMultisampledTexture::Clone(
const DepthMultisampledTexture* DepthMultisampledTexture::Clone(
CloneContext* ctx) const {
auto src = ctx->Clone(source);
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`.
/// @param ctx the clone context
/// @return the newly cloned type
DepthMultisampledTexture* Clone(CloneContext* ctx) const override;
const DepthMultisampledTexture* Clone(CloneContext* ctx) const override;
};
} // namespace ast

View File

@ -44,7 +44,7 @@ std::string DepthTexture::FriendlyName(const SymbolTable&) const {
return out.str();
}
DepthTexture* DepthTexture::Clone(CloneContext* ctx) const {
const DepthTexture* DepthTexture::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source);
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`.
/// @param ctx the clone context
/// @return the newly cloned type
DepthTexture* Clone(CloneContext* ctx) const override;
const DepthTexture* Clone(CloneContext* ctx) const override;
};
} // namespace ast

View File

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

View File

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

View File

@ -28,7 +28,7 @@ DiscardStatement::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
auto src = ctx->Clone(source);
return ctx->dst->create<DiscardStatement>(src);

View File

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

View File

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

View File

@ -33,8 +33,8 @@ class ElseStatement : public Castable<ElseStatement, Statement> {
/// @param body the else body
ElseStatement(ProgramID pid,
const Source& src,
Expression* condition,
BlockStatement* body);
const Expression* condition,
const BlockStatement* body);
/// Move constructor
ElseStatement(ElseStatement&&);
~ElseStatement() override;
@ -43,17 +43,17 @@ class ElseStatement : public Castable<ElseStatement, Statement> {
/// `ctx`.
/// @param ctx the clone context
/// @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
Expression* const condition;
const Expression* const condition;
/// The else body
BlockStatement* const body;
const BlockStatement* const body;
};
/// A list of else statements
using ElseStatementList = std::vector<ElseStatement*>;
using ElseStatementList = std::vector<const ElseStatement*>;
} // namespace ast
} // namespace tint

View File

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

View File

@ -33,7 +33,7 @@ std::string ExternalTexture::FriendlyName(const SymbolTable&) const {
return "texture_external";
}
ExternalTexture* ExternalTexture::Clone(CloneContext* ctx) const {
const ExternalTexture* ExternalTexture::Clone(CloneContext* ctx) const {
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`.
/// @param ctx the clone context
/// @return the newly cloned type
ExternalTexture* Clone(CloneContext* ctx) const override;
const ExternalTexture* Clone(CloneContext* ctx) const override;
};
} // namespace ast

View File

@ -31,7 +31,7 @@ std::string F32::FriendlyName(const SymbolTable&) const {
return "f32";
}
F32* F32::Clone(CloneContext* ctx) const {
const F32* F32::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source);
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`.
/// @param ctx the clone context
/// @return the newly cloned type
F32* Clone(CloneContext* ctx) const override;
const F32* Clone(CloneContext* ctx) const override;
};
} // namespace ast

View File

@ -28,7 +28,8 @@ FallthroughStatement::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
auto src = ctx->Clone(source);
return ctx->dst->create<FallthroughStatement>(src);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -32,7 +32,7 @@ std::string GroupDecoration::Name() const {
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
auto src = ctx->Clone(source);
return ctx->dst->create<GroupDecoration>(src, value);

View File

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

View File

@ -31,7 +31,7 @@ std::string I32::FriendlyName(const SymbolTable&) const {
return "i32";
}
I32* I32::Clone(CloneContext* ctx) const {
const I32* I32::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source);
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`.
/// @param ctx the clone context
/// @return the newly cloned type
I32* Clone(CloneContext* ctx) const override;
const I32* Clone(CloneContext* ctx) const override;
};
} // namespace ast

View File

@ -33,7 +33,8 @@ IdentifierExpression::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
auto src = ctx->Clone(source);
auto sym = ctx->Clone(symbol);

View File

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

View File

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

View File

@ -33,8 +33,8 @@ class IfStatement : public Castable<IfStatement, Statement> {
/// @param else_stmts the else statements
IfStatement(ProgramID pid,
const Source& src,
Expression* condition,
BlockStatement* body,
const Expression* condition,
const BlockStatement* body,
ElseStatementList else_stmts);
/// Move constructor
IfStatement(IfStatement&&);
@ -44,16 +44,16 @@ class IfStatement : public Castable<IfStatement, Statement> {
/// `ctx`.
/// @param ctx the clone context
/// @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
Expression* const condition;
const Expression* const condition;
/// The if body
BlockStatement* const body;
const BlockStatement* const body;
/// The else statements
ElseStatementList const else_statements;
const ElseStatementList else_statements;
};
} // namespace ast

View File

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

View File

@ -35,7 +35,8 @@ std::string InterpolateDecoration::Name() const {
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
auto src = ctx->Clone(source);
return ctx->dst->create<InterpolateDecoration>(src, type, sampling);

View File

@ -51,13 +51,13 @@ class InterpolateDecoration
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
InterpolateDecoration* Clone(CloneContext* ctx) const override;
const InterpolateDecoration* Clone(CloneContext* ctx) const override;
/// The interpolation type
InterpolationType const type;
const InterpolationType type;
/// The interpolation sampling
InterpolationSampling const sampling;
const InterpolationSampling sampling;
};
/// @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;
}
ast::Type* TextureOverloadCase::BuildResultVectorComponentType(
const ast::Type* TextureOverloadCase::BuildResultVectorComponentType(
ProgramBuilder* b) const {
switch (texture_data_type) {
case ast::intrinsic::test::TextureDataType::kF32:
@ -149,7 +149,7 @@ ast::Type* TextureOverloadCase::BuildResultVectorComponentType(
return {};
}
ast::Variable* TextureOverloadCase::BuildTextureVariable(
const ast::Variable* TextureOverloadCase::BuildTextureVariable(
ProgramBuilder* b) const {
DecorationList decos = {
b->create<ast::GroupDecoration>(0),
@ -188,7 +188,7 @@ ast::Variable* TextureOverloadCase::BuildTextureVariable(
return nullptr;
}
ast::Variable* TextureOverloadCase::BuildSamplerVariable(
const ast::Variable* TextureOverloadCase::BuildSamplerVariable(
ProgramBuilder* b) const {
DecorationList decos = {
b->create<ast::GroupDecoration>(0),

View File

@ -205,22 +205,23 @@ struct TextureOverloadCase {
/// @param builder the AST builder used for the test
/// @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
/// @returns a variable holding the test texture, automatically registered as
/// 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
/// @returns a Variable holding the test sampler, automatically registered as
/// a global variable.
ast::Variable* BuildSamplerVariable(ProgramBuilder* builder) const;
const ast::Variable* BuildSamplerVariable(ProgramBuilder* builder) const;
/// The enumerator for this overload
ValidTextureOverload const overload;
const ValidTextureOverload overload;
/// A human readable description of the overload
const char* const description;
/// The texture kind for the texture parameter
TextureKind const texture_kind;
const TextureKind texture_kind;
/// The sampler kind for the sampler parameter
/// Used only when texture_kind is not kStorage
ast::SamplerKind const sampler_kind = ast::SamplerKind::kSampler;
@ -233,7 +234,7 @@ struct TextureOverloadCase {
/// The dimensions of the texture parameter
ast::TextureDimension const texture_dimension;
/// 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
const char* const function;
/// A function that builds the AST arguments for the overload

View File

@ -30,7 +30,7 @@ std::string InvariantDecoration::Name() const {
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
auto src = ctx->Clone(source);
return ctx->dst->create<InvariantDecoration>(src);

View File

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

View File

@ -34,7 +34,7 @@ std::string LocationDecoration::Name() const {
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
auto src = ctx->Clone(source);
return ctx->dst->create<LocationDecoration>(src, value);

View File

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

View File

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

View File

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

View File

@ -23,7 +23,7 @@ namespace ast {
Matrix::Matrix(ProgramID pid,
const Source& src,
Type* subtype,
const Type* subtype,
uint32_t r,
uint32_t 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();
}
Matrix* Matrix::Clone(CloneContext* ctx) const {
const Matrix* Matrix::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);
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
Matrix(ProgramID pid,
const Source& src,
Type* subtype,
const Type* subtype,
uint32_t rows,
uint32_t columns);
/// Move constructor
@ -48,16 +48,16 @@ class Matrix : public Castable<Matrix, Type> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context
/// @return the newly cloned type
Matrix* Clone(CloneContext* ctx) const override;
const Matrix* Clone(CloneContext* ctx) const override;
/// The type of the matrix
Type* const type;
const Type* const type;
/// The number of rows in the matrix
uint32_t const rows;
const uint32_t rows;
/// The number of columns in the matrix
uint32_t const columns;
const uint32_t columns;
};
} // namespace ast

View File

@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::MemberAccessorExpression);
namespace tint {
namespace ast {
MemberAccessorExpression::MemberAccessorExpression(ProgramID pid,
const Source& src,
Expression* str,
IdentifierExpression* mem)
MemberAccessorExpression::MemberAccessorExpression(
ProgramID pid,
const Source& src,
const Expression* str,
const IdentifierExpression* mem)
: Base(pid, src), structure(str), member(mem) {
TINT_ASSERT(AST, structure);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, structure, program_id);
@ -37,7 +38,7 @@ MemberAccessorExpression::MemberAccessorExpression(MemberAccessorExpression&&) =
MemberAccessorExpression::~MemberAccessorExpression() = default;
MemberAccessorExpression* MemberAccessorExpression::Clone(
const MemberAccessorExpression* MemberAccessorExpression::Clone(
CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);

View File

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

View File

@ -28,7 +28,7 @@ Module::Module(ProgramID pid, const Source& src) : Base(pid, src) {}
Module::Module(ProgramID pid,
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)) {
for (auto* decl : global_declarations_) {
if (decl == nullptr) {
@ -59,28 +59,28 @@ const ast::TypeDecl* Module::LookupType(Symbol name) const {
return nullptr;
}
void Module::AddGlobalVariable(ast::Variable* var) {
void Module::AddGlobalVariable(const ast::Variable* var) {
TINT_ASSERT(AST, var);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, var, program_id);
global_variables_.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_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id);
type_decls_.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_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id);
functions_.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>();
out->Copy(ctx, this);
return out;

View File

@ -42,23 +42,23 @@ class Module : public Castable<Module, Node> {
/// the order they were declared in the source program
Module(ProgramID pid,
const Source& src,
std::vector<ast::Node*> global_decls);
std::vector<const Node*> global_decls);
/// Destructor
~Module() override;
/// @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_;
}
/// Add a global variable to the Builder
/// @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`
/// @param decl the declaration to check
bool HasGlobalDeclaration(ast::Node* decl) const {
bool HasGlobalDeclaration(Node* decl) const {
for (auto* d : global_declarations_) {
if (d == decl) {
return true;
@ -75,18 +75,18 @@ class Module : public Castable<Module, Node> {
/// Adds a type declaration to the Builder.
/// @param decl the type declaration to add
void AddTypeDecl(ast::TypeDecl* decl);
void AddTypeDecl(const TypeDecl* decl);
/// @returns the TypeDecl registered as a TypeDecl()
/// @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
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
/// @param func the function to add
void AddFunction(ast::Function* func);
void AddFunction(const Function* func);
/// @returns the functions declared in the translation unit
const FunctionList& Functions() const { return functions_; }
@ -95,7 +95,7 @@ class Module : public Castable<Module, Node> {
/// `ctx`.
/// @param ctx the clone context
/// @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.
/// @param ctx the clone context
@ -103,8 +103,8 @@ class Module : public Castable<Module, Node> {
void Copy(CloneContext* ctx, const Module* src);
private:
std::vector<ast::Node*> global_declarations_;
std::vector<ast::TypeDecl*> type_decls_;
std::vector<const Node*> global_declarations_;
std::vector<const TypeDecl*> type_decls_;
FunctionList functions_;
VariableList global_variables_;
};

View File

@ -106,15 +106,15 @@ TEST_F(ModuleTest, CloneOrder) {
// declaration that triggered the ReplaceAll().
ProgramBuilder cloned;
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());
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());
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());
return nullptr;
});

View File

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

View File

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

View File

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

View File

@ -37,7 +37,7 @@ std::string OverrideDecoration::Name() const {
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
auto src = ctx->Clone(source);
if (has_value) {

View File

@ -43,13 +43,13 @@ class OverrideDecoration : public Castable<OverrideDecoration, Decoration> {
/// `ctx`.
/// @param ctx the clone context
/// @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
bool const has_value;
const bool has_value;
/// The override id value
uint32_t const value;
const uint32_t value;
};
} // namespace ast

View File

@ -23,7 +23,7 @@ namespace ast {
Pointer::Pointer(ProgramID pid,
const Source& src,
Type* const subtype,
const Type* const subtype,
ast::StorageClass sc,
ast::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::Clone(CloneContext* ctx) const {
const Pointer* Pointer::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);
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
Pointer(ProgramID pid,
const Source& src,
Type* const subtype,
const Type* const subtype,
ast::StorageClass storage_class,
ast::Access access);
/// Move constructor
@ -50,10 +50,10 @@ class Pointer : public Castable<Pointer, Type> {
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context
/// @return the newly cloned type
Pointer* Clone(CloneContext* ctx) const override;
const Pointer* Clone(CloneContext* ctx) const override;
/// The pointee type
Type* const type;
const Type* const type;
/// The storage class of the pointer
ast::StorageClass const storage_class;

View File

@ -26,7 +26,7 @@ ReturnStatement::ReturnStatement(ProgramID pid, const Source& src)
ReturnStatement::ReturnStatement(ProgramID pid,
const Source& src,
Expression* val)
const Expression* val)
: Base(pid, src), value(val) {
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, value, program_id);
}
@ -35,7 +35,7 @@ ReturnStatement::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
auto src = ctx->Clone(source);
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 src the source of this node
/// @param value the return value
ReturnStatement(ProgramID pid, const Source& src, Expression* value);
ReturnStatement(ProgramID pid, const Source& src, const Expression* value);
/// Move constructor
ReturnStatement(ReturnStatement&&);
~ReturnStatement() override;
@ -42,10 +42,10 @@ class ReturnStatement : public Castable<ReturnStatement, Statement> {
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
ReturnStatement* Clone(CloneContext* ctx) const override;
const ReturnStatement* Clone(CloneContext* ctx) const override;
/// The value returned. May be null.
Expression* const value;
const Expression* const value;
};
} // namespace ast

View File

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

View File

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

View File

@ -44,7 +44,7 @@ std::string Sampler::FriendlyName(const SymbolTable&) const {
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);
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`.
/// @param ctx the clone context
/// @return the newly cloned type
Sampler* Clone(CloneContext* ctx) const override;
const Sampler* Clone(CloneContext* ctx) const override;
/// The sampler type
SamplerKind const kind;
const SamplerKind kind;
};
} // namespace ast

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