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 "etsStringLiteralType.h"
17
18 #include "checker/ETSchecker.h"
19
20 namespace ark::es2panda::ir {
TransformChildren(const NodeTransformer & cb,std::string_view const transformationName)21 void ETSStringLiteralType::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 ETSStringLiteralType::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 ETSStringLiteralType::Dump(ir::AstDumper *dumper) const
40 {
41 dumper->Add(
42 {{"type", "ETSStringLiteralType"}, {"value", value_}, {"annotations", AstDumper::Optional(Annotations())}});
43 }
44
Dump(ir::SrcDumper * dumper) const45 void ETSStringLiteralType::Dump(ir::SrcDumper *dumper) const
46 {
47 for (auto *anno : Annotations()) {
48 anno->Dump(dumper);
49 }
50 dumper->Add("\"" + value_.Mutf8() + "\"");
51 }
52
Compile(compiler::PandaGen * pg) const53 void ETSStringLiteralType::Compile([[maybe_unused]] compiler::PandaGen *pg) const
54 {
55 ES2PANDA_UNREACHABLE();
56 }
57
Check(checker::TSChecker * checker)58 checker::Type *ETSStringLiteralType::Check([[maybe_unused]] checker::TSChecker *checker)
59 {
60 ES2PANDA_UNREACHABLE();
61 }
62
Check(checker::ETSChecker * checker)63 checker::VerifiedType ETSStringLiteralType::Check([[maybe_unused]] checker::ETSChecker *checker)
64 {
65 return {this, checker->GetAnalyzer()->Check(this)};
66 }
67
GetType(checker::ETSChecker * checker)68 checker::Type *ETSStringLiteralType::GetType([[maybe_unused]] checker::ETSChecker *checker)
69 {
70 SetTsType(checker->CreateETSStringLiteralType(value_));
71 return TsType();
72 }
73
Clone(ArenaAllocator * allocator,AstNode * parent)74 ETSStringLiteralType *ETSStringLiteralType::Clone(ArenaAllocator *allocator, AstNode *parent)
75 {
76 auto *const clone = allocator->New<ir::ETSStringLiteralType>(value_, allocator);
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 ES2PANDA_ASSERT(annotationUsage->Clone(allocator, clone));
86 annotationUsages.push_back(annotationUsage->Clone(allocator, clone)->AsAnnotationUsage());
87 }
88 clone->SetAnnotations(std::move(annotationUsages));
89 }
90
91 clone->SetRange(Range());
92 return clone;
93 }
94 } // namespace ark::es2panda::ir
95