edu.umd.cs.findbugs.ba
Class CFG

java.lang.Object
  extended by edu.umd.cs.findbugs.graph.AbstractGraph<Edge,BasicBlock>
      extended by edu.umd.cs.findbugs.ba.CFG
All Implemented Interfaces:
Debug, Graph<Edge,BasicBlock>

public class CFG
extends AbstractGraph<Edge,BasicBlock>
implements Debug

Simple control flow graph abstraction for BCEL.

See Also:
BasicBlock, Edge

Nested Class Summary
private  class CFG.LocationIterator
          An Iterator over the Locations in the CFG.
 
Field Summary
private  BasicBlock entry
           
private  BasicBlock exit
           
private  int flags
           
 
Fields inherited from interface edu.umd.cs.findbugs.ba.Debug
CHECK_ASSERTIONS, VERIFY_INTEGRITY
 
Constructor Summary
CFG()
          Constructor.
 
Method Summary
 BasicBlock allocate()
          Allocate a new BasicBlock.
protected  Edge allocateEdge(BasicBlock source, BasicBlock target)
           
 java.util.Iterator<BasicBlock> blockIterator()
          Get an Iterator over the nodes (BasicBlocks) of the control flow graph.
 void checkIntegrity()
           
 Edge createEdge(BasicBlock source, BasicBlock dest, int type)
          Add a unique edge to the graph.
 java.util.Collection<BasicBlock> getBlocks(java.util.BitSet idSet)
          Get Collection of basic blocks whose IDs are specified by given BitSet.
 java.util.Collection<BasicBlock> getBlocksContainingInstructionWithOffset(int offset)
          Get a Collection of basic blocks which contain the bytecode instruction with given offset.
 BasicBlock getEntry()
          Get the entry node.
 BasicBlock getExit()
          Get the exit node.
(package private)  int getFlags()
           
 int getMaxEdgeId()
          Get the number of edge labels allocated.
 int getNumBasicBlocks()
          Get number of basic blocks.
 Edge getOutgoingEdgeWithType(BasicBlock basicBlock, int edgeType)
          Get the first outgoing edge in basic block with given type.
 BasicBlock getSuccessorWithEdgeType(BasicBlock source, int edgeType)
          Get the first successor reachable from given edge type.
(package private)  boolean isFlagSet(int flag)
           
 java.util.Iterator<Location> locationIterator()
          Get an Iterator over the Locations in the control flow graph.
 Edge lookupEdgeById(int id)
          Look up an Edge by its id.
(package private)  void setFlags(int flags)
           
 
Methods inherited from class edu.umd.cs.findbugs.graph.AbstractGraph
addVertex, containsVertex, createEdge, edgeIterator, getNumEdgeLabels, getNumEdges, getNumIncomingEdges, getNumOutgoingEdges, getNumVertexLabels, getNumVertices, incomingEdgeIterator, lookupEdge, outgoingEdgeIterator, predecessorIterator, removeEdge, removeVertex, setNumEdgeLabels, setNumVertexLabels, successorIterator, vertexIterator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entry

private BasicBlock entry

exit

private BasicBlock exit

flags

private int flags
Constructor Detail

CFG

public CFG()
Constructor. Creates empty control flow graph (with just entry and exit nodes).

Method Detail

setFlags

void setFlags(int flags)

getFlags

int getFlags()

isFlagSet

boolean isFlagSet(int flag)

getEntry

public BasicBlock getEntry()
Get the entry node.


getExit

public BasicBlock getExit()
Get the exit node.


createEdge

public Edge createEdge(BasicBlock source,
                       BasicBlock dest,
                       int type)
Add a unique edge to the graph. There must be no other edge already in the CFG with the same source and destination blocks.

Parameters:
source - the source basic block
dest - the destination basic block
type - the type of edge; see constants in EdgeTypes interface
Returns:
the newly created Edge
Throws:
java.lang.IllegalStateException - if there is already an edge in the CFG with the same source and destination block

lookupEdgeById

public Edge lookupEdgeById(int id)
Look up an Edge by its id.

Parameters:
id - the id of the edge to look up
Returns:
the Edge, or null if no matching Edge was found

blockIterator

public java.util.Iterator<BasicBlock> blockIterator()
Get an Iterator over the nodes (BasicBlocks) of the control flow graph.


locationIterator

public java.util.Iterator<Location> locationIterator()
Get an Iterator over the Locations in the control flow graph.


getBlocks

public java.util.Collection<BasicBlock> getBlocks(java.util.BitSet idSet)
Get Collection of basic blocks whose IDs are specified by given BitSet.

Parameters:
idSet - BitSet of block IDs
Returns:
a Collection containing the blocks whose IDs are given

getBlocksContainingInstructionWithOffset

public java.util.Collection<BasicBlock> getBlocksContainingInstructionWithOffset(int offset)
Get a Collection of basic blocks which contain the bytecode instruction with given offset.

Parameters:
offset - the bytecode offset of an instruction
Returns:
Collection of BasicBlock objects which contain the instruction with that offset

getSuccessorWithEdgeType

public BasicBlock getSuccessorWithEdgeType(BasicBlock source,
                                           int edgeType)
Get the first successor reachable from given edge type.

Parameters:
source - the source block
edgeType - the edge type leading to the successor
Returns:
the successor, or null if there is no outgoing edge with the specified edge type

getOutgoingEdgeWithType

public Edge getOutgoingEdgeWithType(BasicBlock basicBlock,
                                    int edgeType)
Get the first outgoing edge in basic block with given type.

Parameters:
basicBlock - the basic block
edgeType - the edge type
Returns:
the Edge, or null if there is no edge with that edge type

allocate

public BasicBlock allocate()
Allocate a new BasicBlock. The block won't be connected to any node in the graph.


getNumBasicBlocks

public int getNumBasicBlocks()
Get number of basic blocks. This is just here for compatibility with the old CFG method names.


getMaxEdgeId

public int getMaxEdgeId()
Get the number of edge labels allocated. This is just here for compatibility with the old CFG method names.


checkIntegrity

public void checkIntegrity()

allocateEdge

protected Edge allocateEdge(BasicBlock source,
                            BasicBlock target)
Specified by:
allocateEdge in class AbstractGraph<Edge,BasicBlock>