Verified Commit 8b2d964e authored by Carlos Galindo's avatar Carlos Galindo
Browse files

ES-SlicingAlgorithm: modify rule 4 to account for PPDG

The PPDG makes some transitive CDs direct, in order to
remove some of them. The ES-SDG then stops some of these,
which had the consequence of not reaching `Enter` in some
cases.
parent 807845d9
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -11,4 +11,21 @@ import es.upv.mist.slicing.graphs.sdg.SDG;
 * {@code b} if and only if {@code b} alters the number of times {@code a} is executed.
 */
public class ControlDependencyArc extends Arc {
    private boolean ppdgExclusive = false;

    /** Mark this arc as PPDG exclusive.
     * @see #isPPDGExclusive() */
    public void setPPDGExclusive() {
        this.ppdgExclusive = true;
    }

    /** Whether this arc appears in the PPDG or subsequent graphs, but not in the APDG. */
    public boolean isPPDGExclusive() {
        return ppdgExclusive;
    }

    @Override
    public String getLabel() {
        return ppdgExclusive ? "*" : super.getLabel();
    }
}
+27 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs.augmented;

import com.github.javaparser.ast.body.CallableDeclaration;
import es.upv.mist.slicing.arcs.Arc;
import es.upv.mist.slicing.arcs.pdg.ControlDependencyArc;
import es.upv.mist.slicing.graphs.pdg.PDG;

import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/** A pseudo-predicate PDG, equivalent to an APDG that is built using the {@link PPControlDependencyBuilder
 * pseudo-predicate control dependency algorithm} instead of the classic one. */
public class PPDG extends APDG {
@@ -26,9 +33,29 @@ public class PPDG extends APDG {
            super();
        }

        @Override
        public void build(CallableDeclaration<?> declaration) {
            super.build(declaration);
            markPPDGExclusiveEdges(declaration);
        }

        @Override
        protected void buildControlDependency() {
            new PPControlDependencyBuilder((ACFG) cfg, PPDG.this).build();
        }

        /** Finds the CD arcs that are only present in the PPDG and marks them as such. */
        protected void markPPDGExclusiveEdges(CallableDeclaration<?> declaration) {
            APDG apdg = new APDG((ACFG) cfg);
            apdg.build(declaration);
            Set<Arc> apdgArcs = apdg.edgeSet().stream()
                    .filter(Arc::isUnconditionalControlDependencyArc)
                    .collect(Collectors.toSet());
            edgeSet().stream()
                    .filter(Arc::isUnconditionalControlDependencyArc)
                    .filter(Predicate.not(apdgArcs::contains))
                    .map(Arc::asControlDependencyArc)
                    .forEach(ControlDependencyArc::setPPDGExclusive);
        }
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -21,7 +21,8 @@ import java.util.stream.Stream;
 *          not keep traversing control-dependency arcs.</li>
 *     <li>CCD: a node reached by a CC1 or CC2 arc is not included in the slice until it has either been
 *          reached by an unconditional dependency or by the opposite (CC2 or CC1, respectively) arc.</li>
 *     <li>CCD: a node included only due to conditional-control-dependency should not keep traversing any arc.</li>
 *     <li>CCD: a node included only due to conditional-control-dependency should not keep traversing any arc,
 *          except for CD arcs that are exclusive to the PPDG.</li>
 *     <li>CCD (apply only if none of the previous allow for a new node and this does): CC1 arcs are
 *          transitively traversed, even when the intermediate nodes are not (yet) included in the slice.</li>
 * </ol>
@@ -121,6 +122,8 @@ public class ExceptionSensitiveSlicingAlgorithm implements SlicingAlgorithm {
    /** Applies rule 4 of the algorithm. */
    protected boolean essdgIgnore(Arc arc) {
        GraphNode<?> target = graph.getEdgeTarget(arc);
        if (arc.isUnconditionalControlDependencyArc() && arc.asControlDependencyArc().isPPDGExclusive())
            return false;
        return hasOnlyBeenReachedBy(target, ConditionalControlDependencyArc.class);
    }