Class PathQuery


  • public class PathQuery
    extends Object
    Reachability and path-enumeration queries over the control flow graph a simulation covered.
    • Method Detail

      • from

        public static PathQuery from​(SimulationResult result)
        Creates a path query from a simulation result, indexing its successor and predecessor edges.
        Parameters:
        result - the simulation result to query
        Returns:
        a query over that result's method
      • canReach

        public boolean canReach​(IRBlock from,
                                IRBlock to)
        Checks if one block can reach another in the CFG.
        Parameters:
        from - the starting block
        to - the block to reach
        Returns:
        true when a successor walk from the start hits the target; false if either is null
      • canReach

        public boolean canReach​(IRInstruction from,
                                IRInstruction to)
        Checks if one instruction can reach another, comparing positions when both share a block.
        Parameters:
        from - the starting instruction
        to - the instruction to reach
        Returns:
        true when the target is later in the same block or its block is reachable
      • getAllPaths

        public List<List<IRBlock>> getAllPaths​(IRBlock from,
                                               IRBlock to)
        Gets all paths between two blocks, capped at 100 results.
        Parameters:
        from - the starting block
        to - the target block
        Returns:
        the acyclic paths found, each as a block sequence
      • getAllPaths

        public List<List<IRBlock>> getAllPaths​(IRBlock from,
                                               IRBlock to,
                                               int maxPaths)
        Gets all paths between two blocks with a maximum limit.
        Parameters:
        from - the starting block
        to - the target block
        maxPaths - how many paths to collect before stopping the search
        Returns:
        the acyclic paths found, empty when either block is null
      • getShortestPath

        public List<IRBlock> getShortestPath​(IRBlock from,
                                             IRBlock to)
        Gets the shortest path between two blocks by breadth-first search.
        Parameters:
        from - the starting block
        to - the target block
        Returns:
        the block sequence from start to target, empty when unreachable or either is null
      • getReachableBlocks

        public Set<IRBlock> getReachableBlocks​(IRBlock from)
        Gets all blocks reachable from a given block, the block itself included.
        Parameters:
        from - the starting block
        Returns:
        the reachable set, empty when the block is null
      • getBlocksReaching

        public Set<IRBlock> getBlocksReaching​(IRBlock to)
        Gets all blocks that can reach a given block, the block itself included.
        Parameters:
        to - the target block
        Returns:
        the reaching set, empty when the block is null
      • wasVisited

        public boolean wasVisited​(IRBlock block)
        Checks if a block was visited during simulation.
        Parameters:
        block - the block to test
        Returns:
        true when a recorded state was positioned in that block
      • getVisitedBlocks

        public Set<IRBlock> getVisitedBlocks()
        Returns:
        an unmodifiable view of the blocks the simulation visited
      • getUnvisitedBlocks

        public Set<IRBlock> getUnvisitedBlocks()
        Gets blocks that were not visited during simulation.
        Returns:
        the method's blocks minus the visited ones, empty when there is no method
      • getVisitedPercentage

        public double getVisitedPercentage()
        Gets the percentage of blocks that were visited.
        Returns:
        visited blocks over total blocks scaled to 0-100, or 0 when there are no blocks
      • getLoopHeaders

        public Set<IRBlock> getLoopHeaders()
        Detects potential loops (back edges).
        Returns:
        the successors that can reach back to their own predecessor
      • getEntryBlock

        public IRBlock getEntryBlock()
        Returns:
        the method's entry block, or null when the result carried no method
      • getExitBlocks

        public Set<IRBlock> getExitBlocks()
        Gets all exit blocks (blocks with returns or throws).
        Returns:
        the non-empty blocks that have no successors