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