Class Block

  • All Implemented Interfaces:
    Iterable<Unit>

    public class Block
    extends Object
    implements Iterable<Unit>
    Represents BasicBlocks that partition a method body. It is implemented as view on an underlying Body instance; as a consequence, changes made on a Block will be automatically reflected in its enclosing method body. Blocks also exist in the context of a BlockGraph, a CFG for a method where Block instances are the nodes of the graph. Hence, a Block can be queried for its successors and predecessors Blocks, as found in this graph.
    • Constructor Detail

      • Block

        public Block​(Unit aHead,
                     Unit aTail,
                     Body aBody,
                     int aIndexInMethod,
                     int aBlockLength,
                     BlockGraph aBlockGraph)
        Constructs a Block in the context of a BlockGraph, and enclosing Body instances.
        Parameters:
        aHead - The first unit ir this Block.
        aTail - The last unit in this Block.
        aBody - The Block's enclosing Body instance.
        aIndexInMethod - The index of this Block in the list of Blocks that partition it's enclosing Body instance.
        aBlockLength - The number of units that makeup this block.
        aBlockGraph - The Graph of Blocks in which this block lives.
        See Also:
        Body, Chain, BlockGraph, Unit, SootMethod
    • Method Detail

      • getBody

        public Body getBody()
        Returns the Block's enclosing Body instance.
        Returns:
        The block's chain of instructions.
        See Also:
        JimpleBody, BafBody, Body
      • iterator

        public Iterator<Unit> iterator()
        Returns an iterator for the linear chain of Units that make up the block.
        Specified by:
        iterator in interface Iterable<Unit>
        Returns:
        An iterator that iterates over the block's units.
        See Also:
        Chain, Unit
      • insertBefore

        public void insertBefore​(Unit toInsert,
                                 Unit point)
        Inserts a Unit before some other Unit in this block.
        Parameters:
        toInsert - A Unit to be inserted.
        point - A Unit in the Block's body before which we wish to insert the Unit.
        See Also:
        Unit, Chain
      • insertAfter

        public void insertAfter​(Unit toInsert,
                                Unit point)
        Inserts a Unit after some other Unit in the Block.
        Parameters:
        toInsert - A Unit to be inserted.
        point - A Unit in the Block after which we wish to insert the Unit.
        See Also:
        Unit
      • remove

        public boolean remove​(Unit item)
        Removes a Unit occurring before some other Unit in the Block.
        Parameters:
        item - A Unit to be remove from the Block's Unit Chain.
        Returns:
        True if the item could be found and removed.
      • getSuccOf

        public Unit getSuccOf​(Unit aItem)
        Returns the Unit occurring immediately after some other Unit in the block.
        Parameters:
        aItem - The Unit from which we wish to get it's successor.
        Returns:
        The successor or null if aItem is the tail for this Block.
      • getPredOf

        public Unit getPredOf​(Unit aItem)
        Returns the Unit occurring immediately before some other Unit in the block.
        Parameters:
        aItem - The Unit from which we wish to get it's predecessor.
        Returns:
        The predecessor or null if aItem is the head for this Block.
      • setIndexInMethod

        public void setIndexInMethod​(int aIndexInMethod)
        Set the index of this Block in the list of Blocks that partition its enclosing Body instance.
        Parameters:
        aIndexInMethod - The index of this Block in the list of Blocks that partition it's enclosing Body instance.
      • getIndexInMethod

        public int getIndexInMethod()
        Returns the index of this Block in the list of Blocks that partition it's enclosing Body instance.
        Returns:
        The index of the block in it's enclosing Body instance.
      • getHead

        public Unit getHead()
        Returns the first unit in this block.
        Returns:
        The first unit in this block.
      • getTail

        public Unit getTail()
        Returns the last unit in this block.
        Returns:
        The last unit in this block.
      • setPreds

        public void setPreds​(List<Block> preds)
        Sets the list of Blocks that are predecessors of this block in it's enclosing BlockGraph instance.
        Parameters:
        preds - The a List of Blocks that precede this block.
        See Also:
        BlockGraph
      • getPreds

        public List<Block> getPreds()
        Returns the List of Block that are predecessors to this block,
        Returns:
        A list of predecessor blocks.
        See Also:
        BlockGraph
      • setSuccs

        public void setSuccs​(List<Block> succs)
        Sets the list of Blocks that are successors of this block in it's enclosing BlockGraph instance.
        Parameters:
        succs - The a List of Blocks that succede this block.
        See Also:
        BlockGraph
      • getSuccs

        public List<Block> getSuccs()
        Returns the List of Blocks that are successors to this block,
        Returns:
        A list of successorblocks.
        See Also:
        BlockGraph
      • toShortString

        public String toShortString()