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 analysis
S - the store type used in the analysis
T - the transfer function type that is used to approximated runtime 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.
  • Field Details

    • direction

      protected final Analysis.Direction direction
      The direction of this analysis.
    • isRunning

      protected boolean isRunning
      Is the analysis currently running?
    • transferFunction

      protected @MonotonicNonNull T extends TransferFunction<V,S> 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>,S extends Store<S>>> inputs
      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

      protected final AbstractAnalysis.Worklist worklist
      The worklist used for the fix-point iteration.
    • nodeValues

      protected final IdentityHashMap<Node,V extends AbstractValue<V>> nodeValues
      Abstract values of nodes.
    • finalLocalValues

      protected final HashMap<VariableElement,V extends AbstractValue<V>> finalLocalValues
      Map from (effectively final) local variable elements to their abstract value.
    • currentNode

      protected @InternedDistinct @Nullable Node currentNode
      The node that is currently handled in the analysis (if it is running). The following invariant holds:
         !isRunning ⇒ (currentNode == null)
       
    • currentTree

      protected @InternedDistinct @Nullable Tree currentTree
      The tree that is currently being looked at. The transfer function can set this tree to make sure that calls to getValue will not return information for this given tree.
    • currentInput

      protected @Nullable TransferInput<V extends AbstractValue<V>,S extends Store<S>> currentInput
      The current transfer input when the analysis is running.
  • Constructor Details

  • Method Details

    • getCurrentTree

      public @Nullable Tree getCurrentTree()
      Returns the tree that is currently being looked at. The transfer function can set this tree to make sure that calls to getValue will not return information for this given tree.
      Returns:
      the tree that is currently being looked at
    • setCurrentTree

      public void setCurrentTree(@FindDistinct Tree currentTree)
      Set the tree that is currently being looked at.
      Parameters:
      currentTree - the tree that should be currently looked at
    • setCurrentNode

      protected void setCurrentNode(@FindDistinct @Nullable Node currentNode)
      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 in currentInput to the next block in the direction of analysis, according to the flowRule.
      Parameters:
      nextBlock - the target block to propagate the stores to
      node - the node of the target block
      currentInput - the current transfer input
      flowRule - the flow rule being used
      addToWorklistAgain - whether the block should be added to worklist again
    • isRunning

      public boolean isRunning()
      Description copied from interface: Analysis
      Is the analysis currently running?
      Specified by:
      isRunning in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
      Returns:
      true if the analysis is running currently, else false
    • getDirection

      public Analysis.Direction getDirection()
      Description copied from interface: Analysis
      Get the direction of this analysis.
      Specified by:
      getDirection in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
      Returns:
      the direction of this analysis
    • getResult

      @RequiresNonNull("cfg") public AnalysisResult<V,S> getResult()
      Description copied from interface: Analysis
      The result of running the analysis. This is only available once the analysis finished running.
      Specified by:
      getResult in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
      Returns:
      the result of running the analysis
    • getTransferFunction

      public @Nullable T getTransferFunction()
      Description copied from interface: Analysis
      Get the transfer function of this analysis.
      Specified by:
      getTransferFunction in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
      Returns:
      the transfer function of this analysis
    • getValue

      public @Nullable V getValue(Node n)
      Description copied from interface: Analysis
      Returns the abstract value for Node n, or null 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.
      Specified by:
      getValue in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
      Parameters:
      n - n a node
      Returns:
      the abstract value for node n, or null if no information is available
    • getNodeValues

      public IdentityHashMap<Node,V> getNodeValues()
      Returns all current node values.
      Returns:
      nodeValues
    • getRegularExitStore

      @RequiresNonNull("cfg") public @Nullable S getRegularExitStore()
      Description copied from interface: Analysis
      Returns the regular exit store, or null, if there is no such store (because the method cannot exit through the regular exit block).
      Specified by:
      getRegularExitStore in interface Analysis<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

      @RequiresNonNull("cfg") public @Nullable S getExceptionalExitStore()
      Description copied from interface: Analysis
      Returns the exceptional exit store.
      Specified by:
      getExceptionalExitStore in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
      Returns:
      the exceptional exit store
    • getNodesForTree

      public @Nullable Set<Node> getNodesForTree(Tree t)
      Get the set of Nodes for a given Tree. Returns null for trees that don't produce a value.
      Parameters:
      t - the given tree
      Returns:
      the set of corresponding nodes to the given tree
    • getValue

      public @Nullable V getValue(Tree t)
      Description copied from interface: Analysis
      Return the abstract value for Tree t, or null 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.
      Specified by:
      getValue in interface Analysis<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
      Parameters:
      t - the given tree
      Returns:
      the abstract value for the given tree
    • getContainingMethod

      public @Nullable MethodTree getContainingMethod(Tree t)
      Get the MethodTree of the current CFG if the argument Tree maps to a Node in the CFG or null otherwise.
      Parameters:
      t - the given tree
      Returns:
      the contained method tree of the given tree
    • getContainingClass

      public @Nullable ClassTree getContainingClass(Tree t)
      Get the ClassTree of the current CFG if the argument Tree maps to a Node in the CFG or null otherwise.
      Parameters:
      t - the given tree
      Returns:
      the contained class tree of the given tree
    • callTransferFunction

      protected TransferResult<V,S> callTransferFunction(Node node, TransferInput<V,S> transferInput)
      Call the transfer function for node node, and set that node as current node first. This method requires a transferInput that the method can modify.
      Parameters:
      node - the given node
      transferInput - the transfer input
      Returns:
      the output of the transfer function
    • init

      protected final void init(ControlFlowGraph cfg)
      Initialize the analysis with a new control flow graph.
      Parameters:
      cfg - the control flow graph to use
    • isIgnoredExceptionType

      protected boolean isIgnoredExceptionType(TypeMirror exceptionType)
      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 to exceptionType should be ignored, false otherwise
    • initFields

      @EnsuresNonNull("this.cfg") protected void initFields(ControlFlowGraph cfg)
      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

      protected boolean updateNodeValues(Node node, TransferResult<V,S> transferResult)
      Updates the value of node node to the value of the transferResult. Returns true if the node's value changed, or a store was updated.
      Parameters:
      node - the node to update
      transferResult - the transfer result being updated
      Returns:
      true if the node's value changed, or a store was updated
    • readFromStore

      protected static <S> @Nullable S readFromStore(Map<Block,S> stores, Block b)
      Read the store for a particular basic block from a map of stores (or null if none exists yet).
      Type Parameters:
      S - method return type should be a subtype of Store
      Parameters:
      stores - a map of stores
      b - the target block
      Returns:
      the store for the target block
    • addToWorklist

      protected void addToWorklist(Block b)
      Add a basic block to worklist. If b is already present, the method does nothing.
      Parameters:
      b - the block to add to worklist