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) noexcept 32 { 33 declNode_ = decl; 34 } 35 GetDeclNode()36 [[nodiscard]] ir::TSTypeParameter *GetDeclNode() const noexcept 37 { 38 return declNode_; 39 } 40 41 [[nodiscard]] ETSTypeParameter *GetOriginal() const noexcept; 42 [[nodiscard]] util::StringView const &Name() const noexcept; 43 SetDefaultType(Type * type)44 void SetDefaultType(Type *type) noexcept 45 { 46 default_ = type; 47 } 48 GetDefaultType()49 [[nodiscard]] Type *GetDefaultType() const noexcept 50 { 51 return default_; 52 } 53 SetConstraintType(Type * type)54 void SetConstraintType(Type *type) noexcept 55 { 56 constraint_ = type; 57 } 58 GetConstraintType()59 [[nodiscard]] Type *GetConstraintType() const 60 { 61 ASSERT(constraint_ != nullptr); 62 return constraint_; 63 } 64 65 void ToString(std::stringstream &ss, bool precise) const override; 66 void Identical(TypeRelation *relation, Type *other) override; 67 void AssignmentTarget(TypeRelation *relation, Type *source) override; 68 bool AssignmentSource(TypeRelation *relation, Type *target) override; 69 void Cast(TypeRelation *relation, Type *target) override; 70 void CastTarget(TypeRelation *relation, Type *source) override; 71 void IsSupertypeOf(TypeRelation *relation, Type *source) override; 72 void IsSubtypeOf(TypeRelation *relation, Type *target) override; 73 Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; 74 Type *Substitute(TypeRelation *relation, const Substitution *substitution) override; 75 76 void ToAssemblerType(std::stringstream &ss) const override; 77 void ToDebugInfoType(std::stringstream &ss) const override; 78 79 private: 80 ir::TSTypeParameter *declNode_ {}; 81 Type *default_ {}; 82 Type *constraint_ {}; 83 }; 84 } // namespace ark::es2panda::checker 85 86 #endif 87