• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "tsNamedTupleMember.h"
17 
18 #include "checker/ETSchecker.h"
19 #include "checker/TSchecker.h"
20 #include "compiler/core/ETSGen.h"
21 #include "compiler/core/pandagen.h"
22 #include "ir/astDump.h"
23 #include "ir/srcDump.h"
24 
25 namespace ark::es2panda::ir {
TransformChildren(const NodeTransformer & cb,std::string_view const transformationName)26 void TSNamedTupleMember::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName)
27 {
28     if (auto *transformedNode = cb(label_); label_ != transformedNode) {
29         label_->SetTransformedNode(transformationName, transformedNode);
30         label_ = transformedNode->AsExpression();
31     }
32 
33     if (auto *transformedNode = cb(elementType_); elementType_ != transformedNode) {
34         elementType_->SetTransformedNode(transformationName, transformedNode);
35         elementType_ = static_cast<TypeNode *>(transformedNode);
36     }
37     for (auto *&it : VectorIterationGuard(Annotations())) {
38         if (auto *transformedNode = cb(it); it != transformedNode) {
39             it->SetTransformedNode(transformationName, transformedNode);
40             it = transformedNode->AsAnnotationUsage();
41         }
42     }
43 }
44 
Iterate(const NodeTraverser & cb) const45 void TSNamedTupleMember::Iterate(const NodeTraverser &cb) const
46 {
47     cb(label_);
48     cb(elementType_);
49     for (auto *it : VectorIterationGuard(Annotations())) {
50         cb(it);
51     }
52 }
53 
Dump(ir::AstDumper * dumper) const54 void TSNamedTupleMember::Dump(ir::AstDumper *dumper) const
55 {
56     dumper->Add({{"type", "TSNamedTupleMember"},
57                  {"elementType", elementType_},
58                  {"label", label_},
59                  {"optional", AstDumper::Optional(optional_)},
60                  {"annotations", AstDumper::Optional(Annotations())}});
61 }
62 
Dump(ir::SrcDumper * dumper) const63 void TSNamedTupleMember::Dump(ir::SrcDumper *dumper) const
64 {
65     for (auto *anno : Annotations()) {
66         anno->Dump(dumper);
67     }
68     dumper->Add("TSNamedTupleMember");
69 }
70 
Compile(compiler::PandaGen * pg) const71 void TSNamedTupleMember::Compile([[maybe_unused]] compiler::PandaGen *pg) const
72 {
73     pg->GetAstCompiler()->Compile(this);
74 }
75 
Compile(compiler::ETSGen * etsg) const76 void TSNamedTupleMember::Compile(compiler::ETSGen *etsg) const
77 {
78     etsg->GetAstCompiler()->Compile(this);
79 }
80 
Check(checker::TSChecker * checker)81 checker::Type *TSNamedTupleMember::Check([[maybe_unused]] checker::TSChecker *checker)
82 {
83     return checker->GetAnalyzer()->Check(this);
84 }
85 
Check(checker::ETSChecker * checker)86 checker::VerifiedType TSNamedTupleMember::Check([[maybe_unused]] checker::ETSChecker *checker)
87 {
88     return {this, checker->GetAnalyzer()->Check(this)};
89 }
90 }  // namespace ark::es2panda::ir
91