V - the abstract value type to be tracked by the analysisS - the store type used in the analysisT - the transfer function type that is used to approximated runtime behaviorpublic abstract class AbstractAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>> extends Object implements Analysis<V,S,T>
BackwardAnalysisImpl and ForwardAnalysisImpl.| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractAnalysis.Worklist
A worklist is a priority queue of blocks in which the order is given by depth-first ordering to
place non-loop predecessors ahead of successors.
|
Analysis.BeforeOrAfter, Analysis.Direction| Modifier and Type | Field and Description |
|---|---|
protected @MonotonicNonNull ControlFlowGraph |
cfg
The current control flow graph to perform the analysis on.
|
protected @Nullable TransferInput<V,S> |
currentInput
The current transfer input when the analysis is running.
|
protected @InternedDistinct @Nullable Node |
currentNode
The node that is currently handled in the analysis (if it is running).
|
protected @InternedDistinct @Nullable Tree |
currentTree
The tree that is currently being looked at.
|
protected Analysis.Direction |
direction
The direction of this analysis.
|
protected HashMap<Element,V> |
finalLocalValues
Map from (effectively final) local variable elements to their abstract value.
|
protected IdentityHashMap<Block,TransferInput<V,S>> |
inputs
The transfer inputs of every basic block (assumed to be 'no information' if not present, inputs
before blocks in forward analysis, after blocks in backward analysis).
|
protected boolean |
isRunning
Is the analysis currently running?
|
protected IdentityHashMap<Node,V> |
nodeValues
Abstract values of nodes.
|
protected T |
transferFunction
The transfer function for regular nodes.
|
protected AbstractAnalysis.Worklist |
worklist
The worklist used for the fix-point iteration.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractAnalysis(Analysis.Direction direction)
Implementation of common features for
BackwardAnalysisImpl and ForwardAnalysisImpl. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addToWorklist(Block b)
Add a basic block to
worklist. |
protected TransferResult<V,S> |
callTransferFunction(Node node,
TransferInput<V,S> transferInput)
Call the transfer function for node
node, and set that node as current node first. |
@Nullable ClassTree |
getContainingClass(Tree t)
|
@Nullable MethodTree |
getContainingMethod(Tree t)
Get the
MethodTree of the current CFG if the argument Tree maps to a Node in the CFG or null otherwise. |
@Nullable Tree |
getCurrentTree()
Returns the tree that is currently being looked at.
|
Analysis.Direction |
getDirection()
Get the direction of this analysis.
|
S |
getExceptionalExitStore()
Returns the exceptional exit store.
|
@Nullable Set<Node> |
getNodesForTree(Tree t)
|
IdentityHashMap<Node,V> |
getNodeValues()
Returns all current node values.
|
S |
getRegularExitStore()
Returns the regular exit store, or
null, if there is no such store (because the method
cannot exit through the regular exit block). |
AnalysisResult<V,S> |
getResult()
The result of running the analysis.
|
T |
getTransferFunction()
Get the transfer function of this analysis.
|
V |
getValue(Node n)
|
V |
getValue(Tree t)
|
protected void |
init(ControlFlowGraph cfg)
Initialize the analysis with a new control flow graph.
|
protected void |
initFields(ControlFlowGraph cfg)
Initialize fields of this object based on a given control flow graph.
|
protected abstract void |
initInitialInputs()
Initialize the transfer inputs of every basic block before performing the analysis.
|
protected boolean |
isIgnoredExceptionType(TypeMirror exceptionType)
Should exceptional control flow for a particular exception type be ignored?
|
boolean |
isRunning()
Is the analysis currently running?
|
protected abstract void |
propagateStoresTo(Block nextBlock,
Node node,
TransferInput<V,S> currentInput,
Store.FlowRule flowRule,
boolean addToWorklistAgain)
Propagate the stores in
currentInput to the next block in the direction of analysis,
according to the flowRule. |
protected static <S> S |
readFromStore(Map<Block,S> stores,
Block b)
Read the store for a particular basic block from a map of stores (or
null if none
exists yet). |
protected void |
setCurrentNode(@Nullable Node currentNode)
Set the node that is currently being looked at.
|
void |
setCurrentTree(Tree currentTree)
Set the tree that is currently being looked at.
|
protected boolean |
updateNodeValues(Node node,
TransferResult<V,S> transferResult)
Updates the value of node
node to the value of the transferResult. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetInput, performAnalysis, performAnalysisBlock, runAnalysisForprotected final Analysis.Direction direction
protected boolean isRunning
protected T extends TransferFunction<V,S> transferFunction
protected @MonotonicNonNull ControlFlowGraph cfg
protected final IdentityHashMap<Block,TransferInput<V extends AbstractValue<V>,S extends Store<S>>> inputs
protected final AbstractAnalysis.Worklist worklist
protected final IdentityHashMap<Node,V extends AbstractValue<V>> nodeValues
protected final HashMap<Element,V extends AbstractValue<V>> finalLocalValues
protected @InternedDistinct @Nullable Node currentNode
!isRunning ⇒ (currentNode == null)
protected @InternedDistinct @Nullable Tree currentTree
getValue will not return information for this given tree.protected @Nullable TransferInput<V extends AbstractValue<V>,S extends Store<S>> currentInput
protected AbstractAnalysis(Analysis.Direction direction)
BackwardAnalysisImpl and ForwardAnalysisImpl.direction - direction of the analysispublic @Nullable Tree getCurrentTree()
getValue will not return information for this given tree.public void setCurrentTree(@FindDistinct Tree currentTree)
currentTree - the tree that should be currently looked atprotected void setCurrentNode(@FindDistinct @Nullable Node currentNode)
currentNode - the node that should be currently looked at@RequiresNonNull(value="cfg") protected abstract void initInitialInputs()
protected abstract void propagateStoresTo(Block nextBlock, Node node, TransferInput<V,S> currentInput, Store.FlowRule flowRule, boolean addToWorklistAgain)
currentInput to the next block in the direction of analysis,
according to the flowRule.nextBlock - the target block to propagate the stores tonode - the node of the target blockcurrentInput - the current transfer inputflowRule - the flow rule being usedaddToWorklistAgain - whether the block should be added to worklist againpublic boolean isRunning()
Analysispublic Analysis.Direction getDirection()
AnalysisgetDirection in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>@RequiresNonNull(value="cfg") public AnalysisResult<V,S> getResult()
Analysispublic T getTransferFunction()
AnalysisgetTransferFunction in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>public V getValue(Node n)
AnalysisNode n, or null if no information is
available. Note that if the analysis has not finished yet, this value might not represent the
final value for this node.public IdentityHashMap<Node,V> getNodeValues()
nodeValues@RequiresNonNull(value="cfg") public S getRegularExitStore()
Analysisnull, if there is no such store (because the method
cannot exit through the regular exit block).getRegularExitStore in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>null, if there is no such store (because the method
cannot exit through the regular exit block)@RequiresNonNull(value="cfg") public S getExceptionalExitStore()
AnalysisgetExceptionalExitStore in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>public @Nullable Set<Node> getNodesForTree(Tree t)
t - the given treepublic V getValue(Tree t)
AnalysisTree t, or null if no information is
available. Note that if the analysis has not finished yet, this value might not represent the
final value for this node.public @Nullable MethodTree getContainingMethod(Tree t)
MethodTree of the current CFG if the argument Tree maps to a Node in the CFG or null otherwise.t - the given treepublic @Nullable ClassTree getContainingClass(Tree t)
ClassTree of the current CFG if the argument Tree maps to a Node in the CFG or null otherwise.t - the given treeprotected TransferResult<V,S> callTransferFunction(Node node, TransferInput<V,S> transferInput)
node, and set that node as current node first. This
method requires a transferInput that the method can modify.node - the given nodetransferInput - the transfer inputprotected final void init(ControlFlowGraph cfg)
cfg - the control flow graph to useprotected boolean isIgnoredExceptionType(TypeMirror exceptionType)
The default implementation always returns false. Subclasses should override the
method to implement a different policy.
exceptionType - the exception typetrue if exceptional control flow due to exceptionType should be
ignored, false otherwise@EnsuresNonNull(value="this.cfg") protected void initFields(ControlFlowGraph cfg)
cfg - a given control flow graphprotected boolean updateNodeValues(Node node, TransferResult<V,S> transferResult)
node to the value of the transferResult. Returns true
if the node's value changed, or a store was updated.node - the node to updatetransferResult - the transfer result being updatedprotected static <S> S readFromStore(Map<Block,S> stores, Block b)
null if none
exists yet).S - method return type should be a subtype of Storestores - a map of storesb - the target block