Compare commits
7 Commits
Final-Proj
...
nico
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c59eb1b5b | ||
|
|
35458c6cbf | ||
|
|
5ac562803a | ||
|
|
4893129144 | ||
|
|
27bc69e837 | ||
|
|
4c7002c263 | ||
|
|
046634109c |
463
README.md
463
README.md
@@ -1,16 +1,467 @@
|
|||||||
### Things
|
## Termanology
|
||||||
1. Forward Slice => All statements that could be affected if you change a given statement.Think of it like ripple effects in water:
|
1. Forward Slice => All statements that could be affected if you change a given statement.
|
||||||
|
2. AIS = Actualy Impacted Set (Manully calcualte the expected outcome)
|
||||||
|
3. EIS = Estimated Impacted Set (The set extracted from the outcome of the program)
|
||||||
|
|
||||||
|
|
||||||
### Run
|
### Run
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
chmod +x run.sh
|
chmod +x run.sh
|
||||||
|
|
||||||
# Show all dependencies for a file
|
# Show all dependencies for a file
|
||||||
./run.sh examples/Example1.java
|
./run.sh examples/Example1.java
|
||||||
|
|
||||||
# Analyze impact of line 3
|
# Analyze impact of line 3
|
||||||
./run.sh examples/Example1.java 3
|
./run.sh examples/Example1.java 3
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Testing
|
||||||
|
## Test1 simple data flow
|
||||||
|
### Line 3 (int x = 5;)
|
||||||
|
AIS = {3, 4, 5, 6}
|
||||||
|
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 3 ===
|
||||||
|
|
||||||
|
Statement(s) at line 3:
|
||||||
|
1: int x = 5 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 3
|
||||||
|
Line 4
|
||||||
|
Line 5
|
||||||
|
Line 6
|
||||||
|
|
||||||
|
Total: 4 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {3, 4, 5, 6} |TP| = 4
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
|
||||||
|
### Line 4 (int y = x + 2;)
|
||||||
|
AIS = {4,5,6}
|
||||||
|
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 4 ===
|
||||||
|
|
||||||
|
Statement(s) at line 4:
|
||||||
|
2: int y = x + 2 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 4
|
||||||
|
Line 5
|
||||||
|
Line 6
|
||||||
|
|
||||||
|
Total: 3 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {4, 5, 6} |TP| = 3
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Test2 Control Dependency
|
||||||
|
### Change at Line 5 (if (x > 5))
|
||||||
|
AIS = {5, 6, 8, 9}
|
||||||
|
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 5 ===
|
||||||
|
|
||||||
|
Statement(s) at line 5:
|
||||||
|
3: if ( x > 5 )
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 5
|
||||||
|
Line 8
|
||||||
|
Line 9
|
||||||
|
|
||||||
|
Total: 3 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {5, 8, 9} |TP| = 3
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {6} |FN| = 1
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
### Change at Line 3 (int x = 10;)
|
||||||
|
AIS = {3, 5, 6, 8, 9}
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 3 ===
|
||||||
|
|
||||||
|
Statement(s) at line 3:
|
||||||
|
1: int x = 10 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 3
|
||||||
|
Line 5
|
||||||
|
Line 6
|
||||||
|
Line 8
|
||||||
|
Line 9
|
||||||
|
|
||||||
|
Total: 5 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {3, 5, 6, 8, 9} |TP| = 5
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Test3 Simple Loop
|
||||||
|
### Change at Line 3 (int sum = 0;)
|
||||||
|
AIS = {3, 6, 8}
|
||||||
|
```Bash
|
||||||
|
=== Impact Analysis for Line 3 ===
|
||||||
|
|
||||||
|
Statement(s) at line 3:
|
||||||
|
1: int sum = 0 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 3
|
||||||
|
Line 6
|
||||||
|
Line 8
|
||||||
|
|
||||||
|
Total: 3 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {3, 6, 8} |TP| = 3
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
### Change at Line 5 (for loop heading)
|
||||||
|
AIS = {5, 6, 8}
|
||||||
|
```Bash
|
||||||
|
=== Impact Analysis for Line 5 ===
|
||||||
|
|
||||||
|
Statement(s) at line 5:
|
||||||
|
3: for ( i = 0 ; i < 5 ; i ++ )
|
||||||
|
4: block
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 5
|
||||||
|
Line 6
|
||||||
|
Line 8
|
||||||
|
|
||||||
|
Total: 3 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {5, 6, 8} |TP| = 3
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Test4 If-Else Branch
|
||||||
|
### Change at Line 5 (if (x > 5))
|
||||||
|
AIS = {5, 6, 8, 10, 11}
|
||||||
|
```Bash
|
||||||
|
=== Impact Analysis for Line 5 ===
|
||||||
|
|
||||||
|
Statement(s) at line 5:
|
||||||
|
4: block
|
||||||
|
3: if ( x > 5 )
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 5
|
||||||
|
Line 6
|
||||||
|
Line 7
|
||||||
|
Line 8
|
||||||
|
Line 10
|
||||||
|
Line 11
|
||||||
|
|
||||||
|
Total: 6 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {5, 6, 7, 8, 10, 11} |TP| = 6
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {7} |FN| = 1
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
### Change at Line 6 (y = x + 10;)
|
||||||
|
AIS = {6, 10, 11}
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 6 ===
|
||||||
|
|
||||||
|
Statement(s) at line 6:
|
||||||
|
5: y = x + 10 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 6
|
||||||
|
|
||||||
|
Total: 1 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {6} |TP| = 1
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {10, 11} |FN| = 2
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Test5 Multiple Uses va
|
||||||
|
### Change at Line 3 (int a = 5;)
|
||||||
|
AIS = {3, 4, 5, 6, 7}
|
||||||
|
```Bash
|
||||||
|
=== Impact Analysis for Line 3 ===
|
||||||
|
|
||||||
|
Statement(s) at line 3:
|
||||||
|
1: int a = 5 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 3
|
||||||
|
Line 4
|
||||||
|
Line 5
|
||||||
|
Line 6
|
||||||
|
Line 7
|
||||||
|
|
||||||
|
Total: 5 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {3, 4, 5, 6, 7} |TP| = 5
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
### Change at Line 4 (int b = a + 2;)
|
||||||
|
AIS = {4, 6, 7}
|
||||||
|
```Bash
|
||||||
|
=== Impact Analysis for Line 4 ===
|
||||||
|
|
||||||
|
Statement(s) at line 4:
|
||||||
|
2: int b = a + 2 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 4
|
||||||
|
Line 6
|
||||||
|
Line 7
|
||||||
|
|
||||||
|
Total: 3 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {4, 6, 7} |TP| = 3
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Test6 Nested Control
|
||||||
|
### Change at Line 5 (if (x > 5))
|
||||||
|
AIS = {5, 6, 7, 10, 11}
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 5 ===
|
||||||
|
|
||||||
|
Statement(s) at line 5:
|
||||||
|
4: block
|
||||||
|
3: if ( x > 5 )
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 5
|
||||||
|
Line 6
|
||||||
|
Line 7
|
||||||
|
Line 10
|
||||||
|
Line 11
|
||||||
|
|
||||||
|
Total: 5 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {5, 6, 7, 10, 11} |TP| = 5
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
### Change at Line 6 (if (x > 8))
|
||||||
|
AIS = {6, 7, 10, 11}
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 6 ===
|
||||||
|
|
||||||
|
Statement(s) at line 6:
|
||||||
|
5: if ( x > 8 )
|
||||||
|
6: block
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 6
|
||||||
|
Line 7
|
||||||
|
Line 10
|
||||||
|
Line 11
|
||||||
|
|
||||||
|
Total: 4 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {6, 7, 10, 11} |TP| = 4
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Test7 While Loop
|
||||||
|
### Change at Line 5 (while (count < 5))
|
||||||
|
AIS = {5, 6, 7, 9}
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 5 ===
|
||||||
|
|
||||||
|
Statement(s) at line 5:
|
||||||
|
3: while ( count < 5 )
|
||||||
|
4: block
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 5
|
||||||
|
Line 6
|
||||||
|
Line 7
|
||||||
|
Line 9
|
||||||
|
|
||||||
|
Total: 4 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {5, 6, 7, 9} |TP| = 4
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
### Change at Line 3 (int count = 0;)
|
||||||
|
AIS = {3, 5, 6, 7, 9}
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 3 ===
|
||||||
|
|
||||||
|
Statement(s) at line 3:
|
||||||
|
1: int count = 0 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 3
|
||||||
|
Line 5
|
||||||
|
Line 6
|
||||||
|
Line 7
|
||||||
|
Line 9
|
||||||
|
|
||||||
|
Total: 5 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {3, 5, 6, 7, 9} |TP| = 5
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
***
|
||||||
|
|
||||||
|
## Test8 Reassignment
|
||||||
|
### Change at Line 3 (int x = 5;)
|
||||||
|
AIS = {3, 4, 7}
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 3 ===
|
||||||
|
|
||||||
|
Statement(s) at line 3:
|
||||||
|
1: int x = 5 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 3
|
||||||
|
Line 4
|
||||||
|
Line 7
|
||||||
|
|
||||||
|
Total: 3 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {3, 4, 7} |TP| = 3
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
### Change at Line 5 (x = 10;)
|
||||||
|
AIS = {5, 6, 8}
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 5 ===
|
||||||
|
|
||||||
|
Statement(s) at line 5:
|
||||||
|
3: x = 10 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 5
|
||||||
|
Line 6
|
||||||
|
Line 8
|
||||||
|
|
||||||
|
Total: 3 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {5, 6, 8} |TP| = 3
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Test9 No Impact
|
||||||
|
### Change at Line 4 (int y = 10;)
|
||||||
|
AIS = {4, 6, 8}
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 4 ===
|
||||||
|
|
||||||
|
Statement(s) at line 4:
|
||||||
|
2: int y = 10 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 4
|
||||||
|
Line 6
|
||||||
|
Line 8
|
||||||
|
|
||||||
|
Total: 3 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {4, 6, 8} |TP| = 3
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
### Change at Line 3 (int x = 5;)
|
||||||
|
AIS = {3, 5, 7}
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 3 ===
|
||||||
|
|
||||||
|
Statement(s) at line 3:
|
||||||
|
1: int x = 5 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 3
|
||||||
|
Line 5
|
||||||
|
Line 7
|
||||||
|
|
||||||
|
Total: 3 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {3, 5, 7} |TP| = 3
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Test10 Complex Expression
|
||||||
|
### Change at Line 3 (int a = 2;)
|
||||||
|
AIS = {3, 6, 7, 8, 9}
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 3 ===
|
||||||
|
|
||||||
|
Statement(s) at line 3:
|
||||||
|
1: int a = 2 ;
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 3
|
||||||
|
Line 6
|
||||||
|
Line 7
|
||||||
|
Line 8
|
||||||
|
Line 9
|
||||||
|
|
||||||
|
Total: 5 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {3, 6, 7, 8, 9} |TP| = 5
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|
||||||
|
### Change at Line 8 (if (x > 5))
|
||||||
|
AIS = {8, 9}
|
||||||
|
|
||||||
|
```bash
|
||||||
|
=== Impact Analysis for Line 8 ===
|
||||||
|
|
||||||
|
Statement(s) at line 8:
|
||||||
|
6: if ( x > 5 )
|
||||||
|
7: block
|
||||||
|
|
||||||
|
=== IMPACTED LINES ===
|
||||||
|
Line 8
|
||||||
|
Line 9
|
||||||
|
|
||||||
|
Total: 2 lines impacted
|
||||||
|
```
|
||||||
|
1. TP: {8, 9} |TP| = 2
|
||||||
|
2. FP: {} |FP| = 0
|
||||||
|
3. FN: {} |FN| = 0
|
||||||
|
4. TN: {} |TN| = 0
|
||||||
|
|||||||
BIN
lib/.DS_Store
vendored
BIN
lib/.DS_Store
vendored
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10
run.sh
10
run.sh
@@ -1,5 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$1" = "clean" ]; then
|
||||||
|
rm -rf bin
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ "$#" -lt 1 ]; then
|
if [ "$#" -lt 1 ]; then
|
||||||
echo "Usage: ./run.sh <file> [line]"
|
echo "Usage: ./run.sh <file> [line]"
|
||||||
echo "Example: ./run.sh examples/Example1.java 3"
|
echo "Example: ./run.sh examples/Example1.java 3"
|
||||||
@@ -19,9 +25,9 @@ if [ ! -d "bin/pdg" ]; then
|
|||||||
CP="lib/antlr-4.13.2-complete.jar"
|
CP="lib/antlr-4.13.2-complete.jar"
|
||||||
javac -d bin -cp "$CP" src/org/lsmr/cfg/*.java || exit 1
|
javac -d bin -cp "$CP" src/org/lsmr/cfg/*.java || exit 1
|
||||||
javac -d bin -cp "$CP:bin" src/pdg/PDG.java || exit 1
|
javac -d bin -cp "$CP:bin" src/pdg/PDG.java || exit 1
|
||||||
javac -d bin -cp "$CP:bin" src/CFGBuilder.java src/PDGTool.java || exit 1
|
javac -d bin -cp "$CP:bin" src/CFGBuilder.java src/CIA.java || exit 1
|
||||||
echo "Build complete!"
|
echo "Build complete!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run
|
# Run
|
||||||
java -cp "bin:lib/antlr-4.13.2-complete.jar" PDGTool "$@"
|
java -cp "bin:lib/antlr-4.13.2-complete.jar" CIA "$@"
|
||||||
|
|||||||
@@ -77,4 +77,5 @@ public class CFGBuilder {
|
|||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
50
src/CIA.java
50
src/CIA.java
@@ -4,11 +4,25 @@ import java.io.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PDG Tool: Change Impact Analysis
|
* Change Impact Analysis (CIA) Tool
|
||||||
* Usage: java PDGTool <java-file> [line-number]
|
*
|
||||||
|
* This tool performs program dependence graph (PDG) analysis on Java source files
|
||||||
|
* to identify which lines of code are impacted by changes to a specific line.
|
||||||
|
*
|
||||||
|
* The analysis works by:
|
||||||
|
* 1. Building a Control Flow Graph (CFG) from the source code
|
||||||
|
* 2. Constructing a Program Dependence Graph (PDG) with control and data dependencies
|
||||||
|
* 3. Computing forward slices to determine impact
|
||||||
|
*
|
||||||
|
* Usage: java CIA <java-file> [line-number]
|
||||||
*/
|
*/
|
||||||
public class CIA {
|
public class CIA {
|
||||||
|
/**
|
||||||
|
* Main entry point for the Change Impact Analysis tool.
|
||||||
|
* Validates arguments and initiates the PDG analysis.
|
||||||
|
*
|
||||||
|
* @param args Command line arguments: [0] = filename, [1] = optional line number
|
||||||
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
System.err.println("Usage: java PDGTool <java-file> [line-number]");
|
System.err.println("Usage: java PDGTool <java-file> [line-number]");
|
||||||
@@ -27,6 +41,18 @@ public class CIA {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs PDG analysis on the specified Java file.
|
||||||
|
*
|
||||||
|
* This method orchestrates the complete analysis workflow:
|
||||||
|
* 1. Builds the Control Flow Graph (CFG)
|
||||||
|
* 2. Constructs the Program Dependence Graph (PDG)
|
||||||
|
* 3. Either displays all dependencies or computes impact for a specific line
|
||||||
|
*
|
||||||
|
* @param filename Path to the Java source file to analyze
|
||||||
|
* @param targetLine Optional line number to analyze for change impact (null for all dependencies)
|
||||||
|
* @throws IOException If file cannot be read or parsed
|
||||||
|
*/
|
||||||
private static void analyzePDG(String filename, Integer targetLine) throws IOException {
|
private static void analyzePDG(String filename, Integer targetLine) throws IOException {
|
||||||
System.out.println("PDG Analysis Tool");
|
System.out.println("PDG Analysis Tool");
|
||||||
System.out.println("File: " + filename);
|
System.out.println("File: " + filename);
|
||||||
@@ -43,6 +69,7 @@ public class CIA {
|
|||||||
|
|
||||||
// Step 3: Show results
|
// Step 3: Show results
|
||||||
System.out.println("\n=== Available Lines ===");
|
System.out.println("\n=== Available Lines ===");
|
||||||
|
|
||||||
List<Integer> lines = cfg.getAllLineNumbers();
|
List<Integer> lines = cfg.getAllLineNumbers();
|
||||||
System.out.println("Lines with statements: " + lines);
|
System.out.println("Lines with statements: " + lines);
|
||||||
|
|
||||||
@@ -58,6 +85,19 @@ public class CIA {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes and displays the change impact for a specific line of code.
|
||||||
|
*
|
||||||
|
* Change impact is determined by computing a forward slice from the target line,
|
||||||
|
* which identifies all statements that could be affected by modifying the target.
|
||||||
|
* This includes both direct dependencies (data flow) and indirect dependencies
|
||||||
|
* (control flow).
|
||||||
|
*
|
||||||
|
* @param cfg The Control Flow Graph of the program
|
||||||
|
* @param pdg The Program Dependence Graph containing dependency information
|
||||||
|
* @param cfgBuilder The CFG builder for line number mapping
|
||||||
|
* @param targetLine The line number to analyze for change impact
|
||||||
|
*/
|
||||||
private static void computeImpact(ControlFlowGraph cfg, PDG pdg,
|
private static void computeImpact(ControlFlowGraph cfg, PDG pdg,
|
||||||
CFGBuilder cfgBuilder, int targetLine) {
|
CFGBuilder cfgBuilder, int targetLine) {
|
||||||
System.out.println("\n=== Impact Analysis for Line " + targetLine + " ===");
|
System.out.println("\n=== Impact Analysis for Line " + targetLine + " ===");
|
||||||
@@ -75,7 +115,9 @@ public class CIA {
|
|||||||
System.out.println(" " + node.label());
|
System.out.println(" " + node.label());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute forward slice
|
// Compute forward slice: all nodes reachable via dependencies
|
||||||
|
// The forward slice represents all statements that could be affected
|
||||||
|
// by changes to the target line
|
||||||
Set<String> allImpacted = new HashSet<>();
|
Set<String> allImpacted = new HashSet<>();
|
||||||
for (Node node : nodesAtLine) {
|
for (Node node : nodesAtLine) {
|
||||||
Set<String> impacted = pdg.computeForwardSlice(node.label());
|
Set<String> impacted = pdg.computeForwardSlice(node.label());
|
||||||
|
|||||||
197
src/pdg/PDG.java
197
src/pdg/PDG.java
@@ -2,11 +2,16 @@ package pdg;
|
|||||||
|
|
||||||
import org.lsmr.cfg.*;
|
import org.lsmr.cfg.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple Program Dependence Graph (PDG)
|
* Implementation notes:
|
||||||
* Computes control and data dependencies for a CFG
|
* - Control dependencies computed via iterative reachability analysis
|
||||||
*/
|
* - Data dependencies computed via reaching definitions analysis
|
||||||
|
* - Support Java 1.4 syntax with simple pattern matching
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class PDG {
|
public class PDG {
|
||||||
|
|
||||||
private ControlFlowGraph cfg;
|
private ControlFlowGraph cfg;
|
||||||
@@ -30,22 +35,35 @@ public class PDG {
|
|||||||
private void computeControlDependencies() {
|
private void computeControlDependencies() {
|
||||||
System.out.println("\tComputing control dependencies...");
|
System.out.println("\tComputing control dependencies...");
|
||||||
|
|
||||||
|
boolean changed = true;
|
||||||
|
|
||||||
|
while (changed) {
|
||||||
|
changed = false;
|
||||||
|
|
||||||
for (Node node : cfg.nodes()) {
|
for (Node node : cfg.nodes()) {
|
||||||
Set<String> deps = new HashSet<>();
|
Set<String> deps = new HashSet<>();
|
||||||
|
|
||||||
for (Edge inEdge : node.inEdges()) {
|
for (Edge inEdge : node.inEdges()) {
|
||||||
Node pred = inEdge.source();
|
Node pred = inEdge.source();
|
||||||
|
|
||||||
if (pred.outEdges().size() > 1) {
|
// get all deps from
|
||||||
deps.add(pred.label());
|
|
||||||
|
|
||||||
if (controlDeps.containsKey(pred.label())) {
|
if (controlDeps.containsKey(pred.label())) {
|
||||||
deps.addAll(controlDeps.get(pred.label()));
|
deps.addAll(controlDeps.get(pred.label()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// update deps if pred is a branching node liek if and while
|
||||||
|
if (pred.outEdges().size() > 1) {
|
||||||
|
deps.add(pred.label());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// compare prev iteration to current if we found changes in depns update control
|
||||||
|
// deps. else exit loop
|
||||||
|
Set<String> oldDeps = controlDeps.get(node.label());
|
||||||
|
if (oldDeps == null || !oldDeps.equals(deps)) {
|
||||||
controlDeps.put(node.label(), deps);
|
controlDeps.put(node.label(), deps);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("\t\tFound " + countDependencies(controlDeps) + " control dependencies");
|
System.out.println("\t\tFound " + countDependencies(controlDeps) + " control dependencies");
|
||||||
@@ -66,10 +84,11 @@ public class PDG {
|
|||||||
defs.put(label, extractDefs(label));
|
defs.put(label, extractDefs(label));
|
||||||
uses.put(label, extractUses(label));
|
uses.put(label, extractUses(label));
|
||||||
}
|
}
|
||||||
|
System.out.println(defs.toString());
|
||||||
|
System.out.println(uses.toString());
|
||||||
|
|
||||||
// 2. Compute reaching definitions
|
// 2. Compute reaching definitions
|
||||||
Map<String, Map<String, Set<String>>> reaching = computeReachingDefinitions(defs);
|
Map<String, Map<String, Set<String>>> reaching = computeReachingDefinitions(defs);
|
||||||
// TODO: check what happens whena node has multiple variable definitions
|
|
||||||
|
|
||||||
// 3. Build data dependencies
|
// 3. Build data dependencies
|
||||||
for (Node node : cfg.nodes()) {
|
for (Node node : cfg.nodes()) {
|
||||||
@@ -94,46 +113,70 @@ public class PDG {
|
|||||||
*/
|
*/
|
||||||
private Set<String> extractDefs(String statement) {
|
private Set<String> extractDefs(String statement) {
|
||||||
Set<String> vars = new HashSet<>();
|
Set<String> vars = new HashSet<>();
|
||||||
|
// exclude comments
|
||||||
// Skip special nodes
|
if (statement.startsWith("*") || statement.startsWith("/"))
|
||||||
if (statement.startsWith("*"))
|
|
||||||
return vars;
|
return vars;
|
||||||
|
|
||||||
if (statement.contains("=") && !statement.contains("==")) {
|
// used for normal assignments exclude anything else
|
||||||
String[] parts = statement.split("=");
|
boolean isDef = statement.contains("=") &&
|
||||||
if (parts.length > 0) {
|
!statement.contains("==") &&
|
||||||
String lhs = parts[0].trim();
|
!statement.contains("<=") &&
|
||||||
|
!statement.contains(">=") &&
|
||||||
|
!statement.contains("!=");
|
||||||
|
|
||||||
|
if (isDef) {
|
||||||
|
String lhs = statement.substring(0, statement.indexOf('=')).trim();
|
||||||
|
|
||||||
|
// remove left over operators after getting teh substring
|
||||||
|
if (lhs.endsWith("+") || lhs.endsWith("-") || lhs.endsWith("*") || lhs.endsWith("/") || lhs.endsWith("%")
|
||||||
|
|| lhs.endsWith("&") || lhs.endsWith("|") || lhs.endsWith("^")) {
|
||||||
|
lhs = lhs.substring(0, lhs.length() - 1).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// for possible arrays
|
||||||
|
if (lhs.contains("[")) {
|
||||||
|
lhs = lhs.substring(0, lhs.indexOf('[')).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// get last "word" splits by whitespace
|
||||||
String[] tokens = lhs.split("\\s+");
|
String[] tokens = lhs.split("\\s+");
|
||||||
if (tokens.length > 0) {
|
if (tokens.length > 0) {
|
||||||
String varName = tokens[tokens.length - 1];
|
String var = tokens[tokens.length - 1];
|
||||||
varName = varName.replaceAll("[\\[\\].();,]", "");
|
if (!var.isEmpty() && Character.isJavaIdentifierStart(var.charAt(0))) {
|
||||||
if (!varName.isEmpty() && Character.isJavaIdentifierStart(varName.charAt(0))) {
|
vars.add(var);
|
||||||
vars.add(varName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle For Loops
|
||||||
if (statement.contains("for") && statement.contains("(")) {
|
if (statement.contains("for") && statement.contains("(")) {
|
||||||
String forPart = statement.substring(statement.indexOf("("));
|
String inside = statement.substring(statement.indexOf("(") + 1);
|
||||||
String[] forParts = forPart.split(";");
|
if (inside.contains(";")) {
|
||||||
if (forParts.length >= 3) {
|
String[] parts = inside.split(";");
|
||||||
if (forParts[0].contains("=")) {
|
|
||||||
String[] initParts = forParts[0].split("=");
|
// Init def: "int i = 0"
|
||||||
if (initParts.length > 0) {
|
if (parts.length > 0 && parts[0].contains("=")) {
|
||||||
String var = initParts[0].trim().replaceAll("[^a-zA-Z0-9_]", "");
|
String part = parts[0].substring(0, parts[0].indexOf('=')).trim();
|
||||||
if (!var.isEmpty())
|
String[] tokens = part.split("\\s+");
|
||||||
|
if (tokens.length > 0) {
|
||||||
|
// retrieve last element
|
||||||
|
String var = tokens[tokens.length - 1];
|
||||||
vars.add(var);
|
vars.add(var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String update = forParts[forParts.length - 1];
|
|
||||||
|
// Update def for: "i++", "i--", "++i"
|
||||||
|
if (parts.length >= 3) {
|
||||||
|
String update = parts[parts.length - 1];
|
||||||
|
update = update.replaceAll("\\)", ""); // remove closing paren if present
|
||||||
if (update.contains("++") || update.contains("--")) {
|
if (update.contains("++") || update.contains("--")) {
|
||||||
String var = update.replaceAll("[^a-zA-Z0-9_]", "");
|
String var = update;
|
||||||
if (!var.isEmpty())
|
if (!var.isEmpty())
|
||||||
vars.add(var);
|
vars.add(var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return vars;
|
return vars;
|
||||||
}
|
}
|
||||||
@@ -144,20 +187,52 @@ public class PDG {
|
|||||||
private Set<String> extractUses(String statement) {
|
private Set<String> extractUses(String statement) {
|
||||||
Set<String> vars = new HashSet<>();
|
Set<String> vars = new HashSet<>();
|
||||||
|
|
||||||
if (statement.startsWith("*"))
|
// check for normal definition
|
||||||
return vars;
|
boolean isDef = statement.contains("=") &&
|
||||||
String[] tokens = statement.split("[\\s+\\-*/=<>!&|(){}\\[\\];,.]");
|
!statement.contains("==") &&
|
||||||
for (String token : tokens) {
|
!statement.contains("<=") &&
|
||||||
token = token.trim();
|
!statement.contains(">=") &&
|
||||||
if (!token.isEmpty() &&
|
!statement.contains("!=");
|
||||||
Character.isJavaIdentifierStart(token.charAt(0)) &&
|
|
||||||
!isKeyword(token) &&
|
String searchArea = statement;
|
||||||
!token.matches("\\d+")) {
|
|
||||||
|
// Two cases: 1. normal def only RHS matters 2. compound def both LHS and RHS
|
||||||
|
// matter
|
||||||
|
if (isDef) {
|
||||||
|
int eqIndex = statement.indexOf('=');
|
||||||
|
// check for += -= etc. if it exists we found a compound def
|
||||||
|
boolean isCompound = eqIndex > 0 && "+-*/%&|^".indexOf(statement.charAt(eqIndex - 1)) != -1;
|
||||||
|
|
||||||
|
if (isCompound) {
|
||||||
|
// both RHS & LHS
|
||||||
|
searchArea = statement;
|
||||||
|
} else {
|
||||||
|
// only RHS
|
||||||
|
searchArea = statement.substring(eqIndex + 1); // skip anything before =
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tokenize and filter
|
||||||
|
// fancy split on non-identifier characters to extract all variables used
|
||||||
|
String[] tokens = searchArea.split("[^a-zA-Z0-9_]+");
|
||||||
|
|
||||||
|
for (int i = 0; i < tokens.length; i++) {
|
||||||
|
String token = tokens[i];
|
||||||
|
if (token.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Basic validity checks
|
||||||
|
if (Character.isJavaIdentifierStart(token.charAt(0))
|
||||||
|
&& !isKeyword(token)
|
||||||
|
&& !token.matches("\\d+")) {
|
||||||
|
// skip if its a method
|
||||||
|
boolean isMethodCall = statement.matches(".*\\b" + token + "\\s*\\(.*");
|
||||||
|
|
||||||
|
if (!isMethodCall) {
|
||||||
vars.add(token);
|
vars.add(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vars.removeAll(extractDefs(statement));
|
}
|
||||||
|
|
||||||
return vars;
|
return vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +244,8 @@ public class PDG {
|
|||||||
"if", "else", "while", "for", "do", "return", "break", "continue",
|
"if", "else", "while", "for", "do", "return", "break", "continue",
|
||||||
"int", "double", "float", "char", "boolean", "void", "String",
|
"int", "double", "float", "char", "boolean", "void", "String",
|
||||||
"new", "null", "true", "false", "class", "public", "private",
|
"new", "null", "true", "false", "class", "public", "private",
|
||||||
"static", "final", "this", "super", "try", "catch", "throw", "throws"));
|
"static", "final", "this", "super", "try", "catch", "throw", "throws", "EXIT", "block", "ENTRY",
|
||||||
|
"THROWN"));
|
||||||
return keywords.contains(word);
|
return keywords.contains(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,10 +260,8 @@ public class PDG {
|
|||||||
reaching.put(node.label(), new HashMap<>());
|
reaching.put(node.label(), new HashMap<>());
|
||||||
}
|
}
|
||||||
boolean changed = true;
|
boolean changed = true;
|
||||||
int iterations = 0;
|
while (changed) {
|
||||||
while (changed && iterations < 100) {
|
|
||||||
changed = false;
|
changed = false;
|
||||||
iterations++;
|
|
||||||
|
|
||||||
for (Node node : cfg.nodes()) {
|
for (Node node : cfg.nodes()) {
|
||||||
String label = node.label();
|
String label = node.label();
|
||||||
@@ -196,24 +270,37 @@ public class PDG {
|
|||||||
for (Edge inEdge : node.inEdges()) {
|
for (Edge inEdge : node.inEdges()) {
|
||||||
Node pred = inEdge.source();
|
Node pred = inEdge.source();
|
||||||
String predLabel = pred.label();
|
String predLabel = pred.label();
|
||||||
|
|
||||||
|
Map<String, Set<String>> predOut = new HashMap<>();
|
||||||
|
|
||||||
|
// In predecesor def
|
||||||
if (reaching.containsKey(predLabel)) {
|
if (reaching.containsKey(predLabel)) {
|
||||||
for (Map.Entry<String, Set<String>> entry : reaching.get(predLabel).entrySet()) {
|
for (Map.Entry<String, Set<String>> entry : reaching.get(predLabel).entrySet()) {
|
||||||
|
// create a copy of the set
|
||||||
|
predOut.put(entry.getKey(), new HashSet<>(entry.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// kill & gen
|
||||||
|
if (defs.containsKey(predLabel)) {
|
||||||
|
for (String var : defs.get(predLabel)) {
|
||||||
|
// since new def, we update definition of x to new definition
|
||||||
|
Set<String> newDef = new HashSet<>();
|
||||||
|
newDef.add(predLabel);
|
||||||
|
predOut.put(var, newDef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// merge
|
||||||
|
for (Map.Entry<String, Set<String>> entry : predOut.entrySet()) {
|
||||||
String var = entry.getKey();
|
String var = entry.getKey();
|
||||||
newReaching.putIfAbsent(var, new HashSet<>());
|
newReaching.putIfAbsent(var, new HashSet<>());
|
||||||
newReaching.get(var).addAll(entry.getValue());
|
newReaching.get(var).addAll(entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add predecessor's definitions
|
|
||||||
for (String var : defs.get(predLabel)) {
|
|
||||||
newReaching.putIfAbsent(var, new HashSet<>());
|
|
||||||
newReaching.get(var).clear();
|
|
||||||
newReaching.get(var).add(predLabel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reaching.put(label, newReaching);
|
reaching.put(label, newReaching);
|
||||||
|
// nothing changed then exit
|
||||||
if (!mapsEqual(oldReaching, newReaching)) {
|
if (!mapsEqual(oldReaching, newReaching)) {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,28 @@
|
|||||||
public class Example1 {
|
public class Example1 {
|
||||||
public void test() {
|
// public void test() {
|
||||||
int x = 5;
|
// int x = 5;
|
||||||
int y = x + 10;
|
// int y = x + 10;
|
||||||
int z = y * 2;
|
// int z = y * 2;
|
||||||
int result = z + x;
|
// int result = z + x;
|
||||||
}
|
// }
|
||||||
public void test1(int a) {
|
// public void test1(int a) {
|
||||||
int x = 5;
|
// int x = 5;
|
||||||
int y = 0;
|
// int y = 0;
|
||||||
|
|
||||||
if (a > 10) {
|
// if (a > 10) {
|
||||||
y = x + a;
|
// y = x + a;
|
||||||
} else {
|
// } else {
|
||||||
y = x - a;
|
// y = x - a;
|
||||||
}
|
// }
|
||||||
|
|
||||||
int result = y * 2;
|
// int result = y * 2;
|
||||||
}
|
// }
|
||||||
public void test2() {
|
public void test2() {
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (i < 10) {
|
while (i < 10) {
|
||||||
|
i = 2;
|
||||||
sum = sum + i;
|
sum = sum + i;
|
||||||
i = i + 1;
|
i = i + 1;
|
||||||
}
|
}
|
||||||
|
|||||||
8
tests/test1.java
Normal file
8
tests/test1.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
public class test1 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int x = 5; // Line 3
|
||||||
|
int y = x + 2; // Line 4
|
||||||
|
int z = y * 3; // Line 5
|
||||||
|
System.out.println(z); // Line 6
|
||||||
|
}
|
||||||
|
}
|
||||||
12
tests/test10.java
Normal file
12
tests/test10.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
public class test10{
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int a = 2; // Line 3
|
||||||
|
int b = 3; // Line 4
|
||||||
|
int c = 4; // Line 5
|
||||||
|
int result = (a + b) * c; // Line 6
|
||||||
|
int x = result / 2; // Line 7
|
||||||
|
if (x > 5) { // Line 8
|
||||||
|
System.out.println(x); // Line 9
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
tests/test2.java
Normal file
11
tests/test2.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
public class test2{
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int x = 10; // Line 3
|
||||||
|
int y = 0; // Line 4
|
||||||
|
if (x > 5) { // Line 5
|
||||||
|
y = x * 2; // Line 6
|
||||||
|
}
|
||||||
|
int z = y + 1; // Line 8
|
||||||
|
System.out.println(z); // Line 9
|
||||||
|
}
|
||||||
|
}
|
||||||
10
tests/test3.java
Normal file
10
tests/test3.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
public class test3 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int sum = 0; // Line 3
|
||||||
|
int i; // Line 4
|
||||||
|
for (i = 0; i < 5; i++) { // Line 5
|
||||||
|
sum = sum + i; // Line 6
|
||||||
|
}
|
||||||
|
System.out.println(sum); // Line 8
|
||||||
|
}
|
||||||
|
}
|
||||||
13
tests/test4.java
Normal file
13
tests/test4.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
public class test4{
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int x = 10; // Line 3
|
||||||
|
int y = 0; // Line 4
|
||||||
|
if (x > 5) { // Line 5
|
||||||
|
y = x + 10; // Line 6
|
||||||
|
} else {
|
||||||
|
y = x - 10; // Line 8
|
||||||
|
}
|
||||||
|
int z = y * 2; // Line 10
|
||||||
|
System.out.println(z); // Line 11
|
||||||
|
}
|
||||||
|
}
|
||||||
9
tests/test5.java
Normal file
9
tests/test5.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
public class test5 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int a = 5; // Line 3
|
||||||
|
int b = a + 2; // Line 4
|
||||||
|
int c = a * 3; // Line 5
|
||||||
|
int d = b + c; // Line 6
|
||||||
|
System.out.println(d); // Line 7
|
||||||
|
}
|
||||||
|
}
|
||||||
13
tests/test6.java
Normal file
13
tests/test6.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
public class test6{
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int x = 10; // Line 3
|
||||||
|
int y = 0; // Line 4
|
||||||
|
if (x > 5) { // Line 5
|
||||||
|
if (x > 8) { // Line 6
|
||||||
|
y = x * 2; // Line 7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int z = y + 1; // Line 10
|
||||||
|
System.out.println(z); // Line 11
|
||||||
|
}
|
||||||
|
}
|
||||||
11
tests/test7.java
Normal file
11
tests/test7.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
public class test7 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int count = 0; // Line 3
|
||||||
|
int sum = 0; // Line 4
|
||||||
|
while (count < 5) { // Line 5
|
||||||
|
sum = sum + count; // Line 6
|
||||||
|
count = count + 1; // Line 7
|
||||||
|
}
|
||||||
|
System.out.println(sum); // Line 9
|
||||||
|
}
|
||||||
|
}
|
||||||
10
tests/test8.java
Normal file
10
tests/test8.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
public class test8 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int x = 5; // Line 3
|
||||||
|
int y = x + 1; // Line 4
|
||||||
|
x = 10; // Line 5
|
||||||
|
int z = x * 2; // Line 6
|
||||||
|
System.out.println(y); // Line 7
|
||||||
|
System.out.println(z); // Line 8
|
||||||
|
}
|
||||||
|
}
|
||||||
10
tests/test9.java
Normal file
10
tests/test9.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
public class test9{
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int x = 5; // Line 3
|
||||||
|
int y = 10; // Line 4
|
||||||
|
int z = x + 1; // Line 5
|
||||||
|
int w = y + 2; // Line 6
|
||||||
|
System.out.println(z); // Line 7
|
||||||
|
System.out.println(w); // Line 8
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user