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_TS_TYPE_ALIAS_DECLARATION_H 17 #define ES2PANDA_IR_TS_TYPE_ALIAS_DECLARATION_H 18 19 #include "ir/statement.h" 20 21 namespace panda::es2panda::varbinder { 22 class Variable; 23 } // namespace panda::es2panda::varbinder 24 25 namespace panda::es2panda::ir { 26 class Identifier; 27 class TSTypeParameterDeclaration; 28 29 class TSTypeAliasDeclaration : public AnnotatedStatement { 30 public: TSTypeAliasDeclaration(ArenaAllocator * allocator,Identifier * id,TSTypeParameterDeclaration * typeParams,TypeNode * typeAnnotation,bool declare)31 explicit TSTypeAliasDeclaration(ArenaAllocator *allocator, Identifier *id, TSTypeParameterDeclaration *typeParams, 32 TypeNode *typeAnnotation, bool declare) 33 : AnnotatedStatement(AstNodeType::TS_TYPE_ALIAS_DECLARATION, typeAnnotation), 34 decorators_(allocator->Adapter()), 35 id_(id), 36 typeParams_(typeParams), 37 typeParamTypes_(allocator->Adapter()), 38 declare_(declare) 39 { 40 } 41 TSTypeAliasDeclaration(ArenaAllocator * allocator,Identifier * id)42 explicit TSTypeAliasDeclaration(ArenaAllocator *allocator, Identifier *id) 43 : AnnotatedStatement(AstNodeType::TS_TYPE_ALIAS_DECLARATION), 44 decorators_(allocator->Adapter()), 45 id_(id), 46 typeParams_(nullptr), 47 typeParamTypes_(allocator->Adapter()), 48 declare_(false) 49 { 50 } 51 Id()52 Identifier *Id() 53 { 54 return id_; 55 } 56 Id()57 const Identifier *Id() const 58 { 59 return id_; 60 } 61 TypeParams()62 TSTypeParameterDeclaration *TypeParams() const 63 { 64 return typeParams_; 65 } 66 Declare()67 bool Declare() const 68 { 69 return declare_; 70 } 71 Decorators()72 const ArenaVector<Decorator *> &Decorators() const 73 { 74 return decorators_; 75 } 76 DecoratorsPtr()77 const ArenaVector<Decorator *> *DecoratorsPtr() const override 78 { 79 return &Decorators(); 80 } 81 SetTypeParameters(ir::TSTypeParameterDeclaration * typeParams)82 void SetTypeParameters(ir::TSTypeParameterDeclaration *typeParams) 83 { 84 typeParams_ = typeParams; 85 } 86 AddDecorators(ArenaVector<ir::Decorator * > && decorators)87 void AddDecorators([[maybe_unused]] ArenaVector<ir::Decorator *> &&decorators) override 88 { 89 decorators_ = std::move(decorators); 90 } 91 CanHaveDecorator(bool inTs)92 bool CanHaveDecorator([[maybe_unused]] bool inTs) const override 93 { 94 return !inTs; 95 } 96 SetTypeParameterTypes(ArenaVector<checker::Type * > && typeParamTypes)97 void SetTypeParameterTypes(ArenaVector<checker::Type *> &&typeParamTypes) 98 { 99 typeParamTypes_ = std::move(typeParamTypes); 100 } 101 TypeParameterTypes()102 ArenaVector<checker::Type *> const &TypeParameterTypes() const 103 { 104 return typeParamTypes_; 105 } 106 107 void TransformChildren(const NodeTransformer &cb) override; 108 void Iterate(const NodeTraverser &cb) const override; 109 void Dump(ir::AstDumper *dumper) const override; 110 void Dump(ir::SrcDumper *dumper) const override; 111 void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; 112 void Compile(compiler::ETSGen *etsg) const override; 113 checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; 114 checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; 115 Accept(ASTVisitorT * v)116 void Accept(ASTVisitorT *v) override 117 { 118 v->Accept(this); 119 } 120 121 private: 122 ArenaVector<Decorator *> decorators_; 123 Identifier *id_; 124 TSTypeParameterDeclaration *typeParams_; 125 ArenaVector<checker::Type *> typeParamTypes_; 126 bool declare_; 127 }; 128 } // namespace panda::es2panda::ir 129 130 #endif 131