AddScopedVariable() 정적인 개인적인 메소드

static private AddScopedVariable ( Expression body, System.Linq.Expressions.ParameterExpression variable, Expression variableInit ) : Expression
body Expression
variable System.Linq.Expressions.ParameterExpression
variableInit Expression
리턴 Expression
예제 #1
0
        private Expression Rewrite(CodeContextScopeExpression ccs)
        {
            Expression          saved  = _context;
            ParameterExpression nested = Expression.Variable(typeof(CodeContext), "$frame");

            // rewrite body with nested context
            _context = nested;
            Expression body = Visit(ccs.Body);

            _context = saved;

            // wrap the body in a scope that initializes the nested context
            return(AstUtils.AddScopedVariable(body, nested, Visit(ccs.NewContext)));
        }
예제 #2
0
        protected override Expression VisitLambda <T>(Expression <T> node)
        {
            _depth++;
            try {
                // Visit the lambda first, so we walk the tree and find any
                // constants we need to rewrite.
                node = (Expression <T>)base.VisitLambda(node);

                if (_depth != 1)
                {
                    return(node);
                }

                var body = node.Body;

                if (_constants != null)
                {
                    // Rewrite the constants, they can contain embedded
                    // CodeContextExpressions
                    for (int i = 0; i < _constants.Count; i++)
                    {
                        _constants[i] = Visit(_constants[i]);
                    }

                    // Add the consant pool variable to the top lambda
                    body = AstUtils.AddScopedVariable(
                        body,
                        _constantPool,
                        Expression.NewArrayInit(typeof(object), _constants)
                        );
                }

                // Rewrite the lambda
                return(Expression.Lambda <T>(
                           body,
                           node.Name + "$" + Interlocked.Increment(ref _uniqueNameId),
                           node.TailCall,
                           node.Parameters
                           ));
            } finally {
                _depth--;
            }
        }
예제 #3
0
        protected override Expression VisitLambda <T>(Expression <T> node)
        {
            // Only run this for the top-level lambda
            if (_array == null)
            {
                _array = Expression.Variable(typeof(ModuleGlobalWrapper[]), "$globals");
                Expression body = AstUtils.AddScopedVariable(
                    node.Body,
                    _array,
                    Expression.Call(typeof(ScriptingRuntimeHelpers).GetMethod("GetGlobalArray"), Context)
                    );
                Debug.Assert(node.NodeType == ExpressionType.Lambda);
                node = Expression.Lambda <T>(
                    body,
                    node.Name,
                    node.Parameters
                    );
            }

            return(base.VisitLambda(node));
        }
예제 #4
0
        public Expression <DlrMainCallTarget> RewriteLambda(LambdaExpression lambda, string name)
        {
            Debug.Assert(_context == null);
            Debug.Assert(lambda.Parameters.Count == 0);

            // Fix up the top-level lambda to have a scope and language parameters
            ParameterExpression scopeParameter    = Expression.Parameter(typeof(Scope), "$scope");
            ParameterExpression languageParameter = Expression.Parameter(typeof(LanguageContext), "$language");
            ParameterExpression contextVariable   = Expression.Variable(typeof(CodeContext), "$globalContext");

            _context = contextVariable;
            lambda   = (LambdaExpression)Visit(lambda);

            return(Expression.Lambda <DlrMainCallTarget>(
                       AstUtils.AddScopedVariable(
                           lambda.Body,
                           contextVariable,
                           Expression.Call(typeof(ScriptingRuntimeHelpers).GetMethod("CreateTopLevelCodeContext"), scopeParameter, languageParameter)
                           ),
                       name,
                       new[] { scopeParameter, languageParameter }
                       ));
        }