comparison 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
comparison
equal deleted inserted replaced
2:b920e6b1be83 3:fdc263e5806b
333 reset(); 333 reset();
334 advance(choiceIndex+1); 334 advance(choiceIndex+1);
335 setDone(); 335 setDone();
336 } 336 }
337 337
338 // override this to support explicit CG enumeration from listeners etc.
339
340 /**
341 * explicit choice enumeration. Override if supported
342 * @return choice value or null if not supported
343 */
344 @Override
345 public T getChoice (int idx){
346 return null;
347 }
348
349 //--- generic choice set getter implementation
350 // Note - this requires an overloaded getChoice() and can be very slow (depending on CG implementation)
351
352 @Override
353 public T[] getAllChoices(){
354 int n = getTotalNumberOfChoices();
355 T[] a = (T[]) new Object[n];
356 for (int i=0; i<n; i++){
357 T c = getChoice(i);
358 if (c == null){
359 return null; // CG doesn't support choice enumeration
360 } else {
361 a[i] = c;
362 }
363 }
364 return a;
365 }
366
367 @Override
368 public T[] getProcessedChoices(){
369 int n = getProcessedNumberOfChoices();
370 T[] a = (T[]) new Object[n];
371 for (int i=0; i<n; i++){
372 T c = getChoice(i);
373 if (c == null){
374 return null; // CG doesn't support choice enumeration
375 } else {
376 a[i] = c;
377 }
378 }
379 return a;
380 }
381
382 @Override
383 public T[] getUnprocessedChoices(){
384 int n = getTotalNumberOfChoices();
385 int m = getProcessedNumberOfChoices();
386 T[] a = (T[]) new Object[n];
387 for (int i=m-1; i<n; i++){
388 T c = getChoice(i);
389 if (c == null){
390 return null; // CG doesn't support choice enumeration
391 } else {
392 a[i] = c;
393 }
394 }
395 return a;
396 }
397
398
338 @Override 399 @Override
339 public boolean isDone() { 400 public boolean isDone() {
340 return isDone; 401 return isDone;
341 } 402 }
342 403