Commit 22c5c2ac authored by Sarah Grebing's avatar Sarah Grebing

Big Bugfix

parent 6019bbae
Pipeline #14592 failed with stage
in 2 minutes and 52 seconds
......@@ -100,9 +100,10 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
*/
@Override
public Object visit(ProofScript proofScript) {
enterScope(proofScript);
//add vars
visit(proofScript.getSignature());
enterScope(proofScript);
proofScript.getBody().accept(this);
exitScope(proofScript);
return null;
......@@ -519,6 +520,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
@Override
public Object visit(CallStatement call) {
enterScope(call);
// System.out.println(stateStack.peek().hashCode());
//neuer VarScope
//enter new variable scope
VariableAssignment params = evaluateParameters(call.getParameters());
......@@ -535,6 +537,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
//pushState(newErrorState);
}
g.exitScope();
// System.out.println(stateStack.peek().hashCode());
exitScope(call);
return null;
}
......@@ -614,11 +617,11 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
@Override
public Object visit(Signature signature) {
exitScope(signature);
// enterScope(signature);
GoalNode<T> node = getSelectedNode();
node.enterScope();
signature.forEach(node::declareVariable);
enterScope(signature);
// exitScope(signature);
return null;
}
......
......@@ -112,4 +112,6 @@ public class GoalNode<T> {
assignments = assignments.push(va);
return assignments;
}
}
package edu.kit.iti.formal.psdbg.interpreter.data;
import edu.kit.iti.formal.psdbg.parser.ast.ASTNode;
import edu.kit.iti.formal.psdbg.parser.ast.CaseStatement;
import lombok.Data;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RequiredArgsConstructor
@Data
public class InterpreterExtendedState<T> {
public class InterpreterExtendedState<T> extends State<T> {
@Getter
@Setter
private Map<CaseStatement, List<GoalNode<T>>> mappingOfCaseToStates = new HashMap<>();
public InterpreterExtendedState(Collection<GoalNode<T>> goals, GoalNode selected) {
super(goals, selected);
}
/**
* State before the statement;
*/
@Getter
@Setter
private State<T> stateBeforeStmt;
/**
* State after execution of statement
*/
@Getter
@Setter
private State<T> stateAfterStmt;
/**
* Statement
*/
@Getter
@Setter
private ASTNode stmt;
/**
* Null if root
*/
@Getter
@Setter
private InterpreterExtendedState<T> predecessor;
public InterpreterExtendedState(Collection<GoalNode<T>> goals, GoalNode selected, Map<CaseStatement, List<GoalNode<T>>> casesMapping) {
super(goals, selected);
this.mappingOfCaseToStates = casesMapping;
}
public Map<CaseStatement, List<GoalNode<T>>> getMappingOfCaseToStates() {
return mappingOfCaseToStates;
public InterpreterExtendedState(InterpreterExtendedState<T> pred) {
if (pred == null) {
this.predecessor = null;
} else {
this.predecessor = pred;
}
}
public void setMappingOfCaseToStates(Map<CaseStatement, List<GoalNode<T>>> mappingOfCaseToStates) {
this.mappingOfCaseToStates = mappingOfCaseToStates;
public InterpreterExtendedState copy() {
InterpreterExtendedState ext = new InterpreterExtendedState();
if (this.predecessor != null) {
ext.setPredecessor(this.predecessor.copy());
} else {
ext.predecessor = null;
}
ext.setStmt(stmt.copy());
if (stateAfterStmt != null) {
ext.setStateAfterStmt(this.stateAfterStmt.copy());
} else {
ext.setStateAfterStmt(null);
}
if (stateBeforeStmt != null) {
ext.setStateBeforeStmt(this.stateBeforeStmt.copy());
} else {
ext.setStateBeforeStmt(null);
}
return ext;
}
/*
public List<GoalNode<T>> getClosedNodes() {
return super.getGoals().stream().filter(nodes -> nodes.isClosed()).collect(Collectors.toList());
}
public List<GoalNode<T>> getopenNodes() {
public List<GoalNode<T>> getOpenNodes() {
return super.getGoals().stream().filter(nodes -> !nodes.isClosed()).collect(Collectors.toList());
}
}*/
public List<GoalNode<T>> getActiveGoalsForCase(CaseStatement caseStmt) {
return mappingOfCaseToStates.getOrDefault(caseStmt, Collections.emptyList());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("\n%%%%%%%%%%%%%%%%%%%%%\nExtended State ");
if (getStmt() != null) {
sb.append(getStmt().getNodeName() + ": \n");
}
sb.append("State before Statement: \n");
if (stateBeforeStmt != null) {
stateBeforeStmt.getGoals().stream().map(tGoalNode -> tGoalNode.getData()).forEach(sb::append);
} else {
sb.append("Before is Empty");
}
sb.append("\nAfter Statement:\n");
if (stateAfterStmt != null) {
stateAfterStmt.getGoals().stream().map(tGoalNode -> tGoalNode.getData()).forEach(sb::append);
} else {
sb.append("After is empty");
}
sb.append("\n%%%%%%%%%%%%%%%%%%%%\n");
return sb.toString();
// this.stateBeforeStmt.toString()+"\n"+this.stateAfterStmt.toString();
}
//getuserSelected/
//verfuegbar im case
//map<case, listgoal>
......
......@@ -10,4 +10,5 @@ public interface GraphChangedListener {
abstract void graphChanged(NodeAddedEvent nodeAddedEvent);
}
......@@ -3,7 +3,6 @@ package edu.kit.iti.formal.psdbg.interpreter.graphs;
import edu.kit.iti.formal.psdbg.interpreter.data.InterpreterExtendedState;
import edu.kit.iti.formal.psdbg.interpreter.data.State;
import edu.kit.iti.formal.psdbg.parser.ast.ASTNode;
import edu.kit.iti.formal.psdbg.parser.ast.CaseStatement;
import java.util.LinkedList;
......@@ -66,11 +65,8 @@ public class PTreeNode<T> {
return extendedState;
}
public void setExtendedState(State<T> state) {
this.extendedState = new InterpreterExtendedState<>(state.getGoals(), state.getSelectedGoalNode());
if (getScriptstmt() instanceof CaseStatement) {
}
public void setExtendedState(InterpreterExtendedState<T> extendedState) {
this.extendedState = extendedState;
}
public String toString() {
......@@ -95,6 +91,7 @@ public class PTreeNode<T> {
}
public String extendedStateToString() {
return this.extendedState.toString();
}
}
......@@ -658,7 +658,7 @@ public class DebuggerMain implements Initializable {
/**
* Perform a step back
*TODO Uebergabe des selctirkten Knotens damit richtiges ausgewählt
*TODO Uebergabe des selctierten Knotens damit richtiges ausgewählt
* @param actionEvent
*/
public void stepBack(ActionEvent actionEvent) {
......
......@@ -61,7 +61,7 @@ public class ProofTreeController {
private ReadOnlyBooleanProperty executeNotPossible = interpreterService.runningProperty();
/**
* Node that is updated whenever a new node is added to the stategraph (this can only happen in debug mode when stepover is invoked)
* Node that is updated whenever a new node is added to the stategraph
*/
private SimpleObjectProperty<PTreeNode> nextComputedNode = new SimpleObjectProperty<>();
......@@ -96,6 +96,7 @@ public class ProofTreeController {
* The mainscipt that is executed
*/
private SimpleObjectProperty<ProofScript> mainScript = new SimpleObjectProperty<>();
/**
* Add a change listener for the stategraph, whenever a new node is added it receives an event
*/
......@@ -199,11 +200,11 @@ public class ProofTreeController {
//ask for root
currentPointer = stateGraphWrapper.rootProperty().get();
statePointer = currentPointer;
}
//get next node
PTreeNode nextNode = stateGraphWrapper.getStepOver(currentPointer);
//if nextnode is null ask interpreter to execute next statement and compute next state
if (nextNode != null) {
State<KeyData> lastState = this.statePointer.getState();
this.statePointer = nextNode;
......@@ -219,6 +220,7 @@ public class ProofTreeController {
//let interpreter run for one step and let listener handle updating the statepointer
blocker.getStepUntilBlock().addAndGet(1);
blocker.unlock();
}
return statePointer;
}
......@@ -308,6 +310,7 @@ public class ProofTreeController {
statusBar.setText("Executed until end of script.");
//TODO is this the right position??
if (currentGoals.isEmpty()) {
Utils.showClosedProofDialog(mainScript.get().getName());
}
statusBar.stopProgress();
......
// Please select one of the following scripts.
//
script test2(){
script test23(){
impRight;
impLeft;
cases{
case match `q==> `:
impRight;
default:
case match `==>`:
impRight;
notRight;
}
......@@ -18,6 +16,7 @@ script test(){
script test1(){
impRight;
impRight;
}
script test2(){
impRight;
......
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