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_COMPILER_CORE_REG_SCOPE_H 17 #define ES2PANDA_COMPILER_CORE_REG_SCOPE_H 18 19 #include "util/es2pandaMacros.h" 20 #include "varbinder/scope.h" 21 #include "vReg.h" 22 23 namespace ark::es2panda::ir { 24 class AstNode; 25 } // namespace ark::es2panda::ir 26 27 namespace ark::es2panda::compiler { 28 class EnvScope; 29 class PandaGen; 30 class CodeGen; 31 32 class RegScope { 33 public: 34 explicit RegScope(CodeGen *cg); 35 NO_COPY_SEMANTIC(RegScope); 36 NO_MOVE_SEMANTIC(RegScope); 37 ~RegScope(); 38 39 void *operator new(size_t) = delete; 40 void *operator new[](size_t) = delete; 41 42 protected: 43 void DebuggerCloseScope(); 44 45 // NOLINTBEGIN(misc-non-private-member-variables-in-classes) 46 CodeGen *cg_; 47 uint32_t regBase_; 48 // NOLINTEND(misc-non-private-member-variables-in-classes) 49 }; 50 51 class LocalRegScope : public RegScope { 52 public: 53 explicit LocalRegScope(PandaGen *pg, varbinder::Scope *scope); 54 explicit LocalRegScope(CodeGen *cg, varbinder::Scope *scope); 55 explicit LocalRegScope(PandaGen *pg); 56 NO_COPY_SEMANTIC(LocalRegScope); 57 NO_MOVE_SEMANTIC(LocalRegScope); 58 ~LocalRegScope(); 59 60 void *operator new(size_t) = delete; 61 void *operator new[](size_t) = delete; 62 63 private: 64 varbinder::Scope *prevScope_ {}; 65 }; 66 67 class LoopRegScope : public RegScope { 68 public: 69 explicit LoopRegScope(PandaGen *pg, varbinder::LoopScope *scope); 70 NO_COPY_SEMANTIC(LoopRegScope); 71 NO_MOVE_SEMANTIC(LoopRegScope); 72 ~LoopRegScope(); 73 74 void *operator new(size_t) = delete; 75 void *operator new[](size_t) = delete; 76 77 private: 78 varbinder::Scope *prevScope_ {}; 79 }; 80 81 class FunctionRegScope : public RegScope { 82 public: 83 explicit FunctionRegScope(CodeGen *cg); 84 explicit FunctionRegScope(PandaGen *pg); 85 NO_COPY_SEMANTIC(FunctionRegScope); 86 NO_MOVE_SEMANTIC(FunctionRegScope); 87 ~FunctionRegScope(); 88 89 void *operator new(size_t) = delete; 90 void *operator new[](size_t) = delete; 91 92 private: 93 using StoreParamCb = std::function<void(varbinder::LocalVariable *, VReg)>; 94 void InitializeParams(const StoreParamCb &cb); 95 EnvScope *envScope_ {}; 96 }; 97 } // namespace ark::es2panda::compiler 98 99 #endif 100