• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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_PARSER_INCLUDE_AST_CLASS_ELEMENT_H
17 #define ES2PANDA_PARSER_INCLUDE_AST_CLASS_ELEMENT_H
18 
19 #include "ir/statement.h"
20 #include "ir/typed.h"
21 
22 namespace ark::es2panda::ir {
23 class Expression;
24 
25 class ClassElement : public TypedStatement {
26 public:
27     ClassElement() = delete;
28     ~ClassElement() override = default;
29 
30     NO_COPY_SEMANTIC(ClassElement);
31     NO_MOVE_SEMANTIC(ClassElement);
32     // CC-OFFNXT(G.FUN.01-CPP) solid logic
ClassElement(AstNodeType const elementType,Expression * const key,Expression * const value,ModifierFlags const modifiers,ArenaAllocator * const allocator,bool const isComputed)33     explicit ClassElement(AstNodeType const elementType, Expression *const key, Expression *const value,
34                           ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const isComputed)
35         : TypedStatement(elementType, modifiers),
36           key_(key),
37           value_(value),
38           decorators_(allocator->Adapter()),
39           isComputed_(isComputed)
40     {
41     }
42 
43     [[nodiscard]] Identifier *Id() noexcept;
44 
45     [[nodiscard]] const Identifier *Id() const noexcept;
46 
Key()47     [[nodiscard]] Expression *Key() noexcept
48     {
49         return key_;
50     }
51 
Key()52     [[nodiscard]] const Expression *Key() const noexcept
53     {
54         return key_;
55     }
56 
Value()57     [[nodiscard]] Expression *Value() noexcept
58     {
59         return value_;
60     }
61 
62     void SetValue(Expression *value) noexcept;
63 
Value()64     [[nodiscard]] const Expression *Value() const noexcept
65     {
66         return value_;
67     }
68 
OriginEnumMember()69     [[nodiscard]] const TSEnumMember *OriginEnumMember() const noexcept
70     {
71         return enumMember_;
72     }
73 
SetOrigEnumMember(ir::TSEnumMember * enumMember)74     void SetOrigEnumMember(ir::TSEnumMember *enumMember)
75     {
76         enumMember_ = enumMember;
77     }
78 
79     [[nodiscard]] bool IsPrivateElement() const noexcept;
80 
Decorators()81     [[nodiscard]] const ArenaVector<Decorator *> &Decorators() const noexcept
82     {
83         return decorators_;
84     }
85 
DecoratorsPtr()86     const ArenaVector<Decorator *> *DecoratorsPtr() const override
87     {
88         return &Decorators();
89     }
90 
IsComputed()91     [[nodiscard]] bool IsComputed() const noexcept
92     {
93         return isComputed_;
94     }
95 
AddDecorators(ArenaVector<ir::Decorator * > && decorators)96     void AddDecorators([[maybe_unused]] ArenaVector<ir::Decorator *> &&decorators) override
97     {
98         decorators_ = std::move(decorators);
99     }
100 
AddDecorator(ir::Decorator * const decorator)101     void AddDecorator(ir::Decorator *const decorator)
102     {
103         if (decorator != nullptr) {
104             decorators_.emplace_back(decorator);
105         }
106     }
107 
CanHaveDecorator(bool inTs)108     bool CanHaveDecorator([[maybe_unused]] bool inTs) const override
109     {
110         return true;
111     }
112 
113     [[nodiscard]] virtual PrivateFieldKind ToPrivateFieldKind(bool isStatic) const = 0;
114 
115     void CopyTo(AstNode *other) const override;
116 
117 protected:
118     friend class SizeOfNodeTest;
119     // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
120     Expression *key_;
121     Expression *value_;
122     ArenaVector<Decorator *> decorators_;
123     bool isComputed_;
124     TSEnumMember *enumMember_ {};
125     // NOLINTEND(misc-non-private-member-variables-in-classes)
126 };
127 }  // namespace ark::es2panda::ir
128 
129 #endif
130