Class AbstractAnalysis<V extends AbstractValue<V>,​S extends Store<S>,​T extends TransferFunction<V,​S>>

    • Field Detail

      • isRunning

        protected boolean isRunning
        Is the analysis currently running?
      • inputs

        protected final java.util.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, inputs before blocks in forward analysis, after blocks in backward analysis).
      • nodeValues

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

        protected final java.util.HashMap<javax.lang.model.element.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 com.sun.source.tree.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.
    • Method Detail

      • getCurrentTree

        public @Nullable com.sun.source.tree.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
                                   com.sun.source.tree.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
      • 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 java.util.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)
      • getNodesForTree

        public @Nullable java.util.Set<Node> getNodesForTree​(com.sun.source.tree.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​(com.sun.source.tree.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 com.sun.source.tree.MethodTree getContainingMethod​(com.sun.source.tree.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 com.sun.source.tree.ClassTree getContainingClass​(com.sun.source.tree.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​(javax.lang.model.type.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​(java.util.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