Commit 54e87c8e authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Stop the creation of NameExpr, and avoid modifying the AST

* VariableAction stores the real name and the variable may be null.
* VariableVisitor entrypoint must be #startVisit().
parent f2125e1f
Loading
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs.augmented;

import com.github.javaparser.ast.body.CallableDeclaration;
import com.github.javaparser.ast.expr.NameExpr;
import com.github.javaparser.ast.stmt.*;
import es.upv.mist.slicing.graphs.cfg.CFGBuilder;
import es.upv.mist.slicing.nodes.GraphNode;
@@ -134,7 +133,7 @@ public class ACFGBuilder extends CFGBuilder {
        GraphNode<ReturnStmt> node = connectTo(returnStmt);
        returnStmt.getExpression().ifPresent(n -> {
            n.accept(this, arg);
            node.addDefinedVariable(new NameExpr(VARIABLE_NAME_OUTPUT), n);
            node.addDefinedVariable(null, VARIABLE_NAME_OUTPUT, n);
        });
        returnList.add(node);
        clearHanging();
+2 −3
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ import com.github.javaparser.ast.body.ConstructorDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.expr.BooleanLiteralExpr;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.NameExpr;
import com.github.javaparser.ast.expr.SimpleName;
import com.github.javaparser.ast.stmt.*;
import com.github.javaparser.ast.visitor.VoidVisitor;
@@ -331,7 +330,7 @@ public class CFGBuilder extends VoidVisitorAdapter<Void> {
        GraphNode<ReturnStmt> node = connectTo(returnStmt);
        returnStmt.getExpression().ifPresent(n -> {
            n.accept(this, arg);
            node.addDefinedVariable(new NameExpr(VARIABLE_NAME_OUTPUT), n);
            node.addDefinedVariable(null, VARIABLE_NAME_OUTPUT, n);
        });
        returnList.add(node);
        clearHanging();
@@ -379,7 +378,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(new NameExpr(VARIABLE_NAME_OUTPUT), exit);
            VariableAction usage = new VariableAction.Usage(null, VARIABLE_NAME_OUTPUT, exit);
            exit.addMovableVariable(new VariableAction.Movable(usage, OutputNode.create(callableDeclaration)));
        }
    }
+4 −5
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ package es.upv.mist.slicing.graphs.exceptionsensitive;

import com.github.javaparser.ast.body.CallableDeclaration;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.ast.expr.NameExpr;
import com.github.javaparser.ast.expr.ObjectCreationExpr;
import com.github.javaparser.ast.stmt.*;
import com.github.javaparser.ast.type.Type;
@@ -127,7 +126,7 @@ public class ESCFG extends ACFG {
                // Exception exit
                Collection<ExceptionExitNode> exceptionExits = processExceptionSources(callableDeclaration);
                for (ExceptionExitNode node : exceptionExits) {
                    node.addUsedVariable(new NameExpr(ACTIVE_EXCEPTION_VARIABLE));
                    node.addUsedVariable(null, ACTIVE_EXCEPTION_VARIABLE);
                    hangingNodes.add(node);
                    lastNodes.addAll(hangingNodes);
                    clearHanging();
@@ -240,7 +239,7 @@ public class ESCFG extends ACFG {
            stmtStack.push(n);
            GraphNode<ThrowStmt> stmt = connectTo(n);
            n.getExpression().accept(this, arg);
            stmt.addDefinedVariable(new NameExpr(ACTIVE_EXCEPTION_VARIABLE), n.getExpression());
            stmt.addDefinedVariable(null, ACTIVE_EXCEPTION_VARIABLE, n.getExpression());
            populateExceptionSourceMap(new ExceptionSource(stmt, n.getExpression().calculateResolvedType()));
            clearHanging();
            nonExecHangingNodes.add(stmt);
@@ -286,7 +285,7 @@ public class ESCFG extends ACFG {
            for (ResolvedType type : resolved.getSpecifiedExceptions()) {
                hangingNodes.add(stmtNode);
                ExceptionReturnNode exceptionReturn = addExceptionReturnNode(call, type);
                exceptionReturn.addDefinedVariable(new NameExpr(ACTIVE_EXCEPTION_VARIABLE), null); // TODO: improve initializer
                exceptionReturn.addDefinedVariable(null, ACTIVE_EXCEPTION_VARIABLE, null); // TODO: improve initializer
                populateExceptionSourceMap(new ExceptionSource(exceptionReturn, type));
                returnNodes.add(exceptionReturn);
                connectTo(exceptionReturn);
@@ -313,7 +312,7 @@ public class ESCFG extends ACFG {
            for (ExceptionSource src : sources)
                (src.isActive() ? hangingNodes : nonExecHangingNodes).add(src.source);
            GraphNode<?> node = connectTo(n, "catch (" + n.getParameter().toString() + ")");
            node.addUsedVariable(new NameExpr(ACTIVE_EXCEPTION_VARIABLE));
            node.addUsedVariable(null, ACTIVE_EXCEPTION_VARIABLE);
            exceptionSourceMap.clear();
            // 2. Set up as exception source
            ExceptionSource catchES = ExceptionSource.merge(node, sources);
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ public class DynamicTypeResolver {
    /** Searches for the corresponding VariableAction object, then calls {@link #resolveVariableAction(VariableAction)}. */
    protected Stream<ResolvedType> resolveVariable(Expression expression, GraphNode<?> graphNode) {
        Optional<VariableAction> va = graphNode.getVariableActions().stream()
                .filter(action -> ASTUtils.equalsWithRange(action.getVariableExpression(), expression))
                .filter(action -> action.hasVariableExpression() && ASTUtils.equalsWithRange(action.getVariableExpression(), expression))
                .findFirst();
        if (va.isEmpty())
            return anyTypeOf(expression);
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ public class InterproceduralDefinitionFinder extends InterproceduralActionFinder
            Set<NameExpr> exprSet = new HashSet<>();
            arg.accept(new OutNodeVariableVisitor(), exprSet);
            for (NameExpr nameExpr : exprSet)
                movables.add(new VariableAction.Movable(new VariableAction.Definition(nameExpr, graphNode), actualOut));
                movables.add(new VariableAction.Movable(new VariableAction.Definition(nameExpr, nameExpr.toString(), graphNode), actualOut));
        } else {
            movables.add(new VariableAction.Movable(def.toDefinition(graphNode), actualOut));
        }
Loading