Verified Commit 6809040f authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Improve parameter and global variables handling, and summary

* Migrated `NodeType`s to specific `GraphNode` child classes.
* Revamped creation of SDG
* Added ASDG and PSDG, based on the APDG and PPDG.
* Improved handling of variable usages, definitions and declarations.
* Added movable variable actions, that can be placed in a CFG node and
  then relocated to their own PDG node.
* Added fix-point and specific slicing algorithm to summary arc
  generation.
* Documentation of most methods (public and private).
* Removed unused elements.
* Fix possible errors by migrating all maps whose key is an AST node
  to IdentityHashMap.
parent 4a9a5b6e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@

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

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
@@ -27,7 +27,7 @@
        <dependency>
            <groupId>tfm</groupId>
            <artifactId>sdg-core</artifactId>
            <version>1.1.2</version>
            <version>1.2.0</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
+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);
+20 −6
Original line number Diff line number Diff line
@@ -8,10 +8,11 @@ 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.NodeIdSlicingCriterion;
import tfm.slicing.Slice;
import tfm.slicing.SlicingCriterion;
@@ -26,23 +27,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,7 +100,15 @@ 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, "");
@@ -127,7 +141,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