Commit da46f315 authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Redesigned VariableAction and ObjectTree

* VariableAction has 0..1 root OTs.
* VariableAction no longer has expressions, but has its kind of variable and name (in the future possibly type).
* Simplified checks and functions as a result
parent c4107366
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ public class DataDependencyArc extends Arc {
    protected final VariableAction targetVar;

    public DataDependencyArc(VariableAction sourceVar, VariableAction targetVar) {
        super(sourceVar.getVariable());
        super(sourceVar.getName());
        if (VALID_VA_COMBOS.stream().noneMatch(p -> p.test(sourceVar, targetVar)))
            throw new IllegalArgumentException("Illegal combination of actions: " + sourceVar + ", " + targetVar);
        this.sourceVar = sourceVar;
+1 −1
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ public class ClassGraph extends DirectedPseudograph<ClassGraph.Vertex, ClassGrap
    protected ObjectTree generateObjectTreeFor(Vertex classVertex) {
        if (classVertex == null)
            return new ObjectTree();
        return generateObjectTreeFor(classVertex, new ObjectTree(), "-root-");
        return generateObjectTreeFor(classVertex, new ObjectTree(), ObjectTree.ROOT_NAME);
    }

    protected ObjectTree generateObjectTreeFor(Vertex classVertex, ObjectTree tree, String level) {
+18 −22
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs;

import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.VariableDeclarator;
import com.github.javaparser.ast.expr.*;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
@@ -40,11 +41,11 @@ public class ExpressionObjectTreeFinder {
        VariableAction lastDef = null;
        for (VariableAction a : graphNode.getVariableActions()) {
            if (a.isDeclaration()) {
                if (a.getVariable().equals(varName))
                if (a.getName().equals(varName))
                    foundDecl = true;
                else if (foundDecl)
                    return lastDef;
            } else if (a.isDefinition() && a.getVariable().equals(varName)) {
            } else if (a.isDefinition() && a.getName().equals(varName)) {
                lastDef = a;
            }
        }
@@ -97,9 +98,7 @@ public class ExpressionObjectTreeFinder {
                if (n.resolve().isType())
                    return;
                for (VariableAction action : graphNode.getVariableActions()) {
                    if (action.isUsage() &&
                            action.getVariable().equals(n.getNameAsString()) &&
                            n.equals(action.getVariableExpression())) {
                    if (action.isUsage() && action.getName().equals(n.getNameAsString())) {
                        list.add(new Pair<>(action, arg));
                        return;
                    }
@@ -110,19 +109,10 @@ public class ExpressionObjectTreeFinder {
            @Override
            public void visit(ThisExpr n, String arg) {
                for (VariableAction action : graphNode.getVariableActions()) {
                    if (action.isUsage()) {
                        if (action.getVariableExpression() == null) {
                            if (action.getVariable().matches("^.*this$")) {
                    if (action.isUsage() && action.getName().matches("^.*this$")) {
                        list.add(new Pair<>(action, arg));
                        return;
                    }
                        } else {
                            if (n.equals(action.getVariableExpression())) {
                                list.add(new Pair<>(action, arg));
                                return;
                            }
                        }
                    }
                }
                throw new IllegalStateException("Could not find USE(this)");
            }
@@ -147,14 +137,20 @@ public class ExpressionObjectTreeFinder {
            protected void visitCall(Expression call, String arg) {
                if (ASTUtils.shouldVisitArgumentsForMethodCalls((Resolvable<? extends ResolvedMethodLikeDeclaration>) call))
                    return;
                VariableAction lastUseOut = null;
                for (VariableAction variableAction : graphNode.getVariableActions()) {
                    if (variableAction.isUsage() &&
                            variableAction.getVariable().equals(VARIABLE_NAME_OUTPUT) &&
                            call.equals(variableAction.getVariableExpression())) {
                        list.add(new Pair<>(variableAction, arg));
                    if (variableAction instanceof VariableAction.CallMarker) {
                        VariableAction.CallMarker marker = (VariableAction.CallMarker) variableAction;
                        if (ASTUtils.equalsWithRange((Node) marker.getCall(), call) && !marker.isEnter()) {
                            assert lastUseOut != null;
                            list.add(new Pair<>(lastUseOut, arg));
                            return;
                        }
                    }
                    if (variableAction.isUsage() && variableAction.getName().equals(VARIABLE_NAME_OUTPUT)) {
                        lastUseOut = variableAction;
                    }
                }
                throw new IllegalStateException("Could not find USE(-output-) corresponding to call " + call);
            }
        }, "");
+1 −1
Original line number Diff line number Diff line
@@ -374,7 +374,7 @@ public class CFGBuilder extends VoidVisitorAdapter<Void> {
     * @see #VARIABLE_NAME_OUTPUT */
    protected void addMethodOutput(CallableDeclaration<?> callableDeclaration, GraphNode<?> exit) {
        if (!(callableDeclaration instanceof MethodDeclaration) || !((MethodDeclaration) callableDeclaration).getType().isVoidType()) {
            VariableAction usage = new VariableAction.Usage(null, VARIABLE_NAME_OUTPUT, exit);
            VariableAction usage = new VariableAction.Usage(VariableAction.DeclarationType.SYNTHETIC, VARIABLE_NAME_OUTPUT, exit);
            exit.addVariableAction(new VariableAction.Movable(usage, OutputNode.create(callableDeclaration)));
        }
    }
+4 −4
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ public class JSysCFG extends ESCFG {
    /** Given a usage of an object member, find the last definitions of that member.
     *  This method returns a list of variable actions, where the caller can find the member. */
    public List<VariableAction> findLastDefinitionOfObjectMember(VariableAction usage, String member) {
        return findLastVarActionsFrom(usage, def -> def.isDefinition() && def.getObjectTree().hasMember(member));
        return findLastVarActionsFrom(usage, def -> def.isDefinition() && def.hasTreeMember(member));
    }

    /** Given a usage of a primitive variable, find the last def actions that affect it. */
@@ -80,7 +80,7 @@ public class JSysCFG extends ESCFG {
    public List<VariableAction> findNextObjectDefinitionsFor(VariableAction definition, String member) {
        if (!this.containsVertex(definition.getGraphNode()))
            throw new NodeNotFoundException(definition.getGraphNode(), this); // TODO: al crear los root/resumen, las movable no se ponen en el movable
        if (definition.getObjectTree().hasMember(member))
        if (definition.hasTreeMember(member))
            return List.of(definition);
        List<VariableAction> list = new LinkedList<>();
        findNextVarActionsFor(new HashSet<>(), list, definition.getGraphNode(), definition, VariableAction::isDefinition, member);
@@ -102,7 +102,7 @@ public class JSysCFG extends ESCFG {
        if (!list.isEmpty()) {
            boolean found = false;
            for (VariableAction variableAction : list) {
                if (!variableAction.isOptional() && variableAction.getObjectTree().hasMember(memberName)) {
                if (!variableAction.isOptional() && variableAction.hasTreeMember(memberName)) {
                    found = true;
                    break;
                }
@@ -189,7 +189,7 @@ public class JSysCFG extends ESCFG {
        protected void addMethodOutput(CallableDeclaration<?> callableDeclaration, GraphNode<?> exit) {
            super.addMethodOutput(callableDeclaration, exit);
            for (VariableAction action : exit.getVariableActions()) {
                if (action.getVariable().equals(VARIABLE_NAME_OUTPUT)) {
                if (action.getName().equals(VARIABLE_NAME_OUTPUT)) {
                    expandOutputVariable(callableDeclaration, action);
                    break;
                }
Loading