Commit 74bb5b37 authored by Sarah Grebing's avatar Sarah Grebing
Browse files

fixed own introduced bug

parent c6f8d090
Pipeline #10613 passed with stage
in 1 minute and 59 seconds
...@@ -146,24 +146,30 @@ public class Interpreter<T> extends DefaultASTVisitor<T> { ...@@ -146,24 +146,30 @@ public class Interpreter<T> extends DefaultASTVisitor<T> {
List<CaseStatement> cases = casesStatement.getCases(); List<CaseStatement> cases = casesStatement.getCases();
Iterator<CaseStatement> casesIter = cases.iterator(); Iterator<CaseStatement> casesIter = cases.iterator();
while (casesIter.hasNext()) { while (casesIter.hasNext()) {
//get information for case
CaseStatement currentCase = casesIter.next(); CaseStatement currentCase = casesIter.next();
Expression guard = currentCase.getGuard(); Expression guard = currentCase.getGuard();
Statements body = currentCase.getBody(); Statements body = currentCase.getBody();
Iterator<GoalNode> goalIter = copiedList.iterator(); Iterator<GoalNode> goalIter = copiedList.iterator();
Set<GoalNode> forCase = new HashSet<>(); Set<GoalNode> forCase = new HashSet<>();
//iterate over all available goals and select those that evaluate to true with the guard
//assumption, matchpattern handles varAssignments
while (goalIter.hasNext()) { while (goalIter.hasNext()) {
GoalNode g = goalIter.next(); GoalNode g = goalIter.next();
Evaluator goalEval = new Evaluator(g); Evaluator goalEval = new Evaluator(g);
Value eval = goalEval.eval(guard); Value eval = goalEval.eval(guard);
if (eval.getData().equals(Value.TRUE)) { System.out.println();
if (eval.getData().equals(true)) {
// if (eval.getData().equals(Value.TRUE)) {
forCase.add(g); forCase.add(g);
//copiedList.remove(g);
} }
} }
copiedList.removeAll(forCase); copiedList.removeAll(forCase);
//for each selected goal put a state onto tze stack and visit the body of the case
Iterator<GoalNode> caseGoals = forCase.iterator(); Iterator<GoalNode> caseGoals = forCase.iterator();
while (caseGoals.hasNext()) { while (caseGoals.hasNext()) {
GoalNode current = caseGoals.next(); GoalNode current = caseGoals.next();
...@@ -172,16 +178,19 @@ public class Interpreter<T> extends DefaultASTVisitor<T> { ...@@ -172,16 +178,19 @@ public class Interpreter<T> extends DefaultASTVisitor<T> {
State s = new State(goalList, current); State s = new State(goalList, current);
stateStack.push(s); stateStack.push(s);
visit(body); visit(body);
//after executing the body collect the newly created goals form the stack and remove the state
State aftercase = (State) stateStack.pop(); State aftercase = (State) stateStack.pop();
goalsAfterCases.addAll(aftercase.getGoals()); goalsAfterCases.addAll(aftercase.getGoals());
} }
//jetzt body auswerten mit der Liste der Ziele
} }
casesStatement.getDefaultCase(); //for all remaining goals execute default
if (!copiedList.isEmpty()) {
Statements defaultCase = casesStatement.getDefaultCase();
}
//exit scope //exit scope and create a new state using the union of all newly created goals
State newStateAfterCases; State newStateAfterCases;
if (!goalsAfterCases.isEmpty()) { if (!goalsAfterCases.isEmpty()) {
......
...@@ -40,11 +40,11 @@ public class Value<T> { ...@@ -40,11 +40,11 @@ public class Value<T> {
} }
public static Value<Boolean> from(BooleanLiteral b) { public static Value<Boolean> from(BooleanLiteral b) {
return new Value(Type.BOOL, (b.isValue() ? Value.TRUE : Value.FALSE)); return new Value(Type.BOOL, b.isValue());
} }
public static Value<Boolean> from(boolean equals) { public static Value<Boolean> from(boolean equals) {
return new Value(Type.BOOL, (equals ? Value.TRUE : Value.FALSE)); return new Value(Type.BOOL, equals);
} }
public static Value<BigInteger> from(BigInteger apply) { public static Value<BigInteger> from(BigInteger apply) {
......
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