Class AnalysisResult<V extends AbstractValue<V>,S extends Store<S>>
- java.lang.Object
-
- org.checkerframework.dataflow.analysis.AnalysisResult<V,S>
-
- Type Parameters:
V
- type of the abstract value that is trackedS
- the store type used in the analysis
- All Implemented Interfaces:
org.plumelib.util.UniqueId
public class AnalysisResult<V extends AbstractValue<V>,S extends Store<S>> extends java.lang.Object implements org.plumelib.util.UniqueId
AnAnalysisResult
represents the result of a org.checkerframework.dataflow analysis by providing the abstract values given a node or a tree. Note that it does not keep track of custom results computed by some analysis.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<TransferInput<V,S>,java.util.IdentityHashMap<Node,TransferResult<V,S>>>
analysisCaches
Caches of the analysis results for each input for the block of the node and each node.protected java.util.Map<javax.lang.model.element.VariableElement,V>
finalLocalValues
Map from (effectively final) local variable elements to their abstract value.protected java.util.IdentityHashMap<Node,V>
nodeValues
Abstract values of nodes.protected java.util.IdentityHashMap<com.sun.source.tree.UnaryTree,com.sun.source.tree.BinaryTree>
postfixLookup
Map from postfix increment or decrement trees that are ASTUnaryTree
s to the synthetic tree that isv + 1
orv - 1
.protected java.util.IdentityHashMap<Block,TransferInput<V,S>>
stores
The stores before every method call.protected java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>>
treeLookup
Map from ASTTree
s to sets ofNode
s.
-
Constructor Summary
Constructors Modifier Constructor Description AnalysisResult(java.util.IdentityHashMap<Node,V> nodeValues, java.util.IdentityHashMap<Block,TransferInput<V,S>> stores, java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>> treeLookup, java.util.IdentityHashMap<com.sun.source.tree.UnaryTree,com.sun.source.tree.BinaryTree> postfixLookup, java.util.Map<javax.lang.model.element.VariableElement,V> finalLocalValues)
Initialize with given mappings and empty cache.protected
AnalysisResult(java.util.IdentityHashMap<Node,V> nodeValues, java.util.IdentityHashMap<Block,TransferInput<V,S>> stores, java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>> treeLookup, java.util.IdentityHashMap<com.sun.source.tree.UnaryTree,com.sun.source.tree.BinaryTree> postfixLookup, java.util.Map<javax.lang.model.element.VariableElement,V> finalLocalValues, java.util.Map<TransferInput<V,S>,java.util.IdentityHashMap<Node,TransferResult<V,S>>> analysisCaches)
Initialize with given mappings.AnalysisResult(java.util.Map<TransferInput<V,S>,java.util.IdentityHashMap<Node,TransferResult<V,S>>> analysisCaches)
Initialize empty result with specified cache.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
combine(AnalysisResult<V,S> other)
Combine with another analysis result.java.util.Map<javax.lang.model.element.VariableElement,V>
getFinalLocalValues()
Returns the value of effectively final local variables.@Nullable java.util.Set<Node>
getNodesForTree(com.sun.source.tree.Tree tree)
Returns theNode
s corresponding to a particularTree
.com.sun.source.tree.BinaryTree
getPostfixBinaryTree(com.sun.source.tree.UnaryTree postfixTree)
Returns the syntheticv + 1
orv - 1
corresponding to the postfix increment or decrement tree.@Nullable S
getStoreAfter(com.sun.source.tree.Tree tree)
Returns the store immediately after a givenTree
.S
getStoreAfter(Block block)
Returns the regular store immediately after a given block.@Nullable S
getStoreAfter(Node node)
Returns the store immediately after a givenNode
.@Nullable S
getStoreBefore(com.sun.source.tree.Tree tree)
Returns the store immediately before a givenTree
.S
getStoreBefore(Block block)
Returns the regular store immediately before a givenBlock
.@Nullable S
getStoreBefore(Node node)
Returns the store immediately before a givenNode
.long
getUid()
@Nullable V
getValue(com.sun.source.tree.Tree t)
Returns the abstract value forTree
t
, ornull
if no information is available.@Nullable V
getValue(Node n)
static <V> java.lang.String
nodeValuesToString(java.util.Map<Node,V> nodeValues)
Returns a verbose string representation, useful for debugging.protected @Nullable S
runAnalysisFor(Node node, Analysis.BeforeOrAfter preOrPost)
Runs the analysis again within the block ofnode
and returns the store at the location ofnode
.static <V extends AbstractValue<V>,S extends Store<S>>
SrunAnalysisFor(Node node, Analysis.BeforeOrAfter preOrPost, TransferInput<V,S> transferInput, 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
.java.lang.String
toStringDebug()
Returns a verbose string representation of this, useful for debugging.static java.lang.String
treeLookupToString(java.util.Map<com.sun.source.tree.Tree,java.util.Set<Node>> treeLookup)
Returns a verbose string representation of a map, useful for debugging.
-
-
-
Field Detail
-
nodeValues
protected java.util.IdentityHashMap<Node,V extends AbstractValue<V>> nodeValues
Abstract values of nodes.
-
treeLookup
protected java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>> treeLookup
Map from ASTTree
s to sets ofNode
s.Some of those Nodes might not be keys in
nodeValues
. One reason is that the Node is unreachable in the control flow graph, so dataflow never gave it a value.
-
postfixLookup
protected java.util.IdentityHashMap<com.sun.source.tree.UnaryTree,com.sun.source.tree.BinaryTree> postfixLookup
Map from postfix increment or decrement trees that are ASTUnaryTree
s to the synthetic tree that isv + 1
orv - 1
.
-
finalLocalValues
protected final java.util.Map<javax.lang.model.element.VariableElement,V extends AbstractValue<V>> finalLocalValues
Map from (effectively final) local variable elements to their abstract value.
-
stores
protected final java.util.IdentityHashMap<Block,TransferInput<V extends AbstractValue<V>,S extends Store<S>>> stores
The stores before every method call.
-
analysisCaches
protected final java.util.Map<TransferInput<V extends AbstractValue<V>,S extends Store<S>>,java.util.IdentityHashMap<Node,TransferResult<V extends AbstractValue<V>,S extends Store<S>>>> analysisCaches
Caches of the analysis results for each input for the block of the node and each node.
-
-
Constructor Detail
-
AnalysisResult
protected AnalysisResult(java.util.IdentityHashMap<Node,V> nodeValues, java.util.IdentityHashMap<Block,TransferInput<V,S>> stores, java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>> treeLookup, java.util.IdentityHashMap<com.sun.source.tree.UnaryTree,com.sun.source.tree.BinaryTree> postfixLookup, java.util.Map<javax.lang.model.element.VariableElement,V> finalLocalValues, java.util.Map<TransferInput<V,S>,java.util.IdentityHashMap<Node,TransferResult<V,S>>> analysisCaches)
Initialize with given mappings.- Parameters:
nodeValues
-nodeValues
stores
-stores
treeLookup
-treeLookup
postfixLookup
-postfixLookup
finalLocalValues
-finalLocalValues
analysisCaches
-analysisCaches
-
AnalysisResult
public AnalysisResult(java.util.IdentityHashMap<Node,V> nodeValues, java.util.IdentityHashMap<Block,TransferInput<V,S>> stores, java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>> treeLookup, java.util.IdentityHashMap<com.sun.source.tree.UnaryTree,com.sun.source.tree.BinaryTree> postfixLookup, java.util.Map<javax.lang.model.element.VariableElement,V> finalLocalValues)
Initialize with given mappings and empty cache.- Parameters:
nodeValues
-nodeValues
stores
-stores
treeLookup
-treeLookup
postfixLookup
-postfixLookup
finalLocalValues
-finalLocalValues
-
AnalysisResult
public AnalysisResult(java.util.Map<TransferInput<V,S>,java.util.IdentityHashMap<Node,TransferResult<V,S>>> analysisCaches)
Initialize empty result with specified cache.- Parameters:
analysisCaches
-analysisCaches
-
-
Method Detail
-
getUid
public long getUid(@UnknownInitialization AnalysisResult<V extends AbstractValue<V>,S extends Store<S>> this)
- Specified by:
getUid
in interfaceorg.plumelib.util.UniqueId
-
combine
public void combine(AnalysisResult<V,S> other)
Combine with another analysis result.- Parameters:
other
- an analysis result to combine with this
-
getFinalLocalValues
public java.util.Map<javax.lang.model.element.VariableElement,V> getFinalLocalValues()
Returns the value of effectively final local variables.- Returns:
- the value of effectively final local variables
-
getValue
public @Nullable V getValue(Node n)
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.- Parameters:
n
- a node- Returns:
- the abstract value for
Node
n
, ornull
if no information is available
-
getValue
public @Nullable V getValue(com.sun.source.tree.Tree t)
Returns 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.- Parameters:
t
- a tree- Returns:
- the abstract value for
Tree
t
, ornull
if no information is available
-
getNodesForTree
public @Nullable java.util.Set<Node> getNodesForTree(com.sun.source.tree.Tree tree)
Returns theNode
s corresponding to a particularTree
. MultipleNode
s can correspond to a singleTree
because of several reasons:- In a lambda expression such as
() -> 5
the5
is both anIntegerLiteralNode
and aLambdaResultExpressionNode
. - Widening and narrowing primitive conversions can result in
WideningConversionNode
andNarrowingConversionNode
. - Automatic String conversion can result in a
StringConversionNode
. - Trees for
finally
blocks are cloned to achieve a precise CFG. AnyTree
within a finally block can have multiple correspondingNode
s attached to them.
Node
s they are not interested in.- Parameters:
tree
- a tree- Returns:
- the set of
Node
s for a givenTree
- In a lambda expression such as
-
getPostfixBinaryTree
public com.sun.source.tree.BinaryTree getPostfixBinaryTree(com.sun.source.tree.UnaryTree postfixTree)
Returns the syntheticv + 1
orv - 1
corresponding to the postfix increment or decrement tree.- Parameters:
postfixTree
- a postfix increment or decrement tree- Returns:
- the synthetic
v + 1
orv - 1
corresponding to the postfix increment or decrement tree
-
getStoreBefore
public @Nullable S getStoreBefore(com.sun.source.tree.Tree tree)
Returns the store immediately before a givenTree
.- Parameters:
tree
- a tree- Returns:
- the store immediately before a given
Tree
-
getStoreBefore
public @Nullable S getStoreBefore(Node node)
Returns the store immediately before a givenNode
.- Parameters:
node
- a node- Returns:
- the store immediately before a given
Node
-
getStoreBefore
public S getStoreBefore(Block block)
Returns the regular store immediately before a givenBlock
.- Parameters:
block
- a block- Returns:
- the store right before the given block
-
getStoreAfter
public S getStoreAfter(Block block)
Returns the regular store immediately after a given block.- Parameters:
block
- a block- Returns:
- the store after the given block
-
getStoreAfter
public @Nullable S getStoreAfter(com.sun.source.tree.Tree tree)
Returns the store immediately after a givenTree
.- Parameters:
tree
- a tree- Returns:
- the store immediately after a given
Tree
-
getStoreAfter
public @Nullable S getStoreAfter(Node node)
Returns the store immediately after a givenNode
.- Parameters:
node
- a node- Returns:
- the store immediately after a given
Node
-
runAnalysisFor
protected @Nullable S runAnalysisFor(Node node, Analysis.BeforeOrAfter preOrPost)
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 afternode
is returned.If the given
Node
cannot be reached (in the control flow graph), thennull
is returned.- Parameters:
node
- the node to analyzepreOrPost
- which store to return: the store immediately beforenode
or the store afternode
- Returns:
- the store before or after
node
(depends on the value ofbefore
) after running the analysis
-
runAnalysisFor
public static <V extends AbstractValue<V>,S extends Store<S>> S runAnalysisFor(Node node, Analysis.BeforeOrAfter preOrPost, TransferInput<V,S> transferInput, 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
. 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.- Type Parameters:
V
- the abstract value type to be tracked by the analysisS
- the store type used in the analysis- Parameters:
node
- the node to analyzepreOrPost
- which store to return: the store immediately beforenode
or the store afternode
transferInput
- a transfer inputnodeValues
-nodeValues
analysisCaches
-analysisCaches
- Returns:
- the store before or after
node
(depends on the value ofbefore
) after running the analysis
-
toStringDebug
public java.lang.String toStringDebug()
Returns a verbose string representation of this, useful for debugging.- Returns:
- a string representation of this
-
nodeValuesToString
public static <V> java.lang.String nodeValuesToString(java.util.Map<Node,V> nodeValues)
Returns a verbose string representation, useful for debugging. The map has the same type as thenodeValues
field.- Type Parameters:
V
- the type of values in the map- Parameters:
nodeValues
- a map to format- Returns:
- a printed representation of the given map
-
treeLookupToString
public static java.lang.String treeLookupToString(java.util.Map<com.sun.source.tree.Tree,java.util.Set<Node>> treeLookup)
Returns a verbose string representation of a map, useful for debugging. The map has the same type as thetreeLookup
field.- Parameters:
treeLookup
- a map to format- Returns:
- a printed representation of the given map
-
-