1 /** 2 * Copyright (c) 2021-2025 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_ETS_TYPE_ALIAS_TYPE_H 17 #define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_ETS_TYPE_ALIAS_TYPE_H 18 19 #include "checker/types/ets/etsObjectType.h" 20 #include "checker/types/typeMapping.h" 21 22 namespace ark::es2panda::checker { 23 class ETSTypeAliasType : public Type { 24 public: 25 using InstantiationMap = ArenaUnorderedMap<util::StringView, ETSTypeAliasType *>; 26 27 explicit ETSTypeAliasType(ETSChecker *checker, util::StringView name, const ir::AstNode *declNode, 28 bool isRecursive = false); 29 TypeName()30 util::StringView TypeName() 31 { 32 return name_; 33 } 34 GetTargetType()35 Type *GetTargetType() 36 { 37 return targetType_; 38 } 39 GetDeclNode()40 const ir::AstNode *GetDeclNode() const 41 { 42 return declNode_; 43 } 44 GetTargetType()45 const Type *GetTargetType() const 46 { 47 ES2PANDA_ASSERT(targetType_ != nullptr); 48 return targetType_; 49 } 50 SetTargetType(Type * targetType)51 void SetTargetType(Type *targetType) 52 { 53 targetType_ = targetType; 54 } 55 ResolveConditionExpr()56 std::tuple<bool, bool> ResolveConditionExpr() const override 57 { 58 return {false, false}; 59 } 60 61 void SetRecursive(bool value = true) 62 { 63 isRecursive_ = value; 64 } 65 IsRecursive()66 bool IsRecursive() const 67 { 68 return isRecursive_; 69 } 70 71 void ToString(std::stringstream &ss, bool precise) const override; 72 73 void ToAssemblerType(std::stringstream &ss) const override; 74 void ToAssemblerTypeWithRank(std::stringstream &ss) const override; 75 void ToDebugInfoType(std::stringstream &ss) const override; 76 77 void Identical(TypeRelation *relation, Type *other) override; 78 void AssignmentTarget(TypeRelation *relation, Type *source) override; 79 bool AssignmentSource(TypeRelation *relation, Type *target) override; 80 void Cast(TypeRelation *relation, Type *target) override; 81 void CastTarget(TypeRelation *relation, Type *source) override; 82 void IsSupertypeOf(TypeRelation *relation, Type *source) override; 83 void IsSubtypeOf(TypeRelation *relation, Type *target) override; 84 Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; 85 86 uint32_t Rank() const override; 87 88 Type *Substitute(TypeRelation *relation, const Substitution *substitution) override; 89 90 void SetTypeArguments(ArenaVector<Type *> typeArguments); 91 92 private: 93 ETSTypeAliasType *GetInstantiatedType(util::StringView hash); 94 void EmplaceInstantiatedType(util::StringView hash, ETSTypeAliasType *emplaceType); 95 bool SubstituteTypeArgs(TypeRelation *const relation, ArenaVector<Type *> &newTypeArgs, 96 const Substitution *const substitution); 97 98 bool IsArgumentsIdentical(TypeRelation *relation, Type *other); 99 GetBaseType()100 ETSTypeAliasType *GetBaseType() 101 { 102 return base_ == nullptr ? this : base_; 103 } 104 105 util::StringView name_; 106 const ir::AstNode *declNode_; 107 bool isRecursive_; 108 ETSTypeAliasType *base_ = nullptr; 109 ETSTypeAliasType *parent_ = nullptr; 110 Type *targetType_ = nullptr; 111 InstantiationMap instantiationMap_; 112 ArenaVector<Type *> typeArguments_; 113 const Substitution *substitution_ = nullptr; 114 mutable bool recursionCount_ = false; 115 }; 116 } // namespace ark::es2panda::checker 117 118 #endif /* ES2PANDA_COMPILER_CHECKER_TYPES_ETS_ETS_RECURSIVE_TYPE_H */ 119