/* * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "baseAnalyzer.h" #include "assignAnalyzer.h" #include "ir/astNode.h" #include "ir/statements/breakStatement.h" #include "ir/statements/continueStatement.h" namespace ark::es2panda::checker { template void BaseAnalyzer::ClearPendingExits() { pendingExits_.clear(); oldPendingExits_.clear(); } template typename BaseAnalyzer::PendingExitsVector &BaseAnalyzer::PendingExits() { return pendingExits_; } template void BaseAnalyzer::SetPendingExits(const PendingExitsVector &pendingExits) { pendingExits_ = pendingExits; } template typename BaseAnalyzer::PendingExitsVector &BaseAnalyzer::OldPendingExits() { return oldPendingExits_; } template void BaseAnalyzer::SetOldPendingExits(const PendingExitsVector &oldPendingExits) { oldPendingExits_ = oldPendingExits; } template const ir::AstNode *BaseAnalyzer::GetJumpTarget(const ir::AstNode *node) const { if (node->IsBreakStatement()) { return node->AsBreakStatement()->Target(); } ASSERT(node->IsContinueStatement()); return node->AsContinueStatement()->Target(); } template LivenessStatus BaseAnalyzer::ResolveJump(const ir::AstNode *node, ir::AstNodeType jumpKind) { bool resolved = false; PendingExitsVector exits = pendingExits_; pendingExits_ = oldPendingExits_; for (auto &it : exits) { if (it.Node()->Type() == jumpKind && node == GetJumpTarget(it.Node())) { it.ResolveJump(); resolved = true; } else { pendingExits_.push_back(it); } } return From(resolved); } template LivenessStatus BaseAnalyzer::ResolveContinues(const ir::AstNode *node) { oldPendingExits_.clear(); return ResolveJump(node, ir::AstNodeType::CONTINUE_STATEMENT); } template LivenessStatus BaseAnalyzer::ResolveBreaks(const ir::AstNode *node) { return ResolveJump(node, ir::AstNodeType::BREAK_STATEMENT); } template class BaseAnalyzer; template class BaseAnalyzer; } // namespace ark::es2panda::checker