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

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);
......
......@@ -34,7 +34,7 @@ public class KeyMatcherDerivableTest {
System.out.println(proof);
// Assert.assertNotNull(a);
// Assert.assertNotNull(a);
Assert.assertEquals(1, proof.getSubtreeGoals(proof.root()).size());
}
......
......@@ -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
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