Commit 58789c46 authored by Alexander Weigl's avatar Alexander Weigl

cleaning up save point

* consolelogger
* fixes ... change to #save
parent bdab4f23
Pipeline #21799 passed with stages
in 3 minutes and 23 seconds
allprojects {
apply plugin: 'maven'
group = 'edu.kit.iti.formal.psdbg'
version = 'Experimental-1.1'
version = '1.1-experimental'
}
subprojects {
......
......@@ -4,26 +4,23 @@ import edu.kit.iti.formal.psdbg.interpreter.Interpreter;
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.VariableAssignment;
import edu.kit.iti.formal.psdbg.interpreter.funchdl.BuiltinCommands;
import edu.kit.iti.formal.psdbg.interpreter.funchdl.CommandHandler;
import edu.kit.iti.formal.psdbg.parser.ast.CallStatement;
import edu.kit.iti.formal.psdbg.parser.ast.Parameters;
import edu.kit.iti.formal.psdbg.parser.data.Value;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import sun.security.ssl.Debug;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.sql.Savepoint;
import java.util.ArrayList;
import java.util.List;
public class SaveCommand implements CommandHandler<KeyData>{
public class SaveCommand implements CommandHandler<KeyData> {
private static final String SAVE_COMMAND_NAME = "#save";
private static Logger logger = LogManager.getLogger(SaveCommand.class);
private static Logger consoleLogger = LogManager.getLogger("console");
@Getter @Setter
@Getter
@Setter
private File path;
public SaveCommand(File path) {
......@@ -33,7 +30,7 @@ public class SaveCommand implements CommandHandler<KeyData>{
@Override
public boolean handles(CallStatement call, @Nullable KeyData data) throws IllegalArgumentException {
return call.getCommand().equals("save");
return call.getCommand().equals(SAVE_COMMAND_NAME);
}
@Override
......@@ -41,18 +38,20 @@ public class SaveCommand implements CommandHandler<KeyData>{
//be careful parameters are uninterpreted
SavePoint sp = new SavePoint(call);
//Not via Parentpath -> dependency on OS
String parentpath = path.getAbsolutePath();
parentpath = parentpath.substring(0, parentpath.length() - path.getName().length());
/* String parentPath = path.getAbsolutePath();
parentPath = parentPath.substring(0, parentPath.length() - path.getName().length());*/
File parent = path.getParentFile();
File newFile = sp.getProofFile(parent);
consoleLogger.info("(Safepoint) Location to be saved to = " + newFile.getAbsolutePath());
File newfile = new File(parentpath + sp.getSavepointName() + ".key");
System.out.println("(Safepoint) Location to be saved to = " + newfile.getAbsolutePath());
try {
interpreter.getSelectedNode().getData().getProof().saveToFile(newfile);
interpreter.getSelectedNode().getData().getProof().saveToFile(newFile);
//TODO Call to key persistend facade
} catch (IOException e) {
e.printStackTrace();
}
}
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
https://logging.apache.org/log4j/2.x/manual/configuration.html
-->
<Configuration status="error">
<Appenders>
<Console name="ConsoleErr" target="SYSTEM_ERR">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5level] %msg%n"/>
<!--<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>-->
<PatternLayout>
<!-- <pattern>%d %highlight{%p} %style{%C{1.} [%t] %m}{bold,green}%n</pattern>-->
<pattern>%r %highlight{%p} %style{[%t] %m}{bold,green} \n\t\tfrom %l%n</pattern>
</PatternLayout>
</Console>
<File name="F" fileName="debug.log" bufferSize="0" bufferedIO="false" append="false">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="Console" level="warn"/>
<AppenderRef ref="ConsoleErr" level="error"/>
<AppenderRef ref="F"/>
</Root>
<Logger name="console">
<AppenderRef ref="Console" level="info"/>
</Logger>
</Loggers>
</Configuration>
package edu.kit.iti.formal.psdbg.interpreter.data;
import com.google.errorprone.annotations.Var;
import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor;
import edu.kit.iti.formal.psdbg.parser.ast.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.io.File;
@Data
@RequiredArgsConstructor
public class SavePoint {
@AllArgsConstructor
public class SavePoint {
private final String name;
private int startOffset = -1;
private int endOffset = -1;
private int lineNumer = -1;
private ForceOption force = ForceOption.YES;
private final String savepointName;
private int start = -1;
private int end = -1;
public SavePoint(CallStatement call){
if(isSaveCommand(call)){
public SavePoint(CallStatement call) {
if (isSaveCommand(call)) {
Parameters p = call.getParameters();
savepointName = ((StringLiteral) p.get(new Variable("#2"))).getText();
start = call.getRuleContext().getStart().getStartIndex();
end = call.getRuleContext().getStart().getStopIndex();
} else {
throw new IllegalArgumentException(call.getCommand()+" is not a save statement");
}}
name = evalAsText(p, "#2", "not-available");
force = ForceOption.valueOf(evalAsText(p, "force", "yes").toUpperCase());
public static boolean isSaveCommand(CallStatement call){
return (call.getCommand().equals("save"));
try {
startOffset = call.getRuleContext().getStart().getStartIndex();
endOffset = call.getRuleContext().getStart().getStopIndex();
lineNumer = call.getRuleContext().getStart().getLine();
} catch (NullPointerException npe) {
}
} else {
throw new IllegalArgumentException(call.getCommand() + " is not a save statement");
}
}
public File getProofFile(File dir){
return new File(dir, savepointName+".proof");
public static boolean isSaveCommand(CallStatement call) {
return (call.getCommand().equals("#save"));
}
public static boolean isSaveCommand(Statement statement) {
try{
try {
CallStatement c = (CallStatement) statement;
return isSaveCommand(c);
}catch (ClassCastException e) {
} catch (ClassCastException e) {
return false;
}
}
public boolean exists(File dir) {
return getProofFile(dir).exists() && getPersistedStateFile(dir).exists();
}
public static String evalAsText(Parameters p, String key, String defaultValue) {
Variable k = new Variable(key);
if (!p.containsKey(k)) {
return defaultValue;
}
return (String) p.get(k).accept(new DefaultASTVisitor<String>() {
@Override
public String defaultVisit(ASTNode node) {
throw new IllegalArgumentException();
}
@Override
public String visit(Variable variable) {
return variable.getIdentifier();
}
@Override
public String visit(StringLiteral stringLiteral) {
return stringLiteral.getText();
}
@Override
public String visit(BooleanLiteral booleanLiteral) {
return Boolean.toString(booleanLiteral.isValue());
}
@Override
public String visit(IntegerLiteral integer) {
return (integer.getValue().toString());
}
});
}
public File getProofFile(File dir) {
return new File(dir, name + ".proof");
}
public File getPersistedStateFile(File dir) {
return new File(dir, name + ".psdbgstate.xml");
}
public boolean isThisStatement(Statement statement) {
if(isSaveCommand(statement)){
if (isSaveCommand(statement)) {
CallStatement c = (CallStatement) statement;
return c.getCommand().equals(savepointName);
return c.getCommand().equals(name);
}
return false;
}
public enum ForceOption {
YES, NO, INTERACTIVE;
}
}
......@@ -34,6 +34,8 @@ public class ProofScriptDebugger extends Application {
public static final String KEY_VERSION = KeYConstants.VERSION;
private Logger logger = LogManager.getLogger("psdbg");
private static Logger consoleLogger = LogManager.getLogger("console");
public static void main(String[] args) {
launch(args);
......@@ -65,6 +67,8 @@ public class ProofScriptDebugger extends Application {
logger.info("KeY Version: " + KeYConstants.VERSION);
logger.info("KeY Internal: " + KeYConstants.INTERNAL_VERSION);
consoleLogger.info("Welcome!");
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
......
package edu.kit.iti.formal.psdbg.gui.controller;
import edu.kit.iti.formal.psdbg.interpreter.data.SavePoint;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.ListProperty;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.util.StringConverter;
import lombok.RequiredArgsConstructor;
import java.util.ArrayList;
import java.util.List;
/**
* @author Alexander Weigl
* @version 1 (17.05.18)
*/
@RequiredArgsConstructor
public class SavePointController {
private final DebuggerMain debuggerMain;
private final ListProperty<SavePoint> savePoints;
private final List<MenuItem> menuItemsExecuteFrom = new ArrayList<>();
private final List<MenuItem> menuItemsRollbackTo = new ArrayList<>();
private final BooleanBinding rollbackEnabled;
public SavePointController(DebuggerMain main) {
debuggerMain = main;
savePoints = main.scriptController.mainScriptSavePointsProperty();
rollbackEnabled = savePoints.emptyProperty().not()
/* .and(main.getModel().debuggerFrameworkProperty().isNotNull())
.and(main.getModel().interpreterStateProperty().isNotEqualTo(
InterpreterThreadState.RUNNING
))*/;
main.btnSavePointRollback.disableProperty().bind(rollbackEnabled.not());
main.cboSavePoints.setDisable(false);
main.cboSavePoints.setConverter(new StringConverter<SavePoint>() {
@Override
public String toString(SavePoint object) {
return String.format("%s (in line %d)",
object.getName(), object.getLineNumer());
}
@Override
public SavePoint fromString(String string) {
//not supported
return null;
}
});
/*savePoints.emptyProperty().addListener((prop, old, empty) -> {
debuggerMain.btnSavePointRollback.setDisable(empty);
debuggerMain.cboSavePoints.setDisable(empty);
});*/
main.cboSavePoints.setPlaceholder(new Label("No savepoint inside main script, or no main script selected."));
main.cboSavePoints.itemsProperty().bind(savePoints);
savePoints.addListener((a, b, c) -> updateStartInterpreter());
debuggerMain.buttonStartInterpreter.getItems().add(new SeparatorMenuItem());
}
private void updateStartInterpreter() {
debuggerMain.buttonStartInterpreter.getItems().removeAll(menuItemsExecuteFrom);
menuItemsRollbackTo.clear();
menuItemsExecuteFrom.clear();
int i = 0;
KeyCode[] quickStart = new KeyCode[]{
KeyCode.DIGIT1,
KeyCode.DIGIT2,
KeyCode.DIGIT3,
KeyCode.DIGIT4,
KeyCode.DIGIT5,
KeyCode.DIGIT6,
KeyCode.DIGIT7,
KeyCode.DIGIT8,
KeyCode.DIGIT9,
KeyCode.DIGIT0,
};
for (SavePoint sp : savePoints) {
MenuItem mi = new MenuItem(String.format("%s (from line %d)", sp.getName(), sp.getLineNumer()));
menuItemsExecuteFrom.add(mi);
MenuItem mirollback = new MenuItem(String.format("%s (from line %d)", sp.getName(), sp.getLineNumer()));
menuItemsRollbackTo.add(mirollback);
if (i < 10) {
mi.setAccelerator(new KeyCodeCombination(quickStart[i],
KeyCodeCombination.CONTROL_DOWN,
KeyCodeCombination.SHIFT_DOWN
));
mirollback.setAccelerator(new KeyCodeCombination(quickStart[i],
KeyCodeCombination.ALT_DOWN));
}
i++;
}
debuggerMain.buttonStartInterpreter.getItems().addAll(menuItemsExecuteFrom);
debuggerMain.menuExecuteFromSavepoint.getItems().setAll(menuItemsExecuteFrom);
debuggerMain.menuRestartFromSavepoint.getItems().setAll(menuItemsRollbackTo);
}
}
......@@ -3,21 +3,19 @@ package edu.kit.iti.formal.psdbg.gui.controls;
import com.google.common.eventbus.Subscribe;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView;
import de.uka.ilkd.key.control.KeYEnvironment;
import edu.kit.iti.formal.psdbg.gui.actions.acomplete.DefaultAutoCompletionController;
import edu.kit.iti.formal.psdbg.gui.actions.inline.FindLabelInGoalList;
import edu.kit.iti.formal.psdbg.gui.actions.inline.FindTermLiteralInSequence;
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.ListProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleObjectProperty;
......@@ -50,55 +48,48 @@ public class ScriptController {
public static final String LINE_HIGHLIGHT_POSTMORTEM = "line-highlight-postmortem";
private static Logger logger = LogManager.getLogger(ScriptController.class);
private static Logger loggerConsole = LogManager.getLogger("console");
private final DockPane parent;
private final ObservableMap<ScriptArea, DockNode> openScripts = FXCollections.observableMap(new HashMap<>());
private final ListProperty<SavePoint> mainScriptSavePoints
= new SimpleListProperty<>(FXCollections.observableArrayList());
private ObjectProperty<MainScriptIdentifier> mainScript = new SimpleObjectProperty<>();
private ScriptArea lastScriptArea;
private ASTNodeHighlighter postMortemHighlighter = new ASTNodeHighlighter(LINE_HIGHLIGHT_POSTMORTEM);
@Getter
@Setter
private List<InlineActionSupplier> actionSuppliers = new ArrayList<>();
@Getter
@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());
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()) {
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);
loggerConsole.info("Found savepoints: " + list);
}
}
......@@ -208,10 +199,10 @@ public class ScriptController {
}
/* Create new DockNode for ScriptArea Tab
*
* @param area ScriptAreaTab
* @return
*/
*
* @param area ScriptAreaTab
* @return
*/
private DockNode createDockNode(ScriptArea area) {
DockNode dockNode = new DockNode(area, area.getFilePath().getName(), new MaterialDesignIconView(MaterialDesignIcon.FILE_DOCUMENT));
dockNode.closedProperty().addListener(o -> {
......@@ -324,6 +315,10 @@ public class ScriptController {
return mainScript.get();
}
public void setMainScript(MainScriptIdentifier mainScript) {
this.mainScript.set(mainScript);
}
public void setMainScript(ProofScript proofScript) {
MainScriptIdentifier msi = new MainScriptIdentifier();
msi.setLineNumber(proofScript.getStartPosition().getLineNumber());
......@@ -333,14 +328,21 @@ public class ScriptController {
setMainScript(msi);
}
public void setMainScript(MainScriptIdentifier mainScript) {
this.mainScript.set(mainScript);
}
public ObjectProperty<MainScriptIdentifier> mainScriptProperty() {
return mainScript;
}
public ObservableList<SavePoint> getMainScriptSavePoints() {
return mainScriptSavePoints.get();
}
public void setMainScriptSavePoints(ObservableList<SavePoint> mainScriptSavePoints) {
this.mainScriptSavePoints.set(mainScriptSavePoints);
}
public ListProperty<SavePoint> mainScriptSavePointsProperty() {
return mainScriptSavePoints;
}
public class ASTNodeHighlighter {
public final String clazzName;
......@@ -392,12 +394,4 @@ public class ScriptController {
else return new ScriptArea.RegionStyle(0, 1, "");
}
}
public ObservableList<SavePoint> getMainScriptSavePoints() {
return mainScriptSavePoints;
}
public void setMainScriptSavePoints(ObservableList<SavePoint> mainScriptSavePoints) {
this.mainScriptSavePoints = mainScriptSavePoints;
}
}
\ No newline at end of file
script testSorts(){
b:bool := true;
i:int :='1';
t:TERM<bool> := `1=1`;
b:bool := true;
i:int :='1';
t:TERM<bool> := `1=1`;
}
script test123() {
impRight;
save 'test0' force='yes';
impRight;
save 'test1';
impLeft;
script test123() {
impRight;
#save 'test0' force='yes';
impRight;
#save 'test1';
impLeft;
}
script test2open() {
impRight;
impRight;
impLeft;
save 'test2';
#save 'test2';
}
script autoScript(){
......
......@@ -77,6 +77,9 @@
<MaterialDesignIconView glyphName="PLAY" size="24.0"/>
</graphic>
</MenuItem>
<Menu text="Execute from Savepoint" fx:id="menuExecuteFromSavepoint" />
<Menu text="Restart to Savepoint" fx:id="menuRestartFromSavepoint" />
<MenuItem text="Debug stepwise"
accelerator="F3"
onAction="#executeStepwise"
......@@ -323,10 +326,12 @@
<Tooltip text="Undo"/>
</tooltip>
</Button>
<ComboBox fx:id="combo_savepoints" disable="true" prefWidth="100" prefHeight="30">
</ComboBox>
<Button fx:id="spselect" onAction="#selectSavepoint" disable="true">
<Separator/>
<Label text="Rollback to: "/>
<ComboBox fx:id="cboSavePoints" disable="true"/>
<Button fx:id="btnSavePointRollback" onAction="#selectSavepoint" disable="true">
<graphic>
<MaterialDesignIconView glyphName="CHECK" size="22.0"/>
</graphic>
......@@ -334,6 +339,8 @@
<Tooltip text="Select Savepoint"/>
</tooltip>
</Button>
<Separator/>
<Pane HBox.hgrow="ALWAYS"/>
<Label text="Windows:"/>
<ToggleButton fx:id="togBtnCodeDock" onAction="#showCodeDock">
......
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