• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 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_IR_ANNOTATION_ALLOWED_H
17 #define ES2PANDA_IR_ANNOTATION_ALLOWED_H
18 
19 #include "ir/astNode.h"
20 #include "ir/statement.h"
21 #include "ir/statements/annotationUsage.h"
22 
23 namespace ark::es2panda::ir {
24 
25 template <typename T>
26 class AnnotationAllowed : public T {
27 public:
28     AnnotationAllowed() = delete;
29     ~AnnotationAllowed() override = default;
30 
31     NO_COPY_OPERATOR(AnnotationAllowed);
32     NO_MOVE_SEMANTIC(AnnotationAllowed);
33 
Annotations()34     [[nodiscard]] ArenaVector<ir::AnnotationUsage *> &Annotations() noexcept
35     {
36         return annotations_;
37     }
38 
Annotations()39     [[nodiscard]] const ArenaVector<ir::AnnotationUsage *> &Annotations() const noexcept
40     {
41         return annotations_;
42     }
43 
SetAnnotations(ArenaVector<ir::AnnotationUsage * > && annotations)44     void SetAnnotations(ArenaVector<ir::AnnotationUsage *> &&annotations)
45     {
46         annotations_ = std::move(annotations);
47         for (ir::AnnotationUsage *anno : annotations_) {
48             anno->SetParent(this);
49         }
50     }
51 
52 protected:
AnnotationAllowed(Expression const & other,ArenaAllocator * allocator)53     explicit AnnotationAllowed(Expression const &other, ArenaAllocator *allocator)
54         : T(other), annotations_(allocator->Adapter())
55     {
56     }
AnnotationAllowed(AstNodeType const type,ArenaVector<AnnotationUsage * > && annotations)57     explicit AnnotationAllowed(AstNodeType const type, ArenaVector<AnnotationUsage *> &&annotations)
58         : T(type), annotations_(std::move(annotations))
59     {
60     }
AnnotationAllowed(AstNodeType const type,ModifierFlags const flags,ArenaVector<AnnotationUsage * > && annotations)61     explicit AnnotationAllowed(AstNodeType const type, ModifierFlags const flags,
62                                ArenaVector<AnnotationUsage *> &&annotations)
63         : T(type, flags), annotations_(std::move(annotations))
64     {
65     }
AnnotationAllowed(AstNodeType const type,ArenaAllocator * const allocator)66     explicit AnnotationAllowed(AstNodeType const type, ArenaAllocator *const allocator)
67         : T(type), annotations_(allocator->Adapter())
68     {
69     }
AnnotationAllowed(AstNodeType const type,ModifierFlags const flags,ArenaAllocator * const allocator)70     explicit AnnotationAllowed(AstNodeType const type, ModifierFlags const flags, ArenaAllocator *const allocator)
71         : T(type, flags), annotations_(allocator->Adapter())
72     {
73     }
AnnotationAllowed(AstNodeType const type,Expression * const key,Expression * const value,ModifierFlags const modifiers,ArenaAllocator * const allocator,bool const isComputed)74     explicit AnnotationAllowed(AstNodeType const type, Expression *const key, Expression *const value,
75                                ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const isComputed)
76         : T(type, key, value, modifiers, allocator, isComputed), annotations_(allocator->Adapter())
77     {
78     }
79 
AnnotationAllowed(ArenaAllocator * const allocator,ArenaVector<Statement * > && statementList)80     explicit AnnotationAllowed(ArenaAllocator *const allocator, ArenaVector<Statement *> &&statementList)
81         : T(allocator, std::move(statementList)), annotations_(allocator->Adapter())
82     {
83     }
84 
AddAnnotations(AnnotationUsage * const annotations)85     void AddAnnotations(AnnotationUsage *const annotations)
86     {
87         annotations_.emplace_back(annotations);
88     }
89 
AnnotationAllowed(AnnotationAllowed const & other)90     AnnotationAllowed(AnnotationAllowed const &other)
91         : T(static_cast<T const &>(other)), annotations_(other.annotations_.get_allocator())
92     {
93     }
94 
CopyTo(AstNode * other)95     void CopyTo(AstNode *other) const override
96     {
97         auto otherImpl = static_cast<AnnotationAllowed<T> *>(other);
98         otherImpl->annotations_ = annotations_;
99         T::CopyTo(other);
100     }
101 
102 private:
103     friend class SizeOfNodeTest;
104     ArenaVector<AnnotationUsage *> annotations_;
105 };
106 }  // namespace ark::es2panda::ir
107 
108 #endif
109