1 /*
2 * Copyright (c) 2024-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
20 namespace ark::es2panda::ir {
TransformChildren(const NodeTransformer & cb,std::string_view const transformationName)21 void ETSNeverType::TransformChildren([[maybe_unused]] const NodeTransformer &cb,
22 [[maybe_unused]] std::string_view const transformationName)
23 {
24 for (auto *&it : VectorIterationGuard(Annotations())) {
25 if (auto *transformedNode = cb(it); it != transformedNode) {
26 it->SetTransformedNode(transformationName, transformedNode);
27 it = transformedNode->AsAnnotationUsage();
28 }
29 }
30 }
31
Iterate(const NodeTraverser & cb) const32 void ETSNeverType::Iterate([[maybe_unused]] const NodeTraverser &cb) const
33 {
34 for (auto *it : VectorIterationGuard(Annotations())) {
35 cb(it);
36 }
37 }
38
Dump(ir::AstDumper * dumper) const39 void ETSNeverType::Dump(ir::AstDumper *dumper) const
40 {
41 dumper->Add({{"type", "ETSNeverType"}, {"annotations", AstDumper::Optional(Annotations())}});
42 }
43
Dump(ir::SrcDumper * dumper) const44 void ETSNeverType::Dump(ir::SrcDumper *dumper) const
45 {
46 for (auto *anno : Annotations()) {
47 anno->Dump(dumper);
48 }
49 dumper->Add("never");
50 }
51
Compile(compiler::PandaGen * pg) const52 void ETSNeverType::Compile([[maybe_unused]] compiler::PandaGen *pg) const
53 {
54 ES2PANDA_UNREACHABLE();
55 }
56
Check(checker::TSChecker * checker)57 checker::Type *ETSNeverType::Check([[maybe_unused]] checker::TSChecker *checker)
58 {
59 ES2PANDA_UNREACHABLE();
60 }
61
Check(checker::ETSChecker * checker)62 checker::VerifiedType ETSNeverType::Check([[maybe_unused]] checker::ETSChecker *checker)
63 {
64 return {this, checker->GetAnalyzer()->Check(this)};
65 }
66
GetType(checker::ETSChecker * checker)67 checker::Type *ETSNeverType::GetType([[maybe_unused]] checker::ETSChecker *checker)
68 {
69 SetTsType(checker->GlobalETSNeverType());
70 return TsType();
71 }
72
Clone(ArenaAllocator * allocator,AstNode * parent)73 ETSNeverType *ETSNeverType::Clone(ArenaAllocator *allocator, AstNode *parent)
74 {
75 auto *const clone = allocator->New<ir::ETSNeverType>(allocator);
76 ES2PANDA_ASSERT(clone != nullptr);
77
78 if (parent != nullptr) {
79 clone->SetParent(parent);
80 }
81
82 if (!Annotations().empty()) {
83 ArenaVector<AnnotationUsage *> annotationUsages {allocator->Adapter()};
84 for (auto *annotationUsage : Annotations()) {
85 auto *const annotationClone = annotationUsage->Clone(allocator, clone);
86 ES2PANDA_ASSERT(annotationClone != nullptr);
87 annotationUsages.push_back(annotationClone->AsAnnotationUsage());
88 }
89 clone->SetAnnotations(std::move(annotationUsages));
90 }
91
92 clone->SetRange(Range());
93 return clone;
94 }
95 } // namespace ark::es2panda::ir
96