• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 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_UTIL_INCLUDE_TS_ENUM_DECLARATION_BUILDER
17 #define ES2PANDA_UTIL_INCLUDE_TS_ENUM_DECLARATION_BUILDER
18 
19 #include "ir/ts/tsEnumDeclaration.h"
20 #include "mem/arena_allocator.h"
21 #include "astBuilder.h"
22 
23 namespace ark::es2panda::ir {
24 
25 class TSEnumDeclarationBuilder : public AstBuilder {
26 public:
TSEnumDeclarationBuilder(ark::ArenaAllocator * allocator)27     explicit TSEnumDeclarationBuilder(ark::ArenaAllocator *allocator)
28         : AstBuilder(allocator), members_(allocator->Adapter())
29     {
30     }
31 
SetParent(AstNode * const parent)32     TSEnumDeclarationBuilder &SetParent(AstNode *const parent)
33     {
34         parent_ = parent;
35         return *this;
36     }
37 
SetKey(Identifier * key)38     TSEnumDeclarationBuilder &SetKey(Identifier *key)
39     {
40         key_ = key;
41         return *this;
42     }
43 
AddMember(TSEnumMember * member)44     TSEnumDeclarationBuilder &AddMember(TSEnumMember *member)
45     {
46         members_.emplace_back(member);
47         return *this;
48     }
49 
SetIsStatic(bool isStatic)50     TSEnumDeclarationBuilder &SetIsStatic(bool isStatic)
51     {
52         isStatic_ = isStatic;
53         return *this;
54     }
55 
SetIsDeclare(bool isDeclare)56     TSEnumDeclarationBuilder &SetIsDeclare(bool isDeclare)
57     {
58         isDeclare_ = isDeclare;
59         return *this;
60     }
61 
SetIsConst(bool isConst)62     TSEnumDeclarationBuilder &SetIsConst(bool isConst)
63     {
64         isConst_ = isConst;
65         return *this;
66     }
67 
Build()68     TSEnumDeclaration *Build()
69     {
70         auto node =
71             AllocNode<ir::TSEnumDeclaration>(Allocator(), key_, std::move(members_),
72                                              ir::TSEnumDeclaration::ConstructorFlags {isConst_, isStatic_, isDeclare_});
73         return node;
74     }
75 
76 private:
77     AstNode *parent_ {};
78     Identifier *key_ {};
79     ArenaVector<AstNode *> members_;
80     bool isConst_ = false;
81     bool isStatic_ = false;
82     bool isDeclare_ = false;
83 };
84 
85 }  // namespace ark::es2panda::ir
86 #endif  // ES2PANDA_UTIL_INCLUDE_TS_ENUM_DECLARATION_BUILDER