Commit 71ef93c8 authored by jacosro's avatar jacosro
Browse files

Apply requested changes

parent b5179999
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -21,6 +21,10 @@ public class DataDependencyArc extends Arc {
        super(variable);
    }

    public DataDependencyArc() {
        super();
    }

    @Override
    public Map<String, Attribute> getDotAttributes() {
        Map<String, Attribute> map = super.getDotAttributes();
+0 −16
Original line number Diff line number Diff line
package tfm.arcs.sdg;

import org.jgrapht.io.Attribute;
import org.jgrapht.io.DefaultAttribute;
import tfm.arcs.Arc;

import java.util.Map;

public class ReturnArc extends Arc {
    @Override
    public Map<String, Attribute> getDotAttributes() {
        Map<String, Attribute> map = super.getDotAttributes();
        map.put("style", DefaultAttribute.createAttribute("dashed"));
        return map;
    }
}
+10 −3
Original line number Diff line number Diff line
@@ -255,6 +255,13 @@ class MethodCallReplacerVisitor extends VoidVisitorAdapter<Context> {
        // Add 'output' node of the call

        // First, check if method has an output node

        if (methodDeclaration.getType().isVoidType()) {
            return;
        }

        // If not void, find the output node

        Optional<GraphNode<EmptyStmt>> optionalDeclarationOutputNode = sdg.outgoingEdgesOf(methodDeclarationNode).stream()
                .filter(arc -> sdg.getEdgeTarget(arc).getNodeType() == NodeType.METHOD_OUTPUT)
                .map(arc -> (GraphNode<EmptyStmt>) sdg.getEdgeTarget(arc))
@@ -268,11 +275,11 @@ class MethodCallReplacerVisitor extends VoidVisitorAdapter<Context> {
        GraphNode<EmptyStmt> declarationOutputNode = optionalDeclarationOutputNode.get();

        // If method has output node, then create output call node and link them
        GraphNode<EmptyStmt> callReturnNode = sdg.addNode("output", new EmptyStmt(), TypeNodeFactory.fromType(NodeType.METHOD_OUTPUT));
        GraphNode<EmptyStmt> callReturnNode = sdg.addNode("output", new EmptyStmt(), TypeNodeFactory.fromType(NodeType.METHOD_CALL_RETURN));

        sdg.addControlDependencyArc(methodCallNode, callReturnNode);
        sdg.addReturnArc(callReturnNode, originalMethodCallNode);
        sdg.addReturnArc(declarationOutputNode, callReturnNode);
        sdg.addDataDependencyArc(callReturnNode, originalMethodCallNode);
        sdg.addParameterInOutArc(declarationOutputNode, callReturnNode);

        Logger.log("MethodCallReplacerVisitor", String.format("%s | Method '%s' called", methodCallExpr, methodDeclaration.getNameAsString()));
    }
+5 −14
Original line number Diff line number Diff line
package tfm.graphs.sdg;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.stmt.EmptyStmt;
import com.github.javaparser.ast.stmt.ExpressionStmt;
import com.github.javaparser.ast.stmt.ReturnStmt;
import tfm.arcs.Arc;
import tfm.arcs.cfg.ControlFlowArc;
import tfm.arcs.pdg.ControlDependencyArc;
import tfm.arcs.pdg.DataDependencyArc;
import tfm.arcs.sdg.CallArc;
import tfm.arcs.sdg.ParameterInOutArc;
import tfm.arcs.sdg.ReturnArc;
import tfm.graphs.Buildable;
import tfm.graphs.Graph;
import tfm.graphs.cfg.CFG;
import tfm.graphs.pdg.PDG;
import tfm.nodes.*;
import tfm.slicing.Slice;
import tfm.slicing.Sliceable;
@@ -26,9 +20,6 @@ import tfm.utils.Context;
import tfm.utils.Utils;

import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class SDG extends Graph implements Sliceable, Buildable<NodeList<CompilationUnit>> {
    private boolean built = false;
@@ -74,6 +65,10 @@ public class SDG extends Graph implements Sliceable, Buildable<NodeList<Compilat
        this.addEdge(from, to, new ControlDependencyArc());
    }

    public void addDataDependencyArc(GraphNode<?> from, GraphNode<?> to) {
        this.addDataDependencyArc(from, to, null);
    }

    public void addDataDependencyArc(GraphNode<?> from, GraphNode<?> to, String variable) {
        this.addEdge(from, to, new DataDependencyArc(variable));
    }
@@ -82,14 +77,10 @@ public class SDG extends Graph implements Sliceable, Buildable<NodeList<Compilat
        this.addEdge(from, to, new CallArc());
    }

    public void addParameterInOutArc(GraphNode<ExpressionStmt> from, GraphNode<ExpressionStmt> to) {
    public void addParameterInOutArc(GraphNode<?> from, GraphNode<?> to) {
        this.addEdge(from, to, new ParameterInOutArc());
    }

    public void addReturnArc(GraphNode<?> from, GraphNode<?> to) {
        this.addEdge(from, to, new ReturnArc());
    }

    public List<GraphNode<?>> findDeclarationsOfVariable(String variable, GraphNode<?> root) {
        return this.methodCFGMap.values().stream()
                .filter(cfg -> cfg.containsVertex(root))
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ class SDGBuilder extends VoidVisitorAdapter<Context> {
        pdg.getCfg().vertexSet().stream()
                .filter(node -> node.getAstNode() instanceof ReturnStmt)
                .map(node -> (GraphNode<ReturnStmt>) node)
                .forEach(node -> sdg.addReturnArc(node, outputNode));
                .forEach(node -> sdg.addDataDependencyArc(node, outputNode));
    }

    @Override
Loading