Commit 7d9770fc authored by Sarah Grebing's avatar Sarah Grebing

Implementation of default case in stategraph

parent 6dbfa6c1
Pipeline #13338 failed with stage
in 2 minutes and 58 seconds
...@@ -18,15 +18,24 @@ import java.util.Map; ...@@ -18,15 +18,24 @@ import java.util.Map;
/** /**
* Logger for Interpreting a try case. If the case was successful, * Logger for Interpreting a try case. If the case was successful,
* the logged Events can be replayed by the parent interpreter listeners * the logged Events can be replayed back to the parent interpreter listeners
*/ */
public class TryCaseHistoryLogger extends HistoryListener { public class TryCaseHistoryLogger extends HistoryListener {
private Interpreter currentInterpreter; private Interpreter currentInterpreter;
private EntryListener entryListener = new EntryListener(); private EntryListener entryListener = new EntryListener();
;
private ExitListener exitListener = new ExitListener(); private ExitListener exitListener = new ExitListener();
/**
* Mapping of ASTNodes and their entry and exit states
*/
private Map<ASTNode, EntryExitPair> mapOfNodesAndStates = new HashMap<>(); private Map<ASTNode, EntryExitPair> mapOfNodesAndStates = new HashMap<>();
/**
* List containing of pairs which contain an ASTNode and whether it was visited by entry or exit
*/
private List<Pair<EntryName, ASTNode>> sequenceOfEvents = new LinkedList<>(); private List<Pair<EntryName, ASTNode>> sequenceOfEvents = new LinkedList<>();
public TryCaseHistoryLogger(Interpreter interpreter) { public TryCaseHistoryLogger(Interpreter interpreter) {
...@@ -57,12 +66,25 @@ public class TryCaseHistoryLogger extends HistoryListener { ...@@ -57,12 +66,25 @@ public class TryCaseHistoryLogger extends HistoryListener {
} }
} }
/**
* Create a new entry in maps. This is done when entering a node
*
* @param node
* @param state
* @return
*/
private Void createNewEntry(ASTNode node, State state) { private Void createNewEntry(ASTNode node, State state) {
this.sequenceOfEvents.add(new Pair<>(EntryName.ENTRY, node)); this.sequenceOfEvents.add(new Pair<>(EntryName.ENTRY, node));
this.mapOfNodesAndStates.put(node, new EntryExitPair(state)); this.mapOfNodesAndStates.put(node, new EntryExitPair(state));
return null; return null;
} }
/**
* Update the antrx after exiting the node
* @param node
* @param state
* @return
*/
private Void updateEntry(ASTNode node, State state) { private Void updateEntry(ASTNode node, State state) {
this.sequenceOfEvents.add(new Pair<>(EntryName.EXIT, node)); this.sequenceOfEvents.add(new Pair<>(EntryName.EXIT, node));
this.mapOfNodesAndStates.get(node).setExitState(state); this.mapOfNodesAndStates.get(node).setExitState(state);
......
...@@ -729,7 +729,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -729,7 +729,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
//endregion //endregion
/** /**
* Start a new context where already registered listsners are not informed * Start a new context where already registered listeners are not informed
*/ */
protected void startSideComputation() { protected void startSideComputation() {
entryListenerStack.push(new ArrayList<>()); entryListenerStack.push(new ArrayList<>());
......
...@@ -74,7 +74,6 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -74,7 +74,6 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
context.add(proofScript); context.add(proofScript);
mappingOfNodes.put(proofScript, scriptNode); mappingOfNodes.put(proofScript, scriptNode);
graph.addNode(scriptNode); graph.addNode(scriptNode);
//System.out.println("\n" + scriptNode + "\n");
lastNode = scriptNode; lastNode = scriptNode;
return this.visit(proofScript.getBody()); return this.visit(proofScript.getBody());
...@@ -86,7 +85,6 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -86,7 +85,6 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
ControlFlowNode assignmentNode = new ControlFlowNode(assignment); ControlFlowNode assignmentNode = new ControlFlowNode(assignment);
mappingOfNodes.put(assignment, assignmentNode); mappingOfNodes.put(assignment, assignmentNode);
graph.addNode(assignmentNode); graph.addNode(assignmentNode);
//System.out.println("\n" + assignmentNode + "\n");
lastNode = assignmentNode; lastNode = assignmentNode;
return null; return null;
} }
...@@ -120,8 +118,6 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -120,8 +118,6 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
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) {
LinkedList<ASTNode> copiedContext = new LinkedList<>(); LinkedList<ASTNode> copiedContext = new LinkedList<>();
//to check whether context is restored properly, copy context before call //to check whether context is restored properly, copy context before call
...@@ -184,7 +180,6 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -184,7 +180,6 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
ControlFlowNode currentNode = new ControlFlowNode(repeatStatement); ControlFlowNode currentNode = new ControlFlowNode(repeatStatement);
mappingOfNodes.put(repeatStatement, currentNode); mappingOfNodes.put(repeatStatement, currentNode);
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;
...@@ -205,9 +200,9 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -205,9 +200,9 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
List<CaseStatement> cases = casesStatement.getCases(); List<CaseStatement> cases = casesStatement.getCases();
for (CaseStatement aCase : cases) { for (CaseStatement aCase : cases) {
if (aCase.isClosedStmt) { // if (aCase.isClosedStmt) {
System.out.println("Handle sondercases");
} else { // } else {
ControlFlowNode caseNode = new ControlFlowNode(aCase); ControlFlowNode caseNode = new ControlFlowNode(aCase);
mappingOfNodes.put(aCase, caseNode); mappingOfNodes.put(aCase, caseNode);
graph.addNode(caseNode); graph.addNode(caseNode);
...@@ -217,7 +212,20 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -217,7 +212,20 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
lastNode = caseNode; lastNode = caseNode;
aCase.getBody().accept(this); aCase.getBody().accept(this);
graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_RETURN); graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_RETURN);
} // }
}
if (casesStatement.getDefaultCase() != null) {
Statements defaultCase = casesStatement.getDefaultCase();
ControlFlowNode caseNode = new ControlFlowNode(defaultCase);
mappingOfNodes.put(defaultCase, caseNode);
graph.addNode(caseNode);
//System.out.println("\n" + caseNode + "\n");
graph.putEdgeValue(currentNode, caseNode, EdgeTypes.STEP_OVER); //??is this right?
graph.putEdgeValue(caseNode, currentNode, EdgeTypes.STEP_BACK);
lastNode = caseNode;
defaultCase.accept(this);
graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_RETURN);
} }
lastNode = currentNode; lastNode = currentNode;
return null; return null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment