Commit e141acf7 authored by LULUDBR\Lulu's avatar LULUDBR\Lulu
Browse files

Merge remote-tracking branch 'origin/master'

parents 7c42f49c 298ba538
package edu.kit.iti.formal.psdbg.examples;
import de.uka.ilkd.key.proof.Proof;
import edu.kit.iti.formal.psdbg.gui.controller.DebuggerMain;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import org.apache.commons.io.IOUtils;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.net.URL;
import java.nio.charset.Charset;
......@@ -24,6 +26,12 @@ public class JavaExample extends Example {
protected URL javaFile;
protected URL settingsFile;
public void setSettingsFile(URL settingsFile) {
this.settingsFile = settingsFile;
}
@Override
public void open(DebuggerMain debuggerMain) {
//TODO should be reworked if we have an example
......@@ -39,7 +47,11 @@ public class JavaExample extends Example {
//System.out.println(java.getAbsolutePath());
//debuggerMain.openKeyFile(key);
debuggerMain.openJavaFile(java);
if (settingsFile != null) {
File settings = newTempFile(settingsFile, getName() + ".props");
ProofListener pl = new ProofListener(debuggerMain, settings);
debuggerMain.getFacade().proofProperty().addListener(pl);
}
debuggerMain.showActiveInspector(null);
if (helpText != null) {
String content = IOUtils.toString(helpText, Charset.defaultCharset());
......@@ -49,4 +61,31 @@ public class JavaExample extends Example {
e.printStackTrace();
}
}
public class ProofListener implements ChangeListener<Proof> {
File settingsFile;
DebuggerMain debuggerMain;
public ProofListener(DebuggerMain debuggerMain, File settingsFile) {
this.debuggerMain = debuggerMain;
this.settingsFile = settingsFile;
}
@Override
public void changed(ObservableValue<? extends Proof> observable, Proof oldValue, Proof newValue) {
if (newValue != null) {
try {
BufferedReader reader = new BufferedReader(new FileReader(settingsFile));
newValue.getSettings().loadSettingsFromStream(reader);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
debuggerMain.getFacade().proofProperty().removeListener(this);
}
}
}
}
......@@ -8,7 +8,7 @@ public class QuickSort extends JavaExample {
setName("Quicksort example");
setSettingsFile(getClass().getResource("proof-settings.props"));
setHelpText(getClass().getResource("help.html"));
setJavaFile(getClass().
......
......@@ -29,7 +29,7 @@ import java.util.Locale;
public class ProofScriptDebugger extends Application {
public static final String NAME = "Proof Script Debugger";
public static final String VERSION = "1.0-FM";
public static final String VERSION = "Experimental-1.1";
public static final String KEY_VERSION = KeYConstants.VERSION;
......@@ -52,7 +52,7 @@ public class ProofScriptDebugger extends Application {
getClass().getResource("debugger-ui.css").toExternalForm(),
DockNode.class.getResource("default.css").toExternalForm()
);
System.out.println(getClass().getResource("debugger-ui.css").toExternalForm());
logger.info("Loading CSS class " + getClass().getResource("debugger-ui.css").toExternalForm());
primaryStage.setTitle(NAME + " (" + VERSION + ") with KeY:" + KEY_VERSION);
primaryStage.setScene(scene);
......
......@@ -30,9 +30,11 @@ import edu.kit.iti.formal.psdbg.interpreter.KeYProofFacade;
import edu.kit.iti.formal.psdbg.interpreter.KeyInterpreter;
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.SavePoint;
import edu.kit.iti.formal.psdbg.interpreter.data.State;
import edu.kit.iti.formal.psdbg.interpreter.dbg.*;
import edu.kit.iti.formal.psdbg.parser.ast.ProofScript;
import edu.kit.iti.formal.psdbg.parser.ast.Statements;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.binding.BooleanBinding;
......@@ -77,7 +79,6 @@ import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import org.reactfx.util.Timer;
/**
* Controller for the Debugger MainWindow
......@@ -132,6 +133,7 @@ public class DebuggerMain implements Initializable {
@FXML
private Button interactive_undo;
private JavaArea javaArea = new JavaArea();
private DockNode javaAreaDock = new DockNode(javaArea, "Java Source",
new MaterialDesignIconView(MaterialDesignIcon.CODEPEN)
......@@ -149,6 +151,50 @@ public class DebuggerMain implements Initializable {
private Menu examplesMenu;
private Timer interpreterThreadTimer;
@Subscribe
public void handle(Events.ShowPostMortem spm){
FindNearestASTNode fna = new FindNearestASTNode(spm.getPosition());
List<PTreeNode<KeyData>> result =
model.getDebuggerFramework().getPtreeManager().getNodes()
.stream()
.filter(it -> Objects.equals(it.getStatement().accept(fna),it.getStatement()))
.collect(Collectors.toList());
System.out.println(result);
for (PTreeNode<KeyData> statePointerToPostMortem : result) {
if(statePointerToPostMortem != null && statePointerToPostMortem.getStateAfterStmt() != null) {
State<KeyData> stateBeforeStmt = statePointerToPostMortem.getStateBeforeStmt();
// stateBeforeStmt.getGoals().forEach(keyDataGoalNode -> System.out.println("BeforeSeq = " + keyDataGoalNode.getData().getNode().sequent()));
State<KeyData> stateAfterStmt = statePointerToPostMortem.getStateAfterStmt();
// stateAfterStmt.getGoals().forEach(keyDataGoalNode -> System.out.println("AfterSeq = " + keyDataGoalNode.getData().getNode().sequent()));
/*List<GoalNode<KeyData>> list = stateAfterStmt.getGoals().stream().filter(keyDataGoalNode ->
keyDataGoalNode.getData().getNode().parent().equals(stateBeforeStmt.getSelectedGoalNode().getData().getNode())
).collect(Collectors.toList());
list.forEach(keyDataGoalNode -> System.out.println("list = " + keyDataGoalNode.getData().getNode().sequent()));*/
InspectionModel im = new InspectionModel();
ObservableList<GoalNode<KeyData>> goals = FXCollections.observableArrayList(stateAfterStmt.getGoals());
im.setGoals(goals);
if(stateAfterStmt.getSelectedGoalNode() != null){
im.setSelectedGoalNodeToShow(stateAfterStmt.getSelectedGoalNode());
} else {
im.setSelectedGoalNodeToShow(goals.get(0));
}
inspectionViewsController.newPostMortemInspector(im)
.dock(dockStation, DockPos.CENTER, getActiveInspectorDock());
} else {
statusBar.publishErrorMessage("There is no post mortem state to show to this node, because this node was not executed.");
}
}
}
@Subscribe
public void handle(Events.ShowSequent ss) {
SequentView sv = new SequentView();
......@@ -191,7 +237,7 @@ public class DebuggerMain implements Initializable {
private void init() {
Events.register(this);
model.setDebugMode(false);
// model.setDebugMode(false);
scriptController = new ScriptController(dockStation);
interactiveModeController = new InteractiveModeController(scriptController);
btnInteractiveMode.setSelected(false);
......@@ -278,6 +324,36 @@ public class DebuggerMain implements Initializable {
proofTreeDock,
DockPos.LEFT);
//if threadstate finished, stepping should still be possible
BooleanBinding disableStepping = FACADE.loadingProperty().
or(FACADE.proofProperty().isNull()).
or(model.interpreterStateProperty().isNotEqualTo(InterpreterThreadState.WAIT));
/* model.statePointerProperty().addListener((observable, oldValue, newValue) -> {
//set all steppings -> remove binding
if(newValue.getStepInvOver() != null)
model.setStepReturnPossible(true);
if(newValue.getStepOver() != null)
model.setStepOverPossible(true);
if(newValue.getStepInvInto() != null)
model.setStepBackPossible(true);
if(newValue.getStepInto() != null)
model.setStepIntoPossible(true);
});*/
model.stepBackPossibleProperty().bind(disableStepping);
model.stepIntoPossibleProperty().bind(disableStepping);
model.stepOverPossibleProperty().bind(disableStepping);
model.stepReturnPossibleProperty().bind(disableStepping);
model.executeNotPossibleProperty().bind(FACADE.loadingProperty().or(FACADE.proofProperty().isNull()));
statusBar.interpreterStatusModelProperty().bind(model.interpreterStateProperty());
renewThreadStateTimer();
}
......@@ -320,6 +396,9 @@ public class DebuggerMain implements Initializable {
}
/**
* Connect the Javacode area with the model and the rest of the GUI
*/
private void marriageJavaCode() {
//Listener on chosenContract from
model.chosenContractProperty().addListener(o -> {
......@@ -428,7 +507,7 @@ public class DebuggerMain implements Initializable {
assert model.getDebuggerFramework() == null : "There should not be any interpreter running.";
if (FACADE.getProofState() == KeYProofFacade.ProofState.EMPTY) {
Alert alert = new Alert(Alert.AlertType.ERROR, "No proof loaded!", ButtonType.OK);
Alert alert = new Alert(Alert.AlertType.INFORMATION, "No proof loaded is loaded yet. If proof loading was onvoked, please wait. Loading may take a while.", ButtonType.OK);
alert.showAndWait();
return;
}
......@@ -523,6 +602,7 @@ public class DebuggerMain implements Initializable {
*/
private void executeScript(InterpreterBuilder ib, boolean addInitBreakpoint) {
try {
Set<Breakpoint> breakpoints = scriptController.getBreakpoints();
// get possible scripts and the main script!
List<ProofScript> scripts = scriptController.getCombinedAST();
......@@ -542,6 +622,59 @@ public class DebuggerMain implements Initializable {
LOGGER.debug("MainScript: {}", ms.getName());
ib.setScripts(scripts);
executeScript0(ib, breakpoints, ms, addInitBreakpoint);
} catch (RecognitionException e) {
LOGGER.error(e);
Utils.showExceptionDialog("Antlr Exception", "", "Could not parse scripts.", e);
}
}
private void executeScriptFromSavePoint(InterpreterBuilder ib, SavePoint point) {
try {
Set<Breakpoint> breakpoints = scriptController.getBreakpoints();
// get possible scripts and the main script!
List<ProofScript> scripts = scriptController.getCombinedAST();
if (scriptController.getMainScript() == null) {
scriptController.setMainScript(scripts.get(0));
}
Optional<ProofScript> mainScript = scriptController.getMainScript().find(scripts);
ProofScript ms;
if (!mainScript.isPresent()) {
scriptController.setMainScript(scripts.get(0));
ms = scripts.get(0);
} else {
ms = mainScript.get();
}
Statements body = new Statements();
boolean flag =false;
for (int i = 0; i < ms.getBody().size(); i++) {
if(flag) {body.add(ms.getBody().get(i));
continue;}
flag = point.isThisStatement(ms.getBody().get(i));
}
ms.setBody(body);
LOGGER.debug("Parsed Scripts, found {}", scripts.size());
LOGGER.debug("MainScript: {}", ms.getName());
//ib.setDirectory(model.getKeyFile() != null ? model.getKeyFile() : model.getJavaFile());
ib.setScripts(scripts);
executeScript0(ib, breakpoints, ms, false);
} catch (RecognitionException e) {
LOGGER.error(e);
Utils.showExceptionDialog("Antlr Exception", "", "Could not parse scripts.", e);
}
}
private void executeScript0(InterpreterBuilder ib,
Collection<? extends Breakpoint> breakpoints,
ProofScript ms, boolean addInitBreakpoint) {
KeyInterpreter interpreter = ib.build();
DebuggerFramework<KeyData> df = new DebuggerFramework<>(interpreter, ms, null);
df.setSucceedListener(this::onInterpreterSucceed);
......@@ -552,12 +685,7 @@ public class DebuggerMain implements Initializable {
df.getBreakpoints().addAll(breakpoints);
df.getStatePointerListener().add(this::handleStatePointer);
df.start();
model.setDebuggerFramework(df);
} catch (RecognitionException e) {
LOGGER.error(e);
Utils.showExceptionDialog("Antlr Exception", "", "Could not parse scripts.", e);
}
}
private void onInterpreterSucceed(DebuggerFramework<KeyData> keyDataDebuggerFramework) {
......@@ -711,10 +839,13 @@ public class DebuggerMain implements Initializable {
if (keyFile != null) {
model.setKeyFile(keyFile);
model.setInitialDirectory(keyFile.getParentFile());
Task<ProofApi> task = FACADE.loadKeyFileTask(keyFile);
task.setOnSucceeded(event -> {
statusBar.publishMessage("Loaded key sourceName: %s", keyFile);
statusBar.stopProgress();
});
task.setOnFailed(event -> {
......@@ -925,7 +1056,7 @@ public class DebuggerMain implements Initializable {
*/
public void saveProof(ActionEvent actionEvent) {
FileChooser fc = new FileChooser();
File file = fc.showOpenDialog(btnInteractiveMode.getScene().getWindow());
File file = fc.showSaveDialog(btnInteractiveMode.getScene().getWindow());
if (file != null) {
try {
saveProof(file);
......@@ -1182,7 +1313,7 @@ public class DebuggerMain implements Initializable {
public void openInKey(@Nullable ActionEvent event) {
if (FACADE.getProofState() == KeYProofFacade.ProofState.EMPTY) {
Alert alert = new Alert(Alert.AlertType.ERROR, "No proof is loaded", ButtonType.OK);
Alert alert = new Alert(Alert.AlertType.INFORMATION, "No proof is loaded yet. If laoding a proof was invoked, proof state loading may take a while.", ButtonType.OK);
alert.show();
return;
}
......
......@@ -14,6 +14,7 @@ import edu.kit.iti.formal.psdbg.parser.ast.CallStatement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.antlr.v4.runtime.Token;
import java.util.List;
......@@ -144,4 +145,12 @@ public class Events {
public static class InsertAtTheEndOfMainScript {
private final String text;
}
@Data
@RequiredArgsConstructor
public static class ShowPostMortem {
private final String node;
private final int position;
}
}
......@@ -21,7 +21,7 @@ public class FindNearestASTNode implements ASTTraversal<ASTNode> {
return childOrMe(proofScript, proofScript.getSignature(), proofScript.getBody());
}
private ASTNode childOrMe(ASTNode me, Stream<? extends ASTNode> nodes) {
public ASTNode childOrMe(ASTNode me, Stream<? extends ASTNode> nodes) {
// range check
if (me == null) {
return null;
......
......@@ -217,7 +217,7 @@ public class InspectionView extends BorderPane {
if (goalOptionsMenu.getSelectedViewOption() != null) {
text = goalOptionsMenu.getSelectedViewOption().getText(item);
}
//setStyle("-fx-font-size: 12pt;");
//TODO for ScreenshotsetStyle("-fx-font-size: 18pt;");
setText(text);
}
}
......
......@@ -47,8 +47,10 @@ public class InspectionViewsController {
public DockNode newPostMortemInspector(InspectionModel im) {
InspectionView iv = new InspectionView();
iv.getGoalView().setItems(im.getGoals());
iv.getModel().setSelectedGoalNodeToShow(im.getSelectedGoalNodeToShow());
Node node = ((KeyData) iv.getModel().getSelectedGoalNodeToShow().getData()).getNode();
String title = "Post-Mortem";
if (node != null) {
iv.getSequentView().setNode(node);
......
......@@ -434,6 +434,7 @@ public class ProofTree extends BorderPane {
tftc.setStyle("-fx-background-color: " + colorOfNodes.get(n) + ";");
}
}
//TODO for Screenshot tftc.setStyle("-fx-font-size: 18pt");
/* if (colorOfNodes.containsKey(n)) {
tftc.setStyle("-fx-border-color: "+colorOfNodes.get(n)+";");
}*/
......
......@@ -130,8 +130,6 @@ public class ScriptArea extends BorderPane {
private ListProperty<LintProblem> problems = new SimpleListProperty<>(FXCollections.observableArrayList());
private SimpleObjectProperty<CharacterHit> currentMouseOver = new SimpleObjectProperty<>();
private ScriptAreaContextMenu contextMenu = new ScriptAreaContextMenu();
private Consumer<Token> onPostMortem = token -> {
};
@Getter
@Setter
private List<InlineActionSupplier> inlineActionSuppliers = new ArrayList<>();
......@@ -280,7 +278,7 @@ public class ScriptArea extends BorderPane {
LOGGER.debug("ScriptArea.updateMainScriptMarker");
if (ms != null && filePath.get().getAbsolutePath().equals(ms.getSourceName())) {
System.out.println(ms);
LOGGER.debug("ScriptArea.updateIdentifier"+ ms);
CharStream stream = CharStreams.fromString(codeArea.getText(), filePath.get().getAbsolutePath());
Optional<ProofScript> ps = ms.find(Facade.getAST(stream));
......@@ -519,13 +517,6 @@ public class ScriptArea extends BorderPane {
d.show((Node) event.getTarget(), event.getScreenX(), event.getScreenY());
}
public Consumer<Token> getOnPostMortem() {
return onPostMortem;
}
public void setOnPostMortem(Consumer<Token> onPostMortem) {
this.onPostMortem = onPostMortem;
}
public ObservableSet<RegionStyle> getMarkedRegions() {
return markedRegions.get();
......@@ -1734,8 +1725,8 @@ public class ScriptArea extends BorderPane {
CharacterHit pos = currentMouseOver.get();
Token node = Utils.findToken(getText(), pos.getInsertionIndex());
onPostMortem.accept(node);
Events.fire(new Events.ShowPostMortem(node.toString(), node.getStopIndex()));
//TODO forward to ProofTreeManager, it jumps to the node and this should be done via the callbacks.
/*ScriptArea area = ScriptArea.this;
......
......@@ -11,15 +11,20 @@ import edu.kit.iti.formal.psdbg.gui.actions.inline.InlineActionSupplier;
import edu.kit.iti.formal.psdbg.gui.controller.Events;
import edu.kit.iti.formal.psdbg.gui.model.MainScriptIdentifier;
import edu.kit.iti.formal.psdbg.gui.actions.acomplete.Suggestion;
import edu.kit.iti.formal.psdbg.interpreter.data.SavePoint;
import edu.kit.iti.formal.psdbg.interpreter.dbg.Breakpoint;
import edu.kit.iti.formal.psdbg.parser.Facade;
import edu.kit.iti.formal.psdbg.parser.ast.ASTNode;
import edu.kit.iti.formal.psdbg.parser.ast.CallStatement;
import edu.kit.iti.formal.psdbg.parser.ast.ProofScript;
import edu.kit.iti.formal.psdbg.parser.ast.Statement;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.ObservableMap;
import lombok.Getter;
import lombok.Setter;
......@@ -64,10 +69,37 @@ public class ScriptController {
@Setter
private DefaultAutoCompletionController autoCompleter = new DefaultAutoCompletionController();
public ScriptController(DockPane parent) {
this.parent = parent;
Events.register(this);
addDefaultInlineActions();
mainScript.addListener((p,o,n)-> {
if(o!=null)
o.getScriptArea().textProperty().removeListener( a-> updateSavePoints());
n.getScriptArea().textProperty().addListener(a->updateSavePoints());
updateSavePoints();
});
}
private ObservableList<SavePoint> mainScriptSavePoints
= new SimpleListProperty<>(FXCollections.observableArrayList());
private void updateSavePoints() {
Optional<ProofScript> ms = getMainScript().find(getCombinedAST());
if(ms.isPresent()) {
List<SavePoint> list = ms.get().getBody().stream()
.filter(SavePoint::isSaveCommand)
.map(a -> (CallStatement) a)
.map(SavePoint::new)
.collect(Collectors.toList());
mainScriptSavePoints.setAll(list);
}
}
private void addDefaultInlineActions() {
......@@ -361,5 +393,11 @@ public class ScriptController {
}
}
public ObservableList<SavePoint> getMainScriptSavePoints() {
return mainScriptSavePoints;
}
public void setMainScriptSavePoints(ObservableList<SavePoint> mainScriptSavePoints) {
this.mainScriptSavePoints = mainScriptSavePoints;
}
}
\ No newline at end of file
......@@ -6,9 +6,10 @@ import de.uka.ilkd.key.logic.Term;
import de.uka.ilkd.key.pp.*;
import edu.kit.iti.formal.psdbg.interpreter.data.GoalNode;
import edu.kit.iti.formal.psdbg.interpreter.data.KeyData;
import edu.kit.iti.formal.psdbg.termmatcher.MatcherFacade;
import edu.kit.iti.formal.psdbg.termmatcher.Matchings;
import edu.kit.iti.formal.psdbg.termmatcher.mp.MatchPath;
import edu.kit.iti.formal.psdbg.interpreter.matcher.KeyMatcherFacade;
import edu.kit.iti.formal.psdbg.interpreter.matcher.Match;
import edu.kit.iti.formal.psdbg.interpreter.matcher.MatchPath;
import edu.kit.iti.formal.psdbg.interpreter.matcher.Matchings;
import javafx.beans.Observable;
import javafx.beans.property.ListProperty;
import javafx.beans.property.ObjectProperty;
......@@ -24,6 +25,7 @@ import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import org.controlsfx.control.StatusBar;
import java.util.HashMap;
import java.util.Map;
......@@ -47,11 +49,12 @@ public class SequentMatcher extends BorderPane {
@FXML
private TextArea matchpattern;
@FXML
private ListView<Map<String, MatchPath>> matchingsView;
private ListView<Match> matchingsView;
@FXML
private Label nomatchings; //only shown when no matchings found, else always hidden
private Map<PosInOccurrence, Range> cursorPosition = new HashMap<>();
public SequentMatcher(Services services) {
this.services = services;
......@@ -66,8 +69,13 @@ public class SequentMatcher extends BorderPane {
);
goalView.getSelectionModel().selectedItemProperty().addListener((prop, old, nnew) ->
selectedGoalNodeToShow.setValue(nnew)
);
{
if (nnew != null) {
selectedGoalNodeToShow.setValue(nnew);
} else {
selectedGoalNodeToShow.setValue(old);
}
});