Package de.fraunhofer.aisec.cpg.passes
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.EOG is similar to the CFG
ControlFlowGraphPass, but its nodes are not limited to *executable* statements but also include (some) *evaluated* expressions and CompoundStatements. This leads to 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. In CFG, the last reachable statement(s) will not have any further nextCFG edges.
- For IF statements, EOG treats the "if" keyword and the condition as separate nodes. CFG treats this as one "if" statement.
- EOG considers an opening blocking ("CompoundStatement", indicated by a "{") as a separate node. CFG will rather use the first actual executable statement within the block.
- EOG considers a method header as a node. CFG will consider the first executable statement of the methods as a node.
-
-
Constructor Summary
Constructors Constructor Description EvaluationOrderGraphPass()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(TranslationResult result)voidaddEOGEdge(Node prev, Node next)Builds an EOG edge from prev to next.voidaddMultipleIncomingEOGEdges(java.util.List<Node> prevs, Node next)voidaddToCurrentEOG(java.util.List<Node> nodes)voidcleanup()voidconnectCurrentToLoopStart()Connects current EOG nodes to the previously saved loop start to mimic control flow of loopsvoidexitLoop(@NonNull Statement loopStatement, @NonNull LoopScope loopScope)Connects the current EOG leaf nodes to the last stacked node, e.g.java.util.List<Node>getCurrentEOG()<T extends Node>
voidpushToEOG(@NonNull T node)voidsetCurrentEOG(Node node)voidsetCurrentEOG(java.util.List<Node> currentEOG)<T extends Node>
voidsetCurrentEOGs(java.util.List<T> nodes)-
Methods inherited from class de.fraunhofer.aisec.cpg.passes.Pass
getLang, setLang, supportsLanguageFrontend
-
-
-
-
Method Detail
-
accept
public void accept(TranslationResult result)
-
pushToEOG
public <T extends Node> void pushToEOG(@NonNull T node)
-
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 statementloopScope- 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 nodenext- the next node
-
-