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 "throwStatement.h"
17
18 #include "checker/TSchecker.h"
19 #include "compiler/core/pandagen.h"
20 #include "compiler/core/ETSGen.h"
21
22 namespace ark::es2panda::ir {
TransformChildren(const NodeTransformer & cb,std::string_view transformationName)23 void ThrowStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName)
24 {
25 if (auto *transformedNode = cb(argument_); argument_ != transformedNode) {
26 argument_->SetTransformedNode(transformationName, transformedNode);
27 argument_ = transformedNode->AsExpression();
28 }
29 }
30
Iterate(const NodeTraverser & cb) const31 void ThrowStatement::Iterate(const NodeTraverser &cb) const
32 {
33 cb(argument_);
34 }
35
Dump(ir::AstDumper * dumper) const36 void ThrowStatement::Dump(ir::AstDumper *dumper) const
37 {
38 dumper->Add({{"type", "ThrowStatement"}, {"argument", argument_}});
39 }
40
Dump(ir::SrcDumper * dumper) const41 void ThrowStatement::Dump(ir::SrcDumper *dumper) const
42 {
43 ES2PANDA_ASSERT(Argument() != nullptr);
44 dumper->Add("throw ");
45 Argument()->Dump(dumper);
46 dumper->Add(";");
47 }
48
Compile(compiler::PandaGen * pg) const49 void ThrowStatement::Compile(compiler::PandaGen *pg) const
50 {
51 pg->GetAstCompiler()->Compile(this);
52 }
53
Compile(compiler::ETSGen * etsg) const54 void ThrowStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const
55 {
56 etsg->GetAstCompiler()->Compile(this);
57 }
58
Check(checker::TSChecker * checker)59 checker::Type *ThrowStatement::Check([[maybe_unused]] checker::TSChecker *checker)
60 {
61 return checker->GetAnalyzer()->Check(this);
62 }
63
Check(checker::ETSChecker * checker)64 checker::VerifiedType ThrowStatement::Check([[maybe_unused]] checker::ETSChecker *checker)
65 {
66 return {this, checker->GetAnalyzer()->Check(this)};
67 }
68
Clone(ArenaAllocator * const allocator,AstNode * const parent)69 ThrowStatement *ThrowStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent)
70 {
71 auto *const expression = argument_->Clone(allocator, nullptr)->AsExpression();
72 auto *const clone = allocator->New<ThrowStatement>(expression);
73 expression->SetParent(clone);
74 if (parent != nullptr) {
75 clone->SetParent(parent);
76 }
77 clone->SetRange(range_);
78 return clone;
79 }
80 } // namespace ark::es2panda::ir
81