Skip to content

Commit 76a78a6

Browse files
committed
Merge branch 'carlos' into develop
# Conflicts: # sdg-core/src/main/java/tfm/graphs/CallGraph.java # sdg-core/src/main/java/tfm/graphs/cfg/CFGBuilder.java # sdg-core/src/main/java/tfm/graphs/sdg/MethodCallReplacerVisitor.java # sdg-core/src/main/java/tfm/graphs/sdg/SDG.java # sdg-core/src/main/java/tfm/graphs/sdg/sumarcs/NaiveSummaryArcsBuilder.java # sdg-core/src/main/java/tfm/nodes/type/NodeType.java
2 parents 41ac79c + 178fa7b commit 76a78a6

File tree

96 files changed

+2842
-2077
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+2842
-2077
lines changed

sdg-cli/pom.xml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,43 @@
66

77
<groupId>tfm</groupId>
88
<artifactId>sdg-cli</artifactId>
9-
<version>1.0.1</version>
9+
<version>1.0.4</version>
1010

1111
<properties>
1212
<maven.compiler.source>11</maven.compiler.source>
1313
<maven.compiler.target>11</maven.compiler.target>
1414
</properties>
1515

16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.apache.maven.plugins</groupId>
20+
<artifactId>maven-assembly-plugin</artifactId>
21+
<version>3.3.0</version>
22+
<configuration>
23+
<archive>
24+
<manifest>
25+
<addClasspath>true</addClasspath>
26+
<mainClass>tfm.cli.Slicer</mainClass>
27+
</manifest>
28+
</archive>
29+
<descriptorRefs>
30+
<descriptorRef>jar-with-dependencies</descriptorRef>
31+
</descriptorRefs>
32+
</configuration>
33+
<executions>
34+
<execution>
35+
<id>assemble-all</id>
36+
<phase>package</phase>
37+
<goals>
38+
<goal>single</goal>
39+
</goals>
40+
</execution>
41+
</executions>
42+
</plugin>
43+
</plugins>
44+
</build>
45+
1646
<dependencies>
1747
<dependency>
1848
<groupId>commons-cli</groupId>
@@ -27,8 +57,7 @@
2757
<dependency>
2858
<groupId>tfm</groupId>
2959
<artifactId>sdg-core</artifactId>
30-
<version>1.1.2</version>
31-
<scope>compile</scope>
60+
<version>1.2.4</version>
3261
</dependency>
3362
</dependencies>
3463
</project>

sdg-cli/src/main/java/tfm/cli/GraphLog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import tfm.arcs.Arc;
55
import tfm.graphs.Graph;
66
import tfm.nodes.GraphNode;
7-
import tfm.utils.FileUtil;
87
import tfm.utils.Logger;
8+
import tfm.utils.Utils;
99

1010
import java.io.*;
1111

