Commit 76c6ac67 authored by Alexander Weigl's avatar Alexander Weigl

...

parent 6b2c2968
Pipeline #15816 passed with stages
in 9 minutes and 59 seconds
......@@ -81,4 +81,8 @@ public class Value<T> {
public String toString() {
return data + ":" + type;
}
public static Value<BigInteger> from(long val) {
return from(BigInteger.valueOf(val));
}
}
......@@ -8,6 +8,7 @@ import de.uka.ilkd.key.control.KeYEnvironment;
import de.uka.ilkd.key.macros.ProofMacro;
import de.uka.ilkd.key.macros.scripts.ProofScriptCommand;
import de.uka.ilkd.key.proof.Proof;
import edu.kit.iti.formal.psdbg.interpreter.assignhook.InterpreterOptionsHook;
import edu.kit.iti.formal.psdbg.interpreter.assignhook.KeyAssignmentHook;
import edu.kit.iti.formal.psdbg.interpreter.data.GoalNode;
import edu.kit.iti.formal.psdbg.interpreter.data.KeyData;
......@@ -52,10 +53,14 @@ public class InterpreterBuilder {
private ScopeLogger logger;
@Getter
private DefaultLookup lookup = new DefaultLookup(psh, pmh, pmc, pmr);
@Getter
private KeyAssignmentHook keyHooks = new KeyAssignmentHook();
private KeyInterpreter interpreter = new KeyInterpreter(lookup);
@Getter
private KeyAssignmentHook variableHook = new KeyAssignmentHook();
private InterpreterOptionsHook<KeyData> optionsHook = new InterpreterOptionsHook<>(interpreter);
public InterpreterBuilder addProofScripts(File file) throws IOException {
return addProofScripts(Facade.getAST(file));
......@@ -72,7 +77,8 @@ public class InterpreterBuilder {
}
public KeyInterpreter build() {
interpreter.setVariableAssignmentHook(variableHook);
interpreter.getVariableHooks().add(keyHooks);
interpreter.getVariableHooks().add(optionsHook);
return interpreter;
}
......
......@@ -5,6 +5,7 @@ import de.uka.ilkd.key.java.SourceElement;
import de.uka.ilkd.key.proof.Goal;
import de.uka.ilkd.key.proof.Node;
import de.uka.ilkd.key.proof.Proof;
import de.uka.ilkd.key.strategy.StrategyProperties;
import edu.kit.iti.formal.psdbg.LabelFactory;
import lombok.*;
......@@ -166,4 +167,7 @@ public class KeyData {
}
public StrategyProperties getActiveStrategyProperties() {
return getProof().getSettings().getStrategySettings().getActiveStrategyProperties();
}
}
import static org.junit.Assert.*;
package edu.kit.iti.formal.psdbg.interpreter.assignhook;
import de.uka.ilkd.key.api.KeYApi;
import de.uka.ilkd.key.proof.io.ProblemLoaderException;
import edu.kit.iti.formal.psdbg.interpreter.InterpreterBuilder;
import edu.kit.iti.formal.psdbg.interpreter.KeyInterpreter;
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.ProofScript;
import edu.kit.iti.formal.psdbg.parser.ast.Variable;
import edu.kit.iti.formal.psdbg.parser.data.Value;
import edu.kit.iti.formal.psdbg.parser.types.SimpleType;
import org.junit.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static edu.kit.iti.formal.psdbg.TestHelper.getFile;
/**
* @author Alexander Weigl
* @version 1 (20.11.17)
*/
public class PrintVariables {
public class PrintSpecialVariables {
@Test
public void printSpecialVariables() throws ProblemLoaderException {
File f = new File(getFile(getClass(), "../contraposition/contraposition.key"));
InterpreterBuilder ib = new InterpreterBuilder();
KeyInterpreter inter = ib.proof(KeYApi.loadFromKeyFile(f).getLoadedProof())
.startState()
.build();
inter.interpret(new ProofScript());
VariableAssignment va = inter.peekState().getSelectedGoalNode().getAssignments();
for (VariableAssignmentHook<KeyData> hook : inter.getVariableHooks()) {
System.out.format("### %s%n%n", hook.toString());
try {
DefaultAssignmentHook<KeyData> dfhook = (DefaultAssignmentHook<KeyData>) hook;
List<String> vars = new ArrayList<>(dfhook.getVariables().keySet());
vars.sort(String::compareTo);
for (String varname : vars) {
DefaultAssignmentHook.Variable v = dfhook.getVariables().get(varname);
Variable var = new Variable(v.getName());
Value rt = va.getValue(var);
System.out.printf("* `%s : %s = %s`%n%n",
v.getName(),
rt.getType(),
(rt.getType() == SimpleType.STRING
? ('"' + rt.getData().toString() + '"')
: rt.getData())
);
String doc = "no documentation";
if (v.getDocumentation() != null && !v.getDocumentation().isEmpty())
doc = v.getDocumentation().replace("\n", "\n ");
System.out.println(" " + doc);
System.out.println();
}
} catch (ClassCastException e) {
}
}
}
}
\ No newline at end of file
......@@ -36,36 +36,26 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
@Getter
public final AtomicBoolean hardStop = new AtomicBoolean(false);
@Getter
private final List<VariableAssignmentHook<T>> variableHooks = new LinkedList<>();
@Getter
protected List<Visitor> entryListeners = new ArrayList<>(),
exitListeners = new ArrayList<>();
/**
*
*/
@Getter
@Setter
private int maxIterationsRepeat = 10000;
private Stack<State<T>> stateStack = new Stack<>();
@Getter
@Setter
private MatcherApi<T> matcherApi;
@Getter
private CommandLookup functionLookup;
@Getter
@Setter
private boolean strictMode = false;
@Getter
@Setter
private VariableAssignmentHook<T> variableAssignmentHook = null;
@Getter
@Setter
private boolean suppressListeners = false;
......@@ -96,12 +86,11 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
}
//initialize environment variables
if (variableAssignmentHook != null) {
VariableAssignment va = variableAssignmentHook.getStartAssignment(getSelectedNode().getData());
for (VariableAssignmentHook<T> hook : variableHooks) {
VariableAssignment va = hook.getStartAssignment(getSelectedNode().getData());
getSelectedNode().setAssignments(
getSelectedNode().getAssignments().push(va));
}
script.accept(this);
exitScope(script);
}
......@@ -159,10 +148,12 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
}
protected boolean fireVariableAssignmentHook(GoalNode<T> node, String identifier, Value v) {
if (variableAssignmentHook != null) {
return variableAssignmentHook.handleAssignment(node.getData(), identifier, v);
for (VariableAssignmentHook<T> hook : variableHooks) {
if (hook.handleAssignment(node.getData(), identifier, v)) {
return true;
}
}
return true;
return variableHooks.size() == 0;
}
private Value evaluate(Expression expr) {
......
package edu.kit.iti.formal.psdbg.interpreter.assignhook;
import edu.kit.iti.formal.psdbg.parser.data.Value;
import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment;
import edu.kit.iti.formal.psdbg.parser.data.Value;
import lombok.Getter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
......@@ -17,33 +17,48 @@ import java.util.function.Function;
public abstract class DefaultAssignmentHook<T> implements VariableAssignmentHook<T> {
private static Logger logger = LogManager.getLogger(DefaultAssignmentHook.class);
private Map<String, Function<T, Value>> initFunctions = new HashMap<>();
private Map<String, BiFunction<T, Value, Boolean>> hooks = new HashMap<>();
@Getter
private final HashMap<String, Variable> variables = new HashMap<>();
protected <K> Variable register(String varName, String doc, BiFunction<T, Value<K>, Boolean> setter, Function<T, Value<K>> getter) {
return register(new Variable<>(varName, doc, getter, setter));
}
protected <K> Variable register(String varName, BiFunction<T, Value<K>, Boolean> setter, Function<T, Value<K>> getter) {
return register(new Variable<>(varName, null, getter, setter));
}
protected void register(String varName, BiFunction<T, Value, Boolean> setter, Function<T, Value> getter) {
initFunctions.put(varName, getter);
hooks.put(varName, setter);
protected <K> Variable register(Variable<T, K> var) {
return variables.put(var.name, var);
}
@Override
@SuppressWarnings("unchecked")
public <S> boolean handleAssignment(T data, String variableName, Value<S> value) {
if (hooks.containsKey(variableName)) {
return hooks.get(variableName).apply(data, value);
if (variables.containsKey(variableName)) {
Variable<T, S> variable = (Variable<T, S>) variables.get(variableName);
return variable.setter.apply(data, value);
}
return true;
}
@Override
@SuppressWarnings("unchecked")
public VariableAssignment getStartAssignment(T data) {
VariableAssignment va = new VariableAssignment();
for (Map.Entry<String, Function<T, Value>> s : initFunctions.entrySet()) {
Value apply = s.getValue().apply(data);
va.declare(s.getKey(), apply.getType());
va.assign(s.getKey(), apply);
for (Variable<T, ?> var : variables.values()) {
Value val = var.init.apply(data);
va.declare(var.name, val.getType());
va.assign(var.name, val);
}
return va;
}
@lombok.Value
public static class Variable<T, K> {
String name, documentation;
Function<T, Value<K>> init;
BiFunction<T, Value<K>, Boolean> setter;
}
}
......@@ -5,6 +5,8 @@ import edu.kit.iti.formal.psdbg.parser.data.Value;
import lombok.Getter;
import lombok.Setter;
import java.math.BigInteger;
public class InterpreterOptionsHook<T> extends DefaultAssignmentHook<T> {
@Getter
@Setter
......@@ -13,10 +15,10 @@ public class InterpreterOptionsHook<T> extends DefaultAssignmentHook<T> {
public InterpreterOptionsHook(Interpreter<T> interpreter) {
this.interpreter = interpreter;
register("__MAX_ITERATIONS_REPEAT",
(T data, Value v) -> {
interpreter.setMaxIterationsRepeat((Integer) v.getData());
"Sets the the upper limit for iterations in repeat loops. Default value is really high.",
(T data, Value<BigInteger> v) -> {
interpreter.setMaxIterationsRepeat(v.getData().intValue());
return true;
},
(T data) -> Value.from(interpreter.getMaxIterationsRepeat())
......@@ -24,12 +26,16 @@ public class InterpreterOptionsHook<T> extends DefaultAssignmentHook<T> {
register("__STRICT_MODE",
(T data, Value v) -> {
interpreter.setStrictMode((boolean) v.getData());
"Defines if the interpreter is in strict or relax mode. \n\n" +
"In strict mode the interpreter throws an exception in following cases:\n\n" +
"* access to undeclared or unassigned variable\n" +
"* application of non-applicable rule\n\n" +
"In non-strict mode these errors are ignored&mdash;a warning is given on the console.",
(T data, Value<Boolean> v) -> {
interpreter.setStrictMode(v.getData());
return true;
},
(T data) -> Value.from(interpreter.isStrictMode())
);
}
}
......@@ -34,27 +34,139 @@ you can do conditions other these options.
Here we give a list of the current special variables
### Interpreter options
### KeY Options
* `__MAX_ITERATIONS_REPEAT : int`
* `__KEY_DEP : BOOL = true`
Sets the the upper limit for iterations in repeat loops. Default value is really high.
no documentation
* `__STRICT_MODE : bool`
* `__KEY_MAX_STEPS : INT = 10000`
Defines if the interpreter is in strict or relax mode.
In strict mode the interpreter throws an exception in following cases:
* access to undeclared or unassigned variable
* application of non-applicable rule
In non-strict mode these errors are ignored&mdash;a warning is given on the console.
### KeY configuration
Should be a positive number and is the limit for rule application in automatic proof searchs.
* `__KEY_AUTO_MAX_STEPS : int`
* `__KEY_METHOD_OPTION : STRING = "method"`
no documentation
* `__KEY_NON_LINEAR_ARITHMETIC : STRING = "none"`
no documentation
* `__KEY_QUERY : BOOL = false`
no documentation
* `__KEY_SMT__ACTIVE_SOLVER : STRING = ""`
no documentation
* `__KEY_SMT__CHECK_FOR_SUPPORT : BOOL = true`
no documentation
* `__KEY_SMT__INT_BOUND : INT = 3`
no documentation
* `__KEY_SMT__INVARIANT_ALL : BOOL = false`
no documentation
* `__KEY_SMT__LOCSET_BOUND : INT = 3`
no documentation
* `__KEY_SMT__MAX_CONCURRENT_PROCESSES : INT = 5`
no documentation
* `__KEY_SMT__MAX_GENERIC_SORTS : INT = 2`
no documentation
* `__KEY_SMT__MAX_INTEGER : INT = 2147483645`
no documentation
* `__KEY_SMT__MIN_INTEGER : INT = -2147483645`
no documentation
* `__KEY_SMT__MODE_OF_PROGRESS_DIALOG : INT = 0`
no documentation
* `__KEY_SMT__OBJECT_BOUND : INT = 3`
no documentation
* `__KEY_SMT__PATH_FOR_SMT_TRANSLATION : STRING = ""`
no documentation
* `__KEY_SMT__SEQ_BOUND : INT = 3`
no documentation
* `__KEY_SMT__SHOW_RESULTS_AFTER_EXECUTION : BOOL = false`
no documentation
* `__KEY_SMT__STORE_TRANSLATION_TO_FILE : BOOL = false`
no documentation
* `__KEY_SMT__TIMEOUT : INT = 5000`
no documentation
* `__KEY_SMT__USE_BUILTIN_UNIQUENESS : BOOL = false`
no documentation
* `__KEY_SMT__USE_CONSTANTS_FOR_INTEGERS : BOOL = true`
no documentation
* `__KEY_SMT__USE_UI_MULTIPLICATION : BOOL = true`
no documentation
* `__KEY_SMT__heapBound : INT = 3`
no documentation
* `__KEY_SMT__useExplicitTypeHierarchy : BOOL = false`
no documentation
* `__KEY_SMT__useNullInstantiation : BOOL = true`
no documentation
* `__KEY_STOP_MODE : STRING = "default"`
no documentation
* `__KEY_TIMEOUT : INT = -1`
no documentation
### Interpreter Options
* `__MAX_ITERATIONS_REPEAT : INT = 10000`
Sets the the upper limit for iterations in repeat loops. Default value is really high.
* `__STRICT_MODE : BOOL = false`
Defines if the interpreter is in strict or relax mode.
In strict mode the interpreter throws an exception in following cases:
* access to undeclared or unassigned variable
* application of non-applicable rule
In non-strict mode these errors are ignored&mdash;a warning is given on the console.
Should be a positive number and is the limit for rule application in automatic proof searchs.
* `__KEY_MATH`
\ 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