Describes arguments in the dynamic binding process.
ArgumentCount - all inclusive number of arguments. ArgumentNames - names for those arguments that are named. Argument names match to the argument values in left to right order and last name corresponds to the last argument. Example: Foo(arg1, arg2, arg3, name1 = arg4, name2 = arg5, name3 = arg6) will correspond to: ArgumentCount: 6 ArgumentNames: {"name1", "name2", "name3"}
Example #1
0
            public static DynamicMetaObject/*!*/ Bind(string/*!*/ methodName, CallInfo/*!*/ callInfo,
                DynamicMetaObjectBinder/*!*/ binder, DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args,
                Func<DynamicMetaObject, DynamicMetaObject[], DynamicMetaObject>/*!*/ fallback)
            {
                Debug.Assert(fallback != null);

                //create DMO
                var phpInvokeBinder = Binder.MethodCall(methodName, 0, callInfo.ArgumentCount, null, Types.Object[0]) as PhpBaseInvokeMemberBinder;

                if (phpInvokeBinder != null)
                {

                    //Add ScriptContext.CurrentContext
                    var context = new DynamicMetaObject(Expression.Call(Methods.ScriptContext.GetCurrentContext), BindingRestrictions.Empty);

                    var restrictions = BinderHelper.GetSimpleInvokeRestrictions(target, args);

                    //Value type arguments have to be boxed
                    DynamicMetaObject[] arguments = new DynamicMetaObject[1 + args.Length];
                    arguments[0] = context;
                    for (int i = 0; i < args.Length; ++i)
                        arguments[1 + i] = new DynamicMetaObject(WrapDynamic(args[i].Expression),
                                                                 args[i].Restrictions);
                    var result = phpInvokeBinder.Bind(target, arguments);

                    //Unwrap result
                    var res = new DynamicMetaObject(Unwrap(result.Expression), restrictions);

                    return res;
                }
                else
                    return fallback(target, args);//this will never happen
            }
Example #2
0
 public GetIndexBinder(
     StaticMetaTables metaTables,
     CallInfo callInfo)
     : base(callInfo)
 {
     _metaTables = metaTables;
 }
        /// <summary>
        /// Creates the cacheable method or indexer or property call.
        /// </summary>
        /// <param name="kind">The kind.</param>
        /// <param name="name">The name.</param>
        /// <param name="callInfo">The callInfo.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public static CacheableInvocation CreateCall(InvocationKind kind, String_OR_InvokeMemberName name = null, CallInfo callInfo = null,object context = null)
        {
            var tArgCount = callInfo != null ? callInfo.ArgumentCount : 0;
            var tArgNames = callInfo != null ? callInfo.ArgumentNames.ToArray() : null;

            return new CacheableInvocation(kind, name, tArgCount, tArgNames, context);
        }
Example #4
0
 public static InvokeMemberBinder New(
     StaticMetaTables metaTables, 
     string name, 
     CallInfo info)
 {
     return new InvokeMemberBinder(metaTables, name, info);
 }
Example #5
0
        private DynamicMetaObject BindComInvoke(DynamicMetaObject[] args, ComMethodDesc method, CallInfo callInfo, bool[] isByRef,
            List<ParameterExpression> temps, List<Expression> initTemps)
        {
            DynamicMetaObject invoke = new ComInvokeBinder(
                callInfo,
                args,
                isByRef,
                IDispatchRestriction(),
                Expression.Constant(method),
                Expression.Property(
                    Helpers.Convert(Expression, typeof(IDispatchComObject)),
                    typeof(IDispatchComObject).GetProperty("DispatchObject")
                ),
                method
            ).Invoke();

            if ((temps != null) && (temps.Any()))
            {
                Expression invokeExpression = invoke.Expression;
                Expression call = Expression.Block(invokeExpression.Type, temps, initTemps.Append(invokeExpression));
                invoke = new DynamicMetaObject(call, invoke.Restrictions);
            }

            return invoke;
        }
