Package com.tonic.analysis.pdg.slice
Class PDGSlicer
- java.lang.Object
-
- com.tonic.analysis.pdg.slice.PDGSlicer
-
public class PDGSlicer extends Object
Intraprocedural slicer over a program dependence graph.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SliceResultbackwardSlice(PDGNode criterion)Slices backwards from a single node.SliceResultbackwardSlice(Set<PDGNode> criterion)Walks incoming edges transitively from every criterion node.SliceResultbackwardSliceControlOnly(PDGNode criterion)Slices backwards over control dependences only, leaving this slicer's settings untouched.SliceResultbackwardSliceDataOnly(PDGNode criterion)Slices backwards over data dependences only, leaving this slicer's settings untouched.SliceResultbackwardSliceWithFilter(PDGNode criterion, Predicate<PDGNode> filter)Slices backwards, stopping the walk at any node the filter rejects.SliceResultchop(PDGNode source, PDGNode sink)Intersects the forward slice of a source with the backward slice of a sink.SliceResultchop(Set<PDGNode> sources, Set<PDGNode> sinks)Intersects the forward slice of the sources with the backward slice of the sinks.List<List<PDGNode>>findAllPaths(PDGNode source, PDGNode target, int maxDepth)Enumerates the simple dependence paths from source to target by depth-first search.SliceResultforwardSlice(PDGNode criterion)Slices forwards from a single node.SliceResultforwardSlice(Set<PDGNode> criterion)Walks outgoing edges transitively from every criterion node.SliceResultforwardSliceControlOnly(PDGNode criterion)Slices forwards over control dependences only, leaving this slicer's settings untouched.SliceResultforwardSliceDataOnly(PDGNode criterion)Slices forwards over data dependences only, leaving this slicer's settings untouched.SliceResultforwardSliceWithFilter(PDGNode criterion, Predicate<PDGNode> filter)Slices forwards, stopping the walk at any node the filter rejects.PDGgetPdg()booleanisIncludeControlDependencies()booleanisIncludeDataDependencies()booleanisReachable(PDGNode source, PDGNode target)Tests whether target appears in the forward slice of source.PDGSlicerwithControlDependencies(boolean include)Sets whether control dependence edges are traversed.PDGSlicerwithDataDependencies(boolean include)Sets whether data dependence edges are traversed.
-
-
-
Constructor Detail
-
PDGSlicer
public PDGSlicer(PDG pdg)
Creates a slicer following both control and data dependences.- Parameters:
pdg- the graph to slice
-
-
Method Detail
-
getPdg
public PDG getPdg()
- Returns:
- the pdg
-
isIncludeControlDependencies
public boolean isIncludeControlDependencies()
- Returns:
- whether include control dependencies
-
isIncludeDataDependencies
public boolean isIncludeDataDependencies()
- Returns:
- whether include data dependencies
-
withControlDependencies
public PDGSlicer withControlDependencies(boolean include)
Sets whether control dependence edges are traversed.- Parameters:
include- whether to follow control dependences- Returns:
- this slicer
-
withDataDependencies
public PDGSlicer withDataDependencies(boolean include)
Sets whether data dependence edges are traversed.- Parameters:
include- whether to follow data dependences- Returns:
- this slicer
-
backwardSlice
public SliceResult backwardSlice(PDGNode criterion)
Slices backwards from a single node.- Parameters:
criterion- the slicing criterion, may be null- Returns:
- the nodes and edges that can affect the criterion, empty if it is null
-
backwardSlice
public SliceResult backwardSlice(Set<PDGNode> criterion)
Walks incoming edges transitively from every criterion node.- Parameters:
criterion- the slicing criteria- Returns:
- the nodes and edges that can affect the criteria
-
forwardSlice
public SliceResult forwardSlice(PDGNode criterion)
Slices forwards from a single node.- Parameters:
criterion- the slicing criterion- Returns:
- the nodes and edges the criterion can affect
-
forwardSlice
public SliceResult forwardSlice(Set<PDGNode> criterion)
Walks outgoing edges transitively from every criterion node.- Parameters:
criterion- the slicing criteria- Returns:
- the nodes and edges the criteria can affect
-
chop
public SliceResult chop(PDGNode source, PDGNode sink)
Intersects the forward slice of a source with the backward slice of a sink.- Parameters:
source- the node to slice forward fromsink- the node to slice backward from- Returns:
- the nodes on some dependence path from source to sink
-
chop
public SliceResult chop(Set<PDGNode> sources, Set<PDGNode> sinks)
Intersects the forward slice of the sources with the backward slice of the sinks.- Parameters:
sources- the nodes to slice forward fromsinks- the nodes to slice backward from- Returns:
- the nodes on some dependence path from a source to a sink
-
backwardSliceWithFilter
public SliceResult backwardSliceWithFilter(PDGNode criterion, Predicate<PDGNode> filter)
Slices backwards, stopping the walk at any node the filter rejects.- Parameters:
criterion- the slicing criterionfilter- predicate a node must satisfy to be kept and traversed through- Returns:
- the accepted nodes and the edges between them
-
forwardSliceWithFilter
public SliceResult forwardSliceWithFilter(PDGNode criterion, Predicate<PDGNode> filter)
Slices forwards, stopping the walk at any node the filter rejects.- Parameters:
criterion- the slicing criterionfilter- predicate a node must satisfy to be kept and traversed through- Returns:
- the accepted nodes and the edges between them
-
backwardSliceControlOnly
public SliceResult backwardSliceControlOnly(PDGNode criterion)
Slices backwards over control dependences only, leaving this slicer's settings untouched.- Parameters:
criterion- the slicing criterion- Returns:
- the control-only backward slice
-
backwardSliceDataOnly
public SliceResult backwardSliceDataOnly(PDGNode criterion)
Slices backwards over data dependences only, leaving this slicer's settings untouched.- Parameters:
criterion- the slicing criterion- Returns:
- the data-only backward slice
-
forwardSliceControlOnly
public SliceResult forwardSliceControlOnly(PDGNode criterion)
Slices forwards over control dependences only, leaving this slicer's settings untouched.- Parameters:
criterion- the slicing criterion- Returns:
- the control-only forward slice
-
forwardSliceDataOnly
public SliceResult forwardSliceDataOnly(PDGNode criterion)
Slices forwards over data dependences only, leaving this slicer's settings untouched.- Parameters:
criterion- the slicing criterion- Returns:
- the data-only forward slice
-
findAllPaths
public List<List<PDGNode>> findAllPaths(PDGNode source, PDGNode target, int maxDepth)
Enumerates the simple dependence paths from source to target by depth-first search.- Parameters:
source- the start nodetarget- the end nodemaxDepth- the maximum number of edges a path may use- Returns:
- every path found, each as a node list from source to target
-
-