/** * Call nextEvaluation() the expected number of times, and check that it returns true (or throws * an exception). */ @Action public void nextEval() { assert data_ != null; debug("nextEval trying nextEval() " + data_.successes + " times."); if (data_.successes > 1) { // just check that true is returned the expected number of times. for (int i = data_.successes; i > 0; i--) Assert.assertTrue(pred_.nextEvaluation()); } else if (data_.successes == 1) { Assert.assertTrue("nextEvaluation should be true", pred_.nextEvaluation()); // check that the correct results were returned. Envir newenv = pred_.getEnvir(); debug("nextEval returns newenv=" + newenv); for (int i = 0; i < names_.length; i++) { Assert.assertTrue(names_[i] + " undefined.", newenv.isDefined(names_[i])); Assert.assertEquals( names_[i] + " has incorrect value.", data_.args[i], newenv.lookup(names_[i])); } } else if (data_.successes == Eval.UNDEF) { try { pred_.nextEvaluation(); Assert.fail("Should have thrown UndefException: " + pred_); } catch (UndefException ex) { // Good! } } // else data_.successes == 0, so we do nothing. data_ = null; state_ = State.Finished; }
/** Infers as precise a fixed point as possible. */ @Action public void inferBounds() { int deductions = 1; while (deductions > 0) { bounds_.startAnalysis(); pred_.inferBounds(bounds_); bounds_.endAnalysis(); deductions = bounds_.getDeductions(); debug("inferBounds did " + deductions + " deductions, bounds=" + bounds_); } state_ = State.NoMode; }
// @requires env_ != null; public void startEval(/*@[email protected]*/ Eval data) { // Note: we use the original env here, as given to chooseMode. for (int i = 0; i < names_.length; i++) { if (env_.isDefined(names_[i])) { Expr value = data.args[i]; env_.setValue(names_[i], value); } } debug("startEval with env=" + env_); pred_.startEvaluation(); data_ = data; state_ = State.Started; }
// @requires inout.length == 3; public void chooseMode(String inout) { assert inout.length() == 3; boolean isInput[] = new boolean[names_.length]; env_ = new Envir(); // Is names_[0] an input? isInput[0] = inout.charAt(0) == 'I'; // Are names_[1..length-2] inputs? for (int i = 1; i <= names_.length - 2; i++) isInput[i] = inout.charAt(1) == 'I'; // Is names_[length-1] an input? isInput[names_.length - 1] = inout.charAt(2) == 'I'; // Now add the inputs into env. for (int i = 0; i < names_.length; i++) if (isInput[i]) env_ = env_.plus(names_[i], null); boolean shouldWork = validModes_.contains(inout); mode_ = pred_.chooseMode(env_); debug("chooseMode(" + env_ + ") --> " + mode_); if (shouldWork) Assert.assertNotNull("Valid mode expected, but got null", mode_); else Assert.assertNull("Null mode expected, but got " + mode_, mode_); if (mode_ == null) { state_ = State.NoMode; env_ = null; } else { // now check that mode is correct. for (int i = 0; i < names_.length; i++) { Assert.assertEquals("name[" + i + "] = " + names_[i], isInput[i], mode_.isInput(names_[i])); } pred_.setMode(mode_); // check that all names are defined in the output environment. Envir newenv = mode_.getEnvir(); for (int i = 0; i < names_.length; i++) Assert.assertTrue(names_[i] + " should be defined", newenv.isDefined(names_[i])); state_ = State.GotMode; // NOTE that env_ is left as the input environment. } }
/** Checks that nextEvaluation() returns false. */ public @Action void nextEvalFalse() { boolean result = pred_.nextEvaluation(); debug("nextEvalFalse gives " + result + " with env=" + env_); Assert.assertFalse(result); }