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 #ifndef ES2PANDA_IR_MODULE_EXPORT_DECLARATION_H
17 #define ES2PANDA_IR_MODULE_EXPORT_DECLARATION_H
18 
19 #include <ir/module/assertClause.h>
20 #include <ir/statement.h>
21 
22 namespace panda::es2panda::compiler {
23 class PandaGen;
24 }  // namespace panda::es2panda::compiler
25 
26 namespace panda::es2panda::checker {
27 class Checker;
28 class Type;
29 }  // namespace panda::es2panda::checker
30 
31 namespace panda::es2panda::ir {
32 
33 class StringLiteral;
34 class ExportSpecifier;
35 
36 class ExportNamedDeclaration : public Statement {
37 public:
ExportNamedDeclaration(StringLiteral *source, ArenaVector<ExportSpecifier *> &&specifiers, AssertClause *assertClause, bool isType)38     explicit ExportNamedDeclaration(StringLiteral *source, ArenaVector<ExportSpecifier *> &&specifiers,
39                                     AssertClause *assertClause, bool isType)
40         : Statement(AstNodeType::EXPORT_NAMED_DECLARATION),
41           source_(source),
42           decl_(nullptr),
43           specifiers_(std::move(specifiers)),
44           assertClause_(assertClause),
45           isType_(isType)
46     {
47     }
48 
ExportNamedDeclaration(Statement *decl, ArenaVector<ExportSpecifier *> &&specifiers)49     explicit ExportNamedDeclaration(Statement *decl, ArenaVector<ExportSpecifier *> &&specifiers)
50         : Statement(AstNodeType::EXPORT_NAMED_DECLARATION),
51           source_(nullptr),
52           decl_(decl),
53           specifiers_(std::move(specifiers)),
54           assertClause_(nullptr),
55           isType_(false)
56     {
57     }
58 
Decl() const59     const Statement *Decl() const
60     {
61         return decl_;
62     }
63 
Decl()64     Statement *Decl()
65     {
66         return decl_;
67     }
68 
SetDecl(Statement *decl)69     void SetDecl(Statement *decl)
70     {
71         decl_ = decl;
72     }
73 
Source() const74     const StringLiteral *Source() const
75     {
76         return source_;
77     }
78 
Specifiers() const79     const ArenaVector<ExportSpecifier *> &Specifiers() const
80     {
81         return specifiers_;
82     }
83 
IsType() const84     bool IsType() const
85     {
86         return isType_;
87     }
88 
89     void Iterate(const NodeTraverser &cb) const override;
90     void Dump(ir::AstDumper *dumper) const override;
91     void Compile(compiler::PandaGen *pg) const override;
92     checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override;
93     void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override;
94 
95 private:
96     StringLiteral *source_;
97     Statement *decl_;
98     ArenaVector<ExportSpecifier *> specifiers_;
99     AssertClause *assertClause_;
100     bool isType_;
101 };
102 
103 }  // namespace panda::es2panda::ir
104 
105 #endif
106