public bool CallPredicateMethod(ZingMethod predicateMethod)
{
if (runningPredicateMethod[MyThreadId])
{
Debugger.Break();
throw new Exception("Predicate !");
}
Process dummyProc = new Process(this.StateImpl, predicateMethod, string.Empty, 0);
Exception savedException = this.StateImpl.Exception;
this.StateImpl.Exception = null;
while (dummyProc.TopOfStack != null)
{
runningPredicateMethod[MyThreadId] = true;
this.StateImpl.RunBlocks(dummyProc);
runningPredicateMethod[MyThreadId] = false;
if (this.StateImpl.Exception != null)
{
if (savedException == null)
{
this.StateImpl.Exception = new Exception("Predicate");
throw this.StateImpl.Exception;
}
else
{
// If we already have a pending exception on the state, just
// return false and restore the original exception.
this.StateImpl.Exception = savedException;
return false;
}
}
if (dummyProc.choicePending)
throw new Exception("Predicate");
}
this.StateImpl.Exception = savedException;
return predicateMethod.BooleanReturnValue;
}