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_IR_ETS_TUPLE_H 17 #define ES2PANDA_IR_ETS_TUPLE_H 18 19 #include "checker/ETSchecker.h" 20 #include "ir/typeNode.h" 21 22 namespace ark::es2panda::ir { 23 24 class ETSTuple : public TypeNode { 25 public: 26 using TupleSizeType = std::size_t; 27 ETSTuple(ArenaAllocator * const allocator)28 explicit ETSTuple(ArenaAllocator *const allocator) 29 : TypeNode(AstNodeType::ETS_TUPLE, allocator), typeAnnotationList_(allocator->Adapter()) 30 { 31 } 32 ETSTuple(ArenaAllocator * const allocator,const TupleSizeType size)33 explicit ETSTuple(ArenaAllocator *const allocator, const TupleSizeType size) 34 : TypeNode(AstNodeType::ETS_TUPLE, allocator), typeAnnotationList_(allocator->Adapter()), size_(size) 35 { 36 } ETSTuple(const ArenaVector<ir::TypeNode * > & typeList,ArenaAllocator * const allocator)37 explicit ETSTuple(const ArenaVector<ir::TypeNode *> &typeList, ArenaAllocator *const allocator) 38 : TypeNode(AstNodeType::ETS_TUPLE, allocator), typeAnnotationList_(typeList), size_(typeList.size()) 39 { 40 } 41 GetTupleSize()42 [[nodiscard]] TupleSizeType GetTupleSize() const 43 { 44 return size_; 45 } 46 GetTupleTypeAnnotationsList()47 [[nodiscard]] ArenaVector<ir::TypeNode *> &GetTupleTypeAnnotationsList() 48 { 49 return typeAnnotationList_; 50 } 51 GetTupleTypeAnnotationsList()52 [[nodiscard]] const ArenaVector<ir::TypeNode *> &GetTupleTypeAnnotationsList() const noexcept 53 { 54 return typeAnnotationList_; 55 } 56 SetTypeAnnotationsList(ArenaVector<TypeNode * > && typeNodeList)57 void SetTypeAnnotationsList(ArenaVector<TypeNode *> &&typeNodeList) 58 { 59 typeAnnotationList_ = std::move(typeNodeList); 60 } 61 62 void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; 63 void Iterate(const NodeTraverser &cb) const override; 64 void Dump(ir::AstDumper *dumper) const override; 65 void Dump(ir::SrcDumper *dumper) const override; 66 void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; 67 void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; 68 checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; 69 checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; 70 [[nodiscard]] checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; 71 Accept(ASTVisitorT * v)72 void Accept(ASTVisitorT *v) override 73 { 74 v->Accept(this); 75 } 76 77 // NOTE(vpukhov): hide in TypeCreation 78 static checker::Type *GetHolderTypeForTuple(checker::ETSChecker *checker, ArenaVector<checker::Type *> &typeList); 79 80 [[nodiscard]] ETSTuple *Clone(ArenaAllocator *allocator, AstNode *parent) override; 81 82 private: 83 ArenaVector<TypeNode *> typeAnnotationList_; 84 TupleSizeType size_ {0}; 85 }; 86 87 } // namespace ark::es2panda::ir 88 89 #endif /* ES2PANDA_IR_ETS_TUPLE_H */ 90