• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021 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 #include "globalTypesHolder.h"
17 
18 #include <typescript/types/numberType.h>
19 #include <typescript/types/anyType.h>
20 #include <typescript/types/stringType.h>
21 #include <typescript/types/symbolType.h>
22 #include <typescript/types/booleanType.h>
23 #include <typescript/types/voidType.h>
24 #include <typescript/types/nullType.h>
25 #include <typescript/types/undefinedType.h>
26 #include <typescript/types/unknownType.h>
27 #include <typescript/types/neverType.h>
28 #include <typescript/types/nonPrimitiveType.h>
29 #include <typescript/types/bigintType.h>
30 #include <typescript/types/booleanLiteralType.h>
31 #include <typescript/types/bigintLiteralType.h>
32 #include <typescript/types/numberLiteralType.h>
33 #include <typescript/types/stringLiteralType.h>
34 #include <typescript/types/tupleType.h>
35 #include <typescript/types/objectLiteralType.h>
36 #include <typescript/types/unionType.h>
37 
38 namespace panda::es2panda::checker {
39 
GlobalTypesHolder(ArenaAllocator * allocator)40 GlobalTypesHolder::GlobalTypesHolder(ArenaAllocator *allocator)
41 {
42     globalTypes_[static_cast<size_t>(GlobalTypeId::NUMBER)] = allocator->New<NumberType>();
43     globalTypes_[static_cast<size_t>(GlobalTypeId::ANY)] = allocator->New<AnyType>();
44     globalTypes_[static_cast<size_t>(GlobalTypeId::STRING)] = allocator->New<StringType>();
45     globalTypes_[static_cast<size_t>(GlobalTypeId::SYMBOL)] = allocator->New<SymbolType>();
46     globalTypes_[static_cast<size_t>(GlobalTypeId::BOOLEAN)] = allocator->New<BooleanType>();
47     globalTypes_[static_cast<size_t>(GlobalTypeId::VOID)] = allocator->New<VoidType>();
48     globalTypes_[static_cast<size_t>(GlobalTypeId::NULL_ID)] = allocator->New<NullType>();
49     globalTypes_[static_cast<size_t>(GlobalTypeId::UNDEFINED)] = allocator->New<UndefinedType>();
50     globalTypes_[static_cast<size_t>(GlobalTypeId::UNKNOWN)] = allocator->New<UnknownType>();
51     globalTypes_[static_cast<size_t>(GlobalTypeId::NEVER)] = allocator->New<NeverType>();
52     globalTypes_[static_cast<size_t>(GlobalTypeId::NON_PRIMITIVE)] = allocator->New<NonPrimitiveType>();
53     globalTypes_[static_cast<size_t>(GlobalTypeId::BIGINT)] = allocator->New<BigintType>();
54     globalTypes_[static_cast<size_t>(GlobalTypeId::FALSE_ID)] = allocator->New<BooleanLiteralType>(false);
55     globalTypes_[static_cast<size_t>(GlobalTypeId::TRUE_ID)] = allocator->New<BooleanLiteralType>(true);
56     globalTypes_[static_cast<size_t>(GlobalTypeId::NUMBER_OR_BIGINT)] =
57         allocator->New<UnionType>(allocator, std::initializer_list<Type *> {GlobalNumberType(), GlobalBigintType()});
58     globalTypes_[static_cast<size_t>(GlobalTypeId::STRING_OR_NUMBER)] =
59         allocator->New<UnionType>(allocator, std::initializer_list<Type *> {GlobalStringType(), GlobalNumberType()});
60     globalTypes_[static_cast<size_t>(GlobalTypeId::ZERO)] = allocator->New<NumberLiteralType>(0);
61     globalTypes_[static_cast<size_t>(GlobalTypeId::EMPTY_STRING)] = allocator->New<StringLiteralType>("");
62     globalTypes_[static_cast<size_t>(GlobalTypeId::ZERO_BIGINT)] = allocator->New<BigintLiteralType>("0n", false);
63     globalTypes_[static_cast<size_t>(GlobalTypeId::PRIMITIVE)] = allocator->New<UnionType>(
64         allocator,
65         std::initializer_list<Type *> {GlobalNumberType(), GlobalStringType(), GlobalBigintType(), GlobalBooleanType(),
66                                        GlobalVoidType(), GlobalUndefinedType(), GlobalNullType(), GlobalSymbolType()});
67     globalTypes_[static_cast<size_t>(GlobalTypeId::EMPTY_TUPLE)] = allocator->New<TupleType>(allocator);
68     globalTypes_[static_cast<size_t>(GlobalTypeId::EMPTY_OBJECT)] = allocator->New<ObjectLiteralType>();
69     globalTypes_[static_cast<size_t>(GlobalTypeId::RESOLVING_RETURN_TYPE)] = allocator->New<AnyType>();
70     globalTypes_[static_cast<size_t>(GlobalTypeId::ERROR_TYPE)] = allocator->New<AnyType>();
71 }
72 
GlobalNumberType()73 Type *GlobalTypesHolder::GlobalNumberType()
74 {
75     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::NUMBER));
76 }
77 
GlobalAnyType()78 Type *GlobalTypesHolder::GlobalAnyType()
79 {
80     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::ANY));
81 }
82 
GlobalStringType()83 Type *GlobalTypesHolder::GlobalStringType()
84 {
85     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::STRING));
86 }
87 
GlobalSymbolType()88 Type *GlobalTypesHolder::GlobalSymbolType()
89 {
90     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::SYMBOL));
91 }
92 
GlobalBooleanType()93 Type *GlobalTypesHolder::GlobalBooleanType()
94 {
95     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::BOOLEAN));
96 }
97 
GlobalVoidType()98 Type *GlobalTypesHolder::GlobalVoidType()
99 {
100     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::VOID));
101 }
102 
GlobalNullType()103 Type *GlobalTypesHolder::GlobalNullType()
104 {
105     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::NULL_ID));
106 }
107 
GlobalUndefinedType()108 Type *GlobalTypesHolder::GlobalUndefinedType()
109 {
110     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::UNDEFINED));
111 }
112 
GlobalUnknownType()113 Type *GlobalTypesHolder::GlobalUnknownType()
114 {
115     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::UNKNOWN));
116 }
117 
GlobalNeverType()118 Type *GlobalTypesHolder::GlobalNeverType()
119 {
120     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::NEVER));
121 }
122 
GlobalNonPrimitiveType()123 Type *GlobalTypesHolder::GlobalNonPrimitiveType()
124 {
125     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::NON_PRIMITIVE));
126 }
127 
GlobalBigintType()128 Type *GlobalTypesHolder::GlobalBigintType()
129 {
130     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::BIGINT));
131 }
132 
GlobalFalseType()133 Type *GlobalTypesHolder::GlobalFalseType()
134 {
135     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::FALSE_ID));
136 }
137 
GlobalTrueType()138 Type *GlobalTypesHolder::GlobalTrueType()
139 {
140     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::TRUE_ID));
141 }
142 
GlobalNumberOrBigintType()143 Type *GlobalTypesHolder::GlobalNumberOrBigintType()
144 {
145     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::NUMBER_OR_BIGINT));
146 }
147 
GlobalStringOrNumberType()148 Type *GlobalTypesHolder::GlobalStringOrNumberType()
149 {
150     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::STRING_OR_NUMBER));
151 }
152 
GlobalZeroType()153 Type *GlobalTypesHolder::GlobalZeroType()
154 {
155     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::ZERO));
156 }
157 
GlobalEmptyStringType()158 Type *GlobalTypesHolder::GlobalEmptyStringType()
159 {
160     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::EMPTY_STRING));
161 }
162 
GlobalZeroBigintType()163 Type *GlobalTypesHolder::GlobalZeroBigintType()
164 {
165     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::ZERO_BIGINT));
166 }
167 
GlobalPrimitiveType()168 Type *GlobalTypesHolder::GlobalPrimitiveType()
169 {
170     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::PRIMITIVE));
171 }
172 
GlobalEmptyTupleType()173 Type *GlobalTypesHolder::GlobalEmptyTupleType()
174 {
175     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::EMPTY_TUPLE));
176 }
177 
GlobalEmptyObjectType()178 Type *GlobalTypesHolder::GlobalEmptyObjectType()
179 {
180     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::EMPTY_OBJECT));
181 }
182 
GlobalResolvingReturnType()183 Type *GlobalTypesHolder::GlobalResolvingReturnType()
184 {
185     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::RESOLVING_RETURN_TYPE));
186 }
187 
GlobalErrorType()188 Type *GlobalTypesHolder::GlobalErrorType()
189 {
190     return globalTypes_.at(static_cast<size_t>(GlobalTypeId::ERROR_TYPE));
191 }
192 
193 }  // namespace panda::es2panda::checker
194