Commit 96b2b783 authored by Sarah Grebing's avatar Sarah Grebing

planning for conceptual merge of actions

parent b8ec7a67
...@@ -8,6 +8,9 @@ import java.util.List; ...@@ -8,6 +8,9 @@ import java.util.List;
* @version 1 (04.06.17) * @version 1 (04.06.17)
*/ */
public class LineMapping { public class LineMapping {
/**
* Position of new lines in the given string value.
*/
private List<Integer> marks = new ArrayList<>(); private List<Integer> marks = new ArrayList<>();
public LineMapping(String value) { public LineMapping(String value) {
...@@ -29,14 +32,14 @@ public class LineMapping { ...@@ -29,14 +32,14 @@ public class LineMapping {
return marks.size(); return marks.size();
} }
public int getLineStart(int line) {
return marks.get(line);
}
public int getLineEnd(int line) { public int getLineEnd(int line) {
return getLineStart(line + 1) - 1; return getLineStart(line + 1) - 1;
} }
public int getLineStart(int line) {
return marks.get(line);
}
public int getCharInLine(int caretPosition) { public int getCharInLine(int caretPosition) {
return caretPosition - getLineStart(getLine(caretPosition)); return caretPosition - getLineStart(getLine(caretPosition));
} }
......
...@@ -149,29 +149,43 @@ public class ScriptArea extends CodeArea { ...@@ -149,29 +149,43 @@ public class ScriptArea extends CodeArea {
} }
private void highlightNonExecutionArea() { private void installPopup() {
if (hasExecutionMarker()) { javafx.stage.Popup popup = new javafx.stage.Popup();
getStyleSpans(0, getExecutionMarkerPosition()).forEach(span -> { setMouseOverTextDelay(Duration.ofSeconds(1));
span.getStyle().add("NON_EXE_AREA"); addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN, e -> {
}); int chIdx = e.getCharacterIndex();
//setStyle(0, getExecutionMarkerPosition(), Collections.singleton("NON_EXE_AREA")); popup.getContent().setAll(
} createPopupInformation(chIdx)
} );
private boolean hasExecutionMarker() { Point2D pos = e.getScreenPosition();
return getText().contains(EXECUTION_MARKER); popup.show(this, pos.getX(), pos.getY() + 10);
});
/*
addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_END, e -> {
popup.hide();
});*/
popup.setAutoHide(true);
} }
public void showContextMenu(MouseEvent mouseEvent) { private void updateMainScriptMarker() {
if (contextMenu.isShowing()) try {
contextMenu.hide(); MainScriptIdentifier ms = mainScript.get();
LOGGER.debug("ScriptArea.updateMainScriptMarker");
if (mouseEvent.getButton() == MouseButton.SECONDARY) { if (ms != null && filePath.get().getAbsolutePath().equals(ms.getSourceName())) {
contextMenu.setAutoHide(true); System.out.println(ms);
contextMenu.show(this, mouseEvent.getScreenX(), mouseEvent.getScreenY()); CharStream stream = CharStreams.fromString(getText(), filePath.get().getAbsolutePath());
mouseEvent.consume(); Optional<ProofScript> ps = ms.find(Facade.getAST(stream));
} else {
if (ps.isPresent()) {
setMainMarker(ps.get().getStartPosition().getLineNumber());
return;
}
}
setMainMarker(-1);
} catch (NullPointerException e) {
} }
} }
...@@ -190,44 +204,30 @@ public class ScriptArea extends CodeArea { ...@@ -190,44 +204,30 @@ public class ScriptArea extends CodeArea {
}); });
} }
private void updateMainScriptMarker() { private void highlightProblems() {
LinterStrategy ls = LinterStrategy.getDefaultLinter();
try { try {
MainScriptIdentifier ms = mainScript.get(); problems.setAll(ls.check(Facade.getAST(CharStreams.fromString(getText()))));
LOGGER.debug("ScriptArea.updateMainScriptMarker"); for (LintProblem p : problems) {
for (Token tok : p.getMarkTokens()) {
if (ms != null && filePath.get().getAbsolutePath().equals(ms.getSourceName())) { Set<String> problem = new HashSet<>();
System.out.println(ms); problem.add("problem");
CharStream stream = CharStreams.fromString(getText(), filePath.get().getAbsolutePath()); setStyle(tok.getStartIndex(),
Optional<ProofScript> ps = ms.find(Facade.getAST(stream)); tok.getStopIndex() + 1, problem);
if (ps.isPresent()) {
setMainMarker(ps.get().getStartPosition().getLineNumber());
return;
} }
} }
setMainMarker(-1); } catch (Exception e) {
} catch (NullPointerException e) { //catch parsing exceptions
} }
} }
private void installPopup() { private void highlightNonExecutionArea() {
javafx.stage.Popup popup = new javafx.stage.Popup(); if (hasExecutionMarker()) {
setMouseOverTextDelay(Duration.ofSeconds(1)); getStyleSpans(0, getExecutionMarkerPosition()).forEach(span -> {
addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN, e -> { span.getStyle().add("NON_EXE_AREA");
int chIdx = e.getCharacterIndex(); });
popup.getContent().setAll( //setStyle(0, getExecutionMarkerPosition(), Collections.singleton("NON_EXE_AREA"));
createPopupInformation(chIdx) }
);
Point2D pos = e.getScreenPosition();
popup.show(this, pos.getX(), pos.getY() + 10);
});
/*
addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_END, e -> {
popup.hide();
});*/
popup.setAutoHide(true);
} }
private Node createPopupInformation(int chIdx) { private Node createPopupInformation(int chIdx) {
...@@ -245,20 +245,30 @@ public class ScriptArea extends CodeArea { ...@@ -245,20 +245,30 @@ public class ScriptArea extends CodeArea {
return box; return box;
} }
private void highlightProblems() { public void setMainMarker(int lineNumber) {
LinterStrategy ls = LinterStrategy.getDefaultLinter(); gutter.lineAnnotations.forEach(a -> a.setMainScript(false));
try { if (lineNumber > 0)
problems.setAll(ls.check(Facade.getAST(CharStreams.fromString(getText())))); gutter.getLineAnnotation(lineNumber - 1).setMainScript(true);
for (LintProblem p : problems) { }
for (Token tok : p.getMarkTokens()) {
Set<String> problem = new HashSet<>(); private boolean hasExecutionMarker() {
problem.add("problem"); return getText().contains(EXECUTION_MARKER);
setStyle(tok.getStartIndex(), }
tok.getStopIndex() + 1, problem);
} public int getExecutionMarkerPosition() {
} return getText().lastIndexOf(EXECUTION_MARKER);
} catch (Exception e) { }
//catch parsing exceptions
public void showContextMenu(MouseEvent mouseEvent) {
if (contextMenu.isShowing())
contextMenu.hide();
if (mouseEvent.getButton() == MouseButton.SECONDARY) {
contextMenu.setAutoHide(true);
contextMenu.show(this, mouseEvent.getScreenX(), mouseEvent.getScreenY());
mouseEvent.consume();
} else {
} }
} }
...@@ -274,11 +284,6 @@ public class ScriptArea extends CodeArea { ...@@ -274,11 +284,6 @@ public class ScriptArea extends CodeArea {
return mainScript; return mainScript;
} }
public void setText(String text) {
clear();
insertText(0, text);
}
private void toggleBreakpoint(int idx) { private void toggleBreakpoint(int idx) {
GutterAnnotation a = gutter.getLineAnnotation(idx); GutterAnnotation a = gutter.getLineAnnotation(idx);
a.setBreakpoint(!a.isBreakpoint()); a.setBreakpoint(!a.isBreakpoint());
...@@ -296,12 +301,6 @@ public class ScriptArea extends CodeArea { ...@@ -296,12 +301,6 @@ public class ScriptArea extends CodeArea {
return filePath; return filePath;
} }
public void setMainMarker(int lineNumber) {
gutter.lineAnnotations.forEach(a -> a.setMainScript(false));
if (lineNumber > 0)
gutter.getLineAnnotation(lineNumber - 1).setMainScript(true);
}
public Collection<? extends Breakpoint> getBreakpoints() { public Collection<? extends Breakpoint> getBreakpoints() {
List<Breakpoint> list = new ArrayList<>(); List<Breakpoint> list = new ArrayList<>();
int line = 0; int line = 0;
...@@ -384,6 +383,11 @@ public class ScriptArea extends CodeArea { ...@@ -384,6 +383,11 @@ public class ScriptArea extends CodeArea {
//Events.unregister(this); //Events.unregister(this);
} }
public void setText(String text) {
clear();
insertText(0, text);
}
private String getTextWithoutMarker() { private String getTextWithoutMarker() {
return getText().replace("" + EXECUTION_MARKER, ""); return getText().replace("" + EXECUTION_MARKER, "");
} }
...@@ -403,7 +407,7 @@ public class ScriptArea extends CodeArea { ...@@ -403,7 +407,7 @@ public class ScriptArea extends CodeArea {
String tapName = tap.getApp().taclet().displayName(); String tapName = tap.getApp().taclet().displayName();
SequentFormula seqForm = tap.getPio().sequentFormula(); SequentFormula seqForm = tap.getPio().sequentFormula();
//transofrm term to parsable string representation //transform term to parsable string representation
String term = Utils.toPrettyTerm(seqForm.formula()); String term = Utils.toPrettyTerm(seqForm.formula());
...@@ -429,12 +433,6 @@ public class ScriptArea extends CodeArea { ...@@ -429,12 +433,6 @@ public class ScriptArea extends CodeArea {
} }
public int getExecutionMarkerPosition() {
return getText().lastIndexOf(EXECUTION_MARKER);
}
private static class GutterView extends HBox { private static class GutterView extends HBox {
private final SimpleObjectProperty<GutterAnnotation> annotation = new SimpleObjectProperty<>(); private final SimpleObjectProperty<GutterAnnotation> annotation = new SimpleObjectProperty<>();
...@@ -484,6 +482,10 @@ public class ScriptArea extends CodeArea { ...@@ -484,6 +482,10 @@ public class ScriptArea extends CodeArea {
addPlaceholder(); addPlaceholder();
} }
public GutterAnnotation getAnnotation() {
return annotation.get();
}
private void addPlaceholder() { private void addPlaceholder() {
Label lbl = new Label(); Label lbl = new Label();
lbl.setMinWidth(12); lbl.setMinWidth(12);
...@@ -491,11 +493,6 @@ public class ScriptArea extends CodeArea { ...@@ -491,11 +493,6 @@ public class ScriptArea extends CodeArea {
getChildren().add(lbl); getChildren().add(lbl);
} }
public GutterAnnotation getAnnotation() {
return annotation.get();
}
public void setAnnotation(GutterAnnotation annotation) { public void setAnnotation(GutterAnnotation annotation) {
this.annotation.set(annotation); this.annotation.set(annotation);
} }
......
...@@ -59,6 +59,18 @@ public class SequentView extends CodeArea { ...@@ -59,6 +59,18 @@ public class SequentView extends CodeArea {
mouseEvent.consume(); mouseEvent.consume();
} }
private void hightlightRange(int start, int end) {
try {
clearHighlight();
setStyleClass(start, end, "sequent-highlight");
} catch (IllegalStateException e) {
}
}
private void clearHighlight() {
clearStyle(0, getLength());
}
public void onMouseClick(MouseEvent e) { public void onMouseClick(MouseEvent e) {
if (menu != null && menu.isShowing()) { if (menu != null && menu.isShowing()) {
menu.hide(); menu.hide();
...@@ -94,18 +106,6 @@ public class SequentView extends CodeArea { ...@@ -94,18 +106,6 @@ public class SequentView extends CodeArea {
} }
private void hightlightRange(int start, int end) {
try {
clearHighlight();
setStyleClass(start, end, "sequent-highlight");
} catch (IllegalStateException e) {
}
}
private void clearHighlight() {
clearStyle(0, getLength());
}
public void update(Observable o) { public void update(Observable o) {
Services services = node.get().proof().getEnv().getServicesForEnvironment(); Services services = node.get().proof().getEnv().getServicesForEnvironment();
NamespaceSet nss = services.getNamespaces(); NamespaceSet nss = services.getNamespaces();
...@@ -130,8 +130,15 @@ public class SequentView extends CodeArea { ...@@ -130,8 +130,15 @@ public class SequentView extends CodeArea {
clear(); clear();
insertText(0, backend.getString()); insertText(0, backend.getString());
if (node.get().isClosed()) { if (node.get().isClosed()) {
System.out.println("Closed " + node.get().sequent());
this.setBorder(new Border(new BorderStroke(Color.GREEN, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT))); this.setBorder(new Border(new BorderStroke(Color.GREEN, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
this.getStyleClass().add("closed-sequent-view"); this.getStyleClass().add("closed-sequent-view");
} else {
this.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
this.getStyleClass().remove("closed-sequent-view");
this.getStyleClass().add("sequent-view");
} }
} }
......
package edu.kit.formal.interpreter.graphs; package edu.kit.formal.interpreter.graphs;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import com.google.common.graph.MutableValueGraph;
import edu.kit.formal.gui.controller.Events; import edu.kit.formal.gui.controller.Events;
import edu.kit.formal.gui.controller.PuppetMaster; import edu.kit.formal.gui.controller.PuppetMaster;
import edu.kit.formal.gui.controls.DebuggerStatusBar; import edu.kit.formal.gui.controls.DebuggerStatusBar;
import edu.kit.formal.gui.model.Breakpoint;
import edu.kit.formal.interpreter.Interpreter; import edu.kit.formal.interpreter.Interpreter;
import edu.kit.formal.interpreter.InterpretingService; import edu.kit.formal.interpreter.InterpretingService;
import edu.kit.formal.interpreter.data.GoalNode; import edu.kit.formal.interpreter.data.GoalNode;
...@@ -19,6 +21,7 @@ import org.apache.logging.log4j.LogManager; ...@@ -19,6 +21,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* Class controlling and maintaining proof tree structure for debugger and handling step functions for the debugger * Class controlling and maintaining proof tree structure for debugger and handling step functions for the debugger
...@@ -138,17 +141,18 @@ public class ProofTreeController { ...@@ -138,17 +141,18 @@ public class ProofTreeController {
} }
/** /**
* Build the control flow graph for looking up step-edges for the given script inligning called script commands * Sets the properties that may notify GUI about statechanges with new state values
* *
* @param mainScript * @param state
*/ */
private void buildControlFlowGraph(ProofScript mainScript) { private void setNewState(State<KeyData> state) {
this.controlFlowGraphVisitor = new ControlFlowVisitor(currentInterpreter.getFunctionLookup()); setCurrentGoals(state == null ? null : state.getGoals());
mainScript.accept(controlFlowGraphVisitor); setCurrentSelectedGoal(state == null ? null : state.getSelectedGoalNode());
System.out.println("CFG\n" + controlFlowGraphVisitor.asdot()); setCurrentHighlightNode(statePointer.getScriptstmt());
LOGGER.debug("New State from this command: {}@{}",
this.statePointer.getScriptstmt().getNodeName(),
this.statePointer.getScriptstmt().getStartPosition());
} }
//TODO handle endpoint //TODO handle endpoint
...@@ -189,7 +193,7 @@ public class ProofTreeController { ...@@ -189,7 +193,7 @@ public class ProofTreeController {
/** /**
* Step Back one Node in the stategraph * Step Back one Node in the stategraph
* *
* @return * @return PTreeNode of current pointer
*/ */
public PTreeNode stepBack() { public PTreeNode stepBack() {
PTreeNode current = this.statePointer; PTreeNode current = this.statePointer;
...@@ -214,6 +218,17 @@ public class ProofTreeController { ...@@ -214,6 +218,17 @@ public class ProofTreeController {
return null; return null;
} }
/**
* Execute script with breakpoints
* @param debugMode
* @param statusBar
* @param breakpoints
*/
public void executeScript(boolean debugMode, DebuggerStatusBar statusBar, Set<Breakpoint> breakpoints) {
breakpoints.forEach(breakpoint -> blocker.addBreakpoint(breakpoint.getLineNumber()));
executeScript(debugMode, statusBar);
}
/** /**
* Execute the script that is identified by the mainscript. * Execute the script that is identified by the mainscript.
* If this method is executed with debug mode true, it executes only statements after invoking the methods stepOver() and stepInto() * If this method is executed with debug mode true, it executes only statements after invoking the methods stepOver() and stepInto()
...@@ -243,6 +258,7 @@ public class ProofTreeController { ...@@ -243,6 +258,7 @@ public class ProofTreeController {
this.stateGraphWrapper.install(currentInterpreter); this.stateGraphWrapper.install(currentInterpreter);
this.stateGraphWrapper.addChangeListener(graphChangedListener); this.stateGraphWrapper.addChangeListener(graphChangedListener);
blocker.getStepUntilBlock().set(1); blocker.getStepUntilBlock().set(1);
} }
...@@ -265,19 +281,22 @@ public class ProofTreeController { ...@@ -265,19 +281,22 @@ public class ProofTreeController {
} }
/** /**
* Sets the properties that may notify GUI about statechanges with new state values * Build the control flow graph for looking up step-edges for the given script inligning called script commands
* *
* @param state * @param mainScript
*/ */
private void setNewState(State<KeyData> state) { private void buildControlFlowGraph(ProofScript mainScript) {
setCurrentGoals(state==null? null : state.getGoals()); this.controlFlowGraphVisitor = new ControlFlowVisitor(currentInterpreter.getFunctionLookup());
setCurrentSelectedGoal(state==null?null:state.getSelectedGoalNode()); mainScript.accept(controlFlowGraphVisitor);
setCurrentHighlightNode(statePointer.getScriptstmt()); System.out.println("CFG\n" + controlFlowGraphVisitor.asdot());
LOGGER.debug("New State from this command: {}@{}",
this.statePointer.getScriptstmt().getNodeName(),
this.statePointer.getScriptstmt().getStartPosition());
} }
/**
* Handle the event that the script was modified
*
* @param mod
*/
@Subscribe @Subscribe
public void handle(Events.ScriptModificationEvent mod) { public void handle(Events.ScriptModificationEvent mod) {
LOGGER.debug("ProofTreeController.handleScriptModificationEvent"); LOGGER.debug("ProofTreeController.handleScriptModificationEvent");
...@@ -287,6 +306,24 @@ public class ProofTreeController { ...@@ -287,6 +306,24 @@ public class ProofTreeController {
this.setCurrentGoals(currentInterpreter.getCurrentGoals()); this.setCurrentGoals(currentInterpreter.getCurrentGoals());
} }
/**
* Save all data structures to compare before reexecution
*/
public void saveGraphs() {
MutableValueGraph stateGraph = stateGraphWrapper.getStateGraph();
MutableValueGraph ctrlFlow = controlFlowGraphVisitor.getGraph();
}
private boolean compareCtrlFlowNodes(ControlFlowNode newNode, ControlFlowNode oldNode) {
return newNode.getScriptstmt().getNodeName().equals(oldNode.getScriptstmt().getNodeName());
}
private boolean comparePTreeNodes(PTreeNode newTreeNode, PTreeNode oldTreeNode) {
return false;
}
/************************************************************************************************************** /**************************************************************************************************************
* *
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
<?import de.jensd.fx.glyphs.materialdesignicons.*?> <?import de.jensd.fx.glyphs.materialdesignicons.*?>
<?import edu.kit.formal.gui.controls.DebuggerStatusBar?> <?import edu.kit.formal.gui.controls.DebuggerStatusBar?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.input.KeyCodeCombination?>
<?import javafx.scene.layout.BorderPane?> <?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<?import org.dockfx.DockPane?> <?import org.dockfx.DockPane?>
...@@ -92,13 +91,21 @@ ...@@ -92,13 +91,21 @@
</MenuItem> </MenuItem>
<MenuItem <MenuItem
text="Run in debug mode" text="Execute Script Stepwise"
onAction="#executeInDebugMode" onAction="#executeInDebugMode"
disable="${controller.executeNotPossible}"> disable="${controller.executeNotPossible}">
<graphic> <graphic>
<MaterialDesignIconView glyphName="PLAY_PAUSE" size="24.0"/>