• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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 = uint32_t;
27 
ETSTuple(ArenaAllocator * const allocator)28     explicit ETSTuple(ArenaAllocator *const allocator)
29         : TypeNode(AstNodeType::ETS_TUPLE), 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), typeAnnotationList_(allocator->Adapter()), size_(size)
35     {
36     }
ETSTuple(const ArenaVector<ir::TypeNode * > & typeList)37     explicit ETSTuple(const ArenaVector<ir::TypeNode *> &typeList)
38         : TypeNode(AstNodeType::ETS_TUPLE),
39           typeAnnotationList_(typeList),
40           size_(static_cast<TupleSizeType>(typeList.size()))
41     {
42     }
43 
GetTupleSize()44     [[nodiscard]] TupleSizeType GetTupleSize() const
45     {
46         return size_;
47     }
48 
GetTupleTypeAnnotationsList()49     [[nodiscard]] ArenaVector<ir::TypeNode *> GetTupleTypeAnnotationsList() const
50     {
51         return typeAnnotationList_;
52     }
53 
HasSpreadType()54     [[nodiscard]] bool HasSpreadType() const
55     {
56         return spreadType_ != nullptr;
57     }
58 
SetSpreadType(TypeNode * const newSpreadType)59     void SetSpreadType(TypeNode *const newSpreadType)
60     {
61         spreadType_ = newSpreadType;
62     }
63 
SetTypeAnnotationsList(ArenaVector<TypeNode * > && typeNodeList)64     void SetTypeAnnotationsList(ArenaVector<TypeNode *> &&typeNodeList)
65     {
66         typeAnnotationList_ = std::move(typeNodeList);
67     }
68 
69     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
70     void Iterate(const NodeTraverser &cb) const override;
71     void Dump(ir::AstDumper *dumper) const override;
72     void Dump(ir::SrcDumper *dumper) const override;
73     void Compile([[maybe_unused]] compiler::PandaGen *pg) const override;
74     void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override;
75     checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override;
76     checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override;
77     checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override;
78 
Accept(ASTVisitorT * v)79     void Accept(ASTVisitorT *v) override
80     {
81         v->Accept(this);
82     }
83 
84     // NOTE(vpukhov): hide in TypeCreation
85     static checker::Type *CalculateLUBForTuple(checker::ETSChecker *checker, ArenaVector<checker::Type *> &typeList,
86                                                checker::Type **spreadTypePtr);
87 
88     [[nodiscard]] ETSTuple *Clone(ArenaAllocator *allocator, AstNode *parent) override;
89 
90 private:
91     ArenaVector<TypeNode *> typeAnnotationList_;
92     TypeNode *spreadType_ {};
93     TupleSizeType size_ {0};
94 };
95 
96 }  // namespace ark::es2panda::ir
97 
98 #endif /* ES2PANDA_IR_ETS_TUPLE_H */
99