Commit 42f19000 authored by Lulu Luong's avatar Lulu Luong
Browse files

merge with master

parents 278609bd 36832366
Pipeline #33461 passed with stages
in 2 minutes and 8 seconds
package edu.kit.iti.formal.psdbg.gui.controller;
import com.google.common.eventbus.Subscribe;
import de.uka.ilkd.key.api.KeYApi;
import de.uka.ilkd.key.control.AbstractUserInterfaceControl;
import de.uka.ilkd.key.control.DefaultUserInterfaceControl;
import de.uka.ilkd.key.java.Services;
import de.uka.ilkd.key.logic.Sequent;
import de.uka.ilkd.key.logic.SequentFormula;
import de.uka.ilkd.key.macros.ProofMacro;
import de.uka.ilkd.key.macros.scripts.*;
import de.uka.ilkd.key.proof.Goal;
import de.uka.ilkd.key.proof.Node;
......@@ -26,7 +26,7 @@ import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment;
import edu.kit.iti.formal.psdbg.interpreter.dbg.DebuggerFramework;
import edu.kit.iti.formal.psdbg.interpreter.dbg.PTreeNode;
import edu.kit.iti.formal.psdbg.interpreter.exceptions.ScriptCommandNotApplicableException;
import edu.kit.iti.formal.psdbg.interpreter.funchdl.MacroCommandHandler;
import edu.kit.iti.formal.psdbg.interpreter.funchdl.ProofScriptCommandBuilder;
import edu.kit.iti.formal.psdbg.parser.PrettyPrinter;
import edu.kit.iti.formal.psdbg.parser.ast.*;
import edu.kit.iti.formal.psdbg.parser.data.Value;
......@@ -43,6 +43,7 @@ import org.key_project.util.collection.ImmutableList;
import recoder.util.Debug;
import javax.annotation.Nullable;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
......@@ -66,8 +67,8 @@ public class InteractiveModeController {
private PTreeNode<KeyData> nodeAtInteractionStart;
//needed for Undo-Operation
private ArrayList<CallStatement> savepointsstatement;
private ArrayList<Node> savepointslist;
private ArrayList<CallStatement> laststatementlist;
private ArrayList<Node> lastnodeslist;
private Proof currentProof;
private Services keYServices;
......@@ -99,8 +100,8 @@ public class InteractiveModeController {
gcs.setBody(v);
casesStatement.getCases().add(gcs);
});
savepointslist = new ArrayList<>();
savepointsstatement = new ArrayList<>();
lastnodeslist = new ArrayList<>();
laststatementlist = new ArrayList<>();
nodeAtInteractionStart = debuggerFramework.getStatePointer();
}
......@@ -110,13 +111,14 @@ public class InteractiveModeController {
* Undo the application of the last rule
*/
public void undo(javafx.event.ActionEvent actionEvent) {
if (savepointslist.isEmpty()) {
if (lastnodeslist.isEmpty()) {
Debug.log("Kein vorheriger Zustand.");
return;
}
val pruneNode = savepointslist.get(savepointslist.size() - 1);
savepointslist.remove(pruneNode);
val pruneNode = lastnodeslist.get(lastnodeslist.size() - 1);
lastnodeslist.remove(pruneNode);
ImmutableList<Goal> goalsbeforePrune = currentProof.getSubtreeGoals(pruneNode);
currentProof.pruneProof(pruneNode);
......@@ -127,19 +129,55 @@ public class InteractiveModeController {
.filter(keyDataGoalNode -> goalsbeforePrune.contains(keyDataGoalNode.getData().getGoal()))
.collect(Collectors.toList());
if(prunedChildren.size() == 0) {
//TODO: add Utils.showInfoD
return;
}
KeyData kd = prunedChildren.get(0).getData();
goals.removeAll(prunedChildren);
//Set selected goal after prune
GoalNode<KeyData> lastGoalNode = null;
KeyData kdn;
if (lastnodeslist.size() == 0) {
kdn = new KeyData(kd, goalsafterPrune.get(0).node());
goals.add(
lastGoalNode = new GoalNode<>(prunedChildren.get(0).getParent(), kdn, kdn.getNode().isClosed()));
} else {
for (Goal newGoalNode : goalsafterPrune) {
KeyData kdn = new KeyData(kd, newGoalNode.node());
kdn = new KeyData(kd, newGoalNode.node());
goals.add(
lastGoalNode = new GoalNode<>(prunedChildren.get(0).getParent().getParent(), kdn, kdn.getNode().isClosed()));
}
}
model.setSelectedGoalNodeToShow(lastGoalNode);
val pruneStatement = savepointsstatement.get(savepointsstatement.size() - 1);
cases.forEach((k, v) -> v.remove(pruneStatement));
val pruneStatement = laststatementlist.get(laststatementlist.size() - 1);
laststatementlist.remove(laststatementlist.size() - 1);
//TODO: buggy cuz allstatements of same node removed
//remove statement from cases / script
Statements statements = (cases.get(pruneNode.parent()) == null)? cases.get(pruneNode) : cases.get(pruneNode.parent());
int i = statements.size()-1;
while(statements.get(i) != pruneStatement && i >= 0) {
statements.remove(i);
i--;
}
statements.remove(i);
/*
cases.forEach((k, v) -> {
v.remove(pruneStatement);
});
*/
String c = getCasesAsString();
scriptArea.setText("" +
......@@ -261,11 +299,39 @@ public class InteractiveModeController {
}
}
@Subscribe
public void handle(Events.CommandApplicationEvent map) {
LOGGER.debug("Handling {}", map);
Goal g = map.getCurrentGoal();
Parameters callp = new Parameters();
CallStatement call = new CallStatement(map.getCommandName().getName(), callp);
try {
applyRuleHelper(call, g, Type.SCRIPT_COMMAND);
String c = getCasesAsString();
scriptArea.setText("" +
"//Preview \n" + c);
} catch (ScriptCommandNotApplicableException e) {
StringBuilder sb = new StringBuilder("The script command ");
sb.append(call.getCommand()).append(" was not applicable.");
System.out.println("e = " + e);
//sb.append("\nSequent Formula: formula=").append(sfTerm);
//sb.append("\nOn Sub Term: on=").append(onTerm);
Utils.showWarningDialog("Proof Command was not applicable",
"Proof Command was not applicable.",
sb.toString(), e);
}
}
private void applyRuleHelper(CallStatement call, Goal g, Type t) throws ScriptCommandNotApplicableException {
savepointslist.add(g.node());
savepointsstatement.add(call);
lastnodeslist.add(g.node());
laststatementlist.add(call);
ObservableList<GoalNode<KeyData>> goals = model.getGoals();
GoalNode<KeyData> expandedNode;
......@@ -313,10 +379,11 @@ public class InteractiveModeController {
postStateHandler(call, g, goals, expandedNode, kd);
break;
case SCRIPT_COMMAND:
ScriptCommand.Parameters ccS = new ScriptCommand.Parameters();
ScriptCommand cS = new ScriptCommand();
ccS = valueInjector.inject(cS, ccS, map);
cS.execute(uiControl, ccS, estate);
ProofScriptCommandBuilder psb = new ProofScriptCommandBuilder(KeYApi.getScriptCommandApi().getScriptCommands());
ProofScriptCommand ps = psb.getCommands().get(call.getCommand());
Object temp = valueInjector.inject(ps, getParameterInstance(ps), map);
ps.execute(uiControl, temp, estate);
postStateHandler(call, g, goals, expandedNode, kd);
break;
default:
......@@ -336,6 +403,12 @@ public class InteractiveModeController {
}
private <T> T getParameterInstance(ProofScriptCommand c) throws NoSuchMethodException, IllegalAccessException,
InstantiationException {
Method method = c.getClass().getMethod("evaluateArguments", EngineState.class, Map.class);
Class rtclazz = method.getReturnType();
return (T) rtclazz.newInstance();
}
private void postStateHandler(CallStatement call, Goal g, ObservableList<GoalNode<KeyData>> goals, GoalNode<KeyData> expandedNode, KeyData kd) {
ImmutableList<Goal> ngoals = g.proof().getSubtreeGoals(expandedNode.getData().getNode());
......@@ -392,8 +465,8 @@ public class InteractiveModeController {
}
/*
private void applyRule(CallStatement call, Goal g) throws ScriptCommandNotApplicableException {
savepointslist.add(g.node());
savepointsstatement.add(call);
lastnodeslist.add(g.node());
laststatementlist.add(call);
ObservableList<GoalNode<KeyData>> goals = model.getGoals();
GoalNode<KeyData> expandedNode;
......
......@@ -66,9 +66,8 @@ public class ScriptExecutionController {
mainCtrl.FACADE.reload(mainCtrl.getModel().getKeyFile());
} catch (ProofInputException | ProblemLoaderException e) {
LOGGER.error(e);
Utils.showExceptionDialog("Loading Error", "Could not clear Environment", "There was an error when clearing old environment",
e
);
// Utils.showExceptionDialog("Loading Error", "Could not clear Environment", "There was an error when clearing old environment", e );
}
}
......
......@@ -10,8 +10,10 @@ import edu.kit.iti.formal.psdbg.gui.actions.acomplete.Suggestion;
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.interpreter.data.KeyData;
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.PTreeNode;
import edu.kit.iti.formal.psdbg.lint.LintProblem;
import edu.kit.iti.formal.psdbg.lint.LinterStrategy;
import edu.kit.iti.formal.psdbg.parser.Facade;
......@@ -89,7 +91,6 @@ import static org.fxmisc.wellbehaved.event.InputMap.*;
public class ScriptArea extends BorderPane {
public static final Logger LOGGER = LogManager.getLogger(ScriptArea.class);
public static final Logger CONSOLE_LOGGER = LogManager.getLogger(ScriptArea.class);
public static final String EXECUTION_MARKER = "\u2316";
public static final FileReloadingService FILE_RELOADING_SERVICE = new FileReloadingService();
......@@ -489,10 +490,12 @@ public class ScriptArea extends BorderPane {
}
@Deprecated
private boolean hasExecutionMarker() {
return getText().contains(EXECUTION_MARKER);
}
@Deprecated
public int getExecutionMarkerPosition() {
return getText().lastIndexOf(EXECUTION_MARKER);
}
......@@ -608,11 +611,13 @@ public class ScriptArea extends BorderPane {
return dirty;
}
@Deprecated
public void removeExecutionMarker() {
setText(getTextWithoutMarker());
//Events.unregister(this);
}
@Deprecated
private String getTextWithoutMarker() {
return getText().replace("" + EXECUTION_MARKER, "");
}
......@@ -622,6 +627,7 @@ public class ScriptArea extends BorderPane {
*
* @param pos
*/
@Deprecated
public void insertExecutionMarker(int pos) {
LOGGER.debug("ScriptArea.insertExecutionMarker");
Events.register(this);
......@@ -992,6 +998,7 @@ public class ScriptArea extends BorderPane {
}*/
}
@Deprecated
public void setExecutionMarker(ActionEvent event) {
LOGGER.debug("ScriptAreaContextMenu.setExecutionMarker");
int pos = codeArea.getCaretPosition();
......
script empty(){
}
script full(){
impRight;
impRight;
impLeft;
cases {
case derivable `p`:
}
}
script full(){
impRight;
impRight;
......
......@@ -10,7 +10,8 @@
<MenuItem text="Show post mortem" onAction="#showPostMortem"/>
<SeparatorMenuItem/>
<MenuItem text="Set Main Script" onAction="#setMainScript"/>
<MenuItem text="Set Execution Marker" onAction="#setExecutionMarker" accelerator="Ctrl+m"/>
<!--<MenuItem text="Set Execution Marker" onAction="#setExecutionMarker" accelerator="Ctrl+m"/>
-->
</items>
</fx:root>
Supports Markdown
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