Example #6
0
        internal ComInvokeBinder(
                CallInfo callInfo, 
                DynamicMetaObject[] args,
                bool[] isByRef,
                BindingRestrictions restrictions, 
                Expression method, 
                Expression dispatch, 
                ComMethodDesc methodDesc
                )
        {
            Debug.Assert(callInfo != null, "arguments");
            Debug.Assert(args != null, "args");
            Debug.Assert(isByRef != null, "isByRef");
            Debug.Assert(method != null, "method");
            Debug.Assert(dispatch != null, "dispatch");

            Debug.Assert(TypeUtils.AreReferenceAssignable(typeof(ComMethodDesc), method.Type), "method");
            Debug.Assert(TypeUtils.AreReferenceAssignable(typeof(IDispatch), dispatch.Type), "dispatch");

            _method = method;
            _dispatch = dispatch;
            _methodDesc = methodDesc;

            _callInfo = callInfo;
            _args = args;
            _isByRef = isByRef;
            _restrictions = restrictions;

            // Set Instance to some value so that CallBinderHelper has the right number of parameters to work with
            _instance = dispatch;
        }
Example #7
0
        public TotemSetIndexBinder(TotemContext /*!*/ context, CallInfo callInfo)
            : base(callInfo)
        {
            Assert.NotNull(context);

            _context = context;
        }
        static IReadOnlyList<IMemberDefinition> CreateNodes(CallInfo callInfo, IReadOnlyList<object> args)
        {
            var result = new List<IMemberDefinition>();

            int difference;
            var nameCount = callInfo.ArgumentNames.Count;
            var argumentCount = args.Count;

            if (argumentCount != nameCount)
            {
                if (nameCount != args.Count(x => !(x is IMemberDefinition)))
                    throw new NotSupportedException("Unnamed arguments must be MemberDefinition instances.");

                difference = argumentCount - nameCount;
            }
            else
            {
                difference = 0;
            }

            var argumentNames = callInfo.ArgumentNames;

            for (var i = argumentCount - 1; i >= 0; i--)
            {
                var argument = args[i];

                var dynamicMember = argument as IMemberDefinition;
                if (dynamicMember == null)
                {
                    var name = argumentNames[i - difference];

                    var @delegate = argument as Delegate;
                    if (@delegate != null)
                    {
                        dynamicMember = MemberDefinition.Method(name, @delegate);
                    }
                    else
                    {
                        var type = argument as Type;

                        if (type == null)
                            throw new NotSupportedException("Definitions require a type.");

                        if (typeof(Delegate).IsAssignableFrom(type))
                        {
                            dynamicMember = MemberDefinition.EmptyMethod(name, type);
                        }
                        else
                        {
                            dynamicMember = MemberDefinition.Property(name, type);
                        }
                    }
                }

                result.Add(dynamicMember);   
            }

            return result;
        }
Example #9
0
 public InvokeMemberBinder(
     StaticMetaTables metaTables, 
     string name, 
     CallInfo callInfo)
     : base(name, false, callInfo)
 {
     _metaTables = metaTables;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="InvokeMemberBinder" />.
        /// </summary>
        /// <param name="name">The name of the member to invoke.</param>
        /// <param name="ignoreCase">true if the name should be matched ignoring case; false otherwise.</param>
        /// <param name="callInfo">The signature of the arguments at the call site.</param>
        protected InvokeMemberBinder(string name, bool ignoreCase, CallInfo callInfo) {
            ContractUtils.RequiresNotNull(name, "name");
            ContractUtils.RequiresNotNull(callInfo, "callInfo");

            _name = name;
            _ignoreCase = ignoreCase;
            _callInfo = callInfo;
        }
Example #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InvokeMemberBinder" />.
        /// </summary>
        /// <param name="name">The name of the member to invoke.</param>
        /// <param name="ignoreCase">true if the name should be matched ignoring case; false otherwise.</param>
        /// <param name="callInfo">The signature of the arguments at the call site.</param>
        protected InvokeMemberBinder(string name, bool ignoreCase, CallInfo callInfo)
        {
            ContractUtils.RequiresNotNull(name, nameof(name));
            ContractUtils.RequiresNotNull(callInfo, nameof(callInfo));

            Name = name;
            IgnoreCase = ignoreCase;
            CallInfo = callInfo;
        }
        private DynamicMetaObject BindGetOrInvoke(DynamicMetaObject[] args, CallInfo callInfo) {
            ComMethodDesc method;
            var target = _callable.DispatchComObject;
            var name = _callable.MemberName;

            if (target.TryGetMemberMethod(name, out method) ||
                target.TryGetMemberMethodExplicit(name, out method)) {

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref args);
                return BindComInvoke(method, args, callInfo, isByRef);
            }
            return null;
        }
