private void executePost() { this.transition = false; if (currentCheckerIndex < checks.size()) { explodedGraphWalker.programState = checks.get(currentCheckerIndex).checkPostStatement(this, syntaxNode); } else { CFG.Block block = (CFG.Block) explodedGraphWalker.programPosition.block; if (explodedGraphWalker.programPosition.i< block.elements().size()) { explodedGraphWalker.clearStack(block.elements().get(explodedGraphWalker.programPosition.i)); } explodedGraphWalker.enqueue( explodedGraphWalker.programPosition.next(), explodedGraphWalker.programState, explodedGraphWalker.node.exitPath, methodYield); return; } if (!transition) { addTransition(explodedGraphWalker.programState); } }
private void analyzeCFG(Map<CFG.Block, Set<Symbol>> in, Map<CFG.Block, Set<Symbol>> kill, Map<CFG.Block, Set<Symbol>> gen) { Deque<CFG.Block> workList = new LinkedList<>(); workList.addAll(cfg.reversedBlocks()); while (!workList.isEmpty()) { CFG.Block block = workList.removeFirst(); Set<Symbol> blockOut = out.get(block); if (blockOut == null) { blockOut = new HashSet<>(); out.put(block, blockOut); } for (CFG.Block successor : block.successors()) { Set<Symbol> inOfSuccessor = in.get(successor); if (inOfSuccessor != null) { blockOut.addAll(inOfSuccessor); } } // in = gen and (out - kill) Set<Symbol> newIn = new HashSet<>(gen.get(block)); newIn.addAll(Sets.difference(blockOut, kill.get(block))); if (newIn.equals(in.get(block))) { continue; } in.put(block, newIn); for (CFG.Block predecessor : block.predecessors()) { workList.addLast(predecessor); } } }
@CheckForNull private static Set<Block> localSuccessors(CFG.Block block, Map<Tree, CFGLoop> container) { if (isStarting(block)) { CFGLoop loop = container.get(block.terminator()); if (loop == null) { loop = create(block, container); } Set<Block> loopSuccessors = new HashSet<>(loop.successors); if (block.trueBlock() == null) { // Special case where no condition is given in FOR loop: only one successor specified return null; } else { loopSuccessors.add(block.falseBlock()); } return loopSuccessors; } return block.successors(); }
private void handleBlockExit(ProgramPoint programPosition) { CFG.Block block = (CFG.Block) programPosition.block; Tree terminator = block.terminator(); cleanUpProgramState(block); boolean exitPath = node.exitPath; if (block.exitBlock() != null) { enqueue(new ProgramPoint(block.exitBlock()), programState, true); } else { for (CFG.Block successor : block.successors()) { enqueue(new ProgramPoint(successor), programState, true); for (CFG.Block successor : block.successors()) { if (!block.isFinallyBlock() || isDirectFlowSuccessorOf(successor, block)) { enqueue(new ProgramPoint(successor), programState, successor == block.exitBlock());
if (block.successors().isEmpty()) { endOfExecutionPath.add(node); continue; Tree terminator = block.terminator(); if (programPosition.i < block.elements().size()) { visit(block.elements().get(programPosition.i), terminator); } else if (terminator == null) { } else if (programPosition.i == block.elements().size()) {
private void handleBlockExit(ExplodedGraph.ProgramPoint programPosition) { CFG.Block block = programPosition.block; Tree terminator = block.terminator(); cleanUpProgramState(block); if (terminator != null) { if(block.exitBlock() != null) { enqueue(new ExplodedGraph.ProgramPoint(block.exitBlock(), 0), programState, true); } else { for (CFG.Block successor : block.successors()) { enqueue(new ExplodedGraph.ProgramPoint(successor, 0), programState, true); for (CFG.Block successor : block.successors()) { if (!block.isFinallyBlock() || successor != block.exitBlock()) { enqueue(new ExplodedGraph.ProgramPoint(successor, 0), programState, successor == block.exitBlock());
private void handleBlockExit(ProgramPoint programPosition) { CFG.Block block = (CFG.Block) programPosition.block; Tree terminator = block.terminator(); cleanUpProgramState(block); boolean exitPath = node.exitPath; if (block.exitBlock() != null) { enqueue(new ProgramPoint(block.exitBlock()), programState, true); } else { for (CFG.Block successor : block.successors()) { enqueue(new ProgramPoint(successor), programState, true); for (CFG.Block successor : block.successors()) { if (!block.isFinallyBlock() || isDirectFlowSuccessorOf(successor, block)) { enqueue(new ProgramPoint(successor), programState, successor == block.exitBlock());
if (block.successors().isEmpty()) { endOfExecutionPath.add(node); continue; Tree terminator = block.terminator(); if (programPosition.i < block.elements().size()) { visit(block.elements().get(programPosition.i), terminator); } else if (terminator == null) { } else if (programPosition.i == block.elements().size()) {
programPosition = node.programPoint; programState = node.programState; if (programPosition.block.successors().isEmpty()) { checkerDispatcher.executeCheckEndOfExecutionPath(constraintManager); LOG.debug("End of potential path reached!"); if (programPosition.i < programPosition.block.elements().size()) { visit(programPosition.block.elements().get(programPosition.i), programPosition.block.terminator()); } else if (programPosition.block.terminator() == null) { } else if (programPosition.i == programPosition.block.elements().size()) { checkerDispatcher.executeCheckPostStatement(programPosition.block.terminator()); } else { checkerDispatcher.executeCheckPreStatement(programPosition.block.terminator()); handleBlockExit(programPosition);
Block finallyBlock = currentBlock; build(finallyBlockTree); finallyBlock.addExitSuccessor(exitBlock()); exitBlocks.push(currentBlock); addContinueTarget(currentBlock);
Block finallyBlock = currentBlock; build(finallyBlockTree); finallyBlock.addExitSuccessor(exitBlock()); exitBlocks.push(currentBlock); if(currentBlock.exitBlock != null && currentBlock.exitBlock.isFinallyBlock) { for (Block catchBlock : catches) { currentBlock.exitBlock.addSuccessor(catchBlock); currentBlock.addSuccessor(catchBlock); exitBlocks.pop(); if(catches.isEmpty()) { currentBlock.addExitSuccessor(finallyOrEndBlock); currentBlock.addSuccessor(catchBlock);
hasDefaultCase = containsDefaultCase(caseGroupTree.labels()); currentBlock.setCaseGroup(caseGroupTree); switches.getLast().addSuccessor(currentBlock); if (!caseGroupTree.equals(firstCase)) { currentBlock.addSuccessor(switchSuccessor);
hasDefaultCase = containsDefaultCase(caseGroupTree.labels()); currentBlock.setCaseGroup(caseGroupTree); switches.getLast().addSuccessor(currentBlock); if (!caseGroupTree.equals(firstCase)) { currentBlock.addSuccessor(switchSuccessor);
hasDefaultCase = containsDefaultCase(caseGroupTree.labels()); switches.getLast().addSuccessor(currentBlock); if (!caseGroupTree.equals(firstCase)) { currentBlock.addSuccessor(switchSuccessor);
private void processBlockElements(CFG.Block block, Set<Symbol> blockKill, Set<Symbol> blockGen) { for (Tree element : Lists.reverse(block.elements())) { Symbol symbol; switch (element.kind()) {
Block finallyBlock = currentBlock; build(finallyBlockTree); finallyBlock.addExitSuccessor(exitBlock()); exitBlocks.push(currentBlock); addContinueTarget(currentBlock);
private void processBlockElements(CFG.Block block, Set<Symbol> blockKill, Set<Symbol> blockGen) { for (Tree element : Lists.reverse(block.elements())) { switch (element.kind()) { case ASSIGNMENT:
currentBlock = createUnconditionalJump(tree, body); updateBlock.addSuccessor(currentBlock);
private void processBlockElements(CFG.Block block, Set<Symbol> blockKill, Set<Symbol> blockGen) { for (Tree element : Lists.reverse(block.elements())) { switch (element.kind()) { case ASSIGNMENT:
private void buildForStatement(ForStatementTree tree) { Block falseBranch = currentBlock; // process step currentBlock = createBlock(); Block updateBlock = currentBlock; build(tree.update()); addContinueTarget(currentBlock); // process body currentBlock = createBlock(currentBlock); breakTargets.addLast(falseBranch); build(tree.statement()); breakTargets.removeLast(); continueTargets.removeLast(); Block body = currentBlock; // process condition ExpressionTree condition = tree.condition(); if (condition != null) { currentBlock = createBranch(tree, body, falseBranch); buildCondition(condition, body, falseBranch); } else { currentBlock = createUnconditionalJump(tree, body, falseBranch); } updateBlock.addSuccessor(currentBlock); // process init currentBlock = createBlock(currentBlock); build(tree.initializer()); }