diff --git a/.DS_Store b/.DS_Store index 67e8aa5..d0eb385 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/lib/.DS_Store b/lib/.DS_Store deleted file mode 100644 index 9b5c16a..0000000 Binary files a/lib/.DS_Store and /dev/null differ diff --git a/lib/antlr-4.9.3-complete.jar b/lib/antlr-4.9.3-complete.jar deleted file mode 100644 index 749296f..0000000 Binary files a/lib/antlr-4.9.3-complete.jar and /dev/null differ diff --git a/lib/apfloat-1.10.1-javadoc.jar b/lib/apfloat-1.10.1-javadoc.jar deleted file mode 100644 index 6e86282..0000000 Binary files a/lib/apfloat-1.10.1-javadoc.jar and /dev/null differ diff --git a/lib/apfloat-1.10.1.jar b/lib/apfloat-1.10.1.jar deleted file mode 100644 index 9958619..0000000 Binary files a/lib/apfloat-1.10.1.jar and /dev/null differ diff --git a/lib/jgrapht-core-1.5.1.jar b/lib/jgrapht-core-1.5.1.jar deleted file mode 100644 index 2667b8f..0000000 Binary files a/lib/jgrapht-core-1.5.1.jar and /dev/null differ diff --git a/lib/jgrapht-core-1.5.2-javadoc.jar b/lib/jgrapht-core-1.5.2-javadoc.jar deleted file mode 100644 index 3f9dc5b..0000000 Binary files a/lib/jgrapht-core-1.5.2-javadoc.jar and /dev/null differ diff --git a/lib/jgrapht-core-1.5.2.jar b/lib/jgrapht-core-1.5.2.jar deleted file mode 100644 index 8283b35..0000000 Binary files a/lib/jgrapht-core-1.5.2.jar and /dev/null differ diff --git a/lib/jgrapht-io-1.5.1.jar b/lib/jgrapht-io-1.5.1.jar deleted file mode 100644 index 27c87ed..0000000 Binary files a/lib/jgrapht-io-1.5.1.jar and /dev/null differ diff --git a/lib/jgrapht-io-1.5.2.jar b/lib/jgrapht-io-1.5.2.jar deleted file mode 100644 index c444182..0000000 Binary files a/lib/jgrapht-io-1.5.2.jar and /dev/null differ diff --git a/lib/jheaps-0.14-javadoc.jar b/lib/jheaps-0.14-javadoc.jar deleted file mode 100644 index 863c71d..0000000 Binary files a/lib/jheaps-0.14-javadoc.jar and /dev/null differ diff --git a/lib/jheaps-0.14.jar b/lib/jheaps-0.14.jar deleted file mode 100644 index a0f0c23..0000000 Binary files a/lib/jheaps-0.14.jar and /dev/null differ diff --git a/src/CIA.java b/src/CIA.java index 597aeef..7f9624c 100644 --- a/src/CIA.java +++ b/src/CIA.java @@ -4,11 +4,25 @@ import java.io.*; import java.util.*; /** - * PDG Tool: Change Impact Analysis - * Usage: java PDGTool [line-number] + * Change Impact Analysis (CIA) Tool + * + * 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 [line-number] */ 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) { if (args.length < 1) { System.err.println("Usage: java PDGTool [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 { System.out.println("PDG Analysis Tool"); System.out.println("File: " + filename); @@ -59,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, CFGBuilder cfgBuilder, int targetLine) { System.out.println("\n=== Impact Analysis for Line " + targetLine + " ==="); @@ -76,7 +115,9 @@ public class CIA { 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 allImpacted = new HashSet<>(); for (Node node : nodesAtLine) { Set impacted = pdg.computeForwardSlice(node.label()); diff --git a/src/pdg/PDG.java b/src/pdg/PDG.java index 6c140ed..1390471 100644 --- a/src/pdg/PDG.java +++ b/src/pdg/PDG.java @@ -6,9 +6,12 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * Simple Program Dependence Graph (PDG) - * Computes control and data dependencies for a CFG - */ +* Implementation notes: +* - 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 { private ControlFlowGraph cfg;