Example #13
0
        internal Binder.SetIndexBinder SetIndexBinder(DYN.CallInfo callInfo)
        {
            lock (this._setIndexBinders)
            {
                if (this._setIndexBinders.ContainsKey(callInfo))
                {
                    return(this._setIndexBinders[callInfo]);
                }

                Binder.SetIndexBinder binder = new Binder.SetIndexBinder(callInfo);
                this._setIndexBinders[callInfo] = binder;
                return(binder);
            }
        }
Example #14
0
        internal Binder.InvokeBinder InvokeBinder(DYN.CallInfo callInfo)
        {
            lock (this._invokeBinders)
            {
                if (this._invokeBinders.ContainsKey(callInfo))
                {
                    return(this._invokeBinders[callInfo]);
                }

                Binder.InvokeBinder binder = new Binder.InvokeBinder(callInfo);
                this._invokeBinders[callInfo] = binder;
                return(binder);
            }
        }
 public static void CopyBackArguments(CallInfo callInfo, object[] packedArgs, object[] args)
 {
     if (packedArgs != args)
     {
         int length = packedArgs.Length;
         int argumentCount = callInfo.ArgumentCount;
         int num3 = length - callInfo.ArgumentNames.Count;
         int num5 = length - 1;
         for (int i = 0; i <= num5; i++)
         {
             args[i] = packedArgs[(i < argumentCount) ? ((i + num3) % argumentCount) : i];
         }
     }
 }
Example #16
0
 private DynamicMetaObject BindComInvoke(DynamicMetaObject[] args, ComMethodDesc method, CallInfo callInfo, bool[] isByRef) {
     return new ComInvokeBinder(
         callInfo,
         args,
         isByRef,
         IDispatchRestriction(),
         Expression.Constant(method),
         Expression.Property(
             Helpers.Convert(Expression, typeof(IDispatchComObject)),
             typeof(IDispatchComObject).GetProperty("DispatchObject")
         ),
         method
     ).Invoke();
 }
