Class EvaluationOrderGraphPass

java.lang.Object
de.fraunhofer.aisec.cpg.passes.Pass
de.fraunhofer.aisec.cpg.passes.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.
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected java.util.List<de.fraunhofer.aisec.cpg.graph.Node> currentEOG  
    protected java.util.EnumMap<Properties,​java.lang.Object> currentProperties  
    protected java.util.List<de.fraunhofer.aisec.cpg.graph.Node> intermediateNodes  
    protected java.util.Map<java.lang.Class<? extends de.fraunhofer.aisec.cpg.graph.Node>,​CallableInterface<? extends de.fraunhofer.aisec.cpg.graph.Node>> map  

    Fields inherited from class de.fraunhofer.aisec.cpg.passes.Pass

    lang, log, name
  • Constructor Summary

    Constructors
    Constructor Description
    EvaluationOrderGraphPass()  
  • Method Summary

    Modifier and Type Method Description
    void accept​(TranslationResult result)  
    protected void addEOGEdge​(de.fraunhofer.aisec.cpg.graph.Node prev, de.fraunhofer.aisec.cpg.graph.Node next)
    Builds an EOG edge from prev to next.
    protected void addMultipleIncomingEOGEdges​(java.util.List<de.fraunhofer.aisec.cpg.graph.Node> prevs, de.fraunhofer.aisec.cpg.graph.Node next)  
    void addToCurrentEOG​(java.util.List<de.fraunhofer.aisec.cpg.graph.Node> nodes)  
    static boolean checkEOGInvariant​(de.fraunhofer.aisec.cpg.graph.Node n)
    Checks if every node that has another node in its next or previous EOG List is also contained in that nodes previous or next EOG list to ensure the bidirectionality of the relation in both lists.
    void cleanup()  
    protected void connectCurrentToLoopStart()
    Connects current EOG nodes to the previously saved loop start to mimic control flow of loops
    protected void createEOG​(@Nullable de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void exitLoop​(@NonNull Statement loopStatement, @NonNull LoopScope loopScope)
    Connects the current EOG leaf nodes to the last stacked node, e.g.
    java.util.List<de.fraunhofer.aisec.cpg.graph.Node> getCurrentEOG()  
    protected void handleArrayCreationExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleArraySubscriptionExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleAssertStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleBinaryOperator​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleBreakStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleCallExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleCaseStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleCastExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleCompoundStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleCompoundStatementExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleConditionalExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleConstructExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleContinueStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleDeclarationStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleDefault​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleDeleteExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleDoStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleExpressionList​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleForEachStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleForStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleFunctionDeclaration​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleGotoStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleIfStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleInitializerListExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleLabelStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleMemberExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleNamespaceDeclaration​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleNewExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleRecordDeclaration​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleReturnStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleStatementHolder​(StatementHolder statementHolder)  
    protected void handleSwitchStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleSynchronizedStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleTranslationUnitDeclaration​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleTryStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleUnaryOperator​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleVariableDeclaration​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    protected void handleWhileStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)  
    void pushToEOG​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    Creates an EOG-edge between the given argument node and the saved currentEOG Edges.
    protected static boolean reachableFromValidEOGRoot​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    Searches backwards in the EOG Graph on whether or not there is a path from a function declaration to the given node.
    protected void removeUnreachableEOGEdges​(@NonNull TranslationUnitDeclaration tu)
    Removes EOG edges by first building the negative set of nodes that cannot be visited and then remove there outgoing edges.In contrast to truncateLooseEdges this also removes cycles.
    void setCurrentEOG​(de.fraunhofer.aisec.cpg.graph.Node node)  
    void setCurrentEOG​(java.util.List<de.fraunhofer.aisec.cpg.graph.Node> currentEOG)  
    <T extends de.fraunhofer.aisec.cpg.graph.Node>
    void
    setCurrentEOGs​(java.util.List<T> nodes)  

    Methods inherited from class de.fraunhofer.aisec.cpg.passes.Pass

    getLang, getName, setLang, supportsLanguageFrontend

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.function.Consumer

    andThen
  • Field Details

    • map

      protected final java.util.Map<java.lang.Class<? extends de.fraunhofer.aisec.cpg.graph.Node>,​CallableInterface<? extends de.fraunhofer.aisec.cpg.graph.Node>> map
    • currentEOG

      protected java.util.List<de.fraunhofer.aisec.cpg.graph.Node> currentEOG
    • currentProperties

      protected final java.util.EnumMap<Properties,​java.lang.Object> currentProperties
    • intermediateNodes

      protected final java.util.List<de.fraunhofer.aisec.cpg.graph.Node> intermediateNodes
  • Constructor Details

    • EvaluationOrderGraphPass

      public EvaluationOrderGraphPass()
  • Method Details

    • reachableFromValidEOGRoot

      protected static boolean reachableFromValidEOGRoot​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
      Searches backwards in the EOG Graph on whether or not there is a path from a function declaration to the given node. After the construction phase some unreachable nodes may have EOG edges. This function also serves to truncate the EOG graph by unreachable paths.
      Parameters:
      node - - That lies on the reachable or unreachable path
      Returns:
      true if the node can bea reached from a function declaration
    • cleanup

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

      public void accept​(TranslationResult result)
    • checkEOGInvariant

      public static boolean checkEOGInvariant​(de.fraunhofer.aisec.cpg.graph.Node n)
      Checks if every node that has another node in its next or previous EOG List is also contained in that nodes previous or next EOG list to ensure the bidirectionality of the relation in both lists.
      Parameters:
      n -
      Returns:
    • removeUnreachableEOGEdges

      protected void removeUnreachableEOGEdges​(@NonNull TranslationUnitDeclaration tu)
      Removes EOG edges by first building the negative set of nodes that cannot be visited and then remove there outgoing edges.In contrast to truncateLooseEdges this also removes cycles.
    • handleTranslationUnitDeclaration

      protected void handleTranslationUnitDeclaration​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleNamespaceDeclaration

      protected void handleNamespaceDeclaration​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleVariableDeclaration

      protected void handleVariableDeclaration​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleRecordDeclaration

      protected void handleRecordDeclaration​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleStatementHolder

      protected void handleStatementHolder​(StatementHolder statementHolder)
    • handleFunctionDeclaration

      protected void handleFunctionDeclaration​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • createEOG

      protected void createEOG​(@Nullable de.fraunhofer.aisec.cpg.graph.Node node)
    • handleDefault

      protected void handleDefault​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleCallExpression

      protected void handleCallExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleMemberExpression

      protected void handleMemberExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleArraySubscriptionExpression

      protected void handleArraySubscriptionExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleArrayCreationExpression

      protected void handleArrayCreationExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleDeclarationStatement

      protected void handleDeclarationStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleReturnStatement

      protected void handleReturnStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleBinaryOperator

      protected void handleBinaryOperator​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleCompoundStatement

      protected void handleCompoundStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleUnaryOperator

      protected void handleUnaryOperator​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleCompoundStatementExpression

      protected void handleCompoundStatementExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleAssertStatement

      protected void handleAssertStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleTryStatement

      protected void handleTryStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleContinueStatement

      protected void handleContinueStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleDeleteExpression

      protected void handleDeleteExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleBreakStatement

      protected void handleBreakStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleLabelStatement

      protected void handleLabelStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleGotoStatement

      protected void handleGotoStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleCaseStatement

      protected void handleCaseStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleNewExpression

      protected void handleNewExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleCastExpression

      protected void handleCastExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleExpressionList

      protected void handleExpressionList​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleInitializerListExpression

      protected void handleInitializerListExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleConstructExpression

      protected void handleConstructExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • pushToEOG

      public void pushToEOG​(@NonNull de.fraunhofer.aisec.cpg.graph.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<de.fraunhofer.aisec.cpg.graph.Node> getCurrentEOG()
    • setCurrentEOG

      public void setCurrentEOG​(java.util.List<de.fraunhofer.aisec.cpg.graph.Node> currentEOG)
    • setCurrentEOG

      public void setCurrentEOG​(de.fraunhofer.aisec.cpg.graph.Node node)
    • setCurrentEOGs

      public <T extends de.fraunhofer.aisec.cpg.graph.Node> void setCurrentEOGs​(java.util.List<T> nodes)
    • addToCurrentEOG

      public void addToCurrentEOG​(java.util.List<de.fraunhofer.aisec.cpg.graph.Node> nodes)
    • exitLoop

      protected 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

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

      protected void addEOGEdge​(de.fraunhofer.aisec.cpg.graph.Node prev, de.fraunhofer.aisec.cpg.graph.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

      protected void addMultipleIncomingEOGEdges​(java.util.List<de.fraunhofer.aisec.cpg.graph.Node> prevs, de.fraunhofer.aisec.cpg.graph.Node next)
    • handleSynchronizedStatement

      protected void handleSynchronizedStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleConditionalExpression

      protected void handleConditionalExpression​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleDoStatement

      protected void handleDoStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleForEachStatement

      protected void handleForEachStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleForStatement

      protected void handleForStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleIfStatement

      protected void handleIfStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleSwitchStatement

      protected void handleSwitchStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)
    • handleWhileStatement

      protected void handleWhileStatement​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node)