• 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_JSDOC_ALLOWED_H
17 #define ES2PANDA_IR_JSDOC_ALLOWED_H
18 
19 #include "ir/astNode.h"
20 #include "ir/statement.h"
21 
22 namespace ark::es2panda::ir {
23 
24 struct JsDocRecord {
25     util::StringView name;     // NOLINT(misc-non-private-member-variables-in-classes)
26     util::StringView param;    // NOLINT(misc-non-private-member-variables-in-classes)
27     util::StringView comment;  // NOLINT(misc-non-private-member-variables-in-classes)
28 
JsDocRecordJsDocRecord29     JsDocRecord(util::StringView initName, util::StringView initParam, util::StringView initComment)
30         : name(initName), param(initParam), comment(initComment)
31     {
32     }
33 };
34 
35 using JsDocInfo = ArenaUnorderedMap<util::StringView, JsDocRecord>;
36 
37 template <typename T>
38 class JsDocAllowed : public T {
39 public:
40     JsDocAllowed() = delete;
41     ~JsDocAllowed() override = default;
42 
43     NO_COPY_OPERATOR(JsDocAllowed);
44     NO_MOVE_SEMANTIC(JsDocAllowed);
45 
JsDocInformation()46     [[nodiscard]] ArenaVector<JsDocInfo> &JsDocInformation() noexcept
47     {
48         return jsDocInformation_;
49     }
50 
JsDocInformation()51     [[nodiscard]] const ArenaVector<JsDocInfo> &JsDocInformation() const noexcept
52     {
53         return jsDocInformation_;
54     }
55 
SetJsDocInformation(ArenaVector<JsDocInfo> && jsDocInformation)56     void SetJsDocInformation(ArenaVector<JsDocInfo> &&jsDocInformation)
57     {
58         jsDocInformation_ = std::move(jsDocInformation);
59     }
60 
61 protected:
JsDocAllowed(Expression const & other,ArenaAllocator * allocator)62     explicit JsDocAllowed(Expression const &other, ArenaAllocator *allocator)
63         : T(other, allocator), jsDocInformation_(allocator->Adapter())
64     {
65     }
66 
JsDocAllowed(ArenaAllocator * const allocator,AstNodeType const type,ArenaVector<AnnotationUsage * > && annotations)67     explicit JsDocAllowed(ArenaAllocator *const allocator, AstNodeType const type,
68                           ArenaVector<AnnotationUsage *> &&annotations)
69         : T(type, std::move(annotations)), jsDocInformation_(allocator->Adapter())
70     {
71     }
72 
JsDocAllowed(AstNodeType const type,ModifierFlags const flags,ArenaVector<AnnotationUsage * > && annotations,ArenaVector<JsDocInfo> && jsDocInformation)73     explicit JsDocAllowed(AstNodeType const type, ModifierFlags const flags,
74                           ArenaVector<AnnotationUsage *> &&annotations, ArenaVector<JsDocInfo> &&jsDocInformation)
75         : T(type, flags, std::move(annotations)), jsDocInformation_(std::move(jsDocInformation))
76     {
77     }
78 
JsDocAllowed(AstNodeType const type,ArenaAllocator * const allocator)79     explicit JsDocAllowed(AstNodeType const type, ArenaAllocator *const allocator)
80         : T(type, allocator), jsDocInformation_(allocator->Adapter())
81     {
82     }
83 
JsDocAllowed(AstNodeType const type,ModifierFlags const flags,ArenaAllocator * const allocator)84     explicit JsDocAllowed(AstNodeType const type, ModifierFlags const flags, ArenaAllocator *const allocator)
85         : T(type, flags, allocator), jsDocInformation_(allocator->Adapter())
86     {
87     }
88 
JsDocAllowed(AstNodeType const type,Expression * const key,Expression * const value,ModifierFlags const modifiers,ArenaAllocator * const allocator,bool const isComputed)89     explicit JsDocAllowed(AstNodeType const type, Expression *const key, Expression *const value,
90                           ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const isComputed)
91         : T(type, key, value, modifiers, allocator, isComputed), jsDocInformation_(allocator->Adapter())
92     {
93     }
94 
JsDocAllowed(AstNodeType const type,TypeNode * typeAnnotation,ArenaAllocator * const allocator)95     explicit JsDocAllowed(AstNodeType const type, TypeNode *typeAnnotation,
96                           [[maybe_unused]] ArenaAllocator *const allocator)
97         : T(type, typeAnnotation), jsDocInformation_(allocator->Adapter())
98     {
99     }
100 
JsDocAllowed(ArenaAllocator * const allocator,AstNodeType const type)101     explicit JsDocAllowed(ArenaAllocator *const allocator, AstNodeType const type)
102         : T(type), jsDocInformation_(allocator->Adapter())
103     {
104     }
105 
JsDocAllowed(ArenaAllocator * allocator,ArenaVector<Statement * > && statements)106     explicit JsDocAllowed(ArenaAllocator *allocator, ArenaVector<Statement *> &&statements)
107         : T(allocator, std::move(statements)), jsDocInformation_(allocator->Adapter())
108     {
109     }
110 
JsDocAllowed(const JsDocAllowed & other)111     JsDocAllowed(const JsDocAllowed &other)
112         : T(static_cast<const T &>(other)), jsDocInformation_(other.jsDocInformation_)
113     {
114     }
115 
JsDocAllowed(JsDocAllowed const & other,ArenaAllocator * const allocator)116     JsDocAllowed(JsDocAllowed const &other, ArenaAllocator *const allocator)
117         : T(static_cast<T const &>(other)), jsDocInformation_(allocator->Adapter())
118     {
119     }
120 
CopyTo(AstNode * other)121     void CopyTo(AstNode *other) const override
122     {
123         auto otherImpl = static_cast<JsDocAllowed<T> *>(other);
124         otherImpl->jsDocInformation_ = jsDocInformation_;
125         T::CopyTo(other);
126     }
127 
128 private:
129     friend class SizeOfNodeTest;
130     ArenaVector<JsDocInfo> jsDocInformation_;
131 };
132 }  // namespace ark::es2panda::ir
133 
134 #endif
135