Example #17
0
        private DynamicMetaObject BindGetOrInvoke(DynamicMetaObject[] args, CallInfo callInfo)
        {
            ComMethodDesc method;
            var target = _callable.DispatchComObject;
            var name = _callable.MemberName;

            if (target.TryGetMemberMethod(name, out method) ||
                target.TryGetMemberMethodExplicit(name, out method))
            {
                List<ParameterExpression> temps = new List<ParameterExpression>();
                List<Expression> initTemps = new List<Expression>();

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(method, ref args, temps, initTemps);
                return BindComInvoke(method, args, callInfo, isByRef, temps, initTemps);
            }
            return null;
        }
        private DynamicMetaObject BindComInvoke(ComMethodDesc method, DynamicMetaObject[] indexes, CallInfo callInfo, bool[] isByRef) {
            var callable = Expression;
            var dispCall = Helpers.Convert(callable, typeof(DispCallable));

            return new ComInvokeBinder(
                callInfo,
                indexes,
                isByRef,
                DispCallableRestrictions(),
                Expression.Constant(method),
                Expression.Property(
                    dispCall,
                    typeof(DispCallable).GetProperty("DispatchObject")
                ),
                method
            ).Invoke();
        }
        private void ParseNamedArgumentValues(CallInfo callInfo, object[] args)
        {
            if (!callInfo.ArgumentNames.Any())
            {
                throw new ArgumentException("No names were specified for the values provided. When using the named arguments (With()) syntax, you should specify the items to be set as argument names, such as With(customerId: customerId).");
            }

            if (callInfo.ArgumentNames.Count() != args.Length)
            {
                throw new ArgumentException("One or more arguments are missing a name. Names should be specified with C# named argument syntax, e.g. With(customerId: customerId).");
            }

            var argumentIndex = 0;
            foreach (var argumentName in callInfo.ArgumentNames.Select(ToCamelCase))
            {
                argumentStore.SetMemberNameAndValue(argumentName, args[argumentIndex++]);
            }
        }
        private DynamicMetaObject BindGetOrInvoke(DynamicMetaObject[] args, CallInfo callInfo) {
            //
            // Demand Full Trust to proceed with the binding.
            //

            new PermissionSet(PermissionState.Unrestricted).Demand();

            ComMethodDesc method;
            var target = _callable.DispatchComObject;
            var name = _callable.MemberName;

            if (target.TryGetMemberMethod(name, out method) ||
                target.TryGetMemberMethodExplicit(name, out method)) {

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref args);
                return BindComInvoke(method, args, callInfo, isByRef);
            }
            return null;
        }
        static IReadOnlyList<Member> CreateValueNodes(CallInfo callInfo, IReadOnlyList<object> args)
        {
            var result = new List<Member>();

            int difference;
            var nameCount = callInfo.ArgumentNames.Count;
            var argumentCount = args.Count;
            if (argumentCount != nameCount)
            {
                if (nameCount != args.Count(x => !(x is Member)))
                    throw new NotSupportedException("Unnamed arguments must be MemberDefinition instances.");

                difference = argumentCount - nameCount;
            }
            else
            {
                difference = 0;
            }

            var argumentNames = callInfo.ArgumentNames;

            for (var i = argumentCount - 1; i >= 0; i--)
            {
                var argument = args[i];

                var dynamicMember = argument as Member;
                if (dynamicMember == null)
                {
                    var name = argumentNames[i - difference];
                    dynamic value = argument;
                    dynamicMember = Member.Unknown(name, value);
                }

                result.Add(dynamicMember);
            }

            return result;
        }
 protected InvokeMemberBinder(string name, bool ignoreCase, CallInfo callInfo)
 {
 }
Example #23
0
        internal static QExprGroup CreateExprGroup(string groupOperator, CallInfo callInfo, object[] args)
        {
            if(callInfo != null
                && args != null
                && args.Length > 0
                && callInfo.ArgumentCount == args.Length)
            {
                int argsCount = args.Length;
                int namedArgsCount = callInfo.ArgumentNames.Count;

                QExpr[] qexprs = new QExpr[namedArgsCount];
                QExprGroup[] qgroups = new QExprGroup[argsCount - namedArgsCount];

                for (int i = 0; i < argsCount - namedArgsCount; i++)
                {
                    QExprGroup qgroup = args[i] as QExprGroup;
                    if (qgroup == null)
                        throw new Exception("An unnamed Q parameter must be of type QPredicate");

                    qgroups[i] = qgroup;
                }

                for (int i = 0; i < namedArgsCount; i++)
                {
                    string[] lhsAndOp = callInfo.ArgumentNames[i].Split(CUSTOM_QUERY_SYNTAX_SEP, StringSplitOptions.None);
                    if (lhsAndOp == null || lhsAndOp.Length == 0 || lhsAndOp.Length < 1)
                        throw new Exception("A Q parameter name must be composed of field name & operator name separated by '__' (double underscore)");

                    qexprs[i] = new QExpr(lhsAndOp[0],
                        lhsAndOp.Length >= 2 ? lhsAndOp[lhsAndOp.Length - 1] : Constants.QueryCompareOps.EXACT,
                        args[argsCount - namedArgsCount + i]);
                }

                QExprGroup exprGroup;

                if (groupOperator == Constants.QUERY_AND)
                    exprGroup = new AndExprGroup();
                else
                    exprGroup = new OrExprGroup();

                if (qgroups != null)
                    exprGroup.SubGroups.AddRange(qgroups);

                if (qexprs != null)
                    exprGroup.Expressions.AddRange(qexprs);

                return exprGroup;
            }

            return null;
        }
