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>> AnalyzedCFG<A> fixpoint​(AnalysisState<A> entryState,
                                                                    InterproceduralAnalysis<A> interprocedural,
                                                                    WorkingSet<Statement> ws,
                                                                    FixpointConfiguration conf,
                                                                    ScopeId id)
                                                             throws FixpointException
        Computes a fixpoint over this control flow graph. This method returns a AnalyzedCFG instance mapping each Statement to the AnalysisState computed by this method. The computation starts at the statements returned by CodeGraph.getEntrypoints(), 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
        Parameters:
        entryState - the entry states to apply to each Statement returned by CodeGraph.getEntrypoints()
        interprocedural - the interprocedural analysis that can be queried when a call towards an other cfg is encountered
        ws - the WorkingSet instance to use for this computation
        conf - the FixpointConfiguration containing the parameters tuning fixpoint behavior
        id - a ScopeId meant to identify this specific result based on how it has been produced, that will be embedded in the returned cfg
        Returns:
        a AnalyzedCFG 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>> AnalyzedCFG<A> fixpoint​(java.util.Collection<Statement> entrypoints,
                                                                    AnalysisState<A> entryState,
                                                                    InterproceduralAnalysis<A> interprocedural,
                                                                    WorkingSet<Statement> ws,
                                                                    FixpointConfiguration conf,
                                                                    ScopeId id)
                                                             throws FixpointException
        Computes a fixpoint over this control flow graph. This method returns a AnalyzedCFG instance mapping each Statement to the AnalysisState computed by this method. 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
        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 interprocedural analysis that can be queried when a call towards an other cfg is encountered
        ws - the WorkingSet instance to use for this computation
        conf - the FixpointConfiguration containing the parameters tuning fixpoint behavior
        id - a ScopeId meant to identify this specific result based on how it has been produced, that will be embedded in the returned cfg
        Returns:
        a AnalyzedCFG 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>> AnalyzedCFG<A> fixpoint​(AnalysisState<A> singleton,
                                                                    java.util.Map<Statement,​AnalysisState<A>> startingPoints,
                                                                    InterproceduralAnalysis<A> interprocedural,
                                                                    WorkingSet<Statement> ws,
                                                                    FixpointConfiguration conf,
                                                                    ScopeId id)
                                                             throws FixpointException
        Computes a fixpoint over this control flow graph. This method returns a AnalyzedCFG instance mapping each Statement to the AnalysisState computed by this method. 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
        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 to use as a starting point of the computation (that must be nodes of this cfg) and the entry states to apply on them
        interprocedural - the interprocedural analysis that can be queried when a call towards an other cfg is encountered
        ws - the WorkingSet instance to use for this computation
        conf - the FixpointConfiguration containing the parameters tuning fixpoint behavior
        id - a ScopeId meant to identify this specific result based on how it has been produced, that will be embedded in the returned cfg
        Returns:
        a AnalyzedCFG 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
      • backwardFixpoint

        public <A extends AbstractState<A>> AnalyzedCFG<A> backwardFixpoint​(AnalysisState<A> exitState,
                                                                            InterproceduralAnalysis<A> interprocedural,
                                                                            WorkingSet<Statement> ws,
                                                                            FixpointConfiguration conf,
                                                                            ScopeId id)
                                                                     throws FixpointException
        Computes a backward fixpoint over this control flow graph. This method returns a BackwardAnalyzedCFG instance mapping each Statement to the AnalysisState computed by this method. The computation starts at the statements returned by getAllExitpoints(), using exitState as exit 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
        Parameters:
        exitState - the exit states to apply to each Statement returned by getAllExitpoints()
        interprocedural - the interprocedural analysis that can be queried when a call towards an other cfg is encountered
        ws - the WorkingSet instance to use for this computation
        conf - the FixpointConfiguration containing the parameters tuning fixpoint behavior
        id - a ScopeId meant to identify this specific result based on how it has been produced, that will be embedded in the returned cfg
        Returns:
        a BackwardAnalyzedCFG 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
      • backwardFixpoint

        public <A extends AbstractState<A>> AnalyzedCFG<A> backwardFixpoint​(java.util.Collection<Statement> exitpoints,
                                                                            AnalysisState<A> exitState,
                                                                            InterproceduralAnalysis<A> interprocedural,
                                                                            WorkingSet<Statement> ws,
                                                                            FixpointConfiguration conf,
                                                                            ScopeId id)
                                                                     throws FixpointException
        Computes a backward fixpoint over this control flow graph. This method returns a BackwardAnalyzedCFG instance mapping each Statement to the AnalysisState computed by this method. The computation starts at the statements in exitpoints, using exitState as exit 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
        Parameters:
        exitpoints - the collection of Statements that to use as a starting point of the computation (that must be nodes of this cfg)
        exitState - the exit states to apply to each Statement in exitpoints
        interprocedural - the interprocedural analysis that can be queried when a call towards an other cfg is encountered
        ws - the WorkingSet instance to use for this computation
        conf - the FixpointConfiguration containing the parameters tuning fixpoint behavior
        id - a ScopeId meant to identify this specific result based on how it has been produced, that will be embedded in the returned cfg
        Returns:
        a BackwardAnalyzedCFG 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
      • backwardFixpoint

        public <A extends AbstractState<A>> AnalyzedCFG<A> backwardFixpoint​(AnalysisState<A> singleton,
                                                                            java.util.Map<Statement,​AnalysisState<A>> startingPoints,
                                                                            InterproceduralAnalysis<A> interprocedural,
                                                                            WorkingSet<Statement> ws,
                                                                            FixpointConfiguration conf,
                                                                            ScopeId id)
                                                                     throws FixpointException
        Computes a backward fixpoint over this control flow graph. This method returns a BackwardAnalyzedCFG instance mapping each Statement to the AnalysisState computed by this method. The computation starts at the statements in startingPoints, using as its exit 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
        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 to use as a starting point of the computation (that must be nodes of this cfg) and the exit states to apply on them
        interprocedural - the interprocedural analysis that can be queried when a call towards an other cfg is encountered
        ws - the WorkingSet instance to use for this computation
        conf - the FixpointConfiguration containing the parameters tuning fixpoint behavior
        id - a ScopeId meant to identify this specific result based on how it has been produced, that will be embedded in the returned cfg
        Returns:
        a BackwardAnalyzedCFG 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
      • getCycleEntries

        public java.util.Collection<Statement> getCycleEntries()
        Yields all the nodes that are part of cycles in the graph that are also reachable from outside the cycle itself (that is, if they are also entrypoints or if they have an incoming back-edge).

        In a CFG, the normal reasoning is replaced by taking all the Loop conditions appearing in the cfg's control flow structures.
        Specified by:
        getCycleEntries in interface Graph<CFG,​Statement,​Edge>
        Returns:
        the nodes that are cycle entries
      • computeBasicBlocks

        public void computeBasicBlocks()
        Computes the basic blocks of this cfg, that is, the sequences of statements with no incoming branches (except to the first statement) and no outgoing branches (except from the last statement). The result of the computation can be retrieved through getBasicBlocks().

        Note that control flow structures must be available for this task: if those have not been provided at construction, ensure that extractControlFlowStructures(ControlFlowExtractor) has been invoked after constructing the cfg.
      • getBasicBlocks

        public java.util.Map<Statement,​Statement[]> getBasicBlocks()
        Yields the basic blocks of this cfg, available only after computeBasicBlocks() has been invoked.
        Returns:
        the basic blocks, returned as pairs in the form of <leader, block>
        Throws:
        java.lang.IllegalStateException - if computeBasicBlocks() has not been invoked first