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_PARAMETER_H 17 #define ES2PANDA_IR_TS_TYPE_PARAMETER_H 18 19 #include "ir/expression.h" 20 21 namespace ark::es2panda::ir { 22 class Identifier; 23 24 class TSTypeParameter : public Expression { 25 public: TSTypeParameter(Identifier * name,TypeNode * constraint,TypeNode * defaultType)26 explicit TSTypeParameter(Identifier *name, TypeNode *constraint, TypeNode *defaultType) 27 : Expression(AstNodeType::TS_TYPE_PARAMETER), name_(name), constraint_(constraint), defaultType_(defaultType) 28 { 29 } 30 TSTypeParameter(Identifier * name,TypeNode * constraint,TypeNode * defaultType,ModifierFlags flags)31 explicit TSTypeParameter(Identifier *name, TypeNode *constraint, TypeNode *defaultType, ModifierFlags flags) 32 : Expression(AstNodeType::TS_TYPE_PARAMETER, flags), 33 name_(name), 34 constraint_(constraint), 35 defaultType_(defaultType) 36 { 37 ASSERT(flags == ModifierFlags::NONE || flags == ModifierFlags::IN || flags == ModifierFlags::OUT); 38 } 39 Name()40 const Identifier *Name() const 41 { 42 return name_; 43 } 44 Name()45 Identifier *Name() 46 { 47 return name_; 48 } 49 Constraint()50 TypeNode *Constraint() 51 { 52 return constraint_; 53 } 54 Constraint()55 const TypeNode *Constraint() const 56 { 57 return constraint_; 58 } 59 SetConstraint(TypeNode * constraint)60 void SetConstraint(TypeNode *constraint) 61 { 62 constraint_ = constraint; 63 } 64 DefaultType()65 TypeNode *DefaultType() const 66 { 67 return defaultType_; 68 } 69 SetDefaultType(TypeNode * defaultType)70 void SetDefaultType(TypeNode *defaultType) 71 { 72 defaultType_ = defaultType; 73 } 74 75 void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; 76 void Iterate(const NodeTraverser &cb) const override; 77 void Dump(ir::AstDumper *dumper) const override; 78 void Dump(ir::SrcDumper *dumper) const override; 79 void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; 80 void Compile(compiler::ETSGen *etsg) const override; 81 checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; 82 checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; 83 Accept(ASTVisitorT * v)84 void Accept(ASTVisitorT *v) override 85 { 86 v->Accept(this); 87 } 88 89 private: 90 Identifier *name_; 91 TypeNode *constraint_; 92 TypeNode *defaultType_; 93 }; 94 } // namespace ark::es2panda::ir 95 96 #endif 97