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 #ifndef ES2PANDA_IR_STATEMENT_LOOP_STATEMENT_H
17 #define ES2PANDA_IR_STATEMENT_LOOP_STATEMENT_H
18 
19 #include "varbinder/scope.h"
20 #include "ir/statement.h"
21 
22 namespace ark::es2panda::ir {
23 class LoopStatement : public Statement {
24 public:
25     LoopStatement() = delete;
26     ~LoopStatement() override = default;
27 
28     NO_COPY_SEMANTIC(LoopStatement);
29     NO_MOVE_SEMANTIC(LoopStatement);
30 
31     [[nodiscard]] bool IsScopeBearer() const noexcept override
32     {
33         return true;
34     }
35 
36     [[nodiscard]] varbinder::LoopScope *Scope() const noexcept final
37     {
38         return scope_;
39     }
40 
SetScope(varbinder::LoopScope *scope)41     void SetScope(varbinder::LoopScope *scope)
42     {
43         ASSERT(scope_ == nullptr);
44         scope_ = scope;
45     }
46 
47     void ClearScope() noexcept override
48     {
49         scope_ = nullptr;
50     }
51 
52     void TransformChildren([[maybe_unused]] const NodeTransformer &cb,
53                            [[maybe_unused]] std::string_view const transformationName) override
54     {
55         UNREACHABLE();
56     }
57 
58     void Iterate([[maybe_unused]] const NodeTraverser &cb) const override
59     {
60         UNREACHABLE();
61     }
62 
63     void Dump([[maybe_unused]] AstDumper *dumper) const override
64     {
65         UNREACHABLE();
66     }
67 
68     void Compile([[maybe_unused]] compiler::PandaGen *pg) const override
69     {
70         UNREACHABLE();
71     }
72 
73     checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override
74     {
75         UNREACHABLE();
76         return nullptr;
77     }
78 
79     checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override
80     {
81         UNREACHABLE();
82         return nullptr;
83     }
84 
85 protected:
LoopStatement(AstNodeType type)86     explicit LoopStatement(AstNodeType type) : Statement(type) {}
87 
88 private:
89     varbinder::LoopScope *scope_ {nullptr};
90 };
91 }  // namespace ark::es2panda::ir
92 
93 #endif
94