Example #24
0
        private bool TryCreateExprGroup(string binderName, CallInfo callInfo, object[] args, out object result)
        {
            string methodName = _GroupOperatorOverride ?? binderName;
            if (methodName == Constants.QUERY_AND || methodName == Constants.QUERY_OR)
            {
                result = CreateExprGroup(methodName, callInfo, args);
                return true;
            }

            result = null;
            return false;
        }
Example #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GetIndexBinder" />.
 /// </summary>
 /// <param name="callInfo">The signature of the arguments at the call site.</param>
 protected GetIndexBinder(CallInfo callInfo)
 {
     ArgumentNullException.ThrowIfNull(callInfo);
     CallInfo = callInfo;
 }
Example #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateInstanceBinder" />.
 /// </summary>
 /// <param name="callInfo">The signature of the arguments at the call site.</param>
 protected CreateInstanceBinder(CallInfo callInfo)
 {
     ArgumentNullException.ThrowIfNull(callInfo);
     CallInfo = callInfo;
 }
Example #27
0
        private DynamicMetaObject BindComInvoke(ComMethodDesc method, DynamicMetaObject[] indexes, CallInfo callInfo, bool[] isByRef,
            List<ParameterExpression> temps, List<Expression> initTemps)
        {
            var callable = Expression;
            var dispCall = Helpers.Convert(callable, typeof(DispCallable));

            DynamicMetaObject invoke = new ComInvokeBinder(
                callInfo,
                indexes,
                isByRef,
                DispCallableRestrictions(),
                Expression.Constant(method),
                Expression.Property(
                    dispCall,
                    typeof(DispCallable).GetProperty("DispatchObject")
                ),
                method
            ).Invoke();

            if ((temps != null) && (temps.Any()))
            {
                Expression invokeExpression = invoke.Expression;
                Expression call = Expression.Block(invokeExpression.Type, temps, initTemps.Append(invokeExpression));
                invoke = new DynamicMetaObject(call, invoke.Restrictions);
            }

            return invoke;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DeleteIndexBinder" />.
 /// </summary>
 /// <param name="callInfo">The signature of the arguments at the call site.</param>
 protected DeleteIndexBinder(CallInfo callInfo)
 {
     ContractUtils.RequiresNotNull(callInfo, "callInfo");
     _callInfo = callInfo;
 }
Example #29
0
 internal InvokeMember(RubyContext/*!*/ context, string/*!*/ name, CallInfo/*!*/ callInfo)
     : base(name, false, callInfo) {
     Assert.NotNull(context);
     _context = context;
 }
Example #30
0
            public static DynamicMetaObject/*!*/ Bind(DynamicMetaObject/*!*/ context, string/*!*/ methodName, CallInfo/*!*/ callInfo, 
                DynamicMetaObjectBinder/*!*/ binder, DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args,
                Func<DynamicMetaObject, DynamicMetaObject[], DynamicMetaObject>/*!*/ fallback) {
                Debug.Assert(fallback != null);

                var callArgs = new CallArguments(context, target, args, RubyCallSignature.Interop(callInfo.ArgumentCount));
                var metaBuilder = new MetaObjectBuilder(target, args);

                if (!RubyCallAction.BuildCall(metaBuilder, methodName, callArgs, false, false)) {
                    metaBuilder.SetMetaResult(fallback(target, args), false);
                }
                return metaBuilder.CreateMetaObject(binder);
            }
Example #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InvokeBinder" />.
 /// </summary>
 /// <param name="callInfo">The signature of the arguments at the call site.</param>
 protected InvokeBinder(CallInfo callInfo)
 {
     ArgumentNullException.ThrowIfNull(callInfo);
     CallInfo = callInfo;
 }
 protected CreateInstanceBinder(CallInfo callInfo)
 {
 }
Example #33
0
 protected InvokeBinder(CallInfo callInfo)
 {
     throw new NotImplementedException();
 }
 protected SetIndexBinder(CallInfo callInfo)
 {
 }
Example #35
0
 /// <summary>
 /// Initializes a new intsance of the <see cref="CreateInstanceBinder" />.
 /// </summary>
 /// <param name="callInfo">The signature of the arguments at the call site.</param>
 protected CreateInstanceBinder(CallInfo callInfo)
 {
     ContractUtils.RequiresNotNull(callInfo, "callInfo");
     _callInfo = callInfo;
 }
Example #36
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="CreateInstanceBinder" />.
 /// </summary>
 /// <param name="callInfo">The signature of the arguments at the call site.</param>
 protected CreateInstanceBinder(CallInfo callInfo)
 {
     ContractUtils.RequiresNotNull(callInfo, nameof(callInfo));
     CallInfo = callInfo;
 }
Example #37
0
 internal Return(RubyContext/*!*/ context, CallInfo/*!*/ callInfo)
     : base(callInfo) {
     Assert.NotNull(context);
     _context = context;
 }
Example #38
0
 internal Invoke(RubyContext/*!*/ context, string/*!*/ fallbackMethod, CallInfo/*!*/ callInfo)
     : base(callInfo) {
     Assert.NotNull(context, fallbackMethod);
     _context = context;
     _fallbackMethod = fallbackMethod;
 }
Example #39
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="SetIndexBinder" />.
 /// </summary>
 /// <param name="callInfo">The signature of the arguments at the call site.</param>
 protected SetIndexBinder(CallInfo callInfo)
 {
     ContractUtils.RequiresNotNull(callInfo, nameof(callInfo));
     CallInfo = callInfo;
 }
Example #40
0
            internal static DynamicMetaObject FallbackInvokeMember(IInteropBinder/*!*/ binder, string/*!*/ methodName, CallInfo/*!*/ callInfo,
                DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args, DynamicMetaObject errorSuggestion) {

                var metaBuilder = new MetaObjectBuilder(binder, target, args);
                var callArgs = new CallArguments(binder.Context, target, args, callInfo);

                if (!RubyCallAction.BuildCall(metaBuilder, methodName, callArgs, errorSuggestion == null, true)) {
                    Debug.Assert(errorSuggestion != null);
                    // method wasn't found so we didn't do any operation with arguments that would require restrictions converted to conditions:
                    metaBuilder.SetMetaResult(errorSuggestion, false);
                }

                return metaBuilder.CreateMetaObject((DynamicMetaObjectBinder)binder);
            }
Example #41
0
 public SetIndexBinder(DYN.CallInfo callinfo)
     : base(callinfo)
 {
 }
Example #42
0
 internal CreateInstance(RubyContext/*!*/ context, CallInfo/*!*/ callInfo)
     : base(callInfo) {
     Assert.NotNull(context);
     _context = context;
 }
Example #43
0
 public InvokeBinder(DYN.CallInfo callInfo)
     : base(callInfo)
 {
 }
Example #44
0
 protected SetIndexBinder(CallInfo callInfo)
 {
     throw new NotImplementedException();
 }
Example #45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InvokeBinder" />.
 /// </summary>
 /// <param name="callInfo">The signature of the arguments at the call site.</param>
 protected InvokeBinder(CallInfo callInfo)
 {
     ContractUtils.RequiresNotNull(callInfo, nameof(callInfo));
     _callInfo = callInfo;
 }
Example #46
0
 public LuaInvokeMemberBinder(LuaContext context, string name, CallInfo callInfo)
     : base(name, false, callInfo)
 {
     ContractUtils.RequiresNotNull(context, "context");
     this.context = context;
 }
 protected CreateInstanceBinder(CallInfo callInfo)
 {
     throw new NotImplementedException();
 }