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_COMPILER_CORE_LABEL_TARGET_H 17 #define ES2PANDA_COMPILER_CORE_LABEL_TARGET_H 18 19 #include "ir/irnode.h" 20 #include "compiler/core/labelPair.h" 21 22 #include <unordered_map> 23 24 namespace ark::es2panda::ir { 25 class AstNode; 26 class Identifier; 27 } // namespace ark::es2panda::ir 28 29 namespace ark::es2panda::compiler { 30 class LabelTarget; 31 class CodeGen; 32 33 enum class ControlFlowChange { 34 CONTINUE, 35 BREAK, 36 }; 37 38 class LabelTarget : public LabelPair { 39 public: 40 explicit LabelTarget(CodeGen *cg); LabelTarget(const util::StringView & label)41 explicit LabelTarget(const util::StringView &label) : LabelTarget(nullptr, label) {} LabelTarget(Label * target,const util::StringView & label)42 explicit LabelTarget(Label *target, const util::StringView &label) 43 : LabelPair(target, nullptr), breakLabel_(label), continueLabel_(label) 44 { 45 } LabelTarget()46 LabelTarget() : LabelPair(nullptr, nullptr) {}; 47 48 ~LabelTarget() = default; 49 DEFAULT_COPY_SEMANTIC(LabelTarget); 50 DEFAULT_MOVE_SEMANTIC(LabelTarget); 51 BreakLabel()52 const util::StringView &BreakLabel() const 53 { 54 return breakLabel_; 55 } 56 BreakTarget()57 Label *BreakTarget() const 58 { 59 return begin_; 60 } 61 SetBreakTarget(Label * label)62 void SetBreakTarget(Label *label) 63 { 64 begin_ = label; 65 } 66 ContinueLabel()67 const util::StringView &ContinueLabel() const 68 { 69 return continueLabel_; 70 } 71 ContinueTarget()72 Label *ContinueTarget() const 73 { 74 return end_; 75 } 76 77 static constexpr std::string_view BREAK_LABEL = "#b"; 78 static constexpr std::string_view CONTINUE_LABEL = "#c"; 79 80 private: 81 util::StringView breakLabel_ {}; 82 util::StringView continueLabel_ {}; 83 }; 84 } // namespace ark::es2panda::compiler 85 86 #endif 87