• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-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_USAGE_H
17 #define ES2PANDA_IR_STATEMENT_ANNOTATION_USAGE_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/expression.h"
24 #include "ir/statements/annotationDeclaration.h"
25 
26 namespace ark::es2panda::ir {
27 class AnnotationUsage : public Statement {
28 public:
AnnotationUsage(Expression * expr,ArenaAllocator * allocator)29     explicit AnnotationUsage(Expression *expr, ArenaAllocator *allocator)
30         : Statement(AstNodeType::ANNOTATION_USAGE), expr_(expr), properties_(allocator->Adapter())
31     {
32     }
AnnotationUsage(Expression * expr,ArenaVector<AstNode * > && properties)33     explicit AnnotationUsage(Expression *expr, ArenaVector<AstNode *> &&properties)
34         : Statement(AstNodeType::ANNOTATION_USAGE), expr_(expr), properties_(std::move(properties))
35     {
36     }
37 
Expr()38     [[nodiscard]] Expression *Expr() noexcept
39     {
40         return expr_;
41     }
42 
Properties()43     [[nodiscard]] ArenaVector<AstNode *> &Properties() noexcept
44     {
45         return properties_;
46     }
47 
Properties()48     [[nodiscard]] const ArenaVector<AstNode *> &Properties() const noexcept
49     {
50         return properties_;
51     }
52 
PropertiesPtr()53     [[nodiscard]] const ArenaVector<AstNode *> *PropertiesPtr() const
54     {
55         return &Properties();
56     }
57 
AddProperty(AstNode * property)58     void AddProperty(AstNode *property)
59     {
60         properties_.emplace_back(property);
61     }
62 
SetProperties(ArenaVector<AstNode * > && properties)63     void SetProperties(ArenaVector<AstNode *> &&properties)
64     {
65         properties_ = std::move(properties);
66     }
67 
68     [[nodiscard]] AnnotationUsage *Clone(ArenaAllocator *allocator, AstNode *parent) override;
69     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
70     void Iterate(const NodeTraverser &cb) const override;
71     void Dump(ir::AstDumper *dumper) const override;
72     void Dump(ir::SrcDumper *dumper) const override;
73     void Compile(compiler::PandaGen *pg) const override;
74     void Compile(compiler::ETSGen *etsg) const override;
75     checker::Type *Check(checker::TSChecker *checker) override;
76     checker::Type *Check(checker::ETSChecker *checker) override;
77 
Accept(ASTVisitorT * v)78     void Accept(ASTVisitorT *v) override
79     {
80         v->Accept(this);
81     }
82 
IsScopeBearer()83     [[nodiscard]] bool IsScopeBearer() const noexcept override
84     {
85         return true;
86     }
87 
Scope()88     [[nodiscard]] varbinder::AnnotationParamScope *Scope() const noexcept override
89     {
90         return propertiesScope_;
91     }
92 
SetScope(varbinder::AnnotationParamScope * scope)93     void SetScope(varbinder::AnnotationParamScope *scope)
94     {
95         ASSERT(propertiesScope_ == nullptr);
96         propertiesScope_ = scope;
97     }
98 
ClearScope()99     void ClearScope() noexcept override
100     {
101         propertiesScope_ = nullptr;
102     }
103 
104     Identifier *GetBaseName() const;
105 
106 private:
107     Expression *expr_;
108     ArenaVector<ir::AstNode *> properties_;
109     varbinder::AnnotationParamScope *propertiesScope_ {};
110 };
111 }  // namespace ark::es2panda::ir
112 
113 #endif