Exemple #1
0
        private Expression VisitVariable(ParameterExpression node, ExpressionAccess access)
        {
            ParameterExpression boxStorage;

            if (!this._loopLocals.Contains(node))
            {
                LoopVariable  variable;
                LocalVariable variable2;
                if (this._loopVariables.TryGetValue(node, out variable))
                {
                    boxStorage = variable.BoxStorage;
                    this._loopVariables[node] = new LoopVariable(variable.Access | access, boxStorage);
                    goto Label_00A5;
                }
                if (this._outerVariables.TryGetValue(node, out variable2) || ((this._closureVariables != null) && this._closureVariables.TryGetValue(node, out variable2)))
                {
                    boxStorage = variable2.InClosureOrBoxed ? Expression.Parameter(typeof(StrongBox <object>), node.Name) : null;
                    this._loopVariables[node] = new LoopVariable(access, boxStorage);
                    goto Label_00A5;
                }
            }
            return(node);

Label_00A5:
            if (boxStorage == null)
            {
                return(node);
            }
            if ((access & ExpressionAccess.Write) != ExpressionAccess.None)
            {
                return(LightCompiler.Unbox(boxStorage));
            }
            return(Expression.Convert(LightCompiler.Unbox(boxStorage), node.Type));
        }
Exemple #2
0
        private Expression VisitVariable(ParameterExpression node, ExpressionAccess access)
        {
            ParameterExpression box;
            LoopVariable        existing;
            LocalVariable       loc;

            if (_loopLocals.Contains(node))
            {
                // local to the loop - not propagated in or out
                return(node);
            }
            else if (_loopVariables.TryGetValue(node, out existing))
            {
                // existing outer variable that we are already tracking
                box = existing.BoxStorage;
                _loopVariables[node] = new LoopVariable(existing.Access | access, box);
            }
            else if (_outerVariables.TryGetValue(node, out loc) ||
                     (_closureVariables != null && _closureVariables.TryGetValue(node, out loc)))
            {
                // not tracking this variable yet, but defined in outer scope and seen for the 1st time
                box = loc.InClosureOrBoxed ? Expression.Parameter(typeof(StrongBox <object>), node.Name) : null;
                _loopVariables[node] = new LoopVariable(access, box);
            }
            else
            {
                // node is a variable defined in a nested lambda -> skip
                return(node);
            }

            if (box != null)
            {
                if ((access & ExpressionAccess.Write) != 0)
                {
                    // compound assignments were reduced:
                    Debug.Assert((access & ExpressionAccess.Read) == 0);

                    // box.Value = (object)rhs
                    return(LightCompiler.Unbox(box));
                }
                else
                {
                    // (T)box.Value
                    return(Expression.Convert(LightCompiler.Unbox(box), node.Type));
                }
            }

            return(node);
        }
Exemple #3
0
        private Expression GetClosureItem(ParameterExpression variable, bool unbox)
        {
            // Skip variables that are shadowed by a nested scope/lambda
            foreach (HashSet <ParameterExpression> hidden in _shadowedVars)
            {
                if (hidden.Contains(variable))
                {
                    return(null);
                }
            }

            if (!_closureVars.TryGetValue(variable, out LocalVariable loc))
            {
                throw new InvalidOperationException("unbound variable: " + variable.Name);
            }

            var result = loc.LoadFromArray(null, _closureArray);

            return((unbox) ? LightCompiler.Unbox(result) : result);
        }
Exemple #4
0
        private Expression VisitVariable(ParameterExpression node, ExpressionAccess access)
        {
            ParameterExpression box;
            LoopVariable        existing;
            LocalVariable       loc;

            if (_loopVariables.TryGetValue(node, out existing))
            {
                box = existing.BoxStorage;
                _loopVariables[node] = new LoopVariable(existing.Access | access, box);
            }
            else if (_locals.TryGetLocal(node, out loc))
            {
                box = loc.InClosureOrBoxed ? Expression.Parameter(typeof(StrongBox <object>), node.Name) : null;
                _loopVariables[node] = new LoopVariable(access, box);
            }
            else
            {
                // node is a variable defined in a nested lambda -> skip
                return(node);
            }

            if (box != null)
            {
                if ((access & ExpressionAccess.Write) != 0)
                {
                    // compound assignments were reduced:
                    Debug.Assert((access & ExpressionAccess.Read) == 0);

                    // box.Value = (object)rhs
                    return(LightCompiler.Unbox(box));
                }
                else
                {
                    // (T)box.Value
                    return(Expression.Convert(LightCompiler.Unbox(box), node.Type));
                }
            }

            return(node);
        }
        private Expression GetClosureItem(ParameterExpression variable, bool unbox)
        {
            LocalVariable variable2;

            foreach (HashSet <ParameterExpression> set in this._shadowedVars)
            {
                if (set.Contains(variable))
                {
                    return(null);
                }
            }
            if (!this._closureVars.TryGetValue(variable, out variable2))
            {
                throw new InvalidOperationException("unbound variable: " + variable.Name);
            }
            Expression strongBoxExpression = variable2.LoadFromArray(null, this._closureArray);

            if (!unbox)
            {
                return(strongBoxExpression);
            }
            return(LightCompiler.Unbox(strongBoxExpression));
        }