1 /** 2 * Copyright (c) 2023-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_ETS_TUPLE_H 17 #define ES2PANDA_IR_ETS_TUPLE_H 18 19 #include "ir/typeNode.h" 20 21 namespace panda::es2panda::ir { 22 23 class ETSTuple : public TypeNode { 24 public: 25 using TupleSizeType = uint32_t; 26 ETSTuple(ArenaAllocator * const allocator)27 explicit ETSTuple(ArenaAllocator *const allocator) 28 : TypeNode(AstNodeType::ETS_TUPLE), typeAnnotationList_(allocator->Adapter()) 29 { 30 } 31 ETSTuple(ArenaAllocator * const allocator,const TupleSizeType size)32 explicit ETSTuple(ArenaAllocator *const allocator, const TupleSizeType size) 33 : TypeNode(AstNodeType::ETS_TUPLE), typeAnnotationList_(allocator->Adapter()), size_(size) 34 { 35 } ETSTuple(const ArenaVector<ir::TypeNode * > & typeList)36 explicit ETSTuple(const ArenaVector<ir::TypeNode *> &typeList) 37 : TypeNode(AstNodeType::ETS_TUPLE), 38 typeAnnotationList_(typeList), 39 size_(static_cast<TupleSizeType>(typeList.size())) 40 { 41 } 42 GetTupleSize()43 [[nodiscard]] TupleSizeType GetTupleSize() const 44 { 45 return size_; 46 } 47 GetTupleTypeAnnotationsList()48 [[nodiscard]] ArenaVector<ir::TypeNode *> GetTupleTypeAnnotationsList() const 49 { 50 return typeAnnotationList_; 51 } 52 HasSpreadType()53 [[nodiscard]] bool HasSpreadType() const 54 { 55 return spreadType_ != nullptr; 56 } 57 SetSpreadType(TypeNode * const newSpreadType)58 void SetSpreadType(TypeNode *const newSpreadType) 59 { 60 spreadType_ = newSpreadType; 61 } 62 SetTypeAnnotationsList(const ArenaVector<TypeNode * > & typeNodeList)63 void SetTypeAnnotationsList(const ArenaVector<TypeNode *> &typeNodeList) 64 { 65 typeAnnotationList_ = typeNodeList; 66 } 67 68 void TransformChildren(const NodeTransformer &cb) override; 69 void Iterate(const NodeTraverser &cb) const override; 70 void Dump(ir::AstDumper *dumper) const override; 71 void Dump(ir::SrcDumper *dumper) const override; 72 void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; 73 void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; 74 checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; 75 checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; 76 checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; 77 78 void SetNullUndefinedFlags(std::pair<bool, bool> &containsNullOrUndefined, const checker::Type *type); 79 checker::Type *CalculateLUBForTuple(checker::ETSChecker *checker, ArenaVector<checker::Type *> &typeList, 80 checker::Type *spreadType); 81 Accept(ASTVisitorT * v)82 void Accept(ASTVisitorT *v) override 83 { 84 v->Accept(this); 85 } 86 87 private: 88 ArenaVector<TypeNode *> typeAnnotationList_; 89 TypeNode *spreadType_ {}; 90 TupleSizeType size_ {0}; 91 }; 92 93 } // namespace panda::es2panda::ir 94 95 #endif /* ES2PANDA_IR_ETS_TUPLE_H */ 96