Commit 955981f3 authored by Sergio Pérez's avatar Sergio Pérez
Browse files

Super call added & JSysDG

parent 39bc794d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSol
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
import es.upv.mist.slicing.graphs.augmented.ASDG;
import es.upv.mist.slicing.graphs.jsysdg.JSysDG;
import es.upv.mist.slicing.graphs.augmented.PSDG;
import es.upv.mist.slicing.graphs.exceptionsensitive.ESSDG;
import es.upv.mist.slicing.graphs.sdg.SDG;
@@ -236,6 +237,7 @@ public class Slicer {
            case "ASDG":  sdg = new ASDG();  break;
            case "PSDG":  sdg = new PSDG();  break;
            case "ESSDG": sdg = new ESSDG(); break;
            case "JSysDG": sdg = new JSysDG(); break;
            default:
                throw new IllegalArgumentException("Unknown type of graph. Available graphs are SDG, ASDG, PSDG, ESSDG");
        }
+11 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs.jsysdg;

import com.github.javaparser.ast.Node;
import es.upv.mist.slicing.nodes.SyntheticNode;

// TODO: Concretar más el tipo T del nodo (Node es muy general). Por ahora seria solo ExplicitConstructorInvocationStmt
public class ImplicitNode extends SyntheticNode<Node> {
    protected ImplicitNode(String instruction, Node astNode) {
        super(instruction, astNode);
    }
}
+34 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs.jsysdg;

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import es.upv.mist.slicing.graphs.ClassGraph;
import es.upv.mist.slicing.graphs.cfg.CFGBuilder;
import es.upv.mist.slicing.graphs.exceptionsensitive.ESCFG;

public class JSysCFG extends ESCFG {

    /** ClassGraph associated to the Method represented by the CFG */
    protected ClassGraph clg;

    public JSysCFG(ClassGraph clg){
        super();
        this.clg = clg;
    }

    public ClassGraph getClassGraph(){
        return this.clg;
    }

    protected CFGBuilder newCFGBuilder() {
        return new JSysCFGBuilder(this);
    }


    /** Obtains the Javaparser Node corresponding to the class where the CFG is contained */
    public ClassOrInterfaceDeclaration getDeclarationClass() {
        assert rootNode != null;
        if (!(rootNode.getAstNode().getParentNode().get() instanceof ClassOrInterfaceDeclaration))
            throw new IllegalStateException("The Method declaration is not directly inside a Class Declaration");
        return (ClassOrInterfaceDeclaration) rootNode.getAstNode().getParentNode().get();
    }
}
+76 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs.jsysdg;

import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.*;
import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt;
import es.upv.mist.slicing.graphs.augmented.ACFGBuilder;
import es.upv.mist.slicing.nodes.io.MethodExitNode;
import es.upv.mist.slicing.utils.ASTUtils;

import java.util.LinkedList;
import java.util.List;

public class JSysCFGBuilder extends ACFGBuilder {

    /** List of inserted super calls in Javaparser AST to process them as Implicit Nodes (@ImplicitNode)*/
    protected List<Node> methodInsertedInstructions = new LinkedList<>();

    protected JSysCFGBuilder(JSysCFG graph) {
        super(graph);
    }

    /** Esto se llama porque lo hemos insertado fantasma o porque existe. A continuacion se inserta el codigo dynInit */
    @Override
    public void visit(ExplicitConstructorInvocationStmt n, Void arg) {

        // 1. Create new super call if not present
        if (methodInsertedInstructions.contains(n)){
            ImplicitNode node = new ImplicitNode(n.toString(), n); // TODO: implementar
            connectTo(node);
        }
        else {
            connectTo(n);
        }
        // 2. Insert dynamic class code
        // TODO

    }

    @Override
    public void visit(FieldDeclaration n, Void arg){
        connectTo(n);
    }

    @Override
    public void visit(InitializerDeclaration n, Void arg){
        // TODO
    }


    @Override
    protected void visitCallableDeclaration(CallableDeclaration<?> callableDeclaration, Void arg) {
        graph.buildRootNode(callableDeclaration);
        hangingNodes.add(graph.getRootNode());

        // 1. Check if first is super (only if constructor)
        //      then, create and build super()
        if (callableDeclaration instanceof ConstructorDeclaration){
            ConstructorDeclaration declaration = (ConstructorDeclaration) callableDeclaration;
            if (!ASTUtils.constructorHasExplicitConstructorInvocation(declaration)){
                ExplicitConstructorInvocationStmt superCall =
                        new ExplicitConstructorInvocationStmt(null, null, false, null, new NodeList<>());
                methodInsertedInstructions.add(superCall);
                declaration.getBody().addStatement(0, superCall);
            }
        }

        ASTUtils.getCallableBody(callableDeclaration).accept(this, arg);
        returnList.stream().filter(node -> !hangingNodes.contains(node)).forEach(hangingNodes::add);

        MethodExitNode exit = new MethodExitNode(callableDeclaration);
        graph.addVertex(exit);
        addMethodOutput(callableDeclaration, exit);
        connectTo(exit);
    }
}
+6 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs.jsysdg;

import es.upv.mist.slicing.graphs.exceptionsensitive.ESSDG;

public class JSysDG extends ESSDG {
}
Loading