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 "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 25namespace ark::es2panda::ir { 26ETSLaunchExpression::ETSLaunchExpression(CallExpression *expr) 27 : Expression(AstNodeType::ETS_LAUNCH_EXPRESSION), expr_(expr) 28{ 29} 30 31void ETSLaunchExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) 32{ 33 if (auto *transformedNode = cb(expr_); expr_ != transformedNode) { 34 expr_->SetTransformedNode(transformationName, transformedNode); 35 expr_ = transformedNode->AsCallExpression(); 36 } 37} 38 39void ETSLaunchExpression::Iterate(const NodeTraverser &cb) const 40{ 41 cb(expr_); 42} 43 44void ETSLaunchExpression::Dump(ir::AstDumper *dumper) const 45{ 46 dumper->Add({{"type", "ETSLaunchExpression"}, {"expr", expr_}}); 47} 48 49void ETSLaunchExpression::Dump(ir::SrcDumper *dumper) const 50{ 51 dumper->Add("launch "); 52 expr_->Dump(dumper); 53} 54 55void ETSLaunchExpression::Compile(compiler::PandaGen *pg) const 56{ 57 pg->GetAstCompiler()->Compile(this); 58} 59 60void ETSLaunchExpression::Compile([[maybe_unused]] compiler::ETSGen *etsg) const 61{ 62#ifdef PANDA_WITH_ETS 63 etsg->GetAstCompiler()->Compile(this); 64#endif // PANDA_WITH_ETS 65} 66 67checker::Type *ETSLaunchExpression::Check(checker::TSChecker *checker) 68{ 69 return checker->GetAnalyzer()->Check(this); 70} 71 72checker::Type *ETSLaunchExpression::Check(checker::ETSChecker *checker) 73{ 74 return checker->GetAnalyzer()->Check(this); 75} 76 77bool ETSLaunchExpression::IsStaticCall() const 78{ 79 return expr_->Signature()->HasSignatureFlag(checker::SignatureFlags::STATIC); 80} 81 82ETSLaunchExpression *ETSLaunchExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) 83{ 84 auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr) : nullptr; 85 86 if (auto *const clone = allocator->New<ETSLaunchExpression>(expr); clone != nullptr) { 87 if (expr != nullptr) { 88 expr->SetParent(clone); 89 } 90 91 if (parent != nullptr) { 92 clone->SetParent(parent); 93 } 94 95 clone->SetRange(Range()); 96 return clone; 97 } 98 99 throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); 100} 101} // namespace ark::es2panda::ir 102