ast: Keep style consistent

Methods and functions are `CamelCase()`
Public fields are `snake_case` with no trailing `_`
Private fields are `snake_case` with a trailing `_`

Remove pointless getters on fully immutable fields.
They provide no value, and just add `()` noise on use.

Remove unused methods.

Bug: tint:1231
Change-Id: If32efd039df48938efd5bc2186d51fe4853e9840
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66600
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton 2021-10-15 17:33:10 +00:00 committed by Tint LUCI CQ
parent b3e6c0d62c
commit 4f3ff57c28
337 changed files with 4287 additions and 4803 deletions

View File

@ -89,8 +89,8 @@ void MutationReplaceIdentifier::Apply(const NodeIdMap& node_id_map,
tint::As<ast::Variable>(node_id_map.GetNode(message_.replacement_id()));
auto* cloned_replacement =
clone_context->dst->Expr(clone_context->Clone(use_node->source()),
clone_context->Clone(replacement_var->symbol()));
clone_context->dst->Expr(clone_context->Clone(use_node->source),
clone_context->Clone(replacement_var->symbol));
clone_context->Replace(use_node, cloned_replacement);
new_node_id_map->Add(cloned_replacement, message_.use_id());
}

View File

@ -49,19 +49,18 @@ TEST(ReplaceIdentifierTest, NotApplicable_Simple) {
NodeIdMap node_id_map(program);
const auto& main_fn_stmts =
program.AST().Functions()[0]->body()->statements();
const auto& main_fn_stmts = program.AST().Functions()[0]->body->statements;
const auto* a_var =
main_fn_stmts[0]->As<ast::VariableDeclStatement>()->variable();
main_fn_stmts[0]->As<ast::VariableDeclStatement>()->variable;
ASSERT_NE(a_var, nullptr);
const auto* b_var =
main_fn_stmts[2]->As<ast::VariableDeclStatement>()->variable();
main_fn_stmts[2]->As<ast::VariableDeclStatement>()->variable;
ASSERT_NE(b_var, nullptr);
const auto* e_var =
main_fn_stmts[4]->As<ast::VariableDeclStatement>()->variable();
main_fn_stmts[4]->As<ast::VariableDeclStatement>()->variable;
ASSERT_NE(e_var, nullptr);
auto a_var_id = node_id_map.GetId(a_var);
@ -70,10 +69,10 @@ TEST(ReplaceIdentifierTest, NotApplicable_Simple) {
auto b_var_id = node_id_map.GetId(b_var);
ASSERT_NE(b_var_id, 0);
const auto* sum_expr = b_var->constructor()->As<ast::BinaryExpression>();
const auto* sum_expr = b_var->constructor->As<ast::BinaryExpression>();
ASSERT_NE(sum_expr, nullptr);
auto a_ident_id = node_id_map.GetId(sum_expr->lhs());
auto a_ident_id = node_id_map.GetId(sum_expr->lhs);
ASSERT_NE(a_ident_id, 0);
auto sum_expr_id = node_id_map.GetId(sum_expr);
@ -83,7 +82,7 @@ TEST(ReplaceIdentifierTest, NotApplicable_Simple) {
ASSERT_NE(e_var_id, 0);
auto vec_member_access_id = node_id_map.GetId(
e_var->constructor()->As<ast::MemberAccessorExpression>()->member());
e_var->constructor->As<ast::MemberAccessorExpression>()->member);
ASSERT_NE(vec_member_access_id, 0);
// use_id is invalid.
@ -136,10 +135,9 @@ var<private> b: i32;
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[0]
->body->statements[0]
->As<ast::AssignmentStatement>()
->lhs());
->lhs);
ASSERT_NE(use_id, 0);
auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[1]);
@ -170,14 +168,11 @@ fn f() {
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[0]
->body->statements[0]
->As<ast::AssignmentStatement>()
->lhs()
->As<ast::UnaryOpExpression>()
->expr()
->As<ast::UnaryOpExpression>()
->expr());
->lhs->As<ast::UnaryOpExpression>()
->expr->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
@ -202,22 +197,18 @@ fn f() {
auto replacement_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[0]
->body->statements[0]
->As<ast::VariableDeclStatement>()
->variable());
->variable);
ASSERT_NE(replacement_id, 0);
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[1]
->body->statements[1]
->As<ast::AssignmentStatement>()
->lhs()
->As<ast::UnaryOpExpression>()
->expr()
->As<ast::UnaryOpExpression>()
->expr());
->lhs->As<ast::UnaryOpExpression>()
->expr->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
@ -242,22 +233,18 @@ fn f() {
auto replacement_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[0]
->body->statements[0]
->As<ast::VariableDeclStatement>()
->variable());
->variable);
ASSERT_NE(replacement_id, 0);
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[1]
->body->statements[1]
->As<ast::AssignmentStatement>()
->lhs()
->As<ast::UnaryOpExpression>()
->expr()
->As<ast::UnaryOpExpression>()
->expr());
->lhs->As<ast::UnaryOpExpression>()
->expr->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
@ -280,19 +267,16 @@ fn f(b: i32) {
NodeIdMap node_id_map(program);
auto replacement_id =
node_id_map.GetId(program.AST().Functions()[0]->params()[0]);
node_id_map.GetId(program.AST().Functions()[0]->params[0]);
ASSERT_NE(replacement_id, 0);
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[0]
->body->statements[0]
->As<ast::AssignmentStatement>()
->lhs()
->As<ast::UnaryOpExpression>()
->expr()
->As<ast::UnaryOpExpression>()
->expr());
->lhs->As<ast::UnaryOpExpression>()
->expr->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
@ -325,14 +309,11 @@ fn f() {
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[0]
->body->statements[0]
->As<ast::AssignmentStatement>()
->lhs()
->As<ast::UnaryOpExpression>()
->expr()
->As<ast::UnaryOpExpression>()
->expr());
->lhs->As<ast::UnaryOpExpression>()
->expr->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
@ -365,12 +346,10 @@ fn f() {
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[1]
->body->statements[1]
->As<ast::AssignmentStatement>()
->rhs()
->As<ast::UnaryOpExpression>()
->expr());
->rhs->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
@ -405,12 +384,10 @@ fn f() {
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[1]
->body->statements[1]
->As<ast::AssignmentStatement>()
->rhs()
->As<ast::UnaryOpExpression>()
->expr());
->rhs->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
@ -443,14 +420,11 @@ fn f() {
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[0]
->body->statements[0]
->As<ast::AssignmentStatement>()
->rhs()
->As<ast::UnaryOpExpression>()
->expr()
->As<ast::UnaryOpExpression>()
->expr());
->rhs->As<ast::UnaryOpExpression>()
->expr->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
@ -483,14 +457,11 @@ fn f() {
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[0]
->body->statements[0]
->As<ast::AssignmentStatement>()
->rhs()
->As<ast::UnaryOpExpression>()
->expr()
->As<ast::UnaryOpExpression>()
->expr());
->rhs->As<ast::UnaryOpExpression>()
->expr->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
@ -514,24 +485,19 @@ fn f() {
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[2]
->body->statements[2]
->As<ast::AssignmentStatement>()
->lhs()
->As<ast::ArrayAccessorExpression>()
->array()
->As<ast::UnaryOpExpression>()
->expr()
->As<ast::UnaryOpExpression>()
->expr());
->lhs->As<ast::ArrayAccessorExpression>()
->array->As<ast::UnaryOpExpression>()
->expr->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
auto replacement_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[0]
->body->statements[0]
->As<ast::VariableDeclStatement>()
->variable());
->variable);
ASSERT_NE(replacement_id, 0);
ASSERT_TRUE(MaybeApplyMutation(
@ -569,18 +535,15 @@ fn f(b: ptr<function, vec2<u32>>) {
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[2]
->body->statements[2]
->As<ast::AssignmentStatement>()
->lhs()
->As<ast::ArrayAccessorExpression>()
->array()
->As<ast::UnaryOpExpression>()
->expr());
->lhs->As<ast::ArrayAccessorExpression>()
->array->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
auto replacement_id =
node_id_map.GetId(program.AST().Functions()[0]->params()[0]);
node_id_map.GetId(program.AST().Functions()[0]->params[0]);
ASSERT_NE(replacement_id, 0);
ASSERT_TRUE(MaybeApplyMutation(
@ -619,16 +582,12 @@ fn f() {
auto use_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[1]
->body->statements[1]
->As<ast::AssignmentStatement>()
->lhs()
->As<ast::ArrayAccessorExpression>()
->array()
->As<ast::UnaryOpExpression>()
->expr()
->As<ast::UnaryOpExpression>()
->expr());
->lhs->As<ast::ArrayAccessorExpression>()
->array->As<ast::UnaryOpExpression>()
->expr->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[0]);
@ -654,19 +613,15 @@ fn f() {
NodeIdMap node_id_map(program);
auto use_id = node_id_map.GetId(program.AST()
auto use_id = node_id_map.GetId(
program.AST()
.Functions()[0]
->body()
->statements()[1]
->body->statements[1]
->As<ast::VariableDeclStatement>()
->variable()
->constructor()
->As<ast::ArrayAccessorExpression>()
->array()
->As<ast::UnaryOpExpression>()
->expr()
->As<ast::UnaryOpExpression>()
->expr());
->variable->constructor->As<ast::ArrayAccessorExpression>()
->array->As<ast::UnaryOpExpression>()
->expr->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[0]);
@ -694,25 +649,21 @@ fn f() {
NodeIdMap node_id_map(program);
auto use_id = node_id_map.GetId(program.AST()
auto use_id = node_id_map.GetId(
program.AST()
.Functions()[0]
->body()
->statements()[3]
->body->statements[3]
->As<ast::VariableDeclStatement>()
->variable()
->constructor()
->As<ast::ArrayAccessorExpression>()
->array()
->As<ast::UnaryOpExpression>()
->expr());
->variable->constructor->As<ast::ArrayAccessorExpression>()
->array->As<ast::UnaryOpExpression>()
->expr);
ASSERT_NE(use_id, 0);
auto replacement_id = node_id_map.GetId(program.AST()
.Functions()[0]
->body()
->statements()[2]
->body->statements[2]
->As<ast::VariableDeclStatement>()
->variable());
->variable);
ASSERT_NE(replacement_id, 0);
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
.IsApplicable(program, node_id_map));

View File

@ -54,7 +54,7 @@ std::vector<const sem::Variable*> GetAllVarsInScope(
// Walk up the hierarchy of blocks in which `curr_stmt` is contained.
for (const auto* block = curr_stmt->Block(); block;
block = tint::As<sem::BlockStatement>(block->Parent())) {
for (const auto* stmt : *block->Declaration()) {
for (const auto* stmt : block->Declaration()->statements) {
if (stmt == curr_stmt->Declaration()) {
// `curr_stmt` was found. This is only possible if `block is the
// enclosing block of `curr_stmt` since the AST nodes are not shared.
@ -65,7 +65,7 @@ std::vector<const sem::Variable*> GetAllVarsInScope(
}
if (const auto* var_node = tint::As<ast::VariableDeclStatement>(stmt)) {
const auto* sem_var = program.Sem().Get(var_node->variable());
const auto* sem_var = program.Sem().Get(var_node->variable);
if (pred(sem_var)) {
result.push_back(sem_var);
}
@ -74,7 +74,7 @@ std::vector<const sem::Variable*> GetAllVarsInScope(
}
// Process function parameters.
for (const auto* param : curr_stmt->Function()->params()) {
for (const auto* param : curr_stmt->Function()->params) {
const auto* sem_var = program.Sem().Get(param);
if (pred(sem_var)) {
result.push_back(sem_var);

View File

@ -21,12 +21,9 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Alias);
namespace tint {
namespace ast {
Alias::Alias(ProgramID program_id,
const Source& source,
const Symbol& name,
Type* subtype)
: Base(program_id, source, name), subtype_(subtype) {
TINT_ASSERT(AST, subtype_);
Alias::Alias(ProgramID pid, const Source& src, const Symbol& n, Type* subtype)
: Base(pid, src, n), type(subtype) {
TINT_ASSERT(AST, type);
}
Alias::Alias(Alias&&) = default;
@ -35,9 +32,9 @@ Alias::~Alias() = default;
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());
auto* ty = ctx->Clone(type());
auto src = ctx->Clone(source);
auto sym = ctx->Clone(name);
auto* ty = ctx->Clone(type);
return ctx->dst->create<Alias>(src, sym, ty);
}

View File

@ -26,32 +26,23 @@ namespace ast {
class Alias : public Castable<Alias, TypeDecl> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this node
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param name the symbol for the alias
/// @param subtype the alias'd type
Alias(ProgramID program_id,
const Source& source,
const Symbol& name,
Type* subtype);
Alias(ProgramID pid, const Source& src, const Symbol& name, Type* subtype);
/// Move constructor
Alias(Alias&&);
/// Destructor
~Alias() override;
/// [DEPRECATED] use name()
/// @returns the alias symbol
Symbol symbol() const { return name(); }
/// @returns the alias type
Type* type() const { return subtype_; }
/// 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;
private:
Type* const subtype_;
/// the alias type
Type* const type;
};
} // namespace ast

View File

@ -36,8 +36,8 @@ using AstAliasTest = TestHelper;
TEST_F(AstAliasTest, Create) {
auto* u32 = create<U32>();
auto* a = Alias("a_type", u32);
EXPECT_EQ(a->symbol(), Symbol(1, ID()));
EXPECT_EQ(a->type(), u32);
EXPECT_EQ(a->name, Symbol(1, ID()));
EXPECT_EQ(a->type, u32);
}
} // namespace

View File

@ -29,14 +29,14 @@ std::string SizeExprToString(const ast::Expression* size,
const SymbolTable* symbols = nullptr) {
if (auto* ident = size->As<ast::IdentifierExpression>()) {
if (symbols) {
return symbols->NameFor(ident->symbol());
return symbols->NameFor(ident->symbol);
}
return "<unknown>";
}
if (auto* scalar = size->As<ast::ScalarConstructorExpression>()) {
auto* literal = scalar->literal()->As<ast::IntLiteral>();
auto* literal = scalar->literal->As<ast::IntLiteral>();
if (literal) {
return std::to_string(literal->value_as_u32());
return std::to_string(literal->ValueAsU32());
}
}
// This will never be exposed to the user as the Resolver will reject this
@ -45,15 +45,12 @@ std::string SizeExprToString(const ast::Expression* size,
}
} // namespace
Array::Array(ProgramID program_id,
const Source& source,
Array::Array(ProgramID pid,
const Source& src,
Type* subtype,
ast::Expression* size,
ast::DecorationList decorations)
: Base(program_id, source),
subtype_(subtype),
size_(size),
decos_(decorations) {}
ast::Expression* cnt,
ast::DecorationList decos)
: Base(pid, src), type(subtype), count(cnt), decorations(decos) {}
Array::Array(Array&&) = default;
@ -61,14 +58,14 @@ Array::~Array() = default;
std::string Array::FriendlyName(const SymbolTable& symbols) const {
std::ostringstream out;
for (auto* deco : decos_) {
for (auto* deco : decorations) {
if (auto* stride = deco->As<ast::StrideDecoration>()) {
out << "[[stride(" << stride->stride() << ")]] ";
out << "[[stride(" << stride->stride << ")]] ";
}
}
out << "array<" << subtype_->FriendlyName(symbols);
out << "array<" << type->FriendlyName(symbols);
if (!IsRuntimeArray()) {
out << ", " << SizeExprToString(size_, &symbols);
out << ", " << SizeExprToString(count, &symbols);
}
out << ">";
return out.str();
@ -76,11 +73,11 @@ std::string Array::FriendlyName(const SymbolTable& symbols) 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());
auto* size = ctx->Clone(Size());
auto decos = ctx->Clone(decorations());
return ctx->dst->create<Array>(src, ty, size, decos);
auto src = ctx->Clone(source);
auto* ty = ctx->Clone(type);
auto* cnt = ctx->Clone(count);
auto decos = ctx->Clone(decorations);
return ctx->dst->create<Array>(src, ty, cnt, decos);
}
} // namespace ast

View File

@ -30,16 +30,16 @@ class Expression;
class Array : public Castable<Array, Type> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this node
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param subtype the type of the array elements
/// @param size the number of elements in the array. nullptr represents a
/// @param count the number of elements in the array. nullptr represents a
/// runtime-sized array.
/// @param decorations the array decorations
Array(ProgramID program_id,
const Source& source,
Array(ProgramID pid,
const Source& src,
Type* subtype,
ast::Expression* size,
ast::Expression* count,
ast::DecorationList decorations);
/// Move constructor
Array(Array&&);
@ -47,16 +47,7 @@ class Array : public Castable<Array, Type> {
/// @returns true if this is a runtime array.
/// i.e. the size is determined at runtime
bool IsRuntimeArray() const { return size_ == nullptr; }
/// @returns the array decorations
const ast::DecorationList& decorations() const { return decos_; }
/// @returns the array type
Type* type() const { return subtype_; }
/// @returns the array size, or nullptr for a runtime array
ast::Expression* Size() const { return size_; }
bool IsRuntimeArray() const { return count == nullptr; }
/// @param symbols the program's symbol table
/// @returns the name for this type that closely resembles how it would be
@ -68,10 +59,14 @@ class Array : public Castable<Array, Type> {
/// @return the newly cloned type
Array* Clone(CloneContext* ctx) const override;
private:
Type* const subtype_;
ast::Expression* const size_;
ast::DecorationList const decos_;
/// the array element type
Type* const type;
/// the array size in elements, or nullptr for a runtime array
ast::Expression* const count;
/// the array decorations
ast::DecorationList const decorations;
};
} // namespace ast

View File

@ -21,15 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ArrayAccessorExpression);
namespace tint {
namespace ast {
ArrayAccessorExpression::ArrayAccessorExpression(ProgramID program_id,
const Source& source,
Expression* array,
Expression* idx_expr)
: Base(program_id, source), array_(array), idx_expr_(idx_expr) {
TINT_ASSERT(AST, array_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, array_, program_id);
TINT_ASSERT(AST, idx_expr_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, idx_expr_, program_id);
ArrayAccessorExpression::ArrayAccessorExpression(ProgramID pid,
const Source& src,
Expression* arr,
Expression* idx)
: Base(pid, src), array(arr), index(idx) {
TINT_ASSERT(AST, array);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, array, program_id);
TINT_ASSERT(AST, idx);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, idx, program_id);
}
ArrayAccessorExpression::ArrayAccessorExpression(ArrayAccessorExpression&&) =
@ -40,9 +40,9 @@ ArrayAccessorExpression::~ArrayAccessorExpression() = default;
ArrayAccessorExpression* ArrayAccessorExpression::Clone(
CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source());
auto* arr = ctx->Clone(array_);
auto* idx = ctx->Clone(idx_expr_);
auto src = ctx->Clone(source);
auto* arr = ctx->Clone(array);
auto* idx = ctx->Clone(index);
return ctx->dst->create<ArrayAccessorExpression>(src, arr, idx);
}

View File

@ -27,33 +27,30 @@ class ArrayAccessorExpression
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the array accessor source
/// @param array the array
/// @param idx_expr the index expression
/// @param arr the array
/// @param idx the index expression
ArrayAccessorExpression(ProgramID program_id,
const Source& source,
Expression* array,
Expression* idx_expr);
Expression* arr,
Expression* idx);
/// Move constructor
ArrayAccessorExpression(ArrayAccessorExpression&&);
~ArrayAccessorExpression() override;
/// @returns the array
Expression* array() const { return array_; }
/// @returns the index expression
Expression* idx_expr() const { return idx_expr_; }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
ArrayAccessorExpression* Clone(CloneContext* ctx) const override;
/// the array
Expression* const array;
/// the index expression
Expression* const index;
private:
ArrayAccessorExpression(const ArrayAccessorExpression&) = delete;
Expression* const array_;
Expression* const idx_expr_;
};
} // namespace ast

View File

@ -26,8 +26,8 @@ TEST_F(ArrayAccessorExpressionTest, Create) {
auto* idx = Expr("idx");
auto* exp = create<ArrayAccessorExpression>(ary, idx);
ASSERT_EQ(exp->array(), ary);
ASSERT_EQ(exp->idx_expr(), idx);
ASSERT_EQ(exp->array, ary);
ASSERT_EQ(exp->index, idx);
}
TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
@ -36,7 +36,7 @@ TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
auto* exp = create<ArrayAccessorExpression>(Source{Source::Location{20, 2}},
ary, idx);
auto src = exp->source();
auto src = exp->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}

View File

@ -24,10 +24,10 @@ using AstArrayTest = TestHelper;
TEST_F(AstArrayTest, CreateSizedArray) {
auto* u32 = create<U32>();
auto* size = Expr(3);
auto* arr = create<Array>(u32, size, DecorationList{});
EXPECT_EQ(arr->type(), u32);
EXPECT_EQ(arr->Size(), size);
auto* count = Expr(3);
auto* arr = create<Array>(u32, count, DecorationList{});
EXPECT_EQ(arr->type, u32);
EXPECT_EQ(arr->count, count);
EXPECT_TRUE(arr->Is<Array>());
EXPECT_FALSE(arr->IsRuntimeArray());
}
@ -35,8 +35,8 @@ TEST_F(AstArrayTest, CreateSizedArray) {
TEST_F(AstArrayTest, CreateRuntimeArray) {
auto* u32 = create<U32>();
auto* arr = create<Array>(u32, nullptr, DecorationList{});
EXPECT_EQ(arr->type(), u32);
EXPECT_EQ(arr->Size(), nullptr);
EXPECT_EQ(arr->type, u32);
EXPECT_EQ(arr->count, nullptr);
EXPECT_TRUE(arr->Is<Array>());
EXPECT_TRUE(arr->IsRuntimeArray());
}

View File

@ -21,15 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::AssignmentStatement);
namespace tint {
namespace ast {
AssignmentStatement::AssignmentStatement(ProgramID program_id,
const Source& source,
Expression* lhs,
Expression* rhs)
: Base(program_id, source), lhs_(lhs), rhs_(rhs) {
TINT_ASSERT(AST, lhs_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs_, program_id);
TINT_ASSERT(AST, rhs_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs_, program_id);
AssignmentStatement::AssignmentStatement(ProgramID pid,
const Source& src,
Expression* l,
Expression* r)
: Base(pid, src), lhs(l), rhs(r) {
TINT_ASSERT(AST, lhs);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id);
TINT_ASSERT(AST, rhs);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs, program_id);
}
AssignmentStatement::AssignmentStatement(AssignmentStatement&&) = default;
@ -38,9 +38,9 @@ AssignmentStatement::~AssignmentStatement() = default;
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_);
auto* r = ctx->Clone(rhs_);
auto src = ctx->Clone(source);
auto* l = ctx->Clone(lhs);
auto* r = ctx->Clone(rhs);
return ctx->dst->create<AssignmentStatement>(src, l, r);
}

View File

@ -37,22 +37,20 @@ class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
AssignmentStatement(AssignmentStatement&&);
~AssignmentStatement() override;
/// @returns the left side expression
Expression* lhs() const { return lhs_; }
/// @returns the right side expression
Expression* rhs() const { return rhs_; }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
AssignmentStatement* Clone(CloneContext* ctx) const override;
/// left side expression
Expression* const lhs;
/// right side expression
Expression* const rhs;
private:
AssignmentStatement(const AssignmentStatement&) = delete;
Expression* const lhs_;
Expression* const rhs_;
};
} // namespace ast

View File

@ -28,8 +28,8 @@ TEST_F(AssignmentStatementTest, Creation) {
auto* rhs = Expr("rhs");
auto* stmt = create<AssignmentStatement>(lhs, rhs);
EXPECT_EQ(stmt->lhs(), lhs);
EXPECT_EQ(stmt->rhs(), rhs);
EXPECT_EQ(stmt->lhs, lhs);
EXPECT_EQ(stmt->rhs, rhs);
}
TEST_F(AssignmentStatementTest, CreationWithSource) {
@ -38,7 +38,7 @@ TEST_F(AssignmentStatementTest, CreationWithSource) {
auto* stmt =
create<AssignmentStatement>(Source{Source::Location{20, 2}}, lhs, rhs);
auto src = stmt->source();
auto src = stmt->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}

View File

@ -31,8 +31,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Type);
namespace tint {
namespace ast {
Type::Type(ProgramID program_id, const Source& source)
: Base(program_id, source) {}
Type::Type(ProgramID pid, const Source& src) : Base(pid, src) {}
Type::Type(Type&&) = default;

View File

@ -21,12 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Atomic);
namespace tint {
namespace ast {
Atomic::Atomic(ProgramID program_id, const Source& source, Type* const subtype)
: Base(program_id, source), subtype_(subtype) {}
Atomic::Atomic(ProgramID pid, const Source& src, Type* const subtype)
: Base(pid, src), type(subtype) {}
std::string Atomic::FriendlyName(const SymbolTable& symbols) const {
std::ostringstream out;
out << "atomic<" << subtype_->FriendlyName(symbols) << ">";
out << "atomic<" << type->FriendlyName(symbols) << ">";
return out.str();
}
@ -36,8 +36,8 @@ Atomic::~Atomic() = default;
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(type());
auto src = ctx->Clone(source);
auto* ty = ctx->Clone(const_cast<Type*>(type));
return ctx->dst->create<Atomic>(src, ty);
}

View File

@ -26,17 +26,14 @@ namespace ast {
class Atomic : public Castable<Atomic, Type> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this node
/// @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 program_id, const Source& source, Type* const subtype);
Atomic(ProgramID pid, const Source& src, Type* const subtype);
/// Move constructor
Atomic(Atomic&&);
~Atomic() override;
/// @returns the pointee type
Type* type() const { return const_cast<Type*>(subtype_); }
/// @param symbols the program's symbol table
/// @returns the name for this type that closely resembles how it would be
/// declared in WGSL.
@ -47,8 +44,8 @@ class Atomic : public Castable<Atomic, Type> {
/// @return the newly cloned type
Atomic* Clone(CloneContext* ctx) const override;
private:
Type const* const subtype_;
/// the pointee type
Type const* const type;
};
} // namespace ast

View File

@ -26,7 +26,7 @@ using AstAtomicTest = TestHelper;
TEST_F(AstAtomicTest, Creation) {
auto* i32 = create<I32>();
auto* p = create<Atomic>(i32);
EXPECT_EQ(p->type(), i32);
EXPECT_EQ(p->type, i32);
}
TEST_F(AstAtomicTest, FriendlyName) {

View File

@ -21,17 +21,17 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BinaryExpression);
namespace tint {
namespace ast {
BinaryExpression::BinaryExpression(ProgramID program_id,
const Source& source,
BinaryOp op,
Expression* lhs,
Expression* rhs)
: Base(program_id, source), op_(op), lhs_(lhs), rhs_(rhs) {
TINT_ASSERT(AST, lhs_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs_, program_id);
TINT_ASSERT(AST, rhs_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs_, program_id);
TINT_ASSERT(AST, op_ != BinaryOp::kNone);
BinaryExpression::BinaryExpression(ProgramID pid,
const Source& src,
BinaryOp o,
Expression* l,
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);
TINT_ASSERT(AST, rhs);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs, program_id);
TINT_ASSERT(AST, op != BinaryOp::kNone);
}
BinaryExpression::BinaryExpression(BinaryExpression&&) = default;
@ -40,10 +40,10 @@ BinaryExpression::~BinaryExpression() = default;
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_);
auto* r = ctx->Clone(rhs_);
return ctx->dst->create<BinaryExpression>(src, op_, l, r);
auto src = ctx->Clone(source);
auto* l = ctx->Clone(lhs);
auto* r = ctx->Clone(rhs);
return ctx->dst->create<BinaryExpression>(src, op, l, r);
}
} // namespace ast

View File

@ -61,45 +61,42 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
BinaryExpression(BinaryExpression&&);
~BinaryExpression() override;
/// @returns the binary op type
BinaryOp op() const { return op_; }
/// @returns true if the op is and
bool IsAnd() const { return op_ == BinaryOp::kAnd; }
bool IsAnd() const { return op == BinaryOp::kAnd; }
/// @returns true if the op is or
bool IsOr() const { return op_ == BinaryOp::kOr; }
bool IsOr() const { return op == BinaryOp::kOr; }
/// @returns true if the op is xor
bool IsXor() const { return op_ == BinaryOp::kXor; }
bool IsXor() const { return op == BinaryOp::kXor; }
/// @returns true if the op is logical and
bool IsLogicalAnd() const { return op_ == BinaryOp::kLogicalAnd; }
bool IsLogicalAnd() const { return op == BinaryOp::kLogicalAnd; }
/// @returns true if the op is logical or
bool IsLogicalOr() const { return op_ == BinaryOp::kLogicalOr; }
bool IsLogicalOr() const { return op == BinaryOp::kLogicalOr; }
/// @returns true if the op is equal
bool IsEqual() const { return op_ == BinaryOp::kEqual; }
bool IsEqual() const { return op == BinaryOp::kEqual; }
/// @returns true if the op is not equal
bool IsNotEqual() const { return op_ == BinaryOp::kNotEqual; }
bool IsNotEqual() const { return op == BinaryOp::kNotEqual; }
/// @returns true if the op is less than
bool IsLessThan() const { return op_ == BinaryOp::kLessThan; }
bool IsLessThan() const { return op == BinaryOp::kLessThan; }
/// @returns true if the op is greater than
bool IsGreaterThan() const { return op_ == BinaryOp::kGreaterThan; }
bool IsGreaterThan() const { return op == BinaryOp::kGreaterThan; }
/// @returns true if the op is less than equal
bool IsLessThanEqual() const { return op_ == BinaryOp::kLessThanEqual; }
bool IsLessThanEqual() const { return op == BinaryOp::kLessThanEqual; }
/// @returns true if the op is greater than equal
bool IsGreaterThanEqual() const { return op_ == BinaryOp::kGreaterThanEqual; }
bool IsGreaterThanEqual() const { return op == BinaryOp::kGreaterThanEqual; }
/// @returns true if the op is shift left
bool IsShiftLeft() const { return op_ == BinaryOp::kShiftLeft; }
bool IsShiftLeft() const { return op == BinaryOp::kShiftLeft; }
/// @returns true if the op is shift right
bool IsShiftRight() const { return op_ == BinaryOp::kShiftRight; }
bool IsShiftRight() const { return op == BinaryOp::kShiftRight; }
/// @returns true if the op is add
bool IsAdd() const { return op_ == BinaryOp::kAdd; }
bool IsAdd() const { return op == BinaryOp::kAdd; }
/// @returns true if the op is subtract
bool IsSubtract() const { return op_ == BinaryOp::kSubtract; }
bool IsSubtract() const { return op == BinaryOp::kSubtract; }
/// @returns true if the op is multiply
bool IsMultiply() const { return op_ == BinaryOp::kMultiply; }
bool IsMultiply() const { return op == BinaryOp::kMultiply; }
/// @returns true if the op is divide
bool IsDivide() const { return op_ == BinaryOp::kDivide; }
bool IsDivide() const { return op == BinaryOp::kDivide; }
/// @returns true if the op is modulo
bool IsModulo() const { return op_ == BinaryOp::kModulo; }
bool IsModulo() const { return op == BinaryOp::kModulo; }
/// @returns true if the op is an arithmetic operation
bool IsArithmetic() const;
/// @returns true if the op is a comparison operation
@ -109,27 +106,25 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
/// @returns true if the op is a bit shift operation
bool IsBitshift() const;
/// @returns the left side expression
Expression* lhs() const { return lhs_; }
/// @returns the right side expression
Expression* rhs() const { return rhs_; }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
BinaryExpression* Clone(CloneContext* ctx) const override;
/// the binary op type
BinaryOp const op;
/// the left side expression
Expression* const lhs;
/// the right side expression
Expression* const rhs;
private:
BinaryExpression(const BinaryExpression&) = delete;
BinaryOp const op_;
Expression* const lhs_;
Expression* const rhs_;
};
inline bool BinaryExpression::IsArithmetic() const {
switch (op_) {
switch (op) {
case ast::BinaryOp::kAdd:
case ast::BinaryOp::kSubtract:
case ast::BinaryOp::kMultiply:
@ -142,7 +137,7 @@ inline bool BinaryExpression::IsArithmetic() const {
}
inline bool BinaryExpression::IsComparison() const {
switch (op_) {
switch (op) {
case ast::BinaryOp::kEqual:
case ast::BinaryOp::kNotEqual:
case ast::BinaryOp::kLessThan:
@ -156,7 +151,7 @@ inline bool BinaryExpression::IsComparison() const {
}
inline bool BinaryExpression::IsBitwise() const {
switch (op_) {
switch (op) {
case ast::BinaryOp::kAnd:
case ast::BinaryOp::kOr:
case ast::BinaryOp::kXor:
@ -167,7 +162,7 @@ inline bool BinaryExpression::IsBitwise() const {
}
inline bool BinaryExpression::IsBitshift() const {
switch (op_) {
switch (op) {
case ast::BinaryOp::kShiftLeft:
case ast::BinaryOp::kShiftRight:
return true;

View File

@ -26,9 +26,9 @@ TEST_F(BinaryExpressionTest, Creation) {
auto* rhs = Expr("rhs");
auto* r = create<BinaryExpression>(BinaryOp::kEqual, lhs, rhs);
EXPECT_EQ(r->lhs(), lhs);
EXPECT_EQ(r->rhs(), rhs);
EXPECT_EQ(r->op(), BinaryOp::kEqual);
EXPECT_EQ(r->lhs, lhs);
EXPECT_EQ(r->rhs, rhs);
EXPECT_EQ(r->op, BinaryOp::kEqual);
}
TEST_F(BinaryExpressionTest, Creation_WithSource) {
@ -37,7 +37,7 @@ TEST_F(BinaryExpressionTest, Creation_WithSource) {
auto* r = create<BinaryExpression>(Source{Source::Location{20, 2}},
BinaryOp::kEqual, lhs, rhs);
auto src = r->source();
auto src = r->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}

View File

@ -23,21 +23,21 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BindingDecoration);
namespace tint {
namespace ast {
BindingDecoration::BindingDecoration(ProgramID program_id,
const Source& source,
BindingDecoration::BindingDecoration(ProgramID pid,
const Source& src,
uint32_t val)
: Base(program_id, source), value_(val) {}
: Base(pid, src), value(val) {}
BindingDecoration::~BindingDecoration() = default;
std::string BindingDecoration::name() const {
std::string BindingDecoration::Name() const {
return "binding";
}
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_);
auto src = ctx->Clone(source);
return ctx->dst->create<BindingDecoration>(src, value);
}
} // namespace ast

View File

@ -26,17 +26,14 @@ namespace ast {
class BindingDecoration : public Castable<BindingDecoration, Decoration> {
public:
/// constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this decoration
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param value the binding value
BindingDecoration(ProgramID program_id, const Source& source, uint32_t value);
BindingDecoration(ProgramID pid, const Source& src, uint32_t value);
~BindingDecoration() override;
/// @returns the binding value
uint32_t value() const { return value_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
std::string Name() const override;
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
@ -44,8 +41,8 @@ class BindingDecoration : public Castable<BindingDecoration, Decoration> {
/// @return the newly cloned node
BindingDecoration* Clone(CloneContext* ctx) const override;
private:
uint32_t const value_;
/// the binding value
uint32_t const value;
};
} // namespace ast

View File

@ -23,7 +23,7 @@ using BindingDecorationTest = TestHelper;
TEST_F(BindingDecorationTest, Creation) {
auto* d = create<BindingDecoration>(2);
EXPECT_EQ(2u, d->value());
EXPECT_EQ(2u, d->value);
}
} // namespace

View File

@ -21,13 +21,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BitcastExpression);
namespace tint {
namespace ast {
BitcastExpression::BitcastExpression(ProgramID program_id,
const Source& source,
ast::Type* type,
Expression* expr)
: Base(program_id, source), type_(type), expr_(expr) {
TINT_ASSERT(AST, type_);
TINT_ASSERT(AST, expr_);
BitcastExpression::BitcastExpression(ProgramID pid,
const Source& src,
ast::Type* t,
Expression* e)
: Base(pid, src), type(t), expr(e) {
TINT_ASSERT(AST, type);
TINT_ASSERT(AST, expr);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id);
}
@ -36,10 +36,10 @@ BitcastExpression::~BitcastExpression() = default;
BitcastExpression* BitcastExpression::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source());
auto* ty = ctx->Clone(type());
auto* e = ctx->Clone(expr_);
return ctx->dst->create<BitcastExpression>(src, ty, e);
auto src = ctx->Clone(source);
auto* t = ctx->Clone(type);
auto* e = ctx->Clone(expr);
return ctx->dst->create<BitcastExpression>(src, t, e);
}
} // namespace ast

View File

@ -39,22 +39,19 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
BitcastExpression(BitcastExpression&&);
~BitcastExpression() override;
/// @returns the left side expression
ast::Type* type() const { return type_; }
/// @returns the expression
Expression* expr() const { return expr_; }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
BitcastExpression* Clone(CloneContext* ctx) const override;
/// the target cast type
ast::Type* const type;
/// the expression
Expression* const expr;
private:
BitcastExpression(const BitcastExpression&) = delete;
ast::Type* const type_;
Expression* const expr_;
};
} // namespace ast

View File

@ -27,8 +27,8 @@ TEST_F(BitcastExpressionTest, Create) {
auto* expr = Expr("expr");
auto* exp = create<BitcastExpression>(ty.f32(), expr);
EXPECT_TRUE(exp->type()->Is<ast::F32>());
ASSERT_EQ(exp->expr(), expr);
EXPECT_TRUE(exp->type->Is<ast::F32>());
ASSERT_EQ(exp->expr, expr);
}
TEST_F(BitcastExpressionTest, CreateWithSource) {
@ -36,7 +36,7 @@ TEST_F(BitcastExpressionTest, CreateWithSource) {
auto* exp = create<BitcastExpression>(Source{Source::Location{20, 2}},
ty.f32(), expr);
auto src = exp->source();
auto src = exp->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}

View File

@ -21,11 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BlockStatement);
namespace tint {
namespace ast {
BlockStatement::BlockStatement(ProgramID program_id,
const Source& source,
const StatementList& statements)
: Base(program_id, source), statements_(std::move(statements)) {
for (auto* stmt : *this) {
BlockStatement::BlockStatement(ProgramID pid,
const Source& src,
const StatementList& stmts)
: Base(pid, src), statements(std::move(stmts)) {
for (auto* stmt : statements) {
TINT_ASSERT(AST, stmt);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, stmt, program_id);
}
@ -37,8 +37,8 @@ BlockStatement::~BlockStatement() = default;
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_);
auto src = ctx->Clone(source);
auto stmts = ctx->Clone(statements);
return ctx->dst->create<BlockStatement>(src, stmts);
}

View File

@ -36,40 +36,13 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
BlockStatement(BlockStatement&&);
~BlockStatement() override;
/// @returns the StatementList
const StatementList& list() const { return statements_; }
/// @returns true if the block is empty
bool empty() const { return statements_.empty(); }
/// @returns the number of statements directly in the block
size_t size() const { return statements_.size(); }
/// @returns true if the block has no statements
bool Empty() const { return statements.empty(); }
/// @returns the last statement in the block or nullptr if block empty
const Statement* last() const {
return statements_.empty() ? nullptr : statements_.back();
Statement* Last() const {
return statements.empty() ? nullptr : statements.back();
}
/// @returns the last statement in the block or nullptr if block empty
Statement* last() {
return statements_.empty() ? nullptr : statements_.back();
}
/// Retrieves the statement at `idx`
/// @param idx the index. The index is not bounds checked.
/// @returns the statement at `idx`
Statement* get(size_t idx) const { return statements_[idx]; }
/// Retrieves the statement at `idx`
/// @param idx the index. The index is not bounds checked.
/// @returns the statement at `idx`
Statement* operator[](size_t idx) const { return statements_[idx]; }
/// @returns the beginning iterator
StatementList::const_iterator begin() const { return statements_.begin(); }
/// @returns the ending iterator
StatementList::const_iterator end() const { return statements_.end(); }
/// @returns the statement list
const StatementList& statements() const { return statements_; }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
@ -77,10 +50,11 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
/// @return the newly cloned node
BlockStatement* Clone(CloneContext* ctx) const override;
/// the statement list
StatementList const statements;
private:
BlockStatement(const BlockStatement&) = delete;
StatementList const statements_;
};
} // namespace ast

View File

@ -29,14 +29,14 @@ TEST_F(BlockStatementTest, Creation) {
auto* b = create<BlockStatement>(StatementList{d});
ASSERT_EQ(b->size(), 1u);
EXPECT_EQ((*b)[0], ptr);
ASSERT_EQ(b->statements.size(), 1u);
EXPECT_EQ(b->statements[0], ptr);
}
TEST_F(BlockStatementTest, Creation_WithSource) {
auto* b = create<BlockStatement>(Source{Source::Location{20, 2}},
ast::StatementList{});
auto src = b->source();
auto src = b->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}

View File

@ -21,8 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Bool);
namespace tint {
namespace ast {
Bool::Bool(ProgramID program_id, const Source& source)
: Base(program_id, source) {}
Bool::Bool(ProgramID pid, const Source& src) : Base(pid, src) {}
Bool::Bool(Bool&&) = default;
@ -33,7 +32,7 @@ std::string Bool::FriendlyName(const SymbolTable&) const {
}
Bool* Bool::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source());
auto src = ctx->Clone(source);
return ctx->dst->create<Bool>(src);
}

View File

@ -32,9 +32,9 @@ namespace ast {
class Bool : public Castable<Bool, Type> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this node
Bool(ProgramID program_id, const Source& source);
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
Bool(ProgramID pid, const Source& src);
/// Move constructor
Bool(Bool&&);
~Bool() override;

View File

@ -21,19 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BoolLiteral);
namespace tint {
namespace ast {
BoolLiteral::BoolLiteral(ProgramID program_id, const Source& source, bool value)
: Base(program_id, source), value_(value) {}
BoolLiteral::BoolLiteral(ProgramID pid, const Source& src, bool val)
: Base(pid, src), value(val) {}
BoolLiteral::~BoolLiteral() = default;
std::string BoolLiteral::name() const {
return value_ ? "__bool_true" : "__bool_false";
}
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_);
auto src = ctx->Clone(source);
return ctx->dst->create<BoolLiteral>(src, value);
}
} // namespace ast

View File

@ -26,19 +26,12 @@ namespace ast {
class BoolLiteral : public Castable<BoolLiteral, Literal> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the input source
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param value the bool literals value
BoolLiteral(ProgramID program_id, const Source& source, bool value);
BoolLiteral(ProgramID pid, const Source& src, bool value);
~BoolLiteral() override;
/// @returns true if the bool literal is true
bool IsTrue() const { return value_; }
/// @returns true if the bool literal is false
bool IsFalse() const { return !value_; }
/// @returns the name for this literal. This name is unique to this value.
std::string name() const override;
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
@ -46,8 +39,8 @@ class BoolLiteral : public Castable<BoolLiteral, Literal> {
/// @return the newly cloned node
BoolLiteral* Clone(CloneContext* ctx) const override;
private:
bool const value_;
/// The boolean literal value
bool const value;
};
} // namespace ast

View File

@ -23,15 +23,13 @@ using BoolLiteralTest = TestHelper;
TEST_F(BoolLiteralTest, True) {
auto* b = create<BoolLiteral>(true);
ASSERT_TRUE(b->Is<BoolLiteral>());
ASSERT_TRUE(b->IsTrue());
ASSERT_FALSE(b->IsFalse());
ASSERT_TRUE(b->value);
}
TEST_F(BoolLiteralTest, False) {
auto* b = create<BoolLiteral>(false);
ASSERT_TRUE(b->Is<BoolLiteral>());
ASSERT_FALSE(b->IsTrue());
ASSERT_TRUE(b->IsFalse());
ASSERT_FALSE(b->value);
}
} // namespace

View File

@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BreakStatement);
namespace tint {
namespace ast {
BreakStatement::BreakStatement(ProgramID program_id, const Source& source)
: Base(program_id, source) {}
BreakStatement::BreakStatement(ProgramID pid, const Source& src)
: Base(pid, src) {}
BreakStatement::BreakStatement(BreakStatement&&) = default;
@ -30,7 +30,7 @@ BreakStatement::~BreakStatement() = default;
BreakStatement* BreakStatement::Clone(CloneContext* ctx) const {
// 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);
}

View File

@ -24,9 +24,9 @@ namespace ast {
class BreakStatement : public Castable<BreakStatement, Statement> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the break statement source
BreakStatement(ProgramID program_id, const Source& source);
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
BreakStatement(ProgramID pid, const Source& src);
/// Move constructor
BreakStatement(BreakStatement&&);
~BreakStatement() override;

View File

@ -24,7 +24,7 @@ using BreakStatementTest = TestHelper;
TEST_F(BreakStatementTest, Creation_WithSource) {
auto* stmt = create<BreakStatement>(Source{Source::Location{20, 2}});
auto src = stmt->source();
auto src = stmt->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}

View File

@ -23,21 +23,21 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BuiltinDecoration);
namespace tint {
namespace ast {
BuiltinDecoration::BuiltinDecoration(ProgramID program_id,
const Source& source,
Builtin builtin)
: Base(program_id, source), builtin_(builtin) {}
BuiltinDecoration::BuiltinDecoration(ProgramID pid,
const Source& src,
Builtin b)
: Base(pid, src), builtin(b) {}
BuiltinDecoration::~BuiltinDecoration() = default;
std::string BuiltinDecoration::name() const {
std::string BuiltinDecoration::Name() const {
return "builtin";
}
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_);
auto src = ctx->Clone(source);
return ctx->dst->create<BuiltinDecoration>(src, builtin);
}
} // namespace ast

View File

@ -27,19 +27,14 @@ namespace ast {
class BuiltinDecoration : public Castable<BuiltinDecoration, Decoration> {
public:
/// constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this decoration
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param builtin the builtin value
BuiltinDecoration(ProgramID program_id,
const Source& source,
Builtin builtin);
BuiltinDecoration(ProgramID pid, const Source& src, Builtin builtin);
~BuiltinDecoration() override;
/// @returns the builtin value
Builtin value() const { return builtin_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
std::string Name() const override;
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
@ -47,8 +42,8 @@ class BuiltinDecoration : public Castable<BuiltinDecoration, Decoration> {
/// @return the newly cloned node
BuiltinDecoration* Clone(CloneContext* ctx) const override;
private:
Builtin const builtin_;
/// The builtin value
Builtin const builtin;
};
} // namespace ast

View File

@ -23,7 +23,7 @@ using BuiltinDecorationTest = TestHelper;
TEST_F(BuiltinDecorationTest, Creation) {
auto* d = create<BuiltinDecoration>(Builtin::kFragDepth);
EXPECT_EQ(Builtin::kFragDepth, d->value());
EXPECT_EQ(Builtin::kFragDepth, d->builtin);
}
} // namespace

View File

@ -21,14 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CallExpression);
namespace tint {
namespace ast {
CallExpression::CallExpression(ProgramID program_id,
const Source& source,
IdentifierExpression* func,
ExpressionList args)
: Base(program_id, source), func_(func), args_(args) {
TINT_ASSERT(AST, func_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func_, program_id);
for (auto* arg : args_) {
CallExpression::CallExpression(ProgramID pid,
const Source& src,
IdentifierExpression* fn,
ExpressionList a)
: Base(pid, src), func(fn), args(a) {
TINT_ASSERT(AST, func);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id);
for (auto* arg : args) {
TINT_ASSERT(AST, arg);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, arg, program_id);
}
@ -40,9 +40,9 @@ CallExpression::~CallExpression() = default;
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_);
auto p = ctx->Clone(args_);
auto src = ctx->Clone(source);
auto* fn = ctx->Clone(func);
auto p = ctx->Clone(args);
return ctx->dst->create<CallExpression>(src, fn, p);
}

View File

@ -39,22 +39,19 @@ class CallExpression : public Castable<CallExpression, Expression> {
CallExpression(CallExpression&&);
~CallExpression() override;
/// @returns the func
IdentifierExpression* func() const { return func_; }
/// @returns the arguments
const ExpressionList& args() const { return args_; }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
CallExpression* Clone(CloneContext* ctx) const override;
/// The target function
IdentifierExpression* const func;
/// The arguments
ExpressionList const args;
private:
CallExpression(const CallExpression&) = delete;
IdentifierExpression* const func_;
ExpressionList const args_;
};
} // namespace ast

View File

@ -28,9 +28,9 @@ TEST_F(CallExpressionTest, Creation) {
params.push_back(Expr("param2"));
auto* stmt = create<CallExpression>(func, params);
EXPECT_EQ(stmt->func(), func);
EXPECT_EQ(stmt->func, func);
const auto& vec = stmt->args();
const auto& vec = stmt->args;
ASSERT_EQ(vec.size(), 2u);
EXPECT_EQ(vec[0], params[0]);
EXPECT_EQ(vec[1], params[1]);
@ -40,7 +40,7 @@ TEST_F(CallExpressionTest, Creation_WithSource) {
auto* func = Expr("func");
auto* stmt = create<CallExpression>(Source{Source::Location{20, 2}}, func,
ExpressionList{});
auto src = stmt->source();
auto src = stmt->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}

View File

@ -21,12 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CallStatement);
namespace tint {
namespace ast {
CallStatement::CallStatement(ProgramID program_id,
const Source& source,
CallStatement::CallStatement(ProgramID pid,
const Source& src,
CallExpression* call)
: Base(program_id, source), call_(call) {
TINT_ASSERT(AST, call_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, call_, program_id);
: Base(pid, src), expr(call) {
TINT_ASSERT(AST, expr);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id);
}
CallStatement::CallStatement(CallStatement&&) = default;
@ -35,8 +35,8 @@ CallStatement::~CallStatement() = default;
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(call_);
auto src = ctx->Clone(source);
auto* call = ctx->Clone(expr);
return ctx->dst->create<CallStatement>(src, call);
}

View File

@ -25,29 +25,25 @@ namespace ast {
class CallStatement : public Castable<CallStatement, Statement> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the input source for the 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 program_id,
const Source& source,
CallExpression* call);
CallStatement(ProgramID pid, const Source& src, CallExpression* call);
/// Move constructor
CallStatement(CallStatement&&);
~CallStatement() override;
/// @returns the call expression
CallExpression* expr() const { return call_; }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
CallStatement* Clone(CloneContext* ctx) const override;
/// The call expression
CallExpression* const expr;
private:
CallStatement(const CallStatement&) = delete;
CallExpression* const call_;
};
} // namespace ast

View File

@ -27,7 +27,7 @@ TEST_F(CallStatementTest, Creation) {
auto* expr = create<CallExpression>(Expr("func"), ExpressionList{});
auto* c = create<CallStatement>(expr);
EXPECT_EQ(c->expr(), expr);
EXPECT_EQ(c->expr, expr);
}
TEST_F(CallStatementTest, IsCall) {

View File

@ -21,13 +21,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CaseStatement);
namespace tint {
namespace ast {
CaseStatement::CaseStatement(ProgramID program_id,
const Source& source,
CaseSelectorList selectors,
BlockStatement* body)
: Base(program_id, source), selectors_(selectors), body_(body) {
TINT_ASSERT(AST, body_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body_, program_id);
CaseStatement::CaseStatement(ProgramID pid,
const Source& src,
CaseSelectorList s,
BlockStatement* b)
: Base(pid, src), selectors(s), body(b) {
TINT_ASSERT(AST, body);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
for (auto* selector : selectors) {
TINT_ASSERT(AST, selector);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, selector, program_id);
@ -40,9 +40,9 @@ CaseStatement::~CaseStatement() = default;
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_);
auto* b = ctx->Clone(body_);
auto src = ctx->Clone(source);
auto sel = ctx->Clone(selectors);
auto* b = ctx->Clone(body);
return ctx->dst->create<CaseStatement>(src, sel, b);
}

View File

@ -30,27 +30,20 @@ using CaseSelectorList = std::vector<IntLiteral*>;
class CaseStatement : public Castable<CaseStatement, Statement> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source information
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param selectors the case selectors
/// @param body the case body
CaseStatement(ProgramID program_id,
const Source& source,
CaseStatement(ProgramID pid,
const Source& src,
CaseSelectorList selectors,
BlockStatement* body);
/// Move constructor
CaseStatement(CaseStatement&&);
~CaseStatement() override;
/// @returns the case selectors, empty if none set
const CaseSelectorList& selectors() const { return selectors_; }
/// @returns true if this is a default statement
bool IsDefault() const { return selectors_.empty(); }
/// @returns the case body
const BlockStatement* body() const { return body_; }
/// @returns the case body
BlockStatement* body() { return body_; }
bool IsDefault() const { return selectors.empty(); }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
@ -58,11 +51,14 @@ class CaseStatement : public Castable<CaseStatement, Statement> {
/// @return the newly cloned node
CaseStatement* Clone(CloneContext* ctx) const override;
/// The case selectors, empty if none set
CaseSelectorList const selectors;
/// The case body
BlockStatement* const body;
private:
CaseStatement(const CaseStatement&) = delete;
CaseSelectorList const selectors_;
BlockStatement* const body_;
};
/// A list of case statements

View File

@ -34,10 +34,10 @@ TEST_F(CaseStatementTest, Creation_i32) {
auto* body = create<BlockStatement>(StatementList{discard});
auto* c = create<CaseStatement>(b, body);
ASSERT_EQ(c->selectors().size(), 1u);
EXPECT_EQ(c->selectors()[0], selector);
ASSERT_EQ(c->body()->size(), 1u);
EXPECT_EQ(c->body()->get(0), discard);
ASSERT_EQ(c->selectors.size(), 1u);
EXPECT_EQ(c->selectors[0], selector);
ASSERT_EQ(c->body->statements.size(), 1u);
EXPECT_EQ(c->body->statements[0], discard);
}
TEST_F(CaseStatementTest, Creation_u32) {
@ -49,10 +49,10 @@ TEST_F(CaseStatementTest, Creation_u32) {
auto* body = create<BlockStatement>(StatementList{discard});
auto* c = create<CaseStatement>(b, body);
ASSERT_EQ(c->selectors().size(), 1u);
EXPECT_EQ(c->selectors()[0], selector);
ASSERT_EQ(c->body()->size(), 1u);
EXPECT_EQ(c->body()->get(0), discard);
ASSERT_EQ(c->selectors.size(), 1u);
EXPECT_EQ(c->selectors[0], selector);
ASSERT_EQ(c->body->statements.size(), 1u);
EXPECT_EQ(c->body->statements[0], discard);
}
TEST_F(CaseStatementTest, Creation_WithSource) {
@ -63,7 +63,7 @@ TEST_F(CaseStatementTest, Creation_WithSource) {
create<DiscardStatement>(),
});
auto* c = create<CaseStatement>(Source{Source::Location{20, 2}}, b, body);
auto src = c->source();
auto src = c->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}

View File

@ -23,9 +23,8 @@ ConstructorExpression::~ConstructorExpression() = default;
ConstructorExpression::ConstructorExpression(ConstructorExpression&&) = default;
ConstructorExpression::ConstructorExpression(ProgramID program_id,
const Source& source)
: Base(program_id, source) {}
ConstructorExpression::ConstructorExpression(ProgramID pid, const Source& src)
: Base(pid, src) {}
} // namespace ast
} // namespace tint

View File

@ -28,9 +28,9 @@ class ConstructorExpression
protected:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the constructor source
ConstructorExpression(ProgramID program_id, const Source& source);
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
ConstructorExpression(ProgramID pid, const Source& src);
/// Move constructor
ConstructorExpression(ConstructorExpression&&);

View File

@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ContinueStatement);
namespace tint {
namespace ast {
ContinueStatement::ContinueStatement(ProgramID program_id, const Source& source)
: Base(program_id, source) {}
ContinueStatement::ContinueStatement(ProgramID pid, const Source& src)
: Base(pid, src) {}
ContinueStatement::ContinueStatement(ContinueStatement&&) = default;
@ -30,7 +30,7 @@ ContinueStatement::~ContinueStatement() = default;
ContinueStatement* ContinueStatement::Clone(CloneContext* ctx) const {
// 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);
}

View File

@ -24,9 +24,9 @@ namespace ast {
class ContinueStatement : public Castable<ContinueStatement, Statement> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the continue statement source
ContinueStatement(ProgramID program_id, const Source& source);
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
ContinueStatement(ProgramID pid, const Source& src);
/// Move constructor
ContinueStatement(ContinueStatement&&);
~ContinueStatement() override;

View File

@ -24,7 +24,7 @@ using ContinueStatementTest = TestHelper;
TEST_F(ContinueStatementTest, Creation_WithSource) {
auto* stmt = create<ContinueStatement>(Source{Source::Location{20, 2}});
auto src = stmt->source();
auto src = stmt->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}

View File

@ -29,14 +29,13 @@ class Decoration : public Castable<Decoration, Node> {
~Decoration() override;
/// @returns the WGSL name for the decoration
virtual std::string name() const = 0;
virtual std::string Name() const = 0;
protected:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this decoration
Decoration(ProgramID program_id, const Source& source)
: Base(program_id, source) {}
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
Decoration(ProgramID pid, const Source& src) : Base(pid, src) {}
};
/// A list of decorations

View File

@ -28,10 +28,10 @@ bool IsValidDepthDimension(TextureDimension dim) {
} // namespace
DepthMultisampledTexture::DepthMultisampledTexture(ProgramID program_id,
const Source& source,
TextureDimension dim)
: Base(program_id, source, dim) {
DepthMultisampledTexture::DepthMultisampledTexture(ProgramID pid,
const Source& src,
TextureDimension d)
: Base(pid, src, d) {
TINT_ASSERT(AST, IsValidDepthDimension(dim));
}
@ -42,14 +42,14 @@ DepthMultisampledTexture::~DepthMultisampledTexture() = default;
std::string DepthMultisampledTexture::FriendlyName(const SymbolTable&) const {
std::ostringstream out;
out << "texture_depth_multisampled_" << dim();
out << "texture_depth_multisampled_" << dim;
return out.str();
}
DepthMultisampledTexture* DepthMultisampledTexture::Clone(
CloneContext* ctx) const {
auto src = ctx->Clone(source());
return ctx->dst->create<DepthMultisampledTexture>(src, dim());
auto src = ctx->Clone(source);
return ctx->dst->create<DepthMultisampledTexture>(src, dim);
}
} // namespace ast

View File

@ -27,11 +27,11 @@ class DepthMultisampledTexture
: public Castable<DepthMultisampledTexture, Texture> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this node
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param dim the dimensionality of the texture
DepthMultisampledTexture(ProgramID program_id,
const Source& source,
DepthMultisampledTexture(ProgramID pid,
const Source& src,
TextureDimension dim);
/// Move constructor
DepthMultisampledTexture(DepthMultisampledTexture&&);

View File

@ -24,7 +24,7 @@ using AstDepthMultisampledTextureTest = TestHelper;
TEST_F(AstDepthMultisampledTextureTest, Dim) {
auto* d = create<DepthMultisampledTexture>(TextureDimension::k2d);
EXPECT_EQ(d->dim(), TextureDimension::k2d);
EXPECT_EQ(d->dim, TextureDimension::k2d);
}
TEST_F(AstDepthMultisampledTextureTest, FriendlyName) {

View File

@ -29,10 +29,8 @@ bool IsValidDepthDimension(TextureDimension dim) {
} // namespace
DepthTexture::DepthTexture(ProgramID program_id,
const Source& source,
TextureDimension dim)
: Base(program_id, source, dim) {
DepthTexture::DepthTexture(ProgramID pid, const Source& src, TextureDimension d)
: Base(pid, src, d) {
TINT_ASSERT(AST, IsValidDepthDimension(dim));
}
@ -42,13 +40,13 @@ DepthTexture::~DepthTexture() = default;
std::string DepthTexture::FriendlyName(const SymbolTable&) const {
std::ostringstream out;
out << "texture_depth_" << dim();
out << "texture_depth_" << dim;
return out.str();
}
DepthTexture* DepthTexture::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source());
return ctx->dst->create<DepthTexture>(src, dim());
auto src = ctx->Clone(source);
return ctx->dst->create<DepthTexture>(src, dim);
}
} // namespace ast

View File

@ -26,12 +26,10 @@ namespace ast {
class DepthTexture : public Castable<DepthTexture, Texture> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this node
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param dim the dimensionality of the texture
DepthTexture(ProgramID program_id,
const Source& source,
TextureDimension dim);
DepthTexture(ProgramID pid, const Source& src, TextureDimension dim);
/// Move constructor
DepthTexture(DepthTexture&&);
~DepthTexture() override;

View File

@ -31,7 +31,7 @@ TEST_F(AstDepthTextureTest, IsTexture) {
TEST_F(AstDepthTextureTest, Dim) {
auto* d = create<DepthTexture>(TextureDimension::kCube);
EXPECT_EQ(d->dim(), TextureDimension::kCube);
EXPECT_EQ(d->dim, TextureDimension::kCube);
}
TEST_F(AstDepthTextureTest, FriendlyName) {

View File

@ -21,15 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::DisableValidationDecoration);
namespace tint {
namespace ast {
DisableValidationDecoration::DisableValidationDecoration(
ProgramID program_id,
DisabledValidation validation)
: Base(program_id), validation_(validation) {}
DisableValidationDecoration::DisableValidationDecoration(ProgramID pid,
DisabledValidation val)
: Base(pid), validation(val) {}
DisableValidationDecoration::~DisableValidationDecoration() = default;
std::string DisableValidationDecoration::InternalName() const {
switch (validation_) {
switch (validation) {
case DisabledValidation::kFunctionHasNoBody:
return "disable_validation__function_has_no_body";
case DisabledValidation::kBindingPointCollision:
@ -51,7 +50,7 @@ std::string DisableValidationDecoration::InternalName() const {
DisableValidationDecoration* DisableValidationDecoration::Clone(
CloneContext* ctx) const {
return ctx->dst->ASTNodes().Create<DisableValidationDecoration>(
ctx->dst->ID(), validation_);
ctx->dst->ID(), validation);
}
} // namespace ast

View File

@ -64,9 +64,6 @@ class DisableValidationDecoration
/// Destructor
~DisableValidationDecoration() override;
/// @return the validation that this decoration disables
DisabledValidation Validation() const { return validation_; }
/// @return a short description of the internal decoration which will be
/// displayed in WGSL as `[[internal(<name>)]]` (but is not parsable).
std::string InternalName() const override;
@ -76,8 +73,8 @@ class DisableValidationDecoration
/// @return the newly cloned object
DisableValidationDecoration* Clone(CloneContext* ctx) const override;
private:
DisabledValidation const validation_;
/// The validation that this decoration disables
DisabledValidation const validation;
};
} // namespace ast

View File

@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::DiscardStatement);
namespace tint {
namespace ast {
DiscardStatement::DiscardStatement(ProgramID program_id, const Source& source)
: Base(program_id, source) {}
DiscardStatement::DiscardStatement(ProgramID pid, const Source& src)
: Base(pid, src) {}
DiscardStatement::DiscardStatement(DiscardStatement&&) = default;
@ -30,7 +30,7 @@ DiscardStatement::~DiscardStatement() = default;
DiscardStatement* DiscardStatement::Clone(CloneContext* ctx) const {
// 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);
}

View File

@ -24,9 +24,9 @@ namespace ast {
class DiscardStatement : public Castable<DiscardStatement, Statement> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the discard statement source
DiscardStatement(ProgramID program_id, const Source& source);
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
DiscardStatement(ProgramID pid, const Source& src);
/// Move constructor
DiscardStatement(DiscardStatement&&);
~DiscardStatement() override;

View File

@ -24,19 +24,19 @@ using DiscardStatementTest = TestHelper;
TEST_F(DiscardStatementTest, Creation) {
auto* stmt = create<DiscardStatement>();
EXPECT_EQ(stmt->source().range.begin.line, 0u);
EXPECT_EQ(stmt->source().range.begin.column, 0u);
EXPECT_EQ(stmt->source().range.end.line, 0u);
EXPECT_EQ(stmt->source().range.end.column, 0u);
EXPECT_EQ(stmt->source.range.begin.line, 0u);
EXPECT_EQ(stmt->source.range.begin.column, 0u);
EXPECT_EQ(stmt->source.range.end.line, 0u);
EXPECT_EQ(stmt->source.range.end.column, 0u);
}
TEST_F(DiscardStatementTest, Creation_WithSource) {
auto* stmt = create<DiscardStatement>(
Source{Source::Range{Source::Location{20, 2}, Source::Location{20, 5}}});
EXPECT_EQ(stmt->source().range.begin.line, 20u);
EXPECT_EQ(stmt->source().range.begin.column, 2u);
EXPECT_EQ(stmt->source().range.end.line, 20u);
EXPECT_EQ(stmt->source().range.end.column, 5u);
EXPECT_EQ(stmt->source.range.begin.line, 20u);
EXPECT_EQ(stmt->source.range.begin.column, 2u);
EXPECT_EQ(stmt->source.range.end.line, 20u);
EXPECT_EQ(stmt->source.range.end.column, 5u);
}
TEST_F(DiscardStatementTest, IsDiscard) {

View File

@ -21,14 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ElseStatement);
namespace tint {
namespace ast {
ElseStatement::ElseStatement(ProgramID program_id,
const Source& source,
Expression* condition,
BlockStatement* body)
: Base(program_id, source), condition_(condition), body_(body) {
TINT_ASSERT(AST, body_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body_, program_id);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition_, program_id);
ElseStatement::ElseStatement(ProgramID pid,
const Source& src,
Expression* cond,
BlockStatement* b)
: Base(pid, src), condition(cond), body(b) {
TINT_ASSERT(AST, body);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id);
}
ElseStatement::ElseStatement(ElseStatement&&) = default;
@ -37,9 +37,9 @@ ElseStatement::~ElseStatement() = default;
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_);
auto* b = ctx->Clone(body_);
auto src = ctx->Clone(source);
auto* cond = ctx->Clone(condition);
auto* b = ctx->Clone(body);
return ctx->dst->create<ElseStatement>(src, cond, b);
}

View File

@ -27,39 +27,32 @@ namespace ast {
class ElseStatement : public Castable<ElseStatement, Statement> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source information
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param condition the else condition
/// @param body the else body
ElseStatement(ProgramID program_id,
const Source& source,
ElseStatement(ProgramID pid,
const Source& src,
Expression* condition,
BlockStatement* body);
/// Move constructor
ElseStatement(ElseStatement&&);
~ElseStatement() override;
/// @returns the else condition or nullptr if none set
Expression* condition() const { return condition_; }
/// @returns true if the else has a condition
bool HasCondition() const { return condition_ != nullptr; }
/// @returns the else body
const BlockStatement* body() const { return body_; }
/// @returns the else body
BlockStatement* body() { return body_; }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
ElseStatement* Clone(CloneContext* ctx) const override;
/// The else condition or nullptr if none set
Expression* const condition;
/// The else body
BlockStatement* const body;
private:
ElseStatement(const ElseStatement&) = delete;
Expression* const condition_;
BlockStatement* const body_;
};
/// A list of else statements

View File

@ -28,18 +28,18 @@ TEST_F(ElseStatementTest, Creation) {
auto* body = create<BlockStatement>(StatementList{
create<DiscardStatement>(),
});
auto* discard = body->get(0);
auto* discard = body->statements[0];
auto* e = create<ElseStatement>(cond, body);
EXPECT_EQ(e->condition(), cond);
ASSERT_EQ(e->body()->size(), 1u);
EXPECT_EQ(e->body()->get(0), discard);
EXPECT_EQ(e->condition, cond);
ASSERT_EQ(e->body->statements.size(), 1u);
EXPECT_EQ(e->body->statements[0], discard);
}
TEST_F(ElseStatementTest, Creation_WithSource) {
auto* e = create<ElseStatement>(Source{Source::Location{20, 2}}, Expr(true),
Block());
auto src = e->source();
auto src = e->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}
@ -52,12 +52,12 @@ TEST_F(ElseStatementTest, IsElse) {
TEST_F(ElseStatementTest, HasCondition) {
auto* cond = Expr(true);
auto* e = create<ElseStatement>(cond, Block());
EXPECT_TRUE(e->HasCondition());
EXPECT_TRUE(e->condition);
}
TEST_F(ElseStatementTest, HasContition_NullCondition) {
auto* e = create<ElseStatement>(nullptr, Block());
EXPECT_FALSE(e->HasCondition());
EXPECT_FALSE(e->condition);
}
TEST_F(ElseStatementTest, Assert_Null_Body) {

View File

@ -22,17 +22,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Expression);
namespace tint {
namespace ast {
Expression::Expression(ProgramID program_id, const Source& source)
: Base(program_id, source) {}
Expression::Expression(ProgramID pid, const Source& src) : Base(pid, src) {}
Expression::Expression(Expression&&) = default;
Expression::~Expression() = default;
std::string Expression::result_type_str(const sem::Info& sem) const {
auto* sem_expr = sem.Get(this);
return sem_expr ? sem_expr->Type()->type_name() : "not set";
}
} // namespace ast
} // namespace tint

View File

@ -31,17 +31,12 @@ class Expression : public Castable<Expression, Node> {
protected:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of the expression
Expression(ProgramID program_id, const Source& source);
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
Expression(ProgramID pid, const Source& src);
/// Move constructor
Expression(Expression&&);
/// @param sem the semantic info for the program
/// @returns a string representation of the result type or 'not set' if no
/// result type present
std::string result_type_str(const sem::Info& sem) const;
private:
Expression(const Expression&) = delete;
};

View File

@ -22,8 +22,8 @@ namespace tint {
namespace ast {
// ExternalTexture::ExternalTexture() : Base(ast::TextureDimension::k2d) {}
ExternalTexture::ExternalTexture(ProgramID program_id, const Source& source)
: Base(program_id, source, ast::TextureDimension::k2d) {}
ExternalTexture::ExternalTexture(ProgramID pid, const Source& src)
: Base(pid, src, ast::TextureDimension::k2d) {}
ExternalTexture::ExternalTexture(ExternalTexture&&) = default;

View File

@ -26,9 +26,9 @@ namespace ast {
class ExternalTexture : public Castable<ExternalTexture, Texture> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this node
ExternalTexture(ProgramID program_id, const Source& source);
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
ExternalTexture(ProgramID pid, const Source& src);
/// Move constructor
ExternalTexture(ExternalTexture&&);

View File

@ -33,7 +33,7 @@ TEST_F(AstExternalTextureTest, IsTexture) {
TEST_F(AstExternalTextureTest, Dim) {
auto* ty = create<ExternalTexture>();
EXPECT_EQ(ty->dim(), ast::TextureDimension::k2d);
EXPECT_EQ(ty->dim, ast::TextureDimension::k2d);
}
TEST_F(AstExternalTextureTest, FriendlyName) {

View File

@ -21,8 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::F32);
namespace tint {
namespace ast {
F32::F32(ProgramID program_id, const Source& source)
: Base(program_id, source) {}
F32::F32(ProgramID pid, const Source& src) : Base(pid, src) {}
F32::F32(F32&&) = default;
@ -33,7 +32,7 @@ std::string F32::FriendlyName(const SymbolTable&) const {
}
F32* F32::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source());
auto src = ctx->Clone(source);
return ctx->dst->create<F32>(src);
}

View File

@ -26,9 +26,9 @@ namespace ast {
class F32 : public Castable<F32, Type> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this node
F32(ProgramID program_id, const Source& source);
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
F32(ProgramID pid, const Source& src);
/// Move constructor
F32(F32&&);
~F32() override;

View File

@ -21,9 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::FallthroughStatement);
namespace tint {
namespace ast {
FallthroughStatement::FallthroughStatement(ProgramID program_id,
const Source& source)
: Base(program_id, source) {}
FallthroughStatement::FallthroughStatement(ProgramID pid, const Source& src)
: Base(pid, src) {}
FallthroughStatement::FallthroughStatement(FallthroughStatement&&) = default;
@ -31,7 +30,7 @@ FallthroughStatement::~FallthroughStatement() = default;
FallthroughStatement* FallthroughStatement::Clone(CloneContext* ctx) const {
// 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);
}

View File

@ -24,9 +24,9 @@ namespace ast {
class FallthroughStatement : public Castable<FallthroughStatement, Statement> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source information
FallthroughStatement(ProgramID program_id, const Source& source);
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
FallthroughStatement(ProgramID pid, const Source& src);
/// Move constructor
FallthroughStatement(FallthroughStatement&&);
~FallthroughStatement() override;

View File

@ -24,15 +24,15 @@ using FallthroughStatementTest = TestHelper;
TEST_F(FallthroughStatementTest, Creation) {
auto* stmt = create<FallthroughStatement>();
EXPECT_EQ(stmt->source().range.begin.line, 0u);
EXPECT_EQ(stmt->source().range.begin.column, 0u);
EXPECT_EQ(stmt->source().range.end.line, 0u);
EXPECT_EQ(stmt->source().range.end.column, 0u);
EXPECT_EQ(stmt->source.range.begin.line, 0u);
EXPECT_EQ(stmt->source.range.begin.column, 0u);
EXPECT_EQ(stmt->source.range.end.line, 0u);
EXPECT_EQ(stmt->source.range.end.column, 0u);
}
TEST_F(FallthroughStatementTest, Creation_WithSource) {
auto* stmt = create<FallthroughStatement>(Source{Source::Location{20, 2}});
auto src = stmt->source();
auto src = stmt->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}

View File

@ -23,25 +23,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::FloatLiteral);
namespace tint {
namespace ast {
FloatLiteral::FloatLiteral(ProgramID program_id,
const Source& source,
float value)
: Base(program_id, source), value_(value) {}
FloatLiteral::FloatLiteral(ProgramID pid, const Source& src, float val)
: Base(pid, src), value(val) {}
FloatLiteral::~FloatLiteral() = default;
std::string FloatLiteral::name() const {
std::ostringstream out;
out.flags(out.flags() | std::ios_base::showpoint);
out.precision(std::numeric_limits<float>::max_digits10);
out << "__float" << value_;
return out.str();
}
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_);
auto src = ctx->Clone(source);
return ctx->dst->create<FloatLiteral>(src, value);
}
} // namespace ast

View File

@ -26,26 +26,20 @@ namespace ast {
class FloatLiteral : public Castable<FloatLiteral, Literal> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the input source
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param value the float literals value
FloatLiteral(ProgramID program_id, const Source& source, float value);
FloatLiteral(ProgramID pid, const Source& src, float value);
~FloatLiteral() override;
/// @returns the float literal value
float value() const { return value_; }
/// @returns the name for this literal. This name is unique to this value.
std::string name() const override;
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
FloatLiteral* Clone(CloneContext* ctx) const override;
private:
float const value_;
/// The float literal value
float const value;
};
} // namespace ast

View File

@ -23,12 +23,7 @@ using FloatLiteralTest = TestHelper;
TEST_F(FloatLiteralTest, Value) {
auto* f = create<FloatLiteral>(47.2f);
ASSERT_TRUE(f->Is<FloatLiteral>());
EXPECT_EQ(f->value(), 47.2f);
}
TEST_F(FloatLiteralTest, ToName) {
auto* f = create<FloatLiteral>(42.1f);
EXPECT_EQ(f->name(), "__float42.0999985");
EXPECT_EQ(f->value, 47.2f);
}
} // namespace

View File

@ -21,23 +21,23 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ForLoopStatement);
namespace tint {
namespace ast {
ForLoopStatement::ForLoopStatement(ProgramID program_id,
const Source& source,
Statement* initializer,
Expression* condition,
Statement* continuing,
BlockStatement* body)
: Base(program_id, source),
initializer_(initializer),
condition_(condition),
continuing_(continuing),
body_(body) {
TINT_ASSERT(AST, body_);
ForLoopStatement::ForLoopStatement(ProgramID pid,
const Source& src,
Statement* init,
Expression* cond,
Statement* cont,
BlockStatement* b)
: Base(pid, src),
initializer(init),
condition(cond),
continuing(cont),
body(b) {
TINT_ASSERT(AST, body);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, initializer_, program_id);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition_, program_id);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, continuing_, program_id);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body_, program_id);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, initializer, program_id);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, continuing, program_id);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
}
ForLoopStatement::ForLoopStatement(ForLoopStatement&&) = default;
@ -46,12 +46,12 @@ ForLoopStatement::~ForLoopStatement() = default;
ForLoopStatement* ForLoopStatement::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source());
auto src = ctx->Clone(source);
auto* init = ctx->Clone(initializer_);
auto* cond = ctx->Clone(condition_);
auto* cont = ctx->Clone(continuing_);
auto* b = ctx->Clone(body_);
auto* init = ctx->Clone(initializer);
auto* cond = ctx->Clone(condition);
auto* cont = ctx->Clone(continuing);
auto* b = ctx->Clone(body);
return ctx->dst->create<ForLoopStatement>(src, init, cond, cont, b);
}

View File

@ -42,39 +42,26 @@ class ForLoopStatement : public Castable<ForLoopStatement, Statement> {
ForLoopStatement(ForLoopStatement&&);
~ForLoopStatement() override;
/// @returns the initializer statement
const Statement* initializer() const { return initializer_; }
/// @returns the initializer statement
Statement* initializer() { return initializer_; }
/// @returns the condition expression
const Expression* condition() const { return condition_; }
/// @returns the condition expression
Expression* condition() { return condition_; }
/// @returns the continuing statement
const Statement* continuing() const { return continuing_; }
/// @returns the continuing statement
Statement* continuing() { return continuing_; }
/// @returns the loop body block
const BlockStatement* body() const { return body_; }
/// @returns the loop body block
BlockStatement* body() { return body_; }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
ForLoopStatement* Clone(CloneContext* ctx) const override;
/// The initializer statement
Statement* const initializer;
/// The condition expression
Expression* const condition;
/// The continuing statement
Statement* const continuing;
/// The loop body block
BlockStatement* const body;
private:
ForLoopStatement(const ForLoopStatement&) = delete;
Statement* const initializer_;
Expression* const condition_;
Statement* const continuing_;
BlockStatement* const body_;
};
} // namespace ast

View File

@ -30,16 +30,16 @@ TEST_F(ForLoopStatementTest, Creation) {
auto* body = Block(Return());
auto* l = For(init, cond, cont, body);
EXPECT_EQ(l->initializer(), init);
EXPECT_EQ(l->condition(), cond);
EXPECT_EQ(l->continuing(), cont);
EXPECT_EQ(l->body(), body);
EXPECT_EQ(l->initializer, init);
EXPECT_EQ(l->condition, cond);
EXPECT_EQ(l->continuing, cont);
EXPECT_EQ(l->body, body);
}
TEST_F(ForLoopStatementTest, Creation_WithSource) {
auto* body = Block(Return());
auto* l = For(Source{{20u, 2u}}, nullptr, nullptr, nullptr, body);
auto src = l->source();
auto src = l->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}
@ -47,7 +47,7 @@ TEST_F(ForLoopStatementTest, Creation_WithSource) {
TEST_F(ForLoopStatementTest, Creation_Null_InitCondCont) {
auto* body = Block(Return());
auto* l = For(nullptr, nullptr, nullptr, body);
EXPECT_EQ(l->body(), body);
EXPECT_EQ(l->body, body);
}
TEST_F(ForLoopStatementTest, Assert_Null_Body) {

View File

@ -23,33 +23,33 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Function);
namespace tint {
namespace ast {
Function::Function(ProgramID program_id,
const Source& source,
Symbol symbol,
VariableList params,
ast::Type* return_type,
BlockStatement* body,
DecorationList decorations,
DecorationList return_type_decorations)
: Base(program_id, source),
symbol_(symbol),
params_(std::move(params)),
return_type_(return_type),
body_(body),
decorations_(std::move(decorations)),
return_type_decorations_(std::move(return_type_decorations)) {
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol_, program_id);
Function::Function(ProgramID pid,
const Source& src,
Symbol sym,
VariableList parameters,
ast::Type* return_ty,
BlockStatement* b,
DecorationList decos,
DecorationList return_type_decos)
: Base(pid, src),
symbol(sym),
params(std::move(parameters)),
return_type(return_ty),
body(b),
decorations(std::move(decos)),
return_type_decorations(std::move(return_type_decos)) {
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
for (auto* param : params_) {
TINT_ASSERT(AST, param && param->is_const());
for (auto* param : params) {
TINT_ASSERT(AST, param && param->is_const);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, param, program_id);
}
TINT_ASSERT(AST, symbol_.IsValid());
TINT_ASSERT(AST, return_type_);
for (auto* deco : decorations_) {
TINT_ASSERT(AST, symbol.IsValid());
TINT_ASSERT(AST, return_type);
for (auto* deco : decorations) {
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, deco, program_id);
}
for (auto* deco : return_type_decorations_) {
for (auto* deco : return_type_decorations) {
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, deco, program_id);
}
}
@ -58,32 +58,28 @@ Function::Function(Function&&) = default;
Function::~Function() = default;
PipelineStage Function::pipeline_stage() const {
if (auto* stage = GetDecoration<StageDecoration>(decorations_)) {
return stage->value();
PipelineStage Function::PipelineStage() const {
if (auto* stage = GetDecoration<StageDecoration>(decorations)) {
return stage->stage;
}
return PipelineStage::kNone;
}
const Statement* Function::get_last_statement() const {
return body_->last();
}
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());
auto p = ctx->Clone(params_);
auto* ret = ctx->Clone(return_type_);
auto* b = ctx->Clone(body_);
auto decos = ctx->Clone(decorations_);
auto ret_decos = ctx->Clone(return_type_decorations_);
auto src = ctx->Clone(source);
auto sym = ctx->Clone(symbol);
auto p = ctx->Clone(params);
auto* ret = ctx->Clone(return_type);
auto* b = ctx->Clone(body);
auto decos = ctx->Clone(decorations);
auto ret_decos = ctx->Clone(return_type_decorations);
return ctx->dst->create<Function>(src, sym, p, ret, b, decos, ret_decos);
}
Function* FunctionList::Find(Symbol sym) const {
for (auto* func : *this) {
if (func->symbol() == sym) {
if (func->symbol == sym) {
return func;
}
}
@ -92,7 +88,7 @@ Function* FunctionList::Find(Symbol sym) const {
Function* FunctionList::Find(Symbol sym, PipelineStage stage) const {
for (auto* func : *this) {
if (func->symbol() == sym && func->pipeline_stage() == stage) {
if (func->symbol == sym && func->PipelineStage() == stage) {
return func;
}
}
@ -101,7 +97,7 @@ Function* FunctionList::Find(Symbol sym, PipelineStage stage) const {
bool FunctionList::HasStage(ast::PipelineStage stage) const {
for (auto* func : *this) {
if (func->pipeline_stage() == stage) {
if (func->PipelineStage() == stage) {
return true;
}
}

View File

@ -57,36 +57,11 @@ class Function : public Castable<Function, Node> {
~Function() override;
/// @returns the function symbol
Symbol symbol() const { return symbol_; }
/// @returns the function params
const VariableList& params() const { return params_; }
/// @returns the decorations attached to this function
const DecorationList& decorations() const { return decorations_; }
/// @returns the functions pipeline stage or None if not set
PipelineStage pipeline_stage() const;
ast::PipelineStage PipelineStage() const;
/// @returns true if this function is an entry point
bool IsEntryPoint() const { return pipeline_stage() != PipelineStage::kNone; }
/// @returns the function return type.
ast::Type* return_type() const { return return_type_; }
/// @returns the decorations attached to the function return type.
const DecorationList& return_type_decorations() const {
return return_type_decorations_;
}
/// @returns a pointer to the last statement of the function or nullptr if
// function is empty
const Statement* get_last_statement() const;
/// @returns the function body
const BlockStatement* body() const { return body_; }
/// @returns the function body
BlockStatement* body() { return body_; }
bool IsEntryPoint() const { return PipelineStage() != PipelineStage::kNone; }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
@ -94,15 +69,26 @@ class Function : public Castable<Function, Node> {
/// @return the newly cloned node
Function* Clone(CloneContext* ctx) const override;
/// The function symbol
Symbol const symbol;
/// The function params
VariableList const params;
/// The function return type
ast::Type* const return_type;
/// The function body
BlockStatement* const body;
/// The decorations attached to this function
DecorationList const decorations;
/// The decorations attached to the function return type.
DecorationList const return_type_decorations;
private:
Function(const Function&) = delete;
Symbol const symbol_;
VariableList const params_;
ast::Type* const return_type_;
BlockStatement* const body_;
DecorationList const decorations_;
DecorationList const return_type_decorations_;
};
/// A list of functions

View File

@ -30,10 +30,10 @@ TEST_F(FunctionTest, Creation) {
auto* var = params[0];
auto* f = Func("func", params, ty.void_(), StatementList{}, DecorationList{});
EXPECT_EQ(f->symbol(), Symbols().Get("func"));
ASSERT_EQ(f->params().size(), 1u);
EXPECT_TRUE(f->return_type()->Is<ast::Void>());
EXPECT_EQ(f->params()[0], var);
EXPECT_EQ(f->symbol, Symbols().Get("func"));
ASSERT_EQ(f->params.size(), 1u);
EXPECT_TRUE(f->return_type->Is<ast::Void>());
EXPECT_EQ(f->params[0], var);
}
TEST_F(FunctionTest, Creation_WithSource) {
@ -42,7 +42,7 @@ TEST_F(FunctionTest, Creation_WithSource) {
auto* f = Func(Source{Source::Location{20, 2}}, "func", params, ty.void_(),
StatementList{}, DecorationList{});
auto src = f->source();
auto src = f->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}
@ -139,22 +139,6 @@ TEST_F(FunctionTest, Assert_NonConstParam) {
"internal compiler error");
}
TEST_F(FunctionTest, GetLastStatement) {
VariableList params;
auto* stmt = create<DiscardStatement>();
auto* f =
Func("func", params, ty.void_(), StatementList{stmt}, DecorationList{});
EXPECT_EQ(f->get_last_statement(), stmt);
}
TEST_F(FunctionTest, GetLastStatement_nullptr) {
VariableList params;
auto* f = Func("func", params, ty.void_(), StatementList{}, DecorationList{});
EXPECT_EQ(f->get_last_statement(), nullptr);
}
using FunctionListTest = TestHelper;
TEST_F(FunctionListTest, FindSymbol) {

View File

@ -23,21 +23,19 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::GroupDecoration);
namespace tint {
namespace ast {
GroupDecoration::GroupDecoration(ProgramID program_id,
const Source& source,
uint32_t val)
: Base(program_id, source), value_(val) {}
GroupDecoration::GroupDecoration(ProgramID pid, const Source& src, uint32_t val)
: Base(pid, src), value(val) {}
GroupDecoration::~GroupDecoration() = default;
std::string GroupDecoration::name() const {
std::string GroupDecoration::Name() const {
return "group";
}
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_);
auto src = ctx->Clone(source);
return ctx->dst->create<GroupDecoration>(src, value);
}
} // namespace ast

View File

@ -26,17 +26,14 @@ namespace ast {
class GroupDecoration : public Castable<GroupDecoration, Decoration> {
public:
/// constructor
/// @param program_id 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 value the group value
/// @param source the source of this decoration
GroupDecoration(ProgramID program_id, const Source& source, uint32_t value);
GroupDecoration(ProgramID pid, const Source& src, uint32_t value);
~GroupDecoration() override;
/// @returns the group value
uint32_t value() const { return value_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
std::string Name() const override;
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
@ -44,8 +41,8 @@ class GroupDecoration : public Castable<GroupDecoration, Decoration> {
/// @return the newly cloned node
GroupDecoration* Clone(CloneContext* ctx) const override;
private:
uint32_t const value_;
/// The group value
uint32_t const value;
};
} // namespace ast

View File

@ -23,7 +23,7 @@ using GroupDecorationTest = TestHelper;
TEST_F(GroupDecorationTest, Creation) {
auto* d = create<GroupDecoration>(2);
EXPECT_EQ(2u, d->value());
EXPECT_EQ(2u, d->value);
}
} // namespace

View File

@ -21,8 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::I32);
namespace tint {
namespace ast {
I32::I32(ProgramID program_id, const Source& source)
: Base(program_id, source) {}
I32::I32(ProgramID pid, const Source& src) : Base(pid, src) {}
I32::I32(I32&&) = default;
@ -33,7 +32,7 @@ std::string I32::FriendlyName(const SymbolTable&) const {
}
I32* I32::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source());
auto src = ctx->Clone(source);
return ctx->dst->create<I32>(src);
}

View File

@ -26,9 +26,9 @@ namespace ast {
class I32 : public Castable<I32, Type> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this node
I32(ProgramID program_id, const Source& source);
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
I32(ProgramID pid, const Source& src);
/// Move constructor
I32(I32&&);
~I32() override;

View File

@ -21,12 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IdentifierExpression);
namespace tint {
namespace ast {
IdentifierExpression::IdentifierExpression(ProgramID program_id,
const Source& source,
IdentifierExpression::IdentifierExpression(ProgramID pid,
const Source& src,
Symbol sym)
: Base(program_id, source), sym_(sym) {
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, sym_, program_id);
TINT_ASSERT(AST, sym_.IsValid());
: Base(pid, src), symbol(sym) {
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id);
TINT_ASSERT(AST, symbol.IsValid());
}
IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default;
@ -35,8 +35,8 @@ IdentifierExpression::~IdentifierExpression() = default;
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());
auto src = ctx->Clone(source);
auto sym = ctx->Clone(symbol);
return ctx->dst->create<IdentifierExpression>(src, sym);
}

View File

@ -24,27 +24,25 @@ namespace ast {
class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param sym the symbol for the identifier
IdentifierExpression(ProgramID program_id, const Source& source, Symbol sym);
IdentifierExpression(ProgramID pid, const Source& src, Symbol sym);
/// Move constructor
IdentifierExpression(IdentifierExpression&&);
~IdentifierExpression() override;
/// @returns the symbol for the identifier
Symbol symbol() const { return sym_; }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
IdentifierExpression* Clone(CloneContext* ctx) const override;
/// The symbol for the identifier
Symbol const symbol;
private:
IdentifierExpression(const IdentifierExpression&) = delete;
Symbol const sym_;
};
} // namespace ast

View File

@ -23,14 +23,14 @@ using IdentifierExpressionTest = TestHelper;
TEST_F(IdentifierExpressionTest, Creation) {
auto* i = Expr("ident");
EXPECT_EQ(i->symbol(), Symbol(1, ID()));
EXPECT_EQ(i->symbol, Symbol(1, ID()));
}
TEST_F(IdentifierExpressionTest, Creation_WithSource) {
auto* i = Expr(Source{Source::Location{20, 2}}, "ident");
EXPECT_EQ(i->symbol(), Symbol(1, ID()));
EXPECT_EQ(i->symbol, Symbol(1, ID()));
auto src = i->source();
auto src = i->source;
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
}

View File

@ -21,20 +21,20 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IfStatement);
namespace tint {
namespace ast {
IfStatement::IfStatement(ProgramID program_id,
const Source& source,
Expression* condition,
BlockStatement* body,
IfStatement::IfStatement(ProgramID pid,
const Source& src,
Expression* cond,
BlockStatement* b,
ElseStatementList else_stmts)
: Base(program_id, source),
condition_(condition),
body_(body),
else_statements_(std::move(else_stmts)) {
TINT_ASSERT(AST, condition_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition_, program_id);
TINT_ASSERT(AST, body_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body_, program_id);
for (auto* el : else_statements_) {
: Base(pid, src),
condition(cond),
body(b),
else_statements(std::move(else_stmts)) {
TINT_ASSERT(AST, condition);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id);
TINT_ASSERT(AST, body);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
for (auto* el : else_statements) {
TINT_ASSERT(AST, el);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, el, program_id);
}
@ -46,10 +46,10 @@ IfStatement::~IfStatement() = default;
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_);
auto* b = ctx->Clone(body_);
auto el = ctx->Clone(else_statements_);
auto src = ctx->Clone(source);
auto* cond = ctx->Clone(condition);
auto* b = ctx->Clone(body);
auto el = ctx->Clone(else_statements);
return ctx->dst->create<IfStatement>(src, cond, b, el);
}

View File

@ -26,13 +26,13 @@ namespace ast {
class IfStatement : public Castable<IfStatement, Statement> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source information
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param condition the if condition
/// @param body the if body
/// @param else_stmts the else statements
IfStatement(ProgramID program_id,
const Source& source,
IfStatement(ProgramID pid,
const Source& src,
Expression* condition,
BlockStatement* body,
ElseStatementList else_stmts);
@ -40,31 +40,23 @@ class IfStatement : public Castable<IfStatement, Statement> {
IfStatement(IfStatement&&);
~IfStatement() override;
/// @returns the if condition or nullptr if none set
Expression* condition() const { return condition_; }
/// @returns the if body
const BlockStatement* body() const { return body_; }
/// @returns the if body
BlockStatement* body() { return body_; }
/// @returns the else statements
const ElseStatementList& else_statements() const { return else_statements_; }
/// @returns true if there are else statements
bool has_else_statements() const { return !else_statements_.empty(); }
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
IfStatement* Clone(CloneContext* ctx) const override;
/// The if condition or nullptr if none set
Expression* const condition;
/// The if body
BlockStatement* const body;
/// The else statements
ElseStatementList const else_statements;
private:
IfStatement(const IfStatement&) = delete;
Expression* const condition_;
BlockStatement* const body_;
ElseStatementList const else_statements_;
};
} // namespace ast

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