MethodGroup's represent a unique collection of method's. Typically this unique set is all the methods which are overloaded by the same name including methods with different arity. These methods represent a single logically overloaded element of a .NET type. The base DLR binders will produce MethodGroup's when provided with a MemberGroup which contains only methods. The MethodGroup's will be unique instances per each unique group of methods.
Inheritance: MemberTracker
Esempio n. 1
0
 public static MethodGroup GetMethodGroup(string name, MethodBase[] methods) {
     MethodGroup res = null;
     MethodBaseCache cache = new MethodBaseCache(name, methods);
     lock (_functions) {
         if (!_functions.TryGetValue(cache, out res)) {
             _functions[cache] = res = new MethodGroup(
                 ArrayUtils.ConvertAll<MethodBase, MethodTracker>(
                     methods,
                     delegate(MethodBase x) {
                         return (MethodTracker)MemberTracker.FromMemberInfo(x);
                     }
                 )
             );
         }
     }
     return res;
 }
Esempio n. 2
0
        public static MethodGroup GetMethodGroup(string name, MemberGroup mems) {
            MethodGroup res = null;

            MethodBase[] bases = new MethodBase[mems.Count];
            MethodTracker[] trackers = new MethodTracker[mems.Count];
            for (int i = 0; i < bases.Length; i++) {
                trackers[i] = (MethodTracker)mems[i];
                bases[i] = trackers[i].Method;
            }

            if (mems.Count != 0) {
                MethodBaseCache cache = new MethodBaseCache(name, bases);
                lock (_functions) {
                    if (!_functions.TryGetValue(cache, out res)) {
                        _functions[cache] = res = new MethodGroup(trackers);
                    }
                }
            }

            return res;
        }
Esempio n. 3
0
        /// <summary>
        /// Binds to the methods in a method group.
        /// </summary>
        private static TargetInfo TryGetMethodGroupTargets(DynamicMetaObject target, DynamicMetaObject[] args, MethodGroup mthgrp) {
            if (mthgrp != null) {
                List<MethodBase> foundTargets = new List<MethodBase>();

                foreach (MethodTracker mt in mthgrp.Methods) {
                    foundTargets.Add(mt.Method);
                }

                return new TargetInfo(null, ArrayUtils.Insert(target, args), BindingRestrictions.GetInstanceRestriction(target.Expression, mthgrp), foundTargets.ToArray());
            }
            return null;
        }
Esempio n. 4
0
 private static BuiltinFunction GetBuiltinFunction(MethodGroup mg) {
     MethodBase[] methods = new MethodBase[mg.Methods.Count];
     for (int i = 0; i < mg.Methods.Count; i++) {
         methods[i] = mg.Methods[i].Method;
     }
     return PythonTypeOps.GetBuiltinFunction(
         mg.DeclaringType,
         mg.Methods[0].Name,
         (PythonTypeOps.GetMethodFunctionType(mg.DeclaringType, methods) & (~FunctionType.FunctionMethodMask)) |
             (mg.ContainsInstance ? FunctionType.Method : FunctionType.None) |
             (mg.ContainsStatic ? FunctionType.Function : FunctionType.None),
         mg.GetMethodBases()
     );
 }
Esempio n. 5
0
 private static Expression ReturnMethodGroup(MethodGroup methodGroup) {
     return Ast.Constant(PythonTypeOps.GetFinalSlotForFunction(GetBuiltinFunction(methodGroup)));
 }
Esempio n. 6
0
        /// <summary>
        /// Returns a BuiltinFunction bound to the provided type arguments.  Returns null if the binding
        /// cannot be performed.
        /// </summary>
        public MethodGroup MakeGenericMethod(Type[] types)
        {
            TypeList tl = new TypeList(types);

            // check for cached method first...
            MethodGroup mg;
            if (_boundGenerics != null) {
                lock (_boundGenerics) {
                    if (_boundGenerics.TryGetValue(tl, out mg)) {
                        return mg;
                    }
                }
            }

            // Search for generic targets with the correct arity (number of type parameters).
            // Compatible targets must be MethodInfos by definition (constructors never take
            // type arguments).
            List<MethodTracker> targets = new List<MethodTracker>(Methods.Count);
            foreach (MethodTracker mt in Methods) {
                MethodInfo mi = mt.Method;
                if (mi.ContainsGenericParameters && mi.GetGenericArguments().Length == types.Length)
                    targets.Add((MethodTracker)MemberTracker.FromMemberInfo(mi.MakeGenericMethod(types)));
            }

            if (targets.Count == 0) {
                return null;
            }

            // Build a new MethodGroup that will contain targets with bound type arguments & cache it.
            mg = new MethodGroup(targets.ToArray());

            EnsureBoundGenericDict();

            lock (_boundGenerics) {
                _boundGenerics[tl] = mg;
            }

            return mg;
        }
Esempio n. 7
0
        /// <summary>
        /// Binds to the methods in a method group.
        /// </summary>
        private static TargetInfo TryGetMethodGroupTargets(DynamicMetaObject target, DynamicMetaObject[] args, MethodGroup mthgrp)
        {
            if (mthgrp != null)
            {
                List <MethodBase> foundTargets = new List <MethodBase>();

                foreach (MethodTracker mt in mthgrp.Methods)
                {
                    foundTargets.Add(mt.Method);
                }

                return(new TargetInfo(null, ArrayUtils.Insert(target, args), BindingRestrictions.GetInstanceRestriction(target.Expression, mthgrp), foundTargets.ToArray()));
            }
            return(null);
        }