Move CloneContext and Traits from src/ast to src/
CloneContext clones the AST, types, symbols and in the future semantic info.
3/4 of these are non-ast, so promote these up to the root.
Bug: tint:390
Change-Id: I49619796e6f81f9ab64f79413a12c87312cb1901
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38361
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/transform/bound_array_accessors.cc b/src/transform/bound_array_accessors.cc
index bdfb938..0c2c290 100644
--- a/src/transform/bound_array_accessors.cc
+++ b/src/transform/bound_array_accessors.cc
@@ -27,7 +27,6 @@
#include "src/ast/call_expression.h"
#include "src/ast/call_statement.h"
#include "src/ast/case_statement.h"
-#include "src/ast/clone_context.h"
#include "src/ast/continue_statement.h"
#include "src/ast/discard_statement.h"
#include "src/ast/else_statement.h"
@@ -44,6 +43,7 @@
#include "src/ast/unary_op_expression.h"
#include "src/ast/variable.h"
#include "src/ast/variable_decl_statement.h"
+#include "src/clone_context.h"
#include "src/type/array_type.h"
#include "src/type/matrix_type.h"
#include "src/type/u32_type.h"
@@ -57,18 +57,17 @@
Transform::Output BoundArrayAccessors::Run(ast::Module* in) {
Output out;
- ast::CloneContext(&out.module, in)
- .ReplaceAll(
- [&](ast::CloneContext* ctx, ast::ArrayAccessorExpression* expr) {
- return Transform(expr, ctx, &out.diagnostics);
- })
+ CloneContext(&out.module, in)
+ .ReplaceAll([&](CloneContext* ctx, ast::ArrayAccessorExpression* expr) {
+ return Transform(expr, ctx, &out.diagnostics);
+ })
.Clone();
return out;
}
ast::ArrayAccessorExpression* BoundArrayAccessors::Transform(
ast::ArrayAccessorExpression* expr,
- ast::CloneContext* ctx,
+ CloneContext* ctx,
diag::List* diags) {
auto* ret_type = expr->array()->result_type()->UnwrapAll();
if (!ret_type->Is<type::Array>() && !ret_type->Is<type::Matrix>() &&
diff --git a/src/transform/bound_array_accessors.h b/src/transform/bound_array_accessors.h
index bfb7546..0d78df1 100644
--- a/src/transform/bound_array_accessors.h
+++ b/src/transform/bound_array_accessors.h
@@ -48,7 +48,7 @@
private:
ast::ArrayAccessorExpression* Transform(ast::ArrayAccessorExpression* expr,
- ast::CloneContext* ctx,
+ CloneContext* ctx,
diag::List* diags);
};
diff --git a/src/transform/emit_vertex_point_size.cc b/src/transform/emit_vertex_point_size.cc
index a46a958..dd2acf0 100644
--- a/src/transform/emit_vertex_point_size.cc
+++ b/src/transform/emit_vertex_point_size.cc
@@ -19,11 +19,11 @@
#include "src/ast/assignment_statement.h"
#include "src/ast/block_statement.h"
-#include "src/ast/clone_context.h"
#include "src/ast/float_literal.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/variable.h"
+#include "src/clone_context.h"
#include "src/type/f32_type.h"
#include "src/type/type_manager.h"
@@ -73,9 +73,9 @@
Source{}, pointsize_ident, one);
// Add the pointsize assignment statement to the front of all vertex stages.
- ast::CloneContext(&out.module, in)
+ CloneContext(&out.module, in)
.ReplaceAll(
- [&](ast::CloneContext* ctx, ast::Function* func) -> ast::Function* {
+ [&](CloneContext* ctx, ast::Function* func) -> ast::Function* {
if (func->pipeline_stage() != ast::PipelineStage::kVertex) {
return nullptr; // Just clone func
}
diff --git a/src/transform/first_index_offset.cc b/src/transform/first_index_offset.cc
index df878ac..2d74c11 100644
--- a/src/transform/first_index_offset.cc
+++ b/src/transform/first_index_offset.cc
@@ -25,7 +25,6 @@
#include "src/ast/builtin_decoration.h"
#include "src/ast/call_statement.h"
#include "src/ast/case_statement.h"
-#include "src/ast/clone_context.h"
#include "src/ast/constructor_expression.h"
#include "src/ast/else_statement.h"
#include "src/ast/expression.h"
@@ -47,6 +46,7 @@
#include "src/ast/variable.h"
#include "src/ast/variable_decl_statement.h"
#include "src/ast/variable_decoration.h"
+#include "src/clone_context.h"
#include "src/type/struct_type.h"
#include "src/type/u32_type.h"
#include "src/type_determiner.h"
@@ -61,7 +61,7 @@
constexpr char kFirstInstanceName[] = "tint_first_instance_index";
constexpr char kIndexOffsetPrefix[] = "tint_first_index_offset_";
-ast::Variable* clone_variable_with_new_name(ast::CloneContext* ctx,
+ast::Variable* clone_variable_with_new_name(CloneContext* ctx,
ast::Variable* in,
std::string new_name) {
return ctx->mod->create<ast::Variable>(
@@ -126,33 +126,32 @@
// these builtins.
Output out;
- ast::CloneContext(&out.module, in)
- .ReplaceAll(
- [&](ast::CloneContext* ctx, ast::Variable* var) -> ast::Variable* {
- for (ast::VariableDecoration* dec : var->decorations()) {
- if (auto* blt_dec = dec->As<ast::BuiltinDecoration>()) {
- ast::Builtin blt_type = blt_dec->value();
- if (blt_type == ast::Builtin::kVertexIndex) {
- vertex_index_sym = var->symbol();
- has_vertex_index_ = true;
- return clone_variable_with_new_name(
- ctx, var,
- kIndexOffsetPrefix + in->SymbolToName(var->symbol()));
- } else if (blt_type == ast::Builtin::kInstanceIndex) {
- instance_index_sym = var->symbol();
- has_instance_index_ = true;
- return clone_variable_with_new_name(
- ctx, var,
- kIndexOffsetPrefix + in->SymbolToName(var->symbol()));
- }
- }
+ CloneContext(&out.module, in)
+ .ReplaceAll([&](CloneContext* ctx, ast::Variable* var) -> ast::Variable* {
+ for (ast::VariableDecoration* dec : var->decorations()) {
+ if (auto* blt_dec = dec->As<ast::BuiltinDecoration>()) {
+ ast::Builtin blt_type = blt_dec->value();
+ if (blt_type == ast::Builtin::kVertexIndex) {
+ vertex_index_sym = var->symbol();
+ has_vertex_index_ = true;
+ return clone_variable_with_new_name(
+ ctx, var,
+ kIndexOffsetPrefix + in->SymbolToName(var->symbol()));
+ } else if (blt_type == ast::Builtin::kInstanceIndex) {
+ instance_index_sym = var->symbol();
+ has_instance_index_ = true;
+ return clone_variable_with_new_name(
+ ctx, var,
+ kIndexOffsetPrefix + in->SymbolToName(var->symbol()));
}
- return nullptr; // Just clone var
- })
+ }
+ }
+ return nullptr; // Just clone var
+ })
.ReplaceAll( // Note: This happens in the same pass as the rename above
// which determines the original builtin variable names,
// but this should be fine, as variables are cloned first.
- [&](ast::CloneContext* ctx, ast::Function* func) -> ast::Function* {
+ [&](CloneContext* ctx, ast::Function* func) -> ast::Function* {
maybe_create_buffer_var(ctx->mod);
if (buffer_var == nullptr) {
return nullptr; // no transform need, just clone func
diff --git a/src/transform/transform.cc b/src/transform/transform.cc
index 65fadb9..54766a7 100644
--- a/src/transform/transform.cc
+++ b/src/transform/transform.cc
@@ -15,8 +15,8 @@
#include "src/transform/transform.h"
#include "src/ast/block_statement.h"
-#include "src/ast/clone_context.h"
#include "src/ast/function.h"
+#include "src/clone_context.h"
namespace tint {
namespace transform {
@@ -25,7 +25,7 @@
Transform::~Transform() = default;
ast::Function* Transform::CloneWithStatementsAtStart(
- ast::CloneContext* ctx,
+ CloneContext* ctx,
ast::Function* in,
ast::StatementList statements) {
for (auto* s : *in->body()) {
diff --git a/src/transform/transform.h b/src/transform/transform.h
index 211be8a..4684a21 100644
--- a/src/transform/transform.h
+++ b/src/transform/transform.h
@@ -57,7 +57,7 @@
/// @param statements the statements to prepend to `in`'s body
/// @return the cloned function
static ast::Function* CloneWithStatementsAtStart(
- ast::CloneContext* ctx,
+ CloneContext* ctx,
ast::Function* in,
ast::StatementList statements);
};
diff --git a/src/transform/vertex_pulling.cc b/src/transform/vertex_pulling.cc
index 24f6da6..104e80a 100644
--- a/src/transform/vertex_pulling.cc
+++ b/src/transform/vertex_pulling.cc
@@ -20,7 +20,6 @@
#include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h"
#include "src/ast/bitcast_expression.h"
-#include "src/ast/clone_context.h"
#include "src/ast/member_accessor_expression.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/stride_decoration.h"
@@ -33,6 +32,7 @@
#include "src/ast/uint_literal.h"
#include "src/ast/variable.h"
#include "src/ast/variable_decl_statement.h"
+#include "src/clone_context.h"
#include "src/type/array_type.h"
#include "src/type/f32_type.h"
#include "src/type/i32_type.h"
@@ -109,15 +109,14 @@
state.ConvertVertexInputVariablesToPrivate();
state.AddVertexStorageBuffers();
- ast::CloneContext(&out.module, in)
- .ReplaceAll(
- [&](ast::CloneContext* ctx, ast::Function* f) -> ast::Function* {
- if (f == func) {
- return CloneWithStatementsAtStart(
- ctx, f, {state.CreateVertexPullingPreamble()});
- }
- return nullptr; // Just clone func
- })
+ CloneContext(&out.module, in)
+ .ReplaceAll([&](CloneContext* ctx, ast::Function* f) -> ast::Function* {
+ if (f == func) {
+ return CloneWithStatementsAtStart(
+ ctx, f, {state.CreateVertexPullingPreamble()});
+ }
+ return nullptr; // Just clone func
+ })
.Clone();
return out;