Unverified Commit b3e32945 authored by Javier Costa's avatar Javier Costa Committed by GitHub
Browse files

Merge pull request #38 from jacosro/37-change-out-nodes-generation

OUT nodes not generated for primitive types or literals
parents 8b75e37d 8e4730fb
Loading
Loading
Loading
Loading
+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);