private static boolean canExecuteMoreThanOnce(IterationStatementTree loopTree) { ControlFlowGraph cfg = CheckUtils.buildControlFlowGraph(loopTree); for (CfgBranchingBlock block : Iterables.filter(cfg.blocks(), CfgBranchingBlock.class)) { if (loopTree.equals(block.branchingTree()) && hasPredecessorInsideLoopBody(block, loopTree)) { return true; } } return false; }
private static Map<CaseClauseTree, CfgBranchingBlock> caseClauseBlocksByTree(SwitchStatementTree switchTree) { ControlFlowGraph cfg = CheckUtils.buildControlFlowGraph(switchTree); Map<CaseClauseTree, CfgBranchingBlock> map = new HashMap<>(); for (CfgBlock block : cfg.blocks()) { if (block instanceof CfgBranchingBlock) { CfgBranchingBlock branchingBlock = (CfgBranchingBlock) block; Tree branchingTree = branchingBlock.branchingTree(); if (branchingTree.is(Kind.CASE_CLAUSE)) { map.put((CaseClauseTree) branchingTree, branchingBlock); } } } return map; }
private boolean isInfiniteLoop(IterationStatementTree tree, @Nullable JavaScriptTree condition) { if (isNeverExecutedLoop(condition)) { return false; } ControlFlowGraph flowGraph = CheckUtils.buildControlFlowGraph(tree); Map<Tree, CfgBlock> treesOfFlowGraph = treesToBlocks(flowGraph); if (isBrokenLoop(condition, tree, flowGraph)) { return false; } return condition == null || !conditionIsUpdated(condition, (JavaScriptTree) tree, treesOfFlowGraph) || alwaysTrueConditions.contains(condition); }
private boolean deadVariableInScope(Symbol symbol, Scope scopeToCheck, Scope upperScope, Tree declaration) { ControlFlowGraph cfg = CheckUtils.buildControlFlowGraph(declaration); IdentifierTree firstIdentifierOfScope = getFirstIdentifier(scopeToCheck.tree()); CfgBlock firstCfgBlockOfScope = null; for (CfgBlock cfgBlock : cfg.blocks()) { if (cfgBlock.elements().contains(firstIdentifierOfScope)) { firstCfgBlockOfScope = cfgBlock; } } // might be null for scopeToCheck being nested inside the function if (firstCfgBlockOfScope == null) { return false; } LiveVariableAnalysis lva = LiveVariableAnalysis.create(cfg, upperScope); return !lva.getLiveInSymbols(firstCfgBlockOfScope).contains(symbol); }