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 { allprojects {
apply plugin: 'maven' apply plugin: 'maven'
group = 'edu.kit.iti.formal.psdbg' group = 'edu.kit.iti.formal.psdbg'
version = 'Experimental-1.1' version = '1.1-experimental'
} }
subprojects { subprojects {
......
...@@ -4,26 +4,23 @@ import edu.kit.iti.formal.psdbg.interpreter.Interpreter; ...@@ -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.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.VariableAssignment; 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.CallStatement;
import edu.kit.iti.formal.psdbg.parser.ast.Parameters;
import edu.kit.iti.formal.psdbg.parser.data.Value;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter; 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 javax.annotation.Nullable;
import java.io.File; import java.io.File;
import java.io.IOException; 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; private File path;
public SaveCommand(File path) { public SaveCommand(File path) {
...@@ -33,7 +30,7 @@ public class SaveCommand implements CommandHandler<KeyData>{ ...@@ -33,7 +30,7 @@ public class SaveCommand implements CommandHandler<KeyData>{
@Override @Override
public boolean handles(CallStatement call, @Nullable KeyData data) throws IllegalArgumentException { public boolean handles(CallStatement call, @Nullable KeyData data) throws IllegalArgumentException {
return call.getCommand().equals("save"); return call.getCommand().equals(SAVE_COMMAND_NAME);
} }
@Override @Override
...@@ -41,18 +38,20 @@ public class SaveCommand implements CommandHandler<KeyData>{ ...@@ -41,18 +38,20 @@ public class SaveCommand implements CommandHandler<KeyData>{
//be careful parameters are uninterpreted //be careful parameters are uninterpreted
SavePoint sp = new SavePoint(call); SavePoint sp = new SavePoint(call);
//Not via Parentpath -> dependency on OS //Not via Parentpath -> dependency on OS
String parentpath = path.getAbsolutePath(); /* String parentPath = path.getAbsolutePath();
parentpath = parentpath.substring(0, parentpath.length() - path.getName().length()); 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 { try {
interpreter.getSelectedNode().getData().getProof().saveToFile(newfile); interpreter.getSelectedNode().getData().getProof().saveToFile(newFile);
//TODO Call to key persistend facade
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!--
https://logging.apache.org/log4j/2.x/manual/configuration.html
-->
<Configuration status="error"> <Configuration status="error">
<Appenders> <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"> <Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5level] %msg%n"/> <PatternLayout>
<!--<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>--> <!-- <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> </Console>
<File name="F" fileName="debug.log" bufferSize="0" bufferedIO="false" append="false"> <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"/> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File> </File>
</Appenders> </Appenders>
<Loggers> <Loggers>
<Root level="trace"> <Root level="trace">
<AppenderRef ref="Console" level="warn"/> <AppenderRef ref="ConsoleErr" level="error"/>
<AppenderRef ref="F"/> <AppenderRef ref="F"/>
</Root> </Root>
<Logger name="console">
<AppenderRef ref="Console" level="info"/>
</Logger>
</Loggers> </Loggers>
</Configuration> </Configuration>
package edu.kit.iti.formal.psdbg.interpreter.data; 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 edu.kit.iti.formal.psdbg.parser.ast.*;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.io.File; import java.io.File;
@Data @Data
@RequiredArgsConstructor @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; public SavePoint(CallStatement call) {
if (isSaveCommand(call)) {
private int start = -1;
private int end = -1;
public SavePoint(CallStatement call){
if(isSaveCommand(call)){
Parameters p = call.getParameters(); Parameters p = call.getParameters();
savepointName = ((StringLiteral) p.get(new Variable("#2"))).getText(); name = evalAsText(p, "#2", "not-available");
start = call.getRuleContext().getStart().getStartIndex(); force = ForceOption.valueOf(evalAsText(p, "force", "yes").toUpperCase());
end = call.getRuleContext().getStart().getStopIndex();
} else {
throw new IllegalArgumentException(call.getCommand()+" is not a save statement");
}}
public static boolean isSaveCommand(CallStatement call){ try {
return (call.getCommand().equals("save")); 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){ public static boolean isSaveCommand(CallStatement call) {
return new File(dir, savepointName+".proof"); return (call.getCommand().equals("#save"));
} }
public static boolean isSaveCommand(Statement statement) { public static boolean isSaveCommand(Statement statement) {
try{ try {
CallStatement c = (CallStatement) statement; CallStatement c = (CallStatement) statement;
return isSaveCommand(c); return isSaveCommand(c);
}catch (ClassCastException e) { } catch (ClassCastException e) {
return false; 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) { public boolean isThisStatement(Statement statement) {
if(isSaveCommand(statement)){ if (isSaveCommand(statement)) {
CallStatement c = (CallStatement) statement; CallStatement c = (CallStatement) statement;
return c.getCommand().equals(savepointName); return c.getCommand().equals(name);
} }
return false; return false;
} }
public enum ForceOption {
YES, NO, INTERACTIVE;
}
} }
...@@ -34,6 +34,8 @@ public class ProofScriptDebugger extends Application { ...@@ -34,6 +34,8 @@ public class ProofScriptDebugger extends Application {
public static final String KEY_VERSION = KeYConstants.VERSION; public static final String KEY_VERSION = KeYConstants.VERSION;
private Logger logger = LogManager.getLogger("psdbg"); private Logger logger = LogManager.getLogger("psdbg");
private static Logger consoleLogger = LogManager.getLogger("console");
public static void main(String[] args) { public static void main(String[] args) {
launch(args); launch(args);
...@@ -65,6 +67,8 @@ public class ProofScriptDebugger extends Application { ...@@ -65,6 +67,8 @@ public class ProofScriptDebugger extends Application {
logger.info("KeY Version: " + KeYConstants.VERSION); logger.info("KeY Version: " + KeYConstants.VERSION);
logger.info("KeY Internal: " + KeYConstants.INTERNAL_VERSION); logger.info("KeY Internal: " + KeYConstants.INTERNAL_VERSION);
consoleLogger.info("Welcome!");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
System.exit(1); 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; ...@@ -3,21 +3,19 @@ package edu.kit.iti.formal.psdbg.gui.controls;
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;
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.acomplete.DefaultAutoCompletionController;
import edu.kit.iti.formal.psdbg.gui.actions.inline.FindLabelInGoalList; 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.FindTermLiteralInSequence;
import edu.kit.iti.formal.psdbg.gui.actions.inline.InlineActionSupplier; 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.controller.Events;
import edu.kit.iti.formal.psdbg.gui.model.MainScriptIdentifier; 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.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.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.ASTNode;
import edu.kit.iti.formal.psdbg.parser.ast.CallStatement; 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.ProofScript;
import edu.kit.iti.formal.psdbg.parser.ast.Statement; import javafx.beans.property.ListProperty;
import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleListProperty; import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
...@@ -50,55 +48,48 @@ public class ScriptController { ...@@ -50,55 +48,48 @@ public class ScriptController {
public static final String LINE_HIGHLIGHT_POSTMORTEM = "line-highlight-postmortem"; public static final String LINE_HIGHLIGHT_POSTMORTEM = "line-highlight-postmortem";
private static Logger logger = LogManager.getLogger(ScriptController.class); private static Logger logger = LogManager.getLogger(ScriptController.class);
private static Logger loggerConsole = LogManager.getLogger("console");
private final DockPane parent; private final DockPane parent;
private final ObservableMap<ScriptArea, DockNode> openScripts = FXCollections.observableMap(new HashMap<>()); 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 ObjectProperty<MainScriptIdentifier> mainScript = new SimpleObjectProperty<>();
private ScriptArea lastScriptArea; private ScriptArea lastScriptArea;
private ASTNodeHighlighter postMortemHighlighter = new ASTNodeHighlighter(LINE_HIGHLIGHT_POSTMORTEM); private ASTNodeHighlighter postMortemHighlighter = new ASTNodeHighlighter(LINE_HIGHLIGHT_POSTMORTEM);
@Getter @Getter
@Setter @Setter
private List<InlineActionSupplier> actionSuppliers = new ArrayList<>(); private List<InlineActionSupplier> actionSuppliers = new ArrayList<>();
@Getter @Getter
@Setter @Setter
private DefaultAutoCompletionController autoCompleter = new DefaultAutoCompletionController(); private DefaultAutoCompletionController autoCompleter = new DefaultAutoCompletionController();
public ScriptController(DockPane parent) { public ScriptController(DockPane parent) {
this.parent = parent; this.parent = parent;
Events.register(this); Events.register(this);
addDefaultInlineActions(); addDefaultInlineActions();
mainScript.addListener((p,o,n)-> { mainScript.addListener((p, o, n) -> {
if(o!=null) if (o != null)
o.getScriptArea().textProperty().removeListener( a-> updateSavePoints()); o.getScriptArea().textProperty().removeListener(a -> updateSavePoints());
n.getScriptArea().textProperty().addListener(a->updateSavePoints()); n.getScriptArea().textProperty().addListener(a -> updateSavePoints());
updateSavePoints(); updateSavePoints();
}); });
} }
private ObservableList<SavePoint> mainScriptSavePoints
= new SimpleListProperty<>(FXCollections.observableArrayList());
private void updateSavePoints() { private void updateSavePoints() {
Optional<ProofScript> ms = getMainScript().find(getCombinedAST()); Optional<ProofScript> ms = getMainScript().find(getCombinedAST());
if(ms.isPresent()) { if (ms.isPresent()) {
List<SavePoint> list = ms.get().getBody().stream() List<SavePoint> list = ms.get().getBody().stream()
.filter(SavePoint::isSaveCommand) .filter(SavePoint::isSaveCommand)
.map(a -> (CallStatement) a) .map(a -> (CallStatement) a)
.map(SavePoint::new) .map(SavePoint::new)
.collect(Collectors.toList()); .collect(Collectors.toList());
mainScriptSavePoints.setAll(list); mainScriptSavePoints.setAll(list);
loggerConsole.info("Found savepoints: " + list);
} }
} }
...@@ -208,10 +199,10 @@ public class ScriptController { ...@@ -208,10 +199,10 @@ public class ScriptController {
} }
/* Create new DockNode for ScriptArea Tab /* Create new DockNode for ScriptArea Tab
* *
* @param area ScriptAreaTab * @param area ScriptAreaTab
* @return * @return
*/ */
private DockNode createDockNode(ScriptArea area) { private DockNode createDockNode(ScriptArea area) {
DockNode dockNode = new DockNode(area, area.getFilePath().getName(), new MaterialDesignIconView(MaterialDesignIcon.FILE_DOCUMENT)); DockNode dockNode = new DockNode(area, area.getFilePath().getName(), new MaterialDesignIconView(MaterialDesignIcon.FILE_DOCUMENT));
dockNode.closedProperty().addListener(o -> { dockNode.closedProperty().addListener(o -> {
...@@ -324,6 +315,10 @@ public class ScriptController { ...@@ -324,6 +315,10 @@ public class ScriptController {
return mainScript.get(); return mainScript.get();
} }
public void setMainScript(MainScriptIdentifier mainScript) {
this.mainScript.set(mainScript);
}
public void setMainScript(ProofScript proofScript) { public void setMainScript(ProofScript proofScript) {
MainScriptIdentifier msi = new MainScriptIdentifier(); MainScriptIdentifier msi = new MainScriptIdentifier();
msi.setLineNumber(proofScript.getStartPosition().getLineNumber()); msi.setLineNumber(proofScript.getStartPosition().getLineNumber());
...@@ -333,14 +328,21 @@ public class ScriptController { ...@@ -333,14 +328,21 @@ public class ScriptController {
setMainScript(msi); setMainScript(msi);
} }
public void setMainScript(MainScriptIdentifier mainScript) {
this.mainScript.set(mainScript);
}
public ObjectProperty<MainScriptIdentifier> mainScriptProperty() { public ObjectProperty<MainScriptIdentifier> mainScriptProperty() {
return mainScript;