• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021 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 panda::es2panda::ir {
25 class AstNode;
26 class Identifier;
27 }  // namespace panda::es2panda::ir
28 
29 namespace panda::es2panda::compiler {
30 
31 class LabelTarget;
32 class PandaGen;
33 
34 enum class ControlFlowChange {
35     CONTINUE,
36     BREAK,
37 };
38 
39 class LabelTarget : public LabelPair {
40 public:
41     explicit LabelTarget(PandaGen *pg);
LabelTarget(const util::StringView & label)42     explicit LabelTarget(const util::StringView &label) : LabelTarget(nullptr, label) {}
LabelTarget(Label * target,const util::StringView & label)43     explicit LabelTarget(Label *target, const util::StringView &label)
44         : LabelPair(target, nullptr), breakLabel_(label), continueLabel_(label)
45     {
46     }
LabelTarget()47     LabelTarget() : LabelPair(nullptr, nullptr) {};
48 
49     ~LabelTarget() = default;
50     DEFAULT_COPY_SEMANTIC(LabelTarget);
51     DEFAULT_MOVE_SEMANTIC(LabelTarget);
52 
BreakLabel()53     const util::StringView &BreakLabel() const
54     {
55         return breakLabel_;
56     }
57 
BreakTarget()58     Label *BreakTarget() const
59     {
60         return begin_;
61     }
62 
SetBreakTarget(Label * label)63     void SetBreakTarget(Label *label)
64     {
65         begin_ = label;
66     }
67 
ContinueLabel()68     const util::StringView &ContinueLabel() const
69     {
70         return continueLabel_;
71     }
72 
ContinueTarget()73     Label *ContinueTarget() const
74     {
75         return end_;
76     }
77 
78     static constexpr std::string_view BREAK_LABEL = "#b";
79     static constexpr std::string_view CONTINUE_LABEL = "#c";
80     static constexpr std::string_view RETURN_LABEL = "#r";
81 
82 private:
83     util::StringView breakLabel_ {};
84     util::StringView continueLabel_ {};
85 };
86 
87 }  // namespace panda::es2panda::compiler
88 
89 #endif
90