• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "importSpecifier.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 ImportSpecifier::TransformChildren(const NodeTransformer &cb, std::string_view transformationName)
26 {
27     if (local_ != nullptr) {
28         if (auto *transformedNode = cb(local_); local_ != transformedNode) {
29             local_->SetTransformedNode(transformationName, transformedNode);
30             local_ = transformedNode->AsIdentifier();
31         }
32     }
33 
34     if (auto *transformedNode = cb(imported_); imported_ != transformedNode) {
35         imported_->SetTransformedNode(transformationName, transformedNode);
36         imported_ = transformedNode->AsIdentifier();
37     }
38 }
39 
Iterate(const NodeTraverser & cb) const40 void ImportSpecifier::Iterate(const NodeTraverser &cb) const
41 {
42     if (local_ != nullptr) {
43         cb(local_);
44     }
45     cb(imported_);
46 }
47 
Dump(ir::AstDumper * dumper) const48 void ImportSpecifier::Dump(ir::AstDumper *dumper) const
49 {
50     dumper->Add({{"type", "ImportSpecifier"}, {"local", ir::AstDumper::Optional(local_)}, {"imported", imported_}});
51 }
52 
Dump(ir::SrcDumper * dumper) const53 void ImportSpecifier::Dump(ir::SrcDumper *dumper) const
54 {
55     dumper->Add("ImportSpecifier");
56 }
57 
Compile(compiler::PandaGen * pg) const58 void ImportSpecifier::Compile(compiler::PandaGen *pg) const
59 {
60     pg->GetAstCompiler()->Compile(this);
61 }
Compile(compiler::ETSGen * etsg) const62 void ImportSpecifier::Compile(compiler::ETSGen *etsg) const
63 {
64     etsg->GetAstCompiler()->Compile(this);
65 }
66 
Check(checker::TSChecker * checker)67 checker::Type *ImportSpecifier::Check(checker::TSChecker *checker)
68 {
69     return checker->GetAnalyzer()->Check(this);
70 }
71 
Check(checker::ETSChecker * checker)72 checker::Type *ImportSpecifier::Check(checker::ETSChecker *checker)
73 {
74     return checker->GetAnalyzer()->Check(this);
75 }
76 }  // namespace ark::es2panda::ir
77