Package edu.umd.cs.findbugs.ba
Class CFG
- java.lang.Object
-
- edu.umd.cs.findbugs.graph.AbstractGraph<Edge,BasicBlock>
-
- 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
-
-
Field Summary
Fields Modifier and Type Field Description static int
BUSY
Flag set if CFG is busy (in the process of being refined.static int
FOUND_INEXACT_UNCONDITIONAL_THROWERS
static int
PRUNED_FAILED_ASSERTION_EDGES
Flag set if CFG edges corresponding to failed assertions have been removed.static int
PRUNED_INFEASIBLE_EXCEPTIONS
Flag set if infeasible exception edges have been pruned from the CFG.static int
PRUNED_UNCONDITIONAL_THROWERS
Flag set if normal return edges from calls to methods which unconditionally throw an exception have been removed.static int
REFINED
Flag set if CFG has been "refined"; i.e., to the extent possible, all infeasible edges have been removed.-
Fields inherited from interface edu.umd.cs.findbugs.ba.Debug
VERIFY_INTEGRITY
-
-
Constructor Summary
Constructors Constructor Description CFG()
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.java.lang.Iterable<BasicBlock>
blocks()
void
checkIntegrity()
void
clearFlag(int flags)
Edge
createEdge(BasicBlock source, BasicBlock dest, int type)
Add a unique edge to the graph.java.util.Collection<BasicBlock>
getBlocks(java.util.BitSet labelSet)
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.Location
getExceptionThrowerLocation(Edge exceptionEdge)
Get the Location where exception(s) thrown on given exception edge are thrown.BasicBlock
getExit()
Get the exit node.int
getFlags()
Edge
getIncomingEdgeWithType(BasicBlock basicBlock, int edgeType)
Get the first incoming edge in basic block with given type.Location
getLocationAtEntry()
Get the Location representing the entry to the CFG.java.util.Collection<Location>
getLocationsContainingInstructionWithOffset(int offset)
Get a Collection of Locations which specify the instruction at given bytecode offset.int
getMaxEdgeId()
Get the number of edge labels allocated.org.apache.bcel.generic.MethodGen
getMethodGen()
java.lang.String
getMethodName()
java.lang.String
getMethodSig()
int
getNumBasicBlocks()
Get number of basic blocks.int
getNumNonExceptionSucessors(BasicBlock block)
Get number of non-exception control successors of given basic block.Edge
getOutgoingEdgeWithType(BasicBlock basicBlock, int edgeType)
Get the first outgoing edge in basic block with given type.BasicBlock
getPredecessorWithEdgeType(BasicBlock target, int edgeType)
Get the first predecessor reachable from given edge type.Location
getPreviousLocation(Location loc)
BasicBlock
getSuccessorWithEdgeType(BasicBlock source, int edgeType)
Get the first successor reachable from given edge type.boolean
isFlagSet(int flag)
java.util.Iterator<Location>
locationIterator()
Get an Iterator over the Locations in the control flow graph.java.lang.Iterable<Location>
locations()
Get an Iterator over the Locations in the control flow graph.BasicBlock
lookupBlockByLabel(int blockLabel)
Look up a BasicBlock by its unique label.Edge
lookupEdgeById(int id)
Look up an Edge by its id.java.util.Collection<Location>
orderedLocations()
Returns a collection of locations, ordered according to the compareTo ordering over locations.java.util.Iterator<Edge>
removedEdgeIterator()
Get an Iterator over Edges removed from this CFG.void
removeEdge(Edge edge)
Remove given edge from the graph.void
setFlag(int flags)
void
setFlags(int flags)
void
setMethodGen(org.apache.bcel.generic.MethodGen methodGen)
void
setMethodName(java.lang.String methodName)
-
Methods inherited from class edu.umd.cs.findbugs.graph.AbstractGraph
addVertex, containsVertex, createEdge, edgeIterator, getNumEdgeLabels, getNumEdges, getNumIncomingEdges, getNumOutgoingEdges, getNumVertexLabels, getNumVertices, incomingEdgeIterator, lookupEdge, outgoingEdgeIterator, predecessorIterator, removeVertex, setNumEdgeLabels, setNumVertexLabels, successorIterator, vertexIterator, vertices
-
-
-
-
Field Detail
-
PRUNED_INFEASIBLE_EXCEPTIONS
public static final int PRUNED_INFEASIBLE_EXCEPTIONS
Flag set if infeasible exception edges have been pruned from the CFG.- See Also:
- Constant Field Values
-
PRUNED_UNCONDITIONAL_THROWERS
public static final int PRUNED_UNCONDITIONAL_THROWERS
Flag set if normal return edges from calls to methods which unconditionally throw an exception have been removed.- See Also:
- Constant Field Values
-
REFINED
public static final int REFINED
Flag set if CFG has been "refined"; i.e., to the extent possible, all infeasible edges have been removed.- See Also:
- Constant Field Values
-
PRUNED_FAILED_ASSERTION_EDGES
public static final int PRUNED_FAILED_ASSERTION_EDGES
Flag set if CFG edges corresponding to failed assertions have been removed.- See Also:
- Constant Field Values
-
BUSY
public static final int BUSY
Flag set if CFG is busy (in the process of being refined.- See Also:
- Constant Field Values
-
FOUND_INEXACT_UNCONDITIONAL_THROWERS
public static final int FOUND_INEXACT_UNCONDITIONAL_THROWERS
- See Also:
- Constant Field Values
-
-
Method Detail
-
setMethodName
public void setMethodName(java.lang.String methodName)
- Parameters:
methodName
- The methodName to set.
-
setMethodGen
public void setMethodGen(org.apache.bcel.generic.MethodGen methodGen)
-
getMethodGen
public org.apache.bcel.generic.MethodGen getMethodGen()
-
getMethodName
public java.lang.String getMethodName()
- Returns:
- Returns the methodName.
-
getMethodSig
public java.lang.String getMethodSig()
-
setFlags
public void setFlags(int flags)
-
setFlag
public void setFlag(int flags)
-
clearFlag
public void clearFlag(int flags)
-
getFlags
public int getFlags()
-
isFlagSet
public 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, @Type 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 blockdest
- the destination basic blocktype
- 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
-
lookupBlockByLabel
public BasicBlock lookupBlockByLabel(int blockLabel)
Look up a BasicBlock by its unique label.- Parameters:
blockLabel
- the label of a BasicBlock- Returns:
- the BasicBlock with the given label, or null if there is no such BasicBlock
-
blockIterator
public java.util.Iterator<BasicBlock> blockIterator()
Get an Iterator over the nodes (BasicBlocks) of the control flow graph.
-
blocks
public java.lang.Iterable<BasicBlock> blocks()
-
locationIterator
public java.util.Iterator<Location> locationIterator()
Get an Iterator over the Locations in the control flow graph.
-
locations
public java.lang.Iterable<Location> locations()
Get an Iterator over the Locations in the control flow graph.
-
orderedLocations
public java.util.Collection<Location> orderedLocations()
Returns a collection of locations, ordered according to the compareTo ordering over locations. If you want to list all the locations in a CFG for debugging purposes, this is a good order to do so in.- Returns:
- collection of locations
-
getBlocks
public java.util.Collection<BasicBlock> getBlocks(java.util.BitSet labelSet)
Get Collection of basic blocks whose IDs are specified by given BitSet.- Parameters:
labelSet
- BitSet of block labels- 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
-
getLocationsContainingInstructionWithOffset
public java.util.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
-
getPredecessorWithEdgeType
public BasicBlock getPredecessorWithEdgeType(BasicBlock target, @Type int edgeType)
Get the first predecessor reachable from given edge type.- Parameters:
target
- the target blockedgeType
- 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, @Type int edgeType)
Get the first successor reachable from given edge type.- Parameters:
source
- the source blockedgeType
- the edge type leading to the successor- Returns:
- the successor, or null if there is no outgoing edge with the specified edge type
-
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
-
removedEdgeIterator
public java.util.Iterator<Edge> removedEdgeIterator()
Get an Iterator over Edges removed from this CFG.- Returns:
- Iterator over Edges removed from this CFG
-
getIncomingEdgeWithType
public Edge getIncomingEdgeWithType(BasicBlock basicBlock, @Type int edgeType)
Get the first incoming edge in basic block with given type.- Parameters:
basicBlock
- the basic blockedgeType
- the edge type- Returns:
- the Edge, or null if there is no edge with that edge type
-
getOutgoingEdgeWithType
public Edge getOutgoingEdgeWithType(BasicBlock basicBlock, @Type int edgeType)
Get the first outgoing edge in basic block with given type.- Parameters:
basicBlock
- the basic blockedgeType
- 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 classAbstractGraph<Edge,BasicBlock>
-
removeEdge
public void removeEdge(Edge edge)
Description copied from interface:Graph
Remove given edge from the graph.- Specified by:
removeEdge
in interfaceGraph<Edge,BasicBlock>
- Overrides:
removeEdge
in classAbstractGraph<Edge,BasicBlock>
-
getNumNonExceptionSucessors
public int getNumNonExceptionSucessors(BasicBlock block)
Get number of non-exception control successors of given basic block.- Parameters:
block
- a BasicBlock- Returns:
- number of non-exception control successors of the basic block
-
getLocationAtEntry
public Location getLocationAtEntry()
Get the Location representing the entry to the CFG. Note that this is a "fake" Location, and shouldn't be relied on to yield source line information.- Returns:
- Location at entry to CFG
-
-