Commit 5bd02453 authored by Alexander Weigl's avatar Alexander Weigl

fixing StateWrapper and Exception in handling calls

parent 9cbd801f
Pipeline #15079 failed with stage
in 1 minute and 48 seconds
...@@ -16,6 +16,11 @@ public class ShortCommandPrinter extends DefaultASTVisitor<String> { ...@@ -16,6 +16,11 @@ public class ShortCommandPrinter extends DefaultASTVisitor<String> {
return (Facade.prettyPrint(node)); return (Facade.prettyPrint(node));
} }
@Override
public String visit(Statements statements) {
return "{ ... " + statements.size() + " ... }";
}
@Override @Override
public String visit(ProofScript proofScript) { public String visit(ProofScript proofScript) {
return String.format("script %s (%s) {%n", return String.format("script %s (%s) {%n",
......
...@@ -129,4 +129,14 @@ public abstract class ASTNode<T extends ParserRuleContext> ...@@ -129,4 +129,14 @@ public abstract class ASTNode<T extends ParserRuleContext>
public boolean eq(ASTNode other) { public boolean eq(ASTNode other) {
return equals(other); return equals(other);
} }
public int getDepth() {
int depth = 0;
ASTNode n = this;
do {
n = n.getParent();
depth++;
} while (n != null);
return depth;
}
} }
...@@ -531,9 +531,11 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -531,9 +531,11 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
//newErrorState.setErrorState(true); //newErrorState.setErrorState(true);
//pushState(newErrorState); //pushState(newErrorState);
} }
g.exitScope(); finally {
// System.out.println(stateStack.peek().hashCode()); g.exitScope();
exitScope(call); // System.out.println(stateStack.peek().hashCode());
exitScope(call);
}
return null; return null;
} }
......
...@@ -13,6 +13,7 @@ import java.util.HashSet; ...@@ -13,6 +13,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.Supplier;
public abstract class Blocker { public abstract class Blocker {
public interface BlockPredicate extends Predicate<ASTNode> { public interface BlockPredicate extends Predicate<ASTNode> {
...@@ -100,6 +101,18 @@ public abstract class Blocker { ...@@ -100,6 +101,18 @@ public abstract class Blocker {
} }
} }
@RequiredArgsConstructor
public static class SmallerContext implements BlockPredicate {
private final int depth;
private final Supplier<Integer> currenDepth;
@Override
public boolean test(ASTNode astNode) {
return currenDepth.get() <= depth;
}
}
@RequiredArgsConstructor @RequiredArgsConstructor
public static class ParentInContext implements BlockPredicate { public static class ParentInContext implements BlockPredicate {
......
package edu.kit.iti.formal.psdbg.interpreter.dbg; package edu.kit.iti.formal.psdbg.interpreter.dbg;
import edu.kit.iti.formal.psdbg.ShortCommandPrinter;
import edu.kit.iti.formal.psdbg.interpreter.Interpreter; import edu.kit.iti.formal.psdbg.interpreter.Interpreter;
import edu.kit.iti.formal.psdbg.interpreter.data.State; import edu.kit.iti.formal.psdbg.interpreter.data.State;
import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor; import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor;
...@@ -7,6 +8,7 @@ import edu.kit.iti.formal.psdbg.parser.Visitor; ...@@ -7,6 +8,7 @@ import edu.kit.iti.formal.psdbg.parser.Visitor;
import edu.kit.iti.formal.psdbg.parser.ast.ASTNode; import edu.kit.iti.formal.psdbg.parser.ast.ASTNode;
import edu.kit.iti.formal.psdbg.parser.ast.ProofScript; import edu.kit.iti.formal.psdbg.parser.ast.ProofScript;
import edu.kit.iti.formal.psdbg.parser.ast.Statement; import edu.kit.iti.formal.psdbg.parser.ast.Statement;
import edu.kit.iti.formal.psdbg.parser.ast.Statements;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
...@@ -87,6 +89,11 @@ public class StateWrapper<T> implements InterpreterObserver<T> { ...@@ -87,6 +89,11 @@ public class StateWrapper<T> implements InterpreterObserver<T> {
lastNode.setStateAfterStmt(getInterpreterStateCopy()); lastNode.setStateAfterStmt(getInterpreterStateCopy());
if (node.equals(peekContext())) { if (node.equals(peekContext())) {
popContext(); popContext();
} else {
LOGGER.error("Context mismatched, got {}, expected {}",
node.accept(new ShortCommandPrinter()),
peekContext().accept(new ShortCommandPrinter())
);
} }
} }
...@@ -105,13 +112,19 @@ public class StateWrapper<T> implements InterpreterObserver<T> { ...@@ -105,13 +112,19 @@ public class StateWrapper<T> implements InterpreterObserver<T> {
@Override @Override
public Void defaultVisit(ASTNode node) { public Void defaultVisit(ASTNode node) {
if (node instanceof Statement) LOGGER.error("enter {}", node.accept(new ShortCommandPrinter()));
createNormalNode(node); createNormalNode(node);
return null;
}
@Override
public Void visit(Statements statements) {
return null; return null;
} }
@Override @Override
public Void visit(ProofScript proofScript) { public Void visit(ProofScript proofScript) {
LOGGER.error("enter {}", proofScript.accept(new ShortCommandPrinter()));
if (root) { if (root) {
createRoot(proofScript); createRoot(proofScript);
root = false; root = false;
...@@ -125,9 +138,15 @@ public class StateWrapper<T> implements InterpreterObserver<T> { ...@@ -125,9 +138,15 @@ public class StateWrapper<T> implements InterpreterObserver<T> {
private class ExitListener extends DefaultASTVisitor<Void> { private class ExitListener extends DefaultASTVisitor<Void> {
@Override @Override
public Void defaultVisit(ASTNode node) { public Void defaultVisit(ASTNode node) {
if (node instanceof Statement) LOGGER.error("exit {}", node.accept(new ShortCommandPrinter()));
completeLastNode(node); completeLastNode(node);
return null; return null;
} }
@Override
public Void visit(Statements statements) {
return null;
}
} }
} }
package edu.kit.iti.formal.psdbg.interpreter.dbg; package edu.kit.iti.formal.psdbg.interpreter.dbg;
import edu.kit.iti.formal.psdbg.parser.ast.ASTNode; import edu.kit.iti.formal.psdbg.parser.ast.ASTNode;
import edu.kit.iti.formal.psdbg.parser.ast.ProofScript;
import java.util.Arrays; import java.util.Arrays;
import java.util.function.Supplier;
public class StepOverCommand<T> extends DebuggerCommand<T> { public class StepOverCommand<T> extends DebuggerCommand<T> {
@Override @Override
...@@ -19,12 +19,15 @@ public class StepOverCommand<T> extends DebuggerCommand<T> { ...@@ -19,12 +19,15 @@ public class StepOverCommand<T> extends DebuggerCommand<T> {
ASTNode[] ctx = statePointer.getContext(); ASTNode[] ctx = statePointer.getContext();
//statePointer stands on the main script, we add the script itself to the context //statePointer stands on the main script, we add the script itself to the context
if (statePointer.getContext().length == 0) { if (statePointer.getContext().length == 0) {
ctx = Arrays.copyOf(ctx, ctx.length+1); ctx = Arrays.copyOf(ctx, ctx.length + 1);
ctx[ctx.length - 1] = statePointer.getStatement(); ctx[ctx.length - 1] = statePointer.getStatement();
} }
Supplier<Integer> currenDepth = () -> dbg.getStatePointer().getContext().length;
Blocker.BlockPredicate predicate = new Blocker.ParentInContext(ctx); //Blocker.BlockPredicate predicate = new Blocker.ParentInContext(ctx);
Blocker.SmallerContext predicate = new Blocker.SmallerContext(
currenDepth.get(), currenDepth);
dbg.releaseUntil(predicate); dbg.releaseUntil(predicate);
} else { } else {
......
...@@ -15,8 +15,6 @@ import javafx.beans.value.ChangeListener; ...@@ -15,8 +15,6 @@ import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableMap; import javafx.collections.ObservableMap;
import javafx.geometry.Point2D;
import javafx.scene.Cursor;
import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CharStreams;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
...@@ -81,8 +79,11 @@ public class ScriptController { ...@@ -81,8 +79,11 @@ public class ScriptController {
} }
private ScriptArea findEditor(ASTNode node) { private ScriptArea findEditor(ASTNode node) {
File f = new File(node.getOrigin()); if (node.getOrigin() != null) {
return findEditor(f); File f = new File(node.getOrigin());
return findEditor(f);
}
return null;
} }
/** /**
...@@ -297,16 +298,19 @@ public class ScriptController { ...@@ -297,16 +298,19 @@ public class ScriptController {
logger.debug("Region for highlighting: {}", r); logger.debug("Region for highlighting: {}", r);
ScriptArea area = findEditor(node); ScriptArea area = findEditor(node);
double scrollY = area.getEstimatedScrollY(); if (area != null) {
area.getMarkedRegions().add(r); area.getMarkedRegions().add(r);
getDockNode(area).focus(); getDockNode(area).focus();
area.requestFocus(); area.requestFocus();
//area.scrollBy(new Point2D(0, scrollY)); //area.scrollBy(new Point2D(0, scrollY));
area.selectRange(0, r.start, 0, r.stop); area.selectRange(0, r.start, 0, r.stop);
lastScriptArea = area; lastScriptArea = area;
lastRegion = r; lastRegion = r;
} else {
logger.error("Could not find editor for: " + node.getOrigin());
}
} }
public void remove() { public void remove() {
......
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