• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_RESIZABLE_ARRAY_TYPE_H
17 #define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_RESIZABLE_ARRAY_TYPE_H
18 
19 #include "checker/types/ets/etsObjectType.h"
20 #include "checker/types/ets/etsObjectTypeConstants.h"
21 
22 namespace ark::es2panda::checker {
23 
24 class ETSResizableArrayType : public ETSObjectType {
25 public:
ETSResizableArrayType(ArenaAllocator * allocator,ETSObjectType * super)26     explicit ETSResizableArrayType(ArenaAllocator *allocator, ETSObjectType *super)
27         : ETSObjectType(allocator, "", compiler::Signatures::BUILTIN_ARRAY, nullptr,
28                         ETSObjectFlags::CLASS | ETSObjectFlags::BUILTIN_ARRAY | ETSObjectFlags::RESOLVED_SUPER),
29           element_(nullptr)
30     {
31         SetSuperType(super);
32     }
33 
ETSResizableArrayType(ArenaAllocator * allocator,util::StringView name,std::tuple<ir::AstNode *,ETSObjectFlags,TypeRelation * > info)34     explicit ETSResizableArrayType(ArenaAllocator *allocator, util::StringView name,
35                                    std::tuple<ir::AstNode *, ETSObjectFlags, TypeRelation *> info)
36         : ETSObjectType(allocator, name, compiler::Signatures::BUILTIN_ARRAY, info), element_(nullptr)
37     {
38     }
39 
ETSResizableArrayType(ArenaAllocator * allocator,ETSObjectType * super,TypeRelation * relation,Type * element)40     explicit ETSResizableArrayType(ArenaAllocator *allocator, ETSObjectType *super, TypeRelation *relation,
41                                    Type *element)
42         : ETSObjectType(
43               allocator, "", compiler::Signatures::BUILTIN_ARRAY,
44               std::make_tuple(nullptr,
45                               ETSObjectFlags::CLASS | ETSObjectFlags::BUILTIN_ARRAY | ETSObjectFlags::RESOLVED_SUPER,
46                               relation)),
47           element_(element)
48     {
49         SetSuperType(super);
50         variable_ = super->Variable();
51     }
52 
53     NO_COPY_SEMANTIC(ETSResizableArrayType);
54     NO_MOVE_SEMANTIC(ETSResizableArrayType);
55 
56     ETSResizableArrayType() = delete;
57     ~ETSResizableArrayType() override = default;
58 
ElementType()59     Type *ElementType()
60     {
61         if (element_ == nullptr) {
62             element_ = TypeArguments()[0];
63         }
64         return element_;
65     }
66 
ElementType()67     const Type *ElementType() const
68     {
69         return TypeArguments()[0];
70     }
71 
SetElementType(Type * element)72     void SetElementType(Type *element)
73     {
74         element_ = element;
75     }
76 
77     ETSResizableArrayType *Substitute(TypeRelation *relation, const Substitution *substitution) override;
78 
79 private:
80     Type *element_;
81 };
82 
83 }  // namespace ark::es2panda::checker
84 
85 #endif