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 #include "etsNeverType.h"
17
18 #include "checker/ETSchecker.h"
19 #include "checker/ets/conversion.h"
20 #include "etsTypeParameter.h"
21
22 namespace ark::es2panda::checker {
Identical(TypeRelation * relation,Type * other)23 void ETSNeverType::Identical(TypeRelation *relation, Type *other)
24 {
25 relation->Result(other->IsETSNeverType());
26 }
27
AssignmentTarget(TypeRelation * relation,Type * source)28 void ETSNeverType::AssignmentTarget(TypeRelation *relation, Type *source)
29 {
30 Identical(relation, source);
31 }
32
AssignmentSource(TypeRelation * relation,Type * target)33 bool ETSNeverType::AssignmentSource(TypeRelation *relation, [[maybe_unused]] Type *target)
34 {
35 relation->Result(true);
36 return true;
37 }
38
Compare(TypeRelation * relation,Type * other)39 void ETSNeverType::Compare([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *other)
40 {
41 ES2PANDA_UNREACHABLE();
42 }
43
Cast(TypeRelation * relation,Type * target)44 void ETSNeverType::Cast(TypeRelation *relation, Type *target)
45 {
46 Identical(relation, target);
47 }
48
CastTarget(TypeRelation * relation,Type * source)49 void ETSNeverType::CastTarget(TypeRelation *relation, Type *source)
50 {
51 relation->IsSupertypeOf(source, this);
52 }
53
IsSubtypeOf(TypeRelation * relation,Type * target)54 void ETSNeverType::IsSubtypeOf(TypeRelation *relation, [[maybe_unused]] Type *target)
55 {
56 relation->Result(true);
57 }
58
IsSupertypeOf(TypeRelation * relation,Type * source)59 void ETSNeverType::IsSupertypeOf(TypeRelation *relation, Type *source)
60 {
61 Identical(relation, source);
62 }
63
ToString(std::stringstream & ss,bool precise) const64 void ETSNeverType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const
65 {
66 ss << "never";
67 }
68
ToAssemblerType(std::stringstream & ss) const69 void ETSNeverType::ToAssemblerType(std::stringstream &ss) const
70 {
71 ss << compiler::Signatures::BUILTIN_OBJECT;
72 }
73
GetTypeFacts() const74 TypeFacts ETSNeverType::GetTypeFacts() const
75 {
76 return TypeFacts::NONE;
77 }
78
ToDebugInfoType(std::stringstream & ss) const79 void ETSNeverType::ToDebugInfoType(std::stringstream &ss) const
80 {
81 ss << ETSObjectType::NameToDescriptor(compiler::Signatures::BUILTIN_OBJECT);
82 }
83
Instantiate(ArenaAllocator * allocator,TypeRelation * relation,GlobalTypesHolder * globalTypes)84 Type *ETSNeverType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation,
85 [[maybe_unused]] GlobalTypesHolder *globalTypes)
86 {
87 return allocator->New<ETSNeverType>();
88 }
89 } // namespace ark::es2panda::checker