2020-12-01 18:04:17 +00:00
|
|
|
// Copyright 2020 The Tint Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2021-01-21 16:20:40 +00:00
|
|
|
#include "src/clone_context.h"
|
2020-12-01 18:04:17 +00:00
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
#include "src/ast/function.h"
|
|
|
|
#include "src/ast/module.h"
|
2021-01-26 16:57:10 +00:00
|
|
|
#include "src/program.h"
|
2021-01-26 16:57:10 +00:00
|
|
|
#include "src/program_builder.h"
|
2020-12-15 12:32:18 +00:00
|
|
|
|
2021-03-02 20:51:18 +00:00
|
|
|
TINT_INSTANTIATE_TYPEINFO(tint::Cloneable);
|
2021-02-17 13:17:39 +00:00
|
|
|
|
2020-12-01 18:04:17 +00:00
|
|
|
namespace tint {
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
CloneContext::CloneContext(ProgramBuilder* to, Program const* from)
|
2021-01-22 13:41:06 +00:00
|
|
|
: dst(to), src(from) {}
|
2020-12-01 18:04:17 +00:00
|
|
|
CloneContext::~CloneContext() = default;
|
|
|
|
|
2020-12-15 12:32:18 +00:00
|
|
|
Symbol CloneContext::Clone(const Symbol& s) const {
|
2021-01-26 16:57:10 +00:00
|
|
|
return dst->Symbols().Register(src->Symbols().NameFor(s));
|
2020-12-15 12:32:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CloneContext::Clone() {
|
2021-02-11 20:23:03 +00:00
|
|
|
dst->AST().Copy(this, &src->AST());
|
2020-12-15 12:32:18 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
ast::FunctionList CloneContext::Clone(const ast::FunctionList& v) {
|
|
|
|
ast::FunctionList out;
|
|
|
|
out.reserve(v.size());
|
|
|
|
for (ast::Function* el : v) {
|
|
|
|
out.Add(Clone(el));
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2021-02-17 20:13:34 +00:00
|
|
|
diag::List& CloneContext::Diagnostics() const {
|
|
|
|
return dst->Diagnostics();
|
|
|
|
}
|
|
|
|
|
2020-12-01 18:04:17 +00:00
|
|
|
} // namespace tint
|