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_CLASS_DECLARATION_H 17 #define ES2PANDA_IR_STATEMENT_CLASS_DECLARATION_H 18 19 #include "ir/statement.h" 20 21 namespace ark::es2panda::ir { 22 class ClassDeclaration : public Statement { 23 public: ClassDeclaration(ClassDefinition *def, ArenaAllocator *allocator)24 explicit ClassDeclaration(ClassDefinition *def, ArenaAllocator *allocator) 25 : Statement(AstNodeType::CLASS_DECLARATION), def_(def), decorators_(allocator->Adapter()) 26 { 27 } 28 Definition()29 ClassDefinition *Definition() 30 { 31 return def_; 32 } 33 Definition() const34 const ClassDefinition *Definition() const 35 { 36 return def_; 37 } 38 Decorators() const39 const ArenaVector<Decorator *> &Decorators() const 40 { 41 return decorators_; 42 } 43 44 const ArenaVector<Decorator *> *DecoratorsPtr() const override 45 { 46 return &Decorators(); 47 } 48 49 void AddDecorators(ArenaVector<Decorator *> &&decorators) override 50 { 51 decorators_ = std::move(decorators); 52 } 53 54 bool CanHaveDecorator([[maybe_unused]] bool inTs) const override 55 { 56 return true; 57 } 58 59 void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; 60 void Iterate(const NodeTraverser &cb) const override; 61 void Dump(ir::AstDumper *dumper) const override; 62 void Dump(ir::SrcDumper *dumper) const override; 63 void Compile(compiler::PandaGen *pg) const override; 64 void Compile(compiler::ETSGen *etsg) const override; 65 66 checker::Type *Check(checker::TSChecker *checker) override; 67 checker::Type *Check(checker::ETSChecker *checker) override; 68 69 void Accept(ASTVisitorT *v) override 70 { 71 v->Accept(this); 72 } 73 74 private: 75 ClassDefinition *def_; 76 ArenaVector<Decorator *> decorators_; 77 }; 78 } // namespace ark::es2panda::ir 79 80 #endif 81