Commit 6b02ec1c authored by Lulu Luong's avatar Lulu Luong
Browse files

Cyclicbarrier + userinteraction UI

Contextmenu for watches
varass sync
parent c8b796af
Pipeline #40785 passed with stages
in 3 minutes and 3 seconds
...@@ -5,6 +5,7 @@ import de.uka.ilkd.key.control.DefaultUserInterfaceControl; ...@@ -5,6 +5,7 @@ import de.uka.ilkd.key.control.DefaultUserInterfaceControl;
import de.uka.ilkd.key.control.instantiation_model.TacletInstantiationModel; import de.uka.ilkd.key.control.instantiation_model.TacletInstantiationModel;
import de.uka.ilkd.key.java.Services; import de.uka.ilkd.key.java.Services;
import de.uka.ilkd.key.logic.*; import de.uka.ilkd.key.logic.*;
import de.uka.ilkd.key.logic.op.SchemaVariable;
import de.uka.ilkd.key.macros.scripts.EngineState; import de.uka.ilkd.key.macros.scripts.EngineState;
import de.uka.ilkd.key.macros.scripts.RuleCommand; import de.uka.ilkd.key.macros.scripts.RuleCommand;
import de.uka.ilkd.key.macros.scripts.ScriptException; import de.uka.ilkd.key.macros.scripts.ScriptException;
...@@ -20,6 +21,7 @@ import de.uka.ilkd.key.rule.IfFormulaInstantiation; ...@@ -20,6 +21,7 @@ import de.uka.ilkd.key.rule.IfFormulaInstantiation;
import de.uka.ilkd.key.rule.Rule; import de.uka.ilkd.key.rule.Rule;
import de.uka.ilkd.key.rule.Taclet; import de.uka.ilkd.key.rule.Taclet;
import de.uka.ilkd.key.rule.TacletApp; import de.uka.ilkd.key.rule.TacletApp;
import de.uka.ilkd.key.rule.inst.InstantiationEntry;
import de.uka.ilkd.key.rule.inst.SVInstantiations; import de.uka.ilkd.key.rule.inst.SVInstantiations;
import edu.kit.iti.formal.psdbg.RuleCommandHelper; import edu.kit.iti.formal.psdbg.RuleCommandHelper;
import edu.kit.iti.formal.psdbg.ValueInjector; import edu.kit.iti.formal.psdbg.ValueInjector;
...@@ -53,11 +55,16 @@ import lombok.RequiredArgsConstructor; ...@@ -53,11 +55,16 @@ import lombok.RequiredArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.key_project.util.collection.DefaultImmutableMap;
import org.key_project.util.collection.ImmutableList; import org.key_project.util.collection.ImmutableList;
import org.key_project.util.collection.ImmutableMap;
import org.key_project.util.collection.ImmutableMapEntry;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.*; import java.util.*;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
/** /**
* @author Alexander Weigl * @author Alexander Weigl
...@@ -75,6 +82,7 @@ public class RuleCommandHandler implements CommandHandler<KeyData> { ...@@ -75,6 +82,7 @@ public class RuleCommandHandler implements CommandHandler<KeyData> {
private Scanner scanner = new Scanner(System.in); private Scanner scanner = new Scanner(System.in);
@Getter @Getter
@Setter @Setter
private TacletAppSelectionDialogService tacletAppSelectionDialogService; private TacletAppSelectionDialogService tacletAppSelectionDialogService;
...@@ -138,7 +146,6 @@ public class RuleCommandHandler implements CommandHandler<KeyData> { ...@@ -138,7 +146,6 @@ public class RuleCommandHandler implements CommandHandler<KeyData> {
if (!rules.containsKey(call.getCommand())) { if (!rules.containsKey(call.getCommand())) {
throw new IllegalStateException(); throw new IllegalStateException();
} }
//FIXME duplicate of ProofScriptCommandBuilder
RuleCommand c = new RuleCommand(); RuleCommand c = new RuleCommand();
State<KeyData> state = interpreter.getCurrentState(); State<KeyData> state = interpreter.getCurrentState();
GoalNode<KeyData> expandedNode = state.getSelectedGoalNode(); GoalNode<KeyData> expandedNode = state.getSelectedGoalNode();
...@@ -168,27 +175,48 @@ public class RuleCommandHandler implements CommandHandler<KeyData> { ...@@ -168,27 +175,48 @@ public class RuleCommandHandler implements CommandHandler<KeyData> {
if (e instanceof ScriptException.IndistinctFormula) { if (e instanceof ScriptException.IndistinctFormula) {
List<TacletApp> matchingapps = ((ScriptException.IndistinctFormula) e).getMatchingApps(); List<TacletApp> matchingapps = ((ScriptException.IndistinctFormula) e).getMatchingApps();
List<TacletApp> completed_matchingapps = new ArrayList<>();
for (TacletApp tacletApp : matchingapps) {
try {
TacletInstantiationModel tim = new TacletInstantiationModel(tacletApp, kd.getGoal().sequent(), kd.getGoal().getLocalNamespaces(), null, kd.getGoal());
TacletApp newTA = tim.createTacletApp();
completed_matchingapps.add(newTA);
} catch (SVInstantiationException svie) {
// Not buildable tacletapps
}
}
ObservableList<String> obsMatchApps = FXCollections.observableArrayList(); ObservableList<String> obsMatchApps = FXCollections.observableArrayList();
int linenr = call.getStartPosition().getLineNumber(); int linenr = call.getStartPosition().getLineNumber();
matchingapps.forEach(k -> obsMatchApps.add(tacletAppIntoString(k, kd.getGoal(), linenr))); completed_matchingapps.forEach(k -> obsMatchApps.add(tacletAppIntoString(k, kd.getGoal(), linenr)));
//TODO: open window here
//open window here
CyclicBarrier cyclicBarrier = new CyclicBarrier(2, tacletAppSelectionDialogService.getRunnable());
IndistinctWindow indistinctWindow = new IndistinctWindow(obsMatchApps); IndistinctWindow indistinctWindow = new IndistinctWindow(obsMatchApps);
tacletAppSelectionDialogService.setCyclicBarrier(cyclicBarrier);
tacletAppSelectionDialogService.setPane(indistinctWindow); tacletAppSelectionDialogService.setPane(indistinctWindow);
tacletAppSelectionDialogService.showDialog(); tacletAppSelectionDialogService.showDialog();
TacletApp chosenApp = matchingapps.get(tacletAppSelectionDialogService.getUserIndexInput());
TacletInstantiationModel tim = new TacletInstantiationModel(chosenApp, kd.getGoal().sequent(), kd.getGoal().getLocalNamespaces(), null, kd.getGoal());
try { try {
TacletApp newTA = tim.createTacletApp(); cyclicBarrier.await();
newTA.execute(kd.getGoal(), kd.getProof().getServices()); } catch (InterruptedException ex) {
exceptionsolved = true; } catch (BrokenBarrierException ex) {
} catch (SVInstantiationException svie) {
} }
}
TacletApp chosenApp = completed_matchingapps.get(tacletAppSelectionDialogService.getUserIndexInput());
System.out.println("chosenapp = " + tacletAppIntoString(chosenApp, kd.getGoal(), linenr));
chosenApp.execute(kd.getGoal(), kd.getProof().getServices());
exceptionsolved = true;
}
if (!exceptionsolved) { if (!exceptionsolved) {
if (interpreter.isStrictMode()) { if (interpreter.isStrictMode()) {
...@@ -250,18 +278,27 @@ public class RuleCommandHandler implements CommandHandler<KeyData> { ...@@ -250,18 +278,27 @@ public class RuleCommandHandler implements CommandHandler<KeyData> {
int occ = rch.getOccurence(tacletApp); int occ = rch.getOccurence(tacletApp);
tacletAppString = String.format("%s formula=' %s ' on=' %s ' occ=%d;", tacletAppString = String.format("%s formula='%s' on='%s' occ=%d ",
tapName, tapName,
sfTerm.trim(), sfTerm.trim(),
onTerm.trim(), onTerm.trim(),
occ); occ);
// add missing instantiations // add missing instantiations
if (!tacletApp.ifInstsComplete()) { String ifInstString = "";
SVInstantiations sv = tacletApp.instantiations(); if (tacletApp.ifInstsComplete()) {
//TODO:
Iterator<ImmutableMapEntry<SchemaVariable, InstantiationEntry<?>>> iterator = tacletApp.instantiations().pairIterator();
while (iterator.hasNext()) {
ImmutableMapEntry<SchemaVariable, InstantiationEntry<?>> mapentry = iterator.next();
ifInstString += String.format("inst_%s ='%s' ", mapentry.key().name(), mapentry.value().getInstantiation());
//"inst_" + mapentry.key().name() + "=" + mapentry.value().getInstantiation();
}
} }
tacletAppString += ifInstString;
tacletAppString += "; ";
tacletAppString += String.format("(linenumber = %d)", linenumber); tacletAppString += String.format("(linenumber = %d)", linenumber);
return tacletAppString; return tacletAppString;
......
...@@ -3,19 +3,22 @@ package edu.kit.iti.formal.psdbg.interpreter; ...@@ -3,19 +3,22 @@ package edu.kit.iti.formal.psdbg.interpreter;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.geometry.Orientation;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import lombok.Getter; import lombok.Getter;
import java.util.List; import java.util.List;
public class IndistinctWindow extends BorderPane { public class IndistinctWindow extends VBox {
@Getter @Getter
int indexOfSelected = -1; int indexOfSelected = -1;
...@@ -24,11 +27,16 @@ public class IndistinctWindow extends BorderPane { ...@@ -24,11 +27,16 @@ public class IndistinctWindow extends BorderPane {
public IndistinctWindow(ObservableList<String> matchApps) { public IndistinctWindow(ObservableList<String> matchApps) {
//Top this.setPrefWidth(700);
ScrollPane scrollPane = new ScrollPane(); //Center
ListView<String> listView = new ListView<String>(matchApps); ListView<String> listView = new ListView<String>(matchApps);
scrollPane.setContent(listView); this.getChildren().add(listView);
this.setTop(scrollPane);
//Bottom
accept = new Button();
accept.setText("Accept");
this.getChildren().add(accept);
listView.setOnMouseClicked(new EventHandler<MouseEvent>() { listView.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override @Override
...@@ -38,19 +46,6 @@ public class IndistinctWindow extends BorderPane { ...@@ -38,19 +46,6 @@ public class IndistinctWindow extends BorderPane {
} }
}); });
//Center
/*
HBox hbox = new HBox();
Text inputlabel = new Text("Enter a number:");
TextField textField = new TextField();
hbox.getChildren().addAll(inputlabel, textField);
this.setCenter(hbox);
*/
//Bottom
accept = new Button();
accept.setText("Accept");
this.setBottom(accept);
} }
} }
...@@ -16,9 +16,7 @@ import lombok.Getter; ...@@ -16,9 +16,7 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.FutureTask;
public abstract class TacletAppSelectionDialogService { public abstract class TacletAppSelectionDialogService {
...@@ -28,10 +26,18 @@ public abstract class TacletAppSelectionDialogService { ...@@ -28,10 +26,18 @@ public abstract class TacletAppSelectionDialogService {
@Getter @Getter
int userIndexInput; int userIndexInput;
private CountDownLatch latch = new CountDownLatch(1); private Runnable runnable;
@Setter
private CyclicBarrier cyclicBarrier;
public void showDialog() { public void showDialog() {
Platform.runLater(new Runnable() { runnable = getRunnable();
Platform.runLater(runnable);
}
public Runnable getRunnable() {
return new Runnable() {
@Override @Override
public void run() { public void run() {
Stage stage = new Stage(); Stage stage = new Stage();
...@@ -45,14 +51,21 @@ public abstract class TacletAppSelectionDialogService { ...@@ -45,14 +51,21 @@ public abstract class TacletAppSelectionDialogService {
public void handle(MouseEvent event) { public void handle(MouseEvent event) {
getIndex(); getIndex();
if (userIndexInput != -1) { if (userIndexInput != -1) {
try {
stage.close(); stage.close();
cyclicBarrier.await();
} catch (InterruptedException ex) {
} catch (BrokenBarrierException ex) {
}
} }
} }
}); });
stage.showAndWait(); stage.showAndWait();
latch.countDown();
} }
}); };
} }
......
...@@ -64,11 +64,10 @@ public class GoalOptionsMenu extends ContextMenu { ...@@ -64,11 +64,10 @@ public class GoalOptionsMenu extends ContextMenu {
Utils.showInfoDialog("Select a goal", "Select a goal", "Please select a goal first."); Utils.showInfoDialog("Select a goal", "Select a goal", "Please select a goal first.");
return; return;
} }
VariableAssignment var_assignm = model.getSelectedGoalNodeToShow().getAssignments(); //VariableAssignment var_assignm = model.getSelectedGoalNodeToShow().getAssignments();
Stage stage = new Stage(); Stage stage = new Stage();
stage.setTitle("Variable Assignment"); stage.setTitle("Variable Assignment");
VariableAssignmentWindow vaw = new VariableAssignmentWindow(var_assignm); VariableAssignmentWindow vaw = new VariableAssignmentWindow(model);
Scene scene = new Scene(vaw); Scene scene = new Scene(vaw);
stage.setScene(scene); stage.setScene(scene);
......
package edu.kit.iti.formal.psdbg.gui.controls; package edu.kit.iti.formal.psdbg.gui.controls;
import edu.kit.iti.formal.psdbg.gui.model.InspectionModel;
import edu.kit.iti.formal.psdbg.interpreter.Evaluator; import edu.kit.iti.formal.psdbg.interpreter.Evaluator;
import edu.kit.iti.formal.psdbg.interpreter.data.GoalNode;
import edu.kit.iti.formal.psdbg.interpreter.data.KeyData;
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.exceptions.VariableNotDefinedException;
import edu.kit.iti.formal.psdbg.parser.Facade; import edu.kit.iti.formal.psdbg.parser.Facade;
import edu.kit.iti.formal.psdbg.parser.ast.StringLiteral;
import edu.kit.iti.formal.psdbg.parser.data.Value; import edu.kit.iti.formal.psdbg.parser.data.Value;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import lombok.Getter; import lombok.Getter;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -28,11 +31,19 @@ public class VariableAssignmentWindow extends BorderPane { ...@@ -28,11 +31,19 @@ public class VariableAssignmentWindow extends BorderPane {
TableView special_tableView; TableView special_tableView;
@FXML @FXML
TableView history_tableView; TableView watches_tableView;
@FXML @FXML
TextArea match_variables; TextArea match_variables;
@FXML
TabPane tabPane;
@FXML
Tab watchesTab;
private ContextMenu contextMenu;
private VariableAssignment assignment; private VariableAssignment assignment;
/** Non special Variables that don't start with __ **/ /** Non special Variables that don't start with __ **/
...@@ -41,30 +52,27 @@ public class VariableAssignmentWindow extends BorderPane { ...@@ -41,30 +52,27 @@ public class VariableAssignmentWindow extends BorderPane {
/** Variables that start with __ **/ /** Variables that start with __ **/
private ObservableList<VariableModel> specialModel; private ObservableList<VariableModel> specialModel;
private ObservableList<VariableModel> historyModel = FXCollections.observableArrayList(); private ObservableList<VariableModel> watchesModel = FXCollections.observableArrayList();
private String matchexp; private String matchexp;
private ScriptEngineManager mgr = new ScriptEngineManager();
private ScriptEngine engine = mgr.getEngineByName("JavaScript");
private List<VariableModel> matchlist_declarative = new ArrayList<>(); private List<VariableModel> matchlist_declarative = new ArrayList<>();
private List<VariableModel> matchlist_special = new ArrayList<>(); private List<VariableModel> matchlist_special = new ArrayList<>();
private Evaluator evaluator; private Evaluator evaluator;
public VariableAssignmentWindow(VariableAssignment assignment) { private InspectionModel inspectionModel;
public VariableAssignmentWindow(InspectionModel inspectionModel) {
//TODO: reduce size of constructor //TODO: reduce size of constructor
Utils.createWithFXML(this); Utils.createWithFXML(this);
if (assignment != null) { this.inspectionModel = inspectionModel;
fillInVariableModelsLists(assignment);
}
declarative_tableView.setEditable(false); declarative_tableView.setEditable(false);
special_tableView.setEditable(false); special_tableView.setEditable(false);
history_tableView.setEditable(false); watches_tableView.setEditable(false);
//Table Colums for declarative_tableView //Table Colums for declarative_tableView
TableColumn decl_varCol = new TableColumn("Variable"); TableColumn decl_varCol = new TableColumn("Variable");
...@@ -86,7 +94,6 @@ public class VariableAssignmentWindow extends BorderPane { ...@@ -86,7 +94,6 @@ public class VariableAssignmentWindow extends BorderPane {
new PropertyValueFactory<VariableModel,String>("varval") new PropertyValueFactory<VariableModel,String>("varval")
); );
declarative_tableView.setItems(declarativeModel);
declarative_tableView.getColumns().addAll(decl_varCol, decl_typeCol, decl_valCol); declarative_tableView.getColumns().addAll(decl_varCol, decl_typeCol, decl_valCol);
//Table Colums for special_tableView //Table Colums for special_tableView
...@@ -109,19 +116,18 @@ public class VariableAssignmentWindow extends BorderPane { ...@@ -109,19 +116,18 @@ public class VariableAssignmentWindow extends BorderPane {
new PropertyValueFactory<VariableModel,String>("varval") new PropertyValueFactory<VariableModel,String>("varval")
); );
special_tableView.setItems(specialModel);
special_tableView.getColumns().addAll(spec_varCol, spec_typeCol, spec_valCol); special_tableView.getColumns().addAll(spec_varCol, spec_typeCol, spec_valCol);
//Table Colums for history_tableView //Table Colums for watches_tableView
TableColumn hist_varCol = new TableColumn("Variable"); TableColumn hist_varCol = new TableColumn("Variable");
TableColumn hist_typeCol = new TableColumn("Type"); TableColumn hist_typeCol = new TableColumn("Type");
TableColumn hist_valCol = new TableColumn("Value"); TableColumn hist_valCol = new TableColumn("Value");
//Set Colums width proportional to windows with //Set Colums width proportional to windows with
hist_varCol.prefWidthProperty().bind(history_tableView.widthProperty().divide(3)); hist_varCol.prefWidthProperty().bind(watches_tableView.widthProperty().divide(3));
hist_typeCol.prefWidthProperty().bind(history_tableView.widthProperty().divide(3)); hist_typeCol.prefWidthProperty().bind(watches_tableView.widthProperty().divide(3));
hist_valCol.prefWidthProperty().bind(history_tableView.widthProperty().divide(3)); hist_valCol.prefWidthProperty().bind(watches_tableView.widthProperty().divide(3));
hist_varCol.setCellValueFactory( hist_varCol.setCellValueFactory(
new PropertyValueFactory<VariableModel, String>("varname") new PropertyValueFactory<VariableModel, String>("varname")
...@@ -133,8 +139,8 @@ public class VariableAssignmentWindow extends BorderPane { ...@@ -133,8 +139,8 @@ public class VariableAssignmentWindow extends BorderPane {
new PropertyValueFactory<VariableModel, String>("varval") new PropertyValueFactory<VariableModel, String>("varval")
); );
history_tableView.setItems(historyModel); watches_tableView.setItems(watchesModel);
history_tableView.getColumns().addAll(hist_varCol, hist_typeCol, hist_valCol); watches_tableView.getColumns().addAll(hist_varCol, hist_typeCol, hist_valCol);
//Row factory added //Row factory added
declarative_tableView.setRowFactory(tv -> new TableRow<VariableModel>() { declarative_tableView.setRowFactory(tv -> new TableRow<VariableModel>() {
...@@ -159,7 +165,17 @@ public class VariableAssignmentWindow extends BorderPane { ...@@ -159,7 +165,17 @@ public class VariableAssignmentWindow extends BorderPane {
} }
}); });
evaluator = new Evaluator(assignment, null); inspectionModel.currentInterpreterGoalProperty().addListener(new ChangeListener<GoalNode<KeyData>>() {
@Override
public void changed(ObservableValue<? extends GoalNode<KeyData>> observable, GoalNode<KeyData> oldValue, GoalNode<KeyData> newValue) {
refresh();
}
});