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_COMPILER_CHECKER_TYPES_ETS_TYPE_PARAMETER_TYPE_H 17 #define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_TYPE_PARAMETER_TYPE_H 18 19 #include "checker/types/type.h" 20 #include "ir/astNode.h" 21 22 namespace ark::es2panda::checker { 23 class ETSTypeParameter : public Type { 24 public: ETSTypeParameter()25 explicit ETSTypeParameter() : Type(TypeFlag::ETS_TYPE_PARAMETER) {} ETSTypeParameter(Type * defaultType,Type * constraintType)26 explicit ETSTypeParameter(Type *defaultType, Type *constraintType) 27 : Type(TypeFlag::ETS_TYPE_PARAMETER), default_(defaultType), constraint_(constraintType) 28 { 29 } 30 SetDeclNode(ir::TSTypeParameter * decl)31 void SetDeclNode(ir::TSTypeParameter *decl) 32 { 33 declNode_ = decl; 34 } 35 GetDeclNode()36 ir::TSTypeParameter *GetDeclNode() const 37 { 38 return declNode_; 39 } 40 41 ETSTypeParameter *GetOriginal() const; 42 SetDefaultType(Type * type)43 void SetDefaultType(Type *type) 44 { 45 default_ = type; 46 } 47 GetDefaultType()48 Type *GetDefaultType() const 49 { 50 return default_; 51 } 52 SetConstraintType(Type * type)53 void SetConstraintType(Type *type) 54 { 55 constraint_ = type; 56 } 57 GetConstraintType()58 Type *GetConstraintType() const 59 { 60 ASSERT(constraint_ != nullptr); 61 return constraint_; 62 } 63 64 void ToString(std::stringstream &ss, bool precise) const override; 65 void Identical(TypeRelation *relation, Type *other) override; 66 void AssignmentTarget(TypeRelation *relation, Type *source) override; 67 bool AssignmentSource(TypeRelation *relation, Type *target) override; 68 void Cast(TypeRelation *relation, Type *target) override; 69 void CastTarget(TypeRelation *relation, Type *source) override; 70 void IsSupertypeOf(TypeRelation *relation, Type *source) override; 71 void IsSubtypeOf(TypeRelation *relation, Type *target) override; 72 Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; 73 Type *Substitute(TypeRelation *relation, const Substitution *substitution) override; 74 75 void ToAssemblerType(std::stringstream &ss) const override; 76 void ToDebugInfoType(std::stringstream &ss) const override; 77 78 private: 79 ir::TSTypeParameter *declNode_ {}; 80 Type *default_ {}; 81 Type *constraint_ {}; 82 }; 83 } // namespace ark::es2panda::checker 84 85 #endif 86