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 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.
  • Field Details Link icon

    • direction Link icon

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

      protected boolean isRunning
      Is the analysis currently running?
    • transferFunction Link icon

      protected @MonotonicNonNull T extends TransferFunction<V,S> transferFunction
      The transfer function for regular nodes.
    • cfg Link icon

      The current control flow graph to perform the analysis on.
    • inputs Link icon

      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 Link icon

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

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

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

      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 Link icon

      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 Link icon

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

  • Method Details Link icon

    • getCurrentTree Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      @RequiresNonNull("cfg") protected abstract void initInitialInputs()
      Initialize the transfer inputs of every basic block before performing the analysis.
    • propagateStoresTo Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      @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 Link icon

      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 Link icon

      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 Link icon

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

      @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 Link icon

      @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 Link icon

      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 Link icon

      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 Link icon

      @Deprecated 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
    • getEnclosingMethod Link icon

      public @Nullable MethodTree getEnclosingMethod(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 Link icon

      @Deprecated 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
    • getEnclosingClass Link icon

      public @Nullable ClassTree getEnclosingClass(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 Link icon

      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 Link icon

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

      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 Link icon

      @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 Link icon

      protected boolean updateNodeValues(Node node, TransferResult<V,S> transferResult)
      Updates the value of node node in nodeValues 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
    • addToWorklist Link icon

      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