Commit 3e566e4a authored by sarah.grebing's avatar sarah.grebing

Merge branch 'luong_workbranch' into 'master'

Luong workbranch

See merge request !20
parents 83df2985 a19583e8
Pipeline #22444 passed with stages
in 3 minutes and 31 seconds
...@@ -14,7 +14,7 @@ public class ASTDiff extends DefaultASTVisitor<ASTNode> { ...@@ -14,7 +14,7 @@ public class ASTDiff extends DefaultASTVisitor<ASTNode> {
newScript.setSignature(proofScript.getSignature()); newScript.setSignature(proofScript.getSignature());
other = ((ProofScript) other).getBody(); other = ((ProofScript) other).getBody();
newScript.setBody(visit(newScript.getBody())); newScript.setBody(visit(proofScript.getBody()));
return newScript; return newScript;
} }
...@@ -61,12 +61,13 @@ public class ASTDiff extends DefaultASTVisitor<ASTNode> { ...@@ -61,12 +61,13 @@ public class ASTDiff extends DefaultASTVisitor<ASTNode> {
int i = 0; int i = 0;
for (; i < statements.size(); i++) { for (; i < statements.size(); i++) {
if (statements.get(i).eq(other.get(i))) { if (!statements.get(i).isSame(other.get(i))) {
break; System.out.println("Alter Script wurde verändert");
return null;
} }
} }
for (int j = i; j < other.size(); j++) { for (; i < other.size(); i++) {
s.add(other.get(i)); s.add(other.get(i));
} }
......
...@@ -167,6 +167,11 @@ public abstract class ASTNode<T extends ParserRuleContext> ...@@ -167,6 +167,11 @@ public abstract class ASTNode<T extends ParserRuleContext>
return Objects.hash(getRuleContext()); return Objects.hash(getRuleContext());
} }
//TODO: param + class
public boolean isSame(ASTNode other) {
return this.getNodeName().equals(other.getNodeName());
}
public int getSyntaxWidth() { public int getSyntaxWidth() {
if (ruleContext != null) { if (ruleContext != null) {
return ruleContext.stop.getStopIndex() return ruleContext.stop.getStopIndex()
......
...@@ -225,9 +225,10 @@ public class InterpreterBuilder { ...@@ -225,9 +225,10 @@ public class InterpreterBuilder {
public InterpreterBuilder setProblemPath(File path){ public InterpreterBuilder setProblemPath(File path){
Map<String, CommandHandler<KeyData>> builtinsnew = this.bich.getBuiltins(); Map<String, CommandHandler<KeyData>> builtinsnew = this.bich.getBuiltins();
SaveCommand sc = new SaveCommand(path);
builtinsnew.put(SaveCommand.SAVE_COMMAND_NAME, sc); builtinsnew.put(SaveCommand.SAVE_COMMAND_NAME, new SaveCommand(path));
this.bich.setBuiltins(builtinsnew); this.bich.setBuiltins(builtinsnew);
return this; return this;
} }
......
...@@ -63,7 +63,8 @@ public class SaveCommand implements CommandHandler<KeyData> { ...@@ -63,7 +63,8 @@ public class SaveCommand implements CommandHandler<KeyData> {
Semaphore semaphore = new Semaphore(0); Semaphore semaphore = new Semaphore(0);
Platform.runLater(() -> { Platform.runLater(() -> {
Alert a = new Alert(Alert.AlertType.CONFIRMATION); Alert a = new Alert(Alert.AlertType.CONFIRMATION);
a.setTitle("Foo"); a.setTitle("Overwrite proof file");
a.setContentText("Overwrite existing proof file \"" + sp.getName()+"\" (line "+ sp.getLineNumber() +") ?");
Optional<ButtonType> buttonType = a.showAndWait(); Optional<ButtonType> buttonType = a.showAndWait();
if(buttonType.isPresent() && buttonType.get() == ButtonType.OK){ if(buttonType.isPresent() && buttonType.get() == ButtonType.OK){
execute.set(true); execute.set(true);
...@@ -86,10 +87,7 @@ public class SaveCommand implements CommandHandler<KeyData> { ...@@ -86,10 +87,7 @@ public class SaveCommand implements CommandHandler<KeyData> {
} }
@Override
public boolean isUninterpretedParams(CallStatement call) {
return true;
}
} }
......
...@@ -599,7 +599,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -599,7 +599,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
private VariableAssignment evaluateParametersStateLess(Parameters parameters) { private VariableAssignment evaluateParametersStateLess(Parameters parameters) {
VariableAssignment va = new VariableAssignment(); VariableAssignment va = new VariableAssignment();
Evaluator<T> evaluator = createEvaluator(null, null); Evaluator<T> evaluator = new Evaluator<>(null, null);
parameters.entrySet().forEach(entry -> { parameters.entrySet().forEach(entry -> {
try { try {
......
...@@ -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 alice.tuprolog.InvalidLibraryException; import alice.tuprolog.InvalidLibraryException;
import alice.tuprolog.InvalidTheoryException; import alice.tuprolog.InvalidTheoryException;
import antlr.collections.AST;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView; import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView;
...@@ -25,6 +26,7 @@ import edu.kit.iti.formal.psdbg.gui.graph.GraphView; ...@@ -25,6 +26,7 @@ import edu.kit.iti.formal.psdbg.gui.graph.GraphView;
import edu.kit.iti.formal.psdbg.gui.model.DebuggerMainModel; import edu.kit.iti.formal.psdbg.gui.model.DebuggerMainModel;
import edu.kit.iti.formal.psdbg.gui.model.InspectionModel; import edu.kit.iti.formal.psdbg.gui.model.InspectionModel;
import edu.kit.iti.formal.psdbg.gui.model.InterpreterThreadState; import edu.kit.iti.formal.psdbg.gui.model.InterpreterThreadState;
import edu.kit.iti.formal.psdbg.gui.model.MainScriptIdentifier;
import edu.kit.iti.formal.psdbg.interpreter.InterpreterBuilder; import edu.kit.iti.formal.psdbg.interpreter.InterpreterBuilder;
import edu.kit.iti.formal.psdbg.interpreter.KeYProofFacade; import edu.kit.iti.formal.psdbg.interpreter.KeYProofFacade;
import edu.kit.iti.formal.psdbg.interpreter.KeyInterpreter; import edu.kit.iti.formal.psdbg.interpreter.KeyInterpreter;
...@@ -33,7 +35,12 @@ import edu.kit.iti.formal.psdbg.interpreter.data.KeyData; ...@@ -33,7 +35,12 @@ 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.SavePoint;
import edu.kit.iti.formal.psdbg.interpreter.data.State; import edu.kit.iti.formal.psdbg.interpreter.data.State;
import edu.kit.iti.formal.psdbg.interpreter.dbg.*; import edu.kit.iti.formal.psdbg.interpreter.dbg.*;
import edu.kit.iti.formal.psdbg.parser.ASTDiff;
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.CaseStatement;
import edu.kit.iti.formal.psdbg.parser.ast.ProofScript; import edu.kit.iti.formal.psdbg.parser.ast.ProofScript;
import edu.kit.iti.formal.psdbg.storage.KeyPersistentFacade;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.InvalidationListener; import javafx.beans.InvalidationListener;
import javafx.beans.binding.BooleanBinding; import javafx.beans.binding.BooleanBinding;
...@@ -54,6 +61,7 @@ import javafx.stage.FileChooser; ...@@ -54,6 +61,7 @@ import javafx.stage.FileChooser;
import javafx.stage.Modality; import javafx.stage.Modality;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.val;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -66,13 +74,16 @@ import org.reactfx.util.Timer; ...@@ -66,13 +74,16 @@ import org.reactfx.util.Timer;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.swing.*; import javax.swing.*;
import javax.xml.bind.JAXBException;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.im.InputContext; import java.awt.im.InputContext;
import java.io.File; import java.io.*;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.security.Permission;
import java.time.Duration; import java.time.Duration;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
...@@ -833,6 +844,9 @@ public class DebuggerMain implements Initializable { ...@@ -833,6 +844,9 @@ public class DebuggerMain implements Initializable {
@FXML @FXML
public void executeDiff() { public void executeDiff() {
//save old PT //save old PT
// Calculate top difference between current and last executed script // Calculate top difference between current and last executed script
// Find last state of common ASTNode // Find last state of common ASTNode
// Use this state to build new interpreter in proof tree controller. // Use this state to build new interpreter in proof tree controller.
...@@ -841,6 +855,36 @@ public class DebuggerMain implements Initializable { ...@@ -841,6 +855,36 @@ public class DebuggerMain implements Initializable {
} }
@Deprecated
public void incremental() {
ProofScript oldScript = null; //used to be global var, that was set in selectSavepoint()
if (oldScript == null) {
return;
}
ProofScript newScript = scriptController.getMainScript().byName(scriptController.getCombinedAST()).get();
ASTDiff astDiff = new ASTDiff();
ProofScript scriptdiff = astDiff.diff(oldScript, newScript);
ASTNode pruneAstNode = scriptdiff.getBody().get(0);
Set<PTreeNode<KeyData>> ptnodes = model.getDebuggerFramework().getPtreeManager().getNodes();
Iterator iterator = ptnodes.iterator();
while (iterator.hasNext()) {
PTreeNode<KeyData> ptn = (PTreeNode<KeyData>) iterator.next();
if(ptn.getStatement().eq(pruneAstNode)) {
getFacade().getProof().pruneProof(ptn.getStateBeforeStmt().getSelectedGoalNode().getData().getNode());
break;
}
}
scriptController.setMainScript(oldScript);
}
/** /**
* Continue after the interpreter has reached a breakpoint * Continue after the interpreter has reached a breakpoint
* *
...@@ -932,12 +976,12 @@ public class DebuggerMain implements Initializable { ...@@ -932,12 +976,12 @@ public class DebuggerMain implements Initializable {
@FXML @FXML
public void saveAsScript() throws IOException { public void saveAsScript() throws IOException {
File f = openFileChooserSaveDialog("Save script", "Save Script files", "kps"); FileChooser fc = new FileChooser();
if (f != null) { File file = fc.showSaveDialog(btnInteractiveMode.getScene().getWindow());
/* if(!f.exists()){ if (file != null) {
f.createNewFile(); saveScript(file);
}*/ } else {
saveScript(f); Utils.showInfoDialog("","Select a destination", "No valid path has been selected.");
} }
} }
...@@ -1149,16 +1193,43 @@ public class DebuggerMain implements Initializable { ...@@ -1149,16 +1193,43 @@ public class DebuggerMain implements Initializable {
@FXML @FXML
public void selectSavepoint(ActionEvent actionEvent) { public void selectSavepoint(ActionEvent actionEvent) {
if (cboSavePoints.getValue() != null) { //TODO remove highlight of SPs
stopDebugMode(actionEvent);
SavePoint selected = cboSavePoints.getValue(); SavePoint selected = cboSavePoints.getValue();
if (selected == null) {
Utils.showInfoDialog("Select Savepoint", "Select Savepoint", "There is no selected Savepoint. Select a Savepoint first.");
return;
}
//prune to savepoint if possible
boolean pruneable = false;
try{
Iterator<PTreeNode<KeyData>> iterator = model.getDebuggerFramework().getPtreeManager().getNodes().iterator();
PTreeNode<KeyData> pTreeNodeOfSave;
while (iterator.hasNext()) {
pTreeNodeOfSave = iterator.next();
if (pTreeNodeOfSave.getStatement().getStartPosition().getLineNumber() == selected.getLineNumber()) {
FACADE.getProof().pruneProof(pTreeNodeOfSave.getStateBeforeStmt().getSelectedGoalNode().getData().getNode());
inspectionViewsController.getActiveInspectionViewTab().activate(pTreeNodeOfSave, pTreeNodeOfSave.getStateAfterStmt());
break;
}
}
//TODO: refresh GUI (Context + Script)
//State<KeyData> proofstate = KeyPersistentFacade.read(FACADE.getEnvironment(), FACADE.getProof(), new StringReader());
} catch (Exception ex){
//Hard Loading of Savepoint
stopDebugMode(actionEvent);
try { try {
abortExecution(); abortExecution();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
/** /**
* reload with selected savepoint * reload with selected savepoint
*/ */
...@@ -1166,6 +1237,7 @@ public class DebuggerMain implements Initializable { ...@@ -1166,6 +1237,7 @@ public class DebuggerMain implements Initializable {
handleStatePointerUI(null); handleStatePointerUI(null);
//reload getInspectionViewsController().getActiveInspectionViewTab().getModel() //reload getInspectionViewsController().getActiveInspectionViewTab().getModel()
InspectionModel iModel = getInspectionViewsController().getActiveInspectionViewTab().getModel(); InspectionModel iModel = getInspectionViewsController().getActiveInspectionViewTab().getModel();
//iModel.setHighlightedJavaLines(FXCollections.emptyObservableSet()); //iModel.setHighlightedJavaLines(FXCollections.emptyObservableSet());
iModel.clearHighlightLines(); iModel.clearHighlightLines();
iModel.getGoals().clear(); iModel.getGoals().clear();
...@@ -1181,6 +1253,8 @@ public class DebuggerMain implements Initializable { ...@@ -1181,6 +1253,8 @@ public class DebuggerMain implements Initializable {
LOGGER.info("Reloaded Successfully"); LOGGER.info("Reloaded Successfully");
statusBar.publishMessage("Reloaded Sucessfully"); statusBar.publishMessage("Reloaded Sucessfully");
} }
} catch (ProofInputException | ProblemLoaderException e) { } catch (ProofInputException | ProblemLoaderException e) {
LOGGER.error(e); LOGGER.error(e);
Utils.showExceptionDialog("Loading Error", "Could not clear Environment", Utils.showExceptionDialog("Loading Error", "Could not clear Environment",
...@@ -1188,9 +1262,22 @@ public class DebuggerMain implements Initializable { ...@@ -1188,9 +1262,22 @@ public class DebuggerMain implements Initializable {
e e
); );
} }
}
//Update Gui
MainScriptIdentifier msi = scriptController.getMainScript();
msi.getScriptArea().setSavepointMarker(selected.getLineNumber());
scriptController.getMainScript().getScriptArea().underlineSavepoint(selected);
// executeScriptFromSavePoint(interpreterBuilder, selected);
try {
KeyPersistentFacade.read(FACADE.getEnvironment(), FACADE.getProof(), new StringReader(selected.getPersistedStateFile(FACADE.getFilepath()).toString()));
} catch (JAXBException e) {
e.printStackTrace();
} }
scriptExecutionController.executeScriptFromSavePoint(interpreterBuilder, selected);
} }
...@@ -1279,22 +1366,34 @@ public class DebuggerMain implements Initializable { ...@@ -1279,22 +1366,34 @@ public class DebuggerMain implements Initializable {
public void openInKey(@Nullable ActionEvent event) { public void openInKey(@Nullable ActionEvent event) {
if (FACADE.getProofState() == KeYProofFacade.ProofState.EMPTY) { if (FACADE.getProofState() == KeYProofFacade.ProofState.EMPTY) {
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 alert = new Alert(Alert.AlertType.INFORMATION, "No proof is loaded yet. If loading a proof was invoked, proof state loading may take a while.", ButtonType.OK);
alert.show(); alert.show();
return; return;
} }
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
SecurityManager secManager = new KeYSecurityManager();
System.setSecurityManager(secManager);
// Swing Thread! // Swing Thread!
try {
MainWindow keyWindow = MainWindow.getInstance(); MainWindow keyWindow = MainWindow.getInstance();
keyWindow.addProblem(new SingleProof(FACADE.getProof(), "script")); keyWindow.addProblem(new SingleProof(FACADE.getProof(), "script"));
//keyWindow.getProofList().getModel().addProof(); //keyWindow.getProofList().getModel().addProof();
keyWindow.makePrettyView(); keyWindow.makePrettyView();
keyWindow.setVisible(true); keyWindow.setVisible(true);
} catch (SecurityException e) {
e.printStackTrace();
}
}); });
} }
public class ContractLoaderService extends Service<List<Contract>> { public class ContractLoaderService extends Service<List<Contract>> {
@Override @Override
protected void succeeded() { protected void succeeded() {
...@@ -1441,6 +1540,17 @@ public class DebuggerMain implements Initializable { ...@@ -1441,6 +1540,17 @@ public class DebuggerMain implements Initializable {
} }
} }
private class KeYSecurityManager extends SecurityManager {
@Override public void checkExit(int status) {
throw new SecurityException();
}
@Override public void checkPermission(Permission perm) {
// Allow other activities by default
}
}
//endregion //endregion
} }
//deprecated //deprecated
......
...@@ -110,7 +110,7 @@ public class InteractiveModeController { ...@@ -110,7 +110,7 @@ public class InteractiveModeController {
*/ */
public void undo(javafx.event.ActionEvent actionEvent) { public void undo(javafx.event.ActionEvent actionEvent) {
if (savepointslist.isEmpty()) { if (savepointslist.isEmpty()) {
Debug.log("Kein vorheriger Zustand."); //TODO: events fire Debug.log("Kein vorheriger Zustand.");
return; return;
} }
......
...@@ -8,7 +8,9 @@ import edu.kit.iti.formal.psdbg.interpreter.KeYProofFacade; ...@@ -8,7 +8,9 @@ import edu.kit.iti.formal.psdbg.interpreter.KeYProofFacade;
import edu.kit.iti.formal.psdbg.interpreter.KeyInterpreter; import edu.kit.iti.formal.psdbg.interpreter.KeyInterpreter;
import edu.kit.iti.formal.psdbg.interpreter.data.SavePoint; import edu.kit.iti.formal.psdbg.interpreter.data.SavePoint;
import edu.kit.iti.formal.psdbg.interpreter.dbg.Breakpoint; import edu.kit.iti.formal.psdbg.interpreter.dbg.Breakpoint;
import edu.kit.iti.formal.psdbg.parser.ASTDiff;
import edu.kit.iti.formal.psdbg.parser.Facade; 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.ProofScript; import edu.kit.iti.formal.psdbg.parser.ast.ProofScript;
import edu.kit.iti.formal.psdbg.parser.ast.Statements; import edu.kit.iti.formal.psdbg.parser.ast.Statements;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
...@@ -160,5 +162,10 @@ public class ScriptExecutionController { ...@@ -160,5 +162,10 @@ public class ScriptExecutionController {
} }
private ASTNode calculateDiff (ASTDiff dff) {
return null;
}
} }
...@@ -29,11 +29,9 @@ import javafx.scene.control.cell.TextFieldTreeCell; ...@@ -29,11 +29,9 @@ import javafx.scene.control.cell.TextFieldTreeCell;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.util.StringConverter; import javafx.util.StringConverter;
import lombok.*; import lombok.*;
import sun.reflect.generics.tree.Tree;
import java.util.HashMap; import java.util.*;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
...@@ -327,12 +325,14 @@ public class ProofTree extends BorderPane { ...@@ -327,12 +325,14 @@ public class ProofTree extends BorderPane {
} }
@AllArgsConstructor @AllArgsConstructor
private static class TreeNode { private static class TreeNode {
String label; String label;
Node node; Node node;
} }
class TreeTransformationKey { class TreeTransformationKey {
public TreeItem<TreeNode> create(Proof proof) { public TreeItem<TreeNode> create(Proof proof) {
...@@ -414,6 +414,7 @@ public class ProofTree extends BorderPane { ...@@ -414,6 +414,7 @@ public class ProofTree extends BorderPane {
} }
@RequiredArgsConstructor @RequiredArgsConstructor
class TreeTransformationScript extends TreeTransformationKey { class TreeTransformationScript extends TreeTransformationKey {
final ProofTreeManager<KeyData> manager; final ProofTreeManager<KeyData> manager;
...@@ -472,5 +473,44 @@ public class ProofTree extends BorderPane { ...@@ -472,5 +473,44 @@ public class ProofTree extends BorderPane {
TreeItem<TreeNode> ti = new TreeItem<>(new TreeNode(lbl, n)); TreeItem<TreeNode> ti = new TreeItem<>(new TreeNode(lbl, n));
return ti; return ti;
} }
//TODO: Reverse ArrayList in the end or nah?
@Deprecated
public ArrayList<String> getBranchLabels (TreeNode node) {
TreeItem<TreeNode> proofTree = create(proof.get());
ArrayList<String> branchlabels = new ArrayList<>();
int i = 0;
branchlabels.set(0, node.label);
while (node != null) {
if(!branchlabels.get(i).equals(node.label)) {
i++;
branchlabels.set(i, node.label);
}
//TODO: node = node.parent
}
return branchlabels;
}
public ArrayList<String> getBranchLabels (Node node) {