Class ForwardAnalysisImpl<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
- java.lang.Object
-
- org.checkerframework.dataflow.analysis.AbstractAnalysis<V,S,T>
-
- org.checkerframework.dataflow.analysis.ForwardAnalysisImpl<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 runtime behavior
- All Implemented Interfaces:
Analysis<V,S,T>
,ForwardAnalysis<V,S,T>
- Direct Known Subclasses:
CFAbstractAnalysis
public class ForwardAnalysisImpl<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>> extends AbstractAnalysis<V,S,T> implements ForwardAnalysis<V,S,T>
An implementation of a forward analysis to solve a org.checkerframework.dataflow problem given a control flow graph and a forward transfer function.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.checkerframework.dataflow.analysis.AbstractAnalysis
AbstractAnalysis.Worklist
-
Nested classes/interfaces inherited from interface org.checkerframework.dataflow.analysis.Analysis
Analysis.BeforeOrAfter, Analysis.Direction
-
-
Field Summary
Fields Modifier and Type Field Description protected @Nullable java.util.IdentityHashMap<Block,java.lang.Integer>
blockCount
Number of times each block has been analyzed since the last time widening was applied.protected java.util.IdentityHashMap<Block,S>
elseStores
Else stores before every basic block (assumed to be 'no information' if not present).protected int
maxCountBeforeWidening
Number of times a block can be analyzed before widening.protected java.util.IdentityHashMap<ReturnNode,TransferResult<V,S>>
storesAtReturnStatements
The stores after every return statement.protected java.util.IdentityHashMap<Block,S>
thenStores
Then stores before every basic block (assumed to be 'no information' if not present).-
Fields inherited from class org.checkerframework.dataflow.analysis.AbstractAnalysis
cfg, currentInput, currentNode, currentTree, direction, finalLocalValues, inputs, isRunning, nodeValues, transferFunction, worklist
-
-
Constructor Summary
Constructors Constructor Description ForwardAnalysisImpl(int maxCountBeforeWidening)
Construct an object that can perform a org.checkerframework.dataflow forward analysis over a control flow graph.ForwardAnalysisImpl(T transferFunction)
Construct an object that can perform a org.checkerframework.dataflow forward analysis over a control flow graph given a transfer function.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addStoreBefore(Block b, @Nullable Node node, S s, Store.Kind kind, boolean addBlockToWorklist)
Add a store before the basic blockb
by merging with the existing stores for that location.protected TransferResult<V,S>
callTransferFunction(Node node, TransferInput<V,S> input)
Call the transfer function for nodenode
, and set that node as current node first.@Nullable TransferInput<V,S>
getInput(Block b)
Get the transfer input of a givenBlock
b.protected @Nullable TransferInput<V,S>
getInputBefore(Block b)
Returns the transfer input corresponding to the location right before the basic blockb
.java.util.List<org.plumelib.util.IPair<ReturnNode,@Nullable TransferResult<V,S>>>
getReturnStatementStores()
Get stores at return statements.protected @Nullable S
getStoreBefore(Block b, Store.Kind kind)
Return the store corresponding to the location right before the basic blockb
.protected void
initFields(ControlFlowGraph cfg)
Initialize fields of this object based on a given control flow graph.protected void
initInitialInputs()
Initialize the transfer inputs of every basic block before performing the analysis.void
performAnalysis(ControlFlowGraph cfg)
Perform the actual analysis.void
performAnalysisBlock(Block b)
Perform the actual analysis on one block.protected void
propagateStoresTo(Block succ, @Nullable 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
.S
runAnalysisFor(Node node, Analysis.BeforeOrAfter preOrPost, TransferInput<V,S> blockTransferInput, java.util.IdentityHashMap<Node,V> nodeValues, @Nullable java.util.Map<TransferInput<V,S>,java.util.IdentityHashMap<Node,TransferResult<V,S>>> analysisCaches)
Runs the analysis again within the block ofnode
and returns the store at the location ofnode
.-
Methods inherited from class org.checkerframework.dataflow.analysis.AbstractAnalysis
addToWorklist, getContainingClass, getContainingMethod, getCurrentTree, getDirection, getExceptionalExitStore, getNodesForTree, getNodeValues, getRegularExitStore, getResult, getTransferFunction, getValue, getValue, init, isIgnoredExceptionType, isRunning, readFromStore, setCurrentNode, setCurrentTree, updateNodeValues
-
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
getDirection, getExceptionalExitStore, getRegularExitStore, getResult, getTransferFunction, getValue, getValue, isRunning
-
-
-
-
Field Detail
-
blockCount
protected final @Nullable java.util.IdentityHashMap<Block,java.lang.Integer> blockCount
Number of times each block has been analyzed since the last time widening was applied. Null if maxCountBeforeWidening is -1, which implies widening isn't used for this analysis.
-
maxCountBeforeWidening
protected final int maxCountBeforeWidening
Number of times a block can be analyzed before widening. -1 implies that widening shouldn't be used.
-
thenStores
protected final java.util.IdentityHashMap<Block,S extends Store<S>> thenStores
Then stores before every basic block (assumed to be 'no information' if not present).
-
elseStores
protected final java.util.IdentityHashMap<Block,S extends Store<S>> elseStores
Else stores before every basic block (assumed to be 'no information' if not present).
-
storesAtReturnStatements
protected final java.util.IdentityHashMap<ReturnNode,TransferResult<V extends AbstractValue<V>,S extends Store<S>>> storesAtReturnStatements
The stores after every return statement.
-
-
Constructor Detail
-
ForwardAnalysisImpl
public ForwardAnalysisImpl(int maxCountBeforeWidening)
Construct an object that can perform a org.checkerframework.dataflow forward analysis over a control flow graph. When using this constructor, the transfer function is set later by the subclass, e.g.,org.checkerframework.framework.flow.CFAbstractAnalysis
.- Parameters:
maxCountBeforeWidening
- number of times a block can be analyzed before widening
-
ForwardAnalysisImpl
public ForwardAnalysisImpl(T transferFunction)
Construct an object that can perform a org.checkerframework.dataflow forward analysis over a control flow graph given a transfer function.- Parameters:
transferFunction
- the transfer function
-
-
Method Detail
-
performAnalysis
public void performAnalysis(ControlFlowGraph cfg)
Description copied from interface:Analysis
Perform the actual analysis.- Specified by:
performAnalysis
in interfaceAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
- Parameters:
cfg
- the control flow graph
-
performAnalysisBlock
public void performAnalysisBlock(Block b)
Description copied from interface:Analysis
Perform the actual analysis on one block.- Specified by:
performAnalysisBlock
in interfaceAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
- Parameters:
b
- the block to analyze
-
getInput
public @Nullable TransferInput<V,S> getInput(Block b)
Description copied from interface:Analysis
Get the transfer input of a givenBlock
b.
-
getReturnStatementStores
@RequiresNonNull("cfg") public java.util.List<org.plumelib.util.IPair<ReturnNode,@Nullable TransferResult<V,S>>> getReturnStatementStores()
Description copied from interface:ForwardAnalysis
Get stores at return statements. These stores are transfer results at return node. Thus for a forward analysis, these stores contain the analyzed flow information from entry nodes to return nodes.- Specified by:
getReturnStatementStores
in interfaceForwardAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
- Returns:
- the transfer results for each return node in the CFG
-
runAnalysisFor
public S runAnalysisFor(@FindDistinct Node node, Analysis.BeforeOrAfter preOrPost, TransferInput<V,S> blockTransferInput, java.util.IdentityHashMap<Node,V> nodeValues, @Nullable java.util.Map<TransferInput<V,S>,java.util.IdentityHashMap<Node,TransferResult<V,S>>> analysisCaches)
Description copied from interface:Analysis
Runs the analysis again within the block ofnode
and returns the store at the location ofnode
. Ifbefore
is true, then the store immediately before theNode
node
is returned. Otherwise, the store immediately afternode
is returned. IfanalysisCaches
is not null, this method uses a cache.analysisCaches
is a map of a block of node to the cached analysis result. If the cache fortransferInput
is not inanalysisCaches
, this method creates new cache and stores it inanalysisCaches
. The cache is a map of nodes to the analysis results of the nodes.- Specified by:
runAnalysisFor
in interfaceAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
- Parameters:
node
- the node to analyzepreOrPost
- which store to return: the store immediately beforenode
or the store afternode
blockTransferInput
- the transfer input of the block of this nodenodeValues
- abstract values of nodesanalysisCaches
- caches of analysis results- Returns:
- the store before or after
node
(depends on the value ofbefore
) after running the analysis
-
initFields
protected void initFields(ControlFlowGraph cfg)
Description copied from class:AbstractAnalysis
Initialize fields of this object based on a given control flow graph. Sub-class may override this method to initialize customized fields.- Overrides:
initFields
in classAbstractAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
- Parameters:
cfg
- a given control flow graph
-
initInitialInputs
@RequiresNonNull("cfg") protected void initInitialInputs()
Description copied from class:AbstractAnalysis
Initialize the transfer inputs of every basic block before performing the analysis.- Specified by:
initInitialInputs
in classAbstractAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
-
callTransferFunction
protected TransferResult<V,S> callTransferFunction(Node node, TransferInput<V,S> input)
Description copied from class:AbstractAnalysis
Call the transfer function for nodenode
, and set that node as current node first. This method requires atransferInput
that the method can modify.- Overrides:
callTransferFunction
in classAbstractAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
- Parameters:
node
- the given nodeinput
- the transfer input- Returns:
- the output of the transfer function
-
propagateStoresTo
protected void propagateStoresTo(Block succ, @Nullable Node node, TransferInput<V,S> currentInput, Store.FlowRule flowRule, boolean addToWorklistAgain)
Description copied from class:AbstractAnalysis
Propagate the stores incurrentInput
to the next block in the direction of analysis, according to theflowRule
.- Specified by:
propagateStoresTo
in classAbstractAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
- Parameters:
succ
- 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 toAbstractAnalysis.worklist
again
-
addStoreBefore
protected void addStoreBefore(Block b, @Nullable Node node, S s, Store.Kind kind, boolean addBlockToWorklist)
Add a store before the basic blockb
by merging with the existing stores for that location.- Parameters:
b
- a basic blocknode
- the node of the basic blockb
s
- the store being addedkind
- the kind of stores
addBlockToWorklist
- whether the basic blockb
should be added back toWorklist
-
getStoreBefore
protected @Nullable S getStoreBefore(Block b, Store.Kind kind)
Return the store corresponding to the location right before the basic blockb
.- Parameters:
b
- a blockkind
- the kind of store which will be returned- Returns:
- the store corresponding to the location right before the basic block
b
-
getInputBefore
protected @Nullable TransferInput<V,S> getInputBefore(Block b)
Returns the transfer input corresponding to the location right before the basic blockb
.- Parameters:
b
- a block- Returns:
- the transfer input corresponding to the location right before the basic block
b
-
-