Commit fef704d0 authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Add Structural arcs to avoid stopping the traversal when a pseudo-predicate...

Add Structural arcs to avoid stopping the traversal when a pseudo-predicate (i.e. return) has objects connected to it.
parent 2bb7bac6
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.arcs.pdg;

import es.upv.mist.slicing.arcs.Arc;
import org.jgrapht.nio.Attribute;
import org.jgrapht.nio.DefaultAttribute;

import java.util.Map;

public class StructuralArc extends Arc {
    @Override
    public Map<String, Attribute> getDotAttributes() {
        Map<String, Attribute> map = super.getDotAttributes();
        map.put("style", DefaultAttribute.createAttribute("dashed"));
        return map;
    }
}
+18 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package es.upv.mist.slicing.graphs.jsysdg;

import es.upv.mist.slicing.arcs.pdg.FlowDependencyArc;
import es.upv.mist.slicing.arcs.pdg.ObjectFlowDependencyArc;
import es.upv.mist.slicing.arcs.pdg.StructuralArc;
import es.upv.mist.slicing.arcs.pdg.TotalDefinitionDependenceArc;
import es.upv.mist.slicing.graphs.exceptionsensitive.ESCFG;
import es.upv.mist.slicing.graphs.exceptionsensitive.ESPDG;
@@ -9,6 +10,7 @@ import es.upv.mist.slicing.graphs.pdg.PDG;
import es.upv.mist.slicing.nodes.GraphNode;
import es.upv.mist.slicing.nodes.ObjectTree;
import es.upv.mist.slicing.nodes.VariableAction;
import es.upv.mist.slicing.nodes.io.ActualIONode;
import es.upv.mist.slicing.nodes.io.CallNode;
import es.upv.mist.slicing.nodes.oo.MemberNode;

@@ -30,6 +32,10 @@ public class JSysPDG extends ESPDG {
        return new Builder();
    }

    protected void addStructuralArc(GraphNode<?> source, GraphNode<?> target) {
        addEdge(source, target, new StructuralArc());
    }

    // definicion de raiz --object-flow--> uso de raiz
    protected void addObjectFlowDependencyArc(VariableAction definition, VariableAction usage) {
        addEdge(graphNodeOf(definition), graphNodeOf(usage), new ObjectFlowDependencyArc());
@@ -149,7 +155,7 @@ public class JSysPDG extends ESPDG {
                            if (node.isImplicitInstruction())
                                callNode.markAsImplicit();
                            addVertex(callNode);
                            addControlDependencyArc(node, callNode);
                            addStructuralArc(node, callNode);
                            callNodeStack.push(callNode);
                        }
                        continue;
@@ -175,6 +181,16 @@ public class JSysPDG extends ESPDG {
            }
        }

        @Override
        protected void connectRealNode(GraphNode<?> graphNode, CallNode callNode, GraphNode<?> realNode) {
            if (realNode instanceof ActualIONode || realNode instanceof CallNode.Return) {
                assert callNode != null;
                addStructuralArc(callNode, realNode);
            } else {
                addStructuralArc(graphNode == cfg.getExitNode() ? rootNode : graphNode, realNode);
            }
        }

        protected void applyTreeConnections() {
            cfg.vertexSet().stream()
                    .flatMap(node -> node.getVariableActions().stream())
@@ -186,7 +202,7 @@ public class JSysPDG extends ESPDG {
                memberNode.setParent(parentNode);
            assert containsVertex(memberNode.getParent());
            addVertex(memberNode);
            addControlDependencyArc(memberNode.getParent(), memberNode);
            addStructuralArc(memberNode.getParent(), memberNode);
        }

        protected void valueDependencyForThrowStatements() {
+0 −3
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ package es.upv.mist.slicing.graphs.sdg;
import com.github.javaparser.ast.body.CallableDeclaration;
import com.github.javaparser.resolution.Resolvable;
import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration;
import es.upv.mist.slicing.arcs.Arc;
import es.upv.mist.slicing.arcs.sdg.CallArc;
import es.upv.mist.slicing.arcs.sdg.ParameterInOutArc;
import es.upv.mist.slicing.graphs.CallGraph;
@@ -54,7 +53,6 @@ public class CallConnector {

        // Locate and connect all ACTUAL nodes
        sdg.outgoingEdgesOf(callNode).stream()
                .filter(Arc::isControlDependencyArc)
                .map(sdg::getEdgeTarget)
                .filter(ActualIONode.class::isInstance)
                .map(ActualIONode.class::cast)
@@ -67,7 +65,6 @@ public class CallConnector {

        // Locate and connect the -output- node
        sdg.outgoingEdgesOf(callNode).stream()
                .filter(Arc::isControlDependencyArc)
                .map(sdg::getEdgeTarget)
                .filter(CallNode.Return.class::isInstance)
                .forEach(n -> connectOutput(declarationNode, n));