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 "doWhileStatement.h"
17 #include <cstddef>
18
19 #include "varbinder/scope.h"
20 #include "compiler/base/condition.h"
21 #include "compiler/core/labelTarget.h"
22 #include "compiler/core/pandagen.h"
23 #include "compiler/core/ETSGen.h"
24 #include "checker/TSchecker.h"
25 #include "ir/astDump.h"
26 #include "ir/srcDump.h"
27
28 namespace ark::es2panda::ir {
TransformChildren(const NodeTransformer &cb, std::string_view const transformationName)29 void DoWhileStatement::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName)
30 {
31 if (auto *transformedNode = cb(body_); body_ != transformedNode) {
32 body_->SetTransformedNode(transformationName, transformedNode);
33 body_ = transformedNode->AsStatement();
34 }
35
36 if (auto *transformedNode = cb(test_); test_ != transformedNode) {
37 test_->SetTransformedNode(transformationName, transformedNode);
38 test_ = transformedNode->AsExpression();
39 }
40 }
41
Iterate(const NodeTraverser &cb) const42 void DoWhileStatement::Iterate(const NodeTraverser &cb) const
43 {
44 cb(body_);
45 cb(test_);
46 }
47
Dump(ir::AstDumper *dumper) const48 void DoWhileStatement::Dump(ir::AstDumper *dumper) const
49 {
50 dumper->Add({{"type", "DoWhileStatement"}, {"body", body_}, {"test", test_}});
51 }
52
Dump(ir::SrcDumper *dumper) const53 void DoWhileStatement::Dump(ir::SrcDumper *dumper) const
54 {
55 dumper->Add("do {");
56 if (body_ != nullptr) {
57 dumper->IncrIndent();
58 dumper->Endl();
59 body_->Dump(dumper);
60 dumper->DecrIndent();
61 dumper->Endl();
62 }
63 dumper->Add("} while");
64 dumper->Add("(");
65 if (test_ != nullptr) {
66 test_->Dump(dumper);
67 }
68 dumper->Add(")");
69 }
70
Compile(compiler::PandaGen *pg) const71 void DoWhileStatement::Compile(compiler::PandaGen *pg) const
72 {
73 pg->GetAstCompiler()->Compile(this);
74 }
75
Compile(compiler::ETSGen *etsg) const76 void DoWhileStatement::Compile(compiler::ETSGen *etsg) const
77 {
78 etsg->GetAstCompiler()->Compile(this);
79 }
80
Check(checker::TSChecker *checker)81 checker::Type *DoWhileStatement::Check(checker::TSChecker *checker)
82 {
83 return checker->GetAnalyzer()->Check(this);
84 }
85
Check(checker::ETSChecker *checker)86 checker::Type *DoWhileStatement::Check(checker::ETSChecker *checker)
87 {
88 return checker->GetAnalyzer()->Check(this);
89 }
90 } // namespace ark::es2panda::ir
91