MCPcopy Create free account
hub / github.com/Whiley/WhileyCompiler / QuickCheck

Class QuickCheck

src/main/java/wyc/task/QuickCheck.java:30–1222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28import wyil.lang.WyilFile.Type.Callable;
29
30public class QuickCheck {
31 public static final Context DEFAULT_CONTEXT = new Context(-3, 3, 3, 3, 2, 2, new String[0], BigDecimal.ONE, 1000,
32 10_000_000, Long.MAX_VALUE);
33 /**
34 * The interpreter instance used for executing code.
35 */
36 private ExtendedInterpreter interpreter;
37
38 /**
39 * Cache of previously computed values. This is useful for reducing memory
40 * requirements. Furthermore, it is necessary to ensure that aliasing bugs are
41 * identified.
42 */
43 private final HashMap<Name, Domain.Big<RValue>> cache = new HashMap<>();
44 /**
45 * Provides the output channel for information about the quick check process.
46 */
47 private final StructuredLogger<LogEntry> logger;
48
49 public QuickCheck(Logger log) {
50 // Default logger just reports up to project logger
51 this.logger = new StructuredLogger<>() {
52 @Override
53 public void logTimedMessage(LogEntry result, long time, long memory) {
54 log.logTimedMessage(result.toString(), time, memory);
55 }
56
57 @Override
58 public void logTimedMessage(String msg, long time, long memory) {
59 log.logTimedMessage(msg, time, memory);
60 }
61 };
62 }
63
64 public boolean check(WyilFile parent, Context context, List<String> targets, WyilFile... deps)
65 throws IOException {
66 try {
67 // Initialise Interpreter
68 this.interpreter = new ExtendedInterpreter(System.err, context, ArrayUtils.append(parent, deps));
69 // Construct extended context
70 ExtendedContext eContext = interpreter.getExtendedContext();
71 // Initialise by context
72 return check(parent, eContext, targets);
73 } catch (Interpreter.RuntimeError e) {
74 // Add appropriate syntax error to the syntactic item where the error arose.
75 ErrorMessages.syntaxError(e.getElement(), e.getErrorCode());
76 // Done
77 return false;
78 }
79 }
80
81 public boolean check(WyilFile parent, ExtendedContext context, List<String> targets) throws IOException {
82 boolean OK = true;
83 if(targets.isEmpty()) {
84 for (Decl.Unit unit : parent.getModule().getUnits()) {
85 OK &= check(parent,unit, context);
86 }
87 } else {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected