Commit 8e4730fb authored by jacosro's avatar jacosro
Browse files

OUT nodes not generated for primitive types or literals

parent 7c29ef7b
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ import tfm.arcs.pdg.ControlDependencyArc;
import tfm.arcs.pdg.DataDependencyArc;
import tfm.arcs.sdg.CallArc;
import tfm.arcs.sdg.ParameterInOutArc;
import tfm.arcs.sdg.ReturnArc;
import tfm.arcs.sdg.SummaryArc;
import tfm.nodes.GraphNode;

@@ -87,17 +86,6 @@ public abstract class Arc extends DefaultEdge {
        throw new UnsupportedOperationException("Not a ParameterInOutArc");
    }

    /** @see ReturnArc */
    public final boolean isReturnArc() {
        return this instanceof ReturnArc;
    }

    public final ReturnArc asReturnArc() {
        if (isReturnArc())
            return (ReturnArc) this;
        throw new UnsupportedOperationException("Not a ReturnArc");
    }

    /** @see SummaryArc */
    public final boolean isSummaryArc() {
        return this instanceof SummaryArc;
+7 −1
Original line number Diff line number Diff line
@@ -309,8 +309,14 @@ public class CFGBuilder extends VoidVisitorAdapter<Void> {
        returnList.stream().filter(node -> !hangingNodes.contains(node)).forEach(hangingNodes::add);

        // Create and connect formal-out nodes sequentially
        for (Parameter param : methodDeclaration.getParameters())
        for (Parameter param : methodDeclaration.getParameters()) {
            // Do not generate out for primitives
            if (param.getType().isPrimitiveType()) {
                continue;
            }

            connectTo(addFormalOutGraphNode(param));
        }
        // Create and connect the exit node
        connectTo(graph.addNode("Exit", new EmptyStmt(), TypeNodeFactory.fromType(NodeType.METHOD_EXIT)));
    }
+2 −34
Original line number Diff line number Diff line
@@ -110,10 +110,6 @@ class MethodCallReplacerVisitor extends VoidVisitorAdapter<Context> {
        GraphNode<MethodDeclaration> methodDeclarationNode = optionalNethodDeclarationNode.get();
        MethodDeclaration methodDeclaration = methodDeclarationNode.getAstNode();

        Optional<CFG> optionalCFG = sdg.getMethodCFG(methodDeclaration);
        assert optionalCFG.isPresent();
        CFG methodCFG = optionalCFG.get();

        GraphNode<MethodCallExpr> methodCallNode = sdg.addNode("CALL " + methodCallExpr.toString(), methodCallExpr, TypeNodeFactory.fromType(NodeType.METHOD_CALL));

        sdg.addControlDependencyArc(originalMethodCallNode, methodCallNode);
@@ -182,32 +178,8 @@ class MethodCallReplacerVisitor extends VoidVisitorAdapter<Context> {

            // Out expression

            OutNodeVariableVisitor shouldHaveOutNodeVisitor = new OutNodeVariableVisitor();
            Set<String> variablesForOutNode = new HashSet<>();
            argument.accept(shouldHaveOutNodeVisitor, variablesForOutNode);

            // Here, variablesForOutNode may have 1 variable or more depending on the expression

            Logger.log("MethodCallReplacerVisitor", String.format("Variables for out node: %s", variablesForOutNode));
            if (variablesForOutNode.isEmpty()) {
                /*
                    If the argument is not a variable or it is not declared in the scope,
                    then there is no OUT node
                 */
                Logger.log("MethodCallReplacerVisitor", String.format("Expression '%s' should not have out node", argument.toString()));
                continue;
            } else if (variablesForOutNode.size() == 1) {
                String variable = variablesForOutNode.iterator().next();

                List<GraphNode<?>> declarations = sdg.findDeclarationsOfVariable(variable, originalMethodCallNode);

                Logger.log("MethodCallReplacerVisitor", String.format("Declarations of variable: '%s': %s", variable, declarations));

                if (declarations.isEmpty()) {
                    Logger.log("MethodCallReplacerVisitor", String.format("Expression '%s' should not have out node", argument.toString()));
                    continue;
                }
            } else {
            // If argument is primitive or not a variable, do not generate out nodes
            if (parameter.getType().isPrimitiveType() || !argument.isNameExpr()) {
                continue;
            }

@@ -284,10 +256,6 @@ class MethodCallReplacerVisitor extends VoidVisitorAdapter<Context> {
        Logger.log("MethodCallReplacerVisitor", String.format("%s | Method '%s' called", methodCallExpr, methodDeclaration.getNameAsString()));
    }

    private void argumentAsNameExpr(GraphNode<ExpressionStmt> methodCallNode) {

    }

    @Override
    public void visit(MethodDeclaration n, Context arg) {
        arg.setCurrentMethod(n);