@@ -99,7 +99,7 @@ public void generateImages(String imageName, String format) throws IOException {
9999

100100
public void openVisualRepresentation() throws IOException {
101101
if (!generated) generateImages();
102-
FileUtil.open(getImageFile());
102+
Utils.openFileForUser(getImageFile());
103103
}
104104

105105
public File getImageFile() {

sdg-cli/src/main/java/tfm/cli/PDGLog.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package tfm.cli;
22

33
import tfm.graphs.pdg.PDG;
4-
import tfm.nodes.GraphNode;
5-
import tfm.utils.Logger;
64

75
import java.io.IOException;
8-
import java.util.Comparator;
9-
import java.util.stream.Collectors;
106

117
public class PDGLog extends GraphLog<PDG> {
12-
private CFGLog cfgLog;
8+
private final CFGLog cfgLog;
139

1410
public PDGLog() {
1511
this(null);
@@ -23,22 +19,6 @@ public PDGLog(PDG pdg) {
2319
else cfgLog = null;
2420
}
2521

26-
@Override
27-
public void log() throws IOException {
28-
super.log();
29-
30-
Logger.log("Nodes with variable info");
31-
Logger.log(graph.vertexSet().stream()
32-
.sorted(Comparator.comparingLong(GraphNode::getId))
33-
.map(node ->
34-
String.format("GraphNode { id: %s, instruction: %s, variables: %s}",
35-
node.getId(),
36-
node.getInstruction(),
37-
node.getVariableActions())
38-
).collect(Collectors.joining(System.lineSeparator()))
39-
);
40-
}
41-
4222
@Override
4323
public void generateImages(String imageName, String format) throws IOException {
4424
super.generateImages(imageName, format);

sdg-cli/src/main/java/tfm/cli/PHPSlice.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
99
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
1010
import org.apache.commons.cli.*;
11+
import tfm.graphs.augmented.ASDG;
12+
import tfm.graphs.augmented.PSDG;
1113
import tfm.graphs.cfg.CFG;
1214
import tfm.graphs.exceptionsensitive.ESSDG;
1315
import tfm.graphs.sdg.SDG;
14-
import tfm.nodes.GraphNode;
16+
import tfm.slicing.FileLineSlicingCriterion;
1517
import tfm.slicing.NodeIdSlicingCriterion;
1618
import tfm.slicing.Slice;
1719
import 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

sdg-cli/src/main/java/tfm/cli/SlicedSDGLog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected DOTExporter<GraphNode<?>, Arc> getDOTExporter(SDG graph) {
3232
return new DOTExporter<>(
3333
n -> String.valueOf(n.getId()),
3434
n -> {
35-
String s = n.getId() + ": " + n.getInstruction();
35+
String s = n.getId() + ": " + n.getLabel();
3636
if (!n.getVariableActions().isEmpty())
3737
s += "\n" + n.getVariableActions().stream().map(Object::toString).reduce((a, b) -> a + "," + b).orElse("--");
3838
return s;

sdg-cli/src/main/java/tfm/cli/Slicer.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver;
1111
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
1212
import org.apache.commons.cli.*;
13+
import tfm.graphs.augmented.ASDG;
14+
import tfm.graphs.augmented.PSDG;
1315
import tfm.graphs.exceptionsensitive.ESSDG;
1416
import tfm.graphs.sdg.SDG;
1517
import tfm.slicing.FileLineSlicingCriterion;
@@ -83,7 +85,11 @@ public class Slicer {
8385
.desc("The directory where the sliced source code should be placed. By default, it is placed at " +
8486
DEFAULT_OUTPUT_DIR)
8587
.build());
86-
OPTIONS.addOption("es", "exception-sensitive", false, "Enable exception-sensitive analysis");
88+
OPTIONS.addOption(Option
89+
.builder("t").longOpt("type")
90+
.hasArg().argName("graph_type")
91+
.desc("The type of graph to be built. Available options are SDG, ASDG, PSDG, ESSDG.")
92+
.build());
8793
OPTIONS.addOption(Option
8894
.builder("h").longOpt("help")
8995
.desc("Shows this text")
@@ -222,7 +228,15 @@ public void slice() throws ParseException {
222228
throw new ParseException(e.getMessage());
223229
}
224230

225-
SDG sdg = cliOpts.hasOption("exception-sensitive") ? new ESSDG() : new SDG();
231+
SDG sdg;
232+
switch (cliOpts.getOptionValue("type")) {
233+
case "SDG": sdg = new SDG(); break;
234+
case "ASDG": sdg = new ASDG(); break;
235+
case "PSDG": sdg = new PSDG(); break;
236+
case "ESSDG": sdg = new ESSDG(); break;
237+
default:
238+
throw new IllegalArgumentException("Unknown type of graph. Available graphs are SDG, ASDG, PSDG, ESSDG");
239+
}
226240
sdg.build(units);
227241

228242
// Slice the SDG

sdg-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>tfm</groupId>
88
<artifactId>sdg-core</artifactId>
9-
<version>1.1.2</version>
9+
<version>1.2.4</version>
1010

1111
<properties>
1212
<maven.compiler.source>11</maven.compiler.source>

0 commit comments

Comments
 (0)