Commit 729fe9ca authored by Alexander Weigl's avatar Alexander Weigl

Merge branch 'master' of git.scc.kit.edu:xt9634/ProofScriptParser

* 'master' of git.scc.kit.edu:xt9634/ProofScriptParser:
  Small working debugger, with some little quirks.
parents 490a1bc0 3836841d
package edu.kit.formal.dbg;
import edu.kit.formal.proofscriptparser.DefaultASTVisitor;
import edu.kit.formal.proofscriptparser.ast.ASTNode;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;
/**
* Created by weigl on 21.05.2017.
*/
public class Blocker extends DefaultASTVisitor<Void> {
public AtomicInteger stepUntilBlock = new AtomicInteger(-1);
//needs to threadable
public Set<Integer> brkpnts = new TreeSet<>();
public final Lock lock = new ReentrantLock();
public final Condition block = lock.newCondition();
@Override
public Void defaultVisit(ASTNode node) {
if (stepUntilBlock.get() > 0)
stepUntilBlock.decrementAndGet();
if (stepUntilBlock.get() == 0)
block();
int lineNumber = node.getStartPosition().getLineNumber();
if (brkpnts.contains(lineNumber)) {
block();
}
return super.defaultVisit(node);
}
private void block() {
try {
lock.lock();
block.await();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
lock.unlock();
}
}
public void addBreakpoint(int i) {
brkpnts.add(i);
}
public void unlock() {
try {
lock.lock();
block.signal();
} finally {
lock.unlock();
}
}
}
This diff is collapsed.
......@@ -7,6 +7,7 @@ import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
......@@ -16,7 +17,6 @@ import java.util.List;
* @author A. Weigl
*/
public class Evaluator extends DefaultASTVisitor<Value> implements ScopeObservable {
private GoalNode currentState;
private List<VariableAssignment> matchedVariables = new ArrayList<>();
@Getter
@Setter
......@@ -27,13 +27,12 @@ public class Evaluator extends DefaultASTVisitor<Value> implements ScopeObservab
private List<Visitor> entryListeners = new ArrayList<>(),
exitListeners = new ArrayList<>();
public Evaluator(GoalNode s) {
this.currentState = s;
}
private final GoalNode goal;
private final VariableAssignment state;
public Evaluator(GoalNode g, MatcherApi matcherApi) {
this(g);
setMatcher(matcherApi);
public Evaluator(VariableAssignment assignment, GoalNode node) {
state = new VariableAssignment(assignment); // unmodifiable version of assignment
goal = node;
}
/**
......@@ -66,9 +65,9 @@ public class Evaluator extends DefaultASTVisitor<Value> implements ScopeObservab
List<VariableAssignment> va = null;
if (pattern.getType() == Type.STRING) {
va = matcher.matchLabel(currentState, (String) pattern.getData());
va = matcher.matchLabel(goal, (String) pattern.getData());
} else if (pattern.getType() == Type.TERM) {
va = matcher.matchSeq(currentState, (String) pattern.getData());
va = matcher.matchSeq(goal, (String) pattern.getData());
}
return va != null && va.size() > 0 ? Value.TRUE : Value.FALSE;
......@@ -94,7 +93,7 @@ public class Evaluator extends DefaultASTVisitor<Value> implements ScopeObservab
public Value visit(Variable variable) {
//get variable value
String id = variable.getIdentifier();
Value v = currentState.lookupVarValue(id);
Value v = state.lookupVarValue(id);
if (v != null) {
return v;
} else {
......
......@@ -16,6 +16,7 @@ import java.util.List;
public class HistoryListener extends DefaultASTVisitor<Void> {
@Getter
private final List<ASTNode> queueNode = new LinkedList<>();
@Getter
private final List<AbstractState> queueState = new LinkedList<>();
private final Interpreter interpreter;
......
......@@ -113,7 +113,8 @@ public class Interpreter extends DefaultASTVisitor<Void>
private Value evaluate(GoalNode g, Expression expr) {
enterScope(expr);
Evaluator evaluator = new Evaluator(g, matcherApi);
Evaluator evaluator = new Evaluator(g.getAssignments(),g);
evaluator.setMatcher(matcherApi);
evaluator.getEntryListeners().addAll(entryListeners);
evaluator.getExitListeners().addAll(exitListeners);
exitScope(expr);
......@@ -272,7 +273,7 @@ public class Interpreter extends DefaultASTVisitor<Void>
}
private VariableAssignment evaluateParameters(Parameters parameters) {
public VariableAssignment evaluateParameters(Parameters parameters) {
VariableAssignment va = new VariableAssignment();
parameters.entrySet().forEach(entry -> {
Value val = evaluate(entry.getValue());
......@@ -370,18 +371,18 @@ public class Interpreter extends DefaultASTVisitor<Void>
return stateStack.peek();
}
private AbstractState newState(List<GoalNode> goals, GoalNode selected) {
public AbstractState newState(List<GoalNode> goals, GoalNode selected) {
if (selected != null && !goals.contains(selected)) {
throw new IllegalStateException("selected goal not in list of goals");
}
return pushState(new State(goals, selected));
}
private AbstractState newState(List<GoalNode> goals) {
public AbstractState newState(List<GoalNode> goals) {
return newState(goals, null);
}
private AbstractState newState(GoalNode selected) {
public AbstractState newState(GoalNode selected) {
return newState(Collections.singletonList(selected), selected);
}
......@@ -393,7 +394,7 @@ public class Interpreter extends DefaultASTVisitor<Void>
return state;
}
private void popState(AbstractState expected) {
public void popState(AbstractState expected) {
AbstractState actual = stateStack.pop();
if (!expected.equals(actual)) {
throw new IllegalStateException("Error on the stack!");
......
......@@ -23,7 +23,6 @@ package edu.kit.formal.proofscriptparser;
*/
import edu.kit.formal.proofscriptparser.ast.*;
import lombok.Getter;
import lombok.Setter;
......@@ -83,9 +82,9 @@ public class PrettyPrinter extends DefaultASTVisitor<Void> {
@Override
public Void visit(AssignmentStatement assign) {
assign.getRhs().accept(this);
s.append(" := ");
assign.getLhs().accept(this);
s.append(" := ");
assign.getRhs().accept(this);
s.append(";");
return null;
}
......@@ -299,8 +298,11 @@ public class PrettyPrinter extends DefaultASTVisitor<Void> {
int posnewline = s.length() - 1;
while (s.charAt(posnewline) != '\n') {
posnewline--;
if (posnewline < 0) {
break;
}
}
return posnewline;
return Math.max(posnewline, 0);
}
private String getWhitespacePrefix() {
......
......@@ -43,7 +43,7 @@ public class EvaluatorTest {
va.setVarValue("a", Value.from(1));
va.setVarValue("b", Value.from(1));
GoalNode selected = new GoalNode(parent, "selg");
eval = new Evaluator(selected);
eval = new Evaluator(selected.getAssignments(), selected);
eval.setMatcher(new PseudoMatcher());
}
......@@ -58,7 +58,7 @@ public class EvaluatorTest {
static class PseudoMatcher implements MatcherApi {
@Override
public List<VariableAssignment> matchLabel(GoalNode currentState, String label) {
Pattern p = Pattern.compile(label,Pattern.CASE_INSENSITIVE);
Pattern p = Pattern.compile(label, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(currentState.getSequent());
return m.matches()
? Collections.singletonList(new VariableAssignment())
......
script Simple1(i:int, j:int) {
i := 1;
j := 2;
theonly {
i := 4;
j := i+i;
}
split 5;
foreach {
i := 4;
j := i+i;
}
repeat {
foreach { i := i + 1; split;}
}
}
\ 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