Commit 12996505 authored by sarah.grebing's avatar sarah.grebing

Merge branch 'luonng_variableAssignment' into 'master'

Luonng variable assignment

See merge request !27
parents 36832366 19df8932
Pipeline #38416 passed with stages
in 2 minutes and 22 seconds
......@@ -211,7 +211,7 @@ public interface ASTTraversal<T> extends Visitor<T> {
}
@Override
default T visit(DerivableCase derivableCase){
default T visit(DerivableCase derivableCase) {
derivableCase.getExpression().accept(this);
derivableCase.getBody().accept(this);
return null;
......
......@@ -414,8 +414,7 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
Expression pattern = (Expression) ctx.derivableExpression.accept(this);
((DerivableCase) cs).setExpression(pattern);
pattern.setParent(cs);
} else
{
} else {
cs = new GuardedCaseStatement();
Expression<ParserRuleContext> guard = (Expression<ParserRuleContext>) ctx.expression().accept(this);
((GuardedCaseStatement) cs).setGuard(guard);
......
......@@ -7,13 +7,13 @@ import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class DerivableCase extends CaseStatement{
public class DerivableCase extends CaseStatement {
private Expression expression;
public DerivableCase(Statements copy, Expression copy1) {
super(copy);
this.expression=copy1;
this.expression = copy1;
}
@Override
......
......@@ -43,7 +43,9 @@ import lombok.Setter;
public class MatchExpression extends Expression<ScriptLanguageParser.MatchPatternContext> {
//private Signature signature = new Signature();
private Expression pattern;
@Deprecated @Getter @Setter
@Deprecated
@Getter
@Setter
private boolean isDerivable = false;
@Deprecated
private Expression derivableTerm;
......
......@@ -148,8 +148,6 @@ public class KeyInterpreter extends Interpreter<KeyData> {
}
@Override
public Object visit(LetStatement let) {
enterScope(let);
......
......@@ -123,6 +123,9 @@ public class KeyData {
return programStatementsLabel;
}
public void getVarAssignment() {
}
public Goal getGoal() {
return goal;
......
......@@ -67,7 +67,7 @@ public class ProofScriptCommandBuilder implements CommandHandler<KeyData> {
State<KeyData> state = interpreter.getCurrentState();
//multiple goals exist
if(state.getGoals().size() > 1) {
if (state.getGoals().size() > 1) {
throw new IllegalStateException("Multiple open goals: Please use a selector.");
/*
//TODO: Utils showWarning
......
......@@ -62,7 +62,7 @@ public class KeYMatcher implements MatcherApi<KeyData> {
Proof proof = kd.getData().getProof();
TermValue tv = (TermValue) pattern.getData();
Term term = tv.getTerm();
if(term == null) {
if (term == null) {
Services services = kd.getData().getProof().getServices();
try {
term = new TermBuilder(services.getTermFactory(), services).parseTerm(tv.getTermRepr());
......@@ -96,10 +96,10 @@ public class KeYMatcher implements MatcherApi<KeyData> {
if (isDerivable) {
//find the open goal node
Goal toSet= null;
if(goalList.head().node().isClosed()){
Goal toSet = null;
if (goalList.head().node().isClosed()) {
toSet = goalList.tail().head();
} else{
} else {
toSet = goalList.head();
}
KeyData kdataNew = new KeyData(kd.getData(), toSet);
......
......@@ -148,6 +148,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
Variable var = assignmentStatement.getLhs();
Expression expr = assignmentStatement.getRhs();
if (t != null) {
System.out.println("t = " + t+ var);
node.declareVariable(var, t);
}
......@@ -160,6 +161,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
if (fireVariableAssignmentHook(node, var.getIdentifier(), v)) {
node.setVariableValue(var, v);
}
System.out.println("v = " + v);
node.setVariableValue(var, v);
}
}
......@@ -218,8 +220,8 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
GoalNode<T> selectedGoal = currentStateToMatch.getSelectedGoalNode();
assert currentStateToMatch.getGoals().contains(selectedGoal);
Value v = evaluate(pattern);
if(v.getType() == TypeFacade.ANY_TERM){
GoalNode<T> newGoalNode= matcherApi.isDerivable(selectedGoal, v);
if (v.getType() == TypeFacade.ANY_TERM) {
GoalNode<T> newGoalNode = matcherApi.isDerivable(selectedGoal, v);
try {
enterScope(derivableCase);
......@@ -236,7 +238,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
exitScope(derivableCase);
}
} else {
throw new RuntimeException("A derivable expression must contain a term. Received a"+v.getType());
throw new RuntimeException("A derivable expression must contain a term. Received a" + v.getType());
}
}
......
......@@ -191,9 +191,9 @@ public class MatchEvaluator extends DefaultASTVisitor<List<VariableAssignment>>
Operator op = e.getOperator();
Expression expr = e.getExpression();
List<VariableAssignment> exValue = (List<VariableAssignment>) expr.accept(this);
if(exValue.isEmpty()){
if (exValue.isEmpty()) {
return transformTruthValue(Value.TRUE);
}else{
} else {
return transformTruthValue(Value.FALSE);
}
......
......@@ -54,8 +54,8 @@ public class GoalNode<T> {
this.id = id;
}
private GoalNode(int id, GoalNode<T> parent, VariableAssignment ass, T data, boolean isClosed) {
this(parent, ass, data, isClosed);
private GoalNode(int id, GoalNode<T> parent, VariableAssignment varas, T data, boolean isClosed) {
this(parent, varas, data, isClosed);
this.id = id;
}
......@@ -64,6 +64,12 @@ public class GoalNode<T> {
this.isClosed = isClosed;
this.id = id;
}
private GoalNode(int id, VariableAssignment ass, T data, boolean isClosed) {
this(data);
this.assignments = ass;
this.isClosed = isClosed;
this.id = id;
}
/**
* @param varname
......@@ -133,11 +139,13 @@ public class GoalNode<T> {
* @return
*/
public GoalNode<T> deepCopy() {
VariableAssignment deepCopy = assignments.deepCopy();
if (parent != null) {
VariableAssignment deepCopy = parent.assignments.deepCopy();
return new GoalNode<T>(id, parent.deepCopy(), deepCopy, data, isClosed);
} else {
return new GoalNode<T>(id, data, isClosed);
return new GoalNode<T>(id, deepCopy, data, isClosed);
}
}
......
......@@ -129,7 +129,7 @@ public class InteractiveModeController {
.filter(keyDataGoalNode -> goalsbeforePrune.contains(keyDataGoalNode.getData().getGoal()))
.collect(Collectors.toList());
if(prunedChildren.size() == 0) {
if (prunedChildren.size() == 0) {
//TODO: add Utils.showInfoD
return;
}
......@@ -162,10 +162,10 @@ public class InteractiveModeController {
//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;
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) {
while (statements.get(i) != pruneStatement && i >= 0) {
statements.remove(i);
i--;
}
......@@ -186,6 +186,7 @@ public class InteractiveModeController {
public void stop() {
Events.unregister(this);
//TODO: casesstatement visiten
String c = getCasesAsString();
scriptController.getDockNode(scriptArea).undock();
......
......@@ -2,14 +2,18 @@ package edu.kit.iti.formal.psdbg.gui.controls;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import edu.kit.iti.formal.psdbg.gui.model.InspectionModel;
import edu.kit.iti.formal.psdbg.interpreter.data.KeyData;
import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.Stage;
import lombok.Setter;
import java.util.function.Function;
......@@ -20,10 +24,17 @@ public class GoalOptionsMenu extends ContextMenu {
@FXML
private RadioMenuItem rmiShowSequent, rmiCFL, rmiCFS, rmiBranchLabels, rmiNodeNames, rmiRuleNames;
@FXML
private MenuItem showVarAssignment;
@Setter
private InspectionModel model;
private ObjectProperty<ViewOption> selectedViewOption = new SimpleObjectProperty<>();
private BiMap<Toggle, ViewOption> optionMap = HashBiMap.create(6);
public GoalOptionsMenu() {
Utils.createWithFXML(this);
......@@ -44,6 +55,27 @@ public class GoalOptionsMenu extends ContextMenu {
});
selectedViewOption.setValue(ViewOption.SEQUENT);
showVarAssignment.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if(model == null || model.getSelectedGoalNodeToShow() == null) {
Utils.showInfoDialog("Select a goal", "Select a goal", "Please select a goal first.");
return;
}
VariableAssignment var_assignm = model.getSelectedGoalNodeToShow().getAssignments();
Stage stage = new Stage();
stage.setTitle("Variable Assignment");
VariableAssignmentWindow vaw = new VariableAssignmentWindow(var_assignm);
Scene scene = new Scene(vaw);
stage.setScene(scene);
stage.show();
}
});
}
......@@ -55,9 +87,6 @@ public class GoalOptionsMenu extends ContextMenu {
return selectedViewOption;
}
public void setSelectedViewOption(ViewOption selectedViewOption) {
this.selectedViewOption.set(selectedViewOption);
}
public enum ViewOption {
BRANCHING(KeyData::getBranchingLabel),
......@@ -67,6 +96,7 @@ public class GoalOptionsMenu extends ContextMenu {
NAME(KeyData::getNameLabel),
SEQUENT(item -> item.getNode().sequent().toString());
private final Function<KeyData, String> projection;
ViewOption(Function<KeyData, String> toString) {
......@@ -77,4 +107,6 @@ public class GoalOptionsMenu extends ContextMenu {
return projection.apply(item);
}
}
}
\ No newline at end of file
......@@ -138,6 +138,8 @@ public class InspectionView extends BorderPane {
Utils.addDebugListener(model.get().currentInterpreterGoalProperty());
Utils.addDebugListener(model.get().highlightedJavaLinesProperty());
goalOptionsMenu.setModel(model.get());
/*TODO redefine CSS bases on selected mode
mode.addListener(o -> {
getStyleClass().removeAll(
......
......@@ -25,6 +25,7 @@ import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import lombok.Getter;
import org.controlsfx.control.StatusBar;
import java.util.HashMap;
......@@ -40,6 +41,8 @@ public class SequentMatcher extends BorderPane {
private final ListProperty<Map<String, MatchPath>> results = new SimpleListProperty<>(this, "results", FXCollections.observableArrayList());
//sicht user selected
private final ObjectProperty<GoalNode<KeyData>> selectedGoalNodeToShow = new SimpleObjectProperty<>(this, "selectedGoalNodeToShow");
@Getter
public GoalOptionsMenu goalOptionsMenu = new GoalOptionsMenu();
@FXML
private SequentViewForMatcher sequentView;
......@@ -97,6 +100,7 @@ public class SequentMatcher extends BorderPane {
}
});
}
private void calculateLookupTable() {
......
......@@ -2,6 +2,7 @@ package edu.kit.iti.formal.psdbg.gui.controls;
import edu.kit.iti.formal.psdbg.gui.model.InspectionModel;
import edu.kit.iti.formal.psdbg.interpreter.data.KeyData;
import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
......@@ -18,6 +19,8 @@ public class SequentOptionsMenu extends ContextMenu {
private MenuItem openSequentMatcher;
public SequentOptionsMenu(InspectionModel model) {
Utils.createWithFXML(this);
this.model = model;
......@@ -31,6 +34,9 @@ public class SequentOptionsMenu extends ContextMenu {
KeyData data = (KeyData) model.getSelectedGoalNodeToShow().getData();
SequentMatcher root1 = new SequentMatcher(data.getProof().getServices());
root1.getGoalOptionsMenu().setModel(model);
root1.setGoals(model.getGoals());
root1.setSelectedGoalNodeToShow(model.getSelectedGoalNodeToShow());
root1.getStyleClass().add("sequent-view");
......@@ -58,6 +64,8 @@ public class SequentOptionsMenu extends ContextMenu {
}
});
}
......
package edu.kit.iti.formal.psdbg.gui.controls;
import alice.tuprolog.Var;
import edu.kit.iti.formal.psdbg.gui.controls.Utils;
import edu.kit.iti.formal.psdbg.gui.model.InspectionModel;
import edu.kit.iti.formal.psdbg.interpreter.assignhook.DefaultAssignmentHook;
import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment;
import edu.kit.iti.formal.psdbg.parser.ast.Variable;
import edu.kit.iti.formal.psdbg.parser.types.Type;
import javafx.beans.Observable;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TabPane;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import lombok.Getter;
import lombok.Setter;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
public class VariableAssignmentWindow extends TabPane {
@FXML
TableView declarative_tableView;
@FXML
TableView special_tableView;
/** Non special Variables that don't start with __ **/
private ObservableList<VariableModel> declarativeModel;
/** Variables that start with __ **/
private ObservableList<VariableModel> specialModel;
public VariableAssignmentWindow(VariableAssignment assignment) {
Utils.createWithFXML(this);
if (assignment != null) {
fillInVariableModelsLists(assignment);
}
declarative_tableView.setEditable(false);
special_tableView.setEditable(false);
//Table Colums for declarative_tableView
TableColumn decl_varCol = new TableColumn("Variable");
TableColumn decl_typeCol = new TableColumn("Type");
TableColumn decl_valCol = new TableColumn("Value");
//Set Colums width proportional to windows with
decl_varCol.prefWidthProperty().bind(declarative_tableView.widthProperty().divide(3));
decl_typeCol.prefWidthProperty().bind(declarative_tableView.widthProperty().divide(3));
decl_valCol.prefWidthProperty().bind(declarative_tableView.widthProperty().divide(3));
decl_varCol.setCellValueFactory(
new PropertyValueFactory<VariableModel,String>("varname")
);
decl_typeCol.setCellValueFactory(
new PropertyValueFactory<VariableModel,String>("vartype")
);
decl_valCol.setCellValueFactory(
new PropertyValueFactory<VariableModel,String>("varval")
);
declarative_tableView.setItems(declarativeModel);
declarative_tableView.getColumns().addAll(decl_varCol, decl_typeCol, decl_valCol);
//Table Colums for special_tableView
TableColumn spec_varCol = new TableColumn("Variable");
TableColumn spec_typeCol = new TableColumn("Type");
TableColumn spec_valCol = new TableColumn("Value");
//Set Colums width proportional to windows with
spec_varCol.prefWidthProperty().bind(special_tableView.widthProperty().divide(3));
spec_typeCol.prefWidthProperty().bind(special_tableView.widthProperty().divide(3));
spec_valCol.prefWidthProperty().bind(special_tableView.widthProperty().divide(3));
spec_varCol.setCellValueFactory(
new PropertyValueFactory<VariableModel,String>("varname")
);
spec_typeCol.setCellValueFactory(
new PropertyValueFactory<VariableModel,String>("vartype")
);
spec_valCol.setCellValueFactory(
new PropertyValueFactory<VariableModel,String>("varval")
);
special_tableView.setItems(specialModel);
special_tableView.getColumns().addAll(spec_varCol, spec_typeCol, spec_valCol);
// TODO: set css for TableView
//declarative_tableView.getStyleClass().add("table_view");
}
/**
* Combine all previous Variableassignments and return it
* @param assignment
*/
private void fillInVariableModelsLists(VariableAssignment assignment) {
ObservableList<VariableModel> varmodel = FXCollections.observableArrayList();
ObservableList<VariableModel> special_varmodel = FXCollections.observableArrayList();
VariableAssignment current = assignment;
while (current != null) {
final VariableAssignment currentcopy = current;
//iterate over types map
currentcopy.getTypes().forEach((k, v) -> {
VariableModel variableModel = new VariableModel(k.getIdentifier(), v.symbol(), currentcopy.getValue(k).getData().toString());
if (variableModel.getVarname().startsWith("__")) {
if (!special_varmodel.contains(variableModel)) {
special_varmodel.add(variableModel);
}
} else if (!varmodel.contains(variableModel)) {
varmodel.add(variableModel);
}
});
current = current.getParent();
}
declarativeModel = varmodel;
specialModel = special_varmodel;
}
public static class VariableModel {
@Getter
private final String varname;
@Getter
private final String vartype;
@Getter
private final String varval;
private VariableModel(String varname, String vartype, String varval) {
this.varname = varname;
this.vartype = vartype;
this.varval = varval;
}
}
}
......@@ -67,3 +67,31 @@ cases{
}
auto;
}
script varDecl1(){
var1 : INT := 1;
var2 : INT := 2;
var3 : INT := 3;
}
script varDecl2(){
var1 : INT := 1;
impRight;
impRight;
impLeft;
cases {
case match `!q ==> p`:
notLeft;
var2 : INT := 2;
notRight;
case match `q==>!p`:
notLeft;
var3 : INT := 3;
}
}
\ No newline at end of file
......@@ -15,6 +15,8 @@
<RadioMenuItem fx:id="rmiNodeNames" text="Show _Node Names " toggleGroup="$toggleProjection"/>
<RadioMenuItem fx:id="rmiRuleNames" text="Show _Rule Names " toggleGroup="$toggleProjection"/>
<MenuItem fx:id="showVarAssignment" text="Show _Variable Assignment" />
<Menu fx:id="a" text="Filter by...">
<MenuItem fx:id="removeFilter" text="Remove Filters"/>
<SeparatorMenuItem/>
......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<fx:root xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
type="edu.kit.iti.formal.psdbg.gui.controls.VariableAssignmentWindow"
prefHeight="400.0" prefWidth="600.0">
<tabs>
<Tab text="Script Variables">
<TableView fx:id="declarative_tableView" ></TableView>
</Tab>
<Tab text="KeY Control Variables">
<TableView fx:id="special_tableView"></TableView>
</Tab>
</tabs>
</fx:root>
......@@ -412,4 +412,13 @@
-fx-background-color: antiquewhite;
-fx-stroke: navy;
}
/**********************************************************************************************************************/
.table-view {
.table-row-cell:empty {
-fx-background-color: white;
}
.table-row-cell:empty .table-cell {
-fx-border-width: 0px;
}
}
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