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> {
return (Facade.prettyPrint(node));
}
@Override
public String visit(Statements statements) {
return "{ ... " + statements.size() + " ... }";
}
@Override
public String visit(ProofScript proofScript) {
return String.format("script %s (%s) {%n",
......
......@@ -129,4 +129,14 @@ public abstract class ASTNode<T extends ParserRuleContext>
public boolean eq(ASTNode 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>
//newErrorState.setErrorState(true);
//pushState(newErrorState);
}
g.exitScope();
// System.out.println(stateStack.peek().hashCode());
exitScope(call);
finally {
g.exitScope();
// System.out.println(stateStack.peek().hashCode());
exitScope(call);
}
return null;
}
......
......@@ -13,6 +13,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.function.Supplier;
public abstract class Blocker {
public interface BlockPredicate extends Predicate<ASTNode> {
......@@ -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
public static class ParentInContext implements BlockPredicate {
......
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.data.State;
import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor;
......@@ -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.ProofScript;
import edu.kit.iti.formal.psdbg.parser.ast.Statement;
import edu.kit.iti.formal.psdbg.parser.ast.Statements;
import lombok.Getter;
import lombok.Setter;
import org.apache.logging.log4j.LogManager;
......@@ -87,6 +89,11 @@ public class StateWrapper<T> implements InterpreterObserver<T> {
lastNode.setStateAfterStmt(getInterpreterStateCopy());
if (node.equals(peekContext())) {
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> {
@Override
public Void defaultVisit(ASTNode node) {
if (node instanceof Statement)
createNormalNode(node);
LOGGER.error("enter {}", node.accept(new ShortCommandPrinter()));
createNormalNode(node);
return null;
}
@Override
public Void visit(Statements statements) {
return null;
}
@Override
public Void visit(ProofScript proofScript) {
LOGGER.error("enter {}", proofScript.accept(new ShortCommandPrinter()));
if (root) {
createRoot(proofScript);
root = false;
......@@ -125,9 +138,15 @@ public class StateWrapper<T> implements InterpreterObserver<T> {
private class ExitListener extends DefaultASTVisitor<Void> {
@Override
public Void defaultVisit(ASTNode node) {
if (node instanceof Statement)
completeLastNode(node);
LOGGER.error("exit {}", node.accept(new ShortCommandPrinter()));
completeLastNode(node);
return null;
}
@Override
public Void visit(Statements statements) {
return null;
}
}
}
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.ProofScript;
import java.util.Arrays;
import java.util.function.Supplier;
public class StepOverCommand<T> extends DebuggerCommand<T> {
@Override
......@@ -19,12 +19,15 @@ public class StepOverCommand<T> extends DebuggerCommand<T> {
ASTNode[] ctx = statePointer.getContext();
//statePointer stands on the main script, we add the script itself to the context
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();
}
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);
} else {
......
......@@ -15,8 +15,6 @@ import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;
import javafx.geometry.Point2D;
import javafx.scene.Cursor;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.apache.commons.io.FileUtils;
......@@ -81,8 +79,11 @@ public class ScriptController {
}
private ScriptArea findEditor(ASTNode node) {
File f = new File(node.getOrigin());
return findEditor(f);
if (node.getOrigin() != null) {
File f = new File(node.getOrigin());
return findEditor(f);
}
return null;
}
/**
......@@ -297,16 +298,19 @@ public class ScriptController {
logger.debug("Region for highlighting: {}", r);
ScriptArea area = findEditor(node);
double scrollY = area.getEstimatedScrollY();
area.getMarkedRegions().add(r);
if (area != null) {
area.getMarkedRegions().add(r);
getDockNode(area).focus();
area.requestFocus();
//area.scrollBy(new Point2D(0, scrollY));
area.selectRange(0, r.start, 0, r.stop);
getDockNode(area).focus();
area.requestFocus();
//area.scrollBy(new Point2D(0, scrollY));
area.selectRange(0, r.start, 0, r.stop);
lastScriptArea = area;
lastRegion = r;
lastScriptArea = area;
lastRegion = r;
} else {
logger.error("Could not find editor for: " + node.getOrigin());
}
}
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