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 "tsMethodSignature.h"
17 #include "ir/astDump.h"
18 #include "ir/srcDump.h"
19 #include "checker/TSchecker.h"
20 #include "compiler/core/ETSGen.h"
21 #include "compiler/core/pandagen.h"
22 
23 namespace ark::es2panda::ir {
TransformChildren(const NodeTransformer &cb, std::string_view const transformationName)24 void TSMethodSignature::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName)
25 {
26     if (auto *transformedNode = cb(key_); key_ != transformedNode) {
27         key_->SetTransformedNode(transformationName, transformedNode);
28         key_ = transformedNode->AsExpression();
29     }
30 
31     signature_.TransformChildren(cb, transformationName);
32 }
33 
Iterate(const NodeTraverser &cb) const34 void TSMethodSignature::Iterate(const NodeTraverser &cb) const
35 {
36     cb(key_);
37     signature_.Iterate(cb);
38 }
39 
Dump(ir::AstDumper *dumper) const40 void TSMethodSignature::Dump(ir::AstDumper *dumper) const
41 {
42     dumper->Add({{"type", "TSMethodSignature"},
43                  {"computed", computed_},
44                  {"optional", optional_},
45                  {"key", key_},
46                  {"params", Params()},
47                  {"typeParameters", AstDumper::Optional(TypeParams())},
48                  {"typeAnnotation", AstDumper::Optional(ReturnTypeAnnotation())}});
49 }
50 
Dump(ir::SrcDumper *dumper) const51 void TSMethodSignature::Dump(ir::SrcDumper *dumper) const
52 {
53     dumper->Add("TSMethodSignature");
54 }
55 
Compile(compiler::PandaGen *pg) const56 void TSMethodSignature::Compile(compiler::PandaGen *pg) const
57 {
58     pg->GetAstCompiler()->Compile(this);
59 }
60 
Compile(compiler::ETSGen *etsg) const61 void TSMethodSignature::Compile(compiler::ETSGen *etsg) const
62 {
63     etsg->GetAstCompiler()->Compile(this);
64 }
65 
Check(checker::TSChecker *checker)66 checker::Type *TSMethodSignature::Check(checker::TSChecker *checker)
67 {
68     return checker->GetAnalyzer()->Check(this);
69 }
70 
Check(checker::ETSChecker *checker)71 checker::Type *TSMethodSignature::Check(checker::ETSChecker *checker)
72 {
73     return checker->GetAnalyzer()->Check(this);
74 }
75 }  // namespace ark::es2panda::ir
76