Class EvaluationOrderGraphPass

  • All Implemented Interfaces:
    java.util.function.Consumer<TranslationResult>

    public class EvaluationOrderGraphPass
    extends Pass
    Creates an Evaluation Order Graph (EOG) based on AST.

    An EOG is an intraprocedural directed graph whose vertices are executable AST nodes and edges connect them in the order they would be executed when running the program.

    An EOG always starts at the header of a method/function and ends in one (virtual) or multiple return statements. A virtual return statement with a code location of (-1,-1) is used if the actual source code does not have an explicit return statement.

    The EOG is similar to the CFG ControlFlowGraphPass, but there are some subtle differences:

    • For methods without explicit return statement, EOF will have an edge to a virtual return node with line number -1 which does not exist in the original code. A CFG will always end with the last reachable statement(s) and not insert any virtual return statements.
    • EOG considers an opening blocking ("CompoundStatement", indicated by a "{") as a separate node. A CFG will rather use the first actual executable statement within the block.
    • For IF statements, EOG treats the "if" keyword and the condition as separate nodes. CFG treats this as one "if" statement.
    • EOG considers a method header as a node. CFG will consider the first executable statement of the methods as a node.
    • Constructor Detail

      • EvaluationOrderGraphPass

        public EvaluationOrderGraphPass()
    • Method Detail

      • cleanup

        public void cleanup()
        Specified by:
        cleanup in class Pass
      • createEOG

        public void createEOG​(@Nullable Node node)
      • pushToEOG

        public void pushToEOG​(@NonNull Node node)
        Creates an EOG-edge between the given argument node and the saved currentEOG Edges.
        Parameters:
        node - node that gets the incoming edge
      • getCurrentEOG

        public java.util.List<Node> getCurrentEOG()
      • setCurrentEOG

        public void setCurrentEOG​(java.util.List<Node> currentEOG)
      • setCurrentEOG

        public void setCurrentEOG​(Node node)
      • setCurrentEOGs

        public <T extends Node> void setCurrentEOGs​(java.util.List<T> nodes)
      • addToCurrentEOG

        public void addToCurrentEOG​(java.util.List<Node> nodes)
      • exitLoop

        public void exitLoop​(@NonNull Statement loopStatement,
                             @NonNull LoopScope loopScope)
        Connects the current EOG leaf nodes to the last stacked node, e.g. loop head, and removes the nodes.
        Parameters:
        loopStatement - the loop statement
        loopScope - the loop scope
      • connectCurrentToLoopStart

        public void connectCurrentToLoopStart()
        Connects current EOG nodes to the previously saved loop start to mimic control flow of loops
      • addEOGEdge

        public void addEOGEdge​(Node prev,
                               Node next)
        Builds an EOG edge from prev to next. 'eogDirection' defines how the node instances save the references constituting the edge. 'FORWARD': only the nodes nextEOG member contains references, an points to the next nodes. 'BACKWARD': only the nodes prevEOG member contains references and points to the previous nodes. 'BIDIRECTIONAL': nextEOG and prevEOG contain references and point to the previous and the next nodes.
        Parameters:
        prev - the previous node
        next - the next node
      • addMultipleIncomingEOGEdges

        public void addMultipleIncomingEOGEdges​(java.util.List<Node> prevs,
                                                Node next)