• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "awaitExpression.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 AwaitExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName)
24 {
25     if (argument_ != nullptr) {
26         if (auto *transformedNode = cb(argument_); argument_ != transformedNode) {
27             argument_->SetTransformedNode(transformationName, transformedNode);
28             argument_ = transformedNode->AsExpression();
29         }
30     }
31 }
32 
Iterate(const NodeTraverser & cb) const33 void AwaitExpression::Iterate(const NodeTraverser &cb) const
34 {
35     if (argument_ != nullptr) {
36         cb(argument_);
37     }
38 }
39 
Dump(ir::AstDumper * dumper) const40 void AwaitExpression::Dump(ir::AstDumper *dumper) const
41 {
42     dumper->Add({{"type", "AwaitExpression"}, {"argument", AstDumper::Nullish(argument_)}});
43 }
44 
Dump(ir::SrcDumper * dumper) const45 void AwaitExpression::Dump(ir::SrcDumper *dumper) const
46 {
47     if (argument_ != nullptr) {
48         dumper->Add("await ");
49         argument_->Dump(dumper);
50     }
51 }
52 
Compile(compiler::PandaGen * pg) const53 void AwaitExpression::Compile(compiler::PandaGen *pg) const
54 {
55     pg->GetAstCompiler()->Compile(this);
56 }
57 
Compile(compiler::ETSGen * etsg) const58 void AwaitExpression::Compile(compiler::ETSGen *etsg) const
59 {
60     etsg->GetAstCompiler()->Compile(this);
61 }
62 
Check(checker::TSChecker * checker)63 checker::Type *AwaitExpression::Check(checker::TSChecker *checker)
64 {
65     return checker->GetAnalyzer()->Check(this);
66 }
67 
Check(checker::ETSChecker * checker)68 checker::VerifiedType AwaitExpression::Check(checker::ETSChecker *checker)
69 {
70     return {this, checker->GetAnalyzer()->Check(this)};
71 }
72 
Clone(ArenaAllocator * const allocator,AstNode * const parent)73 AwaitExpression *AwaitExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent)
74 {
75     auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr;
76     auto *const clone = allocator->New<AwaitExpression>(argument);
77     ES2PANDA_ASSERT(clone);
78 
79     if (argument != nullptr) {
80         argument->SetParent(clone);
81     }
82 
83     if (parent != nullptr) {
84         clone->SetParent(parent);
85     }
86 
87     clone->SetRange(Range());
88     return clone;
89 }
90 }  // namespace ark::es2panda::ir
91