From: John P. <joh...@us...> - 2005-09-11 16:16:22
|
Update of /cvsroot/javapathfinder/javapathfinder/src/gov/nasa/jpf/jvm/choice In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26770/src/gov/nasa/jpf/jvm/choice Modified Files: TwoIntChoice.java IntChoiceFromSet.java Log Message: * two new choice generators for integers Index: IntChoiceFromSet.java =================================================================== RCS file: /cvsroot/javapathfinder/javapathfinder/src/gov/nasa/jpf/jvm/choice/IntChoiceFromSet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- IntChoiceFromSet.java 9 Sep 2005 23:31:42 -0000 1.2 +++ IntChoiceFromSet.java 11 Sep 2005 16:16:14 -0000 1.3 @@ -1,3 +1,22 @@ +// +//Copyright (C) 2005 United States Government as represented by the +//Administrator of the National Aeronautics and Space Administration +//(NASA). All Rights Reserved. +// +//This software is distributed under the NASA Open Source Agreement +//(NOSA), version 1.3. The NOSA has been approved by the Open Source +//Initiative. See the file NOSA-1.3-JPF at the top of the distribution +//directory tree for the complete NOSA document. +// +//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY +//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT +//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO +//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR +//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT +//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT +//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE. +// + /* * Created on Sep 8, 2005 * @@ -9,7 +28,7 @@ import gov.nasa.jpf.Config; import gov.nasa.jpf.jvm.IntChoiceGenerator; import gov.nasa.jpf.jvm.JVM; - +import gov.nasa.jpf.JPFException; /** * @author jpenix * @@ -22,34 +41,42 @@ */ public class IntChoiceFromSet extends IntChoiceGenerator { + // int values to choose from stored as strings String[] values; - int count = 0; + + int count = -1; /** * @param id */ public IntChoiceFromSet(Config conf, String id) { super(id); - values = conf.getStringArray("values"); + values = conf.getStringArray(id + ".values"); + if (values == null) { + throw new JPFException("value set for <" + id + "> choice did not load"); + } } /* (non-Javadoc) * @see gov.nasa.jpf.jvm.IntChoiceGenerator#getNextChoice() */ public int getNextChoice(JVM vm) { -// try { - int ret = Integer.parseInt(values[count]); - System.out.println(id + ": " + ret); + + try { + // watch out this returns 0 if it parses wrong + int ret = Integer.parseInt(values[count]); + vm.println(id + ": " + ret); return ret; -// } catch (NumberFormatException nfx) { -// return 0; + } catch (NumberFormatException nfx) { + throw new JPFException("Number format error for <" + id +">: parsing \"" + values[count] +"\""); + } } /* (non-Javadoc) * @see gov.nasa.jpf.jvm.ChoiceGenerator#hasMoreChoices() */ public boolean hasMoreChoices(JVM vm) { - if (count < values.length) + if (count < values.length-1) return true; else return false; Index: TwoIntChoice.java =================================================================== RCS file: /cvsroot/javapathfinder/javapathfinder/src/gov/nasa/jpf/jvm/choice/TwoIntChoice.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- TwoIntChoice.java 9 Sep 2005 23:31:42 -0000 1.2 +++ TwoIntChoice.java 11 Sep 2005 16:16:14 -0000 1.3 @@ -1,3 +1,22 @@ +// +//Copyright (C) 2005 United States Government as represented by the +//Administrator of the National Aeronautics and Space Administration +//(NASA). All Rights Reserved. +// +//This software is distributed under the NASA Open Source Agreement +//(NOSA), version 1.3. The NOSA has been approved by the Open Source +//Initiative. See the file NOSA-1.3-JPF at the top of the distribution +//directory tree for the complete NOSA document. +// +//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY +//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT +//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO +//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR +//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT +//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT +//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE. +// + /* * Created on Sep 7, 2005 * @@ -17,8 +36,8 @@ */ public class TwoIntChoice extends IntChoiceGenerator { - int firstValue = 1; - int secondValue = 0; + int firstValue = 100; + int secondValue = 200; String firstMsg = "pass"; String secondMsg = "fail"; @@ -41,12 +60,13 @@ switch (state){ case 0: { ret = firstValue; - System.out.println(firstMsg); + vm.println(firstMsg); break; } case 1: { ret = secondValue; - System.out.println(secondMsg); + vm.println(secondMsg); + break; } default: { ret = 99; @@ -67,6 +87,7 @@ */ public void advance(JVM vm) { state++; + //vm.println("advancing to state "+state); } } |