Commit d7e2b00f authored by Sarah Grebing's avatar Sarah Grebing
Browse files

Interim (incomplete commit)

parent f15159ee
Pipeline #11593 passed with stage
in 2 minutes and 15 seconds
...@@ -4,7 +4,10 @@ import de.uka.ilkd.key.proof.init.ProofInputException; ...@@ -4,7 +4,10 @@ import de.uka.ilkd.key.proof.init.ProofInputException;
import de.uka.ilkd.key.speclang.Contract; import de.uka.ilkd.key.speclang.Contract;
import edu.kit.formal.gui.controls.*; import edu.kit.formal.gui.controls.*;
import edu.kit.formal.gui.model.RootModel; import edu.kit.formal.gui.model.RootModel;
import edu.kit.formal.interpreter.*; import edu.kit.formal.interpreter.Interpreter;
import edu.kit.formal.interpreter.InterpreterBuilder;
import edu.kit.formal.interpreter.KeYProofFacade;
import edu.kit.formal.interpreter.ProofTreeController;
import edu.kit.formal.interpreter.data.KeyData; import edu.kit.formal.interpreter.data.KeyData;
import edu.kit.formal.interpreter.data.State; import edu.kit.formal.interpreter.data.State;
import edu.kit.formal.proofscriptparser.Facade; import edu.kit.formal.proofscriptparser.Facade;
...@@ -159,7 +162,7 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -159,7 +162,7 @@ public class DebuggerMainWindowController implements Initializable {
}); });
/** /**
* create a new insepctionviewtab that is the main tab and not closable * create a new inspectionviewtab that is the main tab and not closable
*/ */
inspectionViewTabPane.createNewInspectionViewTab(model, true); inspectionViewTabPane.createNewInspectionViewTab(model, true);
...@@ -224,10 +227,10 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -224,10 +227,10 @@ public class DebuggerMainWindowController implements Initializable {
if (debugMode) { if (debugMode) {
blocker.getStepUntilBlock().set(1); blocker.getStepUntilBlock().set(1);
//for stepping functionality //for stepping functionality
StateGraphVisitor visitor = new StateGraphVisitor(currentInterpreter, scripts.get(0)); pc = new ProofTreeController(currentInterpreter, scripts.get(0));
pc = new ProofTreeController(currentInterpreter, scripts.get(0), visitor); currentInterpreter.getEntryListeners().add(pc.getStateVisitor());
currentInterpreter.getEntryListeners().add(visitor);
} }
blocker.install(currentInterpreter); blocker.install(currentInterpreter);
...@@ -391,8 +394,7 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -391,8 +394,7 @@ public class DebuggerMainWindowController implements Initializable {
} }
public void stepBack(ActionEvent actionEvent) { public void stepBack(ActionEvent actionEvent) {
System.out.println(blocker.getHistoryLogger());
blocker.unlock();
pc.stepBack(); pc.stepBack();
} }
......
...@@ -2,24 +2,35 @@ package edu.kit.formal.interpreter; ...@@ -2,24 +2,35 @@ package edu.kit.formal.interpreter;
import edu.kit.formal.proofscriptparser.ast.ASTNode; import edu.kit.formal.proofscriptparser.ast.ASTNode;
import java.util.ArrayList;
import java.util.List;
/** /**
* ControlFlowNode for ControlFlowGraph to look up step-edges for teh debugger. * ControlFlowNode for ControlFlowGraph to look up step-edges for teh debugger.
*/ */
@Deprecated
public class ControlFlowNode { public class ControlFlowNode {
edu.kit.formal.proofscriptparser.ast.ASTNode scriptstmt; private ASTNode scriptstmt;
private List<ASTNode> callCtx = new ArrayList<>();
public ControlFlowNode(ASTNode node) { public ControlFlowNode(ASTNode node) {
this.setScriptstmt(node); this.setScriptstmt(node);
} }
public List<ASTNode> getCallCtx() {
return callCtx;
}
public edu.kit.formal.proofscriptparser.ast.ASTNode getScriptstmt() { public void setCallCtx(List<ASTNode> callCtx) {
this.callCtx = callCtx;
}
public ASTNode getScriptstmt() {
return scriptstmt; return scriptstmt;
} }
public void setScriptstmt(edu.kit.formal.proofscriptparser.ast.ASTNode scriptstmt) { public void setScriptstmt(ASTNode scriptstmt) {
this.scriptstmt = scriptstmt; this.scriptstmt = scriptstmt;
} }
...@@ -27,10 +38,15 @@ public class ControlFlowNode { ...@@ -27,10 +38,15 @@ public class ControlFlowNode {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Node {"); sb.append("Node {");
if (scriptstmt != null) { if (scriptstmt != null) {
sb.append(scriptstmt.toString()); sb.append(scriptstmt.getNodeName().toString());
} else { } else {
sb.append("No Stmt"); sb.append("No Stmt");
} }
if (callCtx.isEmpty()) {
sb.append("Empty Context");
} else {
sb.append(callCtx.toString());
}
sb.append("}"); sb.append("}");
return sb.toString(); return sb.toString();
} }
......
...@@ -7,6 +7,7 @@ import edu.kit.formal.interpreter.funchdl.ProofScriptHandler; ...@@ -7,6 +7,7 @@ import edu.kit.formal.interpreter.funchdl.ProofScriptHandler;
import edu.kit.formal.proofscriptparser.DefaultASTVisitor; import edu.kit.formal.proofscriptparser.DefaultASTVisitor;
import edu.kit.formal.proofscriptparser.ast.*; import edu.kit.formal.proofscriptparser.ast.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -22,40 +23,47 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -22,40 +23,47 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> {
/** /**
* Last visited Node * Last visited Node
*/ */
private ASTNode lastNode; private ControlFlowNode lastNode;
/** /**
* Control Flow Graph * Control Flow Graph
*/ */
private MutableValueGraph<ASTNode, EdgeTypes> graph = ValueGraphBuilder.directed().allowsSelfLoops(true).build(); private MutableValueGraph<ControlFlowNode, EdgeTypes> graph = ValueGraphBuilder.directed().allowsSelfLoops(true).build();
private List<ASTNode> context = new ArrayList<>();
public ProgramFlowVisitor(CommandLookup functionLookup) { public ProgramFlowVisitor(CommandLookup functionLookup) {
this.functionLookup = functionLookup; this.functionLookup = functionLookup;
} }
public MutableValueGraph<ASTNode, EdgeTypes> getGraph() { public MutableValueGraph<ControlFlowNode, EdgeTypes> getGraph() {
return graph; return graph;
} }
@Override @Override
public Void visit(ProofScript proofScript) { public Void visit(ProofScript proofScript) {
lastNode = proofScript; ControlFlowNode scriptNode = new ControlFlowNode(proofScript);
graph.addNode(scriptNode);
System.out.println("\n" + scriptNode + "\n");
lastNode = scriptNode;
return this.visit(proofScript.getBody()); return this.visit(proofScript.getBody());
} }
@Override @Override
public Void visit(AssignmentStatement assignment) { public Void visit(AssignmentStatement assignment) {
graph.addNode(assignment); ControlFlowNode assignmentNode = new ControlFlowNode(assignment);
lastNode = assignment; graph.addNode(assignmentNode);
System.out.println("\n" + assignmentNode + "\n");
lastNode = assignmentNode;
return null; return null;
} }
@Override @Override
public Void visit(Statements statements) { public Void visit(Statements statements) {
ASTNode curLastNode = lastNode; ControlFlowNode curLastNode = lastNode;
for (Statement stmnt : statements) { for (Statement stmnt : statements) {
stmnt.accept(this); stmnt.accept(this);
graph.putEdgeValue(curLastNode, lastNode, EdgeTypes.STEP_OVER); graph.putEdgeValue(curLastNode, lastNode, EdgeTypes.STEP_OVER);
...@@ -66,26 +74,24 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -66,26 +74,24 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> {
return null; return null;
} }
//stack wenn atomic false
@Override @Override
public Void visit(CallStatement call) { public Void visit(CallStatement call) {
ASTNode currentNode = call; ControlFlowNode currentNode = new ControlFlowNode(call);
if (!context.isEmpty()) {
currentNode.setCallCtx(context);
}
graph.addNode(currentNode); graph.addNode(currentNode);
System.out.println("\n" + currentNode + "\n");
graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER); graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER);
graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK); graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK);
lastNode = currentNode; lastNode = currentNode;
boolean atomic = functionLookup.isAtomic(call); boolean atomic = functionLookup.isAtomic(call);
//Annahme: wenn ich zwischendrin keine return kante habe, dann wird solange durchgegangen, bis eine return kante da ist //Annahme: wenn ich zwischendrin keine return kante habe, dann wird solange durchgegangen, bis eine return kante da ist
if (atomic) { if (atomic) {
context.add(call);
// graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_RETURN); // graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_RETURN);
ProofScriptHandler psh = (ProofScriptHandler) functionLookup.getBuilder(call); ProofScriptHandler psh = (ProofScriptHandler) functionLookup.getBuilder(call);
psh.getScript(call.getCommand()).getBody().accept(this); psh.getScript(call.getCommand()).getBody().accept(this);
...@@ -93,7 +99,7 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -93,7 +99,7 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> {
graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_RETURN); graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_RETURN);
graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_INTO); graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_INTO);
} }
context.remove(call);
lastNode = currentNode; lastNode = currentNode;
return null; return null;
...@@ -101,8 +107,9 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -101,8 +107,9 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> {
@Override @Override
public Void visit(ForeachStatement foreach) { public Void visit(ForeachStatement foreach) {
ASTNode currentNode = foreach; ControlFlowNode currentNode = new ControlFlowNode(foreach);
graph.addNode(currentNode); graph.addNode(currentNode);
System.out.println("\n" + currentNode + "\n");
graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER); graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER);
graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK); graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK);
lastNode = currentNode; lastNode = currentNode;
...@@ -114,8 +121,9 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -114,8 +121,9 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> {
@Override @Override
public Void visit(TheOnlyStatement theOnly) { public Void visit(TheOnlyStatement theOnly) {
ASTNode currentNode = theOnly; ControlFlowNode currentNode = new ControlFlowNode(theOnly);
graph.addNode(currentNode); graph.addNode(currentNode);
System.out.println("\n" + currentNode + "\n");
graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER); graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER);
graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK); graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK);
lastNode = currentNode; lastNode = currentNode;
...@@ -128,8 +136,9 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -128,8 +136,9 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> {
@Override @Override
public Void visit(RepeatStatement repeatStatement) { public Void visit(RepeatStatement repeatStatement) {
ASTNode currentNode = repeatStatement; ControlFlowNode currentNode = new ControlFlowNode(repeatStatement);
graph.addNode(currentNode); graph.addNode(currentNode);
System.out.println("\n" + currentNode + "\n");
graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER); graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER);
graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK); graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK);
lastNode = currentNode; lastNode = currentNode;
...@@ -141,14 +150,16 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -141,14 +150,16 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> {
@Override @Override
public Void visit(CasesStatement casesStatement) { public Void visit(CasesStatement casesStatement) {
ASTNode currentNode = casesStatement; ControlFlowNode currentNode = new ControlFlowNode(casesStatement);
graph.addNode(currentNode); graph.addNode(currentNode);
System.out.println("\n" + currentNode + "\n");
graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER); graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER);
graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK); graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK);
List<CaseStatement> cases = casesStatement.getCases(); List<CaseStatement> cases = casesStatement.getCases();
for (CaseStatement aCase : cases) { for (CaseStatement aCase : cases) {
ASTNode caseNode = aCase; ControlFlowNode caseNode = new ControlFlowNode(aCase);
graph.addNode(caseNode); graph.addNode(caseNode);
System.out.println("\n" + caseNode + "\n");
graph.putEdgeValue(currentNode, caseNode, EdgeTypes.STEP_OVER); //??is this right? graph.putEdgeValue(currentNode, caseNode, EdgeTypes.STEP_OVER); //??is this right?
graph.putEdgeValue(caseNode, currentNode, EdgeTypes.STEP_BACK); graph.putEdgeValue(caseNode, currentNode, EdgeTypes.STEP_BACK);
lastNode = caseNode; lastNode = caseNode;
...@@ -167,9 +178,9 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -167,9 +178,9 @@ public class ProgramFlowVisitor extends DefaultASTVisitor<Void> {
graph.nodes().forEach(n -> { graph.nodes().forEach(n -> {
sb.append(n.hashCode()) sb.append(n.hashCode())
.append(" [label=\"") .append(" [label=\"")
.append(n.getNodeName()) .append(n.getScriptstmt().getNodeName())
.append("@") .append("@")
.append(n.getStartPosition().getLineNumber()) .append(n.getScriptstmt().getStartPosition().getLineNumber())
.append("\"]\n"); .append("\"]\n");
}); });
......
...@@ -2,6 +2,7 @@ package edu.kit.formal.interpreter; ...@@ -2,6 +2,7 @@ package edu.kit.formal.interpreter;
import com.google.common.graph.MutableValueGraph; import com.google.common.graph.MutableValueGraph;
import edu.kit.formal.interpreter.data.KeyData; import edu.kit.formal.interpreter.data.KeyData;
import edu.kit.formal.proofscriptparser.Visitor;
import edu.kit.formal.proofscriptparser.ast.ASTNode; import edu.kit.formal.proofscriptparser.ast.ASTNode;
import edu.kit.formal.proofscriptparser.ast.ProofScript; import edu.kit.formal.proofscriptparser.ast.ProofScript;
...@@ -11,12 +12,15 @@ import edu.kit.formal.proofscriptparser.ast.ProofScript; ...@@ -11,12 +12,15 @@ import edu.kit.formal.proofscriptparser.ast.ProofScript;
* @author S. Grebing * @author S. Grebing
*/ */
public class ProofTreeController { public class ProofTreeController {
//TODO Listener auf den Interperter
StateGraphVisitor stateGraphVisitor; /**
* Visitor to retrieve state graph
*/
private StateGraphVisitor stateGraphVisitor;
/** /**
* ControlFlowGraph to lookup edges * ControlFlowGraph to lookup edges
*/ */
private MutableValueGraph<ASTNode, EdgeTypes> controlFlowGraph; private MutableValueGraph<ControlFlowNode, EdgeTypes> controlFlowGraph;
/** /**
* Graph that is computed on the fly in order to allow stepping * Graph that is computed on the fly in order to allow stepping
*/ */
...@@ -30,13 +34,14 @@ public class ProofTreeController { ...@@ -30,13 +34,14 @@ public class ProofTreeController {
*/ */
private PTreeNode statePointer; private PTreeNode statePointer;
public ProofTreeController(Interpreter<KeyData> inter, ProofScript mainScript, StateGraphVisitor stateGraphVisitor) { public ProofTreeController(Interpreter<KeyData> inter, ProofScript mainScript) {
this.currentInterpreter = inter; this.currentInterpreter = inter;
buildControlFlowGraph(mainScript); buildControlFlowGraph(mainScript);
this.stateGraphVisitor = new StateGraphVisitor(inter, mainScript, this.controlFlowGraph);
stateGraph = stateGraphVisitor.getStateGraph(); stateGraph = stateGraphVisitor.getStateGraph();
statePointer = stateGraphVisitor.getRootNode(); statePointer = stateGraphVisitor.getRootNode();
this.stateGraphVisitor = stateGraphVisitor;
// System.out.println(stateGraph.nodes()); // System.out.println(stateGraph.nodes());
//initializeStateGraph(mainScript); //initializeStateGraph(mainScript);
...@@ -50,44 +55,29 @@ public class ProofTreeController { ...@@ -50,44 +55,29 @@ public class ProofTreeController {
*/ */
private void buildControlFlowGraph(ProofScript mainScript) { private void buildControlFlowGraph(ProofScript mainScript) {
ProgramFlowVisitor visitor = new ProgramFlowVisitor(currentInterpreter.getFunctionLookup()); ProgramFlowVisitor visitor = new ProgramFlowVisitor(currentInterpreter.getFunctionLookup());
mainScript.accept(visitor); mainScript.accept(visitor);
this.controlFlowGraph = visitor.getGraph(); this.controlFlowGraph = visitor.getGraph();
// System.out.println(visitor.asdot()); System.out.println(visitor.asdot());
} }
/* private void initializeStateGraph(ProofScript mainScript){
stateGraph = ValueGraphBuilder.directed().build();
State<KeyData> initState = currentInterpreter.getCurrentState();
System.out.println(initState);
PTreeNode initNode = new PTreeNode(mainScript);
initNode.setState(initState);
stateGraph.addNode(initNode);
// statePointer = initNode;
}*/
public PTreeNode stepOver() { public PTreeNode stepOver() {
if (statePointer == null) {
this.statePointer = stateGraphVisitor.getLastNode();
}
PTreeNode current = statePointer; PTreeNode current = statePointer;
ASTNode stmt = current.getScriptstmt(); ASTNode stmt = current.getScriptstmt();
System.out.println("CurrentPointer: " + stmt.getNodeName() + "@" + stmt.getStartPosition());
if (controlFlowGraph.asGraph().nodes().contains(stmt)) { if (controlFlowGraph.asGraph().nodes().contains(stmt)) {
// System.out.println("\n\nAdjacent:{\n"+controlFlowGraph.asGraph().adjacentNodes(stmt)+"}\n\n\n"); // Object[] nodeArray = controlFlowGraph.asGraph().adjacentNodes(stmt).toArray();
Object[] nodeArray = controlFlowGraph.asGraph().adjacentNodes(stmt).toArray(); // ControlFlowNode firtSucc = (ControlFlowNode) nodeArray[0];
ASTNode firtSucc = (ASTNode) nodeArray[0]; // for (PTreeNode succ : stateGraph.successors(current)) {
for (PTreeNode succ : stateGraph.successors(current)) { // if (succ.getScriptstmt().equals(firtSucc)) {
if (succ.getScriptstmt().equals(firtSucc)) { // statePointer = succ;
statePointer = succ; // }
} // }
}
} }
//System.out.println(stateGraphVisitor.asdot()); //System.out.println(stateGraphVisitor.asdot());
return null; return null;
} }
...@@ -104,4 +94,7 @@ public class ProofTreeController { ...@@ -104,4 +94,7 @@ public class ProofTreeController {
} }
public Visitor getStateVisitor() {
return this.stateGraphVisitor;
}
} }
...@@ -3,11 +3,9 @@ package edu.kit.formal.interpreter; ...@@ -3,11 +3,9 @@ package edu.kit.formal.interpreter;
import com.google.common.graph.MutableValueGraph; import com.google.common.graph.MutableValueGraph;
import com.google.common.graph.ValueGraphBuilder; import com.google.common.graph.ValueGraphBuilder;
import edu.kit.formal.interpreter.data.KeyData;
import edu.kit.formal.interpreter.data.State;
import edu.kit.formal.proofscriptparser.DefaultASTVisitor; import edu.kit.formal.proofscriptparser.DefaultASTVisitor;
import edu.kit.formal.proofscriptparser.ast.ASTNode; import edu.kit.formal.proofscriptparser.ast.*;
import edu.kit.formal.proofscriptparser.ast.ProofScript;
/** /**
* Created by sarah on 6/26/17. * Created by sarah on 6/26/17.
...@@ -18,21 +16,22 @@ public class StateGraphVisitor extends DefaultASTVisitor<Void> { ...@@ -18,21 +16,22 @@ public class StateGraphVisitor extends DefaultASTVisitor<Void> {
* Graph that is computed on the fly in order to allow stepping * Graph that is computed on the fly in order to allow stepping
*/ */
private MutableValueGraph<PTreeNode, EdgeTypes> stateGraph; private MutableValueGraph<PTreeNode, EdgeTypes> stateGraph;
private PTreeNode root; private PTreeNode root;
private PTreeNode lastNode; private PTreeNode lastNode;
public StateGraphVisitor(Interpreter inter, ProofScript mainScript) { /**
* Control Flow Graph
*/
private MutableValueGraph<ControlFlowNode, EdgeTypes> graph;
public StateGraphVisitor(Interpreter inter, ProofScript mainScript, MutableValueGraph<ControlFlowNode, EdgeTypes> cfg) {
stateGraph = ValueGraphBuilder.directed().build(); stateGraph = ValueGraphBuilder.directed().build();
this.currentInterpreter = inter; this.currentInterpreter = inter;
State<KeyData> initState = currentInterpreter.getCurrentState(); graph = cfg;
System.out.println(initState); System.out.println(cfg.nodes().stream().toString());
PTreeNode initNode = new PTreeNode(mainScript);
initNode.setState(initState);
stateGraph.addNode(initNode);
root = initNode;