示例#1
0
        internal bool TryLookupSlotInBases(ICallerContext context, SymbolId name, out object ret)
        {
            Tuple resOrder = MethodResolutionOrder;

            for (int i = 1; i < resOrder.Count; i++)    // skip our own type...
            {
                object type = resOrder[i];

                PythonType pt = type as PythonType;
                if (pt != null)
                {
                    if (pt.TryGetSlot(context, name, out ret))
                    {
                        // respect MRO for base class lookups: method wrappers are
                        // logically a member of a super type, but are available on
                        // derived types for quick access.  We only want to return a method
                        // wrapper here if it's actually exposed on our type.

                        MethodWrapper mw = ret as MethodWrapper;
                        if (mw == null || !mw.IsSuperTypeMethod())
                        {
                            return(true);
                        }
                    }
                }
                else if (Ops.TryGetAttr(context, type, name, out ret))
                {
                    return(true);
                }
            }
            ret = null;
            return(false);
        }
示例#2
0
        internal bool TryGetSlot(ICallerContext context, SymbolId name, out object ret)
        {
            Initialize();

            switch (name.Id)
            {
            case SymbolTable.DictId: ret = dict; return(true);

            case SymbolTable.GetAttributeId:  ret = __getattribute__F;  return(true);

            case SymbolTable.GetAttrId: ret = __getattr__F; return(true);

            case SymbolTable.SetAttrId: ret = __setattr__F; return(true);

            case SymbolTable.DelAttrId: ret = __delattr__F; return(true);

            case SymbolTable.ReprId: ret = __repr__F; return(true);

            case SymbolTable.StringId: ret = __str__F; return(true);

            case SymbolTable.CmpId:
                if (!__cmp__F.IsSuperTypeMethod())
                {
                    ret = __cmp__F;
                    return(true);
                }
                break;

            case SymbolTable.MethodResolutionOrderId:
                if (methodResolutionOrder == null)
                {
                    methodResolutionOrder = CalculateMro(BaseClasses);
                }
                ret = methodResolutionOrder;
                return(true);
            }

            if (dict.TryGetValue(name, out ret))
            {
                IContextAwareMember icam = ret as IContextAwareMember;
                if (icam != null && !icam.IsVisible(context))
                {
                    ret = null;
                    return(false);
                }
                return(true);
            }
            return(false);
        }