Example #1
0
        public override ISet <Namespace> GetDescriptor(Namespace instance, Interpreter.AnalysisUnit unit)
        {
            if (_boundMethod == null)
            {
                _boundMethod = new BoundBuiltinMethodInfo(this);
            }

            return(_boundMethod.SelfSet);
        }
        public override IAnalysisSet GetDescriptor(Node node, AnalysisValue instance, AnalysisValue context, AnalysisUnit unit)
        {
            if (instance == ProjectState._noneInst)
            {
                return(base.GetDescriptor(node, instance, context, unit));
            }

            _boundMethod = _boundMethod ?? new BoundBuiltinMethodInfo(this);
            return(_boundMethod.SelfSet);
        }
        /// <summary>
        /// Checks to see if the member is the method that we've inherited from
        /// our specialized base class.  If it isn't then we should invoke it and
        /// use the result rather than using the information tracked in the
        /// specialized value.
        /// </summary>
        private bool ShouldInvokeMethod(AnalysisValue member, string name)
        {
            BoundBuiltinMethodInfo method = member as BoundBuiltinMethodInfo;

            if (method == null)
            {
                // it's not a builtin function, the method is overridden
                return(true);
            }

            var func = method.Method;

            if (func.Name != name)
            {
                // the function name is wrong, the user may have done something crazy like:
                // class C(dict):
                //      __getitem__ == some_other_builtin_func
                return(true);
            }

            if (func.Function.DeclaringType != null)
            {
                foreach (var inst in _instances)
                {
                    if (inst.TypeId == func.Function.DeclaringType.TypeId)
                    {
                        // the function is the original specialized function, not overridden
                        return(false);
                    }
                }
            }

            // The name matches, but the function is from the wrong type.
            // The user must have done something like:
            // class C(dict):
            //      __getitem__ = list.__getitem__

            return(true);
        }