1 /**
2 * Copyright (c) 2021-2024 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 "tsClassImplements.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 #include "ir/ts/tsTypeParameter.h"
24 #include "ir/ts/tsTypeParameterInstantiation.h"
25
26 namespace ark::es2panda::ir {
TransformChildren(const NodeTransformer &cb, std::string_view transformationName)27 void TSClassImplements::TransformChildren(const NodeTransformer &cb, std::string_view transformationName)
28 {
29 if (auto *transformedNode = cb(expression_); expression_ != transformedNode) {
30 expression_->SetTransformedNode(transformationName, transformedNode);
31 expression_ = transformedNode->AsExpression();
32 }
33 }
34
Iterate(const NodeTraverser &cb) const35 void TSClassImplements::Iterate(const NodeTraverser &cb) const
36 {
37 cb(expression_);
38
39 if (typeParameters_ != nullptr) {
40 cb(typeParameters_);
41 }
42 }
43
Dump(ir::AstDumper *dumper) const44 void TSClassImplements::Dump(ir::AstDumper *dumper) const
45 {
46 dumper->Add({{"type", "TSClassImplements"},
47 {"expression", expression_},
48 {"typeParameters", AstDumper::Optional(typeParameters_)}});
49 }
50
Dump(ir::SrcDumper *dumper) const51 void TSClassImplements::Dump(ir::SrcDumper *dumper) const
52 {
53 expression_->Dump(dumper);
54 ASSERT(typeParameters_ == nullptr);
55 }
56
Compile([[maybe_unused]] compiler::PandaGen *pg) const57 void TSClassImplements::Compile([[maybe_unused]] compiler::PandaGen *pg) const
58 {
59 pg->GetAstCompiler()->Compile(this);
60 }
61
Compile(compiler::ETSGen *etsg) const62 void TSClassImplements::Compile(compiler::ETSGen *etsg) const
63 {
64 etsg->GetAstCompiler()->Compile(this);
65 }
66
Check([[maybe_unused]] checker::TSChecker *checker)67 checker::Type *TSClassImplements::Check([[maybe_unused]] checker::TSChecker *checker)
68 {
69 return checker->GetAnalyzer()->Check(this);
70 }
71
Check([[maybe_unused]] checker::ETSChecker *checker)72 checker::Type *TSClassImplements::Check([[maybe_unused]] checker::ETSChecker *checker)
73 {
74 return checker->GetAnalyzer()->Check(this);
75 }
76 } // namespace ark::es2panda::ir
77