Commit d5199937 authored by Sarah Grebing's avatar Sarah Grebing

Highlighting of next ASTNode, revealed a bug in copy method of ASTNodes

parent a6919087
Pipeline #14960 failed with stage
in 2 minutes and 48 seconds
......@@ -61,6 +61,7 @@ public class AssignmentStatement
s.lhs = lhs.copy();
s.rhs = rhs.copy();
s.type = type;
s.setRuleContext(this.ruleContext);
return s;
}
......
......@@ -58,6 +58,7 @@ public class BinaryExpression extends Expression<ParserRuleContext> {
@Override
public BinaryExpression copy() {
BinaryExpression be = new BinaryExpression(left.copy(), operator, right.copy());
be.setRuleContext(this.ruleContext);
return be;
}
......
......@@ -63,6 +63,9 @@ public class CallStatement extends Statement<ScriptLanguageParser.ScriptCommandC
*/
@Override
public CallStatement copy() {
return new CallStatement(command, parameters.copy());
CallStatement s = new CallStatement(command, parameters.copy());
s.setRuleContext(this.getRuleContext());
return s;
}
}
......@@ -52,6 +52,8 @@ public class CaseStatement extends Statement<ScriptLanguageParser.CasesListConte
* {@inheritDoc}
*/
@Override public CaseStatement copy() {
return new CaseStatement(isClosedStmt, body.copy());
CaseStatement cs = new CaseStatement(isClosedStmt, body.copy());
cs.setRuleContext(this.ruleContext);
return cs;
}
}
......@@ -60,6 +60,7 @@ public class CasesStatement extends Statement<ScriptLanguageParser.CasesStmtCont
// c.defaultCase = defaultCase.copy();
if (defCaseStmt != null)
c.defCaseStmt = defCaseStmt.copy();
c.setRuleContext(this.ruleContext);
return c;
}
}
......@@ -42,7 +42,9 @@ public class ClosesCase extends CaseStatement {
*/
@Override
public ClosesCase copy() {
return new ClosesCase(closesScript.copy(), body.copy());
ClosesCase cs = new ClosesCase(closesScript.copy(), body.copy());
cs.setRuleContext(this.ruleContext);
return cs;
}
}
......@@ -31,7 +31,9 @@ public class DefaultCaseStatement extends Statement<ScriptLanguageParser.StmtLis
*/
@Override
public DefaultCaseStatement copy() {
return new DefaultCaseStatement(body.copy());
DefaultCaseStatement dcs = new DefaultCaseStatement(body.copy());
dcs.setRuleContext(this.ruleContext);
return dcs;
}
}
......
......@@ -52,6 +52,8 @@ public class ForeachStatement extends GoalSelector<ScriptLanguageParser.ForEachS
* {@inheritDoc}
*/
@Override public ForeachStatement copy() {
return new ForeachStatement(getBody().copy());
ForeachStatement fs = new ForeachStatement(getBody().copy());
fs.setRuleContext(this.ruleContext);
return fs;
}
}
......@@ -67,6 +67,7 @@ public class MatchExpression extends Expression<ScriptLanguageParser.MatchPatter
if (signature != null)
me.signature = signature.copy();
me.pattern = pattern.copy();
me.setRuleContext(this.ruleContext);
return me;
}
......
......@@ -53,6 +53,7 @@ public class Parameters extends ASTNode<ScriptLanguageParser.ParametersContext>
@Override public Parameters copy() {
Parameters p = new Parameters();
forEach((k, v) -> p.put(k.copy(), v.copy()));
p.setRuleContext(this.getRuleContext());
return p;
}
......
......@@ -54,6 +54,7 @@ public class ProofScript extends ASTNode<ScriptLanguageParser.ScriptContext> {
ps.setName(getName());
ps.setBody(body.copy());
ps.setSignature(signature.copy());
ps.setRuleContext(this.ruleContext);
return ps;
}
......
......@@ -54,6 +54,8 @@ public class RepeatStatement extends GoalSelector<ScriptLanguageParser.RepeatStm
*/
@Override
public RepeatStatement copy() {
return new RepeatStatement(getBody().copy());
RepeatStatement rs = new RepeatStatement(getBody().copy());
rs.setRuleContext(this.ruleContext);
return rs;
}
}
......@@ -54,6 +54,7 @@ public class Signature extends ASTNode<ScriptLanguageParser.ArgListContext> impl
@Override public Signature copy() {
Signature signature = new Signature();
forEach((k, v) -> signature.put(k.copy(), v));
signature.setRuleContext(this.ruleContext);
return signature;
}
......
......@@ -33,7 +33,9 @@ public class SimpleCaseStatement extends CaseStatement {
*/
@Override
public SimpleCaseStatement copy() {
return new SimpleCaseStatement(guard.copy(), body.copy());
SimpleCaseStatement scs = new SimpleCaseStatement(guard.copy(), body.copy());
scs.setRuleContext(this.ruleContext);
return scs;
}
......
......@@ -174,7 +174,12 @@ public class Statements extends ASTNode<ScriptLanguageParser.StmtListContext>
@Override public Statements copy() {
Statements s = new Statements();
forEach(e -> s.add(e.copy()));
forEach(e -> {
Statement ecopy = e.copy();
ecopy.setRuleContext(e.getRuleContext());
s.add(ecopy);
});
s.setRuleContext(this.getRuleContext());
return s;
}
}
......@@ -39,6 +39,7 @@ public class SubstituteExpression extends Expression<ScriptLanguageParser.ExprSu
SubstituteExpression se = new SubstituteExpression();
se.sub = sub.copy();
se.substitution = new LinkedHashMap<>(substitution);
se.setRuleContext(this.ruleContext);
return se;
}
......
......@@ -54,6 +54,8 @@ public class TheOnlyStatement extends GoalSelector<ScriptLanguageParser.TheOnlyS
*/
@Override
public TheOnlyStatement copy() {
return new TheOnlyStatement(getBody().copy());
TheOnlyStatement tos = new TheOnlyStatement(getBody().copy());
tos.setRuleContext(this.ruleContext);
return tos;
}
}
......@@ -29,6 +29,8 @@ public class TryCase extends CaseStatement {
*/
@Override
public TryCase copy() {
return new TryCase(body.copy());
TryCase tc = new TryCase(body.copy());
tc.setRuleContext(this.getRuleContext());
return tc;
}
}
......@@ -61,6 +61,7 @@ public class UnaryExpression extends Expression<ParserRuleContext> {
@Override
public UnaryExpression copy() {
UnaryExpression u = new UnaryExpression(operator, expression.copy());
u.setRuleContext(this.getRuleContext());
return u;
}
......
......@@ -117,7 +117,7 @@ public class InterpreterBuilder {
}
public InterpreterBuilder onEntry(Visitor v) {
interpreter.getEntryListeners().add(v);
interpreter.getEntryListeners().add(0, v);
return this;
}
......
......@@ -46,8 +46,8 @@ public class TryCaseHistoryLogger extends HistoryListener {
public void install(Interpreter interpreter) {
if (currentInterpreter != null) deinstall(interpreter);
interpreter.getEntryListeners().add(entryListener);
interpreter.getExitListeners().add(exitListener);
interpreter.getEntryListeners().add(0, entryListener);
interpreter.getExitListeners().add(0, exitListener);
this.currentInterpreter = interpreter;
}
......
......@@ -37,6 +37,8 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
//We now need thet stack of listeners to handle try statements scuh that listnersa re only informed if a try was sucessfull
private Stack<List<Visitor>> entryListenerStack = new Stack<>();
private Stack<List<Visitor>> exitListenerStack = new Stack<>();
//there is at most one special listener that is allowed to block and that is invoked last when informing all listeners
private Visitor blockingEntryListener = new DefaultASTVisitor();
//@Getter
//private List<Visitor> entryListeners = new ArrayList<>(),
......@@ -71,6 +73,14 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
return entryListenerStack.peek();
}
public void addBlockingEntryListener(Visitor v) {
blockingEntryListener = v;
}
public void removeBlockingEntryListener() {
blockingEntryListener = new DefaultASTVisitor();
}
/**
* starting point is a statement list
*/
......
......@@ -60,7 +60,7 @@ public class InterpreterExtendedState<T> {
} else {
ext.predecessor = null;
}
ext.setStmt(stmt.copy());
ext.setStmt(stmt);
if (stateAfterStmt != null) {
ext.setStateAfterStmt(this.stateAfterStmt.copy());
} else {
......
......@@ -4,7 +4,6 @@ import edu.kit.iti.formal.psdbg.interpreter.HistoryListener;
import edu.kit.iti.formal.psdbg.interpreter.Interpreter;
import edu.kit.iti.formal.psdbg.interpreter.data.GoalNode;
import edu.kit.iti.formal.psdbg.interpreter.data.State;
import edu.kit.iti.formal.psdbg.parser.data.Value;
import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment;
import edu.kit.iti.formal.psdbg.interpreter.funchdl.BuiltinCommands;
import edu.kit.iti.formal.psdbg.interpreter.funchdl.CommandHandler;
......@@ -13,6 +12,8 @@ import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor;
import edu.kit.iti.formal.psdbg.parser.Facade;
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.TransformAst;
import edu.kit.iti.formal.psdbg.parser.ast.*;
import edu.kit.iti.formal.psdbg.parser.data.Value;
import org.antlr.v4.runtime.CharStreams;
import java.io.BufferedReader;
......@@ -22,7 +23,6 @@ import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.List;
import java.util.function.BiConsumer;
import edu.kit.iti.formal.psdbg.parser.ast.*;
/**
* @author Alexander Weigl
* @version 1 (21.05.2017)
......@@ -44,8 +44,8 @@ public class Debugger {
history = new HistoryListener(interpreter);
scripts = Facade.getAST(new File(file));
interpreter.getEntryListeners().add(history);
interpreter.getEntryListeners().add(blocker);
interpreter.getEntryListeners().add(new CommandLogger());
interpreter.getEntryListeners().add(blocker);
registerDebuggerFunction("step", this::step);
registerDebuggerFunction("b", this::setBreakpoint);
......
......@@ -276,8 +276,6 @@ public class StateGraphWrapper<T> {
}
private void fireNodeAdded(NodeAddedEvent nodeAddedEvent) {
//counter++;
//System.out.println("XXXXXXXXXX counter = " + counter);
changeListeners.forEach(list -> Platform.runLater(() -> {
list.graphChanged(nodeAddedEvent);
//TODO
......@@ -287,8 +285,8 @@ public class StateGraphWrapper<T> {
public void install(Interpreter<T> interpreter) {
if (currentInterpreter != null) deinstall(interpreter);
interpreter.getEntryListeners().add(entryListener);
interpreter.getExitListeners().add(exitListener);
interpreter.getEntryListeners().add(0, entryListener);
interpreter.getExitListeners().add(0, exitListener);
currentInterpreter = interpreter;
}
......
......@@ -3,6 +3,7 @@ package edu.kit.iti.formal.psdbg.gui.controller;
import com.google.common.eventbus.Subscribe;
import com.google.common.graph.MutableValueGraph;
import edu.kit.iti.formal.psdbg.InterpretingService;
import edu.kit.iti.formal.psdbg.gui.controls.ASTNodeHiglightListener;
import edu.kit.iti.formal.psdbg.gui.controls.DebuggerStatusBar;
import edu.kit.iti.formal.psdbg.gui.controls.Utils;
import edu.kit.iti.formal.psdbg.gui.model.Breakpoint;
......@@ -195,7 +196,7 @@ public class ProofTreeController {
LOGGER.info("Setting new State " + state.toString());
//Statepointer null wenn anfangszustand?
if (statePointer != null && state != null) {
setCurrentHighlightNode(statePointer.getScriptstmt());
//setCurrentHighlightNode(statePointer.getScriptstmt());
//get all goals that are open
Object[] arr = state.getGoals().stream().filter(keyDataGoalNode -> !keyDataGoalNode.isClosed()).toArray();
//if there is no selected goal node we might have reached
......@@ -253,7 +254,7 @@ public class ProofTreeController {
//if nextnode is null ask interpreter to execute next statement and compute next state
if (nextNode != null) {
setCurrentHighlightNode(nextNode.getScriptstmt());
//setCurrentHighlightNode(nextNode.getScriptstmt());
}
if (nextNode != null && nextNode.getExtendedState().getStateAfterStmt() != null) {
......@@ -330,7 +331,7 @@ public class ProofTreeController {
statusBar.setText("Starting to interpret script " + mainScript.getName());
statusBar.indicateProgress();
setCurrentHighlightNode(mainScript.get());
//setCurrentHighlightNode(mainScript.get());
//build CFG
buildControlFlowGraph(mainScript.get());
......@@ -341,6 +342,16 @@ public class ProofTreeController {
this.stateGraphWrapper.install(currentInterpreter);
this.stateGraphWrapper.addChangeListener(graphChangedListener);
ASTNodeHiglightListener astNodeHiglightListener = new ASTNodeHiglightListener(currentInterpreter);
astNodeHiglightListener.install(currentInterpreter);
astNodeHiglightListener.currentHighlightNodeProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
ASTNode astNode = (ASTNode) newValue;
setCurrentHighlightNode(astNode);
//this.setCurrentHighlightNode();
}
});
statusBar.publishMessage("Stategraph was set up");
statusBar.stopProgress();
......
......@@ -83,12 +83,12 @@ public class PuppetMaster {
}
public Void checkForHalt(ASTNode node) {
System.out.println("node = [" + node + "]");
//("PuppetMaster CheckForHalt node = [" + node + "]");
//<0 run
if (stepUntilBlock.get() > 0)
stepUntilBlock.decrementAndGet();
System.out.println("Blocker: " + stepUntilBlock.get());
if (stepUntilBlock.get() == 0) {
//publishState();
block();
......
package edu.kit.iti.formal.psdbg.gui.controls;
import edu.kit.iti.formal.psdbg.interpreter.Interpreter;
import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor;
import edu.kit.iti.formal.psdbg.parser.ast.ASTNode;
import edu.kit.iti.formal.psdbg.parser.ast.CallStatement;
import edu.kit.iti.formal.psdbg.parser.ast.ProofScript;
import edu.kit.iti.formal.psdbg.parser.ast.Statements;
import javafx.application.Platform;
import javafx.beans.property.SimpleObjectProperty;
/**
* Sets a property that can be used to highlight ASTNodes in the SScriptArea according to current interpreterstate
* Contains a listener that listens on entry of an ASTNode
*
* @param <T>
*/
public class ASTNodeHiglightListener<T> {
private SimpleObjectProperty<ASTNode> currentHighlightNode = new SimpleObjectProperty<>();
private Interpreter<T> currentInterpreter;
private HighlightEntryListener list = new HighlightEntryListener();
private ASTNode lastHighlightedNode;
public ASTNodeHiglightListener(Interpreter<T> inter) {
}
public ASTNode getCurrentHighlightNode() {
return currentHighlightNode.get();
}
public void setCurrentHighlightNode(ASTNode currentHighlightNode) {
this.currentHighlightNode.set(currentHighlightNode);
}
public SimpleObjectProperty<ASTNode> currentHighlightNodeProperty() {
return currentHighlightNode;
}
public void install(Interpreter<T> interpreter) {
if (currentInterpreter != null) deinstall(interpreter);
int i = interpreter.getEntryListeners().size();
interpreter.getEntryListeners().add(0, list);
// interpreter.getExitListeners().add(0, exitListener);
currentInterpreter = interpreter;
}
private void deinstall(Interpreter<T> interpreter) {
if (interpreter != null) {
interpreter.getEntryListeners().remove(list);
// interpreter.getExitListeners().remove(exitListener);
}
}
public class HighlightEntryListener extends DefaultASTVisitor<Void> {
@Override
public Void visit(ProofScript proofScript) {
return defaultVisit(proofScript);
}
@Override
public Void visit(CallStatement proofScript) {
return defaultVisit(proofScript);
}
@Override
public Void visit(Statements statements) {
return null;
}
@Override
public Void defaultVisit(ASTNode node) {
if (node != null) {
lastHighlightedNode = node;
System.out.println("nodeInHighlighter = " + node);
System.out.println("lastHighlightedNode = " + lastHighlightedNode);
Platform.runLater(() -> {
currentHighlightNode.setValue(lastHighlightedNode);
});
}
return null;
}
}
}
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