diff src/main/gov/nasa/jpf/vm/ChoiceGeneratorBase.java @ 3:fdc263e5806b

added inverse matching in StringSetMatcher. Since this is not easy to do in regexes, it's at the next hight level in StringSetMatcher added a optional CG accessor interface (geChoice(i), getAllChoices(), getProcessedChoices() getUnprocessedChoices()) that can be used from listeners and peers to enumerate/analyse choice sets. Note that not all CGs have to support this as there is no requirement that CGs actually use pre-computed choice sets. The low level accessor is getChoice(i), ChoiceGeneratorBase provides generic (not very efficient) set accessor implementations. Note that ChoiceGeneratorBase.getChoice() has to be overridden in subclasses in order to support choice enumeration, the default impl is just there so that we don't break subclass compilation
author Peter Mehlitz <Peter.C.Mehlitz@nasa.gov>
date Tue, 03 Feb 2015 08:49:33 -0800
parents f6886b2bda4a
children 9d0c3f9df6e0
line wrap: on
line diff
--- a/src/main/gov/nasa/jpf/vm/ChoiceGeneratorBase.java	Sat Jan 24 18:19:08 2015 -0800
+++ b/src/main/gov/nasa/jpf/vm/ChoiceGeneratorBase.java	Tue Feb 03 08:49:33 2015 -0800
@@ -335,6 +335,67 @@
     setDone();
   }
 
+  // override this to support explicit CG enumeration from listeners etc.
+  
+  /**
+   * explicit choice enumeration. Override if supported
+   * @return choice value or null if not supported
+   */
+  @Override
+  public T getChoice (int idx){
+    return null;
+  }
+  
+  //--- generic choice set getter implementation
+  // Note - this requires an overloaded getChoice() and can be very slow (depending on CG implementation)
+  
+  @Override
+  public T[] getAllChoices(){
+    int n = getTotalNumberOfChoices();
+    T[] a = (T[]) new Object[n];
+    for (int i=0; i<n; i++){
+      T c = getChoice(i);
+      if (c == null){
+        return null; // CG doesn't support choice enumeration
+      } else {
+        a[i] = c;
+      }
+    }
+    return a;
+  }
+  
+  @Override
+  public T[] getProcessedChoices(){
+    int n = getProcessedNumberOfChoices();
+    T[] a = (T[]) new Object[n];
+    for (int i=0; i<n; i++){
+      T c = getChoice(i);
+      if (c == null){
+        return null; // CG doesn't support choice enumeration
+      } else {
+        a[i] = c;
+      }
+    }
+    return a;    
+  }
+  
+  @Override
+  public T[] getUnprocessedChoices(){
+    int n = getTotalNumberOfChoices();
+    int m = getProcessedNumberOfChoices();
+    T[] a = (T[]) new Object[n];
+    for (int i=m-1; i<n; i++){
+      T c = getChoice(i);
+      if (c == null){
+        return null; // CG doesn't support choice enumeration
+      } else {
+        a[i] = c;
+      }
+    }
+    return a;    
+  }
+  
+  
   @Override
   public boolean isDone() {
     return isDone;