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 behaviorpublic 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>
AbstractAnalysis.Worklist
Analysis.BeforeOrAfter, Analysis.Direction
Modifier and Type | Field and Description |
---|---|
protected @Nullable IdentityHashMap<Block,Integer> |
blockCount
Number of times each block has been analyzed since the last time widening was applied.
|
protected 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 IdentityHashMap<ReturnNode,TransferResult<V,S>> |
storesAtReturnStatements
The stores after every return statement.
|
protected IdentityHashMap<Block,S> |
thenStores
Then stores before every basic block (assumed to be 'no information' if not present).
|
cfg, currentInput, currentNode, currentTree, direction, finalLocalValues, inputs, isRunning, nodeValues, transferFunction, worklist
Constructor and Description |
---|
ForwardAnalysisImpl(int maxCountBeforeWidening)
Construct an object that can perform a org.checkerframework.dataflow forward analysis over a
control flow graph.
|
ForwardAnalysisImpl(T transfer)
Construct an object that can perform a org.checkerframework.dataflow forward analysis over a
control flow graph given a transfer function.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addStoreBefore(Block b,
@Nullable Node node,
S s,
Store.Kind kind,
boolean addBlockToWorklist)
Add a store before the basic block
b 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 node
node , and set that node as current node first. |
@Nullable TransferInput<V,S> |
getInput(Block b)
Get the transfer input of a given
Block b. |
protected @Nullable TransferInput<V,S> |
getInputBefore(Block b)
Returns the transfer input corresponding to the location right before the basic block
b . |
List<Pair<ReturnNode,TransferResult<V,S>>> |
getReturnStatementStores()
Get stores at return statements.
|
protected S |
getStoreBefore(Block b,
Store.Kind kind)
Return the store corresponding to the location right before the basic block
b . |
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 in
currentInput to the next block in the direction of analysis,
according to the flowRule . |
S |
runAnalysisFor(Node node,
Analysis.BeforeOrAfter preOrPost,
TransferInput<V,S> blockTransferInput,
IdentityHashMap<Node,V> nodeValues,
Map<TransferInput<V,S>,IdentityHashMap<Node,TransferResult<V,S>>> analysisCaches)
Runs the analysis again within the block of
node and returns the store at the
location of node . |
addToWorklist, getContainingClass, getContainingMethod, getCurrentTree, getDirection, getExceptionalExitStore, getNodesForTree, getNodeValues, getRegularExitStore, getResult, getTransferFunction, getValue, getValue, init, isRunning, readFromStore, setCurrentNode, setCurrentTree, updateNodeValues
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getDirection, getExceptionalExitStore, getRegularExitStore, getResult, getTransferFunction, getValue, getValue, isRunning
protected final @Nullable IdentityHashMap<Block,Integer> blockCount
protected final int maxCountBeforeWidening
protected final IdentityHashMap<Block,S extends Store<S>> thenStores
protected final IdentityHashMap<Block,S extends Store<S>> elseStores
protected final IdentityHashMap<ReturnNode,TransferResult<V extends AbstractValue<V>,S extends Store<S>>> storesAtReturnStatements
public ForwardAnalysisImpl(int maxCountBeforeWidening)
org.checkerframework.framework.flow.CFAbstractAnalysis
.maxCountBeforeWidening
- number of times a block can be analyzed before wideningpublic ForwardAnalysisImpl(T transfer)
transfer
- the transfer functionpublic void performAnalysis(ControlFlowGraph cfg)
Analysis
performAnalysis
in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
cfg
- the control flow graphpublic void performAnalysisBlock(Block b)
Analysis
performAnalysisBlock
in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
b
- the block to analyzepublic @Nullable TransferInput<V,S> getInput(Block b)
Analysis
Block
b.@RequiresNonNull(value="cfg") public List<Pair<ReturnNode,TransferResult<V,S>>> getReturnStatementStores()
ForwardAnalysis
getReturnStatementStores
in interface ForwardAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
public S runAnalysisFor(@FindDistinct Node node, Analysis.BeforeOrAfter preOrPost, TransferInput<V,S> blockTransferInput, IdentityHashMap<Node,V> nodeValues, Map<TransferInput<V,S>,IdentityHashMap<Node,TransferResult<V,S>>> analysisCaches)
Analysis
node
and returns the store at the
location of node
. If before
is true, then the store immediately before the
Node
node
is returned. Otherwise, the store immediately after node
is
returned. If analysisCaches
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 for
transferInput
is not in analysisCaches
, this method creates new cache and
stores it in analysisCaches
. The cache is a map of nodes to the analysis results of
the nodes.runAnalysisFor
in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
node
- the node to analyzepreOrPost
- indicates which store to return: the store immediately before node
or the store after node
blockTransferInput
- the transfer input of the block of this nodenodeValues
- abstract values of nodesanalysisCaches
- caches of analysis resultsnode
(depends on the value of before
) after
running the analysisprotected void initFields(ControlFlowGraph cfg)
AbstractAnalysis
initFields
in class AbstractAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
cfg
- a given control flow graph@RequiresNonNull(value="cfg") protected void initInitialInputs()
AbstractAnalysis
initInitialInputs
in class AbstractAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
protected TransferResult<V,S> callTransferFunction(Node node, TransferInput<V,S> input)
AbstractAnalysis
node
, and set that node as current node first.
This method requires a transferInput
that the method can modify.callTransferFunction
in class AbstractAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
node
- the given nodeinput
- the transfer inputprotected void propagateStoresTo(Block succ, @Nullable Node node, TransferInput<V,S> currentInput, Store.FlowRule flowRule, boolean addToWorklistAgain)
AbstractAnalysis
currentInput
to the next block in the direction of analysis,
according to the flowRule
.propagateStoresTo
in class AbstractAnalysis<V extends AbstractValue<V>,S extends Store<S>,T extends ForwardTransferFunction<V,S>>
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 to AbstractAnalysis.worklist
againprotected void addStoreBefore(Block b, @Nullable Node node, S s, Store.Kind kind, boolean addBlockToWorklist)
b
by merging with the existing stores for that
location.b
- a basic blocknode
- the node of the basic block b
s
- the store being addedkind
- the kind of store s
addBlockToWorklist
- whether the basic block b
should be added back to Worklist
protected S getStoreBefore(Block b, Store.Kind kind)
b
.b
- a blockkind
- the kind of store which will be returnedb
protected @Nullable TransferInput<V,S> getInputBefore(Block b)
b
.b
- a blockb