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
Nested ClassesModifier and TypeClassDescriptionprotected static classA 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
FieldsModifier and TypeFieldDescriptionprotected @MonotonicNonNull ControlFlowGraphThe 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 NodeThe node that is currently handled in the analysis (if it is running).protected @InternedDistinct @Nullable TreeThe tree that is currently being looked at.protected final Analysis.DirectionThe 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 booleanIs the analysis currently running?protected final IdentityHashMap<Node,V> Abstract values of nodes.protected @MonotonicNonNull TThe transfer function for regular nodes.protected final AbstractAnalysis.WorklistThe worklist used for the fix-point iteration. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractAnalysis(Analysis.Direction direction) Implementation of common features forBackwardAnalysisImplandForwardAnalysisImpl. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdd 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 ClassTreeDeprecated.@Nullable MethodTreeDeprecated.@Nullable TreeReturns the tree that is currently being looked at.Get the direction of this analysis.@Nullable ClassTree@Nullable MethodTreeGet theMethodTreeof the current CFG if the argumentTreemaps to aNodein the CFG ornullotherwise.@Nullable SReturns the exceptional exit store.Returns all current node values.@Nullable SReturns 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.@Nullable TGet the transfer function of this analysis.@Nullable V@Nullable Vprotected final voidinit(ControlFlowGraph cfg) Initialize the analysis with a new control flow graph.protected voidInitialize fields of this object based on a given control flow graph.protected abstract voidInitialize the transfer inputs of every basic block before performing the analysis.protected booleanisIgnoredExceptionType(TypeMirror exceptionType) Should exceptional control flow for a particular exception type be ignored?booleanIs the analysis currently running?protected abstract voidpropagateStoresTo(Block nextBlock, Node node, TransferInput<V, S> currentInput, Store.FlowRule flowRule, boolean addToWorklistAgain) Propagate the stores incurrentInputto the next block in the direction of analysis, according to theflowRule.protected voidsetCurrentNode(@Nullable Node currentNode) Set the node that is currently being looked at.voidsetCurrentTree(Tree currentTree) Set the tree that is currently being looked at.protected booleanupdateNodeValues(Node node, TransferResult<V, S> transferResult) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 togetValuewill not return information for this given tree. -
currentInput
The current transfer input when the analysis is running.
-
-
Constructor Details
-
AbstractAnalysis
Implementation of common features forBackwardAnalysisImplandForwardAnalysisImpl.- 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 togetValuewill 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
@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 incurrentInputto 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 toworklistagain
-
isRunning
public boolean isRunning()Description copied from interface:AnalysisIs the analysis currently running? -
getDirection
Description copied from interface:AnalysisGet the direction of this analysis.- Specified by:
getDirectionin 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:AnalysisThe result of running the analysis. This is only available once the analysis finished running. -
getTransferFunction
Description copied from interface:AnalysisGet the transfer function of this analysis.- Specified by:
getTransferFunctionin 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:AnalysisReturns the abstract value forNoden, ornullif 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:AnalysisReturns the regular exit store, ornull, if there is no such store (because the method cannot exit through the regular exit block).- Specified by:
getRegularExitStorein 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:AnalysisReturns the exceptional exit store.- Specified by:
getExceptionalExitStorein 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:AnalysisReturn the abstract value forTreet, ornullif 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 theMethodTreeof the current CFG if the argumentTreemaps to aNodein the CFG ornullotherwise.- Parameters:
t- the given tree- Returns:
- the contained method tree of the given tree
-
getEnclosingMethod
Get theMethodTreeof the current CFG if the argumentTreemaps to aNodein the CFG ornullotherwise.- Parameters:
t- the given tree- Returns:
- the contained method tree of the given tree
-
getContainingClass
Deprecated.Get theClassTreeof the current CFG if the argumentTreemaps to aNodein the CFG ornullotherwise.- Parameters:
t- the given tree- Returns:
- the contained class tree of the given tree
-
getEnclosingClass
Get theClassTreeof the current CFG if the argumentTreemaps to aNodein the CFG ornullotherwise.- 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 atransferInputthat 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:
trueif exceptional control flow due toexceptionTypeshould be ignored,falseotherwise
-
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 nodenodeinnodeValuesto 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. Ifbis already present, the method does nothing.- Parameters:
b- the block to add toworklist
-
getEnclosingClass(com.sun.source.tree.Tree)