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