• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "etsNullishTypes.h"
17 #include "etsTypeParameter.h"
18 #include "ir/expressions/identifier.h"
19 #include "ir/ts/tsTypeParameter.h"
20 #include "checker/ETSchecker.h"
21 #include "checker/ets/conversion.h"
22 
23 namespace ark::es2panda::checker {
24 
Identical(TypeRelation * relation,Type * other)25 void ETSNullType::Identical(TypeRelation *relation, Type *other)
26 {
27     relation->Result(other->IsETSNullType());
28 }
29 
AssignmentTarget(TypeRelation * relation,Type * source)30 void ETSNullType::AssignmentTarget(TypeRelation *relation, Type *source)
31 {
32     Identical(relation, source);
33 }
34 
AssignmentSource(TypeRelation * relation,Type * target)35 bool ETSNullType::AssignmentSource(TypeRelation *relation, Type *target)
36 {
37     return relation->IsSupertypeOf(target, this);
38 }
39 
Compare(TypeRelation * relation,Type * other)40 void ETSNullType::Compare([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *other)
41 {
42     ES2PANDA_UNREACHABLE();
43 }
44 
Cast(TypeRelation * relation,Type * target)45 void ETSNullType::Cast(TypeRelation *relation, Type *target)
46 {
47     Identical(relation, target);
48 }
49 
CastTarget(TypeRelation * relation,Type * source)50 void ETSNullType::CastTarget(TypeRelation *relation, Type *source)
51 {
52     relation->IsSupertypeOf(source, this);
53 }
54 
ToString(std::stringstream & ss,bool precise) const55 void ETSNullType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const
56 {
57     ss << "null";
58 }
59 
ToAssemblerType(std::stringstream & ss) const60 void ETSNullType::ToAssemblerType(std::stringstream &ss) const
61 {
62     ss << compiler::Signatures::BUILTIN_OBJECT;
63 }
64 
ToDebugInfoType(std::stringstream & ss) const65 void ETSNullType::ToDebugInfoType(std::stringstream &ss) const
66 {
67     ss << ETSObjectType::NameToDescriptor(compiler::Signatures::BUILTIN_OBJECT);
68 }
69 
Instantiate(ArenaAllocator * allocator,TypeRelation * relation,GlobalTypesHolder * globalTypes)70 Type *ETSNullType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation,
71                                [[maybe_unused]] GlobalTypesHolder *globalTypes)
72 {
73     return allocator->New<ETSNullType>();
74 }
75 
Identical(TypeRelation * relation,Type * other)76 void ETSUndefinedType::Identical(TypeRelation *relation, Type *other)
77 {
78     relation->Result(other->IsETSUndefinedType());
79 }
80 
AssignmentTarget(TypeRelation * relation,Type * source)81 void ETSUndefinedType::AssignmentTarget(TypeRelation *relation, Type *source)
82 {
83     Identical(relation, source);
84 }
85 
AssignmentSource(TypeRelation * relation,Type * target)86 bool ETSUndefinedType::AssignmentSource(TypeRelation *relation, Type *target)
87 {
88     return relation->IsSupertypeOf(target, this);
89 }
90 
Compare(TypeRelation * relation,Type * other)91 void ETSUndefinedType::Compare([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *other)
92 {
93     ES2PANDA_UNREACHABLE();
94 }
95 
Cast(TypeRelation * relation,Type * target)96 void ETSUndefinedType::Cast(TypeRelation *relation, Type *target)
97 {
98     Identical(relation, target);
99 }
100 
CastTarget(TypeRelation * relation,Type * source)101 void ETSUndefinedType::CastTarget(TypeRelation *relation, Type *source)
102 {
103     relation->IsSupertypeOf(source, this);
104 }
105 
ToString(std::stringstream & ss,bool precise) const106 void ETSUndefinedType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const
107 {
108     ss << "undefined";
109 }
110 
ToAssemblerType(std::stringstream & ss) const111 void ETSUndefinedType::ToAssemblerType(std::stringstream &ss) const
112 {
113     ss << compiler::Signatures::BUILTIN_OBJECT;
114 }
115 
ToDebugInfoType(std::stringstream & ss) const116 void ETSUndefinedType::ToDebugInfoType(std::stringstream &ss) const
117 {
118     ss << ETSObjectType::NameToDescriptor(compiler::Signatures::BUILTIN_OBJECT);
119 }
120 
Instantiate(ArenaAllocator * allocator,TypeRelation * relation,GlobalTypesHolder * globalTypes)121 Type *ETSUndefinedType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation,
122                                     [[maybe_unused]] GlobalTypesHolder *globalTypes)
123 {
124     return allocator->New<ETSUndefinedType>();
125 }
126 
127 }  // namespace ark::es2panda::checker
128