Class CFG

    • Constructor Detail

      • CFG

        public CFG​(CodeMemberDescriptor descriptor)
        Builds the control flow graph.
        Parameters:
        descriptor - the descriptor of this cfg
      • CFG

        public CFG​(CodeMemberDescriptor descriptor,
                   java.util.Collection<Statement> entrypoints,
                   NodeList<CFG,​Statement,​Edge> list)
        Builds the control flow graph.
        Parameters:
        descriptor - the descriptor of this cfg
        entrypoints - the statements of this cfg that will be reachable from other cfgs
        list - the node list containing all the statements and the edges that will be part of this cfg
      • CFG

        public CFG​(CFG other)
        Clones the given control flow graph.
        Parameters:
        other - the original cfg
    • Method Detail

      • getNormalExitpoints

        public java.util.Collection<Statement> getNormalExitpoints()
        Yields the statements of this control flow graph that are normal exitpoints, that is, that normally ends the execution of this cfg, returning the control to the caller without throwing an error (i.e., all such statements on which Statement.stopsExecution() holds but Statement.throwsError() does not).
        Returns:
        the normal exitpoints of this cfg.
      • getAllExitpoints

        public java.util.Collection<Statement> getAllExitpoints()
        Yields the statements of this control flow graph that are normal exitpoints, that is, that normally ends the execution of this cfg, returning the control to the caller, or throwing an error (i.e., all such statements on which either Statement.stopsExecution() or Statement.throwsError() hold).
        Returns:
        the exitpoints of this cfg.
      • addControlFlowStructure

        public void addControlFlowStructure​(ControlFlowStructure cf)
        Adds the given ControlFlowStructure to the ones contained in this cfg.
        Parameters:
        cf - the control flow structure to add
        Throws:
        java.lang.IllegalArgumentException - if a control flow structure for the same condition already exists
      • getControlFlowStructures

        public java.util.Collection<ControlFlowStructure> getControlFlowStructures()
        Yields the collection of ControlFlowStructures contained in this cfg.

        Note that if no control flow structures have been provided by frontends, and no attempt at extracting them has been made yet, invoking this method will cause a ControlFlowExtractor to try to extract them.
        Returns:
        the collection, either provided by frontends or extracted, of the control flow structures of this method
      • simplify

        public void simplify()
        Simplifies this cfg, removing all NoOps and rewriting the edge set accordingly. This method will throw an UnsupportedOperationException if one of the NoOps has an outgoing edge that is not a SequentialEdge, since such statement is expected to always be sequential.
        Throws:
        java.lang.UnsupportedOperationException - if there exists at least one NoOp with an outgoing non-sequential edge.
      • fixpoint

        public <A extends AbstractState<A,​H,​V,​T>,​H extends HeapDomain<H>,​V extends ValueDomain<V>,​T extends TypeDomain<T>> CFGWithAnalysisResults<A,​H,​V,​T> fixpoint​(java.util.Collection<Statement> entrypoints,
                                                                                                                                                                                                                          AnalysisState<A,​H,​V,​T> entryState,
                                                                                                                                                                                                                          InterproceduralAnalysis<A,​H,​V,​T> interprocedural,
                                                                                                                                                                                                                          WorkingSet<Statement> ws,
                                                                                                                                                                                                                          int widenAfter)
                                                                                                                                                                                                                   throws FixpointException
        Computes a fixpoint over this control flow graph. This method returns a CFGWithAnalysisResults instance mapping each Statement to the AnalysisState computed by this method. The computation uses Lattice.lub(Lattice) to compose results obtained at different iterations, up to widenAfter * predecessors_number times, where predecessors_number is the number of expressions that are predecessors of the one being processed. After overcoming that threshold, Lattice.widening(Lattice) is used. The computation starts at the statements in entrypoints, using entryState as entry state for all of them. interprocedural will be invoked to get the approximation of all invoked cfgs, while ws is used as working set for the statements to process.
        Type Parameters:
        A - the type of AbstractState contained into the analysis state
        H - the type of HeapDomain contained into the computed abstract state
        V - the type of ValueDomain contained into the computed abstract state
        T - the type of TypeDomain contained into the computed abstract state
        Parameters:
        entrypoints - the collection of Statements that to use as a starting point of the computation (that must be nodes of this cfg)
        entryState - the entry states to apply to each Statement in entrypoints
        interprocedural - the callgraph that can be queried when a call towards an other cfg is encountered
        ws - the WorkingSet instance to use for this computation
        widenAfter - the number of times after which the Lattice.lub(Lattice) invocation gets replaced by the Lattice.widening(Lattice) call. Use 0 to always use Lattice.lub(Lattice)
        Returns:
        a CFGWithAnalysisResults instance that is equivalent to this control flow graph, and that stores for each Statement the result of the fixpoint computation
        Throws:
        FixpointException - if an error occurs during the semantic computation of a statement, or if some unknown/invalid statement ends up in the working set
      • fixpoint

        public <A extends AbstractState<A,​H,​V,​T>,​H extends HeapDomain<H>,​V extends ValueDomain<V>,​T extends TypeDomain<T>> CFGWithAnalysisResults<A,​H,​V,​T> fixpoint​(AnalysisState<A,​H,​V,​T> singleton,
                                                                                                                                                                                                                          java.util.Map<Statement,​AnalysisState<A,​H,​V,​T>> startingPoints,
                                                                                                                                                                                                                          InterproceduralAnalysis<A,​H,​V,​T> interprocedural,
                                                                                                                                                                                                                          WorkingSet<Statement> ws,
                                                                                                                                                                                                                          int widenAfter)
                                                                                                                                                                                                                   throws FixpointException
        Computes a fixpoint over this control flow graph. This method returns a CFGWithAnalysisResults instance mapping each Statement to the AnalysisState computed by this method. The computation uses Lattice.lub(Lattice) to compose results obtained at different iterations, up to widenAfter * predecessors_number times, where predecessors_number is the number of expressions that are predecessors of the one being processed. After overcoming that threshold, Lattice.widening(Lattice) is used. The computation starts at the statements in startingPoints, using as its entry state their respective value. interprocedural will be invoked to get the approximation of all invoked cfgs, while ws is used as working set for the statements to process.
        Type Parameters:
        A - the type of AbstractState contained into the analysis state
        H - the type of HeapDomain contained into the computed abstract state
        V - the type of ValueDomain contained into the computed abstract state
        T - the type of TypeDomain contained into the computed abstract state
        Parameters:
        singleton - an instance of the AnalysisState containing the abstract state of the analysis to run, used to retrieve top and bottom values
        startingPoints - a map between Statements that to use as a starting point of the computation (that must be nodes of this cfg) and the entry states to apply on it
        interprocedural - the callgraph that can be queried when a call towards an other cfg is encountered
        ws - the WorkingSet instance to use for this computation
        widenAfter - the number of times after which the Lattice.lub(Lattice) invocation gets replaced by the Lattice.widening(Lattice) call. Use 0 to always use Lattice.lub(Lattice)
        Returns:
        a CFGWithAnalysisResults instance that is equivalent to this control flow graph, and that stores for each Statement the result of the fixpoint computation
        Throws:
        FixpointException - if an error occurs during the semantic computation of a statement, or if some unknown/invalid statement ends up in the working set
      • preSimplify

        public void preSimplify​(Statement node)
        Description copied from class: CodeGraph
        Callback that is invoked on a node before simplifying it.
        Overrides:
        preSimplify in class CodeGraph<CFG,​Statement,​Edge>
        Parameters:
        node - the node about to be simplified
      • getGenericProgramPoint

        public ProgramPoint getGenericProgramPoint()
        Yields a generic ProgramPoint happening inside this cfg. A generic program point can be used for semantic evaluations of instrumented Statements, that are not tied to any concrete statement.
        Returns:
        a generic program point happening in this cfg
      • isGuarded

        public boolean isGuarded​(ProgramPoint pp)
        Yields true if and only if the given program point is inside the body of a ControlFlowStructure, regardless of its type.

        Note that if no control flow structures have been provided by frontends, and no attempt at extracting them has been made yet, invoking this method will cause a ControlFlowExtractor to try to extract them.
        Parameters:
        pp - the program point
        Returns:
        true if pp is inside a control flow structure
      • isInsideLoop

        public boolean isInsideLoop​(ProgramPoint pp)
        Yields true if and only if the given program point is inside the body of a Loop.

        Note that if no control flow structures have been provided by frontends, and no attempt at extracting them has been made yet, invoking this method will cause a ControlFlowExtractor to try to extract them.
        Parameters:
        pp - the program point
        Returns:
        true if pp is inside a loop
      • isInsideIfThenElse

        public boolean isInsideIfThenElse​(ProgramPoint pp)
        Yields true if and only if the given program point is inside one of the branches of an IfThenElse.

        Note that if no control flow structures have been provided by frontends, and no attempt at extracting them has been made yet, invoking this method will cause a ControlFlowExtractor to try to extract them.
        Parameters:
        pp - the program point
        Returns:
        true if pp is inside an if-then-else
      • getGuards

        public java.util.Collection<Statement> getGuards​(ProgramPoint pp)
        Yields the guard of all the ControlFlowStructures, regardless of their type, containing the given program point. If the program point is not part of the body of a control structure, this method returns an empty collection.

        Note that if no control flow structures have been provided by frontends, and no attempt at extracting them has been made yet, invoking this method will cause a ControlFlowExtractor to try to extract them.
        Parameters:
        pp - the program point
        Returns:
        the collection of the guards of all structures containing pp
      • getLoopGuards

        public java.util.Collection<Statement> getLoopGuards​(ProgramPoint pp)
        Yields the guard of all Loops containing the given program point. If the program point is not part of the body of a loop, this method returns an empty collection.

        Note that if no control flow structures have been provided by frontends, and no attempt at extracting them has been made yet, invoking this method will cause a ControlFlowExtractor to try to extract them.
        Parameters:
        pp - the program point
        Returns:
        the collection of the guards of all loops containing pp
      • getIfThenElseGuards

        public java.util.Collection<Statement> getIfThenElseGuards​(ProgramPoint pp)
        Yields the guard of all the IfThenElse containing the given program point. If the program point is not part of a branch of an if-then-else, this method returns an empty collection.

        Note that if no control flow structures have been provided by frontends, and no attempt at extracting them has been made yet, invoking this method will cause a ControlFlowExtractor to try to extract them.
        Parameters:
        pp - the program point
        Returns:
        the collection of the guards of all if-then-elses containing pp
      • getMostRecentGuard

        public Statement getMostRecentGuard​(ProgramPoint pp)
        Yields the guard of the most recent ControlFlowStructure, regardless of its type, containing the given program point. If the program point is not part of the body of a control structure, this method returns null.

        Note that if no control flow structures have been provided by frontends, and no attempt at extracting them has been made yet, invoking this method will cause a ControlFlowExtractor to try to extract them.
        Parameters:
        pp - the program point
        Returns:
        the most recent if-then-else guard, or null
      • getMostRecentLoopGuard

        public Statement getMostRecentLoopGuard​(ProgramPoint pp)
        Yields the guard of the most recent Loop containing the given program point. If the program point is not part of the body of a loop, this method returns null.

        Note that if no control flow structures have been provided by frontends, and no attempt at extracting them has been made yet, invoking this method will cause a ControlFlowExtractor to try to extract them.
        Parameters:
        pp - the program point
        Returns:
        the most recent loop guard, or null
      • getMostRecentIfThenElseGuard

        public Statement getMostRecentIfThenElseGuard​(ProgramPoint pp)
        Yields the guard of the most recent IfThenElse containing the given program point. If the program point is not part of a branch of an if-then-else, this method returns null.

        Note that if no control flow structures have been provided by frontends, and no attempt at extracting them has been made yet, invoking this method will cause a ControlFlowExtractor to try to extract them.
        Parameters:
        pp - the program point
        Returns:
        the most recent if-then-else guard, or null