mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-09 14:45:58 +00:00
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:
parent
b3e6c0d62c
commit
4f3ff57c28
@ -89,8 +89,8 @@ void MutationReplaceIdentifier::Apply(const NodeIdMap& node_id_map,
|
|||||||
tint::As<ast::Variable>(node_id_map.GetNode(message_.replacement_id()));
|
tint::As<ast::Variable>(node_id_map.GetNode(message_.replacement_id()));
|
||||||
|
|
||||||
auto* cloned_replacement =
|
auto* cloned_replacement =
|
||||||
clone_context->dst->Expr(clone_context->Clone(use_node->source()),
|
clone_context->dst->Expr(clone_context->Clone(use_node->source),
|
||||||
clone_context->Clone(replacement_var->symbol()));
|
clone_context->Clone(replacement_var->symbol));
|
||||||
clone_context->Replace(use_node, cloned_replacement);
|
clone_context->Replace(use_node, cloned_replacement);
|
||||||
new_node_id_map->Add(cloned_replacement, message_.use_id());
|
new_node_id_map->Add(cloned_replacement, message_.use_id());
|
||||||
}
|
}
|
||||||
|
@ -49,19 +49,18 @@ TEST(ReplaceIdentifierTest, NotApplicable_Simple) {
|
|||||||
|
|
||||||
NodeIdMap node_id_map(program);
|
NodeIdMap node_id_map(program);
|
||||||
|
|
||||||
const auto& main_fn_stmts =
|
const auto& main_fn_stmts = program.AST().Functions()[0]->body->statements;
|
||||||
program.AST().Functions()[0]->body()->statements();
|
|
||||||
|
|
||||||
const auto* a_var =
|
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);
|
ASSERT_NE(a_var, nullptr);
|
||||||
|
|
||||||
const auto* b_var =
|
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);
|
ASSERT_NE(b_var, nullptr);
|
||||||
|
|
||||||
const auto* e_var =
|
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);
|
ASSERT_NE(e_var, nullptr);
|
||||||
|
|
||||||
auto a_var_id = node_id_map.GetId(a_var);
|
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);
|
auto b_var_id = node_id_map.GetId(b_var);
|
||||||
ASSERT_NE(b_var_id, 0);
|
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);
|
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);
|
ASSERT_NE(a_ident_id, 0);
|
||||||
|
|
||||||
auto sum_expr_id = node_id_map.GetId(sum_expr);
|
auto sum_expr_id = node_id_map.GetId(sum_expr);
|
||||||
@ -83,7 +82,7 @@ TEST(ReplaceIdentifierTest, NotApplicable_Simple) {
|
|||||||
ASSERT_NE(e_var_id, 0);
|
ASSERT_NE(e_var_id, 0);
|
||||||
|
|
||||||
auto vec_member_access_id = node_id_map.GetId(
|
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);
|
ASSERT_NE(vec_member_access_id, 0);
|
||||||
|
|
||||||
// use_id is invalid.
|
// use_id is invalid.
|
||||||
@ -136,10 +135,9 @@ var<private> b: i32;
|
|||||||
|
|
||||||
auto use_id = node_id_map.GetId(program.AST()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[0]
|
||||||
->statements()[0]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->lhs());
|
->lhs);
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[1]);
|
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()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[0]
|
||||||
->statements()[0]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->lhs()
|
->lhs->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::UnaryOpExpression>()
|
->expr->As<ast::UnaryOpExpression>()
|
||||||
->expr()
|
->expr);
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
||||||
@ -202,22 +197,18 @@ fn f() {
|
|||||||
|
|
||||||
auto replacement_id = node_id_map.GetId(program.AST()
|
auto replacement_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[0]
|
||||||
->statements()[0]
|
|
||||||
->As<ast::VariableDeclStatement>()
|
->As<ast::VariableDeclStatement>()
|
||||||
->variable());
|
->variable);
|
||||||
ASSERT_NE(replacement_id, 0);
|
ASSERT_NE(replacement_id, 0);
|
||||||
|
|
||||||
auto use_id = node_id_map.GetId(program.AST()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[1]
|
||||||
->statements()[1]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->lhs()
|
->lhs->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::UnaryOpExpression>()
|
->expr->As<ast::UnaryOpExpression>()
|
||||||
->expr()
|
->expr);
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
||||||
@ -242,22 +233,18 @@ fn f() {
|
|||||||
|
|
||||||
auto replacement_id = node_id_map.GetId(program.AST()
|
auto replacement_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[0]
|
||||||
->statements()[0]
|
|
||||||
->As<ast::VariableDeclStatement>()
|
->As<ast::VariableDeclStatement>()
|
||||||
->variable());
|
->variable);
|
||||||
ASSERT_NE(replacement_id, 0);
|
ASSERT_NE(replacement_id, 0);
|
||||||
|
|
||||||
auto use_id = node_id_map.GetId(program.AST()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[1]
|
||||||
->statements()[1]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->lhs()
|
->lhs->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::UnaryOpExpression>()
|
->expr->As<ast::UnaryOpExpression>()
|
||||||
->expr()
|
->expr);
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
||||||
@ -280,19 +267,16 @@ fn f(b: i32) {
|
|||||||
NodeIdMap node_id_map(program);
|
NodeIdMap node_id_map(program);
|
||||||
|
|
||||||
auto replacement_id =
|
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_NE(replacement_id, 0);
|
||||||
|
|
||||||
auto use_id = node_id_map.GetId(program.AST()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[0]
|
||||||
->statements()[0]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->lhs()
|
->lhs->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::UnaryOpExpression>()
|
->expr->As<ast::UnaryOpExpression>()
|
||||||
->expr()
|
->expr);
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
||||||
@ -325,14 +309,11 @@ fn f() {
|
|||||||
|
|
||||||
auto use_id = node_id_map.GetId(program.AST()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[0]
|
||||||
->statements()[0]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->lhs()
|
->lhs->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::UnaryOpExpression>()
|
->expr->As<ast::UnaryOpExpression>()
|
||||||
->expr()
|
->expr);
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
||||||
@ -365,12 +346,10 @@ fn f() {
|
|||||||
|
|
||||||
auto use_id = node_id_map.GetId(program.AST()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[1]
|
||||||
->statements()[1]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->rhs()
|
->rhs->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::UnaryOpExpression>()
|
->expr);
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
||||||
@ -405,12 +384,10 @@ fn f() {
|
|||||||
|
|
||||||
auto use_id = node_id_map.GetId(program.AST()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[1]
|
||||||
->statements()[1]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->rhs()
|
->rhs->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::UnaryOpExpression>()
|
->expr);
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
||||||
@ -443,14 +420,11 @@ fn f() {
|
|||||||
|
|
||||||
auto use_id = node_id_map.GetId(program.AST()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[0]
|
||||||
->statements()[0]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->rhs()
|
->rhs->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::UnaryOpExpression>()
|
->expr->As<ast::UnaryOpExpression>()
|
||||||
->expr()
|
->expr);
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
||||||
@ -483,14 +457,11 @@ fn f() {
|
|||||||
|
|
||||||
auto use_id = node_id_map.GetId(program.AST()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[0]
|
||||||
->statements()[0]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->rhs()
|
->rhs->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::UnaryOpExpression>()
|
->expr->As<ast::UnaryOpExpression>()
|
||||||
->expr()
|
->expr);
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
||||||
@ -514,24 +485,19 @@ fn f() {
|
|||||||
|
|
||||||
auto use_id = node_id_map.GetId(program.AST()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[2]
|
||||||
->statements()[2]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->lhs()
|
->lhs->As<ast::ArrayAccessorExpression>()
|
||||||
->As<ast::ArrayAccessorExpression>()
|
->array->As<ast::UnaryOpExpression>()
|
||||||
->array()
|
->expr->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::UnaryOpExpression>()
|
->expr);
|
||||||
->expr()
|
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
auto replacement_id = node_id_map.GetId(program.AST()
|
auto replacement_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[0]
|
||||||
->statements()[0]
|
|
||||||
->As<ast::VariableDeclStatement>()
|
->As<ast::VariableDeclStatement>()
|
||||||
->variable());
|
->variable);
|
||||||
ASSERT_NE(replacement_id, 0);
|
ASSERT_NE(replacement_id, 0);
|
||||||
|
|
||||||
ASSERT_TRUE(MaybeApplyMutation(
|
ASSERT_TRUE(MaybeApplyMutation(
|
||||||
@ -569,18 +535,15 @@ fn f(b: ptr<function, vec2<u32>>) {
|
|||||||
|
|
||||||
auto use_id = node_id_map.GetId(program.AST()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[2]
|
||||||
->statements()[2]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->lhs()
|
->lhs->As<ast::ArrayAccessorExpression>()
|
||||||
->As<ast::ArrayAccessorExpression>()
|
->array->As<ast::UnaryOpExpression>()
|
||||||
->array()
|
->expr);
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
auto replacement_id =
|
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_NE(replacement_id, 0);
|
||||||
|
|
||||||
ASSERT_TRUE(MaybeApplyMutation(
|
ASSERT_TRUE(MaybeApplyMutation(
|
||||||
@ -619,16 +582,12 @@ fn f() {
|
|||||||
|
|
||||||
auto use_id = node_id_map.GetId(program.AST()
|
auto use_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[1]
|
||||||
->statements()[1]
|
|
||||||
->As<ast::AssignmentStatement>()
|
->As<ast::AssignmentStatement>()
|
||||||
->lhs()
|
->lhs->As<ast::ArrayAccessorExpression>()
|
||||||
->As<ast::ArrayAccessorExpression>()
|
->array->As<ast::UnaryOpExpression>()
|
||||||
->array()
|
->expr->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::UnaryOpExpression>()
|
->expr);
|
||||||
->expr()
|
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[0]);
|
auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[0]);
|
||||||
@ -654,19 +613,15 @@ fn f() {
|
|||||||
|
|
||||||
NodeIdMap node_id_map(program);
|
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]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[1]
|
||||||
->statements()[1]
|
|
||||||
->As<ast::VariableDeclStatement>()
|
->As<ast::VariableDeclStatement>()
|
||||||
->variable()
|
->variable->constructor->As<ast::ArrayAccessorExpression>()
|
||||||
->constructor()
|
->array->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::ArrayAccessorExpression>()
|
->expr->As<ast::UnaryOpExpression>()
|
||||||
->array()
|
->expr);
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr()
|
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[0]);
|
auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[0]);
|
||||||
@ -694,25 +649,21 @@ fn f() {
|
|||||||
|
|
||||||
NodeIdMap node_id_map(program);
|
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]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[3]
|
||||||
->statements()[3]
|
|
||||||
->As<ast::VariableDeclStatement>()
|
->As<ast::VariableDeclStatement>()
|
||||||
->variable()
|
->variable->constructor->As<ast::ArrayAccessorExpression>()
|
||||||
->constructor()
|
->array->As<ast::UnaryOpExpression>()
|
||||||
->As<ast::ArrayAccessorExpression>()
|
->expr);
|
||||||
->array()
|
|
||||||
->As<ast::UnaryOpExpression>()
|
|
||||||
->expr());
|
|
||||||
ASSERT_NE(use_id, 0);
|
ASSERT_NE(use_id, 0);
|
||||||
|
|
||||||
auto replacement_id = node_id_map.GetId(program.AST()
|
auto replacement_id = node_id_map.GetId(program.AST()
|
||||||
.Functions()[0]
|
.Functions()[0]
|
||||||
->body()
|
->body->statements[2]
|
||||||
->statements()[2]
|
|
||||||
->As<ast::VariableDeclStatement>()
|
->As<ast::VariableDeclStatement>()
|
||||||
->variable());
|
->variable);
|
||||||
ASSERT_NE(replacement_id, 0);
|
ASSERT_NE(replacement_id, 0);
|
||||||
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id)
|
||||||
.IsApplicable(program, node_id_map));
|
.IsApplicable(program, node_id_map));
|
||||||
|
@ -54,7 +54,7 @@ std::vector<const sem::Variable*> GetAllVarsInScope(
|
|||||||
// Walk up the hierarchy of blocks in which `curr_stmt` is contained.
|
// Walk up the hierarchy of blocks in which `curr_stmt` is contained.
|
||||||
for (const auto* block = curr_stmt->Block(); block;
|
for (const auto* block = curr_stmt->Block(); block;
|
||||||
block = tint::As<sem::BlockStatement>(block->Parent())) {
|
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()) {
|
if (stmt == curr_stmt->Declaration()) {
|
||||||
// `curr_stmt` was found. This is only possible if `block is the
|
// `curr_stmt` was found. This is only possible if `block is the
|
||||||
// enclosing block of `curr_stmt` since the AST nodes are not shared.
|
// 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)) {
|
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)) {
|
if (pred(sem_var)) {
|
||||||
result.push_back(sem_var);
|
result.push_back(sem_var);
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ std::vector<const sem::Variable*> GetAllVarsInScope(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process function parameters.
|
// 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);
|
const auto* sem_var = program.Sem().Get(param);
|
||||||
if (pred(sem_var)) {
|
if (pred(sem_var)) {
|
||||||
result.push_back(sem_var);
|
result.push_back(sem_var);
|
||||||
|
@ -21,12 +21,9 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Alias);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
Alias::Alias(ProgramID program_id,
|
Alias::Alias(ProgramID pid, const Source& src, const Symbol& n, Type* subtype)
|
||||||
const Source& source,
|
: Base(pid, src, n), type(subtype) {
|
||||||
const Symbol& name,
|
TINT_ASSERT(AST, type);
|
||||||
Type* subtype)
|
|
||||||
: Base(program_id, source, name), subtype_(subtype) {
|
|
||||||
TINT_ASSERT(AST, subtype_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Alias::Alias(Alias&&) = default;
|
Alias::Alias(Alias&&) = default;
|
||||||
@ -35,9 +32,9 @@ Alias::~Alias() = default;
|
|||||||
|
|
||||||
Alias* Alias::Clone(CloneContext* ctx) const {
|
Alias* Alias::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto sym = ctx->Clone(name());
|
auto sym = ctx->Clone(name);
|
||||||
auto* ty = ctx->Clone(type());
|
auto* ty = ctx->Clone(type);
|
||||||
return ctx->dst->create<Alias>(src, sym, ty);
|
return ctx->dst->create<Alias>(src, sym, ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,32 +26,23 @@ namespace ast {
|
|||||||
class Alias : public Castable<Alias, TypeDecl> {
|
class Alias : public Castable<Alias, TypeDecl> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source of this node
|
/// @param src the source of this node
|
||||||
/// @param name the symbol for the alias
|
/// @param name the symbol for the alias
|
||||||
/// @param subtype the alias'd type
|
/// @param subtype the alias'd type
|
||||||
Alias(ProgramID program_id,
|
Alias(ProgramID pid, const Source& src, const Symbol& name, Type* subtype);
|
||||||
const Source& source,
|
|
||||||
const Symbol& name,
|
|
||||||
Type* subtype);
|
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
Alias(Alias&&);
|
Alias(Alias&&);
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~Alias() override;
|
~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`.
|
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned type
|
/// @return the newly cloned type
|
||||||
Alias* Clone(CloneContext* ctx) const override;
|
Alias* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
private:
|
/// the alias type
|
||||||
Type* const subtype_;
|
Type* const type;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -36,8 +36,8 @@ using AstAliasTest = TestHelper;
|
|||||||
TEST_F(AstAliasTest, Create) {
|
TEST_F(AstAliasTest, Create) {
|
||||||
auto* u32 = create<U32>();
|
auto* u32 = create<U32>();
|
||||||
auto* a = Alias("a_type", u32);
|
auto* a = Alias("a_type", u32);
|
||||||
EXPECT_EQ(a->symbol(), Symbol(1, ID()));
|
EXPECT_EQ(a->name, Symbol(1, ID()));
|
||||||
EXPECT_EQ(a->type(), u32);
|
EXPECT_EQ(a->type, u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -29,14 +29,14 @@ std::string SizeExprToString(const ast::Expression* size,
|
|||||||
const SymbolTable* symbols = nullptr) {
|
const SymbolTable* symbols = nullptr) {
|
||||||
if (auto* ident = size->As<ast::IdentifierExpression>()) {
|
if (auto* ident = size->As<ast::IdentifierExpression>()) {
|
||||||
if (symbols) {
|
if (symbols) {
|
||||||
return symbols->NameFor(ident->symbol());
|
return symbols->NameFor(ident->symbol);
|
||||||
}
|
}
|
||||||
return "<unknown>";
|
return "<unknown>";
|
||||||
}
|
}
|
||||||
if (auto* scalar = size->As<ast::ScalarConstructorExpression>()) {
|
if (auto* scalar = size->As<ast::ScalarConstructorExpression>()) {
|
||||||
auto* literal = scalar->literal()->As<ast::IntLiteral>();
|
auto* literal = scalar->literal->As<ast::IntLiteral>();
|
||||||
if (literal) {
|
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
|
// 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
|
} // namespace
|
||||||
|
|
||||||
Array::Array(ProgramID program_id,
|
Array::Array(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
Type* subtype,
|
Type* subtype,
|
||||||
ast::Expression* size,
|
ast::Expression* cnt,
|
||||||
ast::DecorationList decorations)
|
ast::DecorationList decos)
|
||||||
: Base(program_id, source),
|
: Base(pid, src), type(subtype), count(cnt), decorations(decos) {}
|
||||||
subtype_(subtype),
|
|
||||||
size_(size),
|
|
||||||
decos_(decorations) {}
|
|
||||||
|
|
||||||
Array::Array(Array&&) = default;
|
Array::Array(Array&&) = default;
|
||||||
|
|
||||||
@ -61,14 +58,14 @@ Array::~Array() = default;
|
|||||||
|
|
||||||
std::string Array::FriendlyName(const SymbolTable& symbols) const {
|
std::string Array::FriendlyName(const SymbolTable& symbols) const {
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
for (auto* deco : decos_) {
|
for (auto* deco : decorations) {
|
||||||
if (auto* stride = deco->As<ast::StrideDecoration>()) {
|
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()) {
|
if (!IsRuntimeArray()) {
|
||||||
out << ", " << SizeExprToString(size_, &symbols);
|
out << ", " << SizeExprToString(count, &symbols);
|
||||||
}
|
}
|
||||||
out << ">";
|
out << ">";
|
||||||
return out.str();
|
return out.str();
|
||||||
@ -76,11 +73,11 @@ std::string Array::FriendlyName(const SymbolTable& symbols) const {
|
|||||||
|
|
||||||
Array* Array::Clone(CloneContext* ctx) const {
|
Array* Array::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto* ty = ctx->Clone(type());
|
auto* ty = ctx->Clone(type);
|
||||||
auto* size = ctx->Clone(Size());
|
auto* cnt = ctx->Clone(count);
|
||||||
auto decos = ctx->Clone(decorations());
|
auto decos = ctx->Clone(decorations);
|
||||||
return ctx->dst->create<Array>(src, ty, size, decos);
|
return ctx->dst->create<Array>(src, ty, cnt, decos);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -30,16 +30,16 @@ class Expression;
|
|||||||
class Array : public Castable<Array, Type> {
|
class Array : public Castable<Array, Type> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source of this node
|
/// @param src the source of this node
|
||||||
/// @param subtype the type of the array elements
|
/// @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.
|
/// runtime-sized array.
|
||||||
/// @param decorations the array decorations
|
/// @param decorations the array decorations
|
||||||
Array(ProgramID program_id,
|
Array(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
Type* subtype,
|
Type* subtype,
|
||||||
ast::Expression* size,
|
ast::Expression* count,
|
||||||
ast::DecorationList decorations);
|
ast::DecorationList decorations);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
Array(Array&&);
|
Array(Array&&);
|
||||||
@ -47,16 +47,7 @@ class Array : public Castable<Array, Type> {
|
|||||||
|
|
||||||
/// @returns true if this is a runtime array.
|
/// @returns true if this is a runtime array.
|
||||||
/// i.e. the size is determined at runtime
|
/// i.e. the size is determined at runtime
|
||||||
bool IsRuntimeArray() const { return size_ == nullptr; }
|
bool IsRuntimeArray() const { return count == 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_; }
|
|
||||||
|
|
||||||
/// @param symbols the program's symbol table
|
/// @param symbols the program's symbol table
|
||||||
/// @returns the name for this type that closely resembles how it would be
|
/// @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
|
/// @return the newly cloned type
|
||||||
Array* Clone(CloneContext* ctx) const override;
|
Array* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
private:
|
/// the array element type
|
||||||
Type* const subtype_;
|
Type* const type;
|
||||||
ast::Expression* const size_;
|
|
||||||
ast::DecorationList const decos_;
|
/// the array size in elements, or nullptr for a runtime array
|
||||||
|
ast::Expression* const count;
|
||||||
|
|
||||||
|
/// the array decorations
|
||||||
|
ast::DecorationList const decorations;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -21,15 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ArrayAccessorExpression);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
ArrayAccessorExpression::ArrayAccessorExpression(ProgramID program_id,
|
ArrayAccessorExpression::ArrayAccessorExpression(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
Expression* array,
|
Expression* arr,
|
||||||
Expression* idx_expr)
|
Expression* idx)
|
||||||
: Base(program_id, source), array_(array), idx_expr_(idx_expr) {
|
: Base(pid, src), array(arr), index(idx) {
|
||||||
TINT_ASSERT(AST, array_);
|
TINT_ASSERT(AST, array);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, array_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, array, program_id);
|
||||||
TINT_ASSERT(AST, idx_expr_);
|
TINT_ASSERT(AST, idx);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, idx_expr_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, idx, program_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayAccessorExpression::ArrayAccessorExpression(ArrayAccessorExpression&&) =
|
ArrayAccessorExpression::ArrayAccessorExpression(ArrayAccessorExpression&&) =
|
||||||
@ -40,9 +40,9 @@ ArrayAccessorExpression::~ArrayAccessorExpression() = default;
|
|||||||
ArrayAccessorExpression* ArrayAccessorExpression::Clone(
|
ArrayAccessorExpression* ArrayAccessorExpression::Clone(
|
||||||
CloneContext* ctx) const {
|
CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto* arr = ctx->Clone(array_);
|
auto* arr = ctx->Clone(array);
|
||||||
auto* idx = ctx->Clone(idx_expr_);
|
auto* idx = ctx->Clone(index);
|
||||||
return ctx->dst->create<ArrayAccessorExpression>(src, arr, idx);
|
return ctx->dst->create<ArrayAccessorExpression>(src, arr, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,33 +27,30 @@ class ArrayAccessorExpression
|
|||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param program_id the identifier of the program that owns this node
|
/// @param program_id the identifier of the program that owns this node
|
||||||
/// @param source the array accessor source
|
/// @param source the array accessor source
|
||||||
/// @param array the array
|
/// @param arr the array
|
||||||
/// @param idx_expr the index expression
|
/// @param idx the index expression
|
||||||
ArrayAccessorExpression(ProgramID program_id,
|
ArrayAccessorExpression(ProgramID program_id,
|
||||||
const Source& source,
|
const Source& source,
|
||||||
Expression* array,
|
Expression* arr,
|
||||||
Expression* idx_expr);
|
Expression* idx);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
ArrayAccessorExpression(ArrayAccessorExpression&&);
|
ArrayAccessorExpression(ArrayAccessorExpression&&);
|
||||||
~ArrayAccessorExpression() override;
|
~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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
ArrayAccessorExpression* Clone(CloneContext* ctx) const override;
|
ArrayAccessorExpression* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
|
/// the array
|
||||||
|
Expression* const array;
|
||||||
|
|
||||||
|
/// the index expression
|
||||||
|
Expression* const index;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ArrayAccessorExpression(const ArrayAccessorExpression&) = delete;
|
ArrayAccessorExpression(const ArrayAccessorExpression&) = delete;
|
||||||
|
|
||||||
Expression* const array_;
|
|
||||||
Expression* const idx_expr_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -26,8 +26,8 @@ TEST_F(ArrayAccessorExpressionTest, Create) {
|
|||||||
auto* idx = Expr("idx");
|
auto* idx = Expr("idx");
|
||||||
|
|
||||||
auto* exp = create<ArrayAccessorExpression>(ary, idx);
|
auto* exp = create<ArrayAccessorExpression>(ary, idx);
|
||||||
ASSERT_EQ(exp->array(), ary);
|
ASSERT_EQ(exp->array, ary);
|
||||||
ASSERT_EQ(exp->idx_expr(), idx);
|
ASSERT_EQ(exp->index, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
|
TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
|
||||||
@ -36,7 +36,7 @@ TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
|
|||||||
|
|
||||||
auto* exp = create<ArrayAccessorExpression>(Source{Source::Location{20, 2}},
|
auto* exp = create<ArrayAccessorExpression>(Source{Source::Location{20, 2}},
|
||||||
ary, idx);
|
ary, idx);
|
||||||
auto src = exp->source();
|
auto src = exp->source;
|
||||||
EXPECT_EQ(src.range.begin.line, 20u);
|
EXPECT_EQ(src.range.begin.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,10 @@ using AstArrayTest = TestHelper;
|
|||||||
|
|
||||||
TEST_F(AstArrayTest, CreateSizedArray) {
|
TEST_F(AstArrayTest, CreateSizedArray) {
|
||||||
auto* u32 = create<U32>();
|
auto* u32 = create<U32>();
|
||||||
auto* size = Expr(3);
|
auto* count = Expr(3);
|
||||||
auto* arr = create<Array>(u32, size, DecorationList{});
|
auto* arr = create<Array>(u32, count, DecorationList{});
|
||||||
EXPECT_EQ(arr->type(), u32);
|
EXPECT_EQ(arr->type, u32);
|
||||||
EXPECT_EQ(arr->Size(), size);
|
EXPECT_EQ(arr->count, count);
|
||||||
EXPECT_TRUE(arr->Is<Array>());
|
EXPECT_TRUE(arr->Is<Array>());
|
||||||
EXPECT_FALSE(arr->IsRuntimeArray());
|
EXPECT_FALSE(arr->IsRuntimeArray());
|
||||||
}
|
}
|
||||||
@ -35,8 +35,8 @@ TEST_F(AstArrayTest, CreateSizedArray) {
|
|||||||
TEST_F(AstArrayTest, CreateRuntimeArray) {
|
TEST_F(AstArrayTest, CreateRuntimeArray) {
|
||||||
auto* u32 = create<U32>();
|
auto* u32 = create<U32>();
|
||||||
auto* arr = create<Array>(u32, nullptr, DecorationList{});
|
auto* arr = create<Array>(u32, nullptr, DecorationList{});
|
||||||
EXPECT_EQ(arr->type(), u32);
|
EXPECT_EQ(arr->type, u32);
|
||||||
EXPECT_EQ(arr->Size(), nullptr);
|
EXPECT_EQ(arr->count, nullptr);
|
||||||
EXPECT_TRUE(arr->Is<Array>());
|
EXPECT_TRUE(arr->Is<Array>());
|
||||||
EXPECT_TRUE(arr->IsRuntimeArray());
|
EXPECT_TRUE(arr->IsRuntimeArray());
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::AssignmentStatement);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
AssignmentStatement::AssignmentStatement(ProgramID program_id,
|
AssignmentStatement::AssignmentStatement(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
Expression* lhs,
|
Expression* l,
|
||||||
Expression* rhs)
|
Expression* r)
|
||||||
: Base(program_id, source), lhs_(lhs), rhs_(rhs) {
|
: Base(pid, src), lhs(l), rhs(r) {
|
||||||
TINT_ASSERT(AST, lhs_);
|
TINT_ASSERT(AST, lhs);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id);
|
||||||
TINT_ASSERT(AST, rhs_);
|
TINT_ASSERT(AST, rhs);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs, program_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
AssignmentStatement::AssignmentStatement(AssignmentStatement&&) = default;
|
AssignmentStatement::AssignmentStatement(AssignmentStatement&&) = default;
|
||||||
@ -38,9 +38,9 @@ AssignmentStatement::~AssignmentStatement() = default;
|
|||||||
|
|
||||||
AssignmentStatement* AssignmentStatement::Clone(CloneContext* ctx) const {
|
AssignmentStatement* AssignmentStatement::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto* l = ctx->Clone(lhs_);
|
auto* l = ctx->Clone(lhs);
|
||||||
auto* r = ctx->Clone(rhs_);
|
auto* r = ctx->Clone(rhs);
|
||||||
return ctx->dst->create<AssignmentStatement>(src, l, r);
|
return ctx->dst->create<AssignmentStatement>(src, l, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,22 +37,20 @@ class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
|
|||||||
AssignmentStatement(AssignmentStatement&&);
|
AssignmentStatement(AssignmentStatement&&);
|
||||||
~AssignmentStatement() override;
|
~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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
AssignmentStatement* Clone(CloneContext* ctx) const override;
|
AssignmentStatement* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
|
/// left side expression
|
||||||
|
Expression* const lhs;
|
||||||
|
|
||||||
|
/// right side expression
|
||||||
|
Expression* const rhs;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AssignmentStatement(const AssignmentStatement&) = delete;
|
AssignmentStatement(const AssignmentStatement&) = delete;
|
||||||
|
|
||||||
Expression* const lhs_;
|
|
||||||
Expression* const rhs_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -28,8 +28,8 @@ TEST_F(AssignmentStatementTest, Creation) {
|
|||||||
auto* rhs = Expr("rhs");
|
auto* rhs = Expr("rhs");
|
||||||
|
|
||||||
auto* stmt = create<AssignmentStatement>(lhs, rhs);
|
auto* stmt = create<AssignmentStatement>(lhs, rhs);
|
||||||
EXPECT_EQ(stmt->lhs(), lhs);
|
EXPECT_EQ(stmt->lhs, lhs);
|
||||||
EXPECT_EQ(stmt->rhs(), rhs);
|
EXPECT_EQ(stmt->rhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AssignmentStatementTest, CreationWithSource) {
|
TEST_F(AssignmentStatementTest, CreationWithSource) {
|
||||||
@ -38,7 +38,7 @@ TEST_F(AssignmentStatementTest, CreationWithSource) {
|
|||||||
|
|
||||||
auto* stmt =
|
auto* stmt =
|
||||||
create<AssignmentStatement>(Source{Source::Location{20, 2}}, lhs, rhs);
|
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.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Type);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
Type::Type(ProgramID program_id, const Source& source)
|
Type::Type(ProgramID pid, const Source& src) : Base(pid, src) {}
|
||||||
: Base(program_id, source) {}
|
|
||||||
|
|
||||||
Type::Type(Type&&) = default;
|
Type::Type(Type&&) = default;
|
||||||
|
|
||||||
|
@ -21,12 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Atomic);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
Atomic::Atomic(ProgramID program_id, const Source& source, Type* const subtype)
|
Atomic::Atomic(ProgramID pid, const Source& src, Type* const subtype)
|
||||||
: Base(program_id, source), subtype_(subtype) {}
|
: Base(pid, src), type(subtype) {}
|
||||||
|
|
||||||
std::string Atomic::FriendlyName(const SymbolTable& symbols) const {
|
std::string Atomic::FriendlyName(const SymbolTable& symbols) const {
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "atomic<" << subtype_->FriendlyName(symbols) << ">";
|
out << "atomic<" << type->FriendlyName(symbols) << ">";
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,8 +36,8 @@ Atomic::~Atomic() = default;
|
|||||||
|
|
||||||
Atomic* Atomic::Clone(CloneContext* ctx) const {
|
Atomic* Atomic::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto* ty = ctx->Clone(type());
|
auto* ty = ctx->Clone(const_cast<Type*>(type));
|
||||||
return ctx->dst->create<Atomic>(src, ty);
|
return ctx->dst->create<Atomic>(src, ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,17 +26,14 @@ namespace ast {
|
|||||||
class Atomic : public Castable<Atomic, Type> {
|
class Atomic : public Castable<Atomic, Type> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source of this node
|
/// @param src the source of this node
|
||||||
/// @param subtype the pointee type
|
/// @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
|
/// Move constructor
|
||||||
Atomic(Atomic&&);
|
Atomic(Atomic&&);
|
||||||
~Atomic() override;
|
~Atomic() override;
|
||||||
|
|
||||||
/// @returns the pointee type
|
|
||||||
Type* type() const { return const_cast<Type*>(subtype_); }
|
|
||||||
|
|
||||||
/// @param symbols the program's symbol table
|
/// @param symbols the program's symbol table
|
||||||
/// @returns the name for this type that closely resembles how it would be
|
/// @returns the name for this type that closely resembles how it would be
|
||||||
/// declared in WGSL.
|
/// declared in WGSL.
|
||||||
@ -47,8 +44,8 @@ class Atomic : public Castable<Atomic, Type> {
|
|||||||
/// @return the newly cloned type
|
/// @return the newly cloned type
|
||||||
Atomic* Clone(CloneContext* ctx) const override;
|
Atomic* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
private:
|
/// the pointee type
|
||||||
Type const* const subtype_;
|
Type const* const type;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -26,7 +26,7 @@ using AstAtomicTest = TestHelper;
|
|||||||
TEST_F(AstAtomicTest, Creation) {
|
TEST_F(AstAtomicTest, Creation) {
|
||||||
auto* i32 = create<I32>();
|
auto* i32 = create<I32>();
|
||||||
auto* p = create<Atomic>(i32);
|
auto* p = create<Atomic>(i32);
|
||||||
EXPECT_EQ(p->type(), i32);
|
EXPECT_EQ(p->type, i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AstAtomicTest, FriendlyName) {
|
TEST_F(AstAtomicTest, FriendlyName) {
|
||||||
|
@ -21,17 +21,17 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BinaryExpression);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
BinaryExpression::BinaryExpression(ProgramID program_id,
|
BinaryExpression::BinaryExpression(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
BinaryOp op,
|
BinaryOp o,
|
||||||
Expression* lhs,
|
Expression* l,
|
||||||
Expression* rhs)
|
Expression* r)
|
||||||
: Base(program_id, source), op_(op), lhs_(lhs), rhs_(rhs) {
|
: Base(pid, src), op(o), lhs(l), rhs(r) {
|
||||||
TINT_ASSERT(AST, lhs_);
|
TINT_ASSERT(AST, lhs);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id);
|
||||||
TINT_ASSERT(AST, rhs_);
|
TINT_ASSERT(AST, rhs);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs, program_id);
|
||||||
TINT_ASSERT(AST, op_ != BinaryOp::kNone);
|
TINT_ASSERT(AST, op != BinaryOp::kNone);
|
||||||
}
|
}
|
||||||
|
|
||||||
BinaryExpression::BinaryExpression(BinaryExpression&&) = default;
|
BinaryExpression::BinaryExpression(BinaryExpression&&) = default;
|
||||||
@ -40,10 +40,10 @@ BinaryExpression::~BinaryExpression() = default;
|
|||||||
|
|
||||||
BinaryExpression* BinaryExpression::Clone(CloneContext* ctx) const {
|
BinaryExpression* BinaryExpression::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto* l = ctx->Clone(lhs_);
|
auto* l = ctx->Clone(lhs);
|
||||||
auto* r = ctx->Clone(rhs_);
|
auto* r = ctx->Clone(rhs);
|
||||||
return ctx->dst->create<BinaryExpression>(src, op_, l, r);
|
return ctx->dst->create<BinaryExpression>(src, op, l, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -61,45 +61,42 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
|
|||||||
BinaryExpression(BinaryExpression&&);
|
BinaryExpression(BinaryExpression&&);
|
||||||
~BinaryExpression() override;
|
~BinaryExpression() override;
|
||||||
|
|
||||||
/// @returns the binary op type
|
|
||||||
BinaryOp op() const { return op_; }
|
|
||||||
|
|
||||||
/// @returns true if the op is and
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @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
|
/// @returns true if the op is an arithmetic operation
|
||||||
bool IsArithmetic() const;
|
bool IsArithmetic() const;
|
||||||
/// @returns true if the op is a comparison operation
|
/// @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
|
/// @returns true if the op is a bit shift operation
|
||||||
bool IsBitshift() const;
|
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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
BinaryExpression* Clone(CloneContext* ctx) const override;
|
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:
|
private:
|
||||||
BinaryExpression(const BinaryExpression&) = delete;
|
BinaryExpression(const BinaryExpression&) = delete;
|
||||||
|
|
||||||
BinaryOp const op_;
|
|
||||||
Expression* const lhs_;
|
|
||||||
Expression* const rhs_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool BinaryExpression::IsArithmetic() const {
|
inline bool BinaryExpression::IsArithmetic() const {
|
||||||
switch (op_) {
|
switch (op) {
|
||||||
case ast::BinaryOp::kAdd:
|
case ast::BinaryOp::kAdd:
|
||||||
case ast::BinaryOp::kSubtract:
|
case ast::BinaryOp::kSubtract:
|
||||||
case ast::BinaryOp::kMultiply:
|
case ast::BinaryOp::kMultiply:
|
||||||
@ -142,7 +137,7 @@ inline bool BinaryExpression::IsArithmetic() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool BinaryExpression::IsComparison() const {
|
inline bool BinaryExpression::IsComparison() const {
|
||||||
switch (op_) {
|
switch (op) {
|
||||||
case ast::BinaryOp::kEqual:
|
case ast::BinaryOp::kEqual:
|
||||||
case ast::BinaryOp::kNotEqual:
|
case ast::BinaryOp::kNotEqual:
|
||||||
case ast::BinaryOp::kLessThan:
|
case ast::BinaryOp::kLessThan:
|
||||||
@ -156,7 +151,7 @@ inline bool BinaryExpression::IsComparison() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool BinaryExpression::IsBitwise() const {
|
inline bool BinaryExpression::IsBitwise() const {
|
||||||
switch (op_) {
|
switch (op) {
|
||||||
case ast::BinaryOp::kAnd:
|
case ast::BinaryOp::kAnd:
|
||||||
case ast::BinaryOp::kOr:
|
case ast::BinaryOp::kOr:
|
||||||
case ast::BinaryOp::kXor:
|
case ast::BinaryOp::kXor:
|
||||||
@ -167,7 +162,7 @@ inline bool BinaryExpression::IsBitwise() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool BinaryExpression::IsBitshift() const {
|
inline bool BinaryExpression::IsBitshift() const {
|
||||||
switch (op_) {
|
switch (op) {
|
||||||
case ast::BinaryOp::kShiftLeft:
|
case ast::BinaryOp::kShiftLeft:
|
||||||
case ast::BinaryOp::kShiftRight:
|
case ast::BinaryOp::kShiftRight:
|
||||||
return true;
|
return true;
|
||||||
|
@ -26,9 +26,9 @@ TEST_F(BinaryExpressionTest, Creation) {
|
|||||||
auto* rhs = Expr("rhs");
|
auto* rhs = Expr("rhs");
|
||||||
|
|
||||||
auto* r = create<BinaryExpression>(BinaryOp::kEqual, lhs, rhs);
|
auto* r = create<BinaryExpression>(BinaryOp::kEqual, lhs, rhs);
|
||||||
EXPECT_EQ(r->lhs(), lhs);
|
EXPECT_EQ(r->lhs, lhs);
|
||||||
EXPECT_EQ(r->rhs(), rhs);
|
EXPECT_EQ(r->rhs, rhs);
|
||||||
EXPECT_EQ(r->op(), BinaryOp::kEqual);
|
EXPECT_EQ(r->op, BinaryOp::kEqual);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BinaryExpressionTest, Creation_WithSource) {
|
TEST_F(BinaryExpressionTest, Creation_WithSource) {
|
||||||
@ -37,7 +37,7 @@ TEST_F(BinaryExpressionTest, Creation_WithSource) {
|
|||||||
|
|
||||||
auto* r = create<BinaryExpression>(Source{Source::Location{20, 2}},
|
auto* r = create<BinaryExpression>(Source{Source::Location{20, 2}},
|
||||||
BinaryOp::kEqual, lhs, rhs);
|
BinaryOp::kEqual, lhs, rhs);
|
||||||
auto src = r->source();
|
auto src = r->source;
|
||||||
EXPECT_EQ(src.range.begin.line, 20u);
|
EXPECT_EQ(src.range.begin.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
@ -23,21 +23,21 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BindingDecoration);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
BindingDecoration::BindingDecoration(ProgramID program_id,
|
BindingDecoration::BindingDecoration(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
uint32_t val)
|
uint32_t val)
|
||||||
: Base(program_id, source), value_(val) {}
|
: Base(pid, src), value(val) {}
|
||||||
|
|
||||||
BindingDecoration::~BindingDecoration() = default;
|
BindingDecoration::~BindingDecoration() = default;
|
||||||
|
|
||||||
std::string BindingDecoration::name() const {
|
std::string BindingDecoration::Name() const {
|
||||||
return "binding";
|
return "binding";
|
||||||
}
|
}
|
||||||
|
|
||||||
BindingDecoration* BindingDecoration::Clone(CloneContext* ctx) const {
|
BindingDecoration* BindingDecoration::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<BindingDecoration>(src, value_);
|
return ctx->dst->create<BindingDecoration>(src, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -26,17 +26,14 @@ namespace ast {
|
|||||||
class BindingDecoration : public Castable<BindingDecoration, Decoration> {
|
class BindingDecoration : public Castable<BindingDecoration, Decoration> {
|
||||||
public:
|
public:
|
||||||
/// constructor
|
/// 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 source the source of this decoration
|
/// @param src the source of this node
|
||||||
/// @param value the binding value
|
/// @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;
|
~BindingDecoration() override;
|
||||||
|
|
||||||
/// @returns the binding value
|
|
||||||
uint32_t value() const { return value_; }
|
|
||||||
|
|
||||||
/// @returns the WGSL name for the decoration
|
/// @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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
@ -44,8 +41,8 @@ class BindingDecoration : public Castable<BindingDecoration, Decoration> {
|
|||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
BindingDecoration* Clone(CloneContext* ctx) const override;
|
BindingDecoration* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
private:
|
/// the binding value
|
||||||
uint32_t const value_;
|
uint32_t const value;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -23,7 +23,7 @@ using BindingDecorationTest = TestHelper;
|
|||||||
|
|
||||||
TEST_F(BindingDecorationTest, Creation) {
|
TEST_F(BindingDecorationTest, Creation) {
|
||||||
auto* d = create<BindingDecoration>(2);
|
auto* d = create<BindingDecoration>(2);
|
||||||
EXPECT_EQ(2u, d->value());
|
EXPECT_EQ(2u, d->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -21,13 +21,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BitcastExpression);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
BitcastExpression::BitcastExpression(ProgramID program_id,
|
BitcastExpression::BitcastExpression(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
ast::Type* type,
|
ast::Type* t,
|
||||||
Expression* expr)
|
Expression* e)
|
||||||
: Base(program_id, source), type_(type), expr_(expr) {
|
: Base(pid, src), type(t), expr(e) {
|
||||||
TINT_ASSERT(AST, type_);
|
TINT_ASSERT(AST, type);
|
||||||
TINT_ASSERT(AST, expr_);
|
TINT_ASSERT(AST, expr);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,10 +36,10 @@ BitcastExpression::~BitcastExpression() = default;
|
|||||||
|
|
||||||
BitcastExpression* BitcastExpression::Clone(CloneContext* ctx) const {
|
BitcastExpression* BitcastExpression::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto* ty = ctx->Clone(type());
|
auto* t = ctx->Clone(type);
|
||||||
auto* e = ctx->Clone(expr_);
|
auto* e = ctx->Clone(expr);
|
||||||
return ctx->dst->create<BitcastExpression>(src, ty, e);
|
return ctx->dst->create<BitcastExpression>(src, t, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -39,22 +39,19 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
|
|||||||
BitcastExpression(BitcastExpression&&);
|
BitcastExpression(BitcastExpression&&);
|
||||||
~BitcastExpression() override;
|
~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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
BitcastExpression* Clone(CloneContext* ctx) const override;
|
BitcastExpression* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
|
/// the target cast type
|
||||||
|
ast::Type* const type;
|
||||||
|
/// the expression
|
||||||
|
Expression* const expr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BitcastExpression(const BitcastExpression&) = delete;
|
BitcastExpression(const BitcastExpression&) = delete;
|
||||||
|
|
||||||
ast::Type* const type_;
|
|
||||||
Expression* const expr_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -27,8 +27,8 @@ TEST_F(BitcastExpressionTest, Create) {
|
|||||||
auto* expr = Expr("expr");
|
auto* expr = Expr("expr");
|
||||||
|
|
||||||
auto* exp = create<BitcastExpression>(ty.f32(), expr);
|
auto* exp = create<BitcastExpression>(ty.f32(), expr);
|
||||||
EXPECT_TRUE(exp->type()->Is<ast::F32>());
|
EXPECT_TRUE(exp->type->Is<ast::F32>());
|
||||||
ASSERT_EQ(exp->expr(), expr);
|
ASSERT_EQ(exp->expr, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BitcastExpressionTest, CreateWithSource) {
|
TEST_F(BitcastExpressionTest, CreateWithSource) {
|
||||||
@ -36,7 +36,7 @@ TEST_F(BitcastExpressionTest, CreateWithSource) {
|
|||||||
|
|
||||||
auto* exp = create<BitcastExpression>(Source{Source::Location{20, 2}},
|
auto* exp = create<BitcastExpression>(Source{Source::Location{20, 2}},
|
||||||
ty.f32(), expr);
|
ty.f32(), expr);
|
||||||
auto src = exp->source();
|
auto src = exp->source;
|
||||||
EXPECT_EQ(src.range.begin.line, 20u);
|
EXPECT_EQ(src.range.begin.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BlockStatement);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
BlockStatement::BlockStatement(ProgramID program_id,
|
BlockStatement::BlockStatement(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
const StatementList& statements)
|
const StatementList& stmts)
|
||||||
: Base(program_id, source), statements_(std::move(statements)) {
|
: Base(pid, src), statements(std::move(stmts)) {
|
||||||
for (auto* stmt : *this) {
|
for (auto* stmt : statements) {
|
||||||
TINT_ASSERT(AST, stmt);
|
TINT_ASSERT(AST, stmt);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, stmt, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, stmt, program_id);
|
||||||
}
|
}
|
||||||
@ -37,8 +37,8 @@ BlockStatement::~BlockStatement() = default;
|
|||||||
|
|
||||||
BlockStatement* BlockStatement::Clone(CloneContext* ctx) const {
|
BlockStatement* BlockStatement::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto stmts = ctx->Clone(statements_);
|
auto stmts = ctx->Clone(statements);
|
||||||
return ctx->dst->create<BlockStatement>(src, stmts);
|
return ctx->dst->create<BlockStatement>(src, stmts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,40 +36,13 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
|
|||||||
BlockStatement(BlockStatement&&);
|
BlockStatement(BlockStatement&&);
|
||||||
~BlockStatement() override;
|
~BlockStatement() override;
|
||||||
|
|
||||||
/// @returns the StatementList
|
/// @returns true if the block has no statements
|
||||||
const StatementList& list() const { return statements_; }
|
bool Empty() const { return statements.empty(); }
|
||||||
|
|
||||||
/// @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 the last statement in the block or nullptr if block empty
|
/// @returns the last statement in the block or nullptr if block empty
|
||||||
const Statement* last() const {
|
Statement* Last() const {
|
||||||
return statements_.empty() ? nullptr : statements_.back();
|
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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
@ -77,10 +50,11 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
|
|||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
BlockStatement* Clone(CloneContext* ctx) const override;
|
BlockStatement* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
|
/// the statement list
|
||||||
|
StatementList const statements;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BlockStatement(const BlockStatement&) = delete;
|
BlockStatement(const BlockStatement&) = delete;
|
||||||
|
|
||||||
StatementList const statements_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -29,14 +29,14 @@ TEST_F(BlockStatementTest, Creation) {
|
|||||||
|
|
||||||
auto* b = create<BlockStatement>(StatementList{d});
|
auto* b = create<BlockStatement>(StatementList{d});
|
||||||
|
|
||||||
ASSERT_EQ(b->size(), 1u);
|
ASSERT_EQ(b->statements.size(), 1u);
|
||||||
EXPECT_EQ((*b)[0], ptr);
|
EXPECT_EQ(b->statements[0], ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BlockStatementTest, Creation_WithSource) {
|
TEST_F(BlockStatementTest, Creation_WithSource) {
|
||||||
auto* b = create<BlockStatement>(Source{Source::Location{20, 2}},
|
auto* b = create<BlockStatement>(Source{Source::Location{20, 2}},
|
||||||
ast::StatementList{});
|
ast::StatementList{});
|
||||||
auto src = b->source();
|
auto src = b->source;
|
||||||
EXPECT_EQ(src.range.begin.line, 20u);
|
EXPECT_EQ(src.range.begin.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Bool);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
Bool::Bool(ProgramID program_id, const Source& source)
|
Bool::Bool(ProgramID pid, const Source& src) : Base(pid, src) {}
|
||||||
: Base(program_id, source) {}
|
|
||||||
|
|
||||||
Bool::Bool(Bool&&) = default;
|
Bool::Bool(Bool&&) = default;
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ std::string Bool::FriendlyName(const SymbolTable&) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bool* Bool::Clone(CloneContext* ctx) const {
|
Bool* Bool::Clone(CloneContext* ctx) const {
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<Bool>(src);
|
return ctx->dst->create<Bool>(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,9 +32,9 @@ namespace ast {
|
|||||||
class Bool : public Castable<Bool, Type> {
|
class Bool : public Castable<Bool, Type> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source of this node
|
/// @param src the source of this node
|
||||||
Bool(ProgramID program_id, const Source& source);
|
Bool(ProgramID pid, const Source& src);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
Bool(Bool&&);
|
Bool(Bool&&);
|
||||||
~Bool() override;
|
~Bool() override;
|
||||||
|
@ -21,19 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BoolLiteral);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
BoolLiteral::BoolLiteral(ProgramID program_id, const Source& source, bool value)
|
BoolLiteral::BoolLiteral(ProgramID pid, const Source& src, bool val)
|
||||||
: Base(program_id, source), value_(value) {}
|
: Base(pid, src), value(val) {}
|
||||||
|
|
||||||
BoolLiteral::~BoolLiteral() = default;
|
BoolLiteral::~BoolLiteral() = default;
|
||||||
|
|
||||||
std::string BoolLiteral::name() const {
|
|
||||||
return value_ ? "__bool_true" : "__bool_false";
|
|
||||||
}
|
|
||||||
|
|
||||||
BoolLiteral* BoolLiteral::Clone(CloneContext* ctx) const {
|
BoolLiteral* BoolLiteral::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<BoolLiteral>(src, value_);
|
return ctx->dst->create<BoolLiteral>(src, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -26,19 +26,12 @@ namespace ast {
|
|||||||
class BoolLiteral : public Castable<BoolLiteral, Literal> {
|
class BoolLiteral : public Castable<BoolLiteral, Literal> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the input source
|
/// @param src the source of this node
|
||||||
/// @param value the bool literals value
|
/// @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;
|
~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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
@ -46,8 +39,8 @@ class BoolLiteral : public Castable<BoolLiteral, Literal> {
|
|||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
BoolLiteral* Clone(CloneContext* ctx) const override;
|
BoolLiteral* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
private:
|
/// The boolean literal value
|
||||||
bool const value_;
|
bool const value;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -23,15 +23,13 @@ using BoolLiteralTest = TestHelper;
|
|||||||
TEST_F(BoolLiteralTest, True) {
|
TEST_F(BoolLiteralTest, True) {
|
||||||
auto* b = create<BoolLiteral>(true);
|
auto* b = create<BoolLiteral>(true);
|
||||||
ASSERT_TRUE(b->Is<BoolLiteral>());
|
ASSERT_TRUE(b->Is<BoolLiteral>());
|
||||||
ASSERT_TRUE(b->IsTrue());
|
ASSERT_TRUE(b->value);
|
||||||
ASSERT_FALSE(b->IsFalse());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BoolLiteralTest, False) {
|
TEST_F(BoolLiteralTest, False) {
|
||||||
auto* b = create<BoolLiteral>(false);
|
auto* b = create<BoolLiteral>(false);
|
||||||
ASSERT_TRUE(b->Is<BoolLiteral>());
|
ASSERT_TRUE(b->Is<BoolLiteral>());
|
||||||
ASSERT_FALSE(b->IsTrue());
|
ASSERT_FALSE(b->value);
|
||||||
ASSERT_TRUE(b->IsFalse());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BreakStatement);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
BreakStatement::BreakStatement(ProgramID program_id, const Source& source)
|
BreakStatement::BreakStatement(ProgramID pid, const Source& src)
|
||||||
: Base(program_id, source) {}
|
: Base(pid, src) {}
|
||||||
|
|
||||||
BreakStatement::BreakStatement(BreakStatement&&) = default;
|
BreakStatement::BreakStatement(BreakStatement&&) = default;
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ BreakStatement::~BreakStatement() = default;
|
|||||||
|
|
||||||
BreakStatement* BreakStatement::Clone(CloneContext* ctx) const {
|
BreakStatement* BreakStatement::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<BreakStatement>(src);
|
return ctx->dst->create<BreakStatement>(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ namespace ast {
|
|||||||
class BreakStatement : public Castable<BreakStatement, Statement> {
|
class BreakStatement : public Castable<BreakStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the break statement source
|
/// @param src the source of this node
|
||||||
BreakStatement(ProgramID program_id, const Source& source);
|
BreakStatement(ProgramID pid, const Source& src);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
BreakStatement(BreakStatement&&);
|
BreakStatement(BreakStatement&&);
|
||||||
~BreakStatement() override;
|
~BreakStatement() override;
|
||||||
|
@ -24,7 +24,7 @@ using BreakStatementTest = TestHelper;
|
|||||||
|
|
||||||
TEST_F(BreakStatementTest, Creation_WithSource) {
|
TEST_F(BreakStatementTest, Creation_WithSource) {
|
||||||
auto* stmt = create<BreakStatement>(Source{Source::Location{20, 2}});
|
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.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
@ -23,21 +23,21 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BuiltinDecoration);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
BuiltinDecoration::BuiltinDecoration(ProgramID program_id,
|
BuiltinDecoration::BuiltinDecoration(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
Builtin builtin)
|
Builtin b)
|
||||||
: Base(program_id, source), builtin_(builtin) {}
|
: Base(pid, src), builtin(b) {}
|
||||||
|
|
||||||
BuiltinDecoration::~BuiltinDecoration() = default;
|
BuiltinDecoration::~BuiltinDecoration() = default;
|
||||||
|
|
||||||
std::string BuiltinDecoration::name() const {
|
std::string BuiltinDecoration::Name() const {
|
||||||
return "builtin";
|
return "builtin";
|
||||||
}
|
}
|
||||||
|
|
||||||
BuiltinDecoration* BuiltinDecoration::Clone(CloneContext* ctx) const {
|
BuiltinDecoration* BuiltinDecoration::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<BuiltinDecoration>(src, builtin_);
|
return ctx->dst->create<BuiltinDecoration>(src, builtin);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -27,19 +27,14 @@ namespace ast {
|
|||||||
class BuiltinDecoration : public Castable<BuiltinDecoration, Decoration> {
|
class BuiltinDecoration : public Castable<BuiltinDecoration, Decoration> {
|
||||||
public:
|
public:
|
||||||
/// constructor
|
/// 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 source the source of this decoration
|
/// @param src the source of this node
|
||||||
/// @param builtin the builtin value
|
/// @param builtin the builtin value
|
||||||
BuiltinDecoration(ProgramID program_id,
|
BuiltinDecoration(ProgramID pid, const Source& src, Builtin builtin);
|
||||||
const Source& source,
|
|
||||||
Builtin builtin);
|
|
||||||
~BuiltinDecoration() override;
|
~BuiltinDecoration() override;
|
||||||
|
|
||||||
/// @returns the builtin value
|
|
||||||
Builtin value() const { return builtin_; }
|
|
||||||
|
|
||||||
/// @returns the WGSL name for the decoration
|
/// @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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
@ -47,8 +42,8 @@ class BuiltinDecoration : public Castable<BuiltinDecoration, Decoration> {
|
|||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
BuiltinDecoration* Clone(CloneContext* ctx) const override;
|
BuiltinDecoration* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
private:
|
/// The builtin value
|
||||||
Builtin const builtin_;
|
Builtin const builtin;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -23,7 +23,7 @@ using BuiltinDecorationTest = TestHelper;
|
|||||||
|
|
||||||
TEST_F(BuiltinDecorationTest, Creation) {
|
TEST_F(BuiltinDecorationTest, Creation) {
|
||||||
auto* d = create<BuiltinDecoration>(Builtin::kFragDepth);
|
auto* d = create<BuiltinDecoration>(Builtin::kFragDepth);
|
||||||
EXPECT_EQ(Builtin::kFragDepth, d->value());
|
EXPECT_EQ(Builtin::kFragDepth, d->builtin);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -21,14 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CallExpression);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
CallExpression::CallExpression(ProgramID program_id,
|
CallExpression::CallExpression(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
IdentifierExpression* func,
|
IdentifierExpression* fn,
|
||||||
ExpressionList args)
|
ExpressionList a)
|
||||||
: Base(program_id, source), func_(func), args_(args) {
|
: Base(pid, src), func(fn), args(a) {
|
||||||
TINT_ASSERT(AST, func_);
|
TINT_ASSERT(AST, func);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id);
|
||||||
for (auto* arg : args_) {
|
for (auto* arg : args) {
|
||||||
TINT_ASSERT(AST, arg);
|
TINT_ASSERT(AST, arg);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, arg, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, arg, program_id);
|
||||||
}
|
}
|
||||||
@ -40,9 +40,9 @@ CallExpression::~CallExpression() = default;
|
|||||||
|
|
||||||
CallExpression* CallExpression::Clone(CloneContext* ctx) const {
|
CallExpression* CallExpression::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto* fn = ctx->Clone(func_);
|
auto* fn = ctx->Clone(func);
|
||||||
auto p = ctx->Clone(args_);
|
auto p = ctx->Clone(args);
|
||||||
return ctx->dst->create<CallExpression>(src, fn, p);
|
return ctx->dst->create<CallExpression>(src, fn, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,22 +39,19 @@ class CallExpression : public Castable<CallExpression, Expression> {
|
|||||||
CallExpression(CallExpression&&);
|
CallExpression(CallExpression&&);
|
||||||
~CallExpression() override;
|
~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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
CallExpression* Clone(CloneContext* ctx) const override;
|
CallExpression* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
|
/// The target function
|
||||||
|
IdentifierExpression* const func;
|
||||||
|
/// The arguments
|
||||||
|
ExpressionList const args;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CallExpression(const CallExpression&) = delete;
|
CallExpression(const CallExpression&) = delete;
|
||||||
|
|
||||||
IdentifierExpression* const func_;
|
|
||||||
ExpressionList const args_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -28,9 +28,9 @@ TEST_F(CallExpressionTest, Creation) {
|
|||||||
params.push_back(Expr("param2"));
|
params.push_back(Expr("param2"));
|
||||||
|
|
||||||
auto* stmt = create<CallExpression>(func, params);
|
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);
|
ASSERT_EQ(vec.size(), 2u);
|
||||||
EXPECT_EQ(vec[0], params[0]);
|
EXPECT_EQ(vec[0], params[0]);
|
||||||
EXPECT_EQ(vec[1], params[1]);
|
EXPECT_EQ(vec[1], params[1]);
|
||||||
@ -40,7 +40,7 @@ TEST_F(CallExpressionTest, Creation_WithSource) {
|
|||||||
auto* func = Expr("func");
|
auto* func = Expr("func");
|
||||||
auto* stmt = create<CallExpression>(Source{Source::Location{20, 2}}, func,
|
auto* stmt = create<CallExpression>(Source{Source::Location{20, 2}}, func,
|
||||||
ExpressionList{});
|
ExpressionList{});
|
||||||
auto src = stmt->source();
|
auto src = stmt->source;
|
||||||
EXPECT_EQ(src.range.begin.line, 20u);
|
EXPECT_EQ(src.range.begin.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CallStatement);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
CallStatement::CallStatement(ProgramID program_id,
|
CallStatement::CallStatement(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
CallExpression* call)
|
CallExpression* call)
|
||||||
: Base(program_id, source), call_(call) {
|
: Base(pid, src), expr(call) {
|
||||||
TINT_ASSERT(AST, call_);
|
TINT_ASSERT(AST, expr);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, call_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
CallStatement::CallStatement(CallStatement&&) = default;
|
CallStatement::CallStatement(CallStatement&&) = default;
|
||||||
@ -35,8 +35,8 @@ CallStatement::~CallStatement() = default;
|
|||||||
|
|
||||||
CallStatement* CallStatement::Clone(CloneContext* ctx) const {
|
CallStatement* CallStatement::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto* call = ctx->Clone(call_);
|
auto* call = ctx->Clone(expr);
|
||||||
return ctx->dst->create<CallStatement>(src, call);
|
return ctx->dst->create<CallStatement>(src, call);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,29 +25,25 @@ namespace ast {
|
|||||||
class CallStatement : public Castable<CallStatement, Statement> {
|
class CallStatement : public Castable<CallStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the input source for the statement
|
/// @param src the source of this node for the statement
|
||||||
/// @param call the function
|
/// @param call the function
|
||||||
CallStatement(ProgramID program_id,
|
CallStatement(ProgramID pid, const Source& src, CallExpression* call);
|
||||||
const Source& source,
|
|
||||||
CallExpression* call);
|
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
CallStatement(CallStatement&&);
|
CallStatement(CallStatement&&);
|
||||||
~CallStatement() override;
|
~CallStatement() override;
|
||||||
|
|
||||||
/// @returns the call expression
|
|
||||||
CallExpression* expr() const { return call_; }
|
|
||||||
|
|
||||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
CallStatement* Clone(CloneContext* ctx) const override;
|
CallStatement* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
|
/// The call expression
|
||||||
|
CallExpression* const expr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CallStatement(const CallStatement&) = delete;
|
CallStatement(const CallStatement&) = delete;
|
||||||
|
|
||||||
CallExpression* const call_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -27,7 +27,7 @@ TEST_F(CallStatementTest, Creation) {
|
|||||||
auto* expr = create<CallExpression>(Expr("func"), ExpressionList{});
|
auto* expr = create<CallExpression>(Expr("func"), ExpressionList{});
|
||||||
|
|
||||||
auto* c = create<CallStatement>(expr);
|
auto* c = create<CallStatement>(expr);
|
||||||
EXPECT_EQ(c->expr(), expr);
|
EXPECT_EQ(c->expr, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CallStatementTest, IsCall) {
|
TEST_F(CallStatementTest, IsCall) {
|
||||||
|
@ -21,13 +21,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CaseStatement);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
CaseStatement::CaseStatement(ProgramID program_id,
|
CaseStatement::CaseStatement(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
CaseSelectorList selectors,
|
CaseSelectorList s,
|
||||||
BlockStatement* body)
|
BlockStatement* b)
|
||||||
: Base(program_id, source), selectors_(selectors), body_(body) {
|
: Base(pid, src), selectors(s), body(b) {
|
||||||
TINT_ASSERT(AST, body_);
|
TINT_ASSERT(AST, body);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
|
||||||
for (auto* selector : selectors) {
|
for (auto* selector : selectors) {
|
||||||
TINT_ASSERT(AST, selector);
|
TINT_ASSERT(AST, selector);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, selector, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, selector, program_id);
|
||||||
@ -40,9 +40,9 @@ CaseStatement::~CaseStatement() = default;
|
|||||||
|
|
||||||
CaseStatement* CaseStatement::Clone(CloneContext* ctx) const {
|
CaseStatement* CaseStatement::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto sel = ctx->Clone(selectors_);
|
auto sel = ctx->Clone(selectors);
|
||||||
auto* b = ctx->Clone(body_);
|
auto* b = ctx->Clone(body);
|
||||||
return ctx->dst->create<CaseStatement>(src, sel, b);
|
return ctx->dst->create<CaseStatement>(src, sel, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,27 +30,20 @@ using CaseSelectorList = std::vector<IntLiteral*>;
|
|||||||
class CaseStatement : public Castable<CaseStatement, Statement> {
|
class CaseStatement : public Castable<CaseStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source information
|
/// @param src the source of this node
|
||||||
/// @param selectors the case selectors
|
/// @param selectors the case selectors
|
||||||
/// @param body the case body
|
/// @param body the case body
|
||||||
CaseStatement(ProgramID program_id,
|
CaseStatement(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
CaseSelectorList selectors,
|
CaseSelectorList selectors,
|
||||||
BlockStatement* body);
|
BlockStatement* body);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
CaseStatement(CaseStatement&&);
|
CaseStatement(CaseStatement&&);
|
||||||
~CaseStatement() override;
|
~CaseStatement() override;
|
||||||
|
|
||||||
/// @returns the case selectors, empty if none set
|
|
||||||
const CaseSelectorList& selectors() const { return selectors_; }
|
|
||||||
/// @returns true if this is a default statement
|
/// @returns true if this is a default statement
|
||||||
bool IsDefault() const { return selectors_.empty(); }
|
bool IsDefault() const { return selectors.empty(); }
|
||||||
|
|
||||||
/// @returns the case body
|
|
||||||
const BlockStatement* body() const { return body_; }
|
|
||||||
/// @returns the case body
|
|
||||||
BlockStatement* body() { return body_; }
|
|
||||||
|
|
||||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
@ -58,11 +51,14 @@ class CaseStatement : public Castable<CaseStatement, Statement> {
|
|||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
CaseStatement* Clone(CloneContext* ctx) const override;
|
CaseStatement* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
|
/// The case selectors, empty if none set
|
||||||
|
CaseSelectorList const selectors;
|
||||||
|
|
||||||
|
/// The case body
|
||||||
|
BlockStatement* const body;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CaseStatement(const CaseStatement&) = delete;
|
CaseStatement(const CaseStatement&) = delete;
|
||||||
|
|
||||||
CaseSelectorList const selectors_;
|
|
||||||
BlockStatement* const body_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A list of case statements
|
/// A list of case statements
|
||||||
|
@ -34,10 +34,10 @@ TEST_F(CaseStatementTest, Creation_i32) {
|
|||||||
auto* body = create<BlockStatement>(StatementList{discard});
|
auto* body = create<BlockStatement>(StatementList{discard});
|
||||||
|
|
||||||
auto* c = create<CaseStatement>(b, body);
|
auto* c = create<CaseStatement>(b, body);
|
||||||
ASSERT_EQ(c->selectors().size(), 1u);
|
ASSERT_EQ(c->selectors.size(), 1u);
|
||||||
EXPECT_EQ(c->selectors()[0], selector);
|
EXPECT_EQ(c->selectors[0], selector);
|
||||||
ASSERT_EQ(c->body()->size(), 1u);
|
ASSERT_EQ(c->body->statements.size(), 1u);
|
||||||
EXPECT_EQ(c->body()->get(0), discard);
|
EXPECT_EQ(c->body->statements[0], discard);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CaseStatementTest, Creation_u32) {
|
TEST_F(CaseStatementTest, Creation_u32) {
|
||||||
@ -49,10 +49,10 @@ TEST_F(CaseStatementTest, Creation_u32) {
|
|||||||
auto* body = create<BlockStatement>(StatementList{discard});
|
auto* body = create<BlockStatement>(StatementList{discard});
|
||||||
|
|
||||||
auto* c = create<CaseStatement>(b, body);
|
auto* c = create<CaseStatement>(b, body);
|
||||||
ASSERT_EQ(c->selectors().size(), 1u);
|
ASSERT_EQ(c->selectors.size(), 1u);
|
||||||
EXPECT_EQ(c->selectors()[0], selector);
|
EXPECT_EQ(c->selectors[0], selector);
|
||||||
ASSERT_EQ(c->body()->size(), 1u);
|
ASSERT_EQ(c->body->statements.size(), 1u);
|
||||||
EXPECT_EQ(c->body()->get(0), discard);
|
EXPECT_EQ(c->body->statements[0], discard);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CaseStatementTest, Creation_WithSource) {
|
TEST_F(CaseStatementTest, Creation_WithSource) {
|
||||||
@ -63,7 +63,7 @@ TEST_F(CaseStatementTest, Creation_WithSource) {
|
|||||||
create<DiscardStatement>(),
|
create<DiscardStatement>(),
|
||||||
});
|
});
|
||||||
auto* c = create<CaseStatement>(Source{Source::Location{20, 2}}, b, body);
|
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.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,8 @@ ConstructorExpression::~ConstructorExpression() = default;
|
|||||||
|
|
||||||
ConstructorExpression::ConstructorExpression(ConstructorExpression&&) = default;
|
ConstructorExpression::ConstructorExpression(ConstructorExpression&&) = default;
|
||||||
|
|
||||||
ConstructorExpression::ConstructorExpression(ProgramID program_id,
|
ConstructorExpression::ConstructorExpression(ProgramID pid, const Source& src)
|
||||||
const Source& source)
|
: Base(pid, src) {}
|
||||||
: Base(program_id, source) {}
|
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
@ -28,9 +28,9 @@ class ConstructorExpression
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Constructor
|
/// 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 source the constructor source
|
/// @param src the source of this node
|
||||||
ConstructorExpression(ProgramID program_id, const Source& source);
|
ConstructorExpression(ProgramID pid, const Source& src);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
ConstructorExpression(ConstructorExpression&&);
|
ConstructorExpression(ConstructorExpression&&);
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ContinueStatement);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
ContinueStatement::ContinueStatement(ProgramID program_id, const Source& source)
|
ContinueStatement::ContinueStatement(ProgramID pid, const Source& src)
|
||||||
: Base(program_id, source) {}
|
: Base(pid, src) {}
|
||||||
|
|
||||||
ContinueStatement::ContinueStatement(ContinueStatement&&) = default;
|
ContinueStatement::ContinueStatement(ContinueStatement&&) = default;
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ ContinueStatement::~ContinueStatement() = default;
|
|||||||
|
|
||||||
ContinueStatement* ContinueStatement::Clone(CloneContext* ctx) const {
|
ContinueStatement* ContinueStatement::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<ContinueStatement>(src);
|
return ctx->dst->create<ContinueStatement>(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ namespace ast {
|
|||||||
class ContinueStatement : public Castable<ContinueStatement, Statement> {
|
class ContinueStatement : public Castable<ContinueStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the continue statement source
|
/// @param src the source of this node
|
||||||
ContinueStatement(ProgramID program_id, const Source& source);
|
ContinueStatement(ProgramID pid, const Source& src);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
ContinueStatement(ContinueStatement&&);
|
ContinueStatement(ContinueStatement&&);
|
||||||
~ContinueStatement() override;
|
~ContinueStatement() override;
|
||||||
|
@ -24,7 +24,7 @@ using ContinueStatementTest = TestHelper;
|
|||||||
|
|
||||||
TEST_F(ContinueStatementTest, Creation_WithSource) {
|
TEST_F(ContinueStatementTest, Creation_WithSource) {
|
||||||
auto* stmt = create<ContinueStatement>(Source{Source::Location{20, 2}});
|
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.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
@ -29,14 +29,13 @@ class Decoration : public Castable<Decoration, Node> {
|
|||||||
~Decoration() override;
|
~Decoration() override;
|
||||||
|
|
||||||
/// @returns the WGSL name for the decoration
|
/// @returns the WGSL name for the decoration
|
||||||
virtual std::string name() const = 0;
|
virtual std::string Name() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Constructor
|
/// 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 source the source of this decoration
|
/// @param src the source of this node
|
||||||
Decoration(ProgramID program_id, const Source& source)
|
Decoration(ProgramID pid, const Source& src) : Base(pid, src) {}
|
||||||
: Base(program_id, source) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A list of decorations
|
/// A list of decorations
|
||||||
|
@ -28,10 +28,10 @@ bool IsValidDepthDimension(TextureDimension dim) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
DepthMultisampledTexture::DepthMultisampledTexture(ProgramID program_id,
|
DepthMultisampledTexture::DepthMultisampledTexture(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
TextureDimension dim)
|
TextureDimension d)
|
||||||
: Base(program_id, source, dim) {
|
: Base(pid, src, d) {
|
||||||
TINT_ASSERT(AST, IsValidDepthDimension(dim));
|
TINT_ASSERT(AST, IsValidDepthDimension(dim));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,14 +42,14 @@ DepthMultisampledTexture::~DepthMultisampledTexture() = default;
|
|||||||
|
|
||||||
std::string DepthMultisampledTexture::FriendlyName(const SymbolTable&) const {
|
std::string DepthMultisampledTexture::FriendlyName(const SymbolTable&) const {
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "texture_depth_multisampled_" << dim();
|
out << "texture_depth_multisampled_" << dim;
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
DepthMultisampledTexture* DepthMultisampledTexture::Clone(
|
DepthMultisampledTexture* DepthMultisampledTexture::Clone(
|
||||||
CloneContext* ctx) const {
|
CloneContext* ctx) const {
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<DepthMultisampledTexture>(src, dim());
|
return ctx->dst->create<DepthMultisampledTexture>(src, dim);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -27,11 +27,11 @@ class DepthMultisampledTexture
|
|||||||
: public Castable<DepthMultisampledTexture, Texture> {
|
: public Castable<DepthMultisampledTexture, Texture> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source of this node
|
/// @param src the source of this node
|
||||||
/// @param dim the dimensionality of the texture
|
/// @param dim the dimensionality of the texture
|
||||||
DepthMultisampledTexture(ProgramID program_id,
|
DepthMultisampledTexture(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
TextureDimension dim);
|
TextureDimension dim);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
DepthMultisampledTexture(DepthMultisampledTexture&&);
|
DepthMultisampledTexture(DepthMultisampledTexture&&);
|
||||||
|
@ -24,7 +24,7 @@ using AstDepthMultisampledTextureTest = TestHelper;
|
|||||||
|
|
||||||
TEST_F(AstDepthMultisampledTextureTest, Dim) {
|
TEST_F(AstDepthMultisampledTextureTest, Dim) {
|
||||||
auto* d = create<DepthMultisampledTexture>(TextureDimension::k2d);
|
auto* d = create<DepthMultisampledTexture>(TextureDimension::k2d);
|
||||||
EXPECT_EQ(d->dim(), TextureDimension::k2d);
|
EXPECT_EQ(d->dim, TextureDimension::k2d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AstDepthMultisampledTextureTest, FriendlyName) {
|
TEST_F(AstDepthMultisampledTextureTest, FriendlyName) {
|
||||||
|
@ -29,10 +29,8 @@ bool IsValidDepthDimension(TextureDimension dim) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
DepthTexture::DepthTexture(ProgramID program_id,
|
DepthTexture::DepthTexture(ProgramID pid, const Source& src, TextureDimension d)
|
||||||
const Source& source,
|
: Base(pid, src, d) {
|
||||||
TextureDimension dim)
|
|
||||||
: Base(program_id, source, dim) {
|
|
||||||
TINT_ASSERT(AST, IsValidDepthDimension(dim));
|
TINT_ASSERT(AST, IsValidDepthDimension(dim));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,13 +40,13 @@ DepthTexture::~DepthTexture() = default;
|
|||||||
|
|
||||||
std::string DepthTexture::FriendlyName(const SymbolTable&) const {
|
std::string DepthTexture::FriendlyName(const SymbolTable&) const {
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "texture_depth_" << dim();
|
out << "texture_depth_" << dim;
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
DepthTexture* DepthTexture::Clone(CloneContext* ctx) const {
|
DepthTexture* DepthTexture::Clone(CloneContext* ctx) const {
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<DepthTexture>(src, dim());
|
return ctx->dst->create<DepthTexture>(src, dim);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -26,12 +26,10 @@ namespace ast {
|
|||||||
class DepthTexture : public Castable<DepthTexture, Texture> {
|
class DepthTexture : public Castable<DepthTexture, Texture> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source of this node
|
/// @param src the source of this node
|
||||||
/// @param dim the dimensionality of the texture
|
/// @param dim the dimensionality of the texture
|
||||||
DepthTexture(ProgramID program_id,
|
DepthTexture(ProgramID pid, const Source& src, TextureDimension dim);
|
||||||
const Source& source,
|
|
||||||
TextureDimension dim);
|
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
DepthTexture(DepthTexture&&);
|
DepthTexture(DepthTexture&&);
|
||||||
~DepthTexture() override;
|
~DepthTexture() override;
|
||||||
|
@ -31,7 +31,7 @@ TEST_F(AstDepthTextureTest, IsTexture) {
|
|||||||
|
|
||||||
TEST_F(AstDepthTextureTest, Dim) {
|
TEST_F(AstDepthTextureTest, Dim) {
|
||||||
auto* d = create<DepthTexture>(TextureDimension::kCube);
|
auto* d = create<DepthTexture>(TextureDimension::kCube);
|
||||||
EXPECT_EQ(d->dim(), TextureDimension::kCube);
|
EXPECT_EQ(d->dim, TextureDimension::kCube);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AstDepthTextureTest, FriendlyName) {
|
TEST_F(AstDepthTextureTest, FriendlyName) {
|
||||||
|
@ -21,15 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::DisableValidationDecoration);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
DisableValidationDecoration::DisableValidationDecoration(
|
DisableValidationDecoration::DisableValidationDecoration(ProgramID pid,
|
||||||
ProgramID program_id,
|
DisabledValidation val)
|
||||||
DisabledValidation validation)
|
: Base(pid), validation(val) {}
|
||||||
: Base(program_id), validation_(validation) {}
|
|
||||||
|
|
||||||
DisableValidationDecoration::~DisableValidationDecoration() = default;
|
DisableValidationDecoration::~DisableValidationDecoration() = default;
|
||||||
|
|
||||||
std::string DisableValidationDecoration::InternalName() const {
|
std::string DisableValidationDecoration::InternalName() const {
|
||||||
switch (validation_) {
|
switch (validation) {
|
||||||
case DisabledValidation::kFunctionHasNoBody:
|
case DisabledValidation::kFunctionHasNoBody:
|
||||||
return "disable_validation__function_has_no_body";
|
return "disable_validation__function_has_no_body";
|
||||||
case DisabledValidation::kBindingPointCollision:
|
case DisabledValidation::kBindingPointCollision:
|
||||||
@ -51,7 +50,7 @@ std::string DisableValidationDecoration::InternalName() const {
|
|||||||
DisableValidationDecoration* DisableValidationDecoration::Clone(
|
DisableValidationDecoration* DisableValidationDecoration::Clone(
|
||||||
CloneContext* ctx) const {
|
CloneContext* ctx) const {
|
||||||
return ctx->dst->ASTNodes().Create<DisableValidationDecoration>(
|
return ctx->dst->ASTNodes().Create<DisableValidationDecoration>(
|
||||||
ctx->dst->ID(), validation_);
|
ctx->dst->ID(), validation);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -64,9 +64,6 @@ class DisableValidationDecoration
|
|||||||
/// Destructor
|
/// Destructor
|
||||||
~DisableValidationDecoration() override;
|
~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
|
/// @return a short description of the internal decoration which will be
|
||||||
/// displayed in WGSL as `[[internal(<name>)]]` (but is not parsable).
|
/// displayed in WGSL as `[[internal(<name>)]]` (but is not parsable).
|
||||||
std::string InternalName() const override;
|
std::string InternalName() const override;
|
||||||
@ -76,8 +73,8 @@ class DisableValidationDecoration
|
|||||||
/// @return the newly cloned object
|
/// @return the newly cloned object
|
||||||
DisableValidationDecoration* Clone(CloneContext* ctx) const override;
|
DisableValidationDecoration* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
private:
|
/// The validation that this decoration disables
|
||||||
DisabledValidation const validation_;
|
DisabledValidation const validation;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::DiscardStatement);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
DiscardStatement::DiscardStatement(ProgramID program_id, const Source& source)
|
DiscardStatement::DiscardStatement(ProgramID pid, const Source& src)
|
||||||
: Base(program_id, source) {}
|
: Base(pid, src) {}
|
||||||
|
|
||||||
DiscardStatement::DiscardStatement(DiscardStatement&&) = default;
|
DiscardStatement::DiscardStatement(DiscardStatement&&) = default;
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ DiscardStatement::~DiscardStatement() = default;
|
|||||||
|
|
||||||
DiscardStatement* DiscardStatement::Clone(CloneContext* ctx) const {
|
DiscardStatement* DiscardStatement::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<DiscardStatement>(src);
|
return ctx->dst->create<DiscardStatement>(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ namespace ast {
|
|||||||
class DiscardStatement : public Castable<DiscardStatement, Statement> {
|
class DiscardStatement : public Castable<DiscardStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the discard statement source
|
/// @param src the source of this node
|
||||||
DiscardStatement(ProgramID program_id, const Source& source);
|
DiscardStatement(ProgramID pid, const Source& src);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
DiscardStatement(DiscardStatement&&);
|
DiscardStatement(DiscardStatement&&);
|
||||||
~DiscardStatement() override;
|
~DiscardStatement() override;
|
||||||
|
@ -24,19 +24,19 @@ using DiscardStatementTest = TestHelper;
|
|||||||
|
|
||||||
TEST_F(DiscardStatementTest, Creation) {
|
TEST_F(DiscardStatementTest, Creation) {
|
||||||
auto* stmt = create<DiscardStatement>();
|
auto* stmt = create<DiscardStatement>();
|
||||||
EXPECT_EQ(stmt->source().range.begin.line, 0u);
|
EXPECT_EQ(stmt->source.range.begin.line, 0u);
|
||||||
EXPECT_EQ(stmt->source().range.begin.column, 0u);
|
EXPECT_EQ(stmt->source.range.begin.column, 0u);
|
||||||
EXPECT_EQ(stmt->source().range.end.line, 0u);
|
EXPECT_EQ(stmt->source.range.end.line, 0u);
|
||||||
EXPECT_EQ(stmt->source().range.end.column, 0u);
|
EXPECT_EQ(stmt->source.range.end.column, 0u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DiscardStatementTest, Creation_WithSource) {
|
TEST_F(DiscardStatementTest, Creation_WithSource) {
|
||||||
auto* stmt = create<DiscardStatement>(
|
auto* stmt = create<DiscardStatement>(
|
||||||
Source{Source::Range{Source::Location{20, 2}, Source::Location{20, 5}}});
|
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.line, 20u);
|
||||||
EXPECT_EQ(stmt->source().range.begin.column, 2u);
|
EXPECT_EQ(stmt->source.range.begin.column, 2u);
|
||||||
EXPECT_EQ(stmt->source().range.end.line, 20u);
|
EXPECT_EQ(stmt->source.range.end.line, 20u);
|
||||||
EXPECT_EQ(stmt->source().range.end.column, 5u);
|
EXPECT_EQ(stmt->source.range.end.column, 5u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DiscardStatementTest, IsDiscard) {
|
TEST_F(DiscardStatementTest, IsDiscard) {
|
||||||
|
@ -21,14 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ElseStatement);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
ElseStatement::ElseStatement(ProgramID program_id,
|
ElseStatement::ElseStatement(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
Expression* condition,
|
Expression* cond,
|
||||||
BlockStatement* body)
|
BlockStatement* b)
|
||||||
: Base(program_id, source), condition_(condition), body_(body) {
|
: Base(pid, src), condition(cond), body(b) {
|
||||||
TINT_ASSERT(AST, body_);
|
TINT_ASSERT(AST, body);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ElseStatement::ElseStatement(ElseStatement&&) = default;
|
ElseStatement::ElseStatement(ElseStatement&&) = default;
|
||||||
@ -37,9 +37,9 @@ ElseStatement::~ElseStatement() = default;
|
|||||||
|
|
||||||
ElseStatement* ElseStatement::Clone(CloneContext* ctx) const {
|
ElseStatement* ElseStatement::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto* cond = ctx->Clone(condition_);
|
auto* cond = ctx->Clone(condition);
|
||||||
auto* b = ctx->Clone(body_);
|
auto* b = ctx->Clone(body);
|
||||||
return ctx->dst->create<ElseStatement>(src, cond, b);
|
return ctx->dst->create<ElseStatement>(src, cond, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,39 +27,32 @@ namespace ast {
|
|||||||
class ElseStatement : public Castable<ElseStatement, Statement> {
|
class ElseStatement : public Castable<ElseStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source information
|
/// @param src the source of this node
|
||||||
/// @param condition the else condition
|
/// @param condition the else condition
|
||||||
/// @param body the else body
|
/// @param body the else body
|
||||||
ElseStatement(ProgramID program_id,
|
ElseStatement(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
Expression* condition,
|
Expression* condition,
|
||||||
BlockStatement* body);
|
BlockStatement* body);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
ElseStatement(ElseStatement&&);
|
ElseStatement(ElseStatement&&);
|
||||||
~ElseStatement() override;
|
~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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
ElseStatement* Clone(CloneContext* ctx) const override;
|
ElseStatement* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
|
/// The else condition or nullptr if none set
|
||||||
|
Expression* const condition;
|
||||||
|
|
||||||
|
/// The else body
|
||||||
|
BlockStatement* const body;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ElseStatement(const ElseStatement&) = delete;
|
ElseStatement(const ElseStatement&) = delete;
|
||||||
|
|
||||||
Expression* const condition_;
|
|
||||||
BlockStatement* const body_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A list of else statements
|
/// A list of else statements
|
||||||
|
@ -28,18 +28,18 @@ TEST_F(ElseStatementTest, Creation) {
|
|||||||
auto* body = create<BlockStatement>(StatementList{
|
auto* body = create<BlockStatement>(StatementList{
|
||||||
create<DiscardStatement>(),
|
create<DiscardStatement>(),
|
||||||
});
|
});
|
||||||
auto* discard = body->get(0);
|
auto* discard = body->statements[0];
|
||||||
|
|
||||||
auto* e = create<ElseStatement>(cond, body);
|
auto* e = create<ElseStatement>(cond, body);
|
||||||
EXPECT_EQ(e->condition(), cond);
|
EXPECT_EQ(e->condition, cond);
|
||||||
ASSERT_EQ(e->body()->size(), 1u);
|
ASSERT_EQ(e->body->statements.size(), 1u);
|
||||||
EXPECT_EQ(e->body()->get(0), discard);
|
EXPECT_EQ(e->body->statements[0], discard);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, Creation_WithSource) {
|
TEST_F(ElseStatementTest, Creation_WithSource) {
|
||||||
auto* e = create<ElseStatement>(Source{Source::Location{20, 2}}, Expr(true),
|
auto* e = create<ElseStatement>(Source{Source::Location{20, 2}}, Expr(true),
|
||||||
Block());
|
Block());
|
||||||
auto src = e->source();
|
auto src = e->source;
|
||||||
EXPECT_EQ(src.range.begin.line, 20u);
|
EXPECT_EQ(src.range.begin.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
@ -52,12 +52,12 @@ TEST_F(ElseStatementTest, IsElse) {
|
|||||||
TEST_F(ElseStatementTest, HasCondition) {
|
TEST_F(ElseStatementTest, HasCondition) {
|
||||||
auto* cond = Expr(true);
|
auto* cond = Expr(true);
|
||||||
auto* e = create<ElseStatement>(cond, Block());
|
auto* e = create<ElseStatement>(cond, Block());
|
||||||
EXPECT_TRUE(e->HasCondition());
|
EXPECT_TRUE(e->condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, HasContition_NullCondition) {
|
TEST_F(ElseStatementTest, HasContition_NullCondition) {
|
||||||
auto* e = create<ElseStatement>(nullptr, Block());
|
auto* e = create<ElseStatement>(nullptr, Block());
|
||||||
EXPECT_FALSE(e->HasCondition());
|
EXPECT_FALSE(e->condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, Assert_Null_Body) {
|
TEST_F(ElseStatementTest, Assert_Null_Body) {
|
||||||
|
@ -22,17 +22,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Expression);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
Expression::Expression(ProgramID program_id, const Source& source)
|
Expression::Expression(ProgramID pid, const Source& src) : Base(pid, src) {}
|
||||||
: Base(program_id, source) {}
|
|
||||||
|
|
||||||
Expression::Expression(Expression&&) = default;
|
Expression::Expression(Expression&&) = default;
|
||||||
|
|
||||||
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 ast
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
@ -31,17 +31,12 @@ class Expression : public Castable<Expression, Node> {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Constructor
|
/// 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 source the source of the expression
|
/// @param src the source of this node
|
||||||
Expression(ProgramID program_id, const Source& source);
|
Expression(ProgramID pid, const Source& src);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
Expression(Expression&&);
|
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:
|
private:
|
||||||
Expression(const Expression&) = delete;
|
Expression(const Expression&) = delete;
|
||||||
};
|
};
|
||||||
|
@ -22,8 +22,8 @@ namespace tint {
|
|||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
// ExternalTexture::ExternalTexture() : Base(ast::TextureDimension::k2d) {}
|
// ExternalTexture::ExternalTexture() : Base(ast::TextureDimension::k2d) {}
|
||||||
ExternalTexture::ExternalTexture(ProgramID program_id, const Source& source)
|
ExternalTexture::ExternalTexture(ProgramID pid, const Source& src)
|
||||||
: Base(program_id, source, ast::TextureDimension::k2d) {}
|
: Base(pid, src, ast::TextureDimension::k2d) {}
|
||||||
|
|
||||||
ExternalTexture::ExternalTexture(ExternalTexture&&) = default;
|
ExternalTexture::ExternalTexture(ExternalTexture&&) = default;
|
||||||
|
|
||||||
|
@ -26,9 +26,9 @@ namespace ast {
|
|||||||
class ExternalTexture : public Castable<ExternalTexture, Texture> {
|
class ExternalTexture : public Castable<ExternalTexture, Texture> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source of this node
|
/// @param src the source of this node
|
||||||
ExternalTexture(ProgramID program_id, const Source& source);
|
ExternalTexture(ProgramID pid, const Source& src);
|
||||||
|
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
ExternalTexture(ExternalTexture&&);
|
ExternalTexture(ExternalTexture&&);
|
||||||
|
@ -33,7 +33,7 @@ TEST_F(AstExternalTextureTest, IsTexture) {
|
|||||||
|
|
||||||
TEST_F(AstExternalTextureTest, Dim) {
|
TEST_F(AstExternalTextureTest, Dim) {
|
||||||
auto* ty = create<ExternalTexture>();
|
auto* ty = create<ExternalTexture>();
|
||||||
EXPECT_EQ(ty->dim(), ast::TextureDimension::k2d);
|
EXPECT_EQ(ty->dim, ast::TextureDimension::k2d);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AstExternalTextureTest, FriendlyName) {
|
TEST_F(AstExternalTextureTest, FriendlyName) {
|
||||||
|
@ -21,8 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::F32);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
F32::F32(ProgramID program_id, const Source& source)
|
F32::F32(ProgramID pid, const Source& src) : Base(pid, src) {}
|
||||||
: Base(program_id, source) {}
|
|
||||||
|
|
||||||
F32::F32(F32&&) = default;
|
F32::F32(F32&&) = default;
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ std::string F32::FriendlyName(const SymbolTable&) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
F32* F32::Clone(CloneContext* ctx) const {
|
F32* F32::Clone(CloneContext* ctx) const {
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<F32>(src);
|
return ctx->dst->create<F32>(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,9 +26,9 @@ namespace ast {
|
|||||||
class F32 : public Castable<F32, Type> {
|
class F32 : public Castable<F32, Type> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source of this node
|
/// @param src the source of this node
|
||||||
F32(ProgramID program_id, const Source& source);
|
F32(ProgramID pid, const Source& src);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
F32(F32&&);
|
F32(F32&&);
|
||||||
~F32() override;
|
~F32() override;
|
||||||
|
@ -21,9 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::FallthroughStatement);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
FallthroughStatement::FallthroughStatement(ProgramID program_id,
|
FallthroughStatement::FallthroughStatement(ProgramID pid, const Source& src)
|
||||||
const Source& source)
|
: Base(pid, src) {}
|
||||||
: Base(program_id, source) {}
|
|
||||||
|
|
||||||
FallthroughStatement::FallthroughStatement(FallthroughStatement&&) = default;
|
FallthroughStatement::FallthroughStatement(FallthroughStatement&&) = default;
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ FallthroughStatement::~FallthroughStatement() = default;
|
|||||||
|
|
||||||
FallthroughStatement* FallthroughStatement::Clone(CloneContext* ctx) const {
|
FallthroughStatement* FallthroughStatement::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<FallthroughStatement>(src);
|
return ctx->dst->create<FallthroughStatement>(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ namespace ast {
|
|||||||
class FallthroughStatement : public Castable<FallthroughStatement, Statement> {
|
class FallthroughStatement : public Castable<FallthroughStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source information
|
/// @param src the source of this node
|
||||||
FallthroughStatement(ProgramID program_id, const Source& source);
|
FallthroughStatement(ProgramID pid, const Source& src);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
FallthroughStatement(FallthroughStatement&&);
|
FallthroughStatement(FallthroughStatement&&);
|
||||||
~FallthroughStatement() override;
|
~FallthroughStatement() override;
|
||||||
|
@ -24,15 +24,15 @@ using FallthroughStatementTest = TestHelper;
|
|||||||
|
|
||||||
TEST_F(FallthroughStatementTest, Creation) {
|
TEST_F(FallthroughStatementTest, Creation) {
|
||||||
auto* stmt = create<FallthroughStatement>();
|
auto* stmt = create<FallthroughStatement>();
|
||||||
EXPECT_EQ(stmt->source().range.begin.line, 0u);
|
EXPECT_EQ(stmt->source.range.begin.line, 0u);
|
||||||
EXPECT_EQ(stmt->source().range.begin.column, 0u);
|
EXPECT_EQ(stmt->source.range.begin.column, 0u);
|
||||||
EXPECT_EQ(stmt->source().range.end.line, 0u);
|
EXPECT_EQ(stmt->source.range.end.line, 0u);
|
||||||
EXPECT_EQ(stmt->source().range.end.column, 0u);
|
EXPECT_EQ(stmt->source.range.end.column, 0u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FallthroughStatementTest, Creation_WithSource) {
|
TEST_F(FallthroughStatementTest, Creation_WithSource) {
|
||||||
auto* stmt = create<FallthroughStatement>(Source{Source::Location{20, 2}});
|
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.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
@ -23,25 +23,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::FloatLiteral);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
FloatLiteral::FloatLiteral(ProgramID program_id,
|
FloatLiteral::FloatLiteral(ProgramID pid, const Source& src, float val)
|
||||||
const Source& source,
|
: Base(pid, src), value(val) {}
|
||||||
float value)
|
|
||||||
: Base(program_id, source), value_(value) {}
|
|
||||||
|
|
||||||
FloatLiteral::~FloatLiteral() = default;
|
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 {
|
FloatLiteral* FloatLiteral::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<FloatLiteral>(src, value_);
|
return ctx->dst->create<FloatLiteral>(src, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -26,26 +26,20 @@ namespace ast {
|
|||||||
class FloatLiteral : public Castable<FloatLiteral, Literal> {
|
class FloatLiteral : public Castable<FloatLiteral, Literal> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the input source
|
/// @param src the source of this node
|
||||||
/// @param value the float literals value
|
/// @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;
|
~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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
FloatLiteral* Clone(CloneContext* ctx) const override;
|
FloatLiteral* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
private:
|
/// The float literal value
|
||||||
float const value_;
|
float const value;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -23,12 +23,7 @@ using FloatLiteralTest = TestHelper;
|
|||||||
TEST_F(FloatLiteralTest, Value) {
|
TEST_F(FloatLiteralTest, Value) {
|
||||||
auto* f = create<FloatLiteral>(47.2f);
|
auto* f = create<FloatLiteral>(47.2f);
|
||||||
ASSERT_TRUE(f->Is<FloatLiteral>());
|
ASSERT_TRUE(f->Is<FloatLiteral>());
|
||||||
EXPECT_EQ(f->value(), 47.2f);
|
EXPECT_EQ(f->value, 47.2f);
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(FloatLiteralTest, ToName) {
|
|
||||||
auto* f = create<FloatLiteral>(42.1f);
|
|
||||||
EXPECT_EQ(f->name(), "__float42.0999985");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -21,23 +21,23 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ForLoopStatement);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
ForLoopStatement::ForLoopStatement(ProgramID program_id,
|
ForLoopStatement::ForLoopStatement(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
Statement* initializer,
|
Statement* init,
|
||||||
Expression* condition,
|
Expression* cond,
|
||||||
Statement* continuing,
|
Statement* cont,
|
||||||
BlockStatement* body)
|
BlockStatement* b)
|
||||||
: Base(program_id, source),
|
: Base(pid, src),
|
||||||
initializer_(initializer),
|
initializer(init),
|
||||||
condition_(condition),
|
condition(cond),
|
||||||
continuing_(continuing),
|
continuing(cont),
|
||||||
body_(body) {
|
body(b) {
|
||||||
TINT_ASSERT(AST, body_);
|
TINT_ASSERT(AST, body);
|
||||||
|
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, initializer_, 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, condition, program_id);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, continuing_, 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, body, program_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ForLoopStatement::ForLoopStatement(ForLoopStatement&&) = default;
|
ForLoopStatement::ForLoopStatement(ForLoopStatement&&) = default;
|
||||||
@ -46,12 +46,12 @@ ForLoopStatement::~ForLoopStatement() = default;
|
|||||||
|
|
||||||
ForLoopStatement* ForLoopStatement::Clone(CloneContext* ctx) const {
|
ForLoopStatement* ForLoopStatement::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
|
|
||||||
auto* init = ctx->Clone(initializer_);
|
auto* init = ctx->Clone(initializer);
|
||||||
auto* cond = ctx->Clone(condition_);
|
auto* cond = ctx->Clone(condition);
|
||||||
auto* cont = ctx->Clone(continuing_);
|
auto* cont = ctx->Clone(continuing);
|
||||||
auto* b = ctx->Clone(body_);
|
auto* b = ctx->Clone(body);
|
||||||
return ctx->dst->create<ForLoopStatement>(src, init, cond, cont, b);
|
return ctx->dst->create<ForLoopStatement>(src, init, cond, cont, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,39 +42,26 @@ class ForLoopStatement : public Castable<ForLoopStatement, Statement> {
|
|||||||
ForLoopStatement(ForLoopStatement&&);
|
ForLoopStatement(ForLoopStatement&&);
|
||||||
~ForLoopStatement() override;
|
~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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
ForLoopStatement* Clone(CloneContext* ctx) const override;
|
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:
|
private:
|
||||||
ForLoopStatement(const ForLoopStatement&) = delete;
|
ForLoopStatement(const ForLoopStatement&) = delete;
|
||||||
|
|
||||||
Statement* const initializer_;
|
|
||||||
Expression* const condition_;
|
|
||||||
Statement* const continuing_;
|
|
||||||
BlockStatement* const body_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -30,16 +30,16 @@ TEST_F(ForLoopStatementTest, Creation) {
|
|||||||
auto* body = Block(Return());
|
auto* body = Block(Return());
|
||||||
auto* l = For(init, cond, cont, body);
|
auto* l = For(init, cond, cont, body);
|
||||||
|
|
||||||
EXPECT_EQ(l->initializer(), init);
|
EXPECT_EQ(l->initializer, init);
|
||||||
EXPECT_EQ(l->condition(), cond);
|
EXPECT_EQ(l->condition, cond);
|
||||||
EXPECT_EQ(l->continuing(), cont);
|
EXPECT_EQ(l->continuing, cont);
|
||||||
EXPECT_EQ(l->body(), body);
|
EXPECT_EQ(l->body, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ForLoopStatementTest, Creation_WithSource) {
|
TEST_F(ForLoopStatementTest, Creation_WithSource) {
|
||||||
auto* body = Block(Return());
|
auto* body = Block(Return());
|
||||||
auto* l = For(Source{{20u, 2u}}, nullptr, nullptr, nullptr, body);
|
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.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ TEST_F(ForLoopStatementTest, Creation_WithSource) {
|
|||||||
TEST_F(ForLoopStatementTest, Creation_Null_InitCondCont) {
|
TEST_F(ForLoopStatementTest, Creation_Null_InitCondCont) {
|
||||||
auto* body = Block(Return());
|
auto* body = Block(Return());
|
||||||
auto* l = For(nullptr, nullptr, nullptr, body);
|
auto* l = For(nullptr, nullptr, nullptr, body);
|
||||||
EXPECT_EQ(l->body(), body);
|
EXPECT_EQ(l->body, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ForLoopStatementTest, Assert_Null_Body) {
|
TEST_F(ForLoopStatementTest, Assert_Null_Body) {
|
||||||
|
@ -23,33 +23,33 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Function);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
Function::Function(ProgramID program_id,
|
Function::Function(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
Symbol symbol,
|
Symbol sym,
|
||||||
VariableList params,
|
VariableList parameters,
|
||||||
ast::Type* return_type,
|
ast::Type* return_ty,
|
||||||
BlockStatement* body,
|
BlockStatement* b,
|
||||||
DecorationList decorations,
|
DecorationList decos,
|
||||||
DecorationList return_type_decorations)
|
DecorationList return_type_decos)
|
||||||
: Base(program_id, source),
|
: Base(pid, src),
|
||||||
symbol_(symbol),
|
symbol(sym),
|
||||||
params_(std::move(params)),
|
params(std::move(parameters)),
|
||||||
return_type_(return_type),
|
return_type(return_ty),
|
||||||
body_(body),
|
body(b),
|
||||||
decorations_(std::move(decorations)),
|
decorations(std::move(decos)),
|
||||||
return_type_decorations_(std::move(return_type_decorations)) {
|
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, symbol, program_id);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
|
||||||
for (auto* param : params_) {
|
for (auto* param : params) {
|
||||||
TINT_ASSERT(AST, param && param->is_const());
|
TINT_ASSERT(AST, param && param->is_const);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, param, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, param, program_id);
|
||||||
}
|
}
|
||||||
TINT_ASSERT(AST, symbol_.IsValid());
|
TINT_ASSERT(AST, symbol.IsValid());
|
||||||
TINT_ASSERT(AST, return_type_);
|
TINT_ASSERT(AST, return_type);
|
||||||
for (auto* deco : decorations_) {
|
for (auto* deco : decorations) {
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, deco, program_id);
|
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);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, deco, program_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,32 +58,28 @@ Function::Function(Function&&) = default;
|
|||||||
|
|
||||||
Function::~Function() = default;
|
Function::~Function() = default;
|
||||||
|
|
||||||
PipelineStage Function::pipeline_stage() const {
|
PipelineStage Function::PipelineStage() const {
|
||||||
if (auto* stage = GetDecoration<StageDecoration>(decorations_)) {
|
if (auto* stage = GetDecoration<StageDecoration>(decorations)) {
|
||||||
return stage->value();
|
return stage->stage;
|
||||||
}
|
}
|
||||||
return PipelineStage::kNone;
|
return PipelineStage::kNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Statement* Function::get_last_statement() const {
|
|
||||||
return body_->last();
|
|
||||||
}
|
|
||||||
|
|
||||||
Function* Function::Clone(CloneContext* ctx) const {
|
Function* Function::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto sym = ctx->Clone(symbol());
|
auto sym = ctx->Clone(symbol);
|
||||||
auto p = ctx->Clone(params_);
|
auto p = ctx->Clone(params);
|
||||||
auto* ret = ctx->Clone(return_type_);
|
auto* ret = ctx->Clone(return_type);
|
||||||
auto* b = ctx->Clone(body_);
|
auto* b = ctx->Clone(body);
|
||||||
auto decos = ctx->Clone(decorations_);
|
auto decos = ctx->Clone(decorations);
|
||||||
auto ret_decos = ctx->Clone(return_type_decorations_);
|
auto ret_decos = ctx->Clone(return_type_decorations);
|
||||||
return ctx->dst->create<Function>(src, sym, p, ret, b, decos, ret_decos);
|
return ctx->dst->create<Function>(src, sym, p, ret, b, decos, ret_decos);
|
||||||
}
|
}
|
||||||
|
|
||||||
Function* FunctionList::Find(Symbol sym) const {
|
Function* FunctionList::Find(Symbol sym) const {
|
||||||
for (auto* func : *this) {
|
for (auto* func : *this) {
|
||||||
if (func->symbol() == sym) {
|
if (func->symbol == sym) {
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,7 +88,7 @@ Function* FunctionList::Find(Symbol sym) const {
|
|||||||
|
|
||||||
Function* FunctionList::Find(Symbol sym, PipelineStage stage) const {
|
Function* FunctionList::Find(Symbol sym, PipelineStage stage) const {
|
||||||
for (auto* func : *this) {
|
for (auto* func : *this) {
|
||||||
if (func->symbol() == sym && func->pipeline_stage() == stage) {
|
if (func->symbol == sym && func->PipelineStage() == stage) {
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,7 +97,7 @@ Function* FunctionList::Find(Symbol sym, PipelineStage stage) const {
|
|||||||
|
|
||||||
bool FunctionList::HasStage(ast::PipelineStage stage) const {
|
bool FunctionList::HasStage(ast::PipelineStage stage) const {
|
||||||
for (auto* func : *this) {
|
for (auto* func : *this) {
|
||||||
if (func->pipeline_stage() == stage) {
|
if (func->PipelineStage() == stage) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,36 +57,11 @@ class Function : public Castable<Function, Node> {
|
|||||||
|
|
||||||
~Function() override;
|
~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
|
/// @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
|
/// @returns true if this function is an entry point
|
||||||
bool IsEntryPoint() const { return pipeline_stage() != PipelineStage::kNone; }
|
bool IsEntryPoint() const { return PipelineStage() != 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_; }
|
|
||||||
|
|
||||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
@ -94,15 +69,26 @@ class Function : public Castable<Function, Node> {
|
|||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
Function* Clone(CloneContext* ctx) const override;
|
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:
|
private:
|
||||||
Function(const Function&) = delete;
|
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
|
/// A list of functions
|
||||||
|
@ -30,10 +30,10 @@ TEST_F(FunctionTest, Creation) {
|
|||||||
auto* var = params[0];
|
auto* var = params[0];
|
||||||
|
|
||||||
auto* f = Func("func", params, ty.void_(), StatementList{}, DecorationList{});
|
auto* f = Func("func", params, ty.void_(), StatementList{}, DecorationList{});
|
||||||
EXPECT_EQ(f->symbol(), Symbols().Get("func"));
|
EXPECT_EQ(f->symbol, Symbols().Get("func"));
|
||||||
ASSERT_EQ(f->params().size(), 1u);
|
ASSERT_EQ(f->params.size(), 1u);
|
||||||
EXPECT_TRUE(f->return_type()->Is<ast::Void>());
|
EXPECT_TRUE(f->return_type->Is<ast::Void>());
|
||||||
EXPECT_EQ(f->params()[0], var);
|
EXPECT_EQ(f->params[0], var);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FunctionTest, Creation_WithSource) {
|
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_(),
|
auto* f = Func(Source{Source::Location{20, 2}}, "func", params, ty.void_(),
|
||||||
StatementList{}, DecorationList{});
|
StatementList{}, DecorationList{});
|
||||||
auto src = f->source();
|
auto src = f->source;
|
||||||
EXPECT_EQ(src.range.begin.line, 20u);
|
EXPECT_EQ(src.range.begin.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
@ -139,22 +139,6 @@ TEST_F(FunctionTest, Assert_NonConstParam) {
|
|||||||
"internal compiler error");
|
"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;
|
using FunctionListTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(FunctionListTest, FindSymbol) {
|
TEST_F(FunctionListTest, FindSymbol) {
|
||||||
|
@ -23,21 +23,19 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::GroupDecoration);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
GroupDecoration::GroupDecoration(ProgramID program_id,
|
GroupDecoration::GroupDecoration(ProgramID pid, const Source& src, uint32_t val)
|
||||||
const Source& source,
|
: Base(pid, src), value(val) {}
|
||||||
uint32_t val)
|
|
||||||
: Base(program_id, source), value_(val) {}
|
|
||||||
|
|
||||||
GroupDecoration::~GroupDecoration() = default;
|
GroupDecoration::~GroupDecoration() = default;
|
||||||
|
|
||||||
std::string GroupDecoration::name() const {
|
std::string GroupDecoration::Name() const {
|
||||||
return "group";
|
return "group";
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupDecoration* GroupDecoration::Clone(CloneContext* ctx) const {
|
GroupDecoration* GroupDecoration::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<GroupDecoration>(src, value_);
|
return ctx->dst->create<GroupDecoration>(src, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -26,17 +26,14 @@ namespace ast {
|
|||||||
class GroupDecoration : public Castable<GroupDecoration, Decoration> {
|
class GroupDecoration : public Castable<GroupDecoration, Decoration> {
|
||||||
public:
|
public:
|
||||||
/// constructor
|
/// 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 value the group value
|
||||||
/// @param source the source of this decoration
|
GroupDecoration(ProgramID pid, const Source& src, uint32_t value);
|
||||||
GroupDecoration(ProgramID program_id, const Source& source, uint32_t value);
|
|
||||||
~GroupDecoration() override;
|
~GroupDecoration() override;
|
||||||
|
|
||||||
/// @returns the group value
|
|
||||||
uint32_t value() const { return value_; }
|
|
||||||
|
|
||||||
/// @returns the WGSL name for the decoration
|
/// @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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
@ -44,8 +41,8 @@ class GroupDecoration : public Castable<GroupDecoration, Decoration> {
|
|||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
GroupDecoration* Clone(CloneContext* ctx) const override;
|
GroupDecoration* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
private:
|
/// The group value
|
||||||
uint32_t const value_;
|
uint32_t const value;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -23,7 +23,7 @@ using GroupDecorationTest = TestHelper;
|
|||||||
|
|
||||||
TEST_F(GroupDecorationTest, Creation) {
|
TEST_F(GroupDecorationTest, Creation) {
|
||||||
auto* d = create<GroupDecoration>(2);
|
auto* d = create<GroupDecoration>(2);
|
||||||
EXPECT_EQ(2u, d->value());
|
EXPECT_EQ(2u, d->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -21,8 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::I32);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
I32::I32(ProgramID program_id, const Source& source)
|
I32::I32(ProgramID pid, const Source& src) : Base(pid, src) {}
|
||||||
: Base(program_id, source) {}
|
|
||||||
|
|
||||||
I32::I32(I32&&) = default;
|
I32::I32(I32&&) = default;
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ std::string I32::FriendlyName(const SymbolTable&) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
I32* I32::Clone(CloneContext* ctx) const {
|
I32* I32::Clone(CloneContext* ctx) const {
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
return ctx->dst->create<I32>(src);
|
return ctx->dst->create<I32>(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,9 +26,9 @@ namespace ast {
|
|||||||
class I32 : public Castable<I32, Type> {
|
class I32 : public Castable<I32, Type> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source of this node
|
/// @param src the source of this node
|
||||||
I32(ProgramID program_id, const Source& source);
|
I32(ProgramID pid, const Source& src);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
I32(I32&&);
|
I32(I32&&);
|
||||||
~I32() override;
|
~I32() override;
|
||||||
|
@ -21,12 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IdentifierExpression);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
IdentifierExpression::IdentifierExpression(ProgramID program_id,
|
IdentifierExpression::IdentifierExpression(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
Symbol sym)
|
Symbol sym)
|
||||||
: Base(program_id, source), sym_(sym) {
|
: Base(pid, src), symbol(sym) {
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, sym_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id);
|
||||||
TINT_ASSERT(AST, sym_.IsValid());
|
TINT_ASSERT(AST, symbol.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default;
|
IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default;
|
||||||
@ -35,8 +35,8 @@ IdentifierExpression::~IdentifierExpression() = default;
|
|||||||
|
|
||||||
IdentifierExpression* IdentifierExpression::Clone(CloneContext* ctx) const {
|
IdentifierExpression* IdentifierExpression::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto sym = ctx->Clone(symbol());
|
auto sym = ctx->Clone(symbol);
|
||||||
return ctx->dst->create<IdentifierExpression>(src, sym);
|
return ctx->dst->create<IdentifierExpression>(src, sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,27 +24,25 @@ namespace ast {
|
|||||||
class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
|
class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source
|
/// @param src the source of this node
|
||||||
/// @param sym the symbol for the identifier
|
/// @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
|
/// Move constructor
|
||||||
IdentifierExpression(IdentifierExpression&&);
|
IdentifierExpression(IdentifierExpression&&);
|
||||||
~IdentifierExpression() override;
|
~IdentifierExpression() override;
|
||||||
|
|
||||||
/// @returns the symbol for the identifier
|
|
||||||
Symbol symbol() const { return sym_; }
|
|
||||||
|
|
||||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
IdentifierExpression* Clone(CloneContext* ctx) const override;
|
IdentifierExpression* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
|
/// The symbol for the identifier
|
||||||
|
Symbol const symbol;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IdentifierExpression(const IdentifierExpression&) = delete;
|
IdentifierExpression(const IdentifierExpression&) = delete;
|
||||||
|
|
||||||
Symbol const sym_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -23,14 +23,14 @@ using IdentifierExpressionTest = TestHelper;
|
|||||||
|
|
||||||
TEST_F(IdentifierExpressionTest, Creation) {
|
TEST_F(IdentifierExpressionTest, Creation) {
|
||||||
auto* i = Expr("ident");
|
auto* i = Expr("ident");
|
||||||
EXPECT_EQ(i->symbol(), Symbol(1, ID()));
|
EXPECT_EQ(i->symbol, Symbol(1, ID()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(IdentifierExpressionTest, Creation_WithSource) {
|
TEST_F(IdentifierExpressionTest, Creation_WithSource) {
|
||||||
auto* i = Expr(Source{Source::Location{20, 2}}, "ident");
|
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.line, 20u);
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
@ -21,20 +21,20 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IfStatement);
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
IfStatement::IfStatement(ProgramID program_id,
|
IfStatement::IfStatement(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
Expression* condition,
|
Expression* cond,
|
||||||
BlockStatement* body,
|
BlockStatement* b,
|
||||||
ElseStatementList else_stmts)
|
ElseStatementList else_stmts)
|
||||||
: Base(program_id, source),
|
: Base(pid, src),
|
||||||
condition_(condition),
|
condition(cond),
|
||||||
body_(body),
|
body(b),
|
||||||
else_statements_(std::move(else_stmts)) {
|
else_statements(std::move(else_stmts)) {
|
||||||
TINT_ASSERT(AST, condition_);
|
TINT_ASSERT(AST, condition);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id);
|
||||||
TINT_ASSERT(AST, body_);
|
TINT_ASSERT(AST, body);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body_, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
|
||||||
for (auto* el : else_statements_) {
|
for (auto* el : else_statements) {
|
||||||
TINT_ASSERT(AST, el);
|
TINT_ASSERT(AST, el);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, el, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, el, program_id);
|
||||||
}
|
}
|
||||||
@ -46,10 +46,10 @@ IfStatement::~IfStatement() = default;
|
|||||||
|
|
||||||
IfStatement* IfStatement::Clone(CloneContext* ctx) const {
|
IfStatement* IfStatement::Clone(CloneContext* ctx) const {
|
||||||
// Clone arguments outside of create() call to have deterministic ordering
|
// Clone arguments outside of create() call to have deterministic ordering
|
||||||
auto src = ctx->Clone(source());
|
auto src = ctx->Clone(source);
|
||||||
auto* cond = ctx->Clone(condition_);
|
auto* cond = ctx->Clone(condition);
|
||||||
auto* b = ctx->Clone(body_);
|
auto* b = ctx->Clone(body);
|
||||||
auto el = ctx->Clone(else_statements_);
|
auto el = ctx->Clone(else_statements);
|
||||||
return ctx->dst->create<IfStatement>(src, cond, b, el);
|
return ctx->dst->create<IfStatement>(src, cond, b, el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,13 +26,13 @@ namespace ast {
|
|||||||
class IfStatement : public Castable<IfStatement, Statement> {
|
class IfStatement : public Castable<IfStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// 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 source the source information
|
/// @param src the source of this node
|
||||||
/// @param condition the if condition
|
/// @param condition the if condition
|
||||||
/// @param body the if body
|
/// @param body the if body
|
||||||
/// @param else_stmts the else statements
|
/// @param else_stmts the else statements
|
||||||
IfStatement(ProgramID program_id,
|
IfStatement(ProgramID pid,
|
||||||
const Source& source,
|
const Source& src,
|
||||||
Expression* condition,
|
Expression* condition,
|
||||||
BlockStatement* body,
|
BlockStatement* body,
|
||||||
ElseStatementList else_stmts);
|
ElseStatementList else_stmts);
|
||||||
@ -40,31 +40,23 @@ class IfStatement : public Castable<IfStatement, Statement> {
|
|||||||
IfStatement(IfStatement&&);
|
IfStatement(IfStatement&&);
|
||||||
~IfStatement() override;
|
~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`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned node
|
/// @return the newly cloned node
|
||||||
IfStatement* Clone(CloneContext* ctx) const override;
|
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:
|
private:
|
||||||
IfStatement(const IfStatement&) = delete;
|
IfStatement(const IfStatement&) = delete;
|
||||||
|
|
||||||
Expression* const condition_;
|
|
||||||
BlockStatement* const body_;
|
|
||||||
ElseStatementList const else_statements_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user