Unverified Commit ee10b5bd authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Small fixes found from coverage analysis.

* Unified both summary arc analyzers
* Deleted unused code.
* Converted checks into assertions
* Removed some bad patterns, including a possible bug in BinaryExpr handling.
parent 33065104
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ public class PHPSlice {
        }
        sdg.build(units);

        SlicingCriterion sc = graph -> Set.of(graph.findNodeById(0).orElseThrow());
        SlicingCriterion sc = graph -> Set.of(graph.findNodeBy(n -> n.getId() == (long) 0).orElseThrow());
        Slice slice = new Slice();
        if (scId != 0) {
            // Slice the SDG
+1 −4
Original line number Diff line number Diff line
@@ -68,10 +68,7 @@ public class ExpressionObjectTreeFinder {

    public void locateAndMarkTransferenceToRoot(Expression expr, int index) {
        List<VariableAction> list = graphNode.getVariableActions();
        if (index < 0)
            locateAndMarkTransferenceToRoot(expr, list.get(list.size() + index));
        else
            locateAndMarkTransferenceToRoot(expr, list.get(index));
        locateAndMarkTransferenceToRoot(expr, list.get(index < 0 ? list.size() + index : index));
    }

    public void locateAndMarkTransferenceToRoot(Expression expression, VariableAction targetAction) {
+0 −5
Original line number Diff line number Diff line
@@ -46,11 +46,6 @@ public abstract class Graph extends DirectedPseudograph<GraphNode<?>, Arc> {
        throw new IllegalStateException("There may only be one real node representing each AST node in the graph!");
    }

    /** Search for a node in the graph given its id. */
    public Optional<GraphNode<?>> findNodeById(long id) {
        return findNodeBy(n -> n.getId() == id);
    }

    /** Search for a node in the graph given a predicate it must pass.
     *  If multiple nodes match the predicate, the first one found is returned. */
    public Optional<GraphNode<?>> findNodeBy(Predicate<GraphNode<?>> p) {
+3 −13
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ import com.github.javaparser.ast.body.CallableDeclaration;
import com.github.javaparser.ast.stmt.*;
import es.upv.mist.slicing.graphs.cfg.CFGBuilder;
import es.upv.mist.slicing.nodes.GraphNode;
import es.upv.mist.slicing.nodes.io.MethodExitNode;
import es.upv.mist.slicing.utils.ASTUtils;

import java.util.Deque;
@@ -141,17 +140,8 @@ public class ACFGBuilder extends CFGBuilder {
    // ======================================================================

    @Override
    protected void visitCallableDeclaration(CallableDeclaration<?> callableDeclaration, Void arg) {
        graph.buildRootNode(callableDeclaration);
        hangingNodes.add(graph.getRootNode());

        ASTUtils.getCallableBody(callableDeclaration).accept(this, arg);
        returnList.stream().filter(node -> !hangingNodes.contains(node)).forEach(hangingNodes::add);
        nonExecHangingNodes.add(graph.getRootNode()); // NEW vs CFG

        MethodExitNode exit = new MethodExitNode(callableDeclaration);
        graph.addVertex(exit);
        addMethodOutput(callableDeclaration, exit);
        connectTo(exit);
    protected void buildExit(CallableDeclaration<?> callableDeclaration) {
        nonExecHangingNodes.add(graph.getRootNode());
        super.buildExit(callableDeclaration);
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -358,12 +358,22 @@ public class CFGBuilder extends VoidVisitorAdapter<Void> {
     * to the exit node.
     */
    protected void visitCallableDeclaration(CallableDeclaration<?> callableDeclaration, Void arg) {
        buildEnter(callableDeclaration);
        visitCallableDeclarationBody(callableDeclaration, arg);
        buildExit(callableDeclaration);
    }

    protected void buildEnter(CallableDeclaration<?> callableDeclaration) {
        graph.buildRootNode(callableDeclaration);
        hangingNodes.add(graph.getRootNode());
    }

    protected void visitCallableDeclarationBody(CallableDeclaration<?> callableDeclaration, Void arg) {
        ASTUtils.getCallableBody(callableDeclaration).accept(this, arg);
        returnList.stream().filter(node -> !hangingNodes.contains(node)).forEach(hangingNodes::add);
    }

    protected void buildExit(CallableDeclaration<?> callableDeclaration) {
        MethodExitNode exit = new MethodExitNode(callableDeclaration);
        graph.addVertex(exit);
        addMethodOutput(callableDeclaration, exit);
Loading