88import com .github .javaparser .symbolsolver .resolution .typesolvers .CombinedTypeSolver ;
99import com .github .javaparser .symbolsolver .resolution .typesolvers .ReflectionTypeSolver ;
1010import org .apache .commons .cli .*;
11+ import tfm .graphs .augmented .ASDG ;
12+ import tfm .graphs .augmented .PSDG ;
1113import tfm .graphs .cfg .CFG ;
1214import tfm .graphs .exceptionsensitive .ESSDG ;
1315import tfm .graphs .sdg .SDG ;
14- import tfm .nodes . GraphNode ;
16+ import tfm .slicing . FileLineSlicingCriterion ;
1517import tfm .slicing .NodeIdSlicingCriterion ;
1618import tfm .slicing .Slice ;
1719import tfm .slicing .SlicingCriterion ;
@@ -26,23 +28,28 @@ public class PHPSlice {
2628
2729 static {
2830 OPTIONS .addOption (Option
29- .builder ("f" )
31+ .builder ("f" ). longOpt ( "file" )
3032 .hasArg ().argName ("CriterionFile.java" ).type (File .class )
3133 .required ()
3234 .desc ("The file that contains the slicing criterion." )
3335 .build ());
3436 OPTIONS .addOption (Option
35- .builder ("i" )
37+ .builder ("i" ). longOpt ( "node-id" )
3638 .hasArg ().argName ("node_id" )
3739 .required ()
3840 .desc ("The slicing criterion, in the form of a node id (a positive integer)." )
3941 .build ());
4042 OPTIONS .addOption (Option
41- .builder ("o" )
43+ .builder ("o" ). longOpt ( "output-dir" )
4244 .hasArg ().argName ("output_file" )
4345 .required ()
4446 .desc ("The folder where the slice and the graphs should be placed" )
4547 .build ());
48+ OPTIONS .addOption (Option
49+ .builder ("t" ).longOpt ("type" )
50+ .hasArg ().argName ("graph_type" )
51+ .desc ("The type of graph to be built. Available options are SDG, ASDG, PSDG, ESSDG." )
52+ .build ());
4653 OPTIONS .addOption ("es" , "exception-sensitive" , false , "Enable exception-sensitive analysis" );
4754 OPTIONS .addOption (Option
4855 .builder ("h" ).longOpt ("help" )
@@ -94,14 +101,22 @@ public void slice() throws ParseException, IOException {
94101 throw new ParseException (e .getMessage ());
95102 }
96103
97- SDG sdg = cliOpts .hasOption ("exception-sensitive" ) ? new ESSDG () : new SDG ();
104+ SDG sdg ;
105+ switch (cliOpts .getOptionValue ("type" )) {
106+ case "SDG" : sdg = new SDG (); break ;
107+ case "ASDG" : sdg = new ASDG (); break ;
108+ case "PSDG" : sdg = new PSDG (); break ;
109+ case "ESSDG" : sdg = new ESSDG (); break ;
110+ default :
111+ throw new IllegalArgumentException ("Unknown type of graph. Available graphs are SDG, ASDG, PSDG, ESSDG" );
112+ }
98113 sdg .build (units );
99114
100115 SlicingCriterion sc = new NodeIdSlicingCriterion (0 , "" );
101116 Slice slice = new Slice ();
102117 if (scId != 0 ) {
103118 // Slice the SDG
104- sc = new NodeIdSlicingCriterion ( scId , "" );
119+ sc = new FileLineSlicingCriterion ( scFile , scId );
105120 slice = sdg .slice (sc );
106121
107122 // Convert the slice to code and output the result to `outputDir`
@@ -127,7 +142,7 @@ public void slice() throws ParseException, IOException {
127142 for (CFG cfg : sdg .getCFGs ()) {
128143 CFGLog log = new CFGLog (cfg );
129144 log .setDirectory (imageDir );
130- log .generateImages ("root" + cfg .getRootNode ().map ( GraphNode :: getId ). orElse (- 1L ), "svg" );
145+ log .generateImages ("root" + cfg .getRootNode ().getId ( ), "svg" );
131146 }
132147 }
133148
0 commit comments