Commit 698add94 authored by Alexander Weigl's avatar Alexander Weigl

sequent view and clean

parent ed44f370
Pipeline #10943 failed with stage
in 2 minutes and 20 seconds
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
<!-- Checks that a package-info.java file exists for each package. --> <!-- Checks that a package-info.java file exists for each package. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage --> <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
<module name="JavadocPackage"/> <!-- <module name="JavadocPackage"/> -->
<!-- Checks whether files end with a new line. --> <!-- Checks whether files end with a new line. -->
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile --> <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
...@@ -153,7 +153,7 @@ ...@@ -153,7 +153,7 @@
<module name="AvoidInlineConditionals"/> <module name="AvoidInlineConditionals"/>
<module name="EmptyStatement"/> <module name="EmptyStatement"/>
<module name="EqualsHashCode"/> <module name="EqualsHashCode"/>
<module name="HiddenField"/> <!-- <module name="HiddenField"/> -->
<module name="IllegalInstantiation"/> <module name="IllegalInstantiation"/>
<module name="InnerAssignment"/> <module name="InnerAssignment"/>
<module name="MagicNumber"/> <module name="MagicNumber"/>
...@@ -172,7 +172,7 @@ ...@@ -172,7 +172,7 @@
<!-- Miscellaneous other checks. --> <!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html --> <!-- See http://checkstyle.sf.net/config_misc.html -->
<module name="ArrayTypeStyle"/> <module name="ArrayTypeStyle"/>
<!-- <module name="FinalParameters"/> --> <!-- <module name="FinalParameters"/> -->
<module name="TodoComment"/> <module name="TodoComment"/>
<module name="UpperEll"/> <module name="UpperEll"/>
......
...@@ -185,7 +185,7 @@ ...@@ -185,7 +185,7 @@
<dependency> <dependency>
<groupId>org.fxmisc.richtext</groupId> <groupId>org.fxmisc.richtext</groupId>
<artifactId>richtextfx</artifactId> <artifactId>richtextfx</artifactId>
<version>0.6.10</version> <version>0.7-M5</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
......
...@@ -61,7 +61,7 @@ public class ContractChooser extends Dialog<Contract> { ...@@ -61,7 +61,7 @@ public class ContractChooser extends Dialog<Contract> {
} }
private class ContractListCell extends ListCell<Contract> { private class ContractListCell extends ListCell<Contract> {
public ContractListCell(ListView<Contract> contractListView) { ContractListCell(ListView<Contract> contractListView) {
itemProperty().addListener((observable, oldValue, newValue) -> render()); itemProperty().addListener((observable, oldValue, newValue) -> render());
selectedProperty().addListener((observable, oldValue, newValue) -> render()); selectedProperty().addListener((observable, oldValue, newValue) -> render());
} }
......
...@@ -2,16 +2,24 @@ package edu.kit.formal.gui.controller; ...@@ -2,16 +2,24 @@ package edu.kit.formal.gui.controller;
import de.uka.ilkd.key.logic.op.IProgramMethod; import de.uka.ilkd.key.logic.op.IProgramMethod;
import de.uka.ilkd.key.pp.ProgramPrinter; import de.uka.ilkd.key.pp.ProgramPrinter;
import de.uka.ilkd.key.proof.init.ProofInputException;
import de.uka.ilkd.key.speclang.Contract; import de.uka.ilkd.key.speclang.Contract;
import edu.kit.formal.gui.controls.JavaArea; import edu.kit.formal.gui.controls.JavaArea;
import edu.kit.formal.gui.controls.ScriptArea; import edu.kit.formal.gui.controls.ScriptArea;
import edu.kit.formal.gui.controls.SequentView; import edu.kit.formal.gui.controls.SequentView;
import edu.kit.formal.gui.model.RootModel; import edu.kit.formal.gui.model.RootModel;
import edu.kit.formal.interpreter.Interpreter;
import edu.kit.formal.interpreter.InterpreterBuilder;
import edu.kit.formal.interpreter.KeYProofFacade; import edu.kit.formal.interpreter.KeYProofFacade;
import edu.kit.formal.interpreter.data.GoalNode; import edu.kit.formal.interpreter.data.GoalNode;
import edu.kit.formal.interpreter.data.KeyData; import edu.kit.formal.interpreter.data.KeyData;
import edu.kit.formal.interpreter.data.State;
import edu.kit.formal.proofscriptparser.Facade;
import edu.kit.formal.proofscriptparser.ast.ProofScript;
import javafx.beans.Observable; import javafx.beans.Observable;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableBooleanValue;
import javafx.collections.SetChangeListener; import javafx.collections.SetChangeListener;
import javafx.concurrent.Service; import javafx.concurrent.Service;
import javafx.concurrent.Task; import javafx.concurrent.Task;
...@@ -23,8 +31,8 @@ import javafx.scene.layout.GridPane; ...@@ -23,8 +31,8 @@ import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority; import javafx.scene.layout.Priority;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import org.antlr.v4.runtime.RecognitionException;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.controlsfx.dialog.Wizard;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
...@@ -81,16 +89,15 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -81,16 +89,15 @@ public class DebuggerMainWindowController implements Initializable {
* **********************************************************************************************************/ * **********************************************************************************************************/
@FXML @FXML
private ListView<GoalNode<KeyData>> goalView; private ListView<GoalNode<KeyData>> goalView;
private ExecutorService executorService = null; private ExecutorService executorService = Executors.newFixedThreadPool(2);
private KeYProofFacade facade; private KeYProofFacade facade = new KeYProofFacade();
private Wizard contractChooserDialog = new Wizard(); private ContractLoaderService contractLoaderService = new ContractLoaderService();
private ContractLoaderService cls;
/** /**
* Model for the DebuggerController containing the neccessary * Model for the DebuggerController containing the neccessary
* references to objects needed for controlling backend through UI * references to objects needed for controlling backend through UI
*/ */
private RootModel model; private RootModel model = new RootModel();
@FXML @FXML
private Label lblStatusMessage; private Label lblStatusMessage;
...@@ -109,6 +116,10 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -109,6 +116,10 @@ public class DebuggerMainWindowController implements Initializable {
@FXML @FXML
private SequentView sequentView; private SequentView sequentView;
private InterpretingService interpreterService = new InterpretingService();
private ObservableBooleanValue executeNotPossible = interpreterService.runningProperty().or(facade.readyToExecuteProperty().not());
/** /**
* @param location * @param location
...@@ -116,15 +127,14 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -116,15 +127,14 @@ public class DebuggerMainWindowController implements Initializable {
*/ */
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
model = new RootModel();
setDebugMode(false); setDebugMode(false);
facade = new KeYProofFacade(this.model);
cls = new ContractLoaderService();
model.scriptFileProperty().addListener((observable, oldValue, newValue) -> { model.scriptFileProperty().addListener((observable, oldValue, newValue) -> {
lblFilename.setText("File: " + (newValue != null ? newValue.getAbsolutePath() : "n/a")); lblFilename.setText("File: " + (newValue != null ? newValue.getAbsolutePath() : "n/a"));
}); });
model.chosenContractProperty().addListener(o -> { model.chosenContractProperty().addListener(o -> {
IProgramMethod method = (IProgramMethod) model.getChosenContract().getTarget(); IProgramMethod method = (IProgramMethod) model.getChosenContract().getTarget();
javaSourceCode.clear(); javaSourceCode.clear();
...@@ -165,7 +175,6 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -165,7 +175,6 @@ public class DebuggerMainWindowController implements Initializable {
);*/ );*/
}); });
goalView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { goalView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
sequentView.setNode(newValue.getData().getNode()); sequentView.setNode(newValue.getData().getNode());
}); });
...@@ -173,30 +182,53 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -173,30 +182,53 @@ public class DebuggerMainWindowController implements Initializable {
goalView.setCellFactory(GoalNodeListCell::new); goalView.setCellFactory(GoalNodeListCell::new);
} }
//region Actions: Execution //region Actions: Execution
@FXML @FXML
public void executeScript() { public void executeScript() {
executeScript(false); executeScript(facade.buildInterpreter(), false);
}
@FXML
public void executeScriptFromCursor() {
InterpreterBuilder ib = facade.buildInterpreter();
ib.inheritState(interpreterService.interpreter.get());
/*
LineMapping lm = new LineMapping(scriptArea.getText());
int line = lm.getLine(scriptArea.getCaretPosition());
int inLine = lm.getCharInLine(scriptArea.getCaretPosition());
*/
ib.ignoreLinesUntil(scriptArea.getCaretPosition());
executeScript(ib, true);
} }
@FXML @FXML
public void executeInDebugMode() { public void executeInDebugMode() {
executeScript(true); executeScript(facade.buildInterpreter(), true);
} }
private void executeScript(boolean debugMode) { private void executeScript(InterpreterBuilder ib, boolean debugMode) {
this.debugMode.set(debugMode); this.debugMode.set(debugMode);
lblStatusMessage.setText("Interpreting..."); blocker.deinstall();
lblStatusMessage.setText("Parse ...");
blocker.deinstall(facade.getInterpreter()); try {
if (debugMode) { List<ProofScript> scripts = Facade.getAST(scriptArea.getText());
blocker.getStepUntilBlock().set(1); lblStatusMessage.setText("Creating new Interpreter instance ...");
blocker.install(facade.getInterpreter()); ib.inheritState(interpreterService.interpreter.get())
.setScripts(scripts);
Interpreter<KeyData> currentInterpreter = ib.build();
if (debugMode) {
blocker.getStepUntilBlock().set(1);
blocker.install(currentInterpreter);
}
interpreterService.interpreter.set(currentInterpreter);
interpreterService.start();
} catch (RecognitionException e) {
showExceptionDialog("Antlr Exception", "", "Could not parse scripts.", e);
} }
facade.executeScript(scriptArea.getText());
List<GoalNode<KeyData>> g = model.getCurrentState().getGoals();
this.model.getCurrentGoalNodes().addAll(g);
lblStatusMessage.setText("Script executed");
} }
//endregion //endregion
...@@ -263,9 +295,23 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -263,9 +295,23 @@ public class DebuggerMainWindowController implements Initializable {
File keyFile = openFileChooserOpenDialog("Select KeY File", "KeY Files", "key", "script"); File keyFile = openFileChooserOpenDialog("Select KeY File", "KeY Files", "key", "script");
this.model.setKeYFile(keyFile); this.model.setKeYFile(keyFile);
if (keyFile != null) { if (keyFile != null) {
buildKeYProofFacade(); Task<Void> task = facade.loadKeyFileTask(keyFile);
} task.setOnSucceeded(event -> {
lblStatusMessage.setText("Loaded key file: " + keyFile);
model.getCurrentGoalNodes().setAll(facade.getPseudoGoals());
});
task.setOnFailed(event -> {
event.getSource().exceptionProperty().get();
showExceptionDialog("Could not load file", "Key file loading error", "",
(Throwable) event.getSource().exceptionProperty().get()
);
});
ProgressBar bar = new ProgressBar();
bar.progressProperty().bind(task.progressProperty());
executorService.execute(task);
}
} }
public void saveProof(ActionEvent actionEvent) { public void saveProof(ActionEvent actionEvent) {
...@@ -278,51 +324,9 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -278,51 +324,9 @@ public class DebuggerMainWindowController implements Initializable {
File javaFile = openFileChooserOpenDialog("Select Java File", "Java Files", "java"); File javaFile = openFileChooserOpenDialog("Select Java File", "Java Files", "java");
if (javaFile != null) { if (javaFile != null) {
model.setJavaFile(javaFile); model.setJavaFile(javaFile);
facade = new KeYProofFacade(model); contractLoaderService.start();
cls.start();
cls.setOnSucceeded(event -> {
model.getLoadedContracts().addAll(cls.getValue());
ContractChooser cc = new ContractChooser(facade.getService(),
model.loadedContractsProperty());
cc.showAndWait().ifPresent(result -> {
model.setChosenContract(result);
if (this.model.getChosenContract() != null) {
buildJavaProofFacade();
System.out.println("Proof Facade is built");
} else {
System.out.println("Something went wrong");
}
});
});
} }
} }
/**
* Spawns a thread that builds the proof environment as facade with interpreter
*/
private void buildKeYProofFacade() {
executorService = Executors.newFixedThreadPool(2);
executorService.execute(() -> {
facade = new KeYProofFacade(model);
facade.prepareEnvWithKeYFile(model.getKeYFile());
});
executorService.shutdown();
}
/**
* Spawns a thread that builds the proof environment as facade with interpreter
*/
private void buildJavaProofFacade() {
executorService = Executors.newFixedThreadPool(2);
executorService.execute(() -> {
if (facade != null) {
facade.prepareEnvForContract(model.getChosenContract(), model.getKeYFile());
}
});
executorService.shutdown();
}
//endregion //endregion
//region Santa's Little Helper //region Santa's Little Helper
...@@ -371,21 +375,38 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -371,21 +375,38 @@ public class DebuggerMainWindowController implements Initializable {
public class ContractLoaderService extends Service<List<Contract>> { public class ContractLoaderService extends Service<List<Contract>> {
@Override @Override
protected Task<List<Contract>> createTask() { protected Task<List<Contract>> createTask() {
Task<List<Contract>> task1 = new Task<List<Contract>>() { return facade.getContractsForJavaFileTask(model.getJavaFile());
@Override }
protected List<Contract> call() throws Exception {
List<Contract> contracts = facade.getContractsForJavaFile(model.getJavaFile()); @Override
System.out.println("Loaded Contracts " + contracts.toString()); protected void failed() {
return contracts; showExceptionDialog("", "", "", exceptionProperty().get());
} }
};
return task1; @Override
protected void succeeded() {
lblStatusMessage.setText("Contract loaded");
model.getLoadedContracts().setAll(getValue());
//FIXME
ContractChooser cc = new ContractChooser(facade.getService(), model.loadedContractsProperty());
cc.showAndWait().ifPresent(result -> {
model.setChosenContract(result);
try {
facade.activateContract(result);
model.getCurrentGoalNodes().setAll(facade.getPseudoGoals());
} catch (ProofInputException e) {
showExceptionDialog("", "", "", e);
}
});
} }
}
public KeYProofFacade getFacade() {
return facade;
} }
public static void showExceptionDialog(String title, String headerText, String contentText, Exception ex) { public static void showExceptionDialog(String title, String headerText, String contentText, Throwable ex) {
Alert alert = new Alert(Alert.AlertType.ERROR); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(title); alert.setTitle(title);
alert.setHeaderText(headerText); alert.setHeaderText(headerText);
...@@ -444,5 +465,32 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -444,5 +465,32 @@ public class DebuggerMainWindowController implements Initializable {
setText(item.getNode().name()); setText(item.getNode().name());
} }
} }
//endregion
public Boolean getExecuteNotPossible() {
return executeNotPossible.get();
}
public ObservableBooleanValue executeNotPossibleProperty() {
return executeNotPossible;
}
private class InterpretingService extends Service<State<KeyData>> {
private final SimpleObjectProperty<Interpreter<KeyData>> interpreter = new SimpleObjectProperty<>();
private final SimpleObjectProperty<ProofScript> mainScript = new SimpleObjectProperty<>();
@Override
protected Task<edu.kit.formal.interpreter.data.State<KeyData>> createTask() {
return new Task<edu.kit.formal.interpreter.data.State<KeyData>>() {
final Interpreter<KeyData> i = interpreter.get();
final ProofScript ast = mainScript.get();
@Override
protected edu.kit.formal.interpreter.data.State<KeyData> call() throws Exception {
i.interpret(ast);
return i.peekState();
}
};
}
}
//endregion
} }
...@@ -141,6 +141,10 @@ public class PuppetMaster { ...@@ -141,6 +141,10 @@ public class PuppetMaster {
return stepUntilBlock; return stepUntilBlock;
} }
public void deinstall() {
deinstall(puppet);
}
private class EntryListener extends DefaultASTVisitor<Void> { private class EntryListener extends DefaultASTVisitor<Void> {
@Override @Override
......
...@@ -2,8 +2,8 @@ package edu.kit.formal.gui.controls; ...@@ -2,8 +2,8 @@ package edu.kit.formal.gui.controls;
import org.antlr.v4.runtime.Lexer; import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.Token;
import org.fxmisc.richtext.StyleSpans; import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.StyleSpansBuilder; import org.fxmisc.richtext.model.StyleSpansBuilder;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
...@@ -23,7 +23,7 @@ public class ANTLR4LexerHighlighter { ...@@ -23,7 +23,7 @@ public class ANTLR4LexerHighlighter {
} }
public StyleSpans<Collection<String>> highlight(String sourcecode) { public StyleSpans<? extends Collection<String>> highlight(String sourcecode) {
Lexer lexer = factory.apply(sourcecode); Lexer lexer = factory.apply(sourcecode);
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>(); StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
try { try {
......
...@@ -7,7 +7,7 @@ import java.util.List; ...@@ -7,7 +7,7 @@ import java.util.List;
* @author Alexander Weigl * @author Alexander Weigl
* @version 1 (04.06.17) * @version 1 (04.06.17)
*/ */
class LineMapping { public class LineMapping {
private List<Integer> marks = new ArrayList<>(); private List<Integer> marks = new ArrayList<>();
public LineMapping(String value) { public LineMapping(String value) {
...@@ -37,4 +37,16 @@ class LineMapping { ...@@ -37,4 +37,16 @@ class LineMapping {
return getLineStart(line + 1) - 1; return getLineStart(line + 1) - 1;
} }
public int getCharInLine(int caretPosition) {
return caretPosition - getLineStart(getLine(caretPosition));
}
public int getLine(int caretPosition) {
for (int i = 0; i < marks.size(); i++) {
if (caretPosition >= marks.get(i)) {
return i;
}
}
return -1;
}
} }
...@@ -14,7 +14,6 @@ import javafx.collections.ObservableList; ...@@ -14,7 +14,6 @@ import javafx.collections.ObservableList;
import javafx.collections.ObservableSet; import javafx.collections.ObservableSet;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.layout.Background; import javafx.scene.layout.Background;
......
...@@ -3,15 +3,13 @@ package edu.kit.formal.gui.controls; ...@@ -3,15 +3,13 @@ package edu.kit.formal.gui.controls;
import de.uka.ilkd.key.java.Services; import de.uka.ilkd.key.java.Services;
import de.uka.ilkd.key.logic.NamespaceSet; import de.uka.ilkd.key.logic.NamespaceSet;
import de.uka.ilkd.key.logic.Sequent; import de.uka.ilkd.key.logic.Sequent;
import de.uka.ilkd.key.pp.IdentitySequentPrintFilter; import de.uka.ilkd.key.pp.*;
import de.uka.ilkd.key.pp.LogicPrinter;
import de.uka.ilkd.key.pp.NotationInfo;
import de.uka.ilkd.key.pp.ProgramPrinter;
import de.uka.ilkd.key.proof.Node; import de.uka.ilkd.key.proof.Node;
import de.uka.ilkd.key.settings.ProofIndependentSettings; import de.uka.ilkd.key.settings.ProofIndependentSettings;
import javafx.beans.Observable; import javafx.beans.Observable;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import org.fxmisc.richtext.CharacterHit;
import org.fxmisc.richtext.CodeArea; import org.fxmisc.richtext.CodeArea;
import java.io.StringWriter; import java.io.StringWriter;
...@@ -21,6 +19,7 @@ import java.io.StringWriter; ...@@ -21,6 +19,7 @@ import java.io.StringWriter;
* @version 1 (03.06.17) * @version 1 (03.06.17)
*/ */
public class SequentView extends CodeArea { public class SequentView extends CodeArea {
private Services services;
private LogicPrinter lp; private LogicPrinter lp;
private IdentitySequentPrintFilter filter; private IdentitySequentPrintFilter filter;
...@@ -35,24 +34,50 @@ public class SequentView extends CodeArea { ...@@ -35,24 +34,50 @@ public class SequentView extends CodeArea {
} }