Commit a559e78e authored by Sarah Grebing's avatar Sarah Grebing

interim

parent e6361f70
package edu.kit.iti.formal.psdbg.interpreter.funchdl;
import edu.kit.iti.formal.psdbg.interpreter.Interpreter;
import edu.kit.iti.formal.psdbg.interpreter.data.KeyData;
import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment;
import edu.kit.iti.formal.psdbg.parser.ast.CallStatement;
public class RigidRuleCommandHandler implements CommandHandler<KeyData> {
@Override
public boolean handles(CallStatement call) throws IllegalArgumentException {
return true;
}
@Override
public void evaluate(Interpreter<KeyData> interpreter, CallStatement call, VariableAssignment params) {
}
}
package edu.kit.iti.formal.psdbg.interpreter;
import edu.kit.iti.formal.psdbg.interpreter.data.InterpreterExtendedState;
import edu.kit.iti.formal.psdbg.interpreter.data.State;
import edu.kit.iti.formal.psdbg.interpreter.graphs.PTreeNode;
import lombok.Getter;
/**
* Event that is fired if a new state was added to a PTreeNode in the Stategraph
*/
public class StateAddedEvent {
@Getter
PTreeNode changedNode;
......@@ -12,9 +16,13 @@ public class StateAddedEvent {
@Getter
State addedState;
public StateAddedEvent(PTreeNode addedNode, State addedState) {
@Getter
InterpreterExtendedState addedExtState;
public StateAddedEvent(PTreeNode addedNode, State addedState, InterpreterExtendedState addedExtState) {
this.changedNode = addedNode;
this.addedState = addedState;
this.addedExtState = addedExtState;
}
public String toString() {
......
......@@ -91,7 +91,9 @@ public class InterpreterExtendedState<T> {
@Override
public String toString() {
StringBuilder sb = new StringBuilder("\n%%%%%%%%%%%%%%%%%%%%%\nExtended State ");
StringBuilder sb = new StringBuilder();
//sb.append("\n%%%%%%%%%%%%%%%%%%%%%\n");
sb.append("Extended State ");
if (getStmt() != null) {
sb.append(getStmt().getNodeName() + ": \n");
}
......@@ -107,7 +109,14 @@ public class InterpreterExtendedState<T> {
} else {
sb.append("After is empty");
}
sb.append("\n%%%%%%%%%%%%%%%%%%%%\n");
if (getMappingOfCaseToStates().containsKey(stmt)) {
sb.append("Case Stmt with");
getMappingOfCaseToStates().get(stmt).forEach(tGoalNode -> {
sb.append(tGoalNode.getData());
});
}
//sb.append("\n%%%%%%%%%%%%%%%%%%%%\n");
return sb.toString();
// this.stateBeforeStmt.toString()+"\n"+this.stateAfterStmt.toString();
}
......
......@@ -4,7 +4,7 @@ import edu.kit.iti.formal.psdbg.interpreter.data.InterpreterExtendedState;
import edu.kit.iti.formal.psdbg.interpreter.data.State;
import edu.kit.iti.formal.psdbg.parser.ast.ASTNode;
import java.util.LinkedList;
import java.util.Stack;
/**
* Inner class representing nodes in the stategraph graph
......@@ -27,7 +27,15 @@ public class PTreeNode<T> {
/**
* Call context
*/
private LinkedList<ASTNode> context = new LinkedList<>();
private Stack<ASTNode> context = new Stack<>();
public Stack<ASTNode> getContext() {
return context;
}
public void setContext(Stack<ASTNode> context) {
this.context = context;
}
private boolean root;
......@@ -51,19 +59,11 @@ public class PTreeNode<T> {
this.scriptstmt = scriptstmt;
}
public LinkedList<ASTNode> getContext() {
return context;
}
public void setContext(LinkedList<ASTNode> context) {
this.context = context;
}
InterpreterExtendedState<T> getExtendedState() {
public InterpreterExtendedState<T> getExtendedState() {
return extendedState;
}
void setExtendedState(InterpreterExtendedState<T> extendedState) {
public void setExtendedState(InterpreterExtendedState<T> extendedState) {
this.extendedState = extendedState;
}
......@@ -75,10 +75,15 @@ public class PTreeNode<T> {
} else {
sb.append("Root Node");
}
if (hasState()) {
/* if (hasState()) {
sb.append("\nState " + state.getGoals() + "\n");
} else {
sb.append("No State yet");
}*/
if (extendedState != null) {
sb.append(extendedStateToString());
} else {
sb.append("No extended State yet");
}
sb.append("}");
return sb.toString();
......
......@@ -10,6 +10,7 @@ import edu.kit.iti.formal.psdbg.interpreter.KeyInterpreter;
import edu.kit.iti.formal.psdbg.interpreter.NodeAddedEvent;
import edu.kit.iti.formal.psdbg.interpreter.StateAddedEvent;
import edu.kit.iti.formal.psdbg.interpreter.data.GoalNode;
import edu.kit.iti.formal.psdbg.interpreter.data.InterpreterExtendedState;
import edu.kit.iti.formal.psdbg.interpreter.data.KeyData;
import edu.kit.iti.formal.psdbg.interpreter.data.State;
import edu.kit.iti.formal.psdbg.interpreter.graphs.*;
......@@ -118,12 +119,9 @@ public class ProofTreeController {
@Override
public void graphChanged(StateAddedEvent stateAddedEvent) {
PTreeNode changedNode = stateAddedEvent.getChangedNode();
// if(changedNode.getScriptstmt().equals(statePointer.getScriptstmt())){
LOGGER.info("Graph changed by adding a state to PTreeNode: {} and the statepointer points to {}", stateAddedEvent, statePointer);
nextComputedNode.set(changedNode);
Events.fire(new Events.NewNodeExecuted(changedNode.getScriptstmt()));
// }
}
};
......@@ -145,33 +143,9 @@ public class ProofTreeController {
* and bind properties
*/
public ProofTreeController() {
/* blocker.currentStateProperty().addListener((observable, oldValue, newValue) ->
{
Platform.runLater(() -> {
if (newValue != null) {
setNewState(newValue);
}
});
});*/
//get state from blocker, who communicates with interpreter
//this.currentSelectedGoal.bindBidirectional(blocker.currentSelectedGoalProperty());
/* blocker.currentSelectedGoalProperty().addListener((observable, oldValue, newValue) -> {
Platform.runLater(() -> {
if (newValue != null) {
this.setCurrentSelectedGoal(newValue);
}
});
blocker.currentStateProperty().addListener((observable, oldValue, newValue) -> {
LOGGER.info("The state in the Puppetmaster changed to " + newValue.toString());
});
blocker.currentGoalsProperty().addListener((observable, oldValue, newValue) -> {
Platform.runLater(() -> {
if (newValue != null) {
this.setCurrentGoals(newValue);
}
});
});*/
//add listener to nextcomputed node, that is updated whenever a new node is added to the stategraph
nextComputedNode.addListener((observable, oldValue, newValue) -> {
//update statepointer
......@@ -192,7 +166,7 @@ public class ProofTreeController {
* @param state
*/
private void setNewState(State<KeyData> state) {
// LOGGER.info("Setting new State "+state.toString());
LOGGER.info("Setting new State " + state.toString());
//Statepointer null wenn anfangszustand?
if (statePointer != null && state != null) {
setCurrentHighlightNode(statePointer.getScriptstmt());
......@@ -251,26 +225,21 @@ public class ProofTreeController {
PTreeNode<KeyData> nextNode = stateGraphWrapper.getStepOver(currentPointer);
//if nextnode is null ask interpreter to execute next statement and compute next state
if (nextNode != null) {
if (nextNode != null && nextNode.getExtendedState().getStateAfterStmt() != null) {
PTreeNode<KeyData> lastNode = this.statePointer;
PTreeNode<KeyData> possibleextNode = nextNode;
if (possibleextNode.getState().getGoals() == null || possibleextNode.getState().getGoals().isEmpty() || possibleextNode.getState() == null) {
InterpreterExtendedState<KeyData> extendedStateOfStmt = possibleextNode.getExtendedState();
//check whether we have reached an endpoint in the graph
if (lastNode.equals(nextNode)) {
nextComputedNode.setValue(lastNode);
} else {
nextComputedNode.setValue(possibleextNode);
if (extendedStateOfStmt.getStateBeforeStmt() == null || extendedStateOfStmt.getStateBeforeStmt().getGoals() == null || extendedStateOfStmt.getStateBeforeStmt().getGoals().isEmpty()) {
nextComputedNode.setValue(lastNode);
} else {
nextComputedNode.setValue(possibleextNode);
}
}
/* State<KeyData> lastState = this.statePointer.getState();
this.statePointer = nextNode;
//TODO: replace this code by firing a nodeChangedEvent
State<KeyData> state = this.statePointer.getState();
//if statepointer is at the end, the set of goals is empty therefore return old pointer
if (state.getGoals().isEmpty()) {
setNewState(lastState);
} else {
setNewState(state);
}*/
// setHighlightStmt(this.statePointer.getScriptstmt().getStartPosition(), this.statePointer.getScriptstmt().getStartPosition());
} else {
//no next node is present yet
//let interpreter run for one step and let listener handle updating the statepointer
......@@ -328,24 +297,18 @@ public class ProofTreeController {
blocker.deinstall();
blocker.install(currentInterpreter);
/* if (!debugMode) {
statusBar.setText("Starting in execution mode for script " + mainScript.getName());
statusBar.indicateProgress();
blocker.getStepUntilBlock().set(-1);
} else {*/
statusBar.setText("Starting in debug mode for script " + mainScript.getName());
statusBar.indicateProgress();
setCurrentHighlightNode(mainScript.get());
//build CFG
buildControlFlowGraph(mainScript.get());
//build StateGraph
statusBar.setText("Starting in debug mode for script " + mainScript.getName());
statusBar.indicateProgress();
setCurrentHighlightNode(mainScript.get());
//build CFG
buildControlFlowGraph(mainScript.get());
//build StateGraph
this.stateGraphWrapper = new StateGraphWrapper<>(currentInterpreter, mainScript.get(), this.controlFlowGraphVisitor);
this.stateGraphWrapper.install(currentInterpreter);
this.stateGraphWrapper.addChangeListener(graphChangedListener);
statusBar.stopProgress();
//}
this.stateGraphWrapper.install(currentInterpreter);
this.stateGraphWrapper.addChangeListener(graphChangedListener);
statusBar.stopProgress();
//create interpreter service and start
if (interpreterService.getState() == Worker.State.SUCCEEDED
......@@ -370,7 +333,6 @@ public class ProofTreeController {
statusBar.setText("Failed to execute script");
statusBar.stopProgress();
});
}
/**
......@@ -419,11 +381,6 @@ public class ProofTreeController {
this.currentInterpreter = currentInterpreter;
}
/* public void setMainScript(ProofScript mainScript) {
this.mainScript = mainScript;
}*/
public StateGraphWrapper getStateVisitor() {
return this.stateGraphWrapper;
}
......
......@@ -88,7 +88,7 @@ public class PuppetMaster {
//<0 run
if (stepUntilBlock.get() > 0)
stepUntilBlock.decrementAndGet();
System.out.println("Blocker: " + stepUntilBlock.get());
if (stepUntilBlock.get() == 0) {
publishState();
block();
......@@ -111,6 +111,7 @@ public class PuppetMaster {
if (puppet != null) {
final State<KeyData> state = puppet.getCurrentState().copy();
this.setCurrentState(state);
Platform.runLater(() -> {
......
......@@ -6,4 +6,17 @@ script main() {
//allLeft formula=`\forall` with=`a`;
allLeft on=`\forall s x; f(f(x)) = f(x)` inst_t=`c`;
}
script proj() {
impRight;
eqSymm formula = `f(c) = f(f(f(c)))`;
allLeft on =`\forall s x; f(f(x)) = f(x)` inst_t=`f(f(c))`;
allLeft on =`\forall s x; f(f(x)) = f(x)` inst_t=`c`;
//applyEqRigid;
//applyEq formula=`f(f(f(c))) = f(c)` occ=`f(f(c))`;
//applyEq formula=`f(f(f(c))) = f(c)` occ=4;
applyEq on=`f(f(c))` formula=`f(f(f(c))) = f(c)` ;
close;
//close formula=`f(f(c))=f(c)`;
}
\ 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