• 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_IR_STATEMENT_ANNOTATION_DECLARATION_H
17 #define ES2PANDA_IR_STATEMENT_ANNOTATION_DECLARATION_H
18 
19 #include "varbinder/scope.h"
20 #include "varbinder/variable.h"
21 #include "ir/statement.h"
22 #include "ir/astNode.h"
23 #include "ir/expressions/identifier.h"
24 
25 namespace ark::es2panda::ir {
26 class AnnotationDeclaration : public Statement {
27 public:
AnnotationDeclaration(Expression * expr,ArenaAllocator * allocator)28     explicit AnnotationDeclaration(Expression *expr, ArenaAllocator *allocator)
29         : Statement(AstNodeType::ANNOTATION_DECLARATION), expr_(expr), properties_(allocator->Adapter())
30     {
31     }
AnnotationDeclaration(Expression * expr,ArenaVector<AstNode * > && properties)32     explicit AnnotationDeclaration(Expression *expr, ArenaVector<AstNode *> &&properties)
33         : Statement(AstNodeType::ANNOTATION_DECLARATION), expr_(expr), properties_(std::move(properties))
34     {
35     }
36 
InternalName()37     const util::StringView &InternalName() const
38     {
39         return internalName_;
40     }
41 
SetInternalName(util::StringView internalName)42     void SetInternalName(util::StringView internalName)
43     {
44         internalName_ = internalName;
45     }
46 
Expr()47     [[nodiscard]] const Expression *Expr() const noexcept
48     {
49         return expr_;
50     }
51 
Expr()52     [[nodiscard]] Expression *Expr() noexcept
53     {
54         return expr_;
55     }
56 
Properties()57     [[nodiscard]] ArenaVector<AstNode *> &Properties() noexcept
58     {
59         return properties_;
60     }
61 
Properties()62     [[nodiscard]] const ArenaVector<AstNode *> &Properties() const noexcept
63     {
64         return properties_;
65     }
66 
PropertiesPtr()67     [[nodiscard]] const ArenaVector<AstNode *> *PropertiesPtr() const
68     {
69         return &Properties();
70     }
71 
AddProperties(ArenaVector<AstNode * > && properties)72     void AddProperties(ArenaVector<AstNode *> &&properties)
73     {
74         properties_ = std::move(properties);
75     }
76 
77     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
78     void Iterate(const NodeTraverser &cb) const override;
79     void Dump(ir::AstDumper *dumper) const override;
80     void Dump(ir::SrcDumper *dumper) const override;
81     void Compile(compiler::PandaGen *pg) const override;
82     void Compile(compiler::ETSGen *etsg) const override;
83     checker::Type *Check(checker::TSChecker *checker) override;
84     checker::Type *Check(checker::ETSChecker *checker) override;
85 
Accept(ASTVisitorT * v)86     void Accept(ASTVisitorT *v) override
87     {
88         v->Accept(this);
89     }
90 
IsScopeBearer()91     [[nodiscard]] bool IsScopeBearer() const noexcept override
92     {
93         return true;
94     }
95 
Scope()96     [[nodiscard]] varbinder::LocalScope *Scope() const noexcept override
97     {
98         return scope_;
99     }
100 
SetScope(varbinder::LocalScope * scope)101     void SetScope(varbinder::LocalScope *scope)
102     {
103         ASSERT(scope_ == nullptr);
104         scope_ = scope;
105     }
106 
ClearScope()107     void ClearScope() noexcept override
108     {
109         scope_ = nullptr;
110     }
111 
112     Identifier *GetBaseName() const;
113 
114 private:
115     util::StringView internalName_ {};
116     varbinder::LocalScope *scope_ {};
117     Expression *expr_;
118     ArenaVector<AstNode *> properties_;
119 };
120 }  // namespace ark::es2panda::ir
121 
122 #endif