Пример #1
0
        private MethodBinder(ActionBinder binder, string name, IList <MethodBase> methods, BinderType binderType, SymbolId[] kwArgs)
        {
            _binder     = binder;
            _name       = name;
            _binderType = binderType;
            _kwArgs     = kwArgs;
            foreach (MethodBase method in methods)
            {
                if (IsUnsupported(method))
                {
                    continue;
                }

                AddBasicMethodTargets(method);
            }

            if (_paramsCandidates != null)
            {
                foreach (MethodCandidate maker in _paramsCandidates)
                {
                    foreach (int count in _targetSets.Keys)
                    {
                        MethodCandidate target = maker.MakeParamsExtended(binder, count, _kwArgs);
                        if (target != null)
                        {
                            AddTarget(target);
                        }
                    }
                }
            }
        }
Пример #2
0
        public int CompareTo(MethodCandidate other, CallType callType, Type[] actualTypes)
        {
            int?cmpParams = CompareParameters(other, actualTypes);

            if (cmpParams == +1 || cmpParams == -1)
            {
                return((int)cmpParams);
            }

            int ret = Target.CompareEqualParameters(other.Target);

            if (ret != 0)
            {
                return(ret);
            }

            if (CompilerHelpers.IsStatic(Target.Method) && !CompilerHelpers.IsStatic(other.Target.Method))
            {
                return(callType == CallType.ImplicitInstance ? -1 : +1);
            }
            else if (!CompilerHelpers.IsStatic(Target.Method) && CompilerHelpers.IsStatic(other.Target.Method))
            {
                return(callType == CallType.ImplicitInstance ? +1 : -1);
            }

            return(0);
        }
Пример #3
0
 private void AddSimpleTarget(MethodCandidate target)
 {
     AddTarget(target);
     if (CompilerHelpers.IsParamsMethod(target.Target.Method))
     {
         if (_paramsCandidates == null)
         {
             _paramsCandidates = new List <MethodCandidate>();
         }
         _paramsCandidates.Add(target);
     }
 }
Пример #4
0
        private void AddTarget(MethodCandidate target)
        {
            int       count = target.Target.ParameterCount;
            TargetSet set;

            if (!_targetSets.TryGetValue(count, out set))
            {
                set = new TargetSet(this, count);
                _targetSets[count] = set;
            }
            set.Add(target);
        }
Пример #5
0
 private static bool IsBest(MethodCandidate candidate, List <MethodCandidate> applicableTargets, CallType callType, Type[] actualTypes)
 {
     foreach (MethodCandidate target in applicableTargets)
     {
         if (candidate == target)
         {
             continue;
         }
         if (candidate.CompareTo(target, callType, actualTypes) != +1)
         {
             return(false);
         }
     }
     return(true);
 }
Пример #6
0
        private TargetSet BuildTargetSet(int count)
        {
            TargetSet ts = new TargetSet(this, count);

            if (_paramsCandidates != null)
            {
                foreach (MethodCandidate maker in _paramsCandidates)
                {
                    MethodCandidate target = maker.MakeParamsExtended(_binder, count, _kwArgs);
                    if (target != null)
                    {
                        ts.Add(target);
                    }
                }
            }

            return(ts);
        }
Пример #7
0
 private bool TryGetApplicableTarget(CallType callType, List <MethodCandidate> applicableTargets, Type[] actualTypes, out List <MethodCandidate> result)
 {
     result = null;
     if (applicableTargets.Count == 1)
     {
         result = applicableTargets;
         return(true);
     }
     if (applicableTargets.Count > 1)
     {
         MethodCandidate target = FindBest(callType, applicableTargets, actualTypes);
         if (target != null)
         {
             result = new List <MethodCandidate>(new MethodCandidate[] { target });
             return(true);
         }
         else
         {
             result = applicableTargets;
             return(true);
         }
     }
     return(false);
 }
Пример #8
0
        public void Add(MethodCandidate target)
        {
            Debug.Assert(target.Parameters.Count == _count);

            _targets.Add(target);
        }
Пример #9
0
 public MethodCandidate(MethodCandidate previous, NarrowingLevel narrowingLevel)
 {
     this._target     = previous.Target;
     this._parameters = previous._parameters;
     _narrowingLevel  = narrowingLevel;
 }
Пример #10
0
 public int?CompareParameters(MethodCandidate other, Type[] actualTypes)
 {
     return(ParameterWrapper.CompareParameters(this._parameters, other._parameters, actualTypes));
 }