1 /** 2 * Copyright (c) 2023-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_TUPLE_TYPE_H 17 #define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_TUPLE_TYPE_H 18 19 #include "checker/ETSchecker.h" 20 #include "checker/types/type.h" 21 22 namespace ark::es2panda::checker { 23 24 class ETSTupleType : public Type { 25 using TupleSizeType = std::size_t; 26 27 public: ETSTupleType(ETSChecker * checker,const ArenaVector<Type * > & typeList)28 explicit ETSTupleType(ETSChecker *checker, const ArenaVector<Type *> &typeList) 29 : Type(checker::TypeFlag::ETS_TUPLE), 30 typeList_(typeList), 31 // NOLINTNEXTLINE(readability-implicit-bool-conversion) 32 wrapperType_(checker->GlobalBuiltinTupleType(typeList_.size()) != nullptr 33 ? checker->GlobalBuiltinTupleType(typeList_.size())->AsETSObjectType() 34 : nullptr) 35 { 36 typeFlags_ |= TypeFlag::ETS_TUPLE; 37 } 38 GetTupleSize()39 [[nodiscard]] TupleSizeType GetTupleSize() const 40 { 41 return typeList_.size(); 42 } 43 GetTupleTypesList()44 [[nodiscard]] ArenaVector<Type *> const &GetTupleTypesList() const 45 { 46 return typeList_; 47 } 48 ResolveConditionExpr()49 std::tuple<bool, bool> ResolveConditionExpr() const override 50 { 51 return {false, false}; 52 } 53 GetWrapperType()54 [[nodiscard]] ETSObjectType *GetWrapperType() const 55 { 56 return wrapperType_; 57 } 58 59 [[nodiscard]] Type *GetTypeAtIndex(TupleSizeType index) const; 60 61 void ToString(std::stringstream &ss, bool precise) const override; 62 63 void Identical(TypeRelation *relation, Type *other) override; 64 void AssignmentTarget(TypeRelation *relation, Type *source) override; 65 bool AssignmentSource(TypeRelation *relation, Type *target) override; 66 Type *Substitute(TypeRelation *relation, const Substitution *substitution) override; 67 void IsSubtypeOf(TypeRelation *relation, Type *target) override; 68 void Cast(TypeRelation *relation, Type *target) override; 69 Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; 70 void CheckVarianceRecursively(TypeRelation *relation, VarianceFlag varianceFlag) override; 71 72 void ToAssemblerType(std::stringstream &ss) const override; 73 void ToDebugInfoType(std::stringstream &ss) const override; 74 75 private: 76 bool CheckElementsIdentical(TypeRelation *relation, const ETSTupleType *other) const; 77 78 const ArenaVector<Type *> typeList_; 79 ETSObjectType *wrapperType_; 80 }; 81 82 } // namespace ark::es2panda::checker 83 84 #endif /* ES2PANDA_COMPILER_CHECKER_TYPES_ETS_TUPLE_TYPE_H */ 85