Skip to content
Snippets Groups Projects
Commit 955981f3 authored by Sergio Pérez's avatar Sergio Pérez
Browse files

Super call added & JSysDG

parent 39bc794d
No related branches found
No related tags found
1 merge request!52Dynamic initializerDeclaration in ConstructorDeclaration
......@@ -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");
}
......
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);
}
}
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();
}
}
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);
}
}
package es.upv.mist.slicing.graphs.jsysdg;
import es.upv.mist.slicing.graphs.exceptionsensitive.ESSDG;
public class JSysDG extends ESSDG {
}
package es.upv.mist.slicing.graphs.jsysdg;
import es.upv.mist.slicing.graphs.ClassGraph;
import es.upv.mist.slicing.graphs.exceptionsensitive.ESPDG;
public class JSysPDG extends ESPDG {
public JSysPDG(ClassGraph clg) {
this(new JSysCFG(clg));
}
public JSysPDG(JSysCFG oocfg) {
super(oocfg);
}
}
......@@ -106,9 +106,9 @@ public class SDG extends Graph implements Sliceable, Buildable<NodeList<Compilat
public class Builder {
public void build(NodeList<CompilationUnit> nodeList) {
// See creation strategy at http://kaz2.dsic.upv.es:3000/Fzg46cQvT1GzHQG9hFnP1g#Using-data-flow-in-the-SDG
buildCFGs(nodeList); // 1
CallGraph callGraph = createCallGraph(nodeList); // 2
ClassGraph classGraph = createClassGraph(nodeList); // TODO: Update order and creation strategy
buildCFGs(nodeList, classGraph); // 1
CallGraph callGraph = createCallGraph(nodeList); // 2
dataFlowAnalysis(callGraph); // 3
buildAndCopyPDGs(); // 4
connectCalls(callGraph); // 5
......@@ -116,7 +116,7 @@ public class SDG extends Graph implements Sliceable, Buildable<NodeList<Compilat
}
/** Build a CFG per declaration found in the list of compilation units. */
protected void buildCFGs(NodeList<CompilationUnit> nodeList) {
protected void buildCFGs(NodeList<CompilationUnit> nodeList, ClassGraph clg) {
nodeList.accept(new VoidVisitorAdapter<Void>() {
@Override
public void visit(MethodDeclaration n, Void arg) {
......
......@@ -4,6 +4,7 @@ import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.visitor.CloneVisitor;
import es.upv.mist.slicing.graphs.jsysdg.ImplicitNode;
import es.upv.mist.slicing.nodes.GraphNode;
import java.util.*;
......@@ -20,8 +21,10 @@ public class Slice {
/** Add a node to this slice. */
public void add(GraphNode<?> node) {
assert !map.containsKey(node.getId());
map.put(node.getId(), node);
nodes.add(node.getAstNode());
if (this.isASTOriginalNode(node)) {
map.put(node.getId(), node);
nodes.add(node.getAstNode());
}
}
/** Add multiple nodes to this slice. */
......@@ -81,4 +84,9 @@ public class Slice {
}
return cus;
}
/** Returns whether a node was in the original AST or was added by instrumentation. */
private boolean isASTOriginalNode(GraphNode<?> node){
return !(node instanceof ImplicitNode);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment