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/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