Commit 3f27dd1a authored by Jonathan Andrade's avatar Jonathan Andrade
Browse files

set topological numbers into ICFG

parent ee6dea7f
Loading
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -90,8 +90,16 @@ public class ICFG extends es.upv.mist.slicing.graphs.Graph implements Buildable<
        protected IntraSCRGraph intraSCRs;
        /** Non-Recursive interprocedural Arcs from {@link  #intraSCRs} */
        protected Set<Triple<GraphNode<?>, GraphNode<?>, ControlFlowArc>> interprocNonRecArcs = new HashSet<>();
        /** A list of all {@link  #intraSCRs} that have an callSite type in Nanda-Ramesh algorithm */
        protected Set<IntraSCR> callSiteIntraSCRs = new HashSet<>();
        /** A list of all {@link  #intraSCRs} that have an returnSite type in Nanda-Ramesh algorithm */
        protected Set<IntraSCR> returnSiteIntraSCRs = new HashSet<>();
        /** A map to locate the correspondent call node from a return node */
        protected final Map<IntraSCR, IntraSCR> returnToCorrespondentCallSiteMap = new HashMap<>();
        /** A map to locate the {@link  #intraSCRs} within a call*/
        protected final Map<IntraSCR, Set<IntraSCR>> callNodeProcessMap = new HashMap<>();
        /** A map to get the topological number associated to the {@link  #intraSCRs} */
        protected final Map<Integer, IntraSCR> topologicalNumbersMap = new HashMap<>();
        /** counter for topologicalNumbers */
        protected int topologicalNumber = 0;

@@ -116,6 +124,15 @@ public class ICFG extends es.upv.mist.slicing.graphs.Graph implements Buildable<
            computeIntraSCRs();
            buildISCR();
            generateTopologicalNumbers();
            setTopologicalNumbersIntoICFG();
        }

        private void setTopologicalNumbersIntoICFG() {
            for (IntraSCR intraSCR : intraSCRs.vertexSet()) {
                for (GraphNode<?> graphNode : intraSCR.vertexSet()) {
                    graphNode.setTopologicalNumbers(intraSCR.getTopologicalNumberSet());
                }
            }
        }

        private void generateTopologicalNumbers() {
+4 −0
Original line number Diff line number Diff line
@@ -31,4 +31,8 @@ public class IntraSCR extends AbstractSCR<GraphNode<?>, Arc> {
                .map(String::valueOf)
                .collect(Collectors.joining("-"));
    }

    public Set<Integer> getTopologicalNumberSet() {
        return this.topologicalNumberSet;
    }
}
+15 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import es.upv.mist.slicing.graphs.sdg.SDG;
import es.upv.mist.slicing.utils.ASTUtils;

import java.util.*;
import java.util.stream.Collectors;

import static es.upv.mist.slicing.graphs.exceptionsensitive.ESCFG.ACTIVE_EXCEPTION_VARIABLE;

@@ -38,6 +39,8 @@ public class GraphNode<N extends Node> implements Comparable<GraphNode<?>> {
    /** @see #isImplicitInstruction() */
    protected boolean isImplicit = false;

    protected final Set<Integer> topologicalNumbersSet = new HashSet<>();

    /** Create a graph node, with id and variable actions generated automatically. */
    public GraphNode(String label, N astNode) {
        this(IdHelper.getInstance().getNextId(), label, astNode);
@@ -97,7 +100,8 @@ public class GraphNode<N extends Node> implements Comparable<GraphNode<?>> {

    /** The node's long-form label, including its id and information on variables. */
    public String getLongLabel() {
        String label = getId() + ": " + getLabel().replace("\\", "\\\\");
        String label = "Top - " + getTopologicalNumbersString() + " -";
        label += getId() + ": " + getLabel().replace("\\", "\\\\");
        if (!getVariableActions().isEmpty())
            label += "\\n" + getVariableActions().stream().map(Object::toString).reduce((a, b) -> a + "," + b).orElse("--");
        return label;
@@ -208,6 +212,16 @@ public class GraphNode<N extends Node> implements Comparable<GraphNode<?>> {
        variableActions.add(new VariableAction.CallMarker(call, this, enter));
    }

    public void setTopologicalNumbers(Set<Integer> topologicalNumbers) {
        this.topologicalNumbersSet.addAll(topologicalNumbers);
    }

    public String getTopologicalNumbersString() {
        return this.topologicalNumbersSet.stream()
                .map(String::valueOf)
                .collect(Collectors.joining(","));
    }

    // ============================================================
    // =======================  Overridden  =======================
    // ============================================================