Ejemplo n.º 1
0
 private void PrepareForWriting(IScope scope, VariableOptions options)
 {
     foreach (Variable v in scope.Variables)
     {
         if (v.IsLoopCounter || v.IsConstant)
         {
             continue;
         }
         if (options.Has(VariableOptions.NonFunctionInitializer) && (v.Initializer is FunctionExpression))
         {
             continue;
         }
         for (int i = 0; i <= _scopeFactor * v.Parent.FunctionDepth; ++i)
         {
             _candidates.Add(v);
         }
     }
 }
Ejemplo n.º 2
0
        public Variable ChooseVariable(IScope scope, VariableOptions options = VariableOptions.None)
        {
            _candidates.Clear();
            if (options.Has(VariableOptions.ForWriting))
            {
                PrepareForWriting(scope, options);
            }
            else
            {
                PrepareForReading(scope, options);
            }
            var count = _candidates.Count;

            if (count > 0)
            {
                return(_rand.Choose(_candidates));
            }
            return(null);
        }