• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021 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 "exportNamedDeclaration.h"
17 
18 #include <ir/astDump.h>
19 #include <ir/expressions/literals/stringLiteral.h>
20 #include <ir/module/exportSpecifier.h>
21 
22 namespace panda::es2panda::ir {
23 
Iterate(const NodeTraverser & cb) const24 void ExportNamedDeclaration::Iterate(const NodeTraverser &cb) const
25 {
26     if (decl_) {
27         cb(decl_);
28     } else {
29         if (source_) {
30             cb(source_);
31         }
32 
33         for (auto *it : specifiers_) {
34             cb(it);
35         }
36 
37         if (assertClause_) {
38             cb(assertClause_);
39         }
40     }
41 }
42 
Dump(ir::AstDumper * dumper) const43 void ExportNamedDeclaration::Dump(ir::AstDumper *dumper) const
44 {
45     dumper->Add({{"type", "ExportNamedDeclaration"},
46                  {"declaration", AstDumper::Nullable(decl_)},
47                  {"source", AstDumper::Nullable(source_)},
48                  {"specifiers", specifiers_},
49                  {"assertClause", AstDumper::Optional(assertClause_)},
50                  {"isType", AstDumper::Optional(IsType())}});
51 }
52 
Compile(compiler::PandaGen * pg) const53 void ExportNamedDeclaration::Compile(compiler::PandaGen *pg) const
54 {
55     if (!decl_) {
56         return;
57     }
58 
59     decl_->Compile(pg);
60 }
61 
Check(checker::Checker * checker) const62 checker::Type *ExportNamedDeclaration::Check([[maybe_unused]] checker::Checker *checker) const
63 {
64     return nullptr;
65 }
66 
UpdateSelf(const NodeUpdater & cb,binder::Binder * binder)67 void ExportNamedDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder)
68 {
69     if (decl_) {
70         decl_ = std::get<ir::AstNode *>(cb(decl_))->AsStatement();
71     } else {
72         if (source_) {
73             source_ = std::get<ir::AstNode *>(cb(source_))->AsStringLiteral();
74         }
75 
76         for (auto iter = specifiers_.begin(); iter != specifiers_.end(); iter++) {
77             *iter = std::get<ir::AstNode *>(cb(*iter))->AsExportSpecifier();
78         }
79 
80         if (assertClause_) {
81             assertClause_ = std::get<ir::AstNode *>(cb(assertClause_))->AsAssertClause();
82         }
83     }
84 }
85 
86 }  // namespace panda::es2panda::ir
87