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 24namespace ark::es2panda::ir { 25class AstNode; 26class Identifier; 27} // namespace ark::es2panda::ir 28 29namespace ark::es2panda::compiler { 30class LabelTarget; 31class CodeGen; 32 33enum class ControlFlowChange { 34 CONTINUE, 35 BREAK, 36}; 37 38class LabelTarget : public LabelPair { 39public: 40 explicit LabelTarget(CodeGen *cg); 41 explicit LabelTarget(const util::StringView &label) : LabelTarget(nullptr, label) {} 42 explicit LabelTarget(Label *target, const util::StringView &label) 43 : LabelPair(target, nullptr), breakLabel_(label), continueLabel_(label) 44 { 45 } 46 LabelTarget() : LabelPair(nullptr, nullptr) {}; 47 48 ~LabelTarget() = default; 49 DEFAULT_COPY_SEMANTIC(LabelTarget); 50 DEFAULT_MOVE_SEMANTIC(LabelTarget); 51 52 const util::StringView &BreakLabel() const 53 { 54 return breakLabel_; 55 } 56 57 Label *BreakTarget() const 58 { 59 return begin_; 60 } 61 62 void SetBreakTarget(Label *label) 63 { 64 begin_ = label; 65 } 66 67 const util::StringView &ContinueLabel() const 68 { 69 return continueLabel_; 70 } 71 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 80private: 81 util::StringView breakLabel_ {}; 82 util::StringView continueLabel_ {}; 83}; 84} // namespace ark::es2panda::compiler 85 86#endif 87