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_ETS_STRUCT_DECLARATION_H 17 #define ES2PANDA_IR_ETS_STRUCT_DECLARATION_H 18 19 #include "ir/statement.h" 20 21 namespace ark::es2panda::ir { 22 class ETSStructDeclaration : public Statement { 23 public: 24 ETSStructDeclaration() = delete; 25 ~ETSStructDeclaration() override = default; 26 27 NO_COPY_SEMANTIC(ETSStructDeclaration); 28 NO_MOVE_SEMANTIC(ETSStructDeclaration); 29 ETSStructDeclaration(ClassDefinition *const def, ArenaAllocator *const allocator)30 explicit ETSStructDeclaration(ClassDefinition *const def, ArenaAllocator *const allocator) 31 : Statement(AstNodeType::STRUCT_DECLARATION), def_(def), decorators_(allocator->Adapter()) 32 { 33 } 34 35 [[nodiscard]] ClassDefinition *Definition() noexcept 36 { 37 return def_; 38 } 39 40 [[nodiscard]] const ClassDefinition *Definition() const noexcept 41 { 42 return def_; 43 } 44 45 [[nodiscard]] const ArenaVector<Decorator *> &Decorators() const noexcept 46 { 47 return decorators_; 48 } 49 50 const ArenaVector<Decorator *> *DecoratorsPtr() const override 51 { 52 return &Decorators(); 53 } 54 55 void AddDecorators(ArenaVector<Decorator *> &&decorators) override 56 { 57 decorators_ = std::move(decorators); 58 } 59 AddDecorator(Decorator *const decorator)60 void AddDecorator(Decorator *const decorator) 61 { 62 decorators_.emplace_back(decorator); 63 } 64 65 bool CanHaveDecorator([[maybe_unused]] bool inTs) const override 66 { 67 return true; 68 } 69 70 [[nodiscard]] ETSStructDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent) override; 71 72 void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; 73 void Iterate(const NodeTraverser &cb) const override; 74 75 void Dump(ir::AstDumper *dumper) const override; 76 void Dump(ir::SrcDumper *dumper) const override; 77 void Compile(compiler::PandaGen *pg) const override; 78 void Compile(compiler::ETSGen *etsg) const override; 79 80 checker::Type *Check(checker::TSChecker *checker) override; 81 checker::Type *Check(checker::ETSChecker *checker) override; 82 83 void Accept(ASTVisitorT *v) override 84 { 85 v->Accept(this); 86 } 87 88 private: 89 ClassDefinition *def_; 90 ArenaVector<Decorator *> decorators_; 91 }; 92 } // namespace ark::es2panda::ir 93 94 #endif 95