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;
/**
* 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 {
private Interpreter currentInterpreter;
private EntryListener entryListener = new EntryListener();
;
private ExitListener exitListener = new ExitListener();
/**
* Mapping of ASTNodes and their entry and exit states
*/
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<>();
public TryCaseHistoryLogger(Interpreter interpreter) {
......@@ -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) {
this.sequenceOfEvents.add(new Pair<>(EntryName.ENTRY, node));
this.mapOfNodesAndStates.put(node, new EntryExitPair(state));
return null;
}
/**
* Update the antrx after exiting the node
* @param node
* @param state
* @return
*/
private Void updateEntry(ASTNode node, State state) {
this.sequenceOfEvents.add(new Pair<>(EntryName.EXIT, node));
this.mapOfNodesAndStates.get(node).setExitState(state);
......
......@@ -729,7 +729,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
//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() {
entryListenerStack.push(new ArrayList<>());
......
......@@ -74,7 +74,6 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
context.add(proofScript);
mappingOfNodes.put(proofScript, scriptNode);
graph.addNode(scriptNode);
//System.out.println("\n" + scriptNode + "\n");
lastNode = scriptNode;
return this.visit(proofScript.getBody());
......@@ -86,7 +85,6 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
ControlFlowNode assignmentNode = new ControlFlowNode(assignment);
mappingOfNodes.put(assignment, assignmentNode);
graph.addNode(assignmentNode);
//System.out.println("\n" + assignmentNode + "\n");
lastNode = assignmentNode;
return null;
}
......@@ -120,8 +118,6 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
boolean atomic = functionLookup.isAtomic(call);
//Annahme: wenn ich zwischendrin keine return kante habe, dann wird solange durchgegangen, bis eine return kante da ist
if (atomic) {
LinkedList<ASTNode> copiedContext = new LinkedList<>();
//to check whether context is restored properly, copy context before call
......@@ -184,7 +180,6 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
ControlFlowNode currentNode = new ControlFlowNode(repeatStatement);
mappingOfNodes.put(repeatStatement, currentNode);
graph.addNode(currentNode);
// System.out.println("\n" + currentNode + "\n");
graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER);
graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK);
lastNode = currentNode;
......@@ -205,9 +200,9 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
List<CaseStatement> cases = casesStatement.getCases();
for (CaseStatement aCase : cases) {
if (aCase.isClosedStmt) {
System.out.println("Handle sondercases");
} else {
// if (aCase.isClosedStmt) {
// } else {
ControlFlowNode caseNode = new ControlFlowNode(aCase);
mappingOfNodes.put(aCase, caseNode);
graph.addNode(caseNode);
......@@ -217,7 +212,20 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
lastNode = caseNode;
aCase.getBody().accept(this);
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;
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