예제 #1
0
            public override DynamicMetaObject /*!*/ MakeInitCall(PythonBinder /*!*/ binder, DynamicMetaObject /*!*/ createExpr)
            {
                Expression init = Ast.Call(
                    typeof(PythonOps).GetMethod("GetInitSlotMember"),
                    CodeContext,
                    Ast.Convert(Arguments.Self.Expression, typeof(PythonType)),
                    Ast.Convert(AstUtils.WeakConstant(_slot), typeof(PythonTypeSlot)),
                    AstUtils.Convert(createExpr.Expression, typeof(object))
                    );

                return(MakeDefaultInit(binder, createExpr, init));
            }
예제 #2
0
            protected override bool AddSlotAccess(PythonType pt, PythonTypeSlot pts)
            {
                pts.MakeGetExpression(
                    _state.Binder,
                    _codeContext,
                    null,
                    new DynamicMetaObject(
                        AstUtils.Convert(AstUtils.WeakConstant(Value), typeof(PythonType)),
                        BindingRestrictions.Empty,
                        Value
                        ),
                    _cb
                    );

                if (!pts.IsAlwaysVisible)
                {
                    _cb.ExtendLastCondition(Ast.Call(typeof(PythonOps).GetMethod(nameof(PythonOps.IsClsVisible)), _codeContext));
                    return(false);
                }

                return(pts.GetAlwaysSucceeds);
            }
예제 #3
0
        private DynamicMetaObject /*!*/ MakeSetMember(SetMemberBinder /*!*/ member, DynamicMetaObject /*!*/ value)
        {
            PythonContext     state = PythonContext.GetPythonContext(member);
            DynamicMetaObject self  = Restrict(Value.GetType());

            if (Value.GetType() != typeof(PythonType) && DynamicHelpers.GetPythonType(Value).IsSystemType)
            {
                // built-in subclass of .NET type.  Usually __setattr__ is handled by MetaUserObject
                // but we can have a built-in subtype that's not a user type.
                PythonTypeSlot pts;
                if (Value.TryGetCustomSetAttr(state.SharedContext, out pts))
                {
                    Debug.Assert(pts.GetAlwaysSucceeds);

                    ParameterExpression tmp = Ast.Variable(typeof(object), "boundVal");

                    return(BindingHelpers.AddDynamicTestAndDefer(
                               member,
                               new DynamicMetaObject(
                                   Ast.Block(
                                       new[] { tmp },
                                       DynamicExpression.Dynamic(
                                           state.Invoke(new CallSignature(2)),
                                           typeof(object),
                                           AstUtils.Constant(state.SharedContext),
                                           Ast.Block(
                                               Ast.Call(
                                                   typeof(PythonOps).GetMethod(nameof(PythonOps.SlotTryGetValue)),
                                                   AstUtils.Constant(state.SharedContext),
                                                   AstUtils.Convert(AstUtils.WeakConstant(pts), typeof(PythonTypeSlot)),
                                                   AstUtils.Convert(Expression, typeof(object)),
                                                   AstUtils.Convert(AstUtils.WeakConstant(DynamicHelpers.GetPythonType(Value)), typeof(PythonType)),
                                                   tmp
                                                   ),
                                               tmp
                                               ),
                                           Ast.Constant(member.Name),
                                           value.Expression
                                           )
                                       ),
                                   self.Restrictions
                                   ),
                               new DynamicMetaObject[] { this, value },
                               TestUserType()
                               ));
                }
            }

            return(BindingHelpers.AddDynamicTestAndDefer(
                       member,
                       new DynamicMetaObject(
                           Ast.Call(
                               typeof(PythonOps).GetMethod(nameof(PythonOps.PythonTypeSetCustomMember)),
                               AstUtils.Constant(PythonContext.GetPythonContext(member).SharedContext),
                               self.Expression,
                               AstUtils.Constant(member.Name),
                               AstUtils.Convert(
                                   value.Expression,
                                   typeof(object)
                                   )
                               ),
                           self.Restrictions.Merge(value.Restrictions)
                           ),
                       new DynamicMetaObject[] { this, value },
                       TestUserType()
                       ));
        }