1 /** 2 * Copyright (c) 2021-2025 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 IsScopeBearer()31 [[nodiscard]] bool IsScopeBearer() const noexcept override 32 { 33 return true; 34 } 35 Scope()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 ES2PANDA_ASSERT(scope_ == nullptr); 44 scope_ = scope; 45 } 46 ClearScope()47 void ClearScope() noexcept override 48 { 49 scope_ = nullptr; 50 } 51 TransformChildren(const NodeTransformer & cb,std::string_view const transformationName)52 void TransformChildren([[maybe_unused]] const NodeTransformer &cb, 53 [[maybe_unused]] std::string_view const transformationName) override 54 { 55 ES2PANDA_UNREACHABLE(); 56 } 57 Iterate(const NodeTraverser & cb)58 void Iterate([[maybe_unused]] const NodeTraverser &cb) const override 59 { 60 ES2PANDA_UNREACHABLE(); 61 } 62 Dump(AstDumper * dumper)63 void Dump([[maybe_unused]] AstDumper *dumper) const override 64 { 65 ES2PANDA_UNREACHABLE(); 66 } 67 Compile(compiler::PandaGen * pg)68 void Compile([[maybe_unused]] compiler::PandaGen *pg) const override 69 { 70 ES2PANDA_UNREACHABLE(); 71 } 72 Check(checker::TSChecker * checker)73 checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override 74 { 75 ES2PANDA_UNREACHABLE(); 76 return nullptr; 77 } 78 79 checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; 80 81 protected: LoopStatement(AstNodeType type)82 explicit LoopStatement(AstNodeType type) : Statement(type) {} 83 84 private: 85 varbinder::LoopScope *scope_ {nullptr}; 86 }; 87 } // namespace ark::es2panda::ir 88 89 #endif 90