Commit b3b1128d authored by Alexander Weigl's avatar Alexander Weigl

Merge branch 'master' of git.scc.kit.edu:xt9634/ProofScriptParser

* 'master' of git.scc.kit.edu:xt9634/ProofScriptParser:
  First footsteps towards interactive mode
  interim
  interim
  better branching labels
parents 47cf84ca 73c88fff
Pipeline #15250 passed with stages
in 10 minutes and 20 seconds
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
# Execute this in this folder. # Execute this in this folder.
# Set to key/key/deployment/components/ # Set to key/key/deployment/components/
#COMPONENTS=${COMPONENTS:-/home/sarah/Documents/KIT_Mitarbeiter/KeYDevelopment/KeYGitDir/key/key/deployment/components/} COMPONENTS=${COMPONENTS:-/home/sarah/Documents/KIT_Mitarbeiter/KeYDevelopment/KeYGitDir/key/key/deployment/components/}
#COMPONENTS=$HOME/work/key/key/deployment/components/ #COMPONENTS=$HOME/work/key/key/deployment/components/
COMPONENTS=lib/components/ #COMPONENTS=lib/components/
......
...@@ -3,6 +3,7 @@ package edu.kit.iti.formal.psdbg; ...@@ -3,6 +3,7 @@ package edu.kit.iti.formal.psdbg;
import de.uka.ilkd.key.proof.Goal; import de.uka.ilkd.key.proof.Goal;
import de.uka.ilkd.key.proof.Node; import de.uka.ilkd.key.proof.Node;
import de.uka.ilkd.key.proof.Proof; import de.uka.ilkd.key.proof.Proof;
import lombok.val;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.key_project.util.collection.ImmutableList; import org.key_project.util.collection.ImmutableList;
...@@ -23,7 +24,6 @@ public class LabelFactory { ...@@ -23,7 +24,6 @@ public class LabelFactory {
public static String RANGE_SEPARATOR = " -- "; public static String RANGE_SEPARATOR = " -- ";
/** /**
* Create Label for goalview according to function that is passed. * Create Label for goalview according to function that is passed.
* The following functions can be given: * The following functions can be given:
...@@ -58,7 +58,20 @@ public class LabelFactory { ...@@ -58,7 +58,20 @@ public class LabelFactory {
} }
public static String getBranchingLabel(Node node) { public static String getBranchingLabel(Node node) {
return constructLabel(node, n -> n.getNodeInfo().getBranchLabel()); StringBuilder sb = new StringBuilder();
while (node != null) {
val p = node.parent();
if (p != null && p.childrenCount() != 1) {
val branchLabel = node.getNodeInfo().getBranchLabel();
sb.append(branchLabel != null && !branchLabel.isEmpty()
? branchLabel
: "#" + p.getChildNr(node))
.append(SEPARATOR);
}
node = p;
}
sb.append("$$");
return sb.toString();
} }
public static String getNameLabel(Node node) { public static String getNameLabel(Node node) {
......
...@@ -26,6 +26,8 @@ import edu.kit.iti.formal.psdbg.parser.types.Type; ...@@ -26,6 +26,8 @@ import edu.kit.iti.formal.psdbg.parser.types.Type;
import edu.kit.iti.formal.psdbg.termmatcher.MatcherFacade; import edu.kit.iti.formal.psdbg.termmatcher.MatcherFacade;
import edu.kit.iti.formal.psdbg.termmatcher.Matchings; import edu.kit.iti.formal.psdbg.termmatcher.Matchings;
import edu.kit.iti.formal.psdbg.termmatcher.mp.MatchPath; import edu.kit.iti.formal.psdbg.termmatcher.mp.MatchPath;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.key_project.util.collection.ImmutableList; import org.key_project.util.collection.ImmutableList;
import java.util.*; import java.util.*;
...@@ -39,6 +41,8 @@ import java.util.regex.Pattern; ...@@ -39,6 +41,8 @@ import java.util.regex.Pattern;
* @author S. Grebing * @author S. Grebing
*/ */
public class KeYMatcher implements MatcherApi<KeyData> { public class KeYMatcher implements MatcherApi<KeyData> {
private static final Logger LOGGER = LogManager.getLogger(KeYMatcher.class);
private static final Name CUT_TACLET_NAME = new Name("cut"); private static final Name CUT_TACLET_NAME = new Name("cut");
private ScriptApi scrapi; private ScriptApi scrapi;
private KeyInterpreter interpreter; private KeyInterpreter interpreter;
...@@ -244,6 +248,7 @@ public class KeYMatcher implements MatcherApi<KeyData> { ...@@ -244,6 +248,7 @@ public class KeYMatcher implements MatcherApi<KeyData> {
Matchings m = MatcherFacade.matches(data, currentState.getData().getNode().sequent()); Matchings m = MatcherFacade.matches(data, currentState.getData().getNode().sequent());
if (m.isEmpty()) { if (m.isEmpty()) {
LOGGER.error("currentState has no match= " + currentState.getData().getNode().sequent());
return Collections.emptyList(); return Collections.emptyList();
} else { } else {
Map<String, MatchPath> firstMatch = m.first(); Map<String, MatchPath> firstMatch = m.first();
...@@ -260,11 +265,11 @@ public class KeYMatcher implements MatcherApi<KeyData> { ...@@ -260,11 +265,11 @@ public class KeYMatcher implements MatcherApi<KeyData> {
Value<String> value = toValueTerm(currentState.getData(), matched); Value<String> value = toValueTerm(currentState.getData(), matched);
va.declare(s, value.getType()); va.declare(s, value.getType());
va.assign(s, value); va.assign(s, value);
System.out.println("Variable " + s + " : " + value); LOGGER.error("Variables to match " + s + " : " + value);
} }
} }
List<VariableAssignment> retList = new LinkedList(); List<VariableAssignment> retList = new LinkedList();
System.out.println("Matched Variables " + va.toString()); LOGGER.error("Matched Variables " + va.toString());
retList.add(va); retList.add(va);
return retList; return retList;
} }
......
package edu.kit.iti.formal.psdbg.interpreter.data; package edu.kit.iti.formal.psdbg.interpreter.data;
import de.uka.ilkd.key.control.KeYEnvironment; import de.uka.ilkd.key.control.KeYEnvironment;
import de.uka.ilkd.key.java.Label;
import de.uka.ilkd.key.java.SourceElement; import de.uka.ilkd.key.java.SourceElement;
import de.uka.ilkd.key.proof.Goal; import de.uka.ilkd.key.proof.Goal;
import de.uka.ilkd.key.proof.Node; import de.uka.ilkd.key.proof.Node;
...@@ -11,7 +10,6 @@ import lombok.*; ...@@ -11,7 +10,6 @@ import lombok.*;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
/** /**
* @author Alexander Weigl * @author Alexander Weigl
...@@ -52,6 +50,7 @@ public class KeyData { ...@@ -52,6 +50,7 @@ public class KeyData {
env = environment; env = environment;
this.proof = proof; this.proof = proof;
closedNode = proof.closed(); closedNode = proof.closed();
} }
public KeyData(Node root, KeYEnvironment environment, Proof proof) { public KeyData(Node root, KeYEnvironment environment, Proof proof) {
......
...@@ -74,6 +74,7 @@ public class RuleCommandHandler implements CommandHandler<KeyData> { ...@@ -74,6 +74,7 @@ public class RuleCommandHandler implements CommandHandler<KeyData> {
} }
} catch (Exception e) { } catch (Exception e) {
if (e.getClass().equals(ScriptException.class)) { if (e.getClass().equals(ScriptException.class)) {
System.out.println("e.getMessage() = " + e.getMessage());
throw new ScriptCommandNotApplicableException(e, c, map); throw new ScriptCommandNotApplicableException(e, c, map);
} else { } else {
......
...@@ -84,6 +84,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -84,6 +84,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
* starting point is a statement list * starting point is a statement list
*/ */
public void interpret(ProofScript script) { public void interpret(ProofScript script) {
enterScope(script);
if (stateStack.empty()) { if (stateStack.empty()) {
throw new InterpreterRuntimeException("no state on stack. call newState before interpret"); throw new InterpreterRuntimeException("no state on stack. call newState before interpret");
} }
...@@ -96,6 +97,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -96,6 +97,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
} }
script.accept(this); script.accept(this);
exitScope(script);
} }
/** /**
......
...@@ -32,7 +32,6 @@ public abstract class Blocker { ...@@ -32,7 +32,6 @@ public abstract class Blocker {
@Override @Override
public boolean test(ASTNode node) { public boolean test(ASTNode node) {
Evaluator<T> evaluator = new Evaluator<>(interpreter.getSelectedNode().getAssignments(), interpreter.getSelectedNode());
for (Breakpoint brkpt : getBreakpoints()) { for (Breakpoint brkpt : getBreakpoints()) {
// check file name // check file name
if (brkpt.getSourceName().equals(node.getOrigin())) { if (brkpt.getSourceName().equals(node.getOrigin())) {
...@@ -42,6 +41,7 @@ public abstract class Blocker { ...@@ -42,6 +41,7 @@ public abstract class Blocker {
if (brkpt.getConditionAst() == null) { if (brkpt.getConditionAst() == null) {
return true; // no condition ==> trigger return true; // no condition ==> trigger
} else { // if there is a condition, we check: } else { // if there is a condition, we check:
Evaluator<T> evaluator = new Evaluator<>(interpreter.getSelectedNode().getAssignments(), interpreter.getSelectedNode());
val v = evaluator.eval(brkpt.getConditionAst()); val v = evaluator.eval(brkpt.getConditionAst());
if (v.getType() != SimpleType.BOOL) if (v.getType() != SimpleType.BOOL)
throw new InterpreterRuntimeException( throw new InterpreterRuntimeException(
......
...@@ -134,6 +134,7 @@ public class DebuggerFramework<T> { ...@@ -134,6 +134,7 @@ public class DebuggerFramework<T> {
private void run() { private void run() {
try { try {
interpreter.interpret(mainScript); interpreter.interpret(mainScript);
//dummyproofnode
succeedListener.accept(this); succeedListener.accept(this);
} catch (Exception e) { } catch (Exception e) {
error = e; error = e;
......
...@@ -36,6 +36,10 @@ public class PTreeNode<T> { ...@@ -36,6 +36,10 @@ public class PTreeNode<T> {
private boolean atomic; private boolean atomic;
private boolean isFirstNode = false;
private boolean isLastNode = false;
@Nullable @Nullable
private PTreeNode<T> stepInto; private PTreeNode<T> stepInto;
......
...@@ -43,6 +43,9 @@ public class StateWrapper<T> implements InterpreterObserver<T> { ...@@ -43,6 +43,9 @@ public class StateWrapper<T> implements InterpreterObserver<T> {
private Consumer<PTreeNode<T>> emitNode = (n) -> { private Consumer<PTreeNode<T>> emitNode = (n) -> {
}; };
@Getter
private ProofScript root;
@Nullable @Nullable
private PTreeNode<T> lastNode; private PTreeNode<T> lastNode;
...@@ -74,6 +77,7 @@ public class StateWrapper<T> implements InterpreterObserver<T> { ...@@ -74,6 +77,7 @@ public class StateWrapper<T> implements InterpreterObserver<T> {
} }
public void createRoot(ProofScript node) { public void createRoot(ProofScript node) {
this.root = node;
emitNode.accept(createNode(node)); emitNode.accept(createNode(node));
} }
...@@ -81,6 +85,12 @@ public class StateWrapper<T> implements InterpreterObserver<T> { ...@@ -81,6 +85,12 @@ public class StateWrapper<T> implements InterpreterObserver<T> {
emitNode.accept(createNode(node)); emitNode.accept(createNode(node));
} }
public void createSentinel() {
PTreeNode<T> node = createNode(getRoot());
node.setLastNode(true);
emitNode.accept(node);
}
public State<T> getInterpreterStateCopy() { public State<T> getInterpreterStateCopy() {
return interpreter.getCurrentState().copy(); return interpreter.getCurrentState().copy();
...@@ -145,6 +155,16 @@ public class StateWrapper<T> implements InterpreterObserver<T> { ...@@ -145,6 +155,16 @@ public class StateWrapper<T> implements InterpreterObserver<T> {
return null; return null;
} }
@Override
public Void visit(ProofScript proofScript) {
LOGGER.error("exit {}", proofScript.accept(new ShortCommandPrinter()));
if (proofScript.equals(root)) {
createSentinel();
}
return null;
}
@Override @Override
public Void visit(Statements statements) { public Void visit(Statements statements) {
return null; return null;
......
package edu.kit.iti.formal.psdbg.examples.java.bubbleSort;
import edu.kit.iti.formal.psdbg.examples.JavaExample;
public class BubbleSortExample extends JavaExample {
public BubbleSortExample() {
setName("Bubble Sort");
setJavaFile(this.getClass().getResource("Bubblesort.java"));
defaultInit(getClass());
System.out.println(this);
}
}
...@@ -127,6 +127,9 @@ public class DebuggerMain implements Initializable { ...@@ -127,6 +127,9 @@ public class DebuggerMain implements Initializable {
@FXML @FXML
private CheckMenuItem miProofTree; private CheckMenuItem miProofTree;
@FXML
private Button btnIM;
private JavaArea javaArea = new JavaArea(); private JavaArea javaArea = new JavaArea();
private DockNode javaAreaDock = new DockNode(javaArea, "Java Source", private DockNode javaAreaDock = new DockNode(javaArea, "Java Source",
...@@ -148,6 +151,8 @@ public class DebuggerMain implements Initializable { ...@@ -148,6 +151,8 @@ public class DebuggerMain implements Initializable {
private DockNode commandHelpDock = new DockNode(commandHelp, "DebuggerCommand Help"); private DockNode commandHelpDock = new DockNode(commandHelp, "DebuggerCommand Help");
private InteractiveModeController interactiveModeController;
@FXML @FXML
private Menu examplesMenu; private Menu examplesMenu;
...@@ -193,6 +198,7 @@ public class DebuggerMain implements Initializable { ...@@ -193,6 +198,7 @@ public class DebuggerMain implements Initializable {
Events.register(this); Events.register(this);
model.setDebugMode(false); model.setDebugMode(false);
scriptController = new ScriptController(dockStation); scriptController = new ScriptController(dockStation);
interactiveModeController = new InteractiveModeController(scriptController);
inspectionViewsController = new InspectionViewsController(dockStation); inspectionViewsController = new InspectionViewsController(dockStation);
activeInspectorDock = inspectionViewsController.getActiveInterpreterTabDock(); activeInspectorDock = inspectionViewsController.getActiveInterpreterTabDock();
//register the welcome dock in the center //register the welcome dock in the center
...@@ -493,10 +499,12 @@ public class DebuggerMain implements Initializable { ...@@ -493,10 +499,12 @@ public class DebuggerMain implements Initializable {
Platform.runLater(() -> { Platform.runLater(() -> {
scriptController.getDebugPositionHighlighter().remove(); scriptController.getDebugPositionHighlighter().remove();
statusBar.publishSuccessMessage("Interpreter finished."); statusBar.publishSuccessMessage("Interpreter finished.");
btnIM.setDisable(false);
assert model.getDebuggerFramework() != null; assert model.getDebuggerFramework() != null;
PTreeNode<KeyData> statePointer = model.getDebuggerFramework().getStatePointer(); PTreeNode<KeyData> statePointer = model.getDebuggerFramework().getStatePointer();
State<KeyData> lastState = statePointer.getStateAfterStmt(); State<KeyData> lastState = statePointer.getStateAfterStmt();
getInspectionViewsController().getActiveInspectionViewTab().activate(statePointer, lastState); getInspectionViewsController().getActiveInspectionViewTab().activate(statePointer, lastState);
}); });
} }
...@@ -834,10 +842,27 @@ public class DebuggerMain implements Initializable { ...@@ -834,10 +842,27 @@ public class DebuggerMain implements Initializable {
stop.setText("Reload"); stop.setText("Reload");
} }
/* public void handle(Events.TacletApplicationEvent tap){
TacletApp app = tap.getApp();
Goal currentGoal = tap.getCurrentGoal();
ImmutableList<Goal> apply = currentGoal.apply(app);
}*/
public void newScript(ActionEvent actionEvent) { public void newScript(ActionEvent actionEvent) {
scriptController.newScript(); scriptController.newScript();
} }
@FXML
public void interactiveMode(ActionEvent actionEvent) {
interactiveModeController.setActivated(true);
interactiveModeController.start(getFacade().getProof(), getInspectionViewsController().getActiveInspectionViewTab().getModel());
}
@FXML @FXML
public void showWelcomeDock(ActionEvent actionEvent) { public void showWelcomeDock(ActionEvent actionEvent) {
if (!welcomePaneDock.isDocked() && !welcomePaneDock.isFloating()) { if (!welcomePaneDock.isDocked() && !welcomePaneDock.isFloating()) {
...@@ -971,15 +996,19 @@ public class DebuggerMain implements Initializable { ...@@ -971,15 +996,19 @@ public class DebuggerMain implements Initializable {
ptree.setRoot(pnode); ptree.setRoot(pnode);
ptree.setDeactivateRefresh(true); ptree.setDeactivateRefresh(true);
Set<Node> sentinels = proof.getSubtreeGoals(pnode) Set<Node> sentinels = proof.getSubtreeGoals(pnode)
.stream() .stream()
.map(Goal::node) .map(Goal::node)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
ptree.getSentinels().addAll(sentinels); ptree.getSentinels().addAll(sentinels);
ptree.expandRootToLeaves();
//TODO set coloring of starting and end node
DockNode node = new DockNode(ptree, "Proof Tree for Step Into: " + DockNode node = new DockNode(ptree, "Proof Tree for Step Into: " +
original.getStatement().accept(new ShortCommandPrinter()) original.getStatement().accept(new ShortCommandPrinter())
); );
node.dock(dockStation, DockPos.CENTER, getActiveInspectorDock());
node.dock(dockStation, DockPos.CENTER, scriptController.getOpenScripts().get(getScriptController().getMainScript().getScriptArea()));
} }
} }
//endregion //endregion
......
...@@ -2,6 +2,7 @@ package edu.kit.iti.formal.psdbg.gui.controller; ...@@ -2,6 +2,7 @@ package edu.kit.iti.formal.psdbg.gui.controller;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import de.uka.ilkd.key.logic.PosInOccurrence; import de.uka.ilkd.key.logic.PosInOccurrence;
import de.uka.ilkd.key.proof.Goal;
import de.uka.ilkd.key.proof.Node; import de.uka.ilkd.key.proof.Node;
import de.uka.ilkd.key.rule.TacletApp; import de.uka.ilkd.key.rule.TacletApp;
import edu.kit.iti.formal.psdbg.gui.controls.ScriptArea; import edu.kit.iti.formal.psdbg.gui.controls.ScriptArea;
...@@ -47,8 +48,11 @@ public class Events { ...@@ -47,8 +48,11 @@ public class Events {
@RequiredArgsConstructor @RequiredArgsConstructor
public static class TacletApplicationEvent { public static class TacletApplicationEvent {
private final TacletApp app; private final TacletApp app;
private final PosInOccurrence pio; private final PosInOccurrence pio;
private final Goal currentGoal;
} }
@Data @Data
......
package edu.kit.iti.formal.psdbg.gui.controller; package edu.kit.iti.formal.psdbg.gui.controller;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import de.uka.ilkd.key.control.AbstractUserInterfaceControl;
import de.uka.ilkd.key.control.DefaultUserInterfaceControl;
import de.uka.ilkd.key.logic.SequentFormula; import de.uka.ilkd.key.logic.SequentFormula;
import de.uka.ilkd.key.macros.scripts.EngineState;
import de.uka.ilkd.key.macros.scripts.RuleCommand;
import de.uka.ilkd.key.macros.scripts.ScriptException;
import de.uka.ilkd.key.proof.Goal;
import de.uka.ilkd.key.proof.Node; import de.uka.ilkd.key.proof.Node;
import de.uka.ilkd.key.proof.Proof;
import edu.kit.iti.formal.psdbg.LabelFactory; import edu.kit.iti.formal.psdbg.LabelFactory;
import edu.kit.iti.formal.psdbg.gui.controls.ScriptArea;
import edu.kit.iti.formal.psdbg.gui.controls.ScriptController;
import edu.kit.iti.formal.psdbg.gui.model.InspectionModel;
import edu.kit.iti.formal.psdbg.interpreter.data.GoalNode;
import edu.kit.iti.formal.psdbg.interpreter.data.KeyData;
import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment;
import edu.kit.iti.formal.psdbg.interpreter.exceptions.ScriptCommandNotApplicableException;
import edu.kit.iti.formal.psdbg.parser.PrettyPrinter; import edu.kit.iti.formal.psdbg.parser.PrettyPrinter;
import edu.kit.iti.formal.psdbg.parser.ast.*; import edu.kit.iti.formal.psdbg.parser.ast.*;
import javafx.beans.property.BooleanProperty; import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.ObservableList;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.val; import lombok.val;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.key_project.util.collection.ImmutableList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Getter @Getter
@Setter @Setter
@RequiredArgsConstructor
public class InteractiveModeController { public class InteractiveModeController {
private static final Logger LOGGER = LogManager.getLogger(InteractiveModeController.class); private static final Logger LOGGER = LogManager.getLogger(InteractiveModeController.class);
private final Map<Node, Statements> cases = new HashMap<>(); private final Map<Node, Statements> cases = new HashMap<>();
private BooleanProperty activated = new SimpleBooleanProperty(); private BooleanProperty activated = new SimpleBooleanProperty();
private final ScriptController scriptController;
private ScriptArea scriptArea;
private InspectionModel model;
public InteractiveModeController() {
}
public void start() { public void start(Proof currentProof, InspectionModel model) {
Events.register(this); Events.register(this);
cases.clear(); cases.clear();
activated.set(true); currentProof.getSubtreeGoals(currentProof.root()).forEach(goal -> {
cases.put(goal.node(), new Statements());
});