edu.umd.cs.findbugs.ba

Class CFG

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

Simple control flow graph abstraction for BCEL.

See Also: BasicBlock Edge

Constructor Summary
CFG()
Constructor.
Method Summary
BasicBlockallocate()
Allocate a new BasicBlock.
Iterator<BasicBlock>blockIterator()
Get an Iterator over the nodes (BasicBlocks) of the control flow graph.
voidcheckIntegrity()
EdgecreateEdge(BasicBlock source, BasicBlock dest, int type)
Add a unique edge to the graph.
Collection<BasicBlock>getBlocks(BitSet idSet)
Get Collection of basic blocks whose IDs are specified by given BitSet.
Collection<BasicBlock>getBlocksContainingInstructionWithOffset(int offset)
Get a Collection of basic blocks which contain the bytecode instruction with given offset.
BasicBlockgetEntry()
Get the entry node.
LocationgetExceptionThrowerLocation(Edge exceptionEdge)
Get the Location where exception(s) thrown on given exception edge are thrown.
BasicBlockgetExit()
Get the exit node.
EdgegetIncomingEdgeWithType(BasicBlock basicBlock, int edgeType)
Get the first incoming edge in basic block with given type.
Collection<Location>getLocationsContainingInstructionWithOffset(int offset)
Get a Collection of Locations which specify the instruction at given bytecode offset.
intgetMaxEdgeId()
Get the number of edge labels allocated.
MethodGengetMethodGen()
StringgetMethodName()
intgetNumBasicBlocks()
Get number of basic blocks.
EdgegetOutgoingEdgeWithType(BasicBlock basicBlock, int edgeType)
Get the first outgoing edge in basic block with given type.
BasicBlockgetPredecessorWithEdgeType(BasicBlock target, int edgeType)
Get the first predecessor reachable from given edge type.
BasicBlockgetSuccessorWithEdgeType(BasicBlock source, int edgeType)
Get the first successor reachable from given edge type.
Iterator<Location>locationIterator()
Get an Iterator over the Locations in the control flow graph.
EdgelookupEdgeById(int id)
Look up an Edge by its id.
voidsetMethodGen(MethodGen methodGen)
voidsetMethodName(String methodName)

Constructor Detail

CFG

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

Method Detail

allocate

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

blockIterator

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

checkIntegrity

public void checkIntegrity()

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: IllegalStateException if there is already an edge in the CFG with the same source and destination block

getBlocks

public Collection<BasicBlock> getBlocks(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 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

getEntry

public BasicBlock getEntry()
Get the entry node.

getExceptionThrowerLocation

public Location getExceptionThrowerLocation(Edge exceptionEdge)
Get the Location where exception(s) thrown on given exception edge are thrown.

Parameters: exceptionEdge the exception Edge

Returns: Location where exception(s) are thrown from

getExit

public BasicBlock getExit()
Get the exit node.

getIncomingEdgeWithType

public Edge getIncomingEdgeWithType(BasicBlock basicBlock, int edgeType)
Get the first incoming 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

getLocationsContainingInstructionWithOffset

public Collection<Location> getLocationsContainingInstructionWithOffset(int offset)
Get a Collection of Locations which specify the instruction at given bytecode offset.

Parameters: offset the bytecode offset

Returns: all Locations referring to the instruction at that offset

getMaxEdgeId

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

getMethodGen

public MethodGen getMethodGen()

getMethodName

public String getMethodName()

Returns: Returns the methodName.

getNumBasicBlocks

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

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

getPredecessorWithEdgeType

public BasicBlock getPredecessorWithEdgeType(BasicBlock target, int edgeType)
Get the first predecessor reachable from given edge type.

Parameters: target the target block edgeType the edge type leading from the predecessor

Returns: the predecessor, or null if there is no incoming edge with the specified edge type

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

locationIterator

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

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

setMethodGen

public void setMethodGen(MethodGen methodGen)

setMethodName

public void setMethodName(String methodName)

Parameters: methodName The methodName to set.

FindBugs™ is licenced under the LGPL. Copyright © 2006 University of Maryland.