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_IR_TS_ENUM_DECLARATION_H
17#define ES2PANDA_IR_TS_ENUM_DECLARATION_H
18
19#include <ir/statement.h>
20#include <binder/enumMemberResult.h>
21
22namespace panda::es2panda::binder {
23class LocalScope;
24class EnumVariable;
25}  // namespace panda::es2panda::binder
26
27namespace panda::es2panda::compiler {
28class PandaGen;
29}  // namespace panda::es2panda::compiler
30
31namespace panda::es2panda::checker {
32class Checker;
33class Type;
34}  // namespace panda::es2panda::checker
35
36namespace panda::es2panda::ir {
37
38class Identifier;
39class TSEnumMember;
40
41class TSEnumDeclaration : public Statement {
42public:
43    explicit TSEnumDeclaration(binder::TSEnumScope *scope, Identifier *key, ArenaVector<TSEnumMember *> &&members,
44                               bool isExport, bool isDeclare, bool isConst)
45        : Statement(AstNodeType::TS_ENUM_DECLARATION),
46          scope_(scope),
47          key_(key),
48          members_(std::move(members)),
49          isExport_(isExport),
50          isDeclare_(isDeclare),
51          isConst_(isConst)
52    {
53    }
54
55    binder::TSEnumScope *Scope() const
56    {
57        return scope_;
58    }
59
60    const Identifier *Key() const
61    {
62        return key_;
63    }
64
65    const ArenaVector<TSEnumMember *> &Members() const
66    {
67        return members_;
68    }
69
70    bool IsExport() const
71    {
72        return isExport_;
73    }
74
75    bool IsDeclare() const
76    {
77        return isDeclare_;
78    }
79
80    bool IsConst() const
81    {
82        return isConst_;
83    }
84
85    static binder::EnumMemberResult EvaluateEnumMember(checker::Checker *checker, binder::EnumVariable *enumVar,
86                                                       const ir::AstNode *expr);
87    checker::Type *InferType(checker::Checker *checker, bool isConst) const;
88
89    void Iterate(const NodeTraverser &cb) const override;
90    void Dump(ir::AstDumper *dumper) const override;
91    void Compile([[maybe_unused]] compiler::PandaGen *pg) const override;
92    checker::Type *Check(checker::Checker *checker) const override;
93    void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override;
94
95private:
96    binder::TSEnumScope *scope_;
97    Identifier *key_;
98    ArenaVector<TSEnumMember *> members_;
99    bool isExport_;
100    bool isDeclare_;
101    bool isConst_;
102};
103
104}  // namespace panda::es2panda::ir
105
106#endif
107