Commit 17af8cad authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Small fixes

* Tests creates the root node of the PDG
* Data dependency ignores nonexecutable edges
* Non-executable edges are displayed as dashed
* Small bug in the implementation of `CFGBuilder`
parent 07fe208e
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -12,10 +12,6 @@ import java.util.Map;
import java.util.Objects;

public abstract class Arc extends DefaultEdge {
    public Arc() {

    }

    /** @see tfm.arcs.cfg.ControlFlowArc */
    public final boolean isControlFlowArc() {
        return this instanceof ControlFlowArc;
+10 −5
Original line number Diff line number Diff line
package tfm.arcs.cfg;

import org.jgrapht.io.Attribute;
import org.jgrapht.io.DefaultAttribute;
import tfm.arcs.Arc;
import tfm.graphs.augmented.ACFG;

import java.util.Map;

/**
 * An edge of the {@link tfm.graphs.CFG}, representing the direct
 * flow of control. It connects two instructions if, when the source
 * is executed, one of the possible next instructions is the destination.
 */
public class ControlFlowArc extends Arc {
    public ControlFlowArc() {
    }

    /**
     * Represents a non-executable control flow arc, used within the {@link ACFG ACFG}.
     * Initially it had the following meaning: connecting a statement with
@@ -20,8 +21,12 @@ public class ControlFlowArc extends Arc {
     * It is used to improve control dependence, and it should be skipped when
     * computing data dependence and other analyses.
     */
    public final static class NonExecutable extends ControlFlowArc {
        public NonExecutable() {
    public static final class NonExecutable extends ControlFlowArc {
        @Override
        public Map<String, Attribute> getDotAttributes() {
            Map<String, Attribute> map = super.getDotAttributes();
            map.put("style", DefaultAttribute.createAttribute("dashed"));
            return map;
        }
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -9,6 +9,4 @@ import tfm.arcs.Arc;
 * {@code b} if and only if {@code b} alters the number of times {@code a} is executed.
 */
public class ControlDependencyArc extends Arc {
    public ControlDependencyArc() {
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -44,9 +44,9 @@ public class CFG extends GraphWithRootNode<MethodDeclaration> {
        Set<GraphNode<?>> res = new HashSet<>();

        for (Arc arc : incomingEdgesOf(currentNode)) {
            ControlFlowArc controlFlowArc = arc.asControlFlowArc();

            GraphNode<?> from = this.getEdgeSource(controlFlowArc);
            if (!arc.isExecutableControlFlowArc())
                continue;
            GraphNode<?> from = getEdgeSource(arc);

            if (!Objects.equals(startNode, from) && visited.contains(from.getId())) {
                continue;
+1 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ public class CFGBuilder extends VoidVisitorAdapter<Void> {
        hangingNodes.addAll(breakMap.remove(n.getLabel()));
        // Remove the label from the continue map; the list should have been emptied
        // in the corresponding loop.
        if (continueMap.remove(n.getLabel()).isEmpty())
        if (!continueMap.remove(n.getLabel()).isEmpty())
            throw new IllegalStateException("Labeled loop has not cleared its list of continue statements!");
    }

Loading