Commit 3953a34c authored by Sarah Grebing's avatar Sarah Grebing

deep copy of assignments bug

parent 74bb5b37
Pipeline #10620 passed with stage
in 2 minutes and 9 seconds
......@@ -2,6 +2,11 @@ package edu.kit.formal.TestCommands;
import edu.kit.formal.interpreter.GoalNode;
import edu.kit.formal.interpreter.State;
import edu.kit.formal.interpreter.Value;
import edu.kit.formal.interpreter.VariableAssignment;
import edu.kit.formal.proofscriptparser.ast.Type;
import java.math.BigInteger;
/**
* Created by sarah on 5/17/17.
......@@ -10,12 +15,16 @@ public class SplitCommand extends AbstractCommand {
@Override
public State execute(State s) {
GoalNode g = s.getSelectedGoalNode();
VariableAssignment assignments = g.getAssignments();
String seq1 = g.getSequent().concat("1");
String seq2 = g.getSequent().concat("2");
s.getGoals().remove(g);
s.getGoals().add(new GoalNode(g, seq1));
s.getGoals().add(new GoalNode(g, seq2));
GoalNode g2 = new GoalNode(g, seq2);
g2.setVarValue("z", new Value(Type.INT, BigInteger.valueOf(10)));
s.getGoals().add(g2);
return s;
}
}
......@@ -19,11 +19,16 @@ public class GoalNode {
private GoalNode parent;
public GoalNode(GoalNode parent, String seq) {
this.assignments = new VariableAssignment(parent == null ? null : parent.assignments);
//BUG: Hier muesste deepcopy der assignments passieren
this.assignments = new VariableAssignment(parent == null ? null : parent.deepCopyAssignments());
this.parent = parent;
this.sequent = seq;
}
private VariableAssignment deepCopyAssignments() {
return assignments.deepCopy();
}
public VariableAssignment getAssignments() {
return assignments;
}
......
......@@ -162,8 +162,6 @@ public class Interpreter<T> extends DefaultASTVisitor<T> {
Value eval = goalEval.eval(guard);
System.out.println();
if (eval.getData().equals(true)) {
// if (eval.getData().equals(Value.TRUE)) {
forCase.add(g);
}
}
......
......@@ -22,6 +22,7 @@ public class VariableAssignment {
this.parent = parent;
}
public VariableAssignment() {
this(null);
}
......@@ -118,4 +119,15 @@ public class VariableAssignment {
", types=" + types +
'}';
}
public VariableAssignment deepCopy() {
HashMap<String, Type> typeMapCopy = new HashMap<>();
types.forEach((k, v) -> typeMapCopy.put(k, v));
HashMap<String, Value> valueMap = new HashMap<>();
values.forEach((k, v) -> valueMap.put(k, v));
VariableAssignment copy = new VariableAssignment(parent == null ? null : parent.deepCopy());
copy.values = valueMap;
copy.types = typeMapCopy;
return copy;
}
}
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