1 /**
2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "tsInterfaceBody.h"
17
18 #include "checker/TSchecker.h"
19 #include "compiler/core/ETSGen.h"
20 #include "compiler/core/pandagen.h"
21 #include "ir/astDump.h"
22 #include "ir/srcDump.h"
23
24 namespace ark::es2panda::ir {
TransformChildren(const NodeTransformer & cb,std::string_view transformationName)25 void TSInterfaceBody::TransformChildren(const NodeTransformer &cb, std::string_view transformationName)
26 {
27 for (auto *&it : VectorIterationGuard(body_)) {
28 if (auto *transformedNode = cb(it); it != transformedNode) {
29 it->SetTransformedNode(transformationName, transformedNode);
30 it = transformedNode;
31 }
32 }
33 }
34
Iterate(const NodeTraverser & cb) const35 void TSInterfaceBody::Iterate(const NodeTraverser &cb) const
36 {
37 // NOLINTNEXTLINE(modernize-loop-convert)
38 for (size_t idx = 0; idx < body_.size(); idx++) {
39 cb(body_[idx]);
40 }
41 }
42
Dump(ir::AstDumper * dumper) const43 void TSInterfaceBody::Dump(ir::AstDumper *dumper) const
44 {
45 dumper->Add({{"type", "TSInterfaceBody"}, {"body", body_}});
46 }
47
Dump(ir::SrcDumper * dumper) const48 void TSInterfaceBody::Dump(ir::SrcDumper *dumper) const
49 {
50 for (auto b : body_) {
51 b->Dump(dumper);
52 }
53 }
54
Compile(compiler::PandaGen * pg) const55 void TSInterfaceBody::Compile([[maybe_unused]] compiler::PandaGen *pg) const
56 {
57 pg->GetAstCompiler()->Compile(this);
58 }
59
Compile(compiler::ETSGen * etsg) const60 void TSInterfaceBody::Compile(compiler::ETSGen *etsg) const
61 {
62 etsg->GetAstCompiler()->Compile(this);
63 }
64
Check(checker::TSChecker * checker)65 checker::Type *TSInterfaceBody::Check([[maybe_unused]] checker::TSChecker *checker)
66 {
67 return checker->GetAnalyzer()->Check(this);
68 }
69
Check(checker::ETSChecker * checker)70 checker::VerifiedType TSInterfaceBody::Check([[maybe_unused]] checker::ETSChecker *checker)
71 {
72 return {this, checker->GetAnalyzer()->Check(this)};
73 }
74 } // namespace ark::es2panda::ir
75