1/**
2 * Copyright (c) 2021-2024 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 "forInStatement.h"
17
18#include "varbinder/scope.h"
19#include "compiler/base/lreference.h"
20#include "compiler/core/labelTarget.h"
21#include "compiler/core/pandagen.h"
22#include "checker/TSchecker.h"
23#include "compiler/core/ETSGen.h"
24#include "ir/astDump.h"
25#include "ir/srcDump.h"
26
27namespace ark::es2panda::ir {
28void ForInStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName)
29{
30    if (auto *transformedNode = cb(left_); left_ != transformedNode) {
31        left_->SetTransformedNode(transformationName, transformedNode);
32        left_ = transformedNode;
33    }
34
35    if (auto *transformedNode = cb(right_); right_ != transformedNode) {
36        right_->SetTransformedNode(transformationName, transformedNode);
37        right_ = transformedNode->AsExpression();
38    }
39
40    if (auto *transformedNode = cb(body_); body_ != transformedNode) {
41        body_->SetTransformedNode(transformationName, transformedNode);
42        body_ = transformedNode->AsStatement();
43    }
44}
45
46void ForInStatement::Iterate(const NodeTraverser &cb) const
47{
48    cb(left_);
49    cb(right_);
50    cb(body_);
51}
52
53void ForInStatement::Dump(ir::AstDumper *dumper) const
54{
55    dumper->Add({{"type", "ForInStatement"}, {"left", left_}, {"right", right_}, {"body", body_}});
56}
57
58void ForInStatement::Dump(ir::SrcDumper *dumper) const
59{
60    dumper->Add("ForInStatement");
61}
62
63void ForInStatement::Compile(compiler::PandaGen *pg) const
64{
65    pg->GetAstCompiler()->Compile(this);
66}
67
68void ForInStatement::Compile(compiler::ETSGen *etsg) const
69{
70    etsg->GetAstCompiler()->Compile(this);
71}
72
73checker::Type *ForInStatement::Check(checker::TSChecker *checker)
74{
75    return checker->GetAnalyzer()->Check(this);
76}
77
78checker::Type *ForInStatement::Check(checker::ETSChecker *checker)
79{
80    return checker->GetAnalyzer()->Check(this);
81}
82}  // namespace ark::es2panda::ir
83