• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 - 2023 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 "etsLaunchExpression.h"
17 
18 #include "compiler/core/pandagen.h"
19 #include "compiler/core/ETSGen.h"
20 #include "checker/ETSchecker.h"
21 #include "checker/TSchecker.h"
22 #include "ir/astDump.h"
23 #include "ir/srcDump.h"
24 
25 namespace panda::es2panda::ir {
ETSLaunchExpression(CallExpression * expr)26 ETSLaunchExpression::ETSLaunchExpression(CallExpression *expr)
27     : Expression(AstNodeType::ETS_LAUNCH_EXPRESSION), expr_(expr)
28 {
29 }
30 
TransformChildren(const NodeTransformer & cb)31 void ETSLaunchExpression::TransformChildren(const NodeTransformer &cb)
32 {
33     expr_ = cb(expr_)->AsCallExpression();
34 }
35 
Iterate(const NodeTraverser & cb) const36 void ETSLaunchExpression::Iterate(const NodeTraverser &cb) const
37 {
38     cb(expr_);
39 }
40 
Dump(ir::AstDumper * dumper) const41 void ETSLaunchExpression::Dump(ir::AstDumper *dumper) const
42 {
43     dumper->Add({{"type", "ETSLaunchExpression"}, {"expr", expr_}});
44 }
45 
Dump(ir::SrcDumper * dumper) const46 void ETSLaunchExpression::Dump(ir::SrcDumper *dumper) const
47 {
48     dumper->Add("ETSLaunchExpression");
49 }
50 
Compile(compiler::PandaGen * pg) const51 void ETSLaunchExpression::Compile(compiler::PandaGen *pg) const
52 {
53     pg->GetAstCompiler()->Compile(this);
54 }
55 
Compile(compiler::ETSGen * etsg) const56 void ETSLaunchExpression::Compile([[maybe_unused]] compiler::ETSGen *etsg) const
57 {
58 #ifdef PANDA_WITH_ETS
59     etsg->GetAstCompiler()->Compile(this);
60 #endif  // PANDA_WITH_ETS
61 }
62 
Check(checker::TSChecker * checker)63 checker::Type *ETSLaunchExpression::Check(checker::TSChecker *checker)
64 {
65     return checker->GetAnalyzer()->Check(this);
66 }
67 
Check(checker::ETSChecker * checker)68 checker::Type *ETSLaunchExpression::Check(checker::ETSChecker *checker)
69 {
70     return checker->GetAnalyzer()->Check(this);
71 }
72 
IsStaticCall() const73 bool ETSLaunchExpression::IsStaticCall() const
74 {
75     return expr_->Signature()->HasSignatureFlag(checker::SignatureFlags::STATIC);
76 }
77 
78 // NOLINTNEXTLINE(google-default-arguments)
Clone(ArenaAllocator * const allocator,AstNode * const parent)79 ETSLaunchExpression *ETSLaunchExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent)
80 {
81     auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr;
82 
83     if (auto *const clone = allocator->New<ETSLaunchExpression>(expr); clone != nullptr) {
84         if (expr != nullptr) {
85             expr->SetParent(clone);
86         }
87         if (parent != nullptr) {
88             clone->SetParent(parent);
89         }
90         return clone;
91     }
92 
93     throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR);
94 }
95 }  // namespace panda::es2panda::ir
96