• 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 <compiler/core/pandagen.h>
19 #include <ir/astDump.h>
20 #include <ir/expressions/literals/stringLiteral.h>
21 #include <ir/module/exportSpecifier.h>
22 
23 namespace panda::es2panda::ir {
24 
Iterate(const NodeTraverser & cb) const25 void ExportNamedDeclaration::Iterate(const NodeTraverser &cb) const
26 {
27     if (decl_) {
28         cb(decl_);
29     } else {
30         if (source_) {
31             cb(source_);
32         }
33 
34         for (auto *it : specifiers_) {
35             cb(it);
36         }
37     }
38 }
39 
Dump(ir::AstDumper * dumper) const40 void ExportNamedDeclaration::Dump(ir::AstDumper *dumper) const
41 {
42     dumper->Add({{"type", "ExportNamedDeclaration"},
43                  {"declaration", AstDumper::Nullable(decl_)},
44                  {"source", AstDumper::Nullable(source_)},
45                  {"specifiers", specifiers_}});
46 }
47 
Compile(compiler::PandaGen * pg) const48 void ExportNamedDeclaration::Compile(compiler::PandaGen *pg) const
49 {
50     if (!decl_) {
51         return;
52     }
53 
54     decl_->Compile(pg);
55 }
56 
Check(checker::Checker * checker) const57 checker::Type *ExportNamedDeclaration::Check([[maybe_unused]] checker::Checker *checker) const
58 {
59     return nullptr;
60 }
61 
UpdateSelf(const NodeUpdater & cb,binder::Binder * binder)62 void ExportNamedDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder)
63 {
64     if (decl_) {
65         decl_ = std::get<ir::AstNode *>(cb(decl_))->AsStatement();
66     } else {
67         if (source_) {
68             source_ = std::get<ir::AstNode *>(cb(source_))->AsStringLiteral();
69         }
70 
71         for (auto iter = specifiers_.begin(); iter != specifiers_.end(); iter++) {
72             *iter = std::get<ir::AstNode *>(cb(*iter))->AsExportSpecifier();
73         }
74     }
75 }
76 
77 }  // namespace panda::es2panda::ir
78