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; }
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; }
/// <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; }
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() ); }
private static Expression ReturnMethodGroup(MethodGroup methodGroup) { return Ast.Constant(PythonTypeOps.GetFinalSlotForFunction(GetBuiltinFunction(methodGroup))); }
/// <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; }
/// <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); }