1/**
2 * Copyright (c) 2021-2022 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_BASE_CATCH_TABLE_H
17#define ES2PANDA_COMPILER_BASE_CATCH_TABLE_H
18
19#include <ir/irnode.h>
20#include <compiler/core/labelPair.h>
21
22namespace panda::es2panda::compiler {
23
24class PandaGen;
25
26class TryLabelSet {
27public:
28    explicit TryLabelSet(PandaGen *pg);
29
30    ~TryLabelSet() = default;
31    DEFAULT_COPY_SEMANTIC(TryLabelSet);
32    DEFAULT_MOVE_SEMANTIC(TryLabelSet);
33
34    const LabelPair &TryLabelPair() const
35    {
36        return try_;
37    }
38
39    const LabelPair &CatchLabelPair() const
40    {
41        return catch_;
42    }
43
44    Label *TryBegin() const
45    {
46        return try_.Begin();
47    }
48
49    Label *TryEnd() const
50    {
51        return try_.End();
52    }
53
54    Label *CatchBegin() const
55    {
56        return catch_.Begin();
57    }
58
59    Label *CatchEnd() const
60    {
61        return catch_.End();
62    }
63
64private:
65    LabelPair try_;
66    LabelPair catch_;
67};
68
69class CatchTable {
70public:
71    CatchTable(PandaGen *pg, uint32_t depth) : labelSet_(pg), depth_(depth) {}
72
73    ~CatchTable() = default;
74    NO_COPY_SEMANTIC(CatchTable);
75    NO_MOVE_SEMANTIC(CatchTable);
76
77    const TryLabelSet &LabelSet() const
78    {
79        return labelSet_;
80    }
81
82    uint32_t Depth() const
83    {
84        return depth_;
85    }
86
87private:
88    TryLabelSet labelSet_;
89    uint32_t depth_;
90};
91
92}  // namespace panda::es2panda::compiler
93
94#endif
95