ToExpression() protected abstract method

Provides the Expression which provides the value to be passed to the argument. If null is returned the argument is skipped (not passed to the callee).
protected abstract ToExpression ( OverloadResolver resolver, Microsoft.Scripting.Actions.Calls.RestrictedArguments args, bool hasBeenUsed ) : Expression
resolver OverloadResolver
args Microsoft.Scripting.Actions.Calls.RestrictedArguments
hasBeenUsed bool
return System.Linq.Expressions.Expression
コード例 #1
0
        internal protected override Expression ToExpression(ParameterBinder parameterBinder, IList <Expression> parameters, bool[] hasBeenUsed)
        {
            Debug.Assert(BuilderExpectsSingleParameter(_builder));
            int index = GetKeywordIndex(parameters.Count);

            hasBeenUsed[index] = true;
            return(_builder.ToExpression(parameterBinder, new Expression[] { parameters[index] }, new bool[1]));
        }
コード例 #2
0
ファイル: KeywordArgBuilder.cs プロジェクト: gavz/IronKit
        public override Expression ToExpression(OverloadResolver resolver, RestrictedArguments args, bool[] hasBeenUsed)
        {
            Debug.Assert(BuilderExpectsSingleParameter(_builder));

            int index = GetKeywordIndex(args.Length);

            Debug.Assert(!hasBeenUsed[index]);
            hasBeenUsed[index] = true;
            return(_builder.ToExpression(resolver, MakeRestrictedArg(args, index), new bool[1]));
        }
コード例 #3
0
        internal Expression MakeExpression(ParameterBinder parameterBinder, IList <Expression> parameters)
        {
            bool[]       usageMarkers;
            Expression[] spilledArgs;
            Expression[] args = GetArgumentExpressions(parameterBinder, parameters, out usageMarkers, out spilledArgs);

            MethodBase mb = Method;
            MethodInfo mi = mb as MethodInfo;
            Expression ret, call;

            if (!mb.IsPublic || (mb.DeclaringType != null && !mb.DeclaringType.IsVisible))
            {
                if (mi != null)
                {
                    mi = CompilerHelpers.GetCallableMethod(mi, _binder._binder.PrivateBinding);
                    if (mi != null)
                    {
                        mb = mi;
                    }
                }
            }

            ConstructorInfo ci = mb as ConstructorInfo;

            Debug.Assert(mi != null || ci != null);
            if (mb.IsPublic && (mb.DeclaringType == null || mb.DeclaringType.IsVisible))
            {
                // public method
                if (mi != null)
                {
                    Expression instance = mi.IsStatic ? null : _instanceBuilder.ToExpression(parameterBinder, parameters, usageMarkers);
                    call = AstUtils.SimpleCallHelper(instance, mi, args);
                }
                else
                {
                    call = AstUtils.SimpleNewHelper(ci, args);
                }
            }
            else
            {
                // Private binding, invoke via reflection
                if (mi != null)
                {
                    Expression instance = mi.IsStatic ? Ast.Constant(null) : _instanceBuilder.ToExpression(parameterBinder, parameters, usageMarkers);
                    Debug.Assert(instance != null, "Can't skip instance expression");

                    call = Ast.Call(
                        typeof(BinderOps).GetMethod("InvokeMethod"),
                        Ast.Constant(mi),
                        AstUtils.Convert(instance, typeof(object)),
                        AstUtils.NewArrayHelper(typeof(object), args)
                        );
                }
                else
                {
                    call = Ast.Call(
                        typeof(BinderOps).GetMethod("InvokeConstructor"),
                        Ast.Constant(ci),
                        AstUtils.NewArrayHelper(typeof(object), args)
                        );
                }
            }

            if (spilledArgs != null)
            {
                call = Expression.Block(spilledArgs.AddLast(call));
            }

            ret = _returnBuilder.ToExpression(parameterBinder, _argBuilders, parameters, call);

            List <Expression> updates = null;

            for (int i = 0; i < _argBuilders.Count; i++)
            {
                Expression next = _argBuilders[i].UpdateFromReturn(parameterBinder, parameters);
                if (next != null)
                {
                    if (updates == null)
                    {
                        updates = new List <Expression>();
                    }
                    updates.Add(next);
                }
            }

            if (updates != null)
            {
                if (ret.Type != typeof(void))
                {
                    ParameterExpression temp = Ast.Variable(ret.Type, "$ret");
                    updates.Insert(0, Ast.Assign(temp, ret));
                    updates.Add(temp);
                    ret = Ast.Block(new [] { temp }, updates.ToArray());
                }
                else
                {
                    updates.Insert(0, ret);
                    ret = Ast.Convert(
                        Ast.Block(updates.ToArray()),
                        typeof(void)
                        );
                }
            }

            if (parameterBinder.Temps != null)
            {
                ret = Ast.Block(parameterBinder.Temps, ret);
            }

            return(ret);
        }