Class AbstractAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
- java.lang.Object
-
- org.checkerframework.dataflow.analysis.AbstractAnalysis<V,S,T>
-
- Type Parameters:
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 behavior
- All Implemented Interfaces:
Analysis<V,S,T>
- Direct Known Subclasses:
BackwardAnalysisImpl
,ForwardAnalysisImpl
public abstract class AbstractAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>> extends java.lang.Object implements Analysis<V,S,T>
Implementation of common features forBackwardAnalysisImpl
andForwardAnalysisImpl
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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.-
Nested classes/interfaces inherited from interface org.checkerframework.dataflow.analysis.Analysis
Analysis.BeforeOrAfter, Analysis.Direction
-
-
Field Summary
Fields Modifier and Type Field 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 com.sun.source.tree.Tree
currentTree
The tree that is currently being looked at.protected Analysis.Direction
direction
The direction of this analysis.protected java.util.HashMap<javax.lang.model.element.VariableElement,V>
finalLocalValues
Map from (effectively final) local variable elements to their abstract value.protected java.util.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 java.util.IdentityHashMap<Node,V>
nodeValues
Abstract values of nodes.protected @MonotonicNonNull T
transferFunction
The transfer function for regular nodes.protected AbstractAnalysis.Worklist
worklist
The worklist used for the fix-point iteration.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractAnalysis(Analysis.Direction direction)
Implementation of common features forBackwardAnalysisImpl
andForwardAnalysisImpl
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addToWorklist(Block b)
Add a basic block toworklist
.protected TransferResult<V,S>
callTransferFunction(Node node, TransferInput<V,S> transferInput)
Call the transfer function for nodenode
, and set that node as current node first.@Nullable com.sun.source.tree.ClassTree
getContainingClass(com.sun.source.tree.Tree t)
Get theClassTree
of the current CFG if the argumentTree
maps to aNode
in the CFG ornull
otherwise.@Nullable com.sun.source.tree.MethodTree
getContainingMethod(com.sun.source.tree.Tree t)
Get theMethodTree
of the current CFG if the argumentTree
maps to aNode
in the CFG ornull
otherwise.@Nullable com.sun.source.tree.Tree
getCurrentTree()
Returns the tree that is currently being looked at.Analysis.Direction
getDirection()
Get the direction of this analysis.@Nullable S
getExceptionalExitStore()
Returns the exceptional exit store.@Nullable java.util.Set<Node>
getNodesForTree(com.sun.source.tree.Tree t)
Get the set ofNode
s for a givenTree
.java.util.IdentityHashMap<Node,V>
getNodeValues()
Returns all current node values.@Nullable S
getRegularExitStore()
Returns the regular exit store, ornull
, 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.@Nullable T
getTransferFunction()
Get the transfer function of this analysis.@Nullable V
getValue(com.sun.source.tree.Tree t)
Return the abstract value forTree
t
, ornull
if no information is available.@Nullable V
getValue(Node n)
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(javax.lang.model.type.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 incurrentInput
to the next block in the direction of analysis, according to theflowRule
.protected static <S> @Nullable S
readFromStore(java.util.Map<Block,S> stores, Block b)
Read the store for a particular basic block from a map of stores (ornull
if none exists yet).protected void
setCurrentNode(@Nullable Node currentNode)
Set the node that is currently being looked at.void
setCurrentTree(com.sun.source.tree.Tree currentTree)
Set the tree that is currently being looked at.protected boolean
updateNodeValues(Node node, TransferResult<V,S> transferResult)
Updates the value of nodenode
to the value of thetransferResult
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.checkerframework.dataflow.analysis.Analysis
getInput, performAnalysis, performAnalysisBlock, runAnalysisFor
-
-
-
-
Field Detail
-
direction
protected final Analysis.Direction direction
The direction of this analysis.
-
isRunning
protected boolean isRunning
Is the analysis currently running?
-
transferFunction
protected @MonotonicNonNull T extends TransferFunction<V,S> transferFunction
The transfer function for regular nodes.
-
cfg
protected @MonotonicNonNull ControlFlowGraph cfg
The current control flow graph to perform the analysis on.
-
inputs
protected final java.util.IdentityHashMap<Block,TransferInput<V extends AbstractValue<V>,S extends Store<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).
-
worklist
protected final AbstractAnalysis.Worklist worklist
The worklist used for the fix-point iteration.
-
nodeValues
protected final java.util.IdentityHashMap<Node,V extends AbstractValue<V>> nodeValues
Abstract values of nodes.
-
finalLocalValues
protected final java.util.HashMap<javax.lang.model.element.VariableElement,V extends AbstractValue<V>> finalLocalValues
Map from (effectively final) local variable elements to their abstract value.
-
currentNode
protected @InternedDistinct @Nullable Node currentNode
The node that is currently handled in the analysis (if it is running). The following invariant holds:!isRunning ⇒ (currentNode == null)
-
currentTree
protected @InternedDistinct @Nullable com.sun.source.tree.Tree currentTree
The tree that is currently being looked at. The transfer function can set this tree to make sure that calls togetValue
will not return information for this given tree.
-
currentInput
protected @Nullable TransferInput<V extends AbstractValue<V>,S extends Store<S>> currentInput
The current transfer input when the analysis is running.
-
-
Constructor Detail
-
AbstractAnalysis
protected AbstractAnalysis(Analysis.Direction direction)
Implementation of common features forBackwardAnalysisImpl
andForwardAnalysisImpl
.- Parameters:
direction
- direction of the analysis
-
-
Method Detail
-
getCurrentTree
public @Nullable com.sun.source.tree.Tree getCurrentTree()
Returns the tree that is currently being looked at. The transfer function can set this tree to make sure that calls togetValue
will not return information for this given tree.- Returns:
- the tree that is currently being looked at
-
setCurrentTree
public void setCurrentTree(@FindDistinct com.sun.source.tree.Tree currentTree)
Set the tree that is currently being looked at.- Parameters:
currentTree
- the tree that should be currently looked at
-
setCurrentNode
protected void setCurrentNode(@FindDistinct @Nullable Node currentNode)
Set the node that is currently being looked at.- Parameters:
currentNode
- the node that should be currently looked at
-
initInitialInputs
@RequiresNonNull("cfg") protected abstract void initInitialInputs()
Initialize the transfer inputs of every basic block before performing the analysis.
-
propagateStoresTo
protected abstract void propagateStoresTo(Block nextBlock, Node node, TransferInput<V,S> currentInput, Store.FlowRule flowRule, boolean addToWorklistAgain)
Propagate the stores incurrentInput
to the next block in the direction of analysis, according to theflowRule
.- Parameters:
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 toworklist
again
-
isRunning
public boolean isRunning()
Description copied from interface:Analysis
Is the analysis currently running?
-
getDirection
public Analysis.Direction getDirection()
Description copied from interface:Analysis
Get the direction of this analysis.- Specified by:
getDirection
in interfaceAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
- Returns:
- the direction of this analysis
-
getResult
@RequiresNonNull("cfg") public AnalysisResult<V,S> getResult()
Description copied from interface:Analysis
The result of running the analysis. This is only available once the analysis finished running.
-
getTransferFunction
public @Nullable T getTransferFunction()
Description copied from interface:Analysis
Get the transfer function of this analysis.- Specified by:
getTransferFunction
in interfaceAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
- Returns:
- the transfer function of this analysis
-
getValue
public @Nullable V getValue(Node n)
Description copied from interface:Analysis
Returns the abstract value forNode
n
, ornull
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.
-
getNodeValues
public java.util.IdentityHashMap<Node,V> getNodeValues()
Returns all current node values.- Returns:
nodeValues
-
getRegularExitStore
@RequiresNonNull("cfg") public @Nullable S getRegularExitStore()
Description copied from interface:Analysis
Returns the regular exit store, ornull
, if there is no such store (because the method cannot exit through the regular exit block).- Specified by:
getRegularExitStore
in interfaceAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
- Returns:
- the regular exit store, or
null
, if there is no such store (because the method cannot exit through the regular exit block)
-
getExceptionalExitStore
@RequiresNonNull("cfg") public @Nullable S getExceptionalExitStore()
Description copied from interface:Analysis
Returns the exceptional exit store.- Specified by:
getExceptionalExitStore
in interfaceAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
- Returns:
- the exceptional exit store
-
getNodesForTree
public @Nullable java.util.Set<Node> getNodesForTree(com.sun.source.tree.Tree t)
Get the set ofNode
s for a givenTree
. Returns null for trees that don't produce a value.- Parameters:
t
- the given tree- Returns:
- the set of corresponding nodes to the given tree
-
getValue
public @Nullable V getValue(com.sun.source.tree.Tree t)
Description copied from interface:Analysis
Return the abstract value forTree
t
, ornull
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.
-
getContainingMethod
public @Nullable com.sun.source.tree.MethodTree getContainingMethod(com.sun.source.tree.Tree t)
Get theMethodTree
of the current CFG if the argumentTree
maps to aNode
in the CFG ornull
otherwise.- Parameters:
t
- the given tree- Returns:
- the contained method tree of the given tree
-
getContainingClass
public @Nullable com.sun.source.tree.ClassTree getContainingClass(com.sun.source.tree.Tree t)
Get theClassTree
of the current CFG if the argumentTree
maps to aNode
in the CFG ornull
otherwise.- Parameters:
t
- the given tree- Returns:
- the contained class tree of the given tree
-
callTransferFunction
protected TransferResult<V,S> callTransferFunction(Node node, TransferInput<V,S> transferInput)
Call the transfer function for nodenode
, and set that node as current node first. This method requires atransferInput
that the method can modify.- Parameters:
node
- the given nodetransferInput
- the transfer input- Returns:
- the output of the transfer function
-
init
protected final void init(ControlFlowGraph cfg)
Initialize the analysis with a new control flow graph.- Parameters:
cfg
- the control flow graph to use
-
isIgnoredExceptionType
protected boolean isIgnoredExceptionType(javax.lang.model.type.TypeMirror exceptionType)
Should exceptional control flow for a particular exception type be ignored?The default implementation always returns
false
. Subclasses should override the method to implement a different policy.- Parameters:
exceptionType
- the exception type- Returns:
true
if exceptional control flow due toexceptionType
should be ignored,false
otherwise
-
initFields
@EnsuresNonNull("this.cfg") protected void initFields(ControlFlowGraph cfg)
Initialize fields of this object based on a given control flow graph. Sub-class may override this method to initialize customized fields.- Parameters:
cfg
- a given control flow graph
-
updateNodeValues
protected boolean updateNodeValues(Node node, TransferResult<V,S> transferResult)
Updates the value of nodenode
to the value of thetransferResult
. Returns true if the node's value changed, or a store was updated.- Parameters:
node
- the node to updatetransferResult
- the transfer result being updated- Returns:
- true if the node's value changed, or a store was updated
-
readFromStore
protected static <S> @Nullable S readFromStore(java.util.Map<Block,S> stores, Block b)
Read the store for a particular basic block from a map of stores (ornull
if none exists yet).- Type Parameters:
S
- method return type should be a subtype ofStore
- Parameters:
stores
- a map of storesb
- the target block- Returns:
- the store for the target block
-
-