Program Slicing
Program Slicing
For dynamic slicing, the resulting slice would include the following statements:
These statements are considered relevant because they directly affect the execution and output of the program for that
specific run.
Static Slicing
In static slicing, the analysis is performed on the source code without executing it.
It is typically performed using static code analysis techniques like data flow
analysis and control flow analysis.
Static slicing is useful for identifying potential dependencies in the code without
the need for actual execution.
Cont…
Step 1:-Let's create a simple Java program that calculates the factorial of a number.
This static slicing process helps isolate the relevant portion of the code related to the calculation of the factorial of 5
making it easier to analyze and understand
Forward slicing
Forward slicing starts from a slicing criterion and identifies all statements that are
affected by it.
It traces the flow of data and control from the slicing criterion forward in the
program.
Forward slicing is useful for understanding how changes to certain variables or
statements propagate through the program.
Forward slicing
Let's demonstrate forward slicing with a Java example. We'll consider a simple program that
calculates the sum of the first N natural numbers
Let's choose the slicing criterion as the calculation of the sum of the first 5 natural numbers.
Perform Forward Slicing
Trace the flow of data and control from the slicing criterion (calculation of the sum) forward in the program.
Forward slicing
Extract Relevant Code
Based on the forward slicing analysis, extract the relevant portion of the code that directly
contributes to the calculation of the sum of the first 5 natural numbers.
2. https://www.sciencedirect.com/science/article/pii/S2352220822000797
3. https://core.ac.uk/download/pdf/295539081.pdf
4. https://mieszko.ece.ubc.ca/slicer4j-esec-fse-2021.pdf