Inheritance: Microsoft.Scripting.Actions.Calls.OverloadResolver
Ejemplo n.º 1
0
        public override DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
        {
            var type = target.LimitType;
            var methods = type.GetMethods().Where(m => m.Name == Name).Cast<MethodBase>().ToList();
            OverloadResolver ov = new DefaultOverloadResolver(DefaultContext.DefaultTotemContext.Binder, target, args, new CallSignature(args.Length));
            var result = ov.ResolveOverload(Name, methods, NarrowingLevel.None, NarrowingLevel.All);
            var types = new[] { target }.Concat(args).ToArray();
            if (result.Success)
            {
                List<Expression> ret = new List<Expression>();
                ret.Add(result.MakeExpression());
                if (result.MethodCandidate.ReturnType == typeof(void))
                    ret.Add(Utils.Constant(Uninitialized.Instance));

                return new DynamicMetaObject(
                    Expression.Block(ret),
                    BindingRestrictions.Combine(types).Merge(
                        result.RestrictedArguments.GetAllRestrictions()
                    )
                );
            }

            return TotemProtocol.TypeError(
                this,
                "Could not invoke method " + Name + " on '{0}'",
                types
            );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs binding against a set of overloaded methods using the specified arguments.  The arguments are
        /// consumed as specified by the CallSignature object.
        /// </summary>
        /// <param name="minLevel">TODO.</param>
        /// <param name="maxLevel">TODO.</param>
        /// <param name="resolver">Overload resolver.</param>
        /// <param name="targets">The methods to be called</param>
        /// <param name="restrictions">Additional restrictions which should be applied to the resulting MetaObject.</param>
        /// <param name="target">The resulting binding target which can be used for producing error information.</param>
        /// <param name="name">The name of the method or null to use the name from targets.</param>
        /// <returns>A meta object which results from the call.</returns>
        public DynamicMetaObject CallMethod(DefaultOverloadResolver resolver, IList <MethodBase> targets, BindingRestrictions restrictions, string name,
                                            NarrowingLevel minLevel, NarrowingLevel maxLevel, out BindingTarget target)
        {
            ContractUtils.RequiresNotNull(resolver, nameof(resolver));
            ContractUtils.RequiresNotNullItems(targets, nameof(targets));
            ContractUtils.RequiresNotNull(restrictions, nameof(restrictions));

            // attempt to bind to an individual method
            target = resolver.ResolveOverload(name ?? GetTargetName(targets), targets, minLevel, maxLevel);

            if (target.Success)
            {
                // if we succeed make the target for the rule
                return(new DynamicMetaObject(
                           target.MakeExpression(),
                           restrictions.Merge(
                               MakeSplatTests(resolver.CallType, resolver.Signature, resolver.Arguments).
                               Merge(target.RestrictedArguments.GetAllRestrictions())
                               )
                           ));
            }

            // make an error rule
            return(MakeInvalidParametersRule(resolver, restrictions, target));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Performs binding against a set of overloaded methods using the specified arguments.  The arguments are
 /// consumed as specified by the CallSignature object.
 /// </summary>
 /// <param name="resolver">Overload resolver.</param>
 /// <param name="targets">The methods to be called</param>
 /// <param name="restrictions">Additional restrictions which should be applied to the resulting MetaObject.</param>
 /// <returns>A meta object which results from the call.</returns>
 public DynamicMetaObject CallMethod(DefaultOverloadResolver resolver, IList<MethodBase> targets, BindingRestrictions restrictions) {
     return CallMethod(
         resolver,
         targets,
         restrictions,
         null
     );
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Performs binding against a set of overloaded methods using the specified arguments.  The arguments are
 /// consumed as specified by the CallSignature object.
 /// </summary>
 /// <param name="resolver">Overload resolver.</param>
 /// <param name="targets">The methods to be called</param>
 /// <param name="restrictions">Additional restrictions which should be applied to the resulting MetaObject.</param>
 /// <returns>A meta object which results from the call.</returns>
 public DynamicMetaObject CallMethod(DefaultOverloadResolver resolver, IList <MethodBase> targets, BindingRestrictions restrictions)
 {
     return(CallMethod(
                resolver,
                targets,
                restrictions,
                null
                ));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Performs binding against a set of overloaded methods using the specified arguments.  The arguments are
 /// consumed as specified by the CallSignature object.
 /// </summary>
 /// <param name="resolver">Overload resolver.</param>
 /// <param name="targets">The methods to be called</param>
 /// <param name="restrictions">Additional restrictions which should be applied to the resulting MetaObject.</param>
 /// <param name="name">The name of the method or null to use the name from targets.</param>
 /// <returns>A meta object which results from the call.</returns>
 public DynamicMetaObject CallMethod(DefaultOverloadResolver resolver, IList <MethodBase> targets, BindingRestrictions restrictions, string name)
 {
     return(CallMethod(
                resolver,
                targets,
                restrictions,
                name,
                NarrowingLevel.None,
                NarrowingLevel.All,
                out BindingTarget _
                ));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Performs binding against a set of overloaded methods using the specified arguments.  The arguments are
 /// consumed as specified by the CallSignature object.
 /// </summary>
 /// <param name="resolver">Overload resolver.</param>
 /// <param name="targets">The methods to be called</param>
 /// <param name="restrictions">Additional restrictions which should be applied to the resulting MetaObject.</param>
 /// <param name="name">The name of the method or null to use the name from targets.</param>
 /// <returns>A meta object which results from the call.</returns>
 public DynamicMetaObject CallMethod(DefaultOverloadResolver resolver, IList<MethodBase> targets, BindingRestrictions restrictions, string name) {
     BindingTarget target;
     return CallMethod(
         resolver,
         targets,
         restrictions,
         name,
         NarrowingLevel.None,
         NarrowingLevel.All,
         out target
     );
 }
Ejemplo n.º 7
0
        // TODO: revisit
        private DynamicMetaObject MakeInvalidParametersRule(DefaultOverloadResolver binder, BindingRestrictions restrictions, BindingTarget bt)
        {
            var args = binder.Arguments;

            BindingRestrictions restriction = MakeSplatTests(binder.CallType, binder.Signature, true, args);

            // restrict to the exact type of all parameters for errors
            for (int i = 0; i < args.Count; i++)
            {
                args[i] = args[i].Restrict(args[i].GetLimitType());
            }

            return(MakeError(
                       binder.MakeInvalidParametersError(bt),
                       restrictions.Merge(BindingRestrictions.Combine(args).Merge(restriction)),
                       typeof(object)
                       ));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Performs binding against a set of overloaded methods using the specified arguments.  The arguments are
 /// consumed as specified by the CallSignature object.
 /// </summary>
 /// <param name="resolver">Overload resolver.</param>
 /// <param name="targets">The methods to be called</param>
 /// <param name="name">The name of the method or null to use the name from targets.</param>
 /// <returns>A meta object which results from the call.</returns>
 public DynamicMetaObject CallMethod(DefaultOverloadResolver resolver, IList <MethodBase> targets, string name)
 {
     return(CallMethod(resolver, targets, BindingRestrictions.Empty, name));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Performs binding against a set of overloaded methods using the specified arguments.  The arguments are
 /// consumed as specified by the CallSignature object.
 /// </summary>
 /// <param name="resolver">Overload resolver.</param>
 /// <param name="targets">The methods to be called</param>
 /// <param name="name">The name of the method or null to use the name from targets.</param>
 /// <returns>A meta object which results from the call.</returns>
 public DynamicMetaObject CallMethod(DefaultOverloadResolver resolver, IList<MethodBase> targets, string name) {
     return CallMethod(resolver, targets, BindingRestrictions.Empty, name);
 }
Ejemplo n.º 10
0
        // TODO: revisit
        private DynamicMetaObject MakeInvalidParametersRule(DefaultOverloadResolver binder, BindingRestrictions restrictions, BindingTarget bt) {
            var args = binder.Arguments;
            
            BindingRestrictions restriction = MakeSplatTests(binder.CallType, binder.Signature, true, args);

            // restrict to the exact type of all parameters for errors
            for (int i = 0; i < args.Count; i++) {
                args[i] = args[i].Restrict(args[i].GetLimitType());
            }

            return MakeError(
                binder.MakeInvalidParametersError(bt),
                restrictions.Merge(BindingRestrictions.Combine(args).Merge(restriction)),
                typeof(object)
            );
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Performs binding against a set of overloaded methods using the specified arguments.  The arguments are
        /// consumed as specified by the CallSignature object.
        /// </summary>
        /// <param name="minLevel">TODO.</param>
        /// <param name="maxLevel">TODO.</param>
        /// <param name="resolver">Overload resolver.</param>
        /// <param name="targets">The methods to be called</param>
        /// <param name="restrictions">Additional restrictions which should be applied to the resulting MetaObject.</param>
        /// <param name="target">The resulting binding target which can be used for producing error information.</param>
        /// <param name="name">The name of the method or null to use the name from targets.</param>
        /// <returns>A meta object which results from the call.</returns>
        public DynamicMetaObject CallMethod(DefaultOverloadResolver resolver, IList<MethodBase> targets, BindingRestrictions restrictions, string name, 
            NarrowingLevel minLevel, NarrowingLevel maxLevel, out BindingTarget target) {
            ContractUtils.RequiresNotNull(resolver, "resolver");
            ContractUtils.RequiresNotNullItems(targets, "targets");
            ContractUtils.RequiresNotNull(restrictions, "restrictions");

            // attempt to bind to an individual method
            target = resolver.ResolveOverload(name ?? GetTargetName(targets), targets, minLevel, maxLevel);

            if (target.Success) {
                // if we succeed make the target for the rule
                return new DynamicMetaObject(
                    target.MakeExpression(),
                    restrictions.Merge(
                        MakeSplatTests(resolver.CallType, resolver.Signature, resolver.Arguments).
                            Merge(target.RestrictedArguments.GetAllRestrictions())
                    )
                );
            }

            // make an error rule
            return MakeInvalidParametersRule(resolver, restrictions, target);
        }