13af6ab5fSopenharmony_ci/* 23af6ab5fSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License. 53af6ab5fSopenharmony_ci * You may obtain a copy of the License at 63af6ab5fSopenharmony_ci * 73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83af6ab5fSopenharmony_ci * 93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and 133af6ab5fSopenharmony_ci * limitations under the License. 143af6ab5fSopenharmony_ci */ 153af6ab5fSopenharmony_ci 163af6ab5fSopenharmony_ci#ifndef ES2PANDA_COMPILER_CHECKER_ETS_ALIVE_ANALYZER_H 173af6ab5fSopenharmony_ci#define ES2PANDA_COMPILER_CHECKER_ETS_ALIVE_ANALYZER_H 183af6ab5fSopenharmony_ci 193af6ab5fSopenharmony_ci#include "checker/ETSchecker.h" 203af6ab5fSopenharmony_ci#include "checker/ets/baseAnalyzer.h" 213af6ab5fSopenharmony_ci 223af6ab5fSopenharmony_ci#include "utils/arena_containers.h" 233af6ab5fSopenharmony_ci 243af6ab5fSopenharmony_cinamespace ark::es2panda::ir { 253af6ab5fSopenharmony_ciclass AstNode; 263af6ab5fSopenharmony_ciclass Statement; 273af6ab5fSopenharmony_ciclass ClassDefinition; 283af6ab5fSopenharmony_ciclass MethodDefinition; 293af6ab5fSopenharmony_ciclass DoWhileStatement; 303af6ab5fSopenharmony_ciclass VariableDeclaration; 313af6ab5fSopenharmony_ci} // namespace ark::es2panda::ir 323af6ab5fSopenharmony_ci 333af6ab5fSopenharmony_cinamespace ark::es2panda::checker { 343af6ab5fSopenharmony_ciclass AliveAnalyzer : public BaseAnalyzer<PendingExit> { 353af6ab5fSopenharmony_cipublic: 363af6ab5fSopenharmony_ci // NOLINTNEXTLINE(readability-redundant-member-init) 373af6ab5fSopenharmony_ci AliveAnalyzer(const ir::AstNode *node, ETSChecker *checker) : BaseAnalyzer<PendingExit>(), checker_(checker) 383af6ab5fSopenharmony_ci { 393af6ab5fSopenharmony_ci AnalyzeNodes(node); 403af6ab5fSopenharmony_ci } 413af6ab5fSopenharmony_ci 423af6ab5fSopenharmony_ci void MarkDead() override 433af6ab5fSopenharmony_ci { 443af6ab5fSopenharmony_ci status_ = LivenessStatus::DEAD; 453af6ab5fSopenharmony_ci } 463af6ab5fSopenharmony_ci 473af6ab5fSopenharmony_ci LivenessStatus Or(LivenessStatus left, LivenessStatus right) 483af6ab5fSopenharmony_ci { 493af6ab5fSopenharmony_ci return static_cast<LivenessStatus>(left | right); 503af6ab5fSopenharmony_ci } 513af6ab5fSopenharmony_ci 523af6ab5fSopenharmony_ci LivenessStatus And(LivenessStatus left, LivenessStatus right) 533af6ab5fSopenharmony_ci { 543af6ab5fSopenharmony_ci return static_cast<LivenessStatus>(left & right); 553af6ab5fSopenharmony_ci } 563af6ab5fSopenharmony_ci 573af6ab5fSopenharmony_ciprivate: 583af6ab5fSopenharmony_ci void AnalyzeNodes(const ir::AstNode *node); 593af6ab5fSopenharmony_ci void AnalyzeNode(const ir::AstNode *node); 603af6ab5fSopenharmony_ci void AnalyzeNodeHelper1(const ir::AstNode *node); 613af6ab5fSopenharmony_ci void AnalyzeNodeHelper2(const ir::AstNode *node); 623af6ab5fSopenharmony_ci void AnalyzeDef(const ir::AstNode *node); 633af6ab5fSopenharmony_ci void AnalyzeStat(const ir::AstNode *node); 643af6ab5fSopenharmony_ci void AnalyzeStats(const ArenaVector<ir::Statement *> &stats); 653af6ab5fSopenharmony_ci void AnalyzeStructDecl(const ir::ETSStructDeclaration *structDecl); 663af6ab5fSopenharmony_ci void AnalyzeClassDecl(const ir::ClassDeclaration *classDecl); 673af6ab5fSopenharmony_ci void AnalyzeMethodDef(const ir::MethodDefinition *methodDef); 683af6ab5fSopenharmony_ci void AnalyzeVarDef(const ir::VariableDeclaration *varDef); 693af6ab5fSopenharmony_ci void AnalyzeDoLoop(const ir::DoWhileStatement *doWhile); 703af6ab5fSopenharmony_ci void AnalyzeWhileLoop(const ir::WhileStatement *whileStmt); 713af6ab5fSopenharmony_ci void AnalyzeForLoop(const ir::ForUpdateStatement *forStmt); 723af6ab5fSopenharmony_ci void AnalyzeForOfLoop(const ir::ForOfStatement *forOfStmt); 733af6ab5fSopenharmony_ci void AnalyzeIf(const ir::IfStatement *ifStmt); 743af6ab5fSopenharmony_ci void AnalyzeLabelled(const ir::LabelledStatement *labelledStmt); 753af6ab5fSopenharmony_ci void AnalyzeNewClass(const ir::ETSNewClassInstanceExpression *newClass); 763af6ab5fSopenharmony_ci void AnalyzeCall(const ir::CallExpression *callExpr); 773af6ab5fSopenharmony_ci void AnalyzeThrow(const ir::ThrowStatement *throwStmt); 783af6ab5fSopenharmony_ci void AnalyzeSwitch(const ir::SwitchStatement *switchStmt); 793af6ab5fSopenharmony_ci void AnalyzeTry(const ir::TryStatement *tryStmt); 803af6ab5fSopenharmony_ci void AnalyzeBreak(const ir::BreakStatement *breakStmt); 813af6ab5fSopenharmony_ci void AnalyzeContinue(const ir::ContinueStatement *contStmt); 823af6ab5fSopenharmony_ci void AnalyzeReturn(const ir::ReturnStatement *retStmt); 833af6ab5fSopenharmony_ci 843af6ab5fSopenharmony_ci ETSChecker *checker_; 853af6ab5fSopenharmony_ci LivenessStatus status_ {LivenessStatus::ALIVE}; 863af6ab5fSopenharmony_ci}; 873af6ab5fSopenharmony_ci} // namespace ark::es2panda::checker 883af6ab5fSopenharmony_ci 893af6ab5fSopenharmony_ci#endif 90