• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 - 2023 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 
21 namespace panda::es2panda::ir {
22 class Expression;
23 
24 class ClassElement : public TypedStatement {
25 public:
26     ClassElement() = delete;
27     ~ClassElement() override = default;
28 
29     NO_COPY_SEMANTIC(ClassElement);
30     NO_MOVE_SEMANTIC(ClassElement);
31 
ClassElement(AstNodeType const elementType,Expression * const key,Expression * const value,ModifierFlags const modifiers,ArenaAllocator * const allocator,bool const isComputed)32     explicit ClassElement(AstNodeType const elementType, Expression *const key, Expression *const value,
33                           ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const isComputed)
34         : TypedStatement(elementType, modifiers),
35           key_(key),
36           value_(value),
37           decorators_(allocator->Adapter()),
38           isComputed_(isComputed)
39     {
40     }
41 
42     [[nodiscard]] Identifier *Id() noexcept;
43 
44     [[nodiscard]] const Identifier *Id() const noexcept;
45 
Key()46     [[nodiscard]] Expression *Key() noexcept
47     {
48         return key_;
49     }
50 
Key()51     [[nodiscard]] const Expression *Key() const noexcept
52     {
53         return key_;
54     }
55 
Value()56     [[nodiscard]] Expression *Value() noexcept
57     {
58         return value_;
59     }
60 
Value()61     [[nodiscard]] const Expression *Value() const noexcept
62     {
63         return value_;
64     }
65 
66     [[nodiscard]] bool IsPrivateElement() const noexcept;
67 
Decorators()68     [[nodiscard]] const ArenaVector<Decorator *> &Decorators() const noexcept
69     {
70         return decorators_;
71     }
72 
DecoratorsPtr()73     const ArenaVector<Decorator *> *DecoratorsPtr() const override
74     {
75         return &Decorators();
76     }
77 
IsComputed()78     [[nodiscard]] bool IsComputed() const noexcept
79     {
80         return isComputed_;
81     }
82 
AddDecorators(ArenaVector<ir::Decorator * > && decorators)83     void AddDecorators([[maybe_unused]] ArenaVector<ir::Decorator *> &&decorators) override
84     {
85         decorators_ = std::move(decorators);
86     }
87 
AddDecorator(ir::Decorator * const decorator)88     void AddDecorator(ir::Decorator *const decorator)
89     {
90         if (decorator != nullptr) {
91             decorators_.emplace_back(decorator);
92         }
93     }
94 
CanHaveDecorator(bool inTs)95     bool CanHaveDecorator([[maybe_unused]] bool inTs) const override
96     {
97         return true;
98     }
99 
100     [[nodiscard]] virtual PrivateFieldKind ToPrivateFieldKind(bool isStatic) const = 0;
101 
102 protected:
103     // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
104     Expression *key_;
105     Expression *value_;
106     ArenaVector<Decorator *> decorators_;
107     bool isComputed_;
108     // NOLINTEND(misc-non-private-member-variables-in-classes)
109 };
110 }  // namespace panda::es2panda::ir
111 
112 #endif
113