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 approximate run-time 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 Object
implements Analysis<V,S,T>
Implementation of common features for
BackwardAnalysisImpl
and ForwardAnalysisImpl
.-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
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
Modifier and TypeFieldDescriptionprotected @MonotonicNonNull ControlFlowGraph
The current control flow graph to perform the analysis on.protected @Nullable TransferInput<V,
S> The current transfer input when the analysis is running.protected @InternedDistinct @Nullable Node
The node that is currently handled in the analysis (if it is running).protected @InternedDistinct @Nullable Tree
The tree that is currently being looked at.protected final Analysis.Direction
The direction of this analysis.protected final HashMap<VariableElement,
V> Map from (effectively final) local variable elements to their abstract value.protected final IdentityHashMap<Block,
TransferInput<V, S>> The transfer inputs of every basic block; assumed to be 'no information' if not present.protected boolean
Is the analysis currently running?protected final IdentityHashMap<Node,
V> Abstract values of nodes.protected @MonotonicNonNull T
The transfer function for regular nodes.protected final AbstractAnalysis.Worklist
The worklist used for the fix-point iteration. -
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractAnalysis
(Analysis.Direction direction) Implementation of common features forBackwardAnalysisImpl
andForwardAnalysisImpl
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
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.Deprecated.Deprecated.Returns the tree that is currently being looked at.Get the direction of this analysis.Get theMethodTree
of the current CFG if the argumentTree
maps to aNode
in the CFG ornull
otherwise.Returns the exceptional exit store.Returns all current node values.Returns the regular exit store, ornull
, if there is no such store (because the method cannot exit through the regular exit block).The result of running the analysis.Get the transfer function of this analysis.protected final void
init
(ControlFlowGraph cfg) Initialize the analysis with a new control flow graph.protected void
Initialize fields of this object based on a given control flow graph.protected abstract void
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
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 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) 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 Details
-
direction
The direction of this analysis. -
isRunning
protected boolean isRunningIs the analysis currently running? -
transferFunction
The transfer function for regular nodes. -
cfg
The current control flow graph to perform the analysis on. -
inputs
protected final IdentityHashMap<Block,TransferInput<V extends AbstractValue<V>, inputsS extends Store<S>>> The transfer inputs of every basic block; assumed to be 'no information' if not present. The inputs are before blocks in forward analysis, and are after blocks in backward analysis. -
worklist
The worklist used for the fix-point iteration. -
nodeValues
Abstract values of nodes. -
finalLocalValues
Map from (effectively final) local variable elements to their abstract value. -
currentNode
The node that is currently handled in the analysis (if it is running). The following invariant holds:!isRunning ⇒ (currentNode == null)
-
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
The current transfer input when the analysis is running.
-
-
Constructor Details
-
AbstractAnalysis
Implementation of common features forBackwardAnalysisImpl
andForwardAnalysisImpl
.- Parameters:
direction
- direction of the analysis
-
-
Method Details
-
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
Set the tree that is currently being looked at.- Parameters:
currentTree
- the tree that should be currently looked at
-
setCurrentNode
Set the node that is currently being looked at.- Parameters:
currentNode
- the node that should be currently looked at
-
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
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
Description copied from interface:Analysis
The result of running the analysis. This is only available once the analysis finished running. -
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
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
Returns all current node values.- Returns:
nodeValues
-
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
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
- Parameters:
t
- the given tree- Returns:
- the set of corresponding nodes to the given tree
-
getValue
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
Deprecated.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
-
getEnclosingMethod
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
Deprecated.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
-
getEnclosingClass
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
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
Initialize the analysis with a new control flow graph.- Parameters:
cfg
- the control flow graph to use
-
isIgnoredExceptionType
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
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
Updates the value of nodenode
innodeValues
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
-
addToWorklist
Add a basic block toworklist
. Ifb
is already present, the method does nothing.- Parameters:
b
- the block to add toworklist
-
getEnclosingClass(com.sun.source.tree.Tree)