Commit 6ce682af authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Move active exception DEF from CFG builder to VariableVisitor, and connect to expression.

parent 499da150
Loading
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType;
import es.upv.mist.slicing.arcs.Arc;
import es.upv.mist.slicing.nodes.VariableAction.ObjectTree;
import es.upv.mist.slicing.utils.ASTUtils;
import es.upv.mist.slicing.utils.Logger;
import es.upv.mist.slicing.utils.Utils;
import org.jgrapht.graph.DirectedPseudograph;
import org.jgrapht.nio.dot.DOTExporter;
@@ -151,15 +150,12 @@ public class ClassGraph extends DirectedPseudograph<ClassGraph.Vertex, ClassGrap
    }

    public ObjectTree generateObjectTreeFor(ResolvedReferenceType type) {
        Vertex classVertex = vertexDeclarationMap.get(mapKey(type));
        if (classVertex == null) {
            Logger.log("ResolvedReferenceType could not be found in class graph: " + type.describe());
            return new ObjectTree();
        }
        return generateObjectTreeFor(classVertex);
        return generateObjectTreeFor(vertexDeclarationMap.get(mapKey(type)));
    }

    protected ObjectTree generateObjectTreeFor(Vertex classVertex) {
        if (classVertex == null)
            return new ObjectTree();
        return generateObjectTreeFor(classVertex, new ObjectTree(), "-root-");
    }

+0 −1
Original line number Diff line number Diff line
@@ -240,7 +240,6 @@ public class ESCFG extends ACFG {
            stmtStack.push(n);
            GraphNode<ThrowStmt> stmt = connectTo(n);
            n.getExpression().accept(this, arg);
            stmt.addVADefineActiveException(n.getExpression());
            populateExceptionSourceMap(new ExceptionSource(stmt, n.getExpression().calculateResolvedType()));
            clearHanging();
            nonExecHangingNodes.add(stmt);
+12 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import java.util.List;
import java.util.Optional;

import static es.upv.mist.slicing.graphs.cfg.CFGBuilder.VARIABLE_NAME_OUTPUT;
import static es.upv.mist.slicing.graphs.exceptionsensitive.ESCFG.ACTIVE_EXCEPTION_VARIABLE;
import static es.upv.mist.slicing.nodes.VariableVisitor.Action.*;

/** A graph node visitor that extracts the actions performed in a given GraphNode. An initial action mode can
@@ -170,6 +171,17 @@ public class VariableVisitor extends GraphNodeContentVisitor<VariableVisitor.Act
        }
    }

    @Override
    public void visit(ThrowStmt n, Action arg) {
        super.visit(n, arg);
        definitionStack.push(n.getExpression());
        acceptAction(ACTIVE_EXCEPTION_VARIABLE, DEFINITION);
        definitionStack.pop();
        var fields = ClassGraph.getInstance().generateObjectTreeFor(n.getExpression().calculateResolvedType().asReferenceType());
        graphNode.getVariableActions().get(graphNode.getVariableActions().size() - 1).getObjectTree().addAll(fields);
        new ExpressionObjectTreeFinder(graphNode).locateAndMarkTransferenceToRoot(n.getExpression(), -1);
    }

    @Override
    public void visit(ForEachStmt n, Action action) {
        n.getIterable().accept(this, USE);