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