Verified Commit 76a78a60 authored by Carlos Galindo's avatar Carlos Galindo
Browse files

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
parents 41ac79c2 178fa7ba
Loading
Loading
Loading
Loading
+32 −3
Original line number Diff line number Diff line
@@ -6,13 +6,43 @@

    <groupId>tfm</groupId>
    <artifactId>sdg-cli</artifactId>
    <version>1.0.1</version>
    <version>1.0.4</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>tfm.cli.Slicer</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>assemble-all</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>commons-cli</groupId>
@@ -27,8 +57,7 @@
        <dependency>
            <groupId>tfm</groupId>
            <artifactId>sdg-core</artifactId>
            <version>1.1.2</version>
            <scope>compile</scope>
            <version>1.2.4</version>
        </dependency>
    </dependencies>
</project>
+2 −2
Original line number Diff line number Diff line
@@ -4,8 +4,8 @@ import org.jgrapht.io.DOTExporter;
import tfm.arcs.Arc;
import tfm.graphs.Graph;
import tfm.nodes.GraphNode;
import tfm.utils.FileUtil;
import tfm.utils.Logger;
import tfm.utils.Utils;

import java.io.*;

@@ -99,7 +99,7 @@ public abstract class GraphLog<G extends Graph> {

    public void openVisualRepresentation() throws IOException {
        if (!generated) generateImages();
        FileUtil.open(getImageFile());
        Utils.openFileForUser(getImageFile());
    }

    public File getImageFile() {
+1 −21
Original line number Diff line number Diff line
package tfm.cli;

import tfm.graphs.pdg.PDG;
import tfm.nodes.GraphNode;
import tfm.utils.Logger;

import java.io.IOException;
import java.util.Comparator;
import java.util.stream.Collectors;

public class PDGLog extends GraphLog<PDG> {
    private CFGLog cfgLog;
    private final CFGLog cfgLog;

    public PDGLog() {
        this(null);
@@ -23,22 +19,6 @@ public class PDGLog extends GraphLog<PDG> {
        else cfgLog = null;
    }

    @Override
    public void log() throws IOException {
        super.log();

        Logger.log("Nodes with variable info");
        Logger.log(graph.vertexSet().stream()
                .sorted(Comparator.comparingLong(GraphNode::getId))
                .map(node ->
                        String.format("GraphNode { id: %s, instruction: %s, variables: %s}",
                                node.getId(),
                                node.getInstruction(),
                                node.getVariableActions())
                ).collect(Collectors.joining(System.lineSeparator()))
        );
    }

    @Override
    public void generateImages(String imageName, String format) throws IOException {
        super.generateImages(imageName, format);
+22 −7
Original line number Diff line number Diff line
@@ -8,10 +8,12 @@ import com.github.javaparser.symbolsolver.JavaSymbolSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
import org.apache.commons.cli.*;
import tfm.graphs.augmented.ASDG;
import tfm.graphs.augmented.PSDG;
import tfm.graphs.cfg.CFG;
import tfm.graphs.exceptionsensitive.ESSDG;
import tfm.graphs.sdg.SDG;
import tfm.nodes.GraphNode;
import tfm.slicing.FileLineSlicingCriterion;
import tfm.slicing.NodeIdSlicingCriterion;
import tfm.slicing.Slice;
import tfm.slicing.SlicingCriterion;
@@ -26,23 +28,28 @@ public class PHPSlice {

    static {
        OPTIONS.addOption(Option
                .builder("f")
                .builder("f").longOpt("file")
                .hasArg().argName("CriterionFile.java").type(File.class)
                .required()
                .desc("The file that contains the slicing criterion.")
                .build());
        OPTIONS.addOption(Option
                .builder("i")
                .builder("i").longOpt("node-id")
                .hasArg().argName("node_id")
                .required()
                .desc("The slicing criterion, in the form of a node id (a positive integer).")
                .build());
        OPTIONS.addOption(Option
                .builder("o")
                .builder("o").longOpt("output-dir")
                .hasArg().argName("output_file")
                .required()
                .desc("The folder where the slice and the graphs should be placed")
                .build());
        OPTIONS.addOption(Option
                .builder("t").longOpt("type")
                .hasArg().argName("graph_type")
                .desc("The type of graph to be built. Available options are SDG, ASDG, PSDG, ESSDG.")
                .build());
        OPTIONS.addOption("es", "exception-sensitive", false, "Enable exception-sensitive analysis");
        OPTIONS.addOption(Option
                .builder("h").longOpt("help")
@@ -94,14 +101,22 @@ public class PHPSlice {
            throw new ParseException(e.getMessage());
        }

        SDG sdg = cliOpts.hasOption("exception-sensitive") ? new ESSDG() : new SDG();
        SDG sdg;
        switch (cliOpts.getOptionValue("type")) {
            case "SDG":   sdg = new SDG();   break;
            case "ASDG":  sdg = new ASDG();  break;
            case "PSDG":  sdg = new PSDG();  break;
            case "ESSDG": sdg = new ESSDG(); break;
            default:
                throw new IllegalArgumentException("Unknown type of graph. Available graphs are SDG, ASDG, PSDG, ESSDG");
        }
        sdg.build(units);

        SlicingCriterion sc = new NodeIdSlicingCriterion(0, "");
        Slice slice = new Slice();
        if (scId != 0) {
            // Slice the SDG
            sc = new NodeIdSlicingCriterion(scId, "");
            sc = new FileLineSlicingCriterion(scFile, scId);
            slice = sdg.slice(sc);

            // Convert the slice to code and output the result to `outputDir`
@@ -127,7 +142,7 @@ public class PHPSlice {
        for (CFG cfg : sdg.getCFGs()) {
            CFGLog log = new CFGLog(cfg);
            log.setDirectory(imageDir);
            log.generateImages("root" + cfg.getRootNode().map(GraphNode::getId).orElse(-1L), "svg");
            log.generateImages("root" + cfg.getRootNode().getId(), "svg");
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ public class SlicedSDGLog extends SDGLog {
        return new DOTExporter<>(
                n -> String.valueOf(n.getId()),
                n -> {
                    String s = n.getId() + ": " + n.getInstruction();
                    String s = n.getId() + ": " + n.getLabel();
                    if (!n.getVariableActions().isEmpty())
                        s += "\n" + n.getVariableActions().stream().map(Object::toString).reduce((a, b) -> a + "," + b).orElse("--");
                    return s;
Loading