Commit a9b4922a authored by Sarah Grebing's avatar Sarah Grebing

Tried to make interpreter independent from keydata

parent b193e370
Pipeline #12697 failed with stage
in 1 minute and 31 seconds
...@@ -33,6 +33,15 @@ public class Execute { ...@@ -33,6 +33,15 @@ public class Execute {
execute.run(); execute.run();
} }
public static Options argparse() {
Options options = new Options();
options.addOption("h", "--help", false, "print help text");
options.addOption("p", "--script-path", true, "include folder for scripts");
options.addOption("l", "--linter", false, "run linter before execute");
options.addOption("s", "--script", true, "script sourceName");
return options;
}
public Interpreter<KeyData> run() { public Interpreter<KeyData> run() {
try { try {
ProofManagementApi pma = KeYApi.loadFromKeyFile(new File(keyFiles.get(0))); ProofManagementApi pma = KeYApi.loadFromKeyFile(new File(keyFiles.get(0)));
...@@ -49,7 +58,7 @@ public class Execute { ...@@ -49,7 +58,7 @@ public class Execute {
Interpreter<KeyData> inter = interpreterBuilder.build(); Interpreter<KeyData> inter = interpreterBuilder.build();
KeyData keyData = new KeyData(root.getProofNode(), pa.getEnv(), pa.getProof()); KeyData keyData = new KeyData(root.getProofNode(), pa.getEnv(), pa.getProof());
inter.newState(new GoalNode<>(null, keyData)); inter.newState(new GoalNode<>(null, keyData, keyData.isClosedNode()));
inter.interpret(ast.get(0)); inter.interpret(ast.get(0));
return inter; return inter;
} catch (ProblemLoaderException | IOException e) { } catch (ProblemLoaderException | IOException e) {
...@@ -67,14 +76,4 @@ public class Execute { ...@@ -67,14 +76,4 @@ public class Execute {
if (cli.getOptionValue('p') != null) if (cli.getOptionValue('p') != null)
interpreterBuilder.scriptSearchPath(new File(cli.getOptionValue('p'))); interpreterBuilder.scriptSearchPath(new File(cli.getOptionValue('p')));
} }
public static Options argparse() {
Options options = new Options();
options.addOption("h", "--help", false, "print help text");
options.addOption("p", "--script-path", true, "include folder for scripts");
options.addOption("l", "--linter", false, "run linter before execute");
options.addOption("s", "--script", true, "script sourceName");
return options;
}
} }
...@@ -198,30 +198,11 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -198,30 +198,11 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
if (va != null) { if (va != null) {
enterScope(simpleCaseStatement); enterScope(simpleCaseStatement);
executeBody(simpleCaseStatement.getBody(), selectedGoal, va); executeBody(simpleCaseStatement.getBody(), selectedGoal, va);
// executeCase(simpleCaseStatement.getBody(), )
exitScope(simpleCaseStatement); exitScope(simpleCaseStatement);
return true; return true;
} else { } else {
return false; return false;
} }
/* Map<GoalNode<T>, VariableAssignment> matchedGoals =
matchGoal(remainingGoalsSet, (SimpleCaseStatement) aCase);
if (matchedGoals != null) {
remainingGoalsSet.removeAll(matchedGoals.keySet());
goalsAfterCases.addAll(executeCase(aCase.getBody(), matchedGoals));
}
HashMap<GoalNode<T>, VariableAssignment> matchedGoals = new HashMap<>();
Expression matchExpression = aCase.getGuard();
for (GoalNode<T> goal : allGoalsBeforeCases) {
VariableAssignment va = evaluateMatchInGoal(matchExpression, goal);
if (va != null) {
matchedGoals.put(goal, va);
}
}
return matchedGoals;
*/
} }
...@@ -265,20 +246,6 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -265,20 +246,6 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
} }
//===========================================================================================//
/* for (CaseStatement aCase : cases) {
if (aCase.isClosedStmt) {
System.out.println("IsClosableStmt not implemented yet");
} else {
Map<GoalNode<T>, VariableAssignment> matchedGoals =
matchGoal(remainingGoalsSet, (SimpleCaseStatement) aCase);
if (matchedGoals != null) {
remainingGoalsSet.removeAll(matchedGoals.keySet());
goalsAfterCases.addAll(executeCase(aCase.getBody(), matchedGoals));
}
}
}*/
//for all remaining goals execute default //for all remaining goals execute default
if (!remainingGoalsSet.isEmpty()) { if (!remainingGoalsSet.isEmpty()) {
...@@ -297,13 +264,9 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -297,13 +264,9 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
State<T> newStateAfterCases; State<T> newStateAfterCases;
if (!goalsAfterCases.isEmpty()) { if (!goalsAfterCases.isEmpty()) {
//goalsAfterCases.forEach(node -> node.exitScope()); //goalsAfterCases.forEach(node -> node.exitScope());
Stream<GoalNode<T>> goalNodeStream = goalsAfterCases.stream().filter(tGoalNode -> !((KeyData) tGoalNode.getData()).getNode().isClosed()); Stream<GoalNode<T>> goalNodeStream = goalsAfterCases.stream().filter(tGoalNode -> !(tGoalNode.isClosed()));
List<GoalNode<T>> openGoalListAfterCases = goalNodeStream.collect(Collectors.toList()); List<GoalNode<T>> openGoalListAfterCases = goalNodeStream.collect(Collectors.toList());
/*if (goalsAfterCases.size() == 1) {
newStateAfterCases = new State<T>(goalsAfterCases, 0);
} else {
// newStateAfterCases = new State<T>(goalsAfterCases, null);
}*/
if (openGoalListAfterCases.size() == 1) { if (openGoalListAfterCases.size() == 1) {
newStateAfterCases = new State<T>(openGoalListAfterCases, 0); newStateAfterCases = new State<T>(openGoalListAfterCases, 0);
} else { } else {
......
...@@ -191,7 +191,7 @@ public class InterpreterBuilder { ...@@ -191,7 +191,7 @@ public class InterpreterBuilder {
final ProofApi pa = new ProofApi(proof, keyEnvironment); final ProofApi pa = new ProofApi(proof, keyEnvironment);
final ProjectedNode root = pa.getFirstOpenGoal(); final ProjectedNode root = pa.getFirstOpenGoal();
final KeyData keyData = new KeyData(root.getProofNode(), pa.getEnv(), pa.getProof()); final KeyData keyData = new KeyData(root.getProofNode(), pa.getEnv(), pa.getProof());
final GoalNode<KeyData> startGoal = new GoalNode<>(null, keyData); final GoalNode<KeyData> startGoal = new GoalNode<>(null, keyData, keyData.isClosedNode());
return startState(startGoal); return startState(startGoal);
} }
......
...@@ -75,7 +75,8 @@ public class KeYMatcher implements MatcherApi<KeyData> { ...@@ -75,7 +75,8 @@ public class KeYMatcher implements MatcherApi<KeyData> {
boolean isDerivable = proof.getSubtreeGoals(toShow.node()).size() == 0; boolean isDerivable = proof.getSubtreeGoals(toShow.node()).size() == 0;
if (isDerivable) { if (isDerivable) {
GoalNode<KeyData> newGoalNode = new GoalNode<KeyData>(kd, new KeyData(kd.getData(), goalList.head())); KeyData kdataNew = new KeyData(kd.getData(), goalList.head());
GoalNode<KeyData> newGoalNode = new GoalNode<KeyData>(kd, kdataNew, kdataNew.isClosedNode());
return newGoalNode; return newGoalNode;
} else { } else {
proof.pruneProof(kd.getData().getNode(), false); proof.pruneProof(kd.getData().getNode(), false);
......
...@@ -153,7 +153,7 @@ public class KeYProofFacade { ...@@ -153,7 +153,7 @@ public class KeYProofFacade {
public Collection<GoalNode<KeyData>> getPseudoGoals() { public Collection<GoalNode<KeyData>> getPseudoGoals() {
KeyData data = new KeyData(proof.get().root(), getEnvironment(), getProof()); KeyData data = new KeyData(proof.get().root(), getEnvironment(), getProof());
return Collections.singleton(new GoalNode<>(null, data)); return Collections.singleton(new GoalNode<>(null, data, data.getNode().isClosed()));
} }
//endregion //endregion
} }
......
...@@ -21,13 +21,16 @@ public class GoalNode<T> { ...@@ -21,13 +21,16 @@ public class GoalNode<T> {
@Getter @Getter
private T data; private T data;
@Getter
private boolean isClosed;
/** /**
* This conctructur will be replaced with concrete one that uses projectedNode * This conctructur will be replaced with concrete one that uses projectedNode
* *
* @param parent * @param parent
* @param data * @param data
*/ */
public GoalNode(GoalNode<T> parent, T data) { public GoalNode(GoalNode<T> parent, T data, boolean isClosed) {
//BUG: Hier muesste deepcopy der assignments passieren //BUG: Hier muesste deepcopy der assignments passieren
this.assignments = new VariableAssignment(parent == null ? null : parent.deepCopyAssignments()); this.assignments = new VariableAssignment(parent == null ? null : parent.deepCopyAssignments());
this.parent = parent; this.parent = parent;
...@@ -105,7 +108,7 @@ public class GoalNode<T> { ...@@ -105,7 +108,7 @@ public class GoalNode<T> {
public GoalNode<T> deepCopy() { public GoalNode<T> deepCopy() {
//TODO method does nothing helpful atm //TODO method does nothing helpful atm
return new GoalNode<T>(parent, data); return new GoalNode<T>(parent, data, isClosed);
} }
public VariableAssignment enterScope(VariableAssignment va) { public VariableAssignment enterScope(VariableAssignment va) {
......
...@@ -34,6 +34,7 @@ public class KeyData { ...@@ -34,6 +34,7 @@ public class KeyData {
programStatementsLabel, programStatementsLabel,
nameLabel; nameLabel;
private Goal goal; private Goal goal;
private boolean closedNode;
public KeyData(KeyData data, Goal node) { public KeyData(KeyData data, Goal node) {
env = data.env; env = data.env;
...@@ -42,6 +43,7 @@ public class KeyData { ...@@ -42,6 +43,7 @@ public class KeyData {
this.proof = data.proof; this.proof = data.proof;
this.goal = node; this.goal = node;
this.node = goal.node(); this.node = goal.node();
closedNode = this.node.isClosed();
} }
...@@ -49,11 +51,13 @@ public class KeyData { ...@@ -49,11 +51,13 @@ public class KeyData {
goal = g; goal = g;
env = environment; env = environment;
this.proof = proof; this.proof = proof;
closedNode = proof.closed();
} }
public KeyData(Node root, KeYEnvironment environment, Proof proof) { public KeyData(Node root, KeYEnvironment environment, Proof proof) {
this(proof.getGoal(root), environment, proof); this(proof.getGoal(root), environment, proof);
node = root; node = root;
closedNode = root.isClosed();
} }
public KeyData(KeyData kd, Node node) { public KeyData(KeyData kd, Node node) {
...@@ -74,7 +78,7 @@ public class KeyData { ...@@ -74,7 +78,7 @@ public class KeyData {
/** /**
* Create Label for goalview according to function that is passed. * Create Label for goalview according to function that is passed.
* The following fucntions can be given: * The following functions can be given:
* <ul> * <ul>
* <li>@see #Method getRuleLabel()</li> * <li>@see #Method getRuleLabel()</li>
* <li>@see #Method getBranchingLabel()</li> * <li>@see #Method getBranchingLabel()</li>
......
...@@ -61,7 +61,7 @@ public abstract class BuiltinCommands { ...@@ -61,7 +61,7 @@ public abstract class BuiltinCommands {
State<String> state = new State<>(s.getGoals(), null); State<String> state = new State<>(s.getGoals(), null);
state.getGoals().remove(s.getSelectedGoalNode()); state.getGoals().remove(s.getSelectedGoalNode());
for (char i = 0; i < num; i++) { for (char i = 0; i < num; i++) {
state.getGoals().add(new GoalNode<>(g, g.getData() + "." + (char) ('a' + i))); state.getGoals().add(new GoalNode<>(g, g.getData() + "." + (char) ('a' + i), g.isClosed()));
} }
interpreter.pushState(state); interpreter.pushState(state);
} }
......
...@@ -60,7 +60,7 @@ public class ProofScriptCommandBuilder implements CommandHandler<KeyData> { ...@@ -60,7 +60,7 @@ public class ProofScriptCommandBuilder implements CommandHandler<KeyData> {
state.getGoals().remove(expandedNode); state.getGoals().remove(expandedNode);
for (Goal g : ngoals) { for (Goal g : ngoals) {
KeyData kdn = new KeyData(kd, g.node()); KeyData kdn = new KeyData(kd, g.node());
state.getGoals().add(new GoalNode<>(expandedNode, kdn)); state.getGoals().add(new GoalNode<>(expandedNode, kdn, kdn.isClosedNode()));
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
......
...@@ -66,7 +66,7 @@ public class RuleCommandHandler implements CommandHandler<KeyData> { ...@@ -66,7 +66,7 @@ public class RuleCommandHandler implements CommandHandler<KeyData> {
state.getGoals().remove(expandedNode); state.getGoals().remove(expandedNode);
for (Goal g : ngoals) { for (Goal g : ngoals) {
KeyData kdn = new KeyData(kd, g.node()); KeyData kdn = new KeyData(kd, g.node());
state.getGoals().add(new GoalNode<>(expandedNode, kdn)); state.getGoals().add(new GoalNode<>(expandedNode, kdn, kdn.getNode().isClosed()));
} }
} catch (Exception e) { } catch (Exception e) {
if (e.getClass().equals(ScriptException.class)) { if (e.getClass().equals(ScriptException.class)) {
......
...@@ -35,13 +35,13 @@ public class EvaluatorTest { ...@@ -35,13 +35,13 @@ public class EvaluatorTest {
@Before @Before
public void setup() { public void setup() {
GoalNode<String> parent = new GoalNode<>(null, "pa"); GoalNode<String> parent = new GoalNode<>(null, "pa", false);
parent.getAssignments() parent.getAssignments()
.declare("a", Type.INT) .declare("a", Type.INT)
.declare("b", Type.INT) .declare("b", Type.INT)
.assign("a", Value.from(1)) .assign("a", Value.from(1))
.assign("b", Value.from(1)); .assign("b", Value.from(1));
GoalNode<String> selected = new GoalNode<>(parent, "selg"); GoalNode<String> selected = new GoalNode<>(parent, "selg", false);
eval = new Evaluator(selected.getAssignments(), selected); eval = new Evaluator(selected.getAssignments(), selected);
eval.setMatcher(new PseudoMatcher()); eval.setMatcher(new PseudoMatcher());
} }
......
...@@ -28,12 +28,21 @@ import java.util.Map; ...@@ -28,12 +28,21 @@ import java.util.Map;
*/ */
public class InterpreterTest { public class InterpreterTest {
private static <T> T get(Map<Variable, T> m, String... keys) {
for (String k : keys) {
if (m.containsKey(new Variable(k))) {
return m.get(new Variable(k));
}
}
return null;
}
public Interpreter<String> execute(InputStream is) throws IOException { public Interpreter<String> execute(InputStream is) throws IOException {
List<ProofScript> scripts = Facade.getAST(CharStreams.fromStream(is)); List<ProofScript> scripts = Facade.getAST(CharStreams.fromStream(is));
Interpreter<String> i = new Interpreter<>(createTestLookup(scripts)); Interpreter<String> i = new Interpreter<>(createTestLookup(scripts));
i.setMatcherApi(new PseudoMatcher()); i.setMatcherApi(new PseudoMatcher());
//i.getEntryListeners().add(new ScopeLogger("scope:")); //i.getEntryListeners().add(new ScopeLogger("scope:"));
i.newState(new GoalNode<>(null, "abc")); i.newState(new GoalNode<>(null, "abc", false));
i.interpret(scripts.get(0)); i.interpret(scripts.get(0));
return i; return i;
} }
...@@ -50,7 +59,6 @@ public class InterpreterTest { ...@@ -50,7 +59,6 @@ public class InterpreterTest {
return defaultLookup; return defaultLookup;
} }
@Test @Test
public void testSimple() throws IOException { public void testSimple() throws IOException {
Interpreter<String> i = execute(getClass().getResourceAsStream("simple1.txt")); Interpreter<String> i = execute(getClass().getResourceAsStream("simple1.txt"));
...@@ -87,7 +95,6 @@ public class InterpreterTest { ...@@ -87,7 +95,6 @@ public class InterpreterTest {
} }
} }
private class AssertionCommand extends BuiltinCommands.BuiltinCommand { private class AssertionCommand extends BuiltinCommands.BuiltinCommand {
public AssertionCommand() { public AssertionCommand() {
...@@ -105,13 +112,4 @@ public class InterpreterTest { ...@@ -105,13 +112,4 @@ public class InterpreterTest {
Assert.assertTrue(msg.getData(), exp.getData()); Assert.assertTrue(msg.getData(), exp.getData());
} }
} }
private static <T> T get(Map<Variable, T> m, String... keys) {
for (String k : keys) {
if (m.containsKey(new Variable(k))) {
return m.get(new Variable(k));
}
}
return null;
}
} }
...@@ -22,7 +22,8 @@ public class KeyMatcherDerivableTest { ...@@ -22,7 +22,8 @@ public class KeyMatcherDerivableTest {
Proof proof = f.getProof(); Proof proof = f.getProof();
Goal g = proof.getGoal(proof.root()); Goal g = proof.getGoal(proof.root());
GoalNode<KeyData> gn = new GoalNode<>(null, new KeyData(g, f.getEnvironment(), proof)); KeyData newKeYData = new KeyData(g, f.getEnvironment(), proof);
GoalNode<KeyData> gn = new GoalNode<>(null, newKeYData, newKeYData.isClosedNode());
Term termQ = new TermBuilder(f.getEnvironment().getServices().getTermFactory(), Term termQ = new TermBuilder(f.getEnvironment().getServices().getTermFactory(),
f.getEnvironment().getServices()).parseTerm("q"); f.getEnvironment().getServices()).parseTerm("q");
System.out.println(termQ); System.out.println(termQ);
......
...@@ -3,7 +3,6 @@ package edu.kit.formal.interpreter; ...@@ -3,7 +3,6 @@ package edu.kit.formal.interpreter;
import edu.kit.formal.interpreter.data.GoalNode; import edu.kit.formal.interpreter.data.GoalNode;
import edu.kit.formal.interpreter.data.Value; import edu.kit.formal.interpreter.data.Value;
import edu.kit.formal.interpreter.data.VariableAssignment; import edu.kit.formal.interpreter.data.VariableAssignment;
import edu.kit.formal.interpreter.dbg.Debugger;
import edu.kit.formal.interpreter.dbg.PseudoMatcher; import edu.kit.formal.interpreter.dbg.PseudoMatcher;
import edu.kit.formal.proofscriptparser.ast.Type; import edu.kit.formal.proofscriptparser.ast.Type;
import edu.kit.formal.proofscriptparser.ast.Variable; import edu.kit.formal.proofscriptparser.ast.Variable;
...@@ -23,13 +22,13 @@ public class MatchEvaluatorTest { ...@@ -23,13 +22,13 @@ public class MatchEvaluatorTest {
@Before @Before
public void setup() { public void setup() {
GoalNode<String> parent = new GoalNode<>(null, "pa"); GoalNode<String> parent = new GoalNode<>(null, "pa", false);
parent.declareVariable(new Variable("a"), Type.INT); parent.declareVariable(new Variable("a"), Type.INT);
parent.declareVariable(new Variable("b"), Type.INT); parent.declareVariable(new Variable("b"), Type.INT);
VariableAssignment va = parent.getAssignments(); VariableAssignment va = parent.getAssignments();
va.assign(new Variable("a"), Value.from(1)); va.assign(new Variable("a"), Value.from(1));
va.assign(new Variable("b"), Value.from(1)); va.assign(new Variable("b"), Value.from(1));
GoalNode selected = new GoalNode(parent, "selg"); GoalNode selected = new GoalNode(parent, "selg", false);
mEval = new MatchEvaluator(va, selected, new PseudoMatcher()); mEval = new MatchEvaluator(va, selected, new PseudoMatcher());
} }
......
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