Package de.fraunhofer.aisec.cpg.passes
Class ControlFlowSensitiveDFGPass.FunctionLevelFixpointIterator
java.lang.Object
de.fraunhofer.aisec.cpg.passes.ControlFlowSensitiveDFGPass.FunctionLevelFixpointIterator
- Enclosing class:
- ControlFlowSensitiveDFGPass
protected class ControlFlowSensitiveDFGPass.FunctionLevelFixpointIterator
extends java.lang.Object
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>>>joinPointsprotected java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>>removesA Node with refined DFG edges (key) is mapped to a set of nodes that were the previous (unrefined) DFG edges and need to be removed later on -
Constructor Summary
Constructors Modifier Constructor Description protectedFunctionLevelFixpointIterator() -
Method Summary
Modifier and Type Method Description protected voidaddDFGToMap(VariableDeclaration variableDeclaration, de.fraunhofer.aisec.cpg.graph.Node prev, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables)Adds a DFG-Edge to the Mapping of variables.protected voidaddToRemoves(de.fraunhofer.aisec.cpg.graph.Node curr, de.fraunhofer.aisec.cpg.graph.Node prev)protected java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>>createShallowCopy(java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> state)Creates a shallow copy to the depth of the nodes.protected java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>eogTraversal(de.fraunhofer.aisec.cpg.graph.Node node)Traverses the EOG starting at a node until there is no more outgoing EOGs to new nodes.java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>>getRemoves()voidhandle(de.fraunhofer.aisec.cpg.graph.Node functionRoot)protected de.fraunhofer.aisec.cpg.graph.NodehandleDeclaredReferenceExpression(DeclaredReferenceExpression currNode, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables, ControlFlowSensitiveDFGPass.IterationFunction iterationFunction)Method that handles DeclaredReferenceExpressions when the EOG is traversedprotected java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>>iterateTillFixpoint(de.fraunhofer.aisec.cpg.graph.Node node, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables, de.fraunhofer.aisec.cpg.graph.Node endNode, boolean stopBefore)This function collects the set of variable definitions valid for the VariableDeclarations defined in the program when reaching a join-point, a node reached by more than one incoming EOG-Edge.protected booleanmergeStates(java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> currentJoinpoint, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables)Merges two states assuming that both states come from valid paths.protected voidmodifyDFGEdges(de.fraunhofer.aisec.cpg.graph.Node currNode, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables)Perform the actual modification of the DFG edges based on the values that are recorded in the variables map for every VariableDeclarationprotected de.fraunhofer.aisec.cpg.graph.NodeobtainAssignmentNode(de.fraunhofer.aisec.cpg.graph.Node node)Get node of the BinaryOperator where the assignment is finished (last node of the Assignment)protected java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>>propagateFromJoinPoints(de.fraunhofer.aisec.cpg.graph.Node node, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables, de.fraunhofer.aisec.cpg.graph.Node endNode, boolean stopBefore)Propagates the state from the join-point until the next join-point is reached.protected voidpropagateValues()Iterates over all join-points and propagates the state that is valid for the sum of incoming eog-Paths to refine the dfg edges at variable usage points.protected voidregisterOutgoingDFG(de.fraunhofer.aisec.cpg.graph.Node currNode, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables)If a Node has a DFG to a VariableDeclaration we need to remove the nextDFG and store the value of the node in our tracking mapprotected voidsetIngoingDFG(de.fraunhofer.aisec.cpg.graph.Node currNode, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables)Stores the prevDFG to a VariableDeclaration of a node in the removes map and adds the values of the VariableDeclaration as prevDFGs to the nodeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
removes
protected java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> removesA Node with refined DFG edges (key) is mapped to a set of nodes that were the previous (unrefined) DFG edges and need to be removed later on -
joinPoints
protected final java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>>> joinPoints
-
-
Constructor Details
-
FunctionLevelFixpointIterator
protected FunctionLevelFixpointIterator()
-
-
Method Details
-
handle
public void handle(de.fraunhofer.aisec.cpg.graph.Node functionRoot) -
getRemoves
public java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> getRemoves() -
addToRemoves
protected void addToRemoves(de.fraunhofer.aisec.cpg.graph.Node curr, de.fraunhofer.aisec.cpg.graph.Node prev) -
eogTraversal
protected java.util.Set<de.fraunhofer.aisec.cpg.graph.Node> eogTraversal(de.fraunhofer.aisec.cpg.graph.Node node)Traverses the EOG starting at a node until there is no more outgoing EOGs to new nodes.- Parameters:
node- starting node- Returns:
- set containing all nodes that have been reached
-
setIngoingDFG
protected void setIngoingDFG(de.fraunhofer.aisec.cpg.graph.Node currNode, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables)Stores the prevDFG to a VariableDeclaration of a node in the removes map and adds the values of the VariableDeclaration as prevDFGs to the node- Parameters:
currNode- node that is analyzed
-
registerOutgoingDFG
protected void registerOutgoingDFG(de.fraunhofer.aisec.cpg.graph.Node currNode, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables)If a Node has a DFG to a VariableDeclaration we need to remove the nextDFG and store the value of the node in our tracking map- Parameters:
currNode- Node that is being analyzed
-
obtainAssignmentNode
protected de.fraunhofer.aisec.cpg.graph.Node obtainAssignmentNode(de.fraunhofer.aisec.cpg.graph.Node node)Get node of the BinaryOperator where the assignment is finished (last node of the Assignment)- Parameters:
node- start node of the assignment LHS DeclaredReferenceExpression- Returns:
- return the last (in eog order) node of the assignment
-
modifyDFGEdges
protected void modifyDFGEdges(de.fraunhofer.aisec.cpg.graph.Node currNode, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables)Perform the actual modification of the DFG edges based on the values that are recorded in the variables map for every VariableDeclaration- Parameters:
currNode- node whose dfg edges have to be replaced
-
iterateTillFixpoint
protected java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> iterateTillFixpoint(de.fraunhofer.aisec.cpg.graph.Node node, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables, de.fraunhofer.aisec.cpg.graph.Node endNode, boolean stopBefore)This function collects the set of variable definitions valid for the VariableDeclarations defined in the program when reaching a join-point, a node reached by more than one incoming EOG-Edge. The state is computed whenever a write access to a variable is encountered. A node may be passed by multiple paths and therefore the states have to be merged at these join-points. However, the number of paths is finite and scales well enough to make a fixpoint iteration of states at join-points is therefore terminating and feasible.This function iterates over the entire EOG starting at a fixed node. If the execution of this function is started with the function-Node which also represents the EOG-Root-Node all Nodes that are part of a valid execution path will be traversed.
- Parameters:
node- - Start of the fixpoint iterationvariables- - The state, composed of a mapping from variables to expression that were prior written to it.endNode- - A node where the iteration shall stop, if null the iteration stops at a point once a fix-point no outgoing eog edge is reachedstopBefore- - denotes whether the iteration shall stop before or after processing the reached node.- Returns:
- The state after reaching on of the terminating conditions
-
handleDeclaredReferenceExpression
protected de.fraunhofer.aisec.cpg.graph.Node handleDeclaredReferenceExpression(DeclaredReferenceExpression currNode, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables, ControlFlowSensitiveDFGPass.IterationFunction iterationFunction)Method that handles DeclaredReferenceExpressions when the EOG is traversed- Parameters:
currNode- DeclaredReferenceExpression that is found in- Returns:
- Node where the EOG traversal should continue
-
propagateValues
protected void propagateValues()Iterates over all join-points and propagates the state that is valid for the sum of incoming eog-Paths to refine the dfg edges at variable usage points. -
propagateFromJoinPoints
protected java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> propagateFromJoinPoints(de.fraunhofer.aisec.cpg.graph.Node node, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables, de.fraunhofer.aisec.cpg.graph.Node endNode, boolean stopBefore)Propagates the state from the join-point until the next join-point is reached.- Parameters:
node- - Start of the propagationvariables- - The state, composed of a mapping from variables to expression that were prior written to it collected at some join-point.endNode- - A node where the iteration shall stop, if null the iteration stops at a point once a fix-point no outgoing eog edge is reachedstopBefore- - denotes whether the iteration shall stop before or after processing the reached node.- Returns:
- The state after reaching on of the terminating conditions
-
addDFGToMap
protected void addDFGToMap(VariableDeclaration variableDeclaration, de.fraunhofer.aisec.cpg.graph.Node prev, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables)Adds a DFG-Edge to the Mapping of variables. Updating the state.- Parameters:
variableDeclaration- - for which a new valid definition has to be added to the stateprev- - the defining expression to the variablevariables- - the state that is updated by the DFG edge
-
mergeStates
protected boolean mergeStates(java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> currentJoinpoint, java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> variables)Merges two states assuming that both states come from valid paths. All the definition for variables are collected into the current state represented bycurrentJoinpoint- Parameters:
currentJoinpoint- - The state we are merging intovariables- - The state we are merging from- Returns:
- whether or not the merging resulted into an update to
currentJoinpoint
-
createShallowCopy
protected java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> createShallowCopy(java.util.Map<VariableDeclaration,java.util.Set<de.fraunhofer.aisec.cpg.graph.Node>> state)Creates a shallow copy to the depth of the nodes. References to nodes are not copied as new objects. Only the collections are created sd new Objects.- Parameters:
state- The state to copy- Returns:
- The copy
-