edu.umd.cs.findbugs.ba
Class AbstractDataflowAnalysis<Fact>

java.lang.Object
  extended by edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis<Fact>
All Implemented Interfaces:
DataflowAnalysis<Fact>
Direct Known Subclasses:
BackwardDataflowAnalysis, ForwardDataflowAnalysis

public abstract class AbstractDataflowAnalysis<Fact>
extends java.lang.Object
implements DataflowAnalysis<Fact>

Abstract base class providing functionality that will be useful for most dataflow analysis implementations. In particular, it implements the transfer() function by calling down to the transferInstruction() function. It also maintains a map of the dataflow fact for every location in the CFG, which is useful when using the results of the analysis.

Author:
David Hovemeyer
See Also:
Dataflow, DataflowAnalysis

Field Summary
private static boolean DEBUG
           
private  java.util.IdentityHashMap<BasicBlock,Fact> resultFactMap
           
private  java.util.IdentityHashMap<BasicBlock,Fact> startFactMap
           
 
Constructor Summary
AbstractDataflowAnalysis()
           
 
Method Summary
 void endTransfer(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle end, java.lang.Object result)
          Subclasses may override this.
 java.lang.String factToString(Fact fact)
          Call this to get a dataflow value as a String.
 Fact getFactAfterLocation(Location location)
          Get the dataflow fact representing the point just after given Location.
 Fact getFactAtLocation(Location location)
          Get the dataflow fact representing the point just before given Location.
 Fact getResultFact(BasicBlock block)
          Get the result fact for given basic block.
 Fact getStartFact(BasicBlock block)
          Get the start fact for given basic block.
abstract  boolean isFactValid(Fact fact)
          Determine whether the given fact is valid (neither top nor bottom).
private  Fact lookupOrCreateFact(java.util.Map<BasicBlock,Fact> map, BasicBlock block)
           
 java.util.Iterator<Fact> resultFactIterator()
          Get an iterator over the result facts.
 void startTransfer(BasicBlock basicBlock, java.lang.Object fact)
          Subclasses may override this.
 void transfer(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle end, Fact start, Fact result)
          Transfer function for the analysis.
abstract  void transferInstruction(org.apache.bcel.generic.InstructionHandle handle, BasicBlock basicBlock, Fact fact)
          Transfer function for a single instruction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.umd.cs.findbugs.ba.DataflowAnalysis
copy, createFact, getBlockOrder, initEntryFact, initResultFact, isForwards, makeFactTop, meetInto, same
 

Field Detail

DEBUG

private static final boolean DEBUG

startFactMap

private java.util.IdentityHashMap<BasicBlock,Fact> startFactMap

resultFactMap

private java.util.IdentityHashMap<BasicBlock,Fact> resultFactMap
Constructor Detail

AbstractDataflowAnalysis

public AbstractDataflowAnalysis()
Method Detail

transferInstruction

public abstract void transferInstruction(org.apache.bcel.generic.InstructionHandle handle,
                                         BasicBlock basicBlock,
                                         Fact fact)
                                  throws DataflowAnalysisException
Transfer function for a single instruction.

Parameters:
handle - the instruction
basicBlock - the BasicBlock containing the instruction; needed to disambiguate instructions in inlined JSR subroutines
fact - which should be modified based on the instruction
Throws:
DataflowAnalysisException

isFactValid

public abstract boolean isFactValid(Fact fact)
Determine whether the given fact is valid (neither top nor bottom).


startTransfer

public void startTransfer(BasicBlock basicBlock,
                          java.lang.Object fact)
                   throws DataflowAnalysisException
Subclasses may override this. Due to a bug in the 2.2 version of the generics-enabled javac, it is not possible to directly override the transfer() method. This method will be called immediately upon entry to transfer().

Parameters:
basicBlock - the basic block
fact - the start fact for the block
Throws:
DataflowAnalysisException

endTransfer

public void endTransfer(BasicBlock basicBlock,
                        org.apache.bcel.generic.InstructionHandle end,
                        java.lang.Object result)
                 throws DataflowAnalysisException
Subclasses may override this. Due to a bug in the 2.2 version of the generics-enabled javac, it is not possible to directly override the transfer() method. This method will be called just before exiting transfer().

Parameters:
basicBlock - the basic block
end - last instruction analyzed (null if entire block was analyzed)
result - the result fact for the block
Throws:
DataflowAnalysisException

getFactAtLocation

public Fact getFactAtLocation(Location location)
                       throws DataflowAnalysisException
Get the dataflow fact representing the point just before given Location. Note "before" is meant in the logical sense, so for backward analyses, before means after the location in the control flow sense.

Parameters:
location - the location
Returns:
the fact at the point just before the location
Throws:
DataflowAnalysisException

getFactAfterLocation

public Fact getFactAfterLocation(Location location)
                          throws DataflowAnalysisException
Get the dataflow fact representing the point just after given Location. Note "after" is meant in the logical sense, so for backward analyses, after means before the location in the control flow sense.

Throws:
DataflowAnalysisException

resultFactIterator

public java.util.Iterator<Fact> resultFactIterator()
Get an iterator over the result facts.


factToString

public java.lang.String factToString(Fact fact)
Call this to get a dataflow value as a String. By default, we just call toString(). Subclasses may override to get different behavior.


getStartFact

public Fact getStartFact(BasicBlock block)
Description copied from interface: DataflowAnalysis
Get the start fact for given basic block.

Specified by:
getStartFact in interface DataflowAnalysis<Fact>
Parameters:
block - the basic block

getResultFact

public Fact getResultFact(BasicBlock block)
Description copied from interface: DataflowAnalysis
Get the result fact for given basic block.

Specified by:
getResultFact in interface DataflowAnalysis<Fact>
Parameters:
block - the basic block

lookupOrCreateFact

private Fact lookupOrCreateFact(java.util.Map<BasicBlock,Fact> map,
                                BasicBlock block)

transfer

public void transfer(BasicBlock basicBlock,
                     org.apache.bcel.generic.InstructionHandle end,
                     Fact start,
                     Fact result)
              throws DataflowAnalysisException
Description copied from interface: DataflowAnalysis
Transfer function for the analysis. Taking dataflow facts at start (which might be either the entry or exit of the block, depending on whether the analysis is forwards or backwards), modify result to be the facts at the other end of the block.

Specified by:
transfer in interface DataflowAnalysis<Fact>
Parameters:
basicBlock - the basic block
end - if nonnull, stop before considering this instruction; otherwise, consider all of the instructions in the basic block
start - dataflow facts at beginning of block (if forward analysis) or end of block (if backwards analysis)
result - resulting dataflow facts at other end of block
Throws:
DataflowAnalysisException