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 "sequenceExpression.h"
17
18 #include "checker/ETSchecker.h"
19 #include "checker/TSchecker.h"
20 #include "compiler/core/ETSGen.h"
21 #include "compiler/core/pandagen.h"
22
23 namespace ark::es2panda::ir {
SequenceExpression(Tag const tag,SequenceExpression const & other,ArenaAllocator * const allocator)24 SequenceExpression::SequenceExpression([[maybe_unused]] Tag const tag, SequenceExpression const &other,
25 ArenaAllocator *const allocator)
26 : Expression(static_cast<Expression const &>(other)), sequence_(allocator->Adapter())
27 {
28 for (auto *sequence : other.sequence_) {
29 sequence_.emplace_back(sequence->Clone(allocator, this)->AsExpression());
30 }
31 }
32
Clone(ArenaAllocator * const allocator,AstNode * const parent)33 SequenceExpression *SequenceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent)
34 {
35 auto *const clone = allocator->New<SequenceExpression>(Tag {}, *this, allocator);
36 ES2PANDA_ASSERT(clone != nullptr);
37 if (parent != nullptr) {
38 clone->SetParent(parent);
39 }
40 clone->SetRange(Range());
41 return clone;
42 }
43
TransformChildren(const NodeTransformer & cb,std::string_view const transformationName)44 void SequenceExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName)
45 {
46 for (auto *&it : VectorIterationGuard(sequence_)) {
47 if (auto *transformedNode = cb(it); it != transformedNode) {
48 it->SetTransformedNode(transformationName, transformedNode);
49 it = transformedNode->AsExpression();
50 }
51 }
52 }
53
Iterate(const NodeTraverser & cb) const54 void SequenceExpression::Iterate(const NodeTraverser &cb) const
55 {
56 for (auto *it : VectorIterationGuard(sequence_)) {
57 cb(it);
58 }
59 }
60
Dump(ir::AstDumper * dumper) const61 void SequenceExpression::Dump(ir::AstDumper *dumper) const
62 {
63 dumper->Add({{"type", "SequenceExpression"}, {"expressions", sequence_}});
64 }
65
Dump(ir::SrcDumper * dumper) const66 void SequenceExpression::Dump(ir::SrcDumper *dumper) const
67 {
68 for (auto *expr : sequence_) {
69 expr->Dump(dumper);
70 if (expr != sequence_.back()) {
71 dumper->Add(", ");
72 }
73 }
74 }
75
Compile(compiler::PandaGen * pg) const76 void SequenceExpression::Compile(compiler::PandaGen *pg) const
77 {
78 pg->GetAstCompiler()->Compile(this);
79 }
80
Compile(compiler::ETSGen * etsg) const81 void SequenceExpression::Compile(compiler::ETSGen *etsg) const
82 {
83 etsg->GetAstCompiler()->Compile(this);
84 }
85
Check(checker::TSChecker * checker)86 checker::Type *SequenceExpression::Check(checker::TSChecker *checker)
87 {
88 return checker->GetAnalyzer()->Check(this);
89 }
90
Check(checker::ETSChecker * checker)91 checker::VerifiedType SequenceExpression::Check(checker::ETSChecker *checker)
92 {
93 return {this, checker->GetAnalyzer()->Check(this)};
94 }
95 } // namespace ark::es2panda